From 160d1e4cc3f07058e1c7748535815f9f959cfb88 Mon Sep 17 00:00:00 2001 From: Alastair Hawkes Date: Thu, 20 Apr 2017 03:31:25 +0100 Subject: [PATCH] Updated plugin organisation and disabled console portals by default --- Resources/config.yml | 14 +++++ Resources/plugin.yml | 12 ++++ .../AdvancedPortalsCommand.java | 14 +++++ .../AdvancedPortalsPlugin.java | 55 ++++++++++++------- src/com/sekwah/advancedportals/Assets.java | 15 ----- src/com/sekwah/advancedportals/Settings.java | 40 ++++++++++++++ .../advancedportals/effects/WarpEffects.java | 12 ++-- .../advancedportals/portals/Portal.java | 4 +- 8 files changed, 123 insertions(+), 43 deletions(-) delete mode 100644 src/com/sekwah/advancedportals/Assets.java create mode 100644 src/com/sekwah/advancedportals/Settings.java diff --git a/Resources/config.yml b/Resources/config.yml index 4ca88cb..99af443 100644 --- a/Resources/config.yml +++ b/Resources/config.yml @@ -72,3 +72,17 @@ CustomPrefixFail: '&c[&7AdvancedPortals&c]' PortalCooldown: 5 # How long after trying to enter a portal until the player can try to enter another. 0 or lower to deactivate. ThrowbackAmount: 0.7 # How fast to throw them back, 0 or lower to disable throwback + +# Letters are flags. Include them to activate. n always disables everything, remove if you want it to work. +# Lettering may not make too much sense but meh its useful. Examples are "ocpk" or "cop" (doesnt matter order) +# +# Remember enabling this means potentially admins could leave a portal lying around which could let them reop themselves. +# If you think this may be an issue use a permission plugin and specifically give the users you trust permissions. +# +# n Disabled (none +# o Admin Heighten Enabled Permission advancedportals.createportal.commandlevel.op +# c Console Heighten Enabled Permission advancedportals.createportal.commandlevel.console +# p Ops can create admin commands without special perms +# k Ops can create console commands without special perms +# +CommandLevels: n diff --git a/Resources/plugin.yml b/Resources/plugin.yml index 4646dd9..3708650 100644 --- a/Resources/plugin.yml +++ b/Resources/plugin.yml @@ -24,6 +24,18 @@ permissions: advancedportals.createportal: description: Allows you to create portals default: op + advancedportals.createportal.commandlevel.*: + description: Gives access to all level raisers + default: false + children: + advancedportals.createportal.commandlevel.op: true + advancedportals.createportal.commandlevel.console: true + advancedportals.createportal.commandlevel.op: + description: Allows you to increase the users level temporaily to op + default: false + advancedportals.createportal.commandlevel.console: + description: Executes command in the console + default: false advancedportals.portal: description: Allows use of portal commands default: op diff --git a/src/com/sekwah/advancedportals/AdvancedPortalsCommand.java b/src/com/sekwah/advancedportals/AdvancedPortalsCommand.java index 241d144..dca8a6e 100644 --- a/src/com/sekwah/advancedportals/AdvancedPortalsCommand.java +++ b/src/com/sekwah/advancedportals/AdvancedPortalsCommand.java @@ -126,6 +126,20 @@ public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter { executesCommand = true; portalCommand = parseArgVariable(args, i, "command:"); i += this.portalArgsStringLength - 1; + if(!( portalCommand.startsWith("#") + && this.plugin.getSettings().hasCommandLevel("c") + && (sender.hasPermission("advancedportals.createportal.commandlevel.console") + || (this.plugin.getSettings().hasCommandLevel("k") && sender.isOp()) ) )){ + player.sendMessage(PluginMessages.customPrefixFail + " You need permission to make a console command portal!"); + return true; + } + else if(!( portalCommand.startsWith("!") + && this.plugin.getSettings().hasCommandLevel("o") + && (sender.hasPermission("advancedportals.createportal.commandlevel.op") + || (this.plugin.getSettings().hasCommandLevel("p") && sender.isOp()) ) )){ + player.sendMessage(PluginMessages.customPrefixFail + " You need permission to make a op command portal!"); + return true; + } extraData.add(new PortalArg("command.1", portalCommand)); } } diff --git a/src/com/sekwah/advancedportals/AdvancedPortalsPlugin.java b/src/com/sekwah/advancedportals/AdvancedPortalsPlugin.java index ce88875..45fe46e 100644 --- a/src/com/sekwah/advancedportals/AdvancedPortalsPlugin.java +++ b/src/com/sekwah/advancedportals/AdvancedPortalsPlugin.java @@ -14,6 +14,7 @@ import java.io.IOException; public class AdvancedPortalsPlugin extends JavaPlugin { public CraftBukkit compat = null; + private Settings settings; public void onEnable() { @@ -38,10 +39,7 @@ public class AdvancedPortalsPlugin extends JavaPlugin { ConfigAccessor destinationConfig = new ConfigAccessor(this, "destinations.yml"); destinationConfig.saveDefaultConfig(); - new Assets(this); - - // Opens a channel that messages bungeeCord - this.getServer().getMessenger().registerOutgoingPluginChannel(this, "BungeeCord"); + this.settings = new Settings(this); // Loads the portal and destination editors new Portal(this); @@ -50,27 +48,14 @@ public class AdvancedPortalsPlugin extends JavaPlugin { new DataCollector(this); - // These register the commands - new PluginMessages(this); - new AdvancedPortalsCommand(this); - new DestinationCommand(this); + this.registerCommands(); new WarpEffects(this); + this.addListeners(); + this.setupDataCollector(); - // These register the listeners - new Listeners(this); - - new FlowStopper(this); - new PortalProtect(this); - new PortalPlacer(this); - - Selection.LoadData(this); - - DataCollector.setupMetrics(); - - this.getServer().getMessenger().registerOutgoingPluginChannel(this, "BungeeCord"); - this.getServer().getMessenger().registerIncomingPluginChannel(this, "BungeeCord", new BungeeListener(this)); + this.setupBungee(); this.getServer().getConsoleSender().sendMessage("\u00A7aAdvanced portals have been successfully enabled!"); @@ -92,10 +77,38 @@ public class AdvancedPortalsPlugin extends JavaPlugin { // only copy the file if it doesnt exist! } + private void registerCommands() { + new PluginMessages(this); + new AdvancedPortalsCommand(this); + new DestinationCommand(this); + } + + private void addListeners() { + new Listeners(this); + + new FlowStopper(this); + new PortalProtect(this); + new PortalPlacer(this); + } + + private void setupDataCollector() { + Selection.LoadData(this); + + DataCollector.setupMetrics(); + } + + private void setupBungee() { + this.getServer().getMessenger().registerOutgoingPluginChannel(this, "BungeeCord"); + this.getServer().getMessenger().registerIncomingPluginChannel(this, "BungeeCord", new BungeeListener(this)); + } + public void onDisable() { this.getServer().getConsoleSender().sendMessage("\u00A7cAdvanced portals are being disabled!"); } + public Settings getSettings() { + return settings; + } } diff --git a/src/com/sekwah/advancedportals/Assets.java b/src/com/sekwah/advancedportals/Assets.java deleted file mode 100644 index 2a40abc..0000000 --- a/src/com/sekwah/advancedportals/Assets.java +++ /dev/null @@ -1,15 +0,0 @@ -package com.sekwah.advancedportals; - -public class Assets { - - public static int currentWarpParticles = 0; - - public static int currentWarpSound = 0; - - public Assets(AdvancedPortalsPlugin plugin) { - ConfigAccessor config = new ConfigAccessor(plugin, "config.yml"); - currentWarpParticles = config.getConfig().getInt("WarpParticles"); - currentWarpSound = config.getConfig().getInt("WarpSound"); - } - -} diff --git a/src/com/sekwah/advancedportals/Settings.java b/src/com/sekwah/advancedportals/Settings.java new file mode 100644 index 0000000..8e82f99 --- /dev/null +++ b/src/com/sekwah/advancedportals/Settings.java @@ -0,0 +1,40 @@ +package com.sekwah.advancedportals; + +/** + * This contains generally used settings mostly + */ +public class Settings { + + private int currentWarpParticles = 0; + + private int currentWarpSound = 0; + + private String commandLevels = "n"; + + public Settings(AdvancedPortalsPlugin plugin) { + ConfigAccessor config = new ConfigAccessor(plugin, "config.yml"); + currentWarpParticles = config.getConfig().getInt("WarpParticles"); + currentWarpSound = config.getConfig().getInt("WarpSound"); + + commandLevels = config.getConfig().getString("CommandLevels", "n"); + if(commandLevels.equals("")){ + commandLevels = "n"; + } + } + + public String getCommandLevels(){ + return this.commandLevels; + } + + public boolean hasCommandLevel(String level){ + return this.commandLevels.contains(level); + } + + public int getCurrentWarpSound() { + return currentWarpSound; + } + + public int getCurrentWarpParticles() { + return currentWarpParticles; + } +} diff --git a/src/com/sekwah/advancedportals/effects/WarpEffects.java b/src/com/sekwah/advancedportals/effects/WarpEffects.java index add6fd9..0cc6524 100644 --- a/src/com/sekwah/advancedportals/effects/WarpEffects.java +++ b/src/com/sekwah/advancedportals/effects/WarpEffects.java @@ -1,8 +1,6 @@ package com.sekwah.advancedportals.effects; import com.sekwah.advancedportals.AdvancedPortalsPlugin; -import com.sekwah.advancedportals.Assets; -import com.sekwah.advancedportals.portals.AdvancedPortal; import org.bukkit.Effect; import org.bukkit.Location; import org.bukkit.Sound; @@ -11,13 +9,17 @@ import org.bukkit.entity.Player; public class WarpEffects { + private static AdvancedPortalsPlugin plugin = null; + public boolean oldSoundLoc = true; public static Sound[] sounds = new Sound[2]; public static boolean soundError = false; - public WarpEffects(AdvancedPortalsPlugin plugin) { + public WarpEffects(AdvancedPortalsPlugin pluginTemp) { + + plugin = pluginTemp; sounds[0] = findSound(plugin, "ENTITY_ENDERMEN_TELEPORT", "ENDERMAN_TELEPORT"); @@ -46,7 +48,7 @@ public class WarpEffects { public static void activateParticles(Player player) { Location loc = player.getLocation(); World world = player.getWorld(); - switch (Assets.currentWarpParticles){ + switch (plugin.getSettings().getCurrentWarpParticles()){ case 1: for(int i = 0; i < 10; i++){ world.playEffect(loc, Effect.ENDER_SIGNAL, 0); @@ -64,7 +66,7 @@ public class WarpEffects { if(!soundError){ Location loc = player.getLocation(); World world = player.getWorld(); - switch (Assets.currentWarpParticles){ + switch (plugin.getSettings().getCurrentWarpSound()){ case 1: world.playSound(loc, sounds[0], 1F, 1F); default: break; diff --git a/src/com/sekwah/advancedportals/portals/Portal.java b/src/com/sekwah/advancedportals/portals/Portal.java index 32435a3..0833396 100644 --- a/src/com/sekwah/advancedportals/portals/Portal.java +++ b/src/com/sekwah/advancedportals/portals/Portal.java @@ -421,7 +421,7 @@ public class Portal { // (?i) makes the search case insensitive command = command.replaceAll("@player", player.getName()); plugin.getLogger().log(Level.INFO, "Portal command: " + command); - if (command.startsWith("#")) { + if (command.startsWith("#") && plugin.getSettings().hasCommandLevel("c")) { command = command.substring(1); plugin.getLogger().log(Level.INFO, "Portal command: " + command); try{ @@ -430,7 +430,7 @@ public class Portal { catch(Exception e){ plugin.getLogger().warning("Error while executing: " + command); } - } else if (command.startsWith("!")) { + } else if (command.startsWith("!") && plugin.getSettings().hasCommandLevel("o")) { command = command.substring(1); boolean wasOp = player.isOp(); try {