Fixed Some Bugs and Finalized The Staff Management System

This commit is contained in:
Trixkz 2023-10-26 17:21:17 -04:00
parent b21133c8c9
commit be529195df
8 changed files with 164 additions and 39 deletions

View File

@ -0,0 +1,124 @@
package com.loganmagnan.eventcore.listeners;
import com.loganmagnan.eventcore.EventCore;
import com.loganmagnan.eventcore.managers.hotbar.ClickableItem;
import com.loganmagnan.eventcore.managers.hotbar.HotBar;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.Event;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.Action;
import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.player.PlayerDropItemEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.inventory.ItemStack;
public class ClickableItemListener implements Listener {
private EventCore main = EventCore.getInstance();
@EventHandler
public void onBlockPlace(BlockPlaceEvent event) {
Player player = event.getPlayer();
ItemStack itemStack = player.getItemInHand();
if (itemStack.getType() == Material.AIR) {
return;
}
for (HotBar hotBar : this.main.getHotBarManager().getHotBars()) {
for (ClickableItem clickableItem : hotBar.getClickableItems().values()) {
if (!itemStack.isSimilar(clickableItem.getItemStack())) {
continue;
}
event.setCancelled(true);
break;
}
}
}
@EventHandler
public void onPlayerInteract(PlayerInteractEvent event) {
Player player = event.getPlayer();
ItemStack itemStack = player.getItemInHand();
if (itemStack.getType() == Material.AIR || (event.getAction() != Action.RIGHT_CLICK_AIR && event.getAction() != Action.RIGHT_CLICK_BLOCK)) {
return;
}
for (HotBar hotBar : this.main.getHotBarManager().getHotBars()) {
for (ClickableItem clickableItem : hotBar.getClickableItems().values()) {
if (!itemStack.isSimilar(clickableItem.getItemStack())) {
continue;
}
event.setCancelled(true);
event.setUseItemInHand(Event.Result.DENY);
event.setUseInteractedBlock(Event.Result.DENY);
if (clickableItem.getClickHandler() == null) {
continue;
}
clickableItem.getClickHandler().executeAs(player);
break;
}
}
}
@EventHandler
public void onPlayerDropItem(PlayerDropItemEvent event) {
Player player = event.getPlayer();
ItemStack itemStack = event.getItemDrop().getItemStack();
for (HotBar hotBar : this.main.getHotBarManager().getHotBars()) {
for (ClickableItem clickableItem : hotBar.getClickableItems().values()) {
if (!itemStack.isSimilar(clickableItem.getItemStack()) || clickableItem.isDroppable()) {
continue;
}
event.setCancelled(true);
break;
}
}
}
@EventHandler
public void onInventoryClick(InventoryClickEvent event) {
Player player = (Player) event.getWhoClicked();
for (HotBar hotBar : this.main.getHotBarManager().getHotBars()) {
for (ClickableItem clickableItem : hotBar.getClickableItems().values()) {
if (event.getCurrentItem() != null && event.getCurrentItem().isSimilar(clickableItem.getItemStack()) && !clickableItem.isMoveable()) {
event.setCancelled(true);
event.setResult(Event.Result.DENY);
break;
}
if (event.getCursor() != null && event.getCursor().isSimilar(clickableItem.getItemStack()) && !clickableItem.isMoveable()) {
event.setCancelled(true);
event.setResult(Event.Result.DENY);
break;
}
if (event.getHotbarButton() != -1 && player.getInventory().getItem(event.getHotbarButton()) != null && player.getInventory().getItem(event.getHotbarButton()).isSimilar(clickableItem.getItemStack()) && !clickableItem.isMoveable()) {
event.setCancelled(true);
event.setResult(Event.Result.DENY);
break;
}
}
}
}
}

View File

@ -53,8 +53,6 @@ public class PlayerDataListener implements Listener {
Player player = event.getPlayer();
PlayerData playerData = this.plugin.getPlayerDataManager().getPlayerData(player.getUniqueId());
this.plugin.getPlayerDataManager().sendToSpawnAndResetPlayer(player);
}
@EventHandler

View File

@ -36,7 +36,9 @@ public class PlayerDataManager {
Document document = this.main.getMongoManager().getPlayers().find(Filters.eq("unique-id", playerData.getUniqueId().toString())).first();
if (document != null) {
playerData.setChatColor(ChatColor.valueOf(document.getString("chat-color")));
if (document.getString("chat-color") != null) {
playerData.setChatColor(ChatColor.valueOf(document.getString("chat-color")));
}
}
playerData.setLoaded(true);
@ -45,7 +47,10 @@ public class PlayerDataManager {
public void savePlayerData(PlayerData playerData) {
Document document = new Document();
document.put("unique-id", playerData.getUniqueId().toString());
document.put("chat-color", playerData.getChatColor().name());
if (playerData.getChatColor() != null) {
document.put("chat-color", playerData.getChatColor().name());
}
this.main.getMongoManager().getPlayers().replaceOne(Filters.eq("unique-id", playerData.getUniqueId().toString()), document, new UpdateOptions().upsert(true));
}
@ -81,6 +86,16 @@ public class PlayerDataManager {
player.updateInventory();
}
public void sendPlayerToSpawn(Player player) {
if (!player.isOnline()) {
return;
}
if (this.main.getSpawnManager().getSpawnLocation() != null) {
player.teleport(this.main.getSpawnManager().getSpawnLocation().toBukkitLocation());
}
}
public void resetPlayer(Player player) {
PlayerData playerData = this.getPlayerData(player.getUniqueId());
playerData.setPlayerState(PlayerState.SPAWN);

View File

@ -45,21 +45,25 @@ public class StaffManager {
}
}
this.setVanish(player, true);
this.playersInStaffMode.add(player.getUniqueId());
this.cachedInventories.put(player.getUniqueId(), new CachedInventory(player, false));
this.staffModeHotBar.applyToPlayer(player, true);
player.getInventory().clear();
player.getInventory().setArmorContents(null);
player.setGameMode(GameMode.CREATIVE);
this.setVanish(player, true);
this.staffModeHotBar.applyToPlayer(player, true);
player.sendMessage(ColorUtils.getMessageType("&bYou've &aenabled &bstaff mode"));
} else {
this.setVanish(player, false);
this.playersInStaffMode.remove(player.getUniqueId());
this.cachedInventories.get(player.getUniqueId()).applyToPlayer(player, false);
player.setGameMode(GameMode.SURVIVAL);
this.setVanish(player, false);
player.sendMessage(ColorUtils.getMessageType("&bYou've &cdisabled &bstaff mode"));
}
}

View File

@ -4,5 +4,5 @@ import org.bukkit.entity.Player;
public interface ClickHandler {
void click(Player player);
void executeAs(Player player);
}

View File

@ -14,7 +14,7 @@ public abstract class HotBar {
private EventCore main = EventCore.getInstance();
private Map<String, ClickableItem> cachedItems = new ConcurrentHashMap<String, ClickableItem>();
private Map<String, ClickableItem> clickableItems = new ConcurrentHashMap<String, ClickableItem>();
private String id;
@ -23,27 +23,20 @@ public abstract class HotBar {
}
public ClickableItem getClickableItem(String id) {
return this.cachedItems.get(id);
return this.clickableItems.get(id);
}
public void addClickableItem(String id, ClickableItem clickableItem) {
this.cachedItems.put(id, clickableItem);
this.clickableItems.put(id, clickableItem);
}
public void removeClickableItem(String id) {
this.cachedItems.remove(id);
this.clickableItems.remove(id);
}
public void applyToPlayer(Player player, ClickableItem clickableItem, int slot) {
player.getInventory().setItem(slot, null);
player.getInventory().setItem(slot, clickableItem.getItemStack());
(new BukkitRunnable() {
@Override
public void run() {
player.updateInventory();
}
}).runTaskLater(this.main, 1);
}
public void applyToPlayer(Player player, boolean clearHotBar) {
@ -58,13 +51,6 @@ public abstract class HotBar {
for (int slot : clickableItemsToApply.keySet()) {
player.getInventory().setItem(slot, clickableItemsToApply.get(slot).getItemStack());
}
(new BukkitRunnable() {
@Override
public void run() {
player.updateInventory();
}
}).runTaskLater(this.main, 1);
}
public abstract Map<Integer, ClickableItem> getClickableItemsToApply(Player player);

View File

@ -36,7 +36,7 @@ public class StaffModeHotBar extends HotBar {
clickableItems.put(3, this.getClickableItem("better-looking"));
clickableItems.put(7, this.getClickableItem("staff-online"));
clickableItems.put(8, this.getClickableItem("vanish"));
clickableItems.put(8, this.getClickableItem("unvanish"));
return clickableItems;
}
@ -44,36 +44,36 @@ public class StaffModeHotBar extends HotBar {
public void registerClickableItems() {
this.addClickableItem("teleport-compass", new ClickableItem(player -> {
}, (new ItemBuilder(Material.COMPASS).name(ColorUtils.getMessageType("&bTeleport Compass"))).build(), false, false, false));
}, new ItemBuilder(Material.COMPASS).name(ColorUtils.getMessageType("&bTeleport Compass")).build(), false, false, false));
this.addClickableItem("inventory-inspect", new ClickableItem(player -> {
}, (new ItemBuilder(Material.BOOK).name(ColorUtils.getMessageType("&bInventory Inspect"))).build(), false, false, false));
}, new ItemBuilder(Material.BOOK).name(ColorUtils.getMessageType("&bInventory Inspect")).build(), false, false, false));
this.addClickableItem("world-edit-wand", new ClickableItem(player -> {
}, (new ItemBuilder(Material.WOODEN_AXE).name(ColorUtils.getMessageType("&bWorld Edit Wand"))).build(), false, false, false));
}, new ItemBuilder(Material.WOODEN_AXE).name(ColorUtils.getMessageType("&bWorld Edit Wand")).build(), false, false, false));
this.addClickableItem("better-looking", new ClickableItem(player -> {
}, (new ItemBuilder(Material.RED_CARPET).name(ColorUtils.getMessageType(""))).build(), false, false, false));
}, new ItemBuilder(Material.RED_CARPET).name(ColorUtils.getMessageType("&bBetter Looking")).build(), false, false, false));
this.addClickableItem("staff-online", new ClickableItem(player -> {
// To Do: Staff Online System
}, (new ItemBuilder(Material.PLAYER_HEAD).name(ColorUtils.getMessageType("&bStaff Online"))).build(), false, false, false));
}, new ItemBuilder(Material.PLAYER_HEAD).name(ColorUtils.getMessageType("&bStaff Online")).build(), false, false, false));
this.addClickableItem("vanish", new ClickableItem(player -> {
this.applyToPlayer(player, this.getClickableItem("unvanish"), 8);
this.main.getStaffManager().setVanish(player, true);
player.sendMessage(ColorUtils.getMessageType("&bYou've &aenabled &bvanish"));
}, (new ItemBuilder(Material.LIME_DYE).name(ColorUtils.getMessageType("&bVanish"))).build(), false, false, false));
}, new ItemBuilder(Material.GRAY_DYE).name(ColorUtils.getMessageType("&bVanish")).build(), false, false, false));
this.addClickableItem("unvanish", new ClickableItem(player -> {
this.applyToPlayer(player, this.getClickableItem("vanish"), 8);
this.main.getStaffManager().setVanish(player, false);
player.sendMessage(ColorUtils.getMessageType("&bYou've &cdisabled &bvanish"));
}, (new ItemBuilder(Material.GRAY_DYE).name(ColorUtils.getMessageType("&bUnvanish"))).build(), false, false, false));
}, new ItemBuilder(Material.LIME_DYE).name(ColorUtils.getMessageType("&bUnvanish")).build(), false, false, false));
}
}

View File

@ -47,16 +47,12 @@ public class ChatManagementMenu extends Menu {
case SOUL_SAND:
if (event.getClick().isLeftClick()) {
this.delayAmount++;
new ChatManagementMenu(this.playerMenuUtil, this.delayAmount).open(player);
} else if (event.getClick().isRightClick()) {
if (this.delayAmount <= 0) {
return;
}
this.delayAmount--;
new ChatManagementMenu(this.playerMenuUtil, this.delayAmount).open(player);
} else if (event.getClick().isShiftClick()) {
this.main.getChatManager().slowChat(player, this.delayAmount);
}
@ -67,6 +63,8 @@ public class ChatManagementMenu extends Menu {
break;
}
new ChatManagementMenu(this.playerMenuUtil, this.delayAmount).open(player);
}
}
@ -96,7 +94,7 @@ public class ChatManagementMenu extends Menu {
"&fSlowed By: &b" + (this.main.getChatManager().getSlowedBy() == null ? "None" : this.main.getServer().getOfflinePlayer(this.main.getChatManager().getSlowedBy()).getName()),
"&fLast Slowed: &b" + (this.main.getChatManager().getLastSlowedTime() == 0 ? "Never" : Utils.getTimeAsAString(this.main.getChatManager().getLastSlowedTime())),
"",
"&bShift click to slow the chat for &3" + (this.delayAmount + "second" + (this.delayAmount > 1 ? "s" : "")),
"&bShift click to slow the chat for &3" + (this.delayAmount + " second" + (this.delayAmount > 1 ? "s" : "")),
"",
"&fLeft Click: &b+1",
"&fRight Click: &b-1"