Fixed Some Bugs and Finalized The Staff Management System
This commit is contained in:
parent
b21133c8c9
commit
be529195df
@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -53,8 +53,6 @@ public class PlayerDataListener implements Listener {
|
|||||||
Player player = event.getPlayer();
|
Player player = event.getPlayer();
|
||||||
|
|
||||||
PlayerData playerData = this.plugin.getPlayerDataManager().getPlayerData(player.getUniqueId());
|
PlayerData playerData = this.plugin.getPlayerDataManager().getPlayerData(player.getUniqueId());
|
||||||
|
|
||||||
this.plugin.getPlayerDataManager().sendToSpawnAndResetPlayer(player);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
|
@ -36,7 +36,9 @@ public class PlayerDataManager {
|
|||||||
Document document = this.main.getMongoManager().getPlayers().find(Filters.eq("unique-id", playerData.getUniqueId().toString())).first();
|
Document document = this.main.getMongoManager().getPlayers().find(Filters.eq("unique-id", playerData.getUniqueId().toString())).first();
|
||||||
|
|
||||||
if (document != null) {
|
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);
|
playerData.setLoaded(true);
|
||||||
@ -45,7 +47,10 @@ public class PlayerDataManager {
|
|||||||
public void savePlayerData(PlayerData playerData) {
|
public void savePlayerData(PlayerData playerData) {
|
||||||
Document document = new Document();
|
Document document = new Document();
|
||||||
document.put("unique-id", playerData.getUniqueId().toString());
|
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));
|
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();
|
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) {
|
public void resetPlayer(Player player) {
|
||||||
PlayerData playerData = this.getPlayerData(player.getUniqueId());
|
PlayerData playerData = this.getPlayerData(player.getUniqueId());
|
||||||
playerData.setPlayerState(PlayerState.SPAWN);
|
playerData.setPlayerState(PlayerState.SPAWN);
|
||||||
|
@ -45,21 +45,25 @@ public class StaffManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this.setVanish(player, true);
|
|
||||||
this.playersInStaffMode.add(player.getUniqueId());
|
this.playersInStaffMode.add(player.getUniqueId());
|
||||||
this.cachedInventories.put(player.getUniqueId(), new CachedInventory(player, false));
|
this.cachedInventories.put(player.getUniqueId(), new CachedInventory(player, false));
|
||||||
this.staffModeHotBar.applyToPlayer(player, true);
|
|
||||||
|
|
||||||
player.getInventory().clear();
|
player.getInventory().clear();
|
||||||
player.getInventory().setArmorContents(null);
|
player.getInventory().setArmorContents(null);
|
||||||
player.setGameMode(GameMode.CREATIVE);
|
player.setGameMode(GameMode.CREATIVE);
|
||||||
|
|
||||||
|
this.setVanish(player, true);
|
||||||
|
this.staffModeHotBar.applyToPlayer(player, true);
|
||||||
|
|
||||||
player.sendMessage(ColorUtils.getMessageType("&bYou've &aenabled &bstaff mode"));
|
player.sendMessage(ColorUtils.getMessageType("&bYou've &aenabled &bstaff mode"));
|
||||||
} else {
|
} else {
|
||||||
this.setVanish(player, false);
|
|
||||||
this.playersInStaffMode.remove(player.getUniqueId());
|
this.playersInStaffMode.remove(player.getUniqueId());
|
||||||
this.cachedInventories.get(player.getUniqueId()).applyToPlayer(player, false);
|
this.cachedInventories.get(player.getUniqueId()).applyToPlayer(player, false);
|
||||||
|
|
||||||
player.setGameMode(GameMode.SURVIVAL);
|
player.setGameMode(GameMode.SURVIVAL);
|
||||||
|
|
||||||
|
this.setVanish(player, false);
|
||||||
|
|
||||||
player.sendMessage(ColorUtils.getMessageType("&bYou've &cdisabled &bstaff mode"));
|
player.sendMessage(ColorUtils.getMessageType("&bYou've &cdisabled &bstaff mode"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,5 +4,5 @@ import org.bukkit.entity.Player;
|
|||||||
|
|
||||||
public interface ClickHandler {
|
public interface ClickHandler {
|
||||||
|
|
||||||
void click(Player player);
|
void executeAs(Player player);
|
||||||
}
|
}
|
||||||
|
@ -14,7 +14,7 @@ public abstract class HotBar {
|
|||||||
|
|
||||||
private EventCore main = EventCore.getInstance();
|
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;
|
private String id;
|
||||||
|
|
||||||
@ -23,27 +23,20 @@ public abstract class HotBar {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public ClickableItem getClickableItem(String id) {
|
public ClickableItem getClickableItem(String id) {
|
||||||
return this.cachedItems.get(id);
|
return this.clickableItems.get(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addClickableItem(String id, ClickableItem clickableItem) {
|
public void addClickableItem(String id, ClickableItem clickableItem) {
|
||||||
this.cachedItems.put(id, clickableItem);
|
this.clickableItems.put(id, clickableItem);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void removeClickableItem(String id) {
|
public void removeClickableItem(String id) {
|
||||||
this.cachedItems.remove(id);
|
this.clickableItems.remove(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void applyToPlayer(Player player, ClickableItem clickableItem, int slot) {
|
public void applyToPlayer(Player player, ClickableItem clickableItem, int slot) {
|
||||||
player.getInventory().setItem(slot, null);
|
player.getInventory().setItem(slot, null);
|
||||||
player.getInventory().setItem(slot, clickableItem.getItemStack());
|
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) {
|
public void applyToPlayer(Player player, boolean clearHotBar) {
|
||||||
@ -58,13 +51,6 @@ public abstract class HotBar {
|
|||||||
for (int slot : clickableItemsToApply.keySet()) {
|
for (int slot : clickableItemsToApply.keySet()) {
|
||||||
player.getInventory().setItem(slot, clickableItemsToApply.get(slot).getItemStack());
|
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);
|
public abstract Map<Integer, ClickableItem> getClickableItemsToApply(Player player);
|
||||||
|
@ -36,7 +36,7 @@ public class StaffModeHotBar extends HotBar {
|
|||||||
|
|
||||||
clickableItems.put(3, this.getClickableItem("better-looking"));
|
clickableItems.put(3, this.getClickableItem("better-looking"));
|
||||||
clickableItems.put(7, this.getClickableItem("staff-online"));
|
clickableItems.put(7, this.getClickableItem("staff-online"));
|
||||||
clickableItems.put(8, this.getClickableItem("vanish"));
|
clickableItems.put(8, this.getClickableItem("unvanish"));
|
||||||
|
|
||||||
return clickableItems;
|
return clickableItems;
|
||||||
}
|
}
|
||||||
@ -44,36 +44,36 @@ public class StaffModeHotBar extends HotBar {
|
|||||||
public void registerClickableItems() {
|
public void registerClickableItems() {
|
||||||
this.addClickableItem("teleport-compass", new ClickableItem(player -> {
|
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 -> {
|
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 -> {
|
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 -> {
|
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 -> {
|
this.addClickableItem("staff-online", new ClickableItem(player -> {
|
||||||
// To Do: Staff Online System
|
// 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.addClickableItem("vanish", new ClickableItem(player -> {
|
||||||
this.applyToPlayer(player, this.getClickableItem("unvanish"), 8);
|
this.applyToPlayer(player, this.getClickableItem("unvanish"), 8);
|
||||||
this.main.getStaffManager().setVanish(player, true);
|
this.main.getStaffManager().setVanish(player, true);
|
||||||
|
|
||||||
player.sendMessage(ColorUtils.getMessageType("&bYou've &aenabled &bvanish"));
|
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.addClickableItem("unvanish", new ClickableItem(player -> {
|
||||||
this.applyToPlayer(player, this.getClickableItem("vanish"), 8);
|
this.applyToPlayer(player, this.getClickableItem("vanish"), 8);
|
||||||
this.main.getStaffManager().setVanish(player, false);
|
this.main.getStaffManager().setVanish(player, false);
|
||||||
|
|
||||||
player.sendMessage(ColorUtils.getMessageType("&bYou've &cdisabled &bvanish"));
|
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));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -47,16 +47,12 @@ public class ChatManagementMenu extends Menu {
|
|||||||
case SOUL_SAND:
|
case SOUL_SAND:
|
||||||
if (event.getClick().isLeftClick()) {
|
if (event.getClick().isLeftClick()) {
|
||||||
this.delayAmount++;
|
this.delayAmount++;
|
||||||
|
|
||||||
new ChatManagementMenu(this.playerMenuUtil, this.delayAmount).open(player);
|
|
||||||
} else if (event.getClick().isRightClick()) {
|
} else if (event.getClick().isRightClick()) {
|
||||||
if (this.delayAmount <= 0) {
|
if (this.delayAmount <= 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.delayAmount--;
|
this.delayAmount--;
|
||||||
|
|
||||||
new ChatManagementMenu(this.playerMenuUtil, this.delayAmount).open(player);
|
|
||||||
} else if (event.getClick().isShiftClick()) {
|
} else if (event.getClick().isShiftClick()) {
|
||||||
this.main.getChatManager().slowChat(player, this.delayAmount);
|
this.main.getChatManager().slowChat(player, this.delayAmount);
|
||||||
}
|
}
|
||||||
@ -67,6 +63,8 @@ public class ChatManagementMenu extends Menu {
|
|||||||
|
|
||||||
break;
|
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()),
|
"&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())),
|
"&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",
|
"&fLeft Click: &b+1",
|
||||||
"&fRight Click: &b-1"
|
"&fRight Click: &b-1"
|
||||||
|
Loading…
Reference in New Issue
Block a user