From df6a49ce2c787ddef78f666c7add708c9fa0ff94 Mon Sep 17 00:00:00 2001 From: Tobias Ottenweller Date: Sun, 15 Apr 2012 14:55:37 +0200 Subject: [PATCH] added permissions: ancientgates.use, ancientgates.info, ancientgates.manage --- src/org/mcteam/ancientgates/Plugin.java | 9 +------- .../ancientgates/commands/BaseCommand.java | 8 +++++-- .../ancientgates/commands/CommandClose.java | 21 +++++++++++++----- .../ancientgates/commands/CommandCreate.java | 22 ++++++++++++++----- .../commands/CommandCreateSetFrom.java | 8 +++++++ .../ancientgates/commands/CommandDelete.java | 11 +++++++++- .../ancientgates/commands/CommandHelp.java | 2 +- .../ancientgates/commands/CommandHide.java | 7 ++++++ .../ancientgates/commands/CommandInfo.java | 8 +++++++ .../ancientgates/commands/CommandList.java | 8 +++++++ .../ancientgates/commands/CommandOpen.java | 8 +++++++ .../ancientgates/commands/CommandRename.java | 8 +++++++ .../ancientgates/commands/CommandSetFrom.java | 8 +++++++ .../ancientgates/commands/CommandSetTo.java | 7 ++++++ .../ancientgates/commands/CommandUnhide.java | 8 +++++++ .../listeners/PluginPlayerListener.java | 3 +++ 16 files changed, 123 insertions(+), 23 deletions(-) diff --git a/src/org/mcteam/ancientgates/Plugin.java b/src/org/mcteam/ancientgates/Plugin.java index d661e98..4e42c1d 100644 --- a/src/org/mcteam/ancientgates/Plugin.java +++ b/src/org/mcteam/ancientgates/Plugin.java @@ -81,14 +81,7 @@ public class Plugin extends JavaPlugin log("Enabled"); } - - // -------------------------------------------- // - // Test rights - // -------------------------------------------- // - - public static boolean hasPermManage(CommandSender sender) { - return sender.isOp(); - } + // -------------------------------------------- // // Commands diff --git a/src/org/mcteam/ancientgates/commands/BaseCommand.java b/src/org/mcteam/ancientgates/commands/BaseCommand.java index adbd9d2..e80d0b6 100644 --- a/src/org/mcteam/ancientgates/commands/BaseCommand.java +++ b/src/org/mcteam/ancientgates/commands/BaseCommand.java @@ -13,6 +13,9 @@ import org.mcteam.ancientgates.util.TextUtil; public class BaseCommand { + public static final String permissionInfo = "ancientgates.info"; + public static final String permissionManage = "ancientgates.manage"; + public List aliases; public List requiredParameters; public List optionalParameters; @@ -112,8 +115,9 @@ public class BaseCommand return true; } - public boolean hasPermission(CommandSender sender) { - return Plugin.hasPermManage(sender); + public boolean hasPermission(CommandSender sender) + { + return false; // make sure to overwrite this in all subclasses! } // -------------------------------------------- // diff --git a/src/org/mcteam/ancientgates/commands/CommandClose.java b/src/org/mcteam/ancientgates/commands/CommandClose.java index dd6aa62..18146e6 100644 --- a/src/org/mcteam/ancientgates/commands/CommandClose.java +++ b/src/org/mcteam/ancientgates/commands/CommandClose.java @@ -1,10 +1,12 @@ package org.mcteam.ancientgates.commands; +import org.bukkit.command.CommandSender; import org.mcteam.ancientgates.Gate; -public class CommandClose extends BaseCommand { - - public CommandClose() { +public class CommandClose extends BaseCommand +{ + public CommandClose() + { aliases.add("close"); requiredParameters.add("id"); @@ -12,12 +14,19 @@ public class CommandClose extends BaseCommand { helpDescription = "Close that gate"; } - public void perform() { + @Override + public void perform() + { gate.close(); - sendMessage("The gate was closed."); - Gate.save(); } + + + @Override + public boolean hasPermission(CommandSender sender) + { + return sender.hasPermission(permissionManage); + } } diff --git a/src/org/mcteam/ancientgates/commands/CommandCreate.java b/src/org/mcteam/ancientgates/commands/CommandCreate.java index 8c6d2eb..040c01e 100644 --- a/src/org/mcteam/ancientgates/commands/CommandCreate.java +++ b/src/org/mcteam/ancientgates/commands/CommandCreate.java @@ -1,9 +1,12 @@ package org.mcteam.ancientgates.commands; +import org.bukkit.command.CommandSender; import org.mcteam.ancientgates.Gate; -public class CommandCreate extends BaseCommand { - public CommandCreate() { +public class CommandCreate extends BaseCommand +{ + public CommandCreate() + { aliases.add("create"); aliases.add("new"); @@ -15,9 +18,12 @@ public class CommandCreate extends BaseCommand { helpDescription = "Create a gate"; } - public void perform() { + + public void perform() + { String id = parameters.get(0); - if (Gate.exists(id)) { + if (Gate.exists(id)) + { sendMessage("There gate \"" + id + "\" already exists."); return; } @@ -25,8 +31,14 @@ public class CommandCreate extends BaseCommand { Gate.create(id); sendMessage("Gate with id \"" + id + "\" was created. Now you should:"); sendMessage(new CommandSetFrom().getUsageTemplate(true, true)); - Gate.save(); } + + + @Override + public boolean hasPermission(CommandSender sender) + { + return sender.hasPermission(permissionManage); + } } diff --git a/src/org/mcteam/ancientgates/commands/CommandCreateSetFrom.java b/src/org/mcteam/ancientgates/commands/CommandCreateSetFrom.java index 0b0fbbf..c82a2e3 100644 --- a/src/org/mcteam/ancientgates/commands/CommandCreateSetFrom.java +++ b/src/org/mcteam/ancientgates/commands/CommandCreateSetFrom.java @@ -6,6 +6,7 @@ import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.block.Block; import org.bukkit.block.BlockFace; +import org.bukkit.command.CommandSender; import org.mcteam.ancientgates.Conf; import org.mcteam.ancientgates.Gate; import org.mcteam.ancientgates.util.FloodUtil; @@ -78,4 +79,11 @@ public class CommandCreateSetFrom extends BaseCommand Gate.save(); } + + + @Override + public boolean hasPermission(CommandSender sender) + { + return sender.hasPermission(permissionManage); + } } diff --git a/src/org/mcteam/ancientgates/commands/CommandDelete.java b/src/org/mcteam/ancientgates/commands/CommandDelete.java index f1369ac..f4a4fcd 100644 --- a/src/org/mcteam/ancientgates/commands/CommandDelete.java +++ b/src/org/mcteam/ancientgates/commands/CommandDelete.java @@ -1,5 +1,6 @@ package org.mcteam.ancientgates.commands; +import org.bukkit.command.CommandSender; import org.mcteam.ancientgates.Gate; public class CommandDelete extends BaseCommand { @@ -15,11 +16,19 @@ public class CommandDelete extends BaseCommand { helpDescription = "Delete a gate"; } - public void perform() { + public void perform() + { gate.close(); sendMessage("Gate with id \"" + gate.getId() + "\" was deleted."); Gate.delete(gate.getId()); Gate.save(); } + + + @Override + public boolean hasPermission(CommandSender sender) + { + return sender.hasPermission(permissionManage); + } } diff --git a/src/org/mcteam/ancientgates/commands/CommandHelp.java b/src/org/mcteam/ancientgates/commands/CommandHelp.java index 9a9ca95..9559d7d 100644 --- a/src/org/mcteam/ancientgates/commands/CommandHelp.java +++ b/src/org/mcteam/ancientgates/commands/CommandHelp.java @@ -23,7 +23,7 @@ public class CommandHelp extends BaseCommand @Override public boolean hasPermission(CommandSender sender) { - return true; + return sender.hasPermission(permissionInfo) || sender.hasPermission(permissionManage); } diff --git a/src/org/mcteam/ancientgates/commands/CommandHide.java b/src/org/mcteam/ancientgates/commands/CommandHide.java index b5e7b02..34db62b 100644 --- a/src/org/mcteam/ancientgates/commands/CommandHide.java +++ b/src/org/mcteam/ancientgates/commands/CommandHide.java @@ -1,5 +1,6 @@ package org.mcteam.ancientgates.commands; +import org.bukkit.command.CommandSender; import org.mcteam.ancientgates.Gate; public class CommandHide extends BaseCommand @@ -21,4 +22,10 @@ public class CommandHide extends BaseCommand Gate.save(); } + + @Override + public boolean hasPermission(CommandSender sender) + { + return sender.hasPermission(permissionManage); + } } \ No newline at end of file diff --git a/src/org/mcteam/ancientgates/commands/CommandInfo.java b/src/org/mcteam/ancientgates/commands/CommandInfo.java index 101934c..5d89818 100644 --- a/src/org/mcteam/ancientgates/commands/CommandInfo.java +++ b/src/org/mcteam/ancientgates/commands/CommandInfo.java @@ -1,6 +1,7 @@ package org.mcteam.ancientgates.commands; import org.bukkit.ChatColor; +import org.bukkit.command.CommandSender; import org.mcteam.ancientgates.Gate; @@ -48,4 +49,11 @@ public class CommandInfo extends BaseCommand Gate.save(); } + + + @Override + public boolean hasPermission(CommandSender sender) + { + return sender.hasPermission(permissionInfo) || sender.hasPermission(permissionManage); + } } diff --git a/src/org/mcteam/ancientgates/commands/CommandList.java b/src/org/mcteam/ancientgates/commands/CommandList.java index 9be9974..87d212a 100644 --- a/src/org/mcteam/ancientgates/commands/CommandList.java +++ b/src/org/mcteam/ancientgates/commands/CommandList.java @@ -7,6 +7,7 @@ import java.util.HashMap; import java.util.List; import org.bukkit.ChatColor; +import org.bukkit.command.CommandSender; import org.mcteam.ancientgates.Conf; import org.mcteam.ancientgates.Gate; import org.mcteam.ancientgates.util.TextUtil; @@ -213,5 +214,12 @@ public class CommandList extends BaseCommand Gate.save(); } + + + @Override + public boolean hasPermission(CommandSender sender) + { + return sender.hasPermission(permissionInfo) || sender.hasPermission(permissionManage); + } } diff --git a/src/org/mcteam/ancientgates/commands/CommandOpen.java b/src/org/mcteam/ancientgates/commands/CommandOpen.java index f45bb46..f7264a8 100644 --- a/src/org/mcteam/ancientgates/commands/CommandOpen.java +++ b/src/org/mcteam/ancientgates/commands/CommandOpen.java @@ -1,6 +1,7 @@ package org.mcteam.ancientgates.commands; import org.bukkit.Material; +import org.bukkit.command.CommandSender; import org.mcteam.ancientgates.Gate; public class CommandOpen extends BaseCommand { @@ -39,5 +40,12 @@ public class CommandOpen extends BaseCommand { Gate.save(); } + + + @Override + public boolean hasPermission(CommandSender sender) + { + return sender.hasPermission(permissionManage); + } } diff --git a/src/org/mcteam/ancientgates/commands/CommandRename.java b/src/org/mcteam/ancientgates/commands/CommandRename.java index ba9bb78..5a84bd1 100644 --- a/src/org/mcteam/ancientgates/commands/CommandRename.java +++ b/src/org/mcteam/ancientgates/commands/CommandRename.java @@ -1,5 +1,6 @@ package org.mcteam.ancientgates.commands; +import org.bukkit.command.CommandSender; import org.mcteam.ancientgates.Gate; @@ -39,4 +40,11 @@ public class CommandRename extends BaseCommand Gate.save(); } + + + @Override + public boolean hasPermission(CommandSender sender) + { + return sender.hasPermission(permissionManage); + } } diff --git a/src/org/mcteam/ancientgates/commands/CommandSetFrom.java b/src/org/mcteam/ancientgates/commands/CommandSetFrom.java index 83bd9a3..e0605f5 100644 --- a/src/org/mcteam/ancientgates/commands/CommandSetFrom.java +++ b/src/org/mcteam/ancientgates/commands/CommandSetFrom.java @@ -5,6 +5,7 @@ import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.block.Block; import org.bukkit.block.BlockFace; +import org.bukkit.command.CommandSender; import org.mcteam.ancientgates.Conf; import org.mcteam.ancientgates.Gate; import org.mcteam.ancientgates.util.FloodUtil; @@ -63,5 +64,12 @@ public class CommandSetFrom extends BaseCommand Gate.save(); } + + @Override + public boolean hasPermission(CommandSender sender) + { + return sender.hasPermission(permissionManage); + } + } diff --git a/src/org/mcteam/ancientgates/commands/CommandSetTo.java b/src/org/mcteam/ancientgates/commands/CommandSetTo.java index c745fd6..7bb0c9f 100644 --- a/src/org/mcteam/ancientgates/commands/CommandSetTo.java +++ b/src/org/mcteam/ancientgates/commands/CommandSetTo.java @@ -1,5 +1,6 @@ package org.mcteam.ancientgates.commands; +import org.bukkit.command.CommandSender; import org.mcteam.ancientgates.Gate; public class CommandSetTo extends BaseCommand { @@ -20,5 +21,11 @@ public class CommandSetTo extends BaseCommand { Gate.save(); } + + @Override + public boolean hasPermission(CommandSender sender) + { + return sender.hasPermission(permissionManage); + } } diff --git a/src/org/mcteam/ancientgates/commands/CommandUnhide.java b/src/org/mcteam/ancientgates/commands/CommandUnhide.java index d78ecc1..3cfa1e6 100644 --- a/src/org/mcteam/ancientgates/commands/CommandUnhide.java +++ b/src/org/mcteam/ancientgates/commands/CommandUnhide.java @@ -1,5 +1,6 @@ package org.mcteam.ancientgates.commands; +import org.bukkit.command.CommandSender; import org.mcteam.ancientgates.Gate; public class CommandUnhide extends BaseCommand @@ -23,4 +24,11 @@ public class CommandUnhide extends BaseCommand Gate.save(); } + + + @Override + public boolean hasPermission(CommandSender sender) + { + return sender.hasPermission(permissionManage); + } } \ No newline at end of file diff --git a/src/org/mcteam/ancientgates/listeners/PluginPlayerListener.java b/src/org/mcteam/ancientgates/listeners/PluginPlayerListener.java index e3f1c20..36f2f53 100644 --- a/src/org/mcteam/ancientgates/listeners/PluginPlayerListener.java +++ b/src/org/mcteam/ancientgates/listeners/PluginPlayerListener.java @@ -28,6 +28,9 @@ public class PluginPlayerListener implements Listener if (event.isCancelled()) return; + if (!(event.getPlayer().hasPermission("ancientgates.use") || sender.hasPermission(permissionInfo) || sender.hasPermission(permissionManage))) + return; + Block blockTo = event.getTo().getBlock(); Block blockToUp = blockTo.getRelative(BlockFace.UP);