diff --git a/src/main/java/de/fanta/challenges/commands/CommandRegistration.java b/src/main/java/de/fanta/challenges/commands/CommandRegistration.java index 2a7531d..f6e7c47 100644 --- a/src/main/java/de/fanta/challenges/commands/CommandRegistration.java +++ b/src/main/java/de/fanta/challenges/commands/CommandRegistration.java @@ -8,6 +8,7 @@ import de.fanta.challenges.commands.challenges.ChallengesPingCommand; import de.fanta.challenges.commands.challenges.ChallengesSaveCommand; import de.fanta.challenges.commands.challenges.ChallengesSpeedCommand; +import de.fanta.challenges.commands.challenges.TeleportCommand; import de.fanta.challenges.commands.coords.CoordsCommand; import de.fanta.challenges.commands.coords.CoordsDeleteCommand; import de.fanta.challenges.commands.coords.CoordsGetCommand; @@ -50,6 +51,7 @@ challengesRouter.addCommandMapping(new ChallengesPingCommand(), "ping"); challengesRouter.addCommandMapping(new ChallengesMemoryCommand(), "mem"); challengesRouter.addCommandMapping(new ChallengesSpeedCommand(), "speed"); + challengesRouter.addCommandMapping(new TeleportCommand(plugin), "tp"); CommandRouter resetRouter = new CommandRouter(plugin.getCommand("reset")); resetRouter.addCommandMapping(new ResetCommand(plugin)); diff --git a/src/main/java/de/fanta/challenges/commands/challenges/TeleportCommand.java b/src/main/java/de/fanta/challenges/commands/challenges/TeleportCommand.java new file mode 100644 index 0000000..8e3a3b3 --- /dev/null +++ b/src/main/java/de/fanta/challenges/commands/challenges/TeleportCommand.java @@ -0,0 +1,35 @@ +package de.fanta.challenges.commands.challenges; + +import de.fanta.challenges.Challenges; +import de.fanta.challenges.guis.TeleportGUI; +import de.fanta.challenges.utils.ChatUtil; +import de.iani.cubesideutils.bukkit.commands.SubCommand; +import de.iani.cubesideutils.commands.ArgsParser; +import org.bukkit.command.Command; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +public class TeleportCommand extends SubCommand { + + private final Challenges plugin; + + public TeleportCommand(Challenges plugin) { + this.plugin = plugin; + } + + @Override + public boolean onCommand(CommandSender sender, Command command, String alias, String commandString, ArgsParser args) { + if (!(sender instanceof Player player)) { + ChatUtil.sendErrorMessage(sender, "You are not a Player :>"); + return true; + } + + if (plugin.getConfig().getBoolean("teleportcommand") || player.hasPermission("Challenges.editor.override")) { + TeleportGUI.buildTeleportInventory(player); + } else { + ChatUtil.sendWarningMessage(player, "Teleport deaktiviert!"); + } + + return true; + } +} diff --git a/src/main/java/de/fanta/challenges/guis/TeleportGUI.java b/src/main/java/de/fanta/challenges/guis/TeleportGUI.java new file mode 100644 index 0000000..a0879f2 --- /dev/null +++ b/src/main/java/de/fanta/challenges/guis/TeleportGUI.java @@ -0,0 +1,95 @@ +package de.fanta.challenges.guis; + +import de.fanta.challenges.Challenges; +import de.fanta.challenges.utils.ChatUtil; +import de.fanta.challenges.utils.guiutils.GUIUtils; +import org.bukkit.Bukkit; +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.inventory.InventoryClickEvent; +import org.bukkit.inventory.Inventory; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.SkullMeta; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Map; + +public class TeleportGUI implements Listener { + + public static final int INVENTORY_SIZE = 27; + private static final Challenges plugin = Challenges.getPlugin(); + private static final Map playerPerSlot = new HashMap<>(); + private static final Map InventoryperPlayer = new HashMap<>(); + private static int CLOSE_IDEX = 0; + + public static void buildTeleportInventory(Player p) { + Inventory TELEPORT_UI = Bukkit.createInventory(p, 9 * (plugin.getVanish().getPlayerListWithoutVanishPlayers().size() / 7 + ((plugin.getVanish().getPlayerListWithoutVanishPlayers().size() % 7 > 0) ? 1 : 0)) + 18, plugin.getGUIPREFIX() + " >> Teleport to..."); + InventoryperPlayer.put(p, TELEPORT_UI); + CLOSE_IDEX = TELEPORT_UI.getSize() - 9; + int row = 0; + int cat = 0; + + if (plugin.getVanish().getPlayerListWithoutVanishPlayers().isEmpty()) { + ChatUtil.sendErrorMessage(p, "Keine Spieler Online"); + return; + } + for (Player pp : plugin.getVanish().getPlayerListWithoutVanishPlayers()) { + int slot = row * 9 + cat + 10; + + ArrayList metalore = new ArrayList<>(); + + ItemStack stack = new ItemStack(Material.PLAYER_HEAD); + SkullMeta skullMeta = (SkullMeta) stack.getItemMeta(); + skullMeta.setPlayerProfile(pp.getPlayerProfile()); + skullMeta.setDisplayName(ChatUtil.BLUE + pp.getName()); + metalore.add(ChatUtil.GREEN + "Linksklick: " + p.getName() + " -> " + pp.getName()); + metalore.add(ChatUtil.GREEN + "Rechtsklick: " + pp.getName() + " -> " + p.getName()); + skullMeta.setLore(metalore); + stack.setItemMeta(skullMeta); + TELEPORT_UI.setItem(slot, stack); + playerPerSlot.put(slot, pp); + if (cat < 6) { + cat++; + continue; + } + row++; + cat = 0; + } + + TELEPORT_UI.setItem(CLOSE_IDEX, GUIUtils.createGuiItem(Material.BARRIER, ChatUtil.RED + "Menü verlassen!")); + for (int i = 0; i < INVENTORY_SIZE; i++) { + if (TELEPORT_UI.getItem(i) == null || TELEPORT_UI.getItem(i).getType() == Material.AIR) { + TELEPORT_UI.setItem(i, GUIUtils.EMPTY_ICON); + } + } + p.openInventory(TELEPORT_UI); + } + + @EventHandler + public void onInventoryClick(InventoryClickEvent e) { + int slot = e.getRawSlot(); + Player p = (Player) e.getWhoClicked(); + Player pp = playerPerSlot.get(slot); + if (e.getInventory() == InventoryperPlayer.get(p)) { + if (pp != null && pp.isOnline()) { + if (e.isLeftClick()) { + p.teleport(pp.getLocation()); + ChatUtil.sendNormalMessage(p, "Du wurdest zu " + pp.getName() + " teleportiert!"); + } else if (e.isRightClick()) { + pp.teleport(p.getLocation()); + ChatUtil.sendNormalMessage(p, pp.getName() + " wurde zu dir teleportiert!"); + } + p.closeInventory(); + } + + if (slot == CLOSE_IDEX) { + p.closeInventory(); + } + e.setCancelled(true); + } + } +} + diff --git a/src/main/java/de/fanta/challenges/guis/settingsgui/OtherSettingsGui.java b/src/main/java/de/fanta/challenges/guis/settingsgui/OtherSettingsGui.java index 52a2829..00bb145 100644 --- a/src/main/java/de/fanta/challenges/guis/settingsgui/OtherSettingsGui.java +++ b/src/main/java/de/fanta/challenges/guis/settingsgui/OtherSettingsGui.java @@ -14,22 +14,19 @@ public class OtherSettingsGui implements Listener { - private static final Challenges plugin = Challenges.getPlugin(); - public static final int INVENTORY_SIZE = 27; + private static final Challenges plugin = Challenges.getPlugin(); + public static final Inventory OTHER_SETTINGS_GUI = Bukkit.createInventory(null, INVENTORY_SIZE, plugin.getGUIPREFIX() + " >> Other Settings"); private static final int BACK_INDEX = 18; private static final int BACKPACK_INDEX = 10; private static final int DMG_INCHAT_INDEX = 11; - private static final int TNT_DEATH_INDEX = 12; + private static final int TELEPORT_COMMAND_INDEX = 12; private static final int TAB_HP_INDEX = 13; private static final int DIREKT_SMLET_INDEX = 14; private static final int FAST_FURNACE_INDEX = 15; private static final int DISABLE_VILLAGER_TRADE_LIMITS_INDEX = 16; private static final int BACKPACK_ADD_INDEX = 1; private static final int BACKPACK_REMOVE_INDEX = 19; - - public static final Inventory OTHER_SETTINGS_GUI = Bukkit.createInventory(null, INVENTORY_SIZE, plugin.getGUIPREFIX() + " >> Other Settings"); - private static final int CLOSE_IDEX = 26; public static void createOtherSettingsGUI(Player p) { @@ -49,14 +46,11 @@ } else { OTHER_SETTINGS_GUI.setItem(DMG_INCHAT_INDEX, GUIUtils.createGuiItem(Material.PAPER, ChatUtil.RED + "Schaden im Chat anzeigen deaktiviert")); } - if (p.hasPermission("challenges.event")) { - if (plugin.getConfig().getBoolean("tntdeath")) { - OTHER_SETTINGS_GUI.setItem(TNT_DEATH_INDEX, GUIUtils.createGuiItem(Material.TNT, ChatUtil.GREEN + "Sterben durch TNT aktiviert", true, ChatUtil.GREEN + "Tötet dich mit TNT bei der \"nicht springen, schleichen und jumpen\" Challenge")); - } else { - OTHER_SETTINGS_GUI.setItem(TNT_DEATH_INDEX, GUIUtils.createGuiItem(Material.TNT, ChatUtil.RED + "Sterben durch TNT deaktiviert", ChatUtil.RED + "Tötet dich mit TNT bei der \"nicht springen, schleichen und jumpen\" Challenge")); - } + + if (plugin.getConfig().getBoolean("teleportcommand")) { + OTHER_SETTINGS_GUI.setItem(TELEPORT_COMMAND_INDEX, GUIUtils.createGuiItem(Material.ENDER_PEARL, ChatUtil.GREEN + "Teleport Command aktiviert", true, ChatUtil.GREEN + "Deaktiviert den \"/challenges tp\" command")); } else { - OTHER_SETTINGS_GUI.setItem(TNT_DEATH_INDEX, GUIUtils.EMPTY_ICON); + OTHER_SETTINGS_GUI.setItem(TELEPORT_COMMAND_INDEX, GUIUtils.createGuiItem(Material.ENDER_PEARL, ChatUtil.RED + "Teleport Command deaktiviert", ChatUtil.RED + "Aktiviert den \"/challenges tp\" command")); } if (plugin.getConfig().getBoolean("tabhp")) { OTHER_SETTINGS_GUI.setItem(TAB_HP_INDEX, GUIUtils.createGuiItem(Material.HEART_OF_THE_SEA, ChatUtil.GREEN + "Herzen in der Tablist anzeigen aktiviert", true)); @@ -115,15 +109,13 @@ GUIUtils.setConfig("dmginchat", true); } break; - case TNT_DEATH_INDEX: - if (e.getCurrentItem() != null && e.getCurrentItem().getType() == Material.TNT) { - if (plugin.getConfig().getBoolean("tntdeath")) { - GUIUtils.sendTitleToAll("Einstellungen", "Sterben durch TNT deaktiviert", ChatUtil.RED); - GUIUtils.setConfig("tntdeath", false); - } else { - GUIUtils.sendTitleToAll("Einstellungen", "Sterben durch TNT aktiviert", ChatUtil.GREEN); - GUIUtils.setConfig("tntdeath", true); - } + case TELEPORT_COMMAND_INDEX: + if (plugin.getConfig().getBoolean("teleportcommand")) { + GUIUtils.sendTitleToAll("Einstellungen", "Teleport Command deaktiviert", ChatUtil.RED); + GUIUtils.setConfig("teleportcommand", false); + } else { + GUIUtils.sendTitleToAll("Einstellungen", "Teleport Command aktiviert", ChatUtil.GREEN); + GUIUtils.setConfig("teleportcommand", true); } break; case TAB_HP_INDEX: diff --git a/src/main/java/de/fanta/challenges/listeners/EventRegistration.java b/src/main/java/de/fanta/challenges/listeners/EventRegistration.java index 2e2dbf0..bbb5291 100644 --- a/src/main/java/de/fanta/challenges/listeners/EventRegistration.java +++ b/src/main/java/de/fanta/challenges/listeners/EventRegistration.java @@ -3,6 +3,7 @@ import de.fanta.challenges.Challenges; import de.fanta.challenges.challenges.*; import de.fanta.challenges.guis.ResetGui; +import de.fanta.challenges.guis.TeleportGUI; import de.fanta.challenges.guis.TimerGui; import de.fanta.challenges.guis.eventgui.EventGui; import de.fanta.challenges.guis.eventgui.SammelFieberSettingsGui; @@ -37,6 +38,7 @@ pM.registerEvents(new EventGui(), plugin); pM.registerEvents(new FurnaceListener(), plugin); pM.registerEvents(new CommandBlockListener(), plugin); + pM.registerEvents(new TeleportGUI(), plugin); pM.registerEvents(new ChallengeGoals(), plugin); diff --git a/src/main/java/de/fanta/challenges/utils/VanishUtils.java b/src/main/java/de/fanta/challenges/utils/VanishUtils.java index e1f447f..0b79ccc 100644 --- a/src/main/java/de/fanta/challenges/utils/VanishUtils.java +++ b/src/main/java/de/fanta/challenges/utils/VanishUtils.java @@ -1,6 +1,7 @@ package de.fanta.challenges.utils; import de.fanta.challenges.Challenges; +import org.bukkit.Bukkit; import org.bukkit.entity.Player; import org.kitteh.vanish.VanishPlugin; @@ -27,4 +28,14 @@ return new ArrayList<>(vanish.getManager().getVanishedPlayers()); } + public List getPlayerListWithoutVanishPlayers() { + List playerlistwithoutvanishplayer = new ArrayList<>(); + for (Player player : Bukkit.getOnlinePlayers()) { + if (!isVanish(player)) { + playerlistwithoutvanishplayer.add(player); + } + } + return playerlistwithoutvanishplayer; + } + } diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index a06d06e..ab45e79 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -27,6 +27,7 @@ worldborderlevellevel: 0 worldborderlevelxp: 0 disablevillagertradelimits: false +teleportcommand: false #Mögliche werte: 1-6 backpack_size: 3 mlg: