From bc6074436c7b1b90ad61d001b104d5af75d3e50f Mon Sep 17 00:00:00 2001 From: Simon Date: Thu, 7 May 2020 16:42:40 +0200 Subject: [PATCH] feat: don't allow players to create a portal --- .../main/java/de/cliffbreak/varo/Varo.java | 4 ++ .../cliffbreak/varo/commands/VaroCommand.java | 12 ++++++ .../varo/listeners/BannedActionListener.java | 37 +++++++++++++++++++ 3 files changed, 53 insertions(+) create mode 100644 varo/src/main/java/de/cliffbreak/varo/listeners/BannedActionListener.java diff --git a/varo/src/main/java/de/cliffbreak/varo/Varo.java b/varo/src/main/java/de/cliffbreak/varo/Varo.java index 42d835d..8f0d670 100644 --- a/varo/src/main/java/de/cliffbreak/varo/Varo.java +++ b/varo/src/main/java/de/cliffbreak/varo/Varo.java @@ -14,6 +14,7 @@ import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.configuration.file.YamlConfiguration; import de.cliffbreak.varo.commands.VaroCommand; +import de.cliffbreak.varo.listeners.BannedActionListener; import de.cliffbreak.varo.listeners.BannedItemListener; import de.cliffbreak.varo.listeners.ChatListener; import de.cliffbreak.varo.listeners.CreatureSpawnListener; @@ -35,6 +36,8 @@ public class Varo extends JavaPlugin { public PlayerCache playerCache; public BanUtils banUtils; + public boolean canCreatePortal = false; + @Override public void onEnable() { @@ -57,6 +60,7 @@ public class Varo extends JavaPlugin { getServer().getPluginManager().registerEvents(new EntityRegainHealthListener(), this); getServer().getPluginManager().registerEvents(new PlayerDeathListener(this), this); getServer().getPluginManager().registerEvents(new BannedItemListener(), this); + getServer().getPluginManager().registerEvents(new BannedActionListener(this), this); getServer().getPluginManager().registerEvents(new CreatureSpawnListener(this), this); getServer().getPluginManager().registerEvents(new PlayerInteractNPCListener(this), this); diff --git a/varo/src/main/java/de/cliffbreak/varo/commands/VaroCommand.java b/varo/src/main/java/de/cliffbreak/varo/commands/VaroCommand.java index bcd958e..80308b8 100644 --- a/varo/src/main/java/de/cliffbreak/varo/commands/VaroCommand.java +++ b/varo/src/main/java/de/cliffbreak/varo/commands/VaroCommand.java @@ -77,6 +77,17 @@ public class VaroCommand implements CommandExecutor { sender.sendMessage(MessageUtils.getRichTextComponent("§9" + "Team 08", "")); sender.sendMessage(MessageUtils.getRichTextComponent("§d" + "Team 09", "")); sender.sendMessage(MessageUtils.getRichTextComponent("§5" + "Team 10", "")); + + } else if (args.length == 2 && args[0].equals("portal")) { + if (args[1].equals("enable")) { + this.plugin.canCreatePortal = true; + sender.sendMessage("§c§lWarnung: §r§cPortale können nun von JEDEM Spieler erstellt werden."); + } else if (args[1].equals("disable")) { + this.plugin.canCreatePortal = false; + sender.sendMessage("§a§lErfolg: §r§aEs können nun keine Portale mehr erstellt werden.."); + } else { + sender.sendMessage("§c§lFehler: §r§cBitte überprüfe deine Eingabe."); + } } else if (args.length == 1 && args[0].equals("test")) { if (sender instanceof Player) { plugin.npcManager.createClone((Player) sender, false); @@ -93,6 +104,7 @@ public class VaroCommand implements CommandExecutor { sender.sendMessage("\n§6========== §b§lCliffbreak.de VARO §r§6============\n "); sender.sendMessage("§a/varo start: §rStarte das Varo Projekt!"); sender.sendMessage("§a/varo unban [Spieler]: §rSpieler wieder auf den Server lassen"); + sender.sendMessage("§a/varo portal [enable|disable]: §rAktiviere/Deaktiviere die Portal-Erstellung"); sender.sendMessage("§a/varo teamcolors: §rZeige verfügbare Team-Farben an"); sender.sendMessage("§a/varo test: §rErstelle einen Klon"); sender.sendMessage("§a/varo testremove: §rLösche den Klon"); diff --git a/varo/src/main/java/de/cliffbreak/varo/listeners/BannedActionListener.java b/varo/src/main/java/de/cliffbreak/varo/listeners/BannedActionListener.java new file mode 100644 index 0000000..a27c06f --- /dev/null +++ b/varo/src/main/java/de/cliffbreak/varo/listeners/BannedActionListener.java @@ -0,0 +1,37 @@ +package de.cliffbreak.varo.listeners; + +import org.bukkit.Material; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.block.Action; +import org.bukkit.event.player.PlayerInteractEvent; +import org.bukkit.event.world.PortalCreateEvent; + +import de.cliffbreak.varo.Varo; + +public class BannedActionListener implements Listener { + + private final Varo plugin; + + public BannedActionListener(Varo plugin) { + this.plugin = plugin; + } + + @EventHandler + public void onPortalCreate(final PortalCreateEvent e) { + if (!this.plugin.canCreatePortal) { + e.setCancelled(true); + } + } + + @EventHandler + public void onPlayerInteract(final PlayerInteractEvent e) { + if (e.getAction().equals(Action.RIGHT_CLICK_BLOCK)) { + if (e.getClickedBlock().getType().equals(Material.OBSIDIAN)) { + e.getPlayer() + .sendMessage("§cEin Nether-Portal kann nicht erzeugt werden.\n §rGehe hierzu in die Mitte."); + } + } + } + +} \ No newline at end of file