diff --git a/src/main/java/com/gmail/nossr50/config/Config.java b/src/main/java/com/gmail/nossr50/config/Config.java index a9e8a2f2e..fe72417ca 100644 --- a/src/main/java/com/gmail/nossr50/config/Config.java +++ b/src/main/java/com/gmail/nossr50/config/Config.java @@ -81,6 +81,7 @@ public class Config extends ConfigLoader { public int getPTPCommandCooldown() { return config.getInt("Commands.ptp.Cooldown", 30); } public int getPTPCommandTimeout() { return config.getInt("Commands.ptp.Request_Timeout", 300); } public boolean getPTPCommandConfirmRequired() { return config.getBoolean("Commands.ptp.Confirm_Required", true); } + public boolean getPTPCommandWorldPermissions() { return config.getBoolean("Commands.ptp.World_Based_Permissions", false); } /* Items */ public int getChimaeraCost() { return config.getInt("Items.Chimaera_Wing.Feather_Cost", 10); } diff --git a/src/main/java/com/gmail/nossr50/party/commands/PtpCommand.java b/src/main/java/com/gmail/nossr50/party/commands/PtpCommand.java index c5c4bf0c2..990dbdc9e 100644 --- a/src/main/java/com/gmail/nossr50/party/commands/PtpCommand.java +++ b/src/main/java/com/gmail/nossr50/party/commands/PtpCommand.java @@ -14,6 +14,7 @@ import com.gmail.nossr50.events.party.McMMOPartyTeleportEvent; import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.party.PartyManager; import com.gmail.nossr50.util.Misc; +import com.gmail.nossr50.util.Permissions; import com.gmail.nossr50.util.Users; public class PtpCommand implements CommandExecutor { @@ -129,6 +130,10 @@ public class PtpCommand implements CommandExecutor { return true; } + if (CommandHelper.noCommandPermissions(player, "mcmmo.commands.ptp.accept")) { + return true; + } + int ptpRequestExpire = Config.getInstance().getPTPCommandTimeout(); if ((mcMMOPlayer.getPtpTimeout() + ptpRequestExpire) * Misc.TIME_CONVERSION_FACTOR < System.currentTimeMillis()) { @@ -149,7 +154,20 @@ public class PtpCommand implements CommandExecutor { return true; } - McMMOPartyTeleportEvent event = new McMMOPartyTeleportEvent(player, target, mcMMOPlayer.getParty().getName()); + if(Config.getInstance().getPTPCommandWorldPermissions()) { + String perm = "mcmmo.commands.ptp.world."; + + if(!Permissions.hasDynamicPermission(target, perm + "all", "op")) { + if(!Permissions.hasDynamicPermission(target, perm + target.getWorld().getName(), "op")) { + return true; + } + else if(target.getWorld() != player.getWorld() && !Permissions.hasDynamicPermission(target, perm + player.getWorld().getName(), "op")) { + return true; + } + } + } + + McMMOPartyTeleportEvent event = new McMMOPartyTeleportEvent(target, player, mcMMOPlayer.getParty().getName()); plugin.getServer().getPluginManager().callEvent(event); if (event.isCancelled()) { @@ -164,6 +182,10 @@ public class PtpCommand implements CommandExecutor { } private boolean acceptAnyTeleportRequest() { + if (CommandHelper.noCommandPermissions(player, "mcmmo.commands.ptp.acceptall")) { + return true; + } + if (mcMMOPlayer.getPtpConfirmRequired()) { player.sendMessage(LocaleLoader.getString("Commands.ptp.AcceptAny.Disabled")); } @@ -176,6 +198,10 @@ public class PtpCommand implements CommandExecutor { } private boolean togglePartyTeleportation() { + if (CommandHelper.noCommandPermissions(player, "mcmmo.commands.ptp.toggle")) { + return true; + } + if (mcMMOPlayer.getPtpEnabled()) { player.sendMessage(LocaleLoader.getString("Commands.ptp.Disabled")); } diff --git a/src/main/java/com/gmail/nossr50/util/Permissions.java b/src/main/java/com/gmail/nossr50/util/Permissions.java index 68783cb11..541ca7a3b 100644 --- a/src/main/java/com/gmail/nossr50/util/Permissions.java +++ b/src/main/java/com/gmail/nossr50/util/Permissions.java @@ -1,7 +1,13 @@ package com.gmail.nossr50.util; +import java.util.HashMap; +import java.util.Map; + +import org.bukkit.Bukkit; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; +import org.bukkit.permissions.Permission; +import org.bukkit.plugin.PluginManager; import com.gmail.nossr50.skills.utilities.SkillType; @@ -12,6 +18,22 @@ public final class Permissions { return (sender.hasPermission(perm)); } + public static boolean hasDynamicPermission(CommandSender sender, String perm, String defaultType) { + Map m = new HashMap(); + + if(defaultType != null) { + m.put("default", defaultType); + } + + PluginManager manager = Bukkit.getPluginManager(); + + if (manager.getPermission(perm) == null) { + Permission.loadPermission(perm, m); + } + + return hasPermission(sender, perm); + } + /* * GENERIC PERMISSIONS */ diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 89ffd6570..e0df8726a 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -329,6 +329,9 @@ Commands: Cooldown: 30 Confirm_Required: true Request_Timeout: 300 + #If true, require players to have a mcmmo.commands.ptp.world.[WorldName] permission + #to teleport to, from, or within any given world. + World_Based_Permissions: false p: #Allow mcMMO to use player display names in chat instead of their usernames Use_Display_Names: true diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 63d6445f0..6e839876d 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -727,6 +727,7 @@ permissions: mcmmo.commands.mmoedit: true mcmmo.commands.mmoedit.others: true mcmmo.commands.mmoupdate: true + mcmmo.commands.ptp.world.all: true mcmmo.commands.skillreset.all: true mcmmo.commands.xprate: true mcmmo.commands.defaults: @@ -740,6 +741,9 @@ permissions: mcmmo.commands.mctop.all: true mcmmo.commands.party.all: true mcmmo.commands.ptp: true + mcmmo.commands.ptp.accept: true + mcmmo.commands.ptp.acceptall: true + mcmmo.commands.ptp.toggle: true mcmmo.commands.ability: description: Allows access to the mcability command children: @@ -913,8 +917,32 @@ permissions: description: Allows access to the party rename command mcmmo.commands.party.unlock: description: Allows access to the party unlock command + mcmmo.commands.ptp.*: + description: Implies access to all mcmmo.commands.ptp permissions. + children: + mcmmo.commands.ptp.all: true + mcmmo.commands.ptp.all: + description: Implies access to all mcmmo.commands.ptp permissions. + children: + mcmmo.commands.ptp: true + mcmmo.commands.ptp.accept: true + mcmmo.commands.ptp.acceptall: true + mcmmo.commands.ptp.toggle: true + mcmmo.commands.ptp.world.all: true mcmmo.commands.ptp: description: Allows access to the ptp command + mcmmo.commands.ptp.accept: + description: Allows access to the ptp accept command + mcmmo.commands.ptp.acceptall: + description: Allows access to the ptp acceptall command + mcmmo.commands.ptp.toggle: + description: Allows access to the ptp toggle command + mcmmo.commands.ptp.world.*: + description: Implies access to all mcmmo.commands.ptp.world permissions. + children: + mcmmo.commands.ptp.world.all: true + mcmmo.commands.ptp.world.all: + description: Implies access to all mcmmo.commands.ptp.world permissions. mcmmo.commands.skillreset.*: description: Implies access to all mcmmo.commands.skillreset permissions children: