From a2a5cd0e391524aab368ba6fe45f97f2cbd40a53 Mon Sep 17 00:00:00 2001 From: Voltstro Date: Sun, 2 Jun 2019 01:21:13 +1000 Subject: [PATCH] Re-organised the project, added sign break permission --- config.yml | 2 + plugin.yml | 2 +- .../hubmanager/HubSignListeners.java | 50 ----------- src/me/creepysin/hubmanager/Main.java | 11 ++- .../hubmanager/{ => cmds}/AllHubsCommand.java | 2 +- .../hubmanager/{ => cmds}/HubCommand.java | 7 +- .../{ => cmds}/HubManagerCommands.java | 4 +- .../hubmanager/{ => cmds}/SetHubCommand.java | 4 +- .../listeners/HubSignListeners.java | 85 +++++++++++++++++++ 9 files changed, 110 insertions(+), 57 deletions(-) delete mode 100644 src/me/creepysin/hubmanager/HubSignListeners.java rename src/me/creepysin/hubmanager/{ => cmds}/AllHubsCommand.java (96%) rename src/me/creepysin/hubmanager/{ => cmds}/HubCommand.java (87%) rename src/me/creepysin/hubmanager/{ => cmds}/HubManagerCommands.java (95%) rename src/me/creepysin/hubmanager/{ => cmds}/SetHubCommand.java (96%) create mode 100644 src/me/creepysin/hubmanager/listeners/HubSignListeners.java diff --git a/config.yml b/config.yml index 09e0b74..fd9366f 100644 --- a/config.yml +++ b/config.yml @@ -19,4 +19,6 @@ signs: - 'Click to be' - 'teleported.' + signHubColor: '§b' + # For you tp messages you can use '%name%' to say the hubs name and you can also use '%line%' for the next line. diff --git a/plugin.yml b/plugin.yml index b679dea..e370e9b 100644 --- a/plugin.yml +++ b/plugin.yml @@ -1,6 +1,6 @@ name: HubManager main: me.creepysin.hubmanager.Main -version: 1.2 +version: 1.3 api-version: 1.14 author: Creepysin website: https://github.com/Creepysin/HubManager diff --git a/src/me/creepysin/hubmanager/HubSignListeners.java b/src/me/creepysin/hubmanager/HubSignListeners.java deleted file mode 100644 index 4f53969..0000000 --- a/src/me/creepysin/hubmanager/HubSignListeners.java +++ /dev/null @@ -1,50 +0,0 @@ -package me.creepysin.hubmanager; - -import org.bukkit.block.Sign; -import org.bukkit.event.EventHandler; -import org.bukkit.event.Listener; -import org.bukkit.event.block.Action; -import org.bukkit.event.block.SignChangeEvent; -import org.bukkit.event.player.PlayerInteractEvent; - -public class HubSignListeners implements Listener { - - private Main plugin; - private HubTeleport hubTele; - - public HubSignListeners(Main _main, HubTeleport _hubtele) { - plugin = _main; - hubTele = _hubtele; - - plugin.getLogger().info("Added events."); - } - - @EventHandler - public void onSignChange(SignChangeEvent e) { - if(e.getLine(0).equalsIgnoreCase("[hub]")) { - - // Check to see if the player has the right permissions - if(!e.getPlayer().hasPermission("hubmanager.signs.create")) return; - - e.setLine(0, "[Hub]"); - - for (int i = 0; i < 2; i++ ) { - e.setLine(i + 2, plugin.getConfig().getList("signs.messages").get(i).toString()); - } - } - } - - @EventHandler - public void onPlayerInteract(PlayerInteractEvent e) { - if(!(e.getAction() == Action.RIGHT_CLICK_BLOCK)) return; - - if(e.getClickedBlock().getState() instanceof Sign) { - Sign sign = (Sign) e.getClickedBlock().getState(); - - if(sign.getLine(0).equalsIgnoreCase("[hub]")) { - hubTele.TeleportPlayer(e.getPlayer(), sign.getLine(1)); - } - } - } - -} diff --git a/src/me/creepysin/hubmanager/Main.java b/src/me/creepysin/hubmanager/Main.java index 9a4fbaa..da73e9f 100644 --- a/src/me/creepysin/hubmanager/Main.java +++ b/src/me/creepysin/hubmanager/Main.java @@ -2,12 +2,19 @@ import java.util.List; +import org.bukkit.ChatColor; import org.bukkit.command.CommandSender; import org.bukkit.craftbukkit.v1_14_R1.CraftServer; import org.bukkit.permissions.Permission; import org.bukkit.plugin.PluginManager; import org.bukkit.plugin.java.JavaPlugin; +import me.creepysin.hubmanager.cmds.AllHubsCommand; +import me.creepysin.hubmanager.cmds.HubCommand; +import me.creepysin.hubmanager.cmds.HubManagerCommands; +import me.creepysin.hubmanager.cmds.SetHubCommand; +import me.creepysin.hubmanager.listeners.HubSignListeners; + public class Main extends JavaPlugin { public List baseCommands; @@ -23,12 +30,14 @@ public void onEnable() { Permission reloadPerm = new Permission("hubmanager.reload"); Permission signsCreatePerm = new Permission("hubmanager.signs.create"); Permission signsInteractPerm = new Permission("hubmanager.signs.interact"); + Permission signsBreakPerm = new Permission("hubmanager.signs.break"); PluginManager pm = getServer().getPluginManager(); pm.addPermission(sethubPerm); pm.addPermission(reloadPerm); pm.addPermission(signsCreatePerm); pm.addPermission(signsInteractPerm); + pm.addPermission(signsBreakPerm); // Add commands getCommand("sethub").setExecutor(new SetHubCommand(this)); @@ -39,7 +48,7 @@ public void onEnable() { getServer().getPluginManager().registerEvents(new HubSignListeners(this, hubTele), this); } - getLogger().info("HubManger has been loaded!"); + getLogger().info(ChatColor.GREEN + "HubManager is now enabled!"); } diff --git a/src/me/creepysin/hubmanager/AllHubsCommand.java b/src/me/creepysin/hubmanager/cmds/AllHubsCommand.java similarity index 96% rename from src/me/creepysin/hubmanager/AllHubsCommand.java rename to src/me/creepysin/hubmanager/cmds/AllHubsCommand.java index 03dee47..2ea461f 100644 --- a/src/me/creepysin/hubmanager/AllHubsCommand.java +++ b/src/me/creepysin/hubmanager/cmds/AllHubsCommand.java @@ -1,4 +1,4 @@ -package me.creepysin.hubmanager; +package me.creepysin.hubmanager.cmds; import java.util.List; diff --git a/src/me/creepysin/hubmanager/HubCommand.java b/src/me/creepysin/hubmanager/cmds/HubCommand.java similarity index 87% rename from src/me/creepysin/hubmanager/HubCommand.java rename to src/me/creepysin/hubmanager/cmds/HubCommand.java index 05335e4..dbf3d66 100644 --- a/src/me/creepysin/hubmanager/HubCommand.java +++ b/src/me/creepysin/hubmanager/cmds/HubCommand.java @@ -1,7 +1,10 @@ -package me.creepysin.hubmanager; +package me.creepysin.hubmanager.cmds; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; + +import me.creepysin.hubmanager.HubTeleport; + import org.bukkit.command.defaults.BukkitCommand; import org.bukkit.ChatColor; @@ -10,7 +13,7 @@ public class HubCommand extends BukkitCommand { private String hubCmd; private HubTeleport hubTeleport; - protected HubCommand(String name, HubTeleport _hubTele) { + public HubCommand(String name, HubTeleport _hubTele) { super(name); this.description = "Goes to a hub"; this.usageMessage = "/"; diff --git a/src/me/creepysin/hubmanager/HubManagerCommands.java b/src/me/creepysin/hubmanager/cmds/HubManagerCommands.java similarity index 95% rename from src/me/creepysin/hubmanager/HubManagerCommands.java rename to src/me/creepysin/hubmanager/cmds/HubManagerCommands.java index a1bef88..577c037 100644 --- a/src/me/creepysin/hubmanager/HubManagerCommands.java +++ b/src/me/creepysin/hubmanager/cmds/HubManagerCommands.java @@ -1,4 +1,4 @@ -package me.creepysin.hubmanager; +package me.creepysin.hubmanager.cmds; import java.util.ArrayList; import java.util.List; @@ -9,6 +9,8 @@ import org.bukkit.command.TabCompleter; import org.bukkit.entity.Player; +import me.creepysin.hubmanager.Main; + public class HubManagerCommands implements CommandExecutor, TabCompleter { private Main plugin; diff --git a/src/me/creepysin/hubmanager/SetHubCommand.java b/src/me/creepysin/hubmanager/cmds/SetHubCommand.java similarity index 96% rename from src/me/creepysin/hubmanager/SetHubCommand.java rename to src/me/creepysin/hubmanager/cmds/SetHubCommand.java index eb68ee7..c09b76f 100644 --- a/src/me/creepysin/hubmanager/SetHubCommand.java +++ b/src/me/creepysin/hubmanager/cmds/SetHubCommand.java @@ -1,4 +1,4 @@ -package me.creepysin.hubmanager; +package me.creepysin.hubmanager.cmds; import java.util.ArrayList; import java.util.List; @@ -10,6 +10,8 @@ import org.bukkit.command.TabCompleter; import org.bukkit.entity.Player; +import me.creepysin.hubmanager.Main; + public class SetHubCommand implements CommandExecutor, TabCompleter { private Main plugin; diff --git a/src/me/creepysin/hubmanager/listeners/HubSignListeners.java b/src/me/creepysin/hubmanager/listeners/HubSignListeners.java new file mode 100644 index 0000000..6ebacf3 --- /dev/null +++ b/src/me/creepysin/hubmanager/listeners/HubSignListeners.java @@ -0,0 +1,85 @@ +package me.creepysin.hubmanager.listeners; + +import org.bukkit.ChatColor; +import org.bukkit.block.Sign; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.block.Action; +import org.bukkit.event.block.BlockBreakEvent; +import org.bukkit.event.block.SignChangeEvent; +import org.bukkit.event.player.PlayerInteractEvent; + +import me.creepysin.hubmanager.HubTeleport; +import me.creepysin.hubmanager.Main; + +public class HubSignListeners implements Listener { + + private Main plugin; + private HubTeleport hubTele; + + public HubSignListeners(Main _main, HubTeleport _hubtele) { + plugin = _main; + hubTele = _hubtele; + + plugin.getLogger().info("Added events."); + } + + @EventHandler + public void onBlockBreak(BlockBreakEvent e) { + // Check to see if it is a hub sign, and if it is then check to see if the player has the right permissions + if(e.getBlock().getState() instanceof Sign) { + Sign sign = (Sign) e.getBlock().getState(); + + if(sign.getLine(0).equalsIgnoreCase("[hub]")) { + if(!e.getPlayer().hasPermission("hubmanager.signs.break")) { + e.setCancelled(true); + e.getPlayer().sendMessage(ChatColor.RED + "You do not have permission to break hub signs!"); + } + } + } + } + + @EventHandler + public void onSignChange(SignChangeEvent e) { + if(e.getLine(0).equalsIgnoreCase("[hub]")) { + + // Check to see if the player has the right permissions + if(!e.getPlayer().hasPermission("hubmanager.signs.create")) { + e.setLine(0, "[§4Hub§0]"); + e.setLine(1, ""); + + e.getPlayer().sendMessage(ChatColor.RED + "You do not have permission to create hub signs!"); + return; + } + + e.setLine(0, "[Hub]"); + + e.setLine(1, plugin.getConfig().getString("signs.signHubColor") + e.getLine(1)); + + for (int i = 0; i < 2; i++ ) { + e.setLine(i + 2, plugin.getConfig().getList("signs.messages").get(i).toString()); + } + } + } + + @EventHandler + public void onPlayerInteract(PlayerInteractEvent e) { + if(!(e.getAction() == Action.RIGHT_CLICK_BLOCK)) return; + + if(e.getClickedBlock().getState() instanceof Sign) { + Sign sign = (Sign) e.getClickedBlock().getState(); + + if(!e.getPlayer().hasPermission("hubmanager.signs.interact")) { + if(!sign.getLine(0).equalsIgnoreCase("[hub]")) return; + + e.getPlayer().sendMessage(ChatColor.RED + "You do not have permission to interact with hub signs!"); + return; + } + + if(sign.getLine(0).equalsIgnoreCase("[hub]")) { + hubTele.TeleportPlayer(e.getPlayer(), sign.getLine(1).substring(2)); + } + } + } + +}