mirror of
https://github.com/Freezy-Studios/BlazeSMP.git
synced 2025-04-22 11:44:05 +02:00
added things
This commit is contained in:
parent
591eb3231e
commit
2059bdb4b9
8 changed files with 50 additions and 66 deletions
|
@ -9,6 +9,7 @@ import me.freezy.plugins.papermc.blazesmp.module.manager.L4M4;
|
|||
import me.freezy.plugins.papermc.blazesmp.module.manager.ProtectedBlocks;
|
||||
import me.freezy.plugins.papermc.blazesmp.tasks.PlayerNameUpdate;
|
||||
import me.freezy.plugins.papermc.blazesmp.tasks.TabListTimer;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
@ -26,6 +27,7 @@ public final class BlazeSMP extends JavaPlugin {
|
|||
@Getter private BukkitTask nameUpdateTask;
|
||||
@Getter private BukkitTask tabListUpdateTask;
|
||||
|
||||
|
||||
@Override
|
||||
public void onLoad() {
|
||||
this.log=getSLF4JLogger();
|
||||
|
|
|
@ -130,6 +130,10 @@ public class ClanCommand extends SimpleCommand {
|
|||
player.sendMessage(miniMessage().deserialize(L4M4.get("error.clan_not_found")));
|
||||
return true;
|
||||
}
|
||||
if (targetClan.getMembers().size() >= 10) {
|
||||
player.sendMessage(miniMessage().deserialize(L4M4.get("error.clan_full")));
|
||||
return true;
|
||||
}
|
||||
clanJoins.computeIfAbsent(targetClan, k -> new LinkedList<>());
|
||||
LinkedList<UUID> joinRequests = clanJoins.get(targetClan);
|
||||
if (joinRequests.contains(playerUUID)) {
|
||||
|
@ -140,7 +144,6 @@ public class ClanCommand extends SimpleCommand {
|
|||
player.sendMessage(miniMessage().deserialize(
|
||||
String.format(L4M4.get("success.join_request_sent"), targetClan.getName())
|
||||
));
|
||||
// Benachrichtige den Clan-Leader, sofern online
|
||||
Player leader = Bukkit.getPlayer(targetClan.getLeaderUUID());
|
||||
if (leader != null && leader.isOnline()) {
|
||||
String acceptCommand = "/clan accept " + player.getName();
|
||||
|
@ -189,6 +192,10 @@ public class ClanCommand extends SimpleCommand {
|
|||
player.sendMessage(miniMessage().deserialize(L4M4.get("error.clan_not_found")));
|
||||
return true;
|
||||
}
|
||||
if (inviterClan.getMembers().size() >= 10) {
|
||||
player.sendMessage(miniMessage().deserialize(L4M4.get("error.clan_full")));
|
||||
return true;
|
||||
}
|
||||
clanInvites.computeIfAbsent(inviterClan, k -> new LinkedList<>());
|
||||
LinkedList<UUID> inviteList = clanInvites.get(inviterClan);
|
||||
if (inviteList.contains(invitee.getUniqueId())) {
|
||||
|
@ -201,7 +208,6 @@ public class ClanCommand extends SimpleCommand {
|
|||
player.sendMessage(miniMessage().deserialize(
|
||||
String.format(L4M4.get("success.invite_sent"), inviteeName)
|
||||
));
|
||||
// Benachrichtige den Eingeladenen
|
||||
String acceptCmd = "/clan accept " + inviterClan.getName();
|
||||
String denyCmd = "/clan deny " + inviterClan.getName();
|
||||
String inviteNotifyText = String.format(L4M4.get("notification.invite"), inviterClan.getName());
|
||||
|
|
|
@ -18,7 +18,7 @@ import java.util.UUID;
|
|||
|
||||
public class VanishCommand extends SimpleCommand {
|
||||
private final Set<UUID> vanishedPlayers = new HashSet<>();
|
||||
private static boolean isvanished = true;
|
||||
private boolean isvanished = true;
|
||||
|
||||
public VanishCommand() {
|
||||
super("vanish");
|
||||
|
@ -31,16 +31,25 @@ public class VanishCommand extends SimpleCommand {
|
|||
return false;
|
||||
}
|
||||
Player player = (Player) sender;
|
||||
Player online = (Player) Bukkit.getOnlinePlayers();
|
||||
|
||||
if (isvanished) {
|
||||
player.showPlayer(BlazeSMP.getInstance(), online);
|
||||
vanishedPlayers.remove(player.getUniqueId());
|
||||
online.sendMessage(MiniMessage.miniMessage().deserialize(L4M4.get("player.join")));
|
||||
if (player.isOp()) {
|
||||
for (Player online : Bukkit.getOnlinePlayers()) {
|
||||
if (isvanished) {
|
||||
player.showPlayer(BlazeSMP.getInstance(), online);
|
||||
online.sendMessage(MiniMessage.miniMessage().deserialize(L4M4.get("player.join")));
|
||||
} else {
|
||||
player.hidePlayer(BlazeSMP.getInstance(), online);
|
||||
online.sendMessage(MiniMessage.miniMessage().deserialize(L4M4.get("player.left")));
|
||||
}
|
||||
}
|
||||
if (isvanished) {
|
||||
vanishedPlayers.remove(player.getUniqueId());
|
||||
} else {
|
||||
vanishedPlayers.add(player.getUniqueId());
|
||||
}
|
||||
} else {
|
||||
player.hidePlayer(BlazeSMP.getInstance(), online);
|
||||
vanishedPlayers.add(player.getUniqueId());
|
||||
online.sendMessage(MiniMessage.miniMessage().deserialize(L4M4.get("player.left")));
|
||||
player.sendMessage(MiniMessage.miniMessage().deserialize(L4M4.get("error.no_permission")));
|
||||
return false;
|
||||
}
|
||||
|
||||
isvanished = !isvanished;
|
||||
|
|
|
@ -33,6 +33,8 @@ public class PlayerClaimListener implements Listener {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@EventHandler
|
||||
public void onBlockPlace(BlockPlaceEvent event) {
|
||||
Location location = event.getBlock().getLocation();
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package me.freezy.plugins.papermc.blazesmp.listener;
|
||||
|
||||
import me.freezy.plugins.papermc.blazesmp.BlazeSMP;
|
||||
import me.freezy.plugins.papermc.blazesmp.manager.PlayerManager;
|
||||
import me.freezy.plugins.papermc.blazesmp.module.manager.L4M4;
|
||||
import net.kyori.adventure.text.Component;
|
||||
|
@ -11,12 +12,21 @@ import org.bukkit.event.Listener;
|
|||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.scoreboard.Team;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.UUID;
|
||||
|
||||
public class PlayerJoinListener implements Listener {
|
||||
private final HashSet<UUID> joinedPlayers = new HashSet<>();
|
||||
@EventHandler
|
||||
public void onJoin(PlayerJoinEvent event) {
|
||||
UUID playerUUID = event.getPlayer().getUniqueId();
|
||||
Player player = event.getPlayer();
|
||||
new PlayerManager().setPlayerTeam(player);
|
||||
Team team = player.getScoreboard().getEntryTeam(player.getName());
|
||||
if (!joinedPlayers.contains(playerUUID)) {
|
||||
event.getPlayer().sendMessage(MiniMessage.miniMessage().deserialize(L4M4.get("join.notify")));
|
||||
joinedPlayers.add(playerUUID);
|
||||
}
|
||||
|
||||
// Verwende den zentral konfigurierten Join-Text aus der JSON-Datei
|
||||
assert team != null;
|
||||
|
|
|
@ -39,9 +39,6 @@ public class ProtectedBlockListener implements Listener {
|
|||
Material.FURNACE, Material.BLAST_FURNACE, Material.SMOKER
|
||||
);
|
||||
|
||||
/*
|
||||
* Prevents items from being transferred into protected storages.
|
||||
*/
|
||||
@EventHandler
|
||||
public void onItemTransferHopperEvent(InventoryMoveItemEvent event) {
|
||||
Location destLocation = event.getDestination().getLocation();
|
||||
|
@ -52,10 +49,6 @@ public class ProtectedBlockListener implements Listener {
|
|||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Handles player interactions with storage blocks.
|
||||
* Supports locking, unlocking, linking keys, and opening GUIs.
|
||||
*/
|
||||
@EventHandler
|
||||
public void onBlockInteractEvent(PlayerInteractEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
|
@ -68,26 +61,22 @@ public class ProtectedBlockListener implements Listener {
|
|||
ItemStack mainHandItem = player.getInventory().getItemInMainHand();
|
||||
ProtectedBlock protectedBlock = getProtectedBlock(block);
|
||||
|
||||
// Owner can manage keys with shift-right-click if the block is already locked.
|
||||
if (player.isSneaking() && protectedBlock != null &&
|
||||
protectedBlock.owner().equals(player.getUniqueId())) {
|
||||
openManageKeysGUI(player, block);
|
||||
return;
|
||||
}
|
||||
|
||||
// Shift + Right-click with a valid trial key relinks the key to the new container.
|
||||
if (player.isSneaking() && isValidKey(mainHandItem)) {
|
||||
relinkKey(player, mainHandItem, block);
|
||||
return;
|
||||
}
|
||||
|
||||
// Shift + Right-click on an unlocked container opens the lock GUI.
|
||||
if (player.isSneaking() && protectedBlock == null) {
|
||||
openLockGUI(player, block);
|
||||
return;
|
||||
}
|
||||
|
||||
// Normal right-click: if a valid key is held for a locked container, open the inventory.
|
||||
if (protectedBlock != null && isValidKey(mainHandItem, protectedBlock.key())) {
|
||||
if (block.getState() instanceof Container container) {
|
||||
player.openInventory(container.getInventory());
|
||||
|
@ -95,24 +84,18 @@ public class ProtectedBlockListener implements Listener {
|
|||
return;
|
||||
}
|
||||
|
||||
// Normal right-click on a locked container without a valid key shows a locked message.
|
||||
if (protectedBlock != null) {
|
||||
String lockedMsg = String.format(L4M4.get("storage.locked"), "minecraft:trial_key");
|
||||
player.sendMessage(miniMessage.deserialize(lockedMsg));
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Opens the lock GUI for a container.
|
||||
* Two trial keys are created and the container is then registered as protected.
|
||||
*/
|
||||
private void openLockGUI(Player player, Block block) {
|
||||
String titleRaw = String.format(L4M4.get("storage.lock_gui_title"), block.getType().toString());
|
||||
Inventory lockInventory = Bukkit.createInventory(player, InventoryType.HOPPER,
|
||||
miniMessage.deserialize(titleRaw));
|
||||
|
||||
UUID lockUUID = UUID.randomUUID();
|
||||
// Create two identical trial keys for symmetry
|
||||
ItemStack trialKey1 = createTrialKey(lockUUID);
|
||||
ItemStack trialKey2 = createTrialKey(lockUUID);
|
||||
|
||||
|
@ -120,19 +103,14 @@ public class ProtectedBlockListener implements Listener {
|
|||
lockInventory.setItem(4, trialKey2);
|
||||
|
||||
player.openInventory(lockInventory);
|
||||
// Save the protected block information
|
||||
protectedBlocks.addBlock(new ProtectedBlock(player.getUniqueId(), lockUUID, block.getLocation()));
|
||||
}
|
||||
|
||||
/*
|
||||
* Opens the manage keys GUI for the owner to add or remove keys.
|
||||
*/
|
||||
private void openManageKeysGUI(Player player, Block block) {
|
||||
String titleRaw = String.format(L4M4.get("storage.manage_gui_title"), block.getType().toString());
|
||||
Inventory manageKeysInventory = Bukkit.createInventory(player, InventoryType.HOPPER,
|
||||
miniMessage.deserialize(titleRaw));
|
||||
|
||||
// Create "Add Key" button
|
||||
ItemStack addKey = new ItemStack(Material.PAPER);
|
||||
ItemMeta addKeyMeta = addKey.getItemMeta();
|
||||
if (addKeyMeta != null) {
|
||||
|
@ -140,7 +118,6 @@ public class ProtectedBlockListener implements Listener {
|
|||
addKey.setItemMeta(addKeyMeta);
|
||||
}
|
||||
|
||||
// Create "Remove Key" button
|
||||
ItemStack removeKey = new ItemStack(Material.BARRIER);
|
||||
ItemMeta removeKeyMeta = removeKey.getItemMeta();
|
||||
if (removeKeyMeta != null) {
|
||||
|
@ -154,10 +131,6 @@ public class ProtectedBlockListener implements Listener {
|
|||
player.openInventory(manageKeysInventory);
|
||||
}
|
||||
|
||||
/*
|
||||
* Relinks the provided trial key to the new block.
|
||||
* A new lock UUID is generated and the key’s lore is updated.
|
||||
*/
|
||||
private void relinkKey(Player player, ItemStack key, Block newBlock) {
|
||||
UUID newLockUUID = UUID.randomUUID();
|
||||
ItemMeta meta = key.getItemMeta();
|
||||
|
@ -173,10 +146,6 @@ public class ProtectedBlockListener implements Listener {
|
|||
player.sendMessage(miniMessage.deserialize(L4M4.get("storage.link_success")));
|
||||
}
|
||||
|
||||
/*
|
||||
* Prevents any changes in the lock or manage keys GUIs.
|
||||
* Also informs the player that the action was completed.
|
||||
*/
|
||||
@EventHandler
|
||||
public void onInventoryClick(InventoryClickEvent event) {
|
||||
String title = event.getView().title().toString();
|
||||
|
@ -191,10 +160,6 @@ public class ProtectedBlockListener implements Listener {
|
|||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Handles block breaking.
|
||||
* If the block is protected, only the owner can break it.
|
||||
*/
|
||||
@EventHandler
|
||||
public void onBlockBreak(BlockBreakEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
|
@ -212,17 +177,11 @@ public class ProtectedBlockListener implements Listener {
|
|||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Prevents explosions from destroying protected storage blocks.
|
||||
*/
|
||||
@EventHandler
|
||||
public void onExplosion(EntityExplodeEvent event) {
|
||||
event.blockList().removeIf(this::isProtected);
|
||||
}
|
||||
|
||||
/*
|
||||
* Helper method to create a trial key with linked lock information.
|
||||
*/
|
||||
private ItemStack createTrialKey(UUID lockUUID) {
|
||||
ItemStack trialKey = new ItemStack(Material.TRIPWIRE_HOOK);
|
||||
ItemMeta meta = trialKey.getItemMeta();
|
||||
|
@ -237,16 +196,10 @@ public class ProtectedBlockListener implements Listener {
|
|||
return trialKey;
|
||||
}
|
||||
|
||||
/*
|
||||
* Validates if the provided item is a trial key.
|
||||
*/
|
||||
private boolean isValidKey(ItemStack item) {
|
||||
return item != null && item.getType() == Material.TRIPWIRE_HOOK && item.hasItemMeta();
|
||||
}
|
||||
|
||||
/*
|
||||
* Validates if the provided item is a trial key that is linked to the given lock UUID.
|
||||
*/
|
||||
private boolean isValidKey(ItemStack item, UUID lockUUID) {
|
||||
if (!isValidKey(item)) return false;
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
|
@ -254,9 +207,6 @@ public class ProtectedBlockListener implements Listener {
|
|||
return Objects.requireNonNull(meta.lore()).stream().anyMatch(line -> line.contains(Component.text(lockUUID.toString())));
|
||||
}
|
||||
|
||||
/*
|
||||
* Returns the ProtectedBlock associated with the given block, or null if not found.
|
||||
*/
|
||||
private ProtectedBlock getProtectedBlock(Block block) {
|
||||
return protectedBlocks.getBlocks().stream()
|
||||
.filter(pb -> pb.location().equals(block.getLocation()))
|
||||
|
@ -264,10 +214,7 @@ public class ProtectedBlockListener implements Listener {
|
|||
.orElse(null);
|
||||
}
|
||||
|
||||
/*
|
||||
* Checks if a block is protected.
|
||||
*/
|
||||
private boolean isProtected(Block block) {
|
||||
return getProtectedBlock(block) != null;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -136,6 +136,7 @@ public class Clan {
|
|||
this.chunkAmount = loaded.chunkAmount;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Saves the clan data to its corresponding JSON file.
|
||||
*/
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue