From 0cc3fd6adaab0849e08f61c2119ae33b10203b0f Mon Sep 17 00:00:00 2001 From: Xefir Date: Sun, 29 Apr 2012 02:11:39 +0200 Subject: [PATCH] Initial version : 1.6.2 --- META-INF/MANIFEST.MF | 2 + config.yml | 44 ++ .../bukkit/simplyperms/SimplyAPI.java | 240 +++++++++ .../bukkit/simplyperms/SimplyCommands.java | 466 ++++++++++++++++++ .../bukkit/simplyperms/SimplyPlayer.java | 50 ++ .../bukkit/simplyperms/SimplyPlugin.java | 283 +++++++++++ .../bukkit/simplyperms/SimplyPrevents.java | 118 +++++ .../bukkit/simplyperms/imports/ImportDB.java | 48 ++ .../simplyperms/imports/ImportFile.java | 48 ++ .../simplyperms/imports/ImportManager.java | 7 + .../simplyperms/imports/ImportPermBukkit.java | 65 +++ .../simplyperms/imports/ImportPrivileges.java | 64 +++ .../bukkit/simplyperms/io/ConfigFile.java | 144 ++++++ .../bukkit/simplyperms/io/ConfigSQL.java | 330 +++++++++++++ .../bukkit/simplyperms/io/PermsConfig.java | 40 ++ .../bukkit/simplyperms/preventions/Bow.java | 26 + .../simplyperms/preventions/Changesign.java | 21 + .../bukkit/simplyperms/preventions/Chat.java | 23 + .../simplyperms/preventions/Command.java | 31 ++ .../simplyperms/preventions/Damage.java | 47 ++ .../bukkit/simplyperms/preventions/Fight.java | 33 ++ .../simplyperms/preventions/Hunger.java | 26 + .../bukkit/simplyperms/preventions/Item.java | 32 ++ .../simplyperms/preventions/Monster.java | 26 + .../bukkit/simplyperms/preventions/Sneak.java | 28 ++ .../simplyperms/preventions/Vehicle.java | 70 +++ .../preventions/animals/Shear.java | 21 + .../simplyperms/preventions/animals/Tame.java | 24 + .../preventions/bucket/Lavabucket.java | 32 ++ .../preventions/bucket/Milking.java | 24 + .../preventions/bucket/Waterbucket.java | 32 ++ .../preventions/build/Breakblock.java | 49 ++ .../preventions/build/Placeblock.java | 28 ++ .../simplyperms/preventions/craft/Brew.java | 27 + .../simplyperms/preventions/craft/Chest.java | 29 ++ .../preventions/craft/Dispenser.java | 27 + .../preventions/craft/Enchant.java | 27 + .../preventions/craft/Furnace.java | 27 + .../preventions/craft/Workbench.java | 27 + .../preventions/fire/Fireball.java | 27 + .../preventions/fire/FlintAndSteel.java | 27 + .../simplyperms/preventions/interact/Bed.java | 21 + .../preventions/interact/Button.java | 29 ++ .../preventions/interact/Cake.java | 27 + .../preventions/interact/Door.java | 34 ++ .../preventions/interact/Fish.java | 21 + .../preventions/interact/Jukebox.java | 27 + .../preventions/interact/Lever.java | 29 ++ .../preventions/interact/Noteblock.java | 29 ++ .../preventions/interact/Pressureplate.java | 29 ++ .../preventions/interact/Repeater.java | 29 ++ .../simplyperms/preventions/loot/Drop.java | 21 + .../simplyperms/preventions/loot/Pickup.java | 21 + .../preventions/projectile/Egg.java | 29 ++ .../preventions/projectile/Potion.java | 29 ++ .../preventions/projectile/Snowball.java | 28 ++ .../preventions/spam/CapsLock.java | 30 ++ .../simplyperms/preventions/spam/Flood.java | 45 ++ plugin.yml | 99 ++++ 59 files changed, 3317 insertions(+) create mode 100755 META-INF/MANIFEST.MF create mode 100755 config.yml create mode 100755 net/crystalyx/bukkit/simplyperms/SimplyAPI.java create mode 100755 net/crystalyx/bukkit/simplyperms/SimplyCommands.java create mode 100755 net/crystalyx/bukkit/simplyperms/SimplyPlayer.java create mode 100755 net/crystalyx/bukkit/simplyperms/SimplyPlugin.java create mode 100755 net/crystalyx/bukkit/simplyperms/SimplyPrevents.java create mode 100755 net/crystalyx/bukkit/simplyperms/imports/ImportDB.java create mode 100755 net/crystalyx/bukkit/simplyperms/imports/ImportFile.java create mode 100755 net/crystalyx/bukkit/simplyperms/imports/ImportManager.java create mode 100755 net/crystalyx/bukkit/simplyperms/imports/ImportPermBukkit.java create mode 100755 net/crystalyx/bukkit/simplyperms/imports/ImportPrivileges.java create mode 100755 net/crystalyx/bukkit/simplyperms/io/ConfigFile.java create mode 100755 net/crystalyx/bukkit/simplyperms/io/ConfigSQL.java create mode 100755 net/crystalyx/bukkit/simplyperms/io/PermsConfig.java create mode 100755 net/crystalyx/bukkit/simplyperms/preventions/Bow.java create mode 100755 net/crystalyx/bukkit/simplyperms/preventions/Changesign.java create mode 100755 net/crystalyx/bukkit/simplyperms/preventions/Chat.java create mode 100755 net/crystalyx/bukkit/simplyperms/preventions/Command.java create mode 100755 net/crystalyx/bukkit/simplyperms/preventions/Damage.java create mode 100755 net/crystalyx/bukkit/simplyperms/preventions/Fight.java create mode 100755 net/crystalyx/bukkit/simplyperms/preventions/Hunger.java create mode 100755 net/crystalyx/bukkit/simplyperms/preventions/Item.java create mode 100755 net/crystalyx/bukkit/simplyperms/preventions/Monster.java create mode 100755 net/crystalyx/bukkit/simplyperms/preventions/Sneak.java create mode 100755 net/crystalyx/bukkit/simplyperms/preventions/Vehicle.java create mode 100755 net/crystalyx/bukkit/simplyperms/preventions/animals/Shear.java create mode 100755 net/crystalyx/bukkit/simplyperms/preventions/animals/Tame.java create mode 100755 net/crystalyx/bukkit/simplyperms/preventions/bucket/Lavabucket.java create mode 100755 net/crystalyx/bukkit/simplyperms/preventions/bucket/Milking.java create mode 100755 net/crystalyx/bukkit/simplyperms/preventions/bucket/Waterbucket.java create mode 100755 net/crystalyx/bukkit/simplyperms/preventions/build/Breakblock.java create mode 100755 net/crystalyx/bukkit/simplyperms/preventions/build/Placeblock.java create mode 100755 net/crystalyx/bukkit/simplyperms/preventions/craft/Brew.java create mode 100755 net/crystalyx/bukkit/simplyperms/preventions/craft/Chest.java create mode 100755 net/crystalyx/bukkit/simplyperms/preventions/craft/Dispenser.java create mode 100755 net/crystalyx/bukkit/simplyperms/preventions/craft/Enchant.java create mode 100755 net/crystalyx/bukkit/simplyperms/preventions/craft/Furnace.java create mode 100755 net/crystalyx/bukkit/simplyperms/preventions/craft/Workbench.java create mode 100755 net/crystalyx/bukkit/simplyperms/preventions/fire/Fireball.java create mode 100755 net/crystalyx/bukkit/simplyperms/preventions/fire/FlintAndSteel.java create mode 100755 net/crystalyx/bukkit/simplyperms/preventions/interact/Bed.java create mode 100755 net/crystalyx/bukkit/simplyperms/preventions/interact/Button.java create mode 100755 net/crystalyx/bukkit/simplyperms/preventions/interact/Cake.java create mode 100755 net/crystalyx/bukkit/simplyperms/preventions/interact/Door.java create mode 100755 net/crystalyx/bukkit/simplyperms/preventions/interact/Fish.java create mode 100755 net/crystalyx/bukkit/simplyperms/preventions/interact/Jukebox.java create mode 100755 net/crystalyx/bukkit/simplyperms/preventions/interact/Lever.java create mode 100755 net/crystalyx/bukkit/simplyperms/preventions/interact/Noteblock.java create mode 100755 net/crystalyx/bukkit/simplyperms/preventions/interact/Pressureplate.java create mode 100755 net/crystalyx/bukkit/simplyperms/preventions/interact/Repeater.java create mode 100755 net/crystalyx/bukkit/simplyperms/preventions/loot/Drop.java create mode 100755 net/crystalyx/bukkit/simplyperms/preventions/loot/Pickup.java create mode 100755 net/crystalyx/bukkit/simplyperms/preventions/projectile/Egg.java create mode 100755 net/crystalyx/bukkit/simplyperms/preventions/projectile/Potion.java create mode 100755 net/crystalyx/bukkit/simplyperms/preventions/projectile/Snowball.java create mode 100755 net/crystalyx/bukkit/simplyperms/preventions/spam/CapsLock.java create mode 100755 net/crystalyx/bukkit/simplyperms/preventions/spam/Flood.java create mode 100755 plugin.yml diff --git a/META-INF/MANIFEST.MF b/META-INF/MANIFEST.MF new file mode 100755 index 0000000..58630c0 --- /dev/null +++ b/META-INF/MANIFEST.MF @@ -0,0 +1,2 @@ +Manifest-Version: 1.0 + diff --git a/config.yml b/config.yml new file mode 100755 index 0000000..086fae5 --- /dev/null +++ b/config.yml @@ -0,0 +1,44 @@ +debug: false +db: + type: file + database: minecraft + host: localhost + port: 3306 + user: root + pass: pass + table: + players: players + groups: groups + column: + playerid: playerid + groupname: groupname + permission: permission + world: world + value: value + date: date +users: + ConspiracyWizard: + permissions: + permissions.example: true + groups: + - admin +groups: + default: + permissions: + permissions.allow.build: false + admin: + permissions: + permissions.*: true + inheritance: + - user + user: + permissions: + permissions.allow.build: true + worlds: + creative: + coolplugin.item: true + inheritance: + - default +messages: + all: '&cYou can''t do this.' + build: '&cYou do not have permission to build here.' diff --git a/net/crystalyx/bukkit/simplyperms/SimplyAPI.java b/net/crystalyx/bukkit/simplyperms/SimplyAPI.java new file mode 100755 index 0000000..10ab582 --- /dev/null +++ b/net/crystalyx/bukkit/simplyperms/SimplyAPI.java @@ -0,0 +1,240 @@ +package net.crystalyx.bukkit.simplyperms; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; + +import org.bukkit.configuration.file.YamlConfiguration; + +import net.crystalyx.bukkit.simplyperms.io.PermsConfig; + +public class SimplyAPI implements PermsConfig { + + private SimplyPlugin plugin; + + public SimplyAPI(SimplyPlugin plugin) { + this.plugin = plugin; + } + + @Override + public void removePlayer(String player) { + plugin.config.removePlayer(player); + } + + @Override + public void removePlayerGroups(String player) { + plugin.config.removePlayerGroups(player); + } + + @Override + public void removePlayerGroup(String player, String group) { + plugin.config.removePlayerGroup(player, group); + } + + @Override + public void addPlayerGroup(String player, String group) { + plugin.config.addPlayerGroup(player, group); + } + + @Override + public void addPlayerPermission(String player, String permission, boolean value) { + plugin.config.addPlayerPermission(player, permission, value); + } + + @Override + public void addPlayerPermission(String player, String world, String permission, boolean value) { + plugin.config.addPlayerPermission(player, world, permission, value); + } + + @Override + public void removePlayerPermissions(String player) { + plugin.config.removePlayerPermissions(player); + } + + @Override + public void removePlayerPermission(String player, String permission) { + plugin.config.removePlayerPermission(player, permission); + } + + @Override + public void removePlayerPermission(String player, String world, String permission) { + plugin.config.removePlayerPermission(player, world, permission); + } + + @Override + public List getPlayers(String group) { + return plugin.config.getPlayers(group); + } + + @Override + public List getPlayerGroups(String player) { + return plugin.config.getPlayerGroups(player); + } + + @Override + public Map getPlayerPermissions(String player) { + return plugin.config.getPlayerPermissions(player); + } + + @Override + public Map getPlayerPermissions(String player, String world) { + return plugin.config.getPlayerPermissions(player, world); + } + + @Override + public boolean isPlayerInDB(String player) { + return plugin.config.isPlayerInDB(player); + } + + @Override + public List getPlayerWorlds(String player) { + return plugin.config.getPlayerWorlds(player); + } + + @Override + public List getAllPlayers() { + return plugin.config.getAllPlayers(); + } + + public List getAllGroups() { + if (plugin.getNode("groups") != null) { + return new ArrayList(plugin.getNode("groups").getKeys(false)); + } + else { + return new ArrayList(); + } + } + + public List getGroupWorlds(String group) { + if (group.isEmpty()) group = "default"; + if (plugin.getNode("groups/" + group + "/worlds") != null) { + return new ArrayList(plugin.getNode("groups/" + group + "/worlds").getKeys(false)); + } + else { + return new ArrayList(); + } + } + + public List getGroupInheritance(String group) { + if (group.isEmpty()) group = "default"; + return plugin.getConfig().getStringList("groups/" + group + "/inheritance"); + } + + public void addGroupInheritance(String group, String inherit) { + if (group.isEmpty()) group = "default"; + List inheritances = getGroupInheritance(group); + if (!inheritances.contains(inherit)) inheritances.add(inherit); + plugin.getConfig().set("groups/" + group + "/inheritance", inheritances); + } + + public void removeGroupInheritance(String group, String inherit) { + if (group.isEmpty()) group = "default"; + List inheritances = getGroupInheritance(group); + inheritances.remove(inherit); + plugin.getConfig().set("groups/" + group + "/inheritance", inheritances); + } + + public void removeGroupInheritances(String group) { + if (group.isEmpty()) group = "default"; + plugin.getConfig().set("groups/" + group + "/inheritance", null); + } + + public Map getGroupPermissions(String group, String world) { + if (group.isEmpty()) group = "default"; + Map finalPerms = new HashMap(); + String permNode = (!world.isEmpty()) ? "groups/" + group + "/worlds/" + world : "groups/" + group + "/permissions"; + if (plugin.getNode(permNode) != null) { + for (Entry permGroup : plugin.getNode(permNode).getValues(false).entrySet()) { + finalPerms.put(permGroup.getKey(), (Boolean) permGroup.getValue()); + } + } + return finalPerms; + } + + public Map getGroupPermissions(String group) { + return getGroupPermissions(group, ""); + } + + public void addGroupPermission(String group, String world, String permission, boolean value) { + if (group.isEmpty()) group = "default"; + Map permissions = getGroupPermissions(group, world); + if (permissions.containsKey(permission)) permissions.remove(permission); + permissions.put(permission, value); + if (!world.isEmpty()) { + plugin.getConfig().set("groups/" + group + "/worlds/" + world, permissions); + } + else { + plugin.getConfig().set("groups/" + group + "/permissions", permissions); + } + } + + public void addGroupPermission(String group, String permission, boolean value) { + addGroupPermission(group, "", permission, value); + } + + public void removeGroupPermission(String group, String world, String permission) { + if (group.isEmpty()) group = "default"; + Map permissions = getGroupPermissions(group, world); + permissions.remove(permission); + if (!world.isEmpty()) { + plugin.getConfig().set("groups/" + group + "/worlds/" + world, (permissions.isEmpty()) ? null : permissions); + } + else { + plugin.getConfig().set("groups/" + group + "/permissions", (permissions.isEmpty()) ? null : permissions); + } + } + + public void removeGroupPermission(String group, String permission) { + removeGroupPermission(group, "", permission); + } + + public void removeGroupPermissions(String group) { + if (group.isEmpty()) group = "default"; + plugin.getConfig().set("groups/" + group + "/permissions", null); + } + + public void removeGroup(String group) { + if (group.isEmpty() || group.equals("default")) { + plugin.debug("You can't delete default group !"); + return; + } + plugin.getConfig().set("groups/" + group, null); + } + + public Map getMessages() { + if (plugin.getNode("messages") != null) { + return plugin.getNode("messages").getValues(false); + } + else { + return new HashMap(); + } + } + + public void addMessage(String key, String message) { + Map messages = getMessages(); + if (!messages.containsKey(key)) messages.put(key, message); + plugin.getConfig().set("messages", messages); + } + + public void removeMessage(String key) { + Map messages = getMessages(); + messages.remove(key); + plugin.getConfig().set("messages", messages); + } + + public void refreshPermissions() { + plugin.refreshPermissions(); + } + + protected List getKeys(YamlConfiguration config, String node) { + if (config.getConfigurationSection(node) != null) { + return new ArrayList(config.getConfigurationSection(node).getKeys(false)); + } + else { + return new ArrayList(); + } + } + +} diff --git a/net/crystalyx/bukkit/simplyperms/SimplyCommands.java b/net/crystalyx/bukkit/simplyperms/SimplyCommands.java new file mode 100755 index 0000000..6581800 --- /dev/null +++ b/net/crystalyx/bukkit/simplyperms/SimplyCommands.java @@ -0,0 +1,466 @@ +package net.crystalyx.bukkit.simplyperms; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.Comparator; +import java.util.Map; + +import net.crystalyx.bukkit.simplyperms.imports.ImportDB; +import net.crystalyx.bukkit.simplyperms.imports.ImportFile; +import net.crystalyx.bukkit.simplyperms.imports.ImportManager; +import net.crystalyx.bukkit.simplyperms.imports.ImportPermBukkit; +import net.crystalyx.bukkit.simplyperms.imports.ImportPrivileges; + +import org.bukkit.ChatColor; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.command.ConsoleCommandSender; +import org.bukkit.configuration.ConfigurationSection; +import org.bukkit.entity.Player; +import org.bukkit.permissions.Permissible; +import org.bukkit.permissions.Permission; +import org.bukkit.permissions.PermissionAttachmentInfo; + +public class SimplyCommands implements CommandExecutor { + + private SimplyPlugin plugin; + + public SimplyCommands(SimplyPlugin plugin) { + this.plugin = plugin; + } + + public boolean onCommand(CommandSender sender, Command command, String label, String[] split) { + if (split.length < 1) { + return !checkPerm(sender, "help") || usage(sender, command); + } + + String subcommand = split[0]; + if (subcommand.equals("reload")) { + if (!checkPerm(sender, "reload")) return true; + plugin.reloadConfig(); + plugin.refreshPermissions(); + sender.sendMessage(ChatColor.GREEN + "Configuration reloaded."); + return true; + } if (subcommand.equals("check")) { + if (!checkPerm(sender, "check")) return true; + if (split.length != 2 && split.length != 3) return usage(sender, command, subcommand); + + String node = split[1]; + Permissible permissible; + if (split.length == 2) { + permissible = sender; + } else { + permissible = plugin.getServer().getPlayer(split[2]); + } + + String name = (permissible instanceof Player) ? ((Player) permissible).getName() : (permissible instanceof ConsoleCommandSender) ? "Console" : "Unknown"; + + if (permissible == null) { + sender.sendMessage(ChatColor.RED + "Player " + ChatColor.WHITE + split[2] + ChatColor.RED + " not found."); + } else { + boolean set = permissible.isPermissionSet(node), has = permissible.hasPermission(node); + String sets = set ? " sets " : " defaults "; + String perm = has ? " true" : " false"; + sender.sendMessage(ChatColor.GREEN + "Player " + ChatColor.WHITE + name + ChatColor.GREEN + sets + ChatColor.WHITE + node + ChatColor.GREEN + " to " + ChatColor.WHITE + perm + ChatColor.GREEN + "."); + } + return true; + } else if (subcommand.equals("info")) { + if (!checkPerm(sender, "info")) return true; + if (split.length != 2) return usage(sender, command, subcommand); + + String node = split[1]; + Permission perm = plugin.getServer().getPluginManager().getPermission(node); + + if (perm == null) { + sender.sendMessage(ChatColor.RED + "Permission " + ChatColor.WHITE + node + ChatColor.RED + " not found."); + } else { + sender.sendMessage(ChatColor.GREEN + "Info on permission " + ChatColor.WHITE + perm.getName() + ChatColor.GREEN + ":"); + sender.sendMessage(ChatColor.GREEN + "Default: " + ChatColor.WHITE + perm.getDefault()); + if (perm.getDescription() != null && perm.getDescription().length() > 0) { + sender.sendMessage(ChatColor.GREEN + "Description: " + ChatColor.WHITE + perm.getDescription()); + } + if (perm.getChildren() != null && perm.getChildren().size() > 0) { + sender.sendMessage(ChatColor.GREEN + "Children: " + ChatColor.WHITE + perm.getChildren().size()); + } + } + return true; + } else if (subcommand.equals("dump")) { + if (!checkPerm(sender, "dump")) return true; + if (split.length < 1 || split.length > 3) return usage(sender, command, subcommand); + + int page; + Permissible permissible; + if (split.length == 1) { + permissible = sender; + page = 1; + } else if (split.length == 2) { + try { + permissible = sender; + page = Integer.parseInt(split[1]); + } + catch (NumberFormatException ex) { + permissible = plugin.getServer().getPlayer(split[1]); + page = 1; + } + } else { + permissible = plugin.getServer().getPlayer(split[1]); + try { + page = Integer.parseInt(split[2]); + } + catch (NumberFormatException ex) { + page = 1; + } + } + + if (permissible == null) { + sender.sendMessage(ChatColor.RED + "Player " + ChatColor.WHITE + split[1] + ChatColor.RED + " not found."); + } else { + ArrayList dump = new ArrayList(permissible.getEffectivePermissions()); + Collections.sort(dump, new Comparator() { + public int compare(PermissionAttachmentInfo a, PermissionAttachmentInfo b) { + return a.getPermission().compareTo(b.getPermission()); + } + }); + + int numpages = 1 + (dump.size() - 1) / 8; + if (page > numpages) { + page = numpages; + } else if (page < 1) { + page = 1; + } + + ChatColor g = ChatColor.GREEN, w = ChatColor.WHITE, r = ChatColor.RED; + + int start = 8 * (page - 1); + sender.sendMessage(ChatColor.RED + "[==== " + ChatColor.GREEN + "Page " + page + " of " + numpages + ChatColor.RED + " ====]"); + for (int i = start; i < start + 8 && i < dump.size(); ++i) { + PermissionAttachmentInfo info = dump.get(i); + + if (info.getAttachment() == null) { + sender.sendMessage(g + "Node " + w + info.getPermission() + g + "=" + w + info.getValue() + g + " (" + r + "default" + g + ")"); + } else { + sender.sendMessage(g + "Node " + w + info.getPermission() + g + "=" + w + info.getValue() + g + " (" + w + info.getAttachment().getPlugin().getDescription().getName() + g + ")"); + } + } + } + return true; + } else if (subcommand.equals("group")) { + if (split.length < 2) { + return !checkPerm(sender, "group.help") || usage(sender, command, subcommand); + } + groupCommand(sender, command, split); + return true; + } else if (subcommand.equals("player")) { + if (split.length < 2) { + return !checkPerm(sender, "player.help") || usage(sender, command, subcommand); + } + playerCommand(sender, command, split); + return true; + } else if (subcommand.equals("import")) { + if (!checkPerm(sender, "import")) return true; + if (split.length != 2) return usage(sender, command, subcommand); + String pluginName = split[1].toLowerCase(); + ImportManager manager; + + if (pluginName.equals("permissionsbukkit")) { + manager = new ImportPermBukkit(plugin); + } else if (pluginName.equals("privileges")) { + manager = new ImportPrivileges(plugin); + } else if (pluginName.equals("file")) { + manager = new ImportFile(plugin); + } else if (plugin.getConfig().getString("db/type") != null + && pluginName.equals(plugin.getConfig().getString("db/type").toLowerCase())) { + manager = new ImportDB(plugin); + } else { + sender.sendMessage(ChatColor.RED + "Unknown import type !"); + return true; + } + + try { + manager.run(); + plugin.refreshPermissions(); + sender.sendMessage(ChatColor.GREEN + "Operation success !"); + } catch (Exception e) { + plugin.reloadConfig(); + sender.sendMessage(ChatColor.RED + "An error occurred ! Please check server log..."); + e.printStackTrace(); + } + return true; + } else { + return !checkPerm(sender, "help") || usage(sender, command); + } + } + + private boolean groupCommand(CommandSender sender, Command command, String[] split) { + String subcommand = split[1]; + + if (subcommand.equals("list")) { + if (!checkPerm(sender, "group.list")) return true; + if (split.length != 2) return usage(sender, command, "group list"); + + String result = "", sep = ""; + for (String key : plugin.getNode("groups").getKeys(false)) { + result += sep + key; + sep = ", "; + } + sender.sendMessage(ChatColor.GREEN + "Groups: " + ChatColor.WHITE + result); + return true; + } else if (subcommand.equals("players")) { + if (!checkPerm(sender, "group.players")) return true; + if (split.length != 3) return usage(sender, command, "group players"); + String group = split[2]; + + if (plugin.getNode("groups/" + group) == null) { + sender.sendMessage(ChatColor.RED + "No such group " + ChatColor.WHITE + group + ChatColor.RED + "."); + return true; + } + + int count = 0; + String text = "", sep = ""; + for (String user : plugin.config.getPlayers(group)) { + ++count; + text += sep + user; + sep = ", "; + } + sender.sendMessage(ChatColor.GREEN + "Users in " + ChatColor.WHITE + group + ChatColor.GREEN + " (" + ChatColor.WHITE + count + ChatColor.GREEN + "): " + ChatColor.WHITE + text); + return true; + } else if (subcommand.equals("setperm")) { + if (!checkPerm(sender, "group.setperm")) return true; + if (split.length != 4 && split.length != 5) return usage(sender, command, "group setperm"); + String group = split[2]; + String perm = split[3]; + boolean value = (split.length != 5) || Boolean.parseBoolean(split[4]); + + String node = "permissions"; + if (plugin.getNode("groups/" + group) == null) { + sender.sendMessage(ChatColor.RED + "No such group " + ChatColor.WHITE + group + ChatColor.RED + "."); + return true; + } + + if (perm.contains(":")) { + String world = perm.substring(0, perm.indexOf(':')); + perm = perm.substring(perm.indexOf(':') + 1); + node = "worlds/" + world; + } + if (plugin.getNode("groups/" + group + "/" + node) == null) { + plugin.getConfig().createSection("groups/" + group + "/" + node); + } + + plugin.getNode("groups/" + group + "/" + node).set(perm, value); + plugin.refreshPermissions(); + + sender.sendMessage(ChatColor.GREEN + "Group " + ChatColor.WHITE + group + ChatColor.GREEN + " now has " + ChatColor.WHITE + perm + ChatColor.GREEN + " = " + ChatColor.WHITE + value + ChatColor.GREEN + "."); + return true; + } else if (subcommand.equals("unsetperm")) { + if (!checkPerm(sender, "group.unsetperm")) return true; + if (split.length != 4) return usage(sender, command, "group unsetperm"); + String group = split[2].toLowerCase(); + String perm = split[3]; + + String node = "permissions"; + if (plugin.getNode("groups/" + group) == null) { + sender.sendMessage(ChatColor.RED + "No such group " + ChatColor.WHITE + group + ChatColor.RED + "."); + return true; + } + + if (perm.contains(":")) { + String world = perm.substring(0, perm.indexOf(':')); + perm = perm.substring(perm.indexOf(':') + 1); + node = "worlds/" + world; + } + if (plugin.getNode("groups/" + group + "/" + node) == null) { + plugin.getConfig().createSection("groups/" + group + "/" + node); + } + + ConfigurationSection sec = plugin.getNode("groups/" + group + "/" + node); + if (!sec.contains(perm)) { + sender.sendMessage(ChatColor.GREEN + "Group " + ChatColor.WHITE + group + ChatColor.GREEN + " did not have " + ChatColor.WHITE + perm + ChatColor.GREEN + " set."); + return true; + } + sec.set(perm, null); + plugin.refreshPermissions(); + + sender.sendMessage(ChatColor.GREEN + "Group " + ChatColor.WHITE + group + ChatColor.GREEN + " no longer has " + ChatColor.WHITE + perm + ChatColor.GREEN + " set."); + return true; + } else { + return !checkPerm(sender, "group.help") || usage(sender, command); + } + } + + private boolean playerCommand(CommandSender sender, Command command, String[] split) { + String subcommand = split[1]; + + if (subcommand.equals("groups")) { + if (!checkPerm(sender, "player.groups")) return true; + if (split.length != 3) return usage(sender, command, "player groups"); + String player = split[2].toLowerCase(); + + if (!plugin.config.isPlayerInDB(player)) { + sender.sendMessage(ChatColor.GREEN + "Player " + ChatColor.WHITE + player + ChatColor.RED + " is in the default group."); + return true; + } + + int count = 0; + String text = "", sep = ""; + for (String group : plugin.config.getPlayerGroups(player)) { + ++count; + text += sep + group; + sep = ", "; + } + sender.sendMessage(ChatColor.GREEN + "Player " + ChatColor.WHITE + player + ChatColor.GREEN + " is in groups (" + ChatColor.WHITE + count + ChatColor.GREEN + "): " + ChatColor.WHITE + text); + return true; + } else if (subcommand.equals("setgroup")) { + if (!checkPerm(sender, "player.setgroup")) return true; + if (split.length != 4) return usage(sender, command, "player setgroup"); + String player = split[2].toLowerCase(); + String[] groups = split[3].split(","); + + plugin.config.removePlayerGroups(player); + for (String group : Arrays.asList(groups)) { + plugin.config.addPlayerGroup(player, group); + } + + plugin.refreshPermissions(); + + sender.sendMessage(ChatColor.GREEN + "Player " + ChatColor.WHITE + player + ChatColor.GREEN + " is now in " + ChatColor.WHITE + split[3] + ChatColor.GREEN + "."); + return true; + } else if (subcommand.equals("addgroup")) { + if (!checkPerm(sender, "player.addgroup")) return true; + if (split.length != 4) return usage(sender, command, "player addgroup"); + String player = split[2].toLowerCase(); + String group = split[3]; + + if (plugin.config.getPlayerGroups(player).contains(group)) { + sender.sendMessage(ChatColor.GREEN + "Player " + ChatColor.WHITE + player + ChatColor.GREEN + " was already in " + ChatColor.WHITE + group + ChatColor.GREEN + "."); + return true; + } + plugin.config.addPlayerGroup(player, group); + + plugin.refreshPermissions(); + + sender.sendMessage(ChatColor.GREEN + "Player " + ChatColor.WHITE + player + ChatColor.GREEN + " is now in " + ChatColor.WHITE + group + ChatColor.GREEN + "."); + return true; + } else if (subcommand.equals("removegroup")) { + if (!checkPerm(sender, "player.removegroup")) return true; + if (split.length != 4) return usage(sender, command, "player removegroup"); + String player = split[2].toLowerCase(); + String group = split[3]; + + if (!plugin.config.getPlayerGroups(player).contains(group)) { + sender.sendMessage(ChatColor.GREEN + "Player " + ChatColor.WHITE + player + ChatColor.GREEN + " was not in " + ChatColor.WHITE + group + ChatColor.GREEN + "."); + return true; + } + plugin.config.removePlayerGroup(player, group); + + plugin.refreshPermissions(); + + sender.sendMessage(ChatColor.GREEN + "Player " + ChatColor.WHITE + player + ChatColor.GREEN + " is no longer in " + ChatColor.WHITE + group + ChatColor.GREEN + "."); + return true; + } else if (subcommand.equals("remove")) { + if (!checkPerm(sender, "player.remove")) return true; + if (split.length != 3) return usage(sender, command, "player remove"); + String player = split[2].toLowerCase(); + + if (!plugin.config.isPlayerInDB(player)) { + sender.sendMessage(ChatColor.GREEN + "Player " + ChatColor.WHITE + player + ChatColor.GREEN + " was not in config file."); + return true; + } + + plugin.config.removePlayer(player); + plugin.refreshPermissions(); + + sender.sendMessage(ChatColor.GREEN + "Player " + ChatColor.WHITE + player + ChatColor.GREEN + " is no longer in config file."); + return true; + } else if (subcommand.equals("setperm")) { + if (!checkPerm(sender, "player.setperm")) return true; + if (split.length != 4 && split.length != 5) return usage(sender, command, "player setperm"); + String player = split[2].toLowerCase(); + String perm = split[3]; + boolean value = (split.length != 5) || Boolean.parseBoolean(split[4]); + + String world = ""; + if (perm.contains(":")) { + world = perm.substring(0, perm.indexOf(':')); + perm = perm.substring(perm.indexOf(':') + 1); + } + + plugin.config.addPlayerPermission(player, world, perm, value); + plugin.refreshPermissions(); + + sender.sendMessage(ChatColor.GREEN + "Player " + ChatColor.WHITE + player + ChatColor.GREEN + " now has " + ChatColor.WHITE + perm + ChatColor.GREEN + " = " + ChatColor.WHITE + value + ChatColor.GREEN + "."); + return true; + } else if (subcommand.equals("unsetperm")) { + if (!checkPerm(sender, "player.unsetperm")) return true; + if (split.length != 4) return usage(sender, command, "player unsetperm"); + String player = split[2].toLowerCase(); + String perm = split[3]; + + String world = ""; + if (perm.contains(":")) { + world = perm.substring(0, perm.indexOf(':')); + perm = perm.substring(perm.indexOf(':') + 1); + } + + Map list = plugin.config.getPlayerPermissions(player, world); + if (!list.containsKey(perm)) { + sender.sendMessage(ChatColor.GREEN + "Player " + ChatColor.WHITE + player + ChatColor.GREEN + " did not have " + ChatColor.WHITE + perm + ChatColor.GREEN + " set."); + return true; + } + plugin.config.removePlayerPermission(player, world, perm); + plugin.refreshPermissions(); + + sender.sendMessage(ChatColor.GREEN + "Player " + ChatColor.WHITE + player + ChatColor.GREEN + " no longer has " + ChatColor.WHITE + perm + ChatColor.GREEN + " set."); + return true; + } else { + return !checkPerm(sender, "player.help") || usage(sender, command); + } + } + + // -- utilities -- + + private boolean checkPerm(CommandSender sender, String subnode) { + boolean ok = sender.hasPermission("permissions." + subnode); + if (!ok) { + sender.sendMessage(ChatColor.RED + "You do not have permissions to do that."); + } + return ok; + } + + private boolean usage(CommandSender sender, Command command) { + sender.sendMessage(ChatColor.RED + "[====" + ChatColor.GREEN + " /permissons " + ChatColor.RED + "====]"); + for (String line : command.getUsage().split("\\n")) { + if ((line.startsWith("/ group") && !line.startsWith("/ group -")) || + (line.startsWith("/ player") && !line.startsWith("/ player -"))) { + continue; + } + sender.sendMessage(formatLine(line)); + } + return true; + } + + private boolean usage(CommandSender sender, Command command, String subcommand) { + sender.sendMessage(ChatColor.RED + "[====" + ChatColor.GREEN + " /permissons " + subcommand + " " + ChatColor.RED + "====]"); + for (String line : command.getUsage().split("\\n")) { + if (line.startsWith("/ " + subcommand)) { + sender.sendMessage(formatLine(line)); + } + } + return true; + } + + private String formatLine(String line) { + int i = line.indexOf(" - "); + String usage = line.substring(0, i); + String desc = line.substring(i + 3); + + usage = usage.replace("", "permissions"); + usage = usage.replaceAll("\\[[^]:]+\\]", ChatColor.AQUA + "$0" + ChatColor.GREEN); + usage = usage.replaceAll("\\[[^]]+:\\]", ChatColor.AQUA + "$0" + ChatColor.LIGHT_PURPLE); + usage = usage.replaceAll("<[^>]+>", ChatColor.LIGHT_PURPLE + "$0" + ChatColor.GREEN); + + return ChatColor.GREEN + usage + " - " + ChatColor.WHITE + desc; + } + +} diff --git a/net/crystalyx/bukkit/simplyperms/SimplyPlayer.java b/net/crystalyx/bukkit/simplyperms/SimplyPlayer.java new file mode 100755 index 0000000..1d21d47 --- /dev/null +++ b/net/crystalyx/bukkit/simplyperms/SimplyPlayer.java @@ -0,0 +1,50 @@ +package net.crystalyx.bukkit.simplyperms; + +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.Listener; +import org.bukkit.event.player.PlayerChangedWorldEvent; +import org.bukkit.event.player.PlayerJoinEvent; +import org.bukkit.event.player.PlayerKickEvent; +import org.bukkit.event.player.PlayerQuitEvent; + +public class SimplyPlayer implements Listener { + + private SimplyPlugin plugin; + + public SimplyPlayer(SimplyPlugin plugin) { + this.plugin = plugin; + } + + // Keep track of player's world + + @EventHandler(priority = EventPriority.LOWEST) + public void onWorldChange(PlayerChangedWorldEvent event) { + plugin.debug("Player " + event.getPlayer().getName() + " changed world, recalculating..."); + plugin.calculateAttachment(event.getPlayer()); + } + + // Register players when needed + + @EventHandler(priority = EventPriority.LOWEST) + public void onPlayerLogin(PlayerJoinEvent event) { + plugin.debug("Player " + event.getPlayer().getName() + " joined, registering..."); + plugin.registerPlayer(event.getPlayer()); + } + + // Unregister players when needed + + @EventHandler(priority = EventPriority.HIGHEST) + public void onPlayerKick(PlayerKickEvent event) { + if (event.isCancelled()) return; + plugin.debug("Player " + event.getPlayer().getName() + " was kicked, unregistering..."); + plugin.unregisterPlayer(event.getPlayer()); + } + + @EventHandler(priority = EventPriority.HIGHEST) + public void onPlayerQuit(PlayerQuitEvent event) { + plugin.debug("Player " + event.getPlayer().getName() + " quit, unregistering..."); + plugin.unregisterPlayer(event.getPlayer()); + } + +} diff --git a/net/crystalyx/bukkit/simplyperms/SimplyPlugin.java b/net/crystalyx/bukkit/simplyperms/SimplyPlugin.java new file mode 100755 index 0000000..cec48f7 --- /dev/null +++ b/net/crystalyx/bukkit/simplyperms/SimplyPlugin.java @@ -0,0 +1,283 @@ +package net.crystalyx.bukkit.simplyperms; + +import java.io.File; +import java.io.IOException; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Set; + +import net.crystalyx.bukkit.simplyperms.io.ConfigFile; +import net.crystalyx.bukkit.simplyperms.io.ConfigSQL; +import net.crystalyx.bukkit.simplyperms.io.PermsConfig; + +import org.bukkit.configuration.ConfigurationSection; +import org.bukkit.configuration.file.FileConfiguration; +import org.bukkit.configuration.file.YamlConfiguration; +import org.bukkit.entity.Player; +import org.bukkit.permissions.PermissionAttachment; +import org.bukkit.plugin.java.JavaPlugin; + +public class SimplyPlugin extends JavaPlugin { + + protected PermsConfig config; + private SimplyPlayer playerListener = new SimplyPlayer(this); + private SimplyCommands commandExecutor = new SimplyCommands(this); + private HashMap permissions = new HashMap(); + + private File configFile; + private YamlConfiguration YamlConfig; + + // -- Basic stuff + @Override + public void onEnable() { + // Take care of configuration + configFile = new File(getDataFolder(), "config.yml"); + if (!configFile.exists()) { + saveDefaultConfig(); + } + reloadConfig(); + + // Register stuff + getCommand("permissions").setExecutor(commandExecutor); + getServer().getPluginManager().registerEvents(playerListener, this); + registerEvents(); + + // Register everyone online right now + for (Player p : getServer().getOnlinePlayers()) { + registerPlayer(p); + } + + // How are you gentlemen + getLogger().info("Enabled successfully, " + getServer().getOnlinePlayers().length + " players registered"); + } + + @Override + public FileConfiguration getConfig() { + return YamlConfig; + } + + @Override + public void reloadConfig() { + YamlConfig = new YamlConfiguration(); + YamlConfig.options().pathSeparator('/'); + try { + YamlConfig.load(configFile); + } catch (Exception e) { + getLogger().severe("Unable to load configuration!"); + } + + // Init DB + initDatabase(); + } + + @Override + public void onDisable() { + // Unregister everyone + for (Player p : getServer().getOnlinePlayers()) { + unregisterPlayer(p); + } + + // Good day to you! I said good day! + getLogger().info("Disabled successfully, " + getServer().getOnlinePlayers().length + " players unregistered"); + } + + private void initDatabase() { + if (getConfig().getString("db/type") != null + && !getConfig().getString("db/type").equals("file")) { + ConfigSQL configsql = new ConfigSQL(this); + if (configsql.checkDatabase()) { + config = configsql; + } else { + debug("Fail to connect to database !"); + config = new ConfigFile(this); + } + } + else { + config = new ConfigFile(this); + } + } + + public SimplyAPI getAPI() { + return new SimplyAPI(this); + } + + // -- Plugin stuff + + protected void registerPlayer(Player player) { + if (permissions.containsKey(player.getName())) { + debug("Registering " + player.getName() + ": was already registered"); + unregisterPlayer(player); + } + PermissionAttachment attachment = player.addAttachment(this); + permissions.put(player.getName(), attachment); + calculateAttachment(player); + } + + protected void unregisterPlayer(Player player) { + if (permissions.containsKey(player.getName())) { + try { + player.removeAttachment(permissions.get(player.getName())); + } + catch (IllegalArgumentException ex) { + debug("Unregistering " + player.getName() + ": player did not have attachment"); + } + permissions.remove(player.getName()); + } else { + debug("Unregistering " + player.getName() + ": was not registered"); + } + } + + protected void refreshPermissions() { + try { + getConfig().save(configFile); + reloadConfig(); + } catch (IOException e) { + getLogger().warning("Failed to write changed config.yml: " + e.getMessage()); + } + for (String player : permissions.keySet()) { + PermissionAttachment attachment = permissions.get(player); + for (String key : attachment.getPermissions().keySet()) { + attachment.unsetPermission(key); + } + + calculateAttachment(getServer().getPlayer(player)); + } + } + + protected ConfigurationSection getNode(String node) { + for (String entry : getConfig().getKeys(true)) { + if (node.equalsIgnoreCase(entry) && getConfig().isConfigurationSection(entry)) { + return getConfig().getConfigurationSection(entry); + } + } + return null; + } + + protected HashMap getAllPerms(String desc, String path) { + HashMap result = new HashMap(); + ConfigurationSection node = getNode(path); + + int failures = 0; + String firstFailure = ""; + + Set keys = node.getKeys(false); + for (String key : keys) { + if (node.isBoolean(key)) { + result.put(key, node.getBoolean(key)); + } else { + ++failures; + if (firstFailure.length() == 0) { + firstFailure = key; + } + } + } + + if (failures == 1) { + getLogger().warning("In " + desc + ": " + firstFailure + " is non-boolean."); + } else if (failures > 1) { + getLogger().warning("In " + desc + ": " + firstFailure + " is non-boolean (+" + (failures-1) + " more)."); + } + + return result; + } + + public void debug(String message) { + if (getConfig().getBoolean("debug", false)) { + getLogger().info("Debug: " + message); + } + } + + protected void calculateAttachment(Player player) { + if (player == null) { + return; + } + PermissionAttachment attachment = permissions.get(player.getName()); + if (attachment == null) { + debug("Calculating permissions on " + player.getName() + ": attachment was null"); + return; + } + + for (String key : attachment.getPermissions().keySet()) { + attachment.unsetPermission(key); + } + + for (Map.Entry entry : calculatePlayerPermissions(player.getName().toLowerCase(), player.getWorld().getName()).entrySet()) { + attachment.setPermission(entry.getKey(), entry.getValue()); + } + + player.recalculatePermissions(); + } + + // -- Private stuff + + private Map calculatePlayerPermissions(String player, String world) { + if (!config.isPlayerInDB(player)) { + return calculateGroupPermissions("default", world); + } + + Map perms = new HashMap(); + List groups = config.getPlayerGroups(player); + if (groups.isEmpty()) groups.add("default"); + + for (Entry entry : config.getPlayerPermissions(player).entrySet()) { + perms.put(entry.getKey(), entry.getValue()); + } + + for (Entry entry : config.getPlayerPermissions(player, world).entrySet()) { + // No containskey; world overrides non-world + perms.put(entry.getKey(), entry.getValue()); + } + + for (String group : groups) { + for (Map.Entry entry : calculateGroupPermissions(group, world).entrySet()) { + if (!perms.containsKey(entry.getKey())) { // User overrides group + perms.put(entry.getKey(), entry.getValue()); + } + } + } + + return perms; + } + + private Map calculateGroupPermissions(String group, String world) { + if (getNode("groups/" + group) == null) { + return new HashMap(); + } + + Map perms = getNode("groups/" + group + "/permissions") == null ? + new HashMap() : + getAllPerms("group " + group, "groups/" + group + "/permissions"); + + + if (getNode("groups/" + group + "/worlds/" + world) != null) { + for (Map.Entry entry : getAllPerms("group " + group, "groups/" + group + "/worlds/" + world).entrySet()) { + // No containskey; world overrides non-world + perms.put(entry.getKey(), entry.getValue()); + } + } + + for (String parent : getNode("groups/" + group).getStringList("inheritance")) { + for (Map.Entry entry : calculateGroupPermissions(parent, world).entrySet()) { + if (!perms.containsKey(entry.getKey())) { // Children override permissions + perms.put(entry.getKey(), entry.getValue()); + } + } + } + + return perms; + } + + private void registerEvents() { + String path = getDescription().getMain().substring(0, getDescription().getMain().lastIndexOf('.')); + for (String prevent : SimplyPrevents.preventions) { + try { + getServer().getPluginManager().registerEvents((SimplyPrevents) Class.forName(path + ".preventions." + prevent).getDeclaredConstructor(SimplyPlugin.class).newInstance(this), this); + } catch (Exception e) { + debug(e.getMessage()); + } + } + } + +} diff --git a/net/crystalyx/bukkit/simplyperms/SimplyPrevents.java b/net/crystalyx/bukkit/simplyperms/SimplyPrevents.java new file mode 100755 index 0000000..3060e76 --- /dev/null +++ b/net/crystalyx/bukkit/simplyperms/SimplyPrevents.java @@ -0,0 +1,118 @@ +package net.crystalyx.bukkit.simplyperms; + +import java.util.HashMap; + +import org.bukkit.entity.Player; +import org.bukkit.event.Cancellable; +import org.bukkit.event.Listener; + +public abstract class SimplyPrevents implements Listener { + + protected SimplyPlugin plugin; + private HashMap throttleTimestamps = new HashMap(); + public static String[] preventions = { + "Bow", + "Changesign", + "Chat", + "Command", + "Damage", + "Fight", + "Hunger", + "Item", + "Monster", + "Sneak", + "Vehicle", + "animals.Shear", + "animals.Tame", + "bucket.Lavabucket", + "bucket.Milking", + "bucket.Waterbucket", + "build.Breakblock", + "build.Placeblock", + "craft.Brew", + "craft.Chest", + "craft.Dispenser", + "craft.Enchant", + "craft.Furnace", + "craft.Workbench", + "fire.FlintAndSteel", + "fire.Fireball", + "interact.Bed", + "interact.Button", + "interact.Cake", + "interact.Door", + "interact.Fish", + "interact.Jukebox", + "interact.Lever", + "interact.Noteblock", + "interact.Pressureplate", + "interact.Repeater", + "loot.Drop", + "loot.Pickup", + "projectile.Egg", + "projectile.Potion", + "projectile.Snowball", + "spam.CapsLock", + "spam.Flood" + }; + + public SimplyPrevents(SimplyPlugin plugin) { + this.plugin = plugin; + } + + public void sendMessage(Player player, String message) { + Long next = throttleTimestamps.get(player); + next = Long.valueOf(next == null ? 0 : next.longValue()); + long current = System.currentTimeMillis(); + + if (next.longValue() < current) { + player.sendMessage(message); + throttleTimestamps.put(player, Long.valueOf(current + 3000)); + } + } + + private void deny(Cancellable event, Player player, String node) { + event.setCancelled(true); + if (plugin.getConfig().getString("messages/" + node) != null) { + sendMessage(player, plugin.getConfig().getString("messages/" + node).replace('&', '\u00A7')); + } else if (plugin.getConfig().getString("messages/all") != null) { + sendMessage(player, plugin.getConfig().getString("messages/all").replace('&', '\u00A7')); + } + plugin.debug("Event '" + node + "' cancelled for " + player.getName()); + } + + protected boolean prevent(Cancellable event, Player player, String node) { + if (player.isPermissionSet("permissions.allow.*") + && player.hasPermission("permissions.allow.*")) { + return false; + } else if (node.contains(",")) { + for (String subNode : node.split(",")) { + if (prevent(event, player, subNode)) { + return true; + } else if (player.isPermissionSet("permissions.allow." + subNode)) { + return false; + } + } + } else if (node.contains(".")) { + if (player.isPermissionSet("permissions.allow." + node)) { + if (!player.hasPermission("permissions.allow." + node)) { + deny(event, player, node); + return true; + } + } else if (prevent(event, player, node.substring(0, node.indexOf('.')))) { + return true; + } + } else if (player.isPermissionSet("permissions.allow." + node)) { + if (!player.hasPermission("permissions.allow." + node)) { + deny(event, player, node); + return true; + } + } else if (player.isPermissionSet("permissions.allow.*") + && !player.hasPermission("permissions.allow.*")) { + deny(event, player, node); + return true; + } + return false; + } + +} diff --git a/net/crystalyx/bukkit/simplyperms/imports/ImportDB.java b/net/crystalyx/bukkit/simplyperms/imports/ImportDB.java new file mode 100755 index 0000000..0cbc2c4 --- /dev/null +++ b/net/crystalyx/bukkit/simplyperms/imports/ImportDB.java @@ -0,0 +1,48 @@ +package net.crystalyx.bukkit.simplyperms.imports; + +import java.util.Map.Entry; + +import net.crystalyx.bukkit.simplyperms.SimplyAPI; +import net.crystalyx.bukkit.simplyperms.SimplyPlugin; +import net.crystalyx.bukkit.simplyperms.io.ConfigFile; +import net.crystalyx.bukkit.simplyperms.io.ConfigSQL; + +public class ImportDB extends SimplyAPI implements ImportManager { + + private SimplyPlugin plugin; + + public ImportDB(SimplyPlugin plugin) { + super(plugin); + this.plugin = plugin; + } + + @Override + public void run() throws Exception { + try { + ConfigFile importFile = new ConfigFile(plugin); + ConfigSQL importSQL = new ConfigSQL(plugin); + if (!importSQL.checkDatabase()) { + throw new Exception("Could not connect to database !"); + } + + for (String player : importSQL.getAllPlayers()) { + for (String group : importSQL.getPlayerGroups(player)) { + importFile.addPlayerGroup(player, group); + } + + for (Entry permission : importSQL.getPlayerPermissions(player).entrySet()) { + importFile.addPlayerPermission(player, permission.getKey(), permission.getValue()); + } + + for (String world : importSQL.getPlayerWorlds(player)) { + for (Entry permission : importSQL.getPlayerPermissions(player, world).entrySet()) { + importFile.addPlayerPermission(player, world, permission.getKey(), permission.getValue()); + } + } + } + } catch (Exception e) { + throw e; + } + } + +} diff --git a/net/crystalyx/bukkit/simplyperms/imports/ImportFile.java b/net/crystalyx/bukkit/simplyperms/imports/ImportFile.java new file mode 100755 index 0000000..4874d93 --- /dev/null +++ b/net/crystalyx/bukkit/simplyperms/imports/ImportFile.java @@ -0,0 +1,48 @@ +package net.crystalyx.bukkit.simplyperms.imports; + +import java.util.Map.Entry; + +import net.crystalyx.bukkit.simplyperms.SimplyAPI; +import net.crystalyx.bukkit.simplyperms.SimplyPlugin; +import net.crystalyx.bukkit.simplyperms.io.ConfigFile; +import net.crystalyx.bukkit.simplyperms.io.ConfigSQL; + +public class ImportFile extends SimplyAPI implements ImportManager { + + private SimplyPlugin plugin; + + public ImportFile(SimplyPlugin plugin) { + super(plugin); + this.plugin = plugin; + } + + @Override + public void run() throws Exception { + try { + ConfigFile importFile = new ConfigFile(plugin); + ConfigSQL importSQL = new ConfigSQL(plugin); + if (!importSQL.checkDatabase()) { + throw new Exception("Could not connect to database !"); + } + + for (String player : importFile.getAllPlayers()) { + for (String group : importFile.getPlayerGroups(player)) { + importSQL.addPlayerGroup(player, group); + } + + for (Entry permission : importFile.getPlayerPermissions(player).entrySet()) { + importSQL.addPlayerPermission(player, permission.getKey(), permission.getValue()); + } + + for (String world : importFile.getPlayerWorlds(player)) { + for (Entry permission : importFile.getPlayerPermissions(player, world).entrySet()) { + importSQL.addPlayerPermission(player, world, permission.getKey(), permission.getValue()); + } + } + } + } catch (Exception e) { + throw e; + } + } + +} diff --git a/net/crystalyx/bukkit/simplyperms/imports/ImportManager.java b/net/crystalyx/bukkit/simplyperms/imports/ImportManager.java new file mode 100755 index 0000000..6d58d16 --- /dev/null +++ b/net/crystalyx/bukkit/simplyperms/imports/ImportManager.java @@ -0,0 +1,7 @@ +package net.crystalyx.bukkit.simplyperms.imports; + +public interface ImportManager { + + public void run() throws Exception; + +} diff --git a/net/crystalyx/bukkit/simplyperms/imports/ImportPermBukkit.java b/net/crystalyx/bukkit/simplyperms/imports/ImportPermBukkit.java new file mode 100755 index 0000000..8a62508 --- /dev/null +++ b/net/crystalyx/bukkit/simplyperms/imports/ImportPermBukkit.java @@ -0,0 +1,65 @@ +package net.crystalyx.bukkit.simplyperms.imports; + +import java.util.Map.Entry; + +import org.bukkit.configuration.file.YamlConfiguration; + +import net.crystalyx.bukkit.simplyperms.SimplyAPI; +import net.crystalyx.bukkit.simplyperms.SimplyPlugin; + +public class ImportPermBukkit extends SimplyAPI implements ImportManager { + + private SimplyPlugin plugin; + private YamlConfiguration permBukkit; + + public ImportPermBukkit(SimplyPlugin plugin) { + super(plugin); + this.plugin = plugin; + this.permBukkit = new YamlConfiguration(); + permBukkit.options().pathSeparator('/'); + } + + @Override + public void run() throws Exception { + try { + permBukkit.load("plugins/PermissionsBukkit/config.yml"); + plugin.getConfig().set("debug", permBukkit.getBoolean("debug")); + addMessage("build", permBukkit.getString("messages/build")); + + for (String player : getKeys(permBukkit, "users")) { + for (String group : permBukkit.getStringList("users/" + player + "/groups")) { + addPlayerGroup(player, group); + } + + for (Entry perm : permBukkit.getConfigurationSection("users/" + player + "/permissions").getValues(false).entrySet()) { + addPlayerPermission(player, perm.getKey(), (Boolean) perm.getValue()); + } + + for (String world : getKeys(permBukkit, "users/" + player + "/worlds")) { + for (Entry worldperm : permBukkit.getConfigurationSection("users/" + player + "/worlds/" + world).getValues(false).entrySet()) { + addPlayerPermission(player, world, worldperm.getKey(), (Boolean) worldperm.getValue()); + } + } + } + + for (String group : getKeys(permBukkit, "groups")) { + for (Entry perms : permBukkit.getConfigurationSection("groups/" + group + "/permissions").getValues(false).entrySet()) { + addGroupPermission(group, perms.getKey(), (Boolean) perms.getValue()); + } + + for (String world : getKeys(permBukkit, "groups/" + group + "/worlds")) { + for (Entry worldperm : permBukkit.getConfigurationSection("groups/" + group + "/worlds/" + world).getValues(false).entrySet()) { + addGroupPermission(group, world, worldperm.getKey(), (Boolean) worldperm.getValue()); + } + } + + for (String inherit : plugin.getConfig().getStringList("groups/" + group + "/inheritance")) { + addGroupInheritance(group, inherit); + } + } + } catch (Exception e) { + throw e; + } + } + +} diff --git a/net/crystalyx/bukkit/simplyperms/imports/ImportPrivileges.java b/net/crystalyx/bukkit/simplyperms/imports/ImportPrivileges.java new file mode 100755 index 0000000..2308079 --- /dev/null +++ b/net/crystalyx/bukkit/simplyperms/imports/ImportPrivileges.java @@ -0,0 +1,64 @@ +package net.crystalyx.bukkit.simplyperms.imports; + +import org.bukkit.configuration.file.YamlConfiguration; + +import net.crystalyx.bukkit.simplyperms.SimplyAPI; +import net.crystalyx.bukkit.simplyperms.SimplyPlugin; + +public class ImportPrivileges extends SimplyAPI implements ImportManager { + + private SimplyPlugin plugin; + private YamlConfiguration privileges; + + public ImportPrivileges(SimplyPlugin plugin) { + super(plugin); + this.plugin = plugin; + this.privileges = new YamlConfiguration(); + } + + @Override + public void run() throws Exception { + try { + privileges.load("plugins/Privileges/config.yml"); + String defaultGroup = privileges.getString("default_group"); + plugin.getConfig().set("debug", privileges.getBoolean("debug")); + + privileges.load("plugins/Privileges/users.yml"); + for (String player : getKeys(privileges, "users")) { + addPlayerGroup(player, privileges.getString("users." + player + ".group")); + + for (String permission : privileges.getStringList("users." + player + ".permissions")) { + addPlayerPermission(player, permission, !permission.contains("-")); + } + + for (String world : getKeys(privileges, "users." + player + ".worlds")) { + for (String worldpermission : privileges.getStringList("users." + player + ".worlds." + world)) { + addPlayerPermission(player, world, worldpermission, !worldpermission.contains("-")); + } + } + } + + privileges.load("plugins/Privileges/groups.yml"); + for (String group : getKeys(privileges, "groups")) { + String simplyGroup = (group.equals(defaultGroup)) ? "default" : group; + + for (String permission : privileges.getStringList("groups." + group + ".permissions")) { + addGroupPermission(simplyGroup, permission, !permission.contains("-")); + } + + for (String world : getKeys(privileges, "groups." + group + ".worlds")) { + for (String worldpermission : privileges.getStringList("groups." + group + ".worlds." + world)) { + addGroupPermission(simplyGroup, world, worldpermission, !worldpermission.contains("-")); + } + } + + for (String inherit : privileges.getStringList("groups." + group + ".inheritance")) { + addGroupInheritance(simplyGroup, inherit); + } + } + } catch (Exception e) { + throw e; + } + } + +} diff --git a/net/crystalyx/bukkit/simplyperms/io/ConfigFile.java b/net/crystalyx/bukkit/simplyperms/io/ConfigFile.java new file mode 100755 index 0000000..4978c26 --- /dev/null +++ b/net/crystalyx/bukkit/simplyperms/io/ConfigFile.java @@ -0,0 +1,144 @@ +package net.crystalyx.bukkit.simplyperms.io; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; + +import net.crystalyx.bukkit.simplyperms.SimplyPlugin; + +public class ConfigFile implements PermsConfig { + + private SimplyPlugin plugin; + + public ConfigFile(SimplyPlugin plugin) { + this.plugin = plugin; + } + + @Override + public void removePlayer(String player) { + plugin.getConfig().set("users/" + player, null); + } + + @Override + public void removePlayerGroups(String player) { + plugin.getConfig().set("users/" + player + "/groups", null); + } + + @Override + public void removePlayerGroup(String player, String group) { + List groups = getPlayerGroups(player); + groups.remove(group); + plugin.getConfig().set("users/" + player + "/groups", (groups.isEmpty()) ? null : groups); + } + + @Override + public void addPlayerGroup(String player, String group) { + if (group.isEmpty() || group.equals("default")) return; + List groups = getPlayerGroups(player); + if (!groups.contains(group)) groups.add(group); + plugin.getConfig().set("users/" + player + "/groups", groups); + } + + @Override + public void addPlayerPermission(String player, String permission, boolean value) { + addPlayerPermission(player, "", permission, value); + } + + @Override + public void addPlayerPermission(String player, String world, String permission, boolean value) { + Map permissions = getPlayerPermissions(player, world); + if (permissions.containsKey(permission)) permissions.remove(permission); + permissions.put(permission, value); + if (!world.isEmpty()) { + plugin.getConfig().set("users/" + player + "/worlds/" + world, permissions); + } + else { + plugin.getConfig().set("users/" + player + "/permissions", permissions); + } + } + + @Override + public void removePlayerPermissions(String player) { + plugin.getConfig().set("users/" + player + "/permissions", null); + } + + @Override + public void removePlayerPermission(String player, String permission) { + removePlayerPermission(player, "", permission); + } + + @Override + public void removePlayerPermission(String player, String world, String permission) { + Map permissions = getPlayerPermissions(player, world); + permissions.remove(permission); + if (!world.isEmpty()) { + plugin.getConfig().set("users/" + player + "/worlds/" + world, (permissions.isEmpty()) ? null : permissions); + } + else { + plugin.getConfig().set("users/" + player + "/permissions", (permissions.isEmpty()) ? null : permissions); + } + } + + @Override + public List getPlayers(String group) { + List players = new ArrayList(); + for (String player : getAllPlayers()) { + for (String groupName : getPlayerGroups(player)) { + if (groupName.equals(group)) { + players.add(player); + } + } + } + return players; + } + + @Override + public List getPlayerGroups(String player) { + return plugin.getConfig().getStringList("users/" + player + "/groups"); + } + + @Override + public Map getPlayerPermissions(String player) { + return getPlayerPermissions(player, ""); + } + + @Override + public Map getPlayerPermissions(String player, String world) { + Map finalPerms = new HashMap(); + String permNode = (!world.isEmpty()) ? "users/" + player + "/worlds/" + world : "users/" + player + "/permissions"; + if (plugin.getConfig().getConfigurationSection(permNode) != null) { + for (Entry permPlayer : plugin.getConfig().getConfigurationSection(permNode).getValues(false).entrySet()) { + finalPerms.put(permPlayer.getKey(), (Boolean) permPlayer.getValue()); + } + } + return finalPerms; + } + + @Override + public boolean isPlayerInDB(String player) { + return plugin.getConfig().getConfigurationSection("users/" + player) != null; + } + + @Override + public List getPlayerWorlds(String player) { + if (plugin.getConfig().getConfigurationSection("users/" + player + "/worlds") != null) { + return new ArrayList(plugin.getConfig().getConfigurationSection("users/" + player + "/worlds").getKeys(false)); + } + else { + return new ArrayList(); + } + } + + @Override + public List getAllPlayers() { + if (plugin.getConfig().getConfigurationSection("users") != null) { + return new ArrayList(plugin.getConfig().getConfigurationSection("users").getKeys(false)); + } + else { + return new ArrayList(); + } + } + +} diff --git a/net/crystalyx/bukkit/simplyperms/io/ConfigSQL.java b/net/crystalyx/bukkit/simplyperms/io/ConfigSQL.java new file mode 100755 index 0000000..dfc23ea --- /dev/null +++ b/net/crystalyx/bukkit/simplyperms/io/ConfigSQL.java @@ -0,0 +1,330 @@ +package net.crystalyx.bukkit.simplyperms.io; + +import java.sql.DriverManager; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.sql.Connection; + +import net.crystalyx.bukkit.simplyperms.SimplyPlugin; + +public class ConfigSQL implements PermsConfig { + + private SimplyPlugin plugin; + private Connection connection; + private String table_players; + private String table_groups; + private String column_playerid; + private String column_groupname; + private String column_permission; + private String column_world; + private String column_value; + private String column_date; + + public ConfigSQL(SimplyPlugin plugin) { + this.plugin = plugin; + table_players = plugin.getConfig().getString("db/table/players"); + table_groups = plugin.getConfig().getString("db/table/groups"); + column_playerid = plugin.getConfig().getString("db/column/playerid"); + column_groupname = plugin.getConfig().getString("db/column/groupname"); + column_permission = plugin.getConfig().getString("db/column/permission"); + column_world = plugin.getConfig().getString("db/column/world"); + column_value = plugin.getConfig().getString("db/column/value"); + column_date = plugin.getConfig().getString("db/column/date"); + } + + private boolean init() { + try { + if (connection != null) { + connection.close(); + } + connection = DriverManager.getConnection("jdbc:" + + plugin.getConfig().getString("db/type") + "://" + + plugin.getConfig().getString("db/host") + ":" + + plugin.getConfig().getString("db/port") + "/" + + plugin.getConfig().getString("db/database"), + plugin.getConfig().getString("db/user"), + plugin.getConfig().getString("db/pass")); + return true; + } catch (SQLException e) { + plugin.debug(e.getMessage()); + return false; + } + } + + public boolean checkDatabase() { + if (init()) { + String date = (!column_date.isEmpty()) ? column_date + " DATETIME," : ""; + try { + PreparedStatement sql = connection.prepareStatement("CREATE TABLE IF NOT EXISTS " + table_players + "(" + column_playerid + " VARCHAR(16) NOT NULL, " + column_world + " VARCHAR(30) NOT NULL, " + column_permission + " VARCHAR(100) NOT NULL, " + column_value + " SMALLINT NOT NULL, " + date + " PRIMARY KEY (" + column_playerid + ", " + column_world + ", " + column_permission + "))"); + sql.executeUpdate(); + } catch (SQLException e) { + plugin.debug(e.getMessage()); + return false; + } + try { + PreparedStatement sql = connection.prepareStatement("CREATE TABLE IF NOT EXISTS " + table_groups + "(" + column_playerid + " VARCHAR(16) NOT NULL, " + column_groupname + " VARCHAR(30) NOT NULL, " + date + " PRIMARY KEY (" + column_playerid + ", " + column_groupname + "))"); + sql.executeUpdate(); + } catch (SQLException e) { + plugin.debug(e.getMessage()); + return false; + } + return true; + } + return false; + } + + @Override + public void removePlayer(String player) { + removePlayerPermissions(player); + removePlayerGroups(player); + } + + @Override + public void removePlayerGroups(String player) { + if (init()) { + try { + PreparedStatement sql = connection.prepareStatement("DELETE FROM " + table_groups + " WHERE " + column_playerid + " = ?"); + sql.setString(1, player); + sql.executeUpdate(); + } catch (SQLException e) { + plugin.debug(e.getMessage()); + } + } + } + + @Override + public void removePlayerGroup(String player, String group) { + if (init()) { + try { + PreparedStatement sql = connection.prepareStatement("DELETE FROM " + table_groups + " WHERE " + column_playerid + " = ? AND " + column_groupname + " = ?"); + sql.setString(1, player); + sql.setString(2, group); + sql.executeUpdate(); + } catch (SQLException e) { + plugin.debug(e.getMessage()); + } + } + } + + private void addPlayerGroup(String player, String group, boolean first) { + if (init()) { + try { + PreparedStatement sql = connection.prepareStatement("INSERT INTO " + table_groups + "(" + column_playerid + ", " + column_groupname + ((!column_date.isEmpty()) ? ", " + column_date : "") + ") VALUES(?, ?" + ((!column_date.isEmpty()) ? ", NOW()" : "") + ")"); + sql.setString(1, player); + sql.setString(2, group); + sql.executeUpdate(); + } catch (SQLException e) { + if (first) { + removePlayerGroup(player, group); + addPlayerGroup(player, group, false); + } + else { + plugin.debug(e.getMessage()); + } + } + } + } + + @Override + public void addPlayerGroup(String player, String group) { + addPlayerGroup(player, group, true); + } + + private void addPlayerPermission(String player, String world, String permission, boolean value, boolean first) { + if (init()) { + try { + PreparedStatement sql = connection.prepareStatement("INSERT INTO " + table_players + "(" + column_playerid + ", " + column_world + ", " + column_permission + ", " + column_value + ((!column_date.isEmpty()) ? ", " + column_date : "") + ") VALUES(?, ?, ?, ?" + ((!column_date.isEmpty()) ? ", NOW()" : "") + ")"); + sql.setString(1, player); + sql.setString(2, world); + sql.setString(3, permission); + sql.setBoolean(4, value); + sql.executeUpdate(); + } catch (SQLException e) { + if (first) { + removePlayerPermission(player, world, permission); + addPlayerPermission(player, world, permission, value, false); + } + else { + plugin.debug(e.getMessage()); + } + } + } + } + + @Override + public void addPlayerPermission(String player, String permission, boolean value) { + addPlayerPermission(player, "", permission, value); + } + + @Override + public void addPlayerPermission(String player, String world, String permission, boolean value) { + addPlayerPermission(player, world, permission, value, true); + } + + @Override + public void removePlayerPermissions(String player) { + if (init()) { + try { + PreparedStatement sql = connection.prepareStatement("DELETE FROM " + table_players + " WHERE " + column_playerid + " = ?"); + sql.setString(1, player); + sql.executeUpdate(); + } catch (SQLException e) { + plugin.debug(e.getMessage()); + } + } + } + + @Override + public void removePlayerPermission(String player, String permission) { + removePlayerPermission(player, "", permission); + } + + @Override + public void removePlayerPermission(String player, String world, String permission) { + if (init()) { + try { + PreparedStatement sql = connection.prepareStatement("DELETE FROM " + table_players + " WHERE " + column_playerid + " = ? AND " + column_world + " = ? AND " + column_permission + " = ?"); + sql.setString(1, player); + sql.setString(2, world); + sql.setString(3, permission); + sql.executeUpdate(); + } catch (SQLException e) { + plugin.debug(e.getMessage()); + } + } + } + + @Override + public List getPlayers(String group) { + List results = new ArrayList(); + if (init()) { + try { + PreparedStatement sql = connection.prepareStatement("SELECT " + column_playerid + " FROM " + table_groups + " WHERE " + column_groupname + " = ?"); + sql.setString(1, group); + ResultSet players = sql.executeQuery(); + while (players.next()) { + results.add(players.getString(column_playerid)); + } + } catch (SQLException e) { + plugin.debug(e.getMessage()); + } + } + return results; + } + + @Override + public List getPlayerGroups(String player) { + List results = new ArrayList(); + if (init()) { + try { + PreparedStatement sql = connection.prepareStatement("SELECT " + column_groupname + " FROM " + table_groups + " WHERE " + column_playerid + " = ?"); + sql.setString(1, player); + ResultSet players = sql.executeQuery(); + while (players.next()) { + results.add(players.getString(column_groupname)); + } + } catch (SQLException e) { + plugin.debug(e.getMessage()); + } + } + return results; + } + + @Override + public Map getPlayerPermissions(String player) { + return getPlayerPermissions(player, ""); + } + + @Override + public Map getPlayerPermissions(String player, String world) { + Map results = new HashMap(); + if (init()) { + try { + PreparedStatement sql = connection.prepareStatement("SELECT " + column_permission + ", " + column_value + " FROM " + table_players + " WHERE " + column_playerid + " = ? AND " + column_world + " = ?"); + sql.setString(1, player); + sql.setString(2, world); + ResultSet permissions = sql.executeQuery(); + while (permissions.next()) { + results.put(permissions.getString(column_permission), permissions.getBoolean(column_value)); + } + } catch (SQLException e) { + plugin.debug(e.getMessage()); + } + } + return results; + } + + @Override + public boolean isPlayerInDB(String player) { + if (init()) { + try { + int count = 0; + PreparedStatement sql = connection.prepareStatement("SELECT COUNT(" + column_playerid + ") FROM " + table_groups + " WHERE " + column_playerid + " = ?"); + sql.setString(1, player); + ResultSet results = sql.executeQuery(); + if (results.next()) { + count += results.getInt(1); + } + sql = connection.prepareStatement("SELECT COUNT(" + column_playerid + ") FROM " + table_players + " WHERE " + column_playerid + " = ?"); + sql.setString(1, player); + results = sql.executeQuery(); + if (results.next()) { + count += results.getInt(1); + } + return count > 0; + } catch (SQLException e) { + plugin.debug(e.getMessage()); + return false; + } + } + return false; + } + + @Override + public List getPlayerWorlds(String player) { + List results = new ArrayList(); + if (init()) { + try { + PreparedStatement sql = connection.prepareStatement("SELECT " + column_world + " FROM " + table_players + " WHERE " + column_playerid + " = ?"); + sql.setString(1, player); + ResultSet players = sql.executeQuery(); + while (players.next()) { + results.add(players.getString(column_world)); + } + } catch (SQLException e) { + plugin.debug(e.getMessage()); + } + } + return results; + } + + @Override + public List getAllPlayers() { + List results = new ArrayList(); + if (init()) { + try { + PreparedStatement sql = connection.prepareStatement("SELECT " + column_playerid + " FROM " + table_groups + " GROUP BY " + column_playerid); + ResultSet players = sql.executeQuery(); + while (players.next()) { + results.add(players.getString(column_playerid)); + } + sql = connection.prepareStatement("SELECT " + column_playerid + " FROM " + table_players + " GROUP BY " + column_playerid); + players = sql.executeQuery(); + while (players.next()) { + if (!results.contains(players.getString(column_playerid))) { + results.add(players.getString(column_playerid)); + } + } + } catch (SQLException e) { + plugin.debug(e.getMessage()); + } + } + return results; + } + +} diff --git a/net/crystalyx/bukkit/simplyperms/io/PermsConfig.java b/net/crystalyx/bukkit/simplyperms/io/PermsConfig.java new file mode 100755 index 0000000..fef0afc --- /dev/null +++ b/net/crystalyx/bukkit/simplyperms/io/PermsConfig.java @@ -0,0 +1,40 @@ +package net.crystalyx.bukkit.simplyperms.io; + +import java.util.List; +import java.util.Map; + +public interface PermsConfig { + + public void removePlayer(String player); + + public void removePlayerGroups(String player); + + public void removePlayerGroup(String player, String group); + + public void addPlayerGroup(String player, String group); + + public void addPlayerPermission(String player, String permission, boolean value); + + public void addPlayerPermission(String player, String world, String permission, boolean value); + + public void removePlayerPermissions(String player); + + public void removePlayerPermission(String player, String permission); + + public void removePlayerPermission(String player, String world, String permission); + + public List getPlayers(String group); + + public List getPlayerGroups(String player); + + public Map getPlayerPermissions(String player); + + public Map getPlayerPermissions(String player, String world); + + public boolean isPlayerInDB(String player); + + public List getPlayerWorlds(String player); + + public List getAllPlayers(); + +} diff --git a/net/crystalyx/bukkit/simplyperms/preventions/Bow.java b/net/crystalyx/bukkit/simplyperms/preventions/Bow.java new file mode 100755 index 0000000..d41d6e1 --- /dev/null +++ b/net/crystalyx/bukkit/simplyperms/preventions/Bow.java @@ -0,0 +1,26 @@ +package net.crystalyx.bukkit.simplyperms.preventions; + +import net.crystalyx.bukkit.simplyperms.SimplyPlugin; +import net.crystalyx.bukkit.simplyperms.SimplyPrevents; + +import org.bukkit.entity.Entity; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.entity.EntityShootBowEvent; + +public class Bow extends SimplyPrevents { + + public Bow(SimplyPlugin plugin) { + super(plugin); + } + + @EventHandler(priority = EventPriority.LOWEST) + public void bow(EntityShootBowEvent event) { + Entity shooter = event.getEntity(); + if (shooter instanceof Player) { + prevent(event, (Player) shooter, "bow"); + } + } + +} diff --git a/net/crystalyx/bukkit/simplyperms/preventions/Changesign.java b/net/crystalyx/bukkit/simplyperms/preventions/Changesign.java new file mode 100755 index 0000000..c52e1fc --- /dev/null +++ b/net/crystalyx/bukkit/simplyperms/preventions/Changesign.java @@ -0,0 +1,21 @@ +package net.crystalyx.bukkit.simplyperms.preventions; + +import net.crystalyx.bukkit.simplyperms.SimplyPlugin; +import net.crystalyx.bukkit.simplyperms.SimplyPrevents; + +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.block.SignChangeEvent; + +public class Changesign extends SimplyPrevents { + + public Changesign(SimplyPlugin plugin) { + super(plugin); + } + + @EventHandler(priority = EventPriority.LOWEST) + public void changesign(SignChangeEvent event) { + prevent(event, event.getPlayer(), "changesign"); + } + +} diff --git a/net/crystalyx/bukkit/simplyperms/preventions/Chat.java b/net/crystalyx/bukkit/simplyperms/preventions/Chat.java new file mode 100755 index 0000000..4dfb48a --- /dev/null +++ b/net/crystalyx/bukkit/simplyperms/preventions/Chat.java @@ -0,0 +1,23 @@ +package net.crystalyx.bukkit.simplyperms.preventions; + +import net.crystalyx.bukkit.simplyperms.SimplyPlugin; +import net.crystalyx.bukkit.simplyperms.SimplyPrevents; + +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.player.PlayerChatEvent; + +public class Chat extends SimplyPrevents { + + public Chat(SimplyPlugin plugin) { + super(plugin); + } + + @EventHandler(priority = EventPriority.LOWEST) + public void chat(PlayerChatEvent event) { + if (!event.getMessage().startsWith("u00a74u00a75u00a73u00a74")) { + prevent(event, event.getPlayer(), "chat"); + } + } + +} diff --git a/net/crystalyx/bukkit/simplyperms/preventions/Command.java b/net/crystalyx/bukkit/simplyperms/preventions/Command.java new file mode 100755 index 0000000..88ddce8 --- /dev/null +++ b/net/crystalyx/bukkit/simplyperms/preventions/Command.java @@ -0,0 +1,31 @@ +package net.crystalyx.bukkit.simplyperms.preventions; + +import net.crystalyx.bukkit.simplyperms.SimplyPlugin; +import net.crystalyx.bukkit.simplyperms.SimplyPrevents; + +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.player.PlayerCommandPreprocessEvent; + +public class Command extends SimplyPrevents { + + public Command(SimplyPlugin plugin) { + super(plugin); + } + + @EventHandler(priority = EventPriority.LOWEST) + public void command(PlayerCommandPreprocessEvent event) { + String message = event.getMessage(); + if (message.startsWith("/")) { + message = message.substring(1).trim(); + int spaceIndex = message.indexOf(' '); + if (spaceIndex >= 0) { + message = message.substring(0, spaceIndex); + } + if (message.length() > 0) { + prevent(event, event.getPlayer(), "command." + message); + } + } + } + +} diff --git a/net/crystalyx/bukkit/simplyperms/preventions/Damage.java b/net/crystalyx/bukkit/simplyperms/preventions/Damage.java new file mode 100755 index 0000000..3bb5544 --- /dev/null +++ b/net/crystalyx/bukkit/simplyperms/preventions/Damage.java @@ -0,0 +1,47 @@ +package net.crystalyx.bukkit.simplyperms.preventions; + +import java.util.Collection; + +import net.crystalyx.bukkit.simplyperms.SimplyPlugin; +import net.crystalyx.bukkit.simplyperms.SimplyPrevents; + +import org.bukkit.entity.Entity; +import org.bukkit.entity.LivingEntity; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.entity.EntityDamageEvent; +import org.bukkit.event.entity.PotionSplashEvent; + +public class Damage extends SimplyPrevents { + + public Damage(SimplyPlugin plugin) { + super(plugin); + } + + @EventHandler(priority = EventPriority.LOWEST) + public void damage(EntityDamageEvent event) { + Entity entity = event.getEntity(); + if (entity instanceof Player) { + Player player = (Player) entity; + if (prevent(event, player, "damage")) { + player.setFireTicks(0); + } + } + } + + @EventHandler(priority = EventPriority.LOWEST) + public void damagePotion(PotionSplashEvent event) { + Collection affectedEntities = event.getAffectedEntities(); + + for (LivingEntity entity : affectedEntities) { + if (entity instanceof Player) { + Player affectedPlayer = (Player) entity; + if (prevent(event, affectedPlayer, "damage")) { + affectedEntities.remove(entity); + } + } + } + } + +} diff --git a/net/crystalyx/bukkit/simplyperms/preventions/Fight.java b/net/crystalyx/bukkit/simplyperms/preventions/Fight.java new file mode 100755 index 0000000..e1d3184 --- /dev/null +++ b/net/crystalyx/bukkit/simplyperms/preventions/Fight.java @@ -0,0 +1,33 @@ +package net.crystalyx.bukkit.simplyperms.preventions; + +import net.crystalyx.bukkit.simplyperms.SimplyPlugin; +import net.crystalyx.bukkit.simplyperms.SimplyPrevents; + +import org.bukkit.entity.Entity; +import org.bukkit.entity.LivingEntity; +import org.bukkit.entity.Player; +import org.bukkit.entity.Projectile; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.entity.EntityDamageByEntityEvent; + +public class Fight extends SimplyPrevents { + + public Fight(SimplyPlugin plugin) { + super(plugin); + } + + @EventHandler(priority = EventPriority.LOWEST) + public void fight(EntityDamageByEntityEvent event) { + Entity damager = event.getDamager(); + if (damager instanceof Player) { + prevent(event, (Player) damager, "fight"); + } else if (damager instanceof Projectile) { + LivingEntity shooter = ((Projectile) damager).getShooter(); + if (shooter instanceof Player) { + prevent(event, (Player) shooter, "fight"); + } + } + } + +} diff --git a/net/crystalyx/bukkit/simplyperms/preventions/Hunger.java b/net/crystalyx/bukkit/simplyperms/preventions/Hunger.java new file mode 100755 index 0000000..ee8c5f2 --- /dev/null +++ b/net/crystalyx/bukkit/simplyperms/preventions/Hunger.java @@ -0,0 +1,26 @@ +package net.crystalyx.bukkit.simplyperms.preventions; + +import net.crystalyx.bukkit.simplyperms.SimplyPlugin; +import net.crystalyx.bukkit.simplyperms.SimplyPrevents; + +import org.bukkit.entity.Entity; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.entity.FoodLevelChangeEvent; + +public class Hunger extends SimplyPrevents { + + public Hunger(SimplyPlugin plugin) { + super(plugin); + } + + @EventHandler(priority = EventPriority.LOWEST) + public void hunger(FoodLevelChangeEvent event) { + Entity entity = event.getEntity(); + if (entity instanceof Player) { + prevent(event, (Player) entity, "hunger"); + } + } + +} diff --git a/net/crystalyx/bukkit/simplyperms/preventions/Item.java b/net/crystalyx/bukkit/simplyperms/preventions/Item.java new file mode 100755 index 0000000..8ded30b --- /dev/null +++ b/net/crystalyx/bukkit/simplyperms/preventions/Item.java @@ -0,0 +1,32 @@ +package net.crystalyx.bukkit.simplyperms.preventions; + +import net.crystalyx.bukkit.simplyperms.SimplyPlugin; +import net.crystalyx.bukkit.simplyperms.SimplyPrevents; + +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.Event.Result; +import org.bukkit.event.block.Action; +import org.bukkit.event.player.PlayerInteractEvent; +import org.bukkit.inventory.ItemStack; + +public class Item extends SimplyPrevents { + + public Item(SimplyPlugin plugin) { + super(plugin); + } + + @EventHandler(priority = EventPriority.LOWEST) + public void item(PlayerInteractEvent event) { + if (event.getAction() != Action.PHYSICAL) { + ItemStack itemInHand = event.getItem(); + if (itemInHand != null) { + if (prevent(event, event.getPlayer(), "item." + itemInHand.getTypeId())) { + event.setUseInteractedBlock(Result.DENY); + event.setUseItemInHand(Result.DENY); + } + } + } + } + +} diff --git a/net/crystalyx/bukkit/simplyperms/preventions/Monster.java b/net/crystalyx/bukkit/simplyperms/preventions/Monster.java new file mode 100755 index 0000000..6cd488f --- /dev/null +++ b/net/crystalyx/bukkit/simplyperms/preventions/Monster.java @@ -0,0 +1,26 @@ +package net.crystalyx.bukkit.simplyperms.preventions; + +import net.crystalyx.bukkit.simplyperms.SimplyPlugin; +import net.crystalyx.bukkit.simplyperms.SimplyPrevents; + +import org.bukkit.entity.Entity; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.entity.EntityTargetEvent; + +public class Monster extends SimplyPrevents { + + public Monster(SimplyPlugin plugin) { + super(plugin); + } + + @EventHandler(priority = EventPriority.LOWEST) + public void monster(EntityTargetEvent event) { + Entity target = event.getTarget(); + if (target instanceof Player) { + prevent(event, (Player) target, "monster"); + } + } + +} diff --git a/net/crystalyx/bukkit/simplyperms/preventions/Sneak.java b/net/crystalyx/bukkit/simplyperms/preventions/Sneak.java new file mode 100755 index 0000000..09c34c9 --- /dev/null +++ b/net/crystalyx/bukkit/simplyperms/preventions/Sneak.java @@ -0,0 +1,28 @@ +package net.crystalyx.bukkit.simplyperms.preventions; + +import net.crystalyx.bukkit.simplyperms.SimplyPlugin; +import net.crystalyx.bukkit.simplyperms.SimplyPrevents; + +import org.bukkit.GameMode; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.player.PlayerToggleSneakEvent; + +public class Sneak extends SimplyPrevents { + + public Sneak(SimplyPlugin plugin) { + super(plugin); + } + + @EventHandler(priority = EventPriority.LOWEST) + public void sneak(PlayerToggleSneakEvent event) { + Player player = event.getPlayer(); + if (event.isSneaking()) { + if (!player.getGameMode().equals(GameMode.CREATIVE)) { + prevent(event, player, "sneak"); + } + } + } + +} diff --git a/net/crystalyx/bukkit/simplyperms/preventions/Vehicle.java b/net/crystalyx/bukkit/simplyperms/preventions/Vehicle.java new file mode 100755 index 0000000..505ac36 --- /dev/null +++ b/net/crystalyx/bukkit/simplyperms/preventions/Vehicle.java @@ -0,0 +1,70 @@ +package net.crystalyx.bukkit.simplyperms.preventions; + +import net.crystalyx.bukkit.simplyperms.SimplyPlugin; +import net.crystalyx.bukkit.simplyperms.SimplyPrevents; + +import org.bukkit.Material; +import org.bukkit.entity.Entity; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.block.Action; +import org.bukkit.event.player.PlayerInteractEvent; +import org.bukkit.event.vehicle.VehicleDestroyEvent; +import org.bukkit.event.vehicle.VehicleEnterEvent; +import org.bukkit.event.vehicle.VehicleEntityCollisionEvent; + +public class Vehicle extends SimplyPrevents { + + public Vehicle(SimplyPlugin plugin) { + super(plugin); + } + + @EventHandler(priority = EventPriority.LOWEST) + public void vehicleEnter(VehicleEnterEvent event) { + Entity entered = event.getEntered(); + if (entered instanceof Player) { + prevent(event, (Player) entered, "vehicle"); + } + } + + @EventHandler(priority = EventPriority.LOWEST) + public void vehicleDestroy(VehicleDestroyEvent event) { + Entity attacker = event.getAttacker(); + if (attacker instanceof Player) { + prevent(event, (Player) attacker, "vehicle"); + } + } + + @EventHandler(priority = EventPriority.LOWEST) + public void vehicleCollision(VehicleEntityCollisionEvent event) { + Entity collider = event.getEntity(); + if (collider instanceof Player) { + if (prevent(event, (Player) collider, "vehicle")) { + event.setCollisionCancelled(true); + event.setPickupCancelled(true); + } + } + } + + @EventHandler(priority = EventPriority.LOWEST) + public void vehicle(PlayerInteractEvent event) { + if (event.getAction() == Action.RIGHT_CLICK_BLOCK) { + Material clickedMaterial = event.getClickedBlock().getType(); + Player player = event.getPlayer(); + Material materialInHand = player.getItemInHand().getType(); + if (clickedMaterial == Material.RAILS + || clickedMaterial == Material.POWERED_RAIL + || clickedMaterial == Material.DETECTOR_RAIL) { + if (materialInHand == Material.MINECART + || materialInHand == Material.POWERED_MINECART + || materialInHand == Material.STORAGE_MINECART) { + prevent(event, player, "vehicle"); + } + } else if (materialInHand == Material.BOAT) { + prevent(event, player, "vehicle"); + } + } + } + +} diff --git a/net/crystalyx/bukkit/simplyperms/preventions/animals/Shear.java b/net/crystalyx/bukkit/simplyperms/preventions/animals/Shear.java new file mode 100755 index 0000000..184c0fb --- /dev/null +++ b/net/crystalyx/bukkit/simplyperms/preventions/animals/Shear.java @@ -0,0 +1,21 @@ +package net.crystalyx.bukkit.simplyperms.preventions.animals; + +import net.crystalyx.bukkit.simplyperms.SimplyPlugin; +import net.crystalyx.bukkit.simplyperms.SimplyPrevents; + +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.player.PlayerShearEntityEvent; + +public class Shear extends SimplyPrevents { + + public Shear(SimplyPlugin plugin) { + super(plugin); + } + + @EventHandler(priority = EventPriority.LOWEST) + public void shear(PlayerShearEntityEvent event) { + prevent(event, event.getPlayer(), "shear,animals,interact"); + } + +} diff --git a/net/crystalyx/bukkit/simplyperms/preventions/animals/Tame.java b/net/crystalyx/bukkit/simplyperms/preventions/animals/Tame.java new file mode 100755 index 0000000..2fec576 --- /dev/null +++ b/net/crystalyx/bukkit/simplyperms/preventions/animals/Tame.java @@ -0,0 +1,24 @@ +package net.crystalyx.bukkit.simplyperms.preventions.animals; + +import net.crystalyx.bukkit.simplyperms.SimplyPlugin; +import net.crystalyx.bukkit.simplyperms.SimplyPrevents; + +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.entity.EntityTameEvent; + +public class Tame extends SimplyPrevents { + + public Tame(SimplyPlugin plugin) { + super(plugin); + } + + @EventHandler(priority = EventPriority.LOWEST) + public void tame(EntityTameEvent event) { + if (event.getOwner() instanceof Player) { + prevent(event, (Player) event.getOwner(), "tame,animals,interact"); + } + } + +} diff --git a/net/crystalyx/bukkit/simplyperms/preventions/bucket/Lavabucket.java b/net/crystalyx/bukkit/simplyperms/preventions/bucket/Lavabucket.java new file mode 100755 index 0000000..f24ec62 --- /dev/null +++ b/net/crystalyx/bukkit/simplyperms/preventions/bucket/Lavabucket.java @@ -0,0 +1,32 @@ +package net.crystalyx.bukkit.simplyperms.preventions.bucket; + +import net.crystalyx.bukkit.simplyperms.SimplyPlugin; +import net.crystalyx.bukkit.simplyperms.SimplyPrevents; + +import org.bukkit.Material; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.player.PlayerBucketEmptyEvent; +import org.bukkit.event.player.PlayerBucketFillEvent; + +public class Lavabucket extends SimplyPrevents { + + public Lavabucket(SimplyPlugin plugin) { + super(plugin); + } + + @EventHandler(priority = EventPriority.LOWEST) + public void lavabucketEmpty(PlayerBucketEmptyEvent event) { + if (event.getBucket() == Material.LAVA_BUCKET) { + prevent(event, event.getPlayer(), "lavabucket,bucket,interact"); + } + } + + @EventHandler(priority = EventPriority.LOWEST) + public void lavabucketFill(PlayerBucketFillEvent event) { + if (event.getItemStack().getType() == Material.LAVA_BUCKET) { + prevent(event, event.getPlayer(), "lavabucket,bucket,interact"); + } + } + +} diff --git a/net/crystalyx/bukkit/simplyperms/preventions/bucket/Milking.java b/net/crystalyx/bukkit/simplyperms/preventions/bucket/Milking.java new file mode 100755 index 0000000..41d21e2 --- /dev/null +++ b/net/crystalyx/bukkit/simplyperms/preventions/bucket/Milking.java @@ -0,0 +1,24 @@ +package net.crystalyx.bukkit.simplyperms.preventions.bucket; + +import net.crystalyx.bukkit.simplyperms.SimplyPlugin; +import net.crystalyx.bukkit.simplyperms.SimplyPrevents; + +import org.bukkit.Material; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.player.PlayerBucketFillEvent; + +public class Milking extends SimplyPrevents { + + public Milking(SimplyPlugin plugin) { + super(plugin); + } + + @EventHandler(priority = EventPriority.LOWEST) + public void milking(PlayerBucketFillEvent event) { + if (event.getItemStack().getType() == Material.MILK_BUCKET) { + prevent(event, event.getPlayer(), "milking,bucket,interact"); + } + } + +} diff --git a/net/crystalyx/bukkit/simplyperms/preventions/bucket/Waterbucket.java b/net/crystalyx/bukkit/simplyperms/preventions/bucket/Waterbucket.java new file mode 100755 index 0000000..403855c --- /dev/null +++ b/net/crystalyx/bukkit/simplyperms/preventions/bucket/Waterbucket.java @@ -0,0 +1,32 @@ +package net.crystalyx.bukkit.simplyperms.preventions.bucket; + +import net.crystalyx.bukkit.simplyperms.SimplyPlugin; +import net.crystalyx.bukkit.simplyperms.SimplyPrevents; + +import org.bukkit.Material; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.player.PlayerBucketEmptyEvent; +import org.bukkit.event.player.PlayerBucketFillEvent; + +public class Waterbucket extends SimplyPrevents { + + public Waterbucket(SimplyPlugin plugin) { + super(plugin); + } + + @EventHandler(priority = EventPriority.LOWEST) + public void waterbucketEmpty(PlayerBucketEmptyEvent event) { + if (event.getBucket() == Material.WATER_BUCKET) { + prevent(event, event.getPlayer(), "waterbucket,bucket,interact"); + } + } + + @EventHandler(priority = EventPriority.LOWEST) + public void waterbucketFill(PlayerBucketFillEvent event) { + if (event.getItemStack().getType() == Material.WATER_BUCKET) { + prevent(event, event.getPlayer(), "waterbucket,bucket,interact"); + } + } + +} diff --git a/net/crystalyx/bukkit/simplyperms/preventions/build/Breakblock.java b/net/crystalyx/bukkit/simplyperms/preventions/build/Breakblock.java new file mode 100755 index 0000000..66d3f5d --- /dev/null +++ b/net/crystalyx/bukkit/simplyperms/preventions/build/Breakblock.java @@ -0,0 +1,49 @@ +package net.crystalyx.bukkit.simplyperms.preventions.build; + +import net.crystalyx.bukkit.simplyperms.SimplyPlugin; +import net.crystalyx.bukkit.simplyperms.SimplyPrevents; + +import org.bukkit.Material; +import org.bukkit.block.BlockFace; +import org.bukkit.entity.Entity; +import org.bukkit.entity.Player; +import org.bukkit.event.Event.Result; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.block.Action; +import org.bukkit.event.block.BlockBreakEvent; +import org.bukkit.event.painting.PaintingBreakByEntityEvent; +import org.bukkit.event.player.PlayerInteractEvent; + +public class Breakblock extends SimplyPrevents { + + public Breakblock(SimplyPlugin plugin) { + super(plugin); + } + + @EventHandler(priority = EventPriority.LOWEST) + public void breakblock(BlockBreakEvent event) { + prevent(event, event.getPlayer(), "breakblock." + event.getBlock().getTypeId() + ",build." + event.getBlock().getTypeId()); + } + + @EventHandler(priority = EventPriority.LOWEST) + public void paintingBreakblock(PaintingBreakByEntityEvent event) { + Entity remover = event.getRemover(); + if (remover instanceof Player) { + prevent(event, (Player) remover, "breakblock." + Material.PAINTING.getId() + ",build." + Material.PAINTING.getId()); + } + } + + @EventHandler(priority = EventPriority.LOWEST) + public void fireBreakblock(PlayerInteractEvent event) { + if (event.getAction() == Action.LEFT_CLICK_BLOCK) { + if (event.getClickedBlock().getRelative(BlockFace.UP).getType() == Material.FIRE) { + if (prevent(event, event.getPlayer(), "breakblock." + Material.FIRE.getId() + ",build." + Material.FIRE.getId())) { + event.setUseInteractedBlock(Result.DENY); + event.setUseItemInHand(Result.DENY); + } + } + } + } + +} diff --git a/net/crystalyx/bukkit/simplyperms/preventions/build/Placeblock.java b/net/crystalyx/bukkit/simplyperms/preventions/build/Placeblock.java new file mode 100755 index 0000000..563a861 --- /dev/null +++ b/net/crystalyx/bukkit/simplyperms/preventions/build/Placeblock.java @@ -0,0 +1,28 @@ +package net.crystalyx.bukkit.simplyperms.preventions.build; + +import net.crystalyx.bukkit.simplyperms.SimplyPlugin; +import net.crystalyx.bukkit.simplyperms.SimplyPrevents; + +import org.bukkit.Material; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.block.BlockPlaceEvent; +import org.bukkit.event.painting.PaintingPlaceEvent; + +public class Placeblock extends SimplyPrevents { + + public Placeblock(SimplyPlugin plugin) { + super(plugin); + } + + @EventHandler(priority = EventPriority.LOWEST) + public void placeblock(BlockPlaceEvent event) { + prevent(event, event.getPlayer(), "placeblock." + event.getBlockPlaced().getTypeId() + ",build." + event.getBlockPlaced().getTypeId()); + } + + @EventHandler(priority = EventPriority.LOWEST) + public void paintingPlaceblock(PaintingPlaceEvent event) { + prevent(event, event.getPlayer(), "placeblock." + Material.PAINTING.getId() + ",build." + Material.PAINTING.getId()); + } + +} diff --git a/net/crystalyx/bukkit/simplyperms/preventions/craft/Brew.java b/net/crystalyx/bukkit/simplyperms/preventions/craft/Brew.java new file mode 100755 index 0000000..830cd56 --- /dev/null +++ b/net/crystalyx/bukkit/simplyperms/preventions/craft/Brew.java @@ -0,0 +1,27 @@ +package net.crystalyx.bukkit.simplyperms.preventions.craft; + +import net.crystalyx.bukkit.simplyperms.SimplyPlugin; +import net.crystalyx.bukkit.simplyperms.SimplyPrevents; + +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.inventory.InventoryOpenEvent; +import org.bukkit.event.inventory.InventoryType; + +public class Brew extends SimplyPrevents { + + public Brew(SimplyPlugin plugin) { + super(plugin); + } + + @EventHandler(priority = EventPriority.LOWEST) + public void brew(InventoryOpenEvent event) { + if (event.getInventory().getType() == InventoryType.BREWING) { + if (event.getPlayer() instanceof Player) { + prevent(event, (Player) event.getPlayer(), "brew,craft"); + } + } + } + +} diff --git a/net/crystalyx/bukkit/simplyperms/preventions/craft/Chest.java b/net/crystalyx/bukkit/simplyperms/preventions/craft/Chest.java new file mode 100755 index 0000000..5522240 --- /dev/null +++ b/net/crystalyx/bukkit/simplyperms/preventions/craft/Chest.java @@ -0,0 +1,29 @@ +package net.crystalyx.bukkit.simplyperms.preventions.craft; + +import net.crystalyx.bukkit.simplyperms.SimplyPlugin; +import net.crystalyx.bukkit.simplyperms.SimplyPrevents; + +import org.bukkit.Material; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.Event.Result; +import org.bukkit.event.block.Action; +import org.bukkit.event.player.PlayerInteractEvent; + +public class Chest extends SimplyPrevents { + + public Chest(SimplyPlugin plugin) { + super(plugin); + } + + @EventHandler(priority = EventPriority.LOWEST) + public void chestPlayerInteract(PlayerInteractEvent event) { + if (event.getAction() == Action.RIGHT_CLICK_BLOCK + && event.getClickedBlock().getType() == Material.CHEST) { + if (prevent(event, event.getPlayer(), "chest,craft")) { + event.setUseInteractedBlock(Result.DENY); + } + } + } + +} diff --git a/net/crystalyx/bukkit/simplyperms/preventions/craft/Dispenser.java b/net/crystalyx/bukkit/simplyperms/preventions/craft/Dispenser.java new file mode 100755 index 0000000..d350b36 --- /dev/null +++ b/net/crystalyx/bukkit/simplyperms/preventions/craft/Dispenser.java @@ -0,0 +1,27 @@ +package net.crystalyx.bukkit.simplyperms.preventions.craft; + +import net.crystalyx.bukkit.simplyperms.SimplyPlugin; +import net.crystalyx.bukkit.simplyperms.SimplyPrevents; + +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.inventory.InventoryOpenEvent; +import org.bukkit.event.inventory.InventoryType; + +public class Dispenser extends SimplyPrevents { + + public Dispenser(SimplyPlugin plugin) { + super(plugin); + } + + @EventHandler(priority = EventPriority.LOWEST) + public void dispenser(InventoryOpenEvent event) { + if (event.getInventory().getType() == InventoryType.DISPENSER) { + if (event.getPlayer() instanceof Player) { + prevent(event, (Player) event.getPlayer(), "dispenser,craft"); + } + } + } + +} diff --git a/net/crystalyx/bukkit/simplyperms/preventions/craft/Enchant.java b/net/crystalyx/bukkit/simplyperms/preventions/craft/Enchant.java new file mode 100755 index 0000000..c795672 --- /dev/null +++ b/net/crystalyx/bukkit/simplyperms/preventions/craft/Enchant.java @@ -0,0 +1,27 @@ +package net.crystalyx.bukkit.simplyperms.preventions.craft; + +import net.crystalyx.bukkit.simplyperms.SimplyPlugin; +import net.crystalyx.bukkit.simplyperms.SimplyPrevents; + +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.inventory.InventoryOpenEvent; +import org.bukkit.event.inventory.InventoryType; + +public class Enchant extends SimplyPrevents { + + public Enchant(SimplyPlugin plugin) { + super(plugin); + } + + @EventHandler(priority = EventPriority.LOWEST) + public void enchant(InventoryOpenEvent event) { + if (event.getInventory().getType() == InventoryType.ENCHANTING) { + if (event.getPlayer() instanceof Player) { + prevent(event, (Player) event.getPlayer(), "enchant,craft"); + } + } + } + +} diff --git a/net/crystalyx/bukkit/simplyperms/preventions/craft/Furnace.java b/net/crystalyx/bukkit/simplyperms/preventions/craft/Furnace.java new file mode 100755 index 0000000..9f0ea47 --- /dev/null +++ b/net/crystalyx/bukkit/simplyperms/preventions/craft/Furnace.java @@ -0,0 +1,27 @@ +package net.crystalyx.bukkit.simplyperms.preventions.craft; + +import net.crystalyx.bukkit.simplyperms.SimplyPlugin; +import net.crystalyx.bukkit.simplyperms.SimplyPrevents; + +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.inventory.InventoryOpenEvent; +import org.bukkit.event.inventory.InventoryType; + +public class Furnace extends SimplyPrevents { + + public Furnace(SimplyPlugin plugin) { + super(plugin); + } + + @EventHandler(priority = EventPriority.LOWEST) + public void furnace(InventoryOpenEvent event) { + if (event.getInventory().getType() == InventoryType.FURNACE) { + if (event.getPlayer() instanceof Player) { + prevent(event, (Player) event.getPlayer(), "furnace,craft"); + } + } + } + +} diff --git a/net/crystalyx/bukkit/simplyperms/preventions/craft/Workbench.java b/net/crystalyx/bukkit/simplyperms/preventions/craft/Workbench.java new file mode 100755 index 0000000..e6a5937 --- /dev/null +++ b/net/crystalyx/bukkit/simplyperms/preventions/craft/Workbench.java @@ -0,0 +1,27 @@ +package net.crystalyx.bukkit.simplyperms.preventions.craft; + +import net.crystalyx.bukkit.simplyperms.SimplyPlugin; +import net.crystalyx.bukkit.simplyperms.SimplyPrevents; + +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.inventory.InventoryOpenEvent; +import org.bukkit.event.inventory.InventoryType; + +public class Workbench extends SimplyPrevents { + + public Workbench(SimplyPlugin plugin) { + super(plugin); + } + + @EventHandler(priority = EventPriority.LOWEST) + public void workbench(InventoryOpenEvent event) { + if (event.getInventory().getType() == InventoryType.WORKBENCH) { + if (event.getPlayer() instanceof Player) { + prevent(event, (Player) event.getPlayer(), "workbench,craft"); + } + } + } + +} diff --git a/net/crystalyx/bukkit/simplyperms/preventions/fire/Fireball.java b/net/crystalyx/bukkit/simplyperms/preventions/fire/Fireball.java new file mode 100755 index 0000000..11ce571 --- /dev/null +++ b/net/crystalyx/bukkit/simplyperms/preventions/fire/Fireball.java @@ -0,0 +1,27 @@ +package net.crystalyx.bukkit.simplyperms.preventions.fire; + +import org.bukkit.Material; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.block.Action; +import org.bukkit.event.player.PlayerInteractEvent; + +import net.crystalyx.bukkit.simplyperms.SimplyPlugin; +import net.crystalyx.bukkit.simplyperms.SimplyPrevents; + +public class Fireball extends SimplyPrevents { + + public Fireball(SimplyPlugin plugin) { + super(plugin); + } + + @EventHandler(priority = EventPriority.LOWEST) + public void fireball(PlayerInteractEvent event) { + if (event.getAction() == Action.RIGHT_CLICK_BLOCK) { + if (event.getPlayer().getItemInHand().getType() == Material.FIREBALL) { + prevent(event, event.getPlayer(), "fireball,fire,interact"); + } + } + } + +} diff --git a/net/crystalyx/bukkit/simplyperms/preventions/fire/FlintAndSteel.java b/net/crystalyx/bukkit/simplyperms/preventions/fire/FlintAndSteel.java new file mode 100755 index 0000000..b175afe --- /dev/null +++ b/net/crystalyx/bukkit/simplyperms/preventions/fire/FlintAndSteel.java @@ -0,0 +1,27 @@ +package net.crystalyx.bukkit.simplyperms.preventions.fire; + +import net.crystalyx.bukkit.simplyperms.SimplyPlugin; +import net.crystalyx.bukkit.simplyperms.SimplyPrevents; + +import org.bukkit.Material; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.block.Action; +import org.bukkit.event.player.PlayerInteractEvent; + +public class FlintAndSteel extends SimplyPrevents { + + public FlintAndSteel(SimplyPlugin plugin) { + super(plugin); + } + + @EventHandler(priority = EventPriority.LOWEST) + public void flint(PlayerInteractEvent event) { + if (event.getAction() == Action.RIGHT_CLICK_BLOCK) { + if (event.getPlayer().getItemInHand().getType() == Material.FLINT_AND_STEEL) { + prevent(event, event.getPlayer(), "flintandsteel,fire,interact"); + } + } + } + +} diff --git a/net/crystalyx/bukkit/simplyperms/preventions/interact/Bed.java b/net/crystalyx/bukkit/simplyperms/preventions/interact/Bed.java new file mode 100755 index 0000000..8a934f5 --- /dev/null +++ b/net/crystalyx/bukkit/simplyperms/preventions/interact/Bed.java @@ -0,0 +1,21 @@ +package net.crystalyx.bukkit.simplyperms.preventions.interact; + +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.player.PlayerBedEnterEvent; + +import net.crystalyx.bukkit.simplyperms.SimplyPlugin; +import net.crystalyx.bukkit.simplyperms.SimplyPrevents; + +public class Bed extends SimplyPrevents { + + public Bed(SimplyPlugin plugin) { + super(plugin); + } + + @EventHandler(priority = EventPriority.LOWEST) + public void bed(PlayerBedEnterEvent event) { + prevent(event, event.getPlayer(), "bed,interact"); + } + +} diff --git a/net/crystalyx/bukkit/simplyperms/preventions/interact/Button.java b/net/crystalyx/bukkit/simplyperms/preventions/interact/Button.java new file mode 100755 index 0000000..f63df1e --- /dev/null +++ b/net/crystalyx/bukkit/simplyperms/preventions/interact/Button.java @@ -0,0 +1,29 @@ +package net.crystalyx.bukkit.simplyperms.preventions.interact; + +import net.crystalyx.bukkit.simplyperms.SimplyPlugin; +import net.crystalyx.bukkit.simplyperms.SimplyPrevents; + +import org.bukkit.Material; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.block.Action; +import org.bukkit.event.player.PlayerInteractEvent; + +public class Button extends SimplyPrevents { + + public Button(SimplyPlugin plugin) { + super(plugin); + } + + @EventHandler(priority = EventPriority.LOWEST) + public void button(PlayerInteractEvent event) { + Action action = event.getAction(); + if (action == Action.LEFT_CLICK_BLOCK + || action == Action.RIGHT_CLICK_BLOCK) { + if (event.getClickedBlock().getType() == Material.STONE_BUTTON) { + prevent(event, event.getPlayer(), "button,interact"); + } + } + } + +} diff --git a/net/crystalyx/bukkit/simplyperms/preventions/interact/Cake.java b/net/crystalyx/bukkit/simplyperms/preventions/interact/Cake.java new file mode 100755 index 0000000..19f5fd8 --- /dev/null +++ b/net/crystalyx/bukkit/simplyperms/preventions/interact/Cake.java @@ -0,0 +1,27 @@ +package net.crystalyx.bukkit.simplyperms.preventions.interact; + +import net.crystalyx.bukkit.simplyperms.SimplyPlugin; +import net.crystalyx.bukkit.simplyperms.SimplyPrevents; + +import org.bukkit.Material; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.block.Action; +import org.bukkit.event.player.PlayerInteractEvent; + +public class Cake extends SimplyPrevents { + + public Cake(SimplyPlugin plugin) { + super(plugin); + } + + @EventHandler(priority = EventPriority.LOWEST) + public void cake(PlayerInteractEvent event) { + if (event.getAction() == Action.RIGHT_CLICK_BLOCK) { + if (event.getClickedBlock().getType() == Material.CAKE_BLOCK) { + prevent(event, event.getPlayer(), "cake,interact"); + } + } + } + +} diff --git a/net/crystalyx/bukkit/simplyperms/preventions/interact/Door.java b/net/crystalyx/bukkit/simplyperms/preventions/interact/Door.java new file mode 100755 index 0000000..898c0c3 --- /dev/null +++ b/net/crystalyx/bukkit/simplyperms/preventions/interact/Door.java @@ -0,0 +1,34 @@ +package net.crystalyx.bukkit.simplyperms.preventions.interact; + +import net.crystalyx.bukkit.simplyperms.SimplyPlugin; +import net.crystalyx.bukkit.simplyperms.SimplyPrevents; + +import org.bukkit.Material; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.block.Action; +import org.bukkit.event.player.PlayerInteractEvent; + +public class Door extends SimplyPrevents { + + public Door(SimplyPlugin plugin) { + super(plugin); + } + + @EventHandler(priority = EventPriority.LOWEST) + public void door(PlayerInteractEvent event) { + Action action = event.getAction(); + if (action == Action.LEFT_CLICK_BLOCK + || action == Action.RIGHT_CLICK_BLOCK) { + Material material = event.getClickedBlock().getType(); + if (material == Material.WOODEN_DOOR + || material == Material.IRON_DOOR + || material == Material.IRON_DOOR_BLOCK + || material == Material.TRAP_DOOR + || material == Material.FENCE_GATE) { + prevent(event, event.getPlayer(), "door,interact"); + } + } + } + +} diff --git a/net/crystalyx/bukkit/simplyperms/preventions/interact/Fish.java b/net/crystalyx/bukkit/simplyperms/preventions/interact/Fish.java new file mode 100755 index 0000000..d785c7e --- /dev/null +++ b/net/crystalyx/bukkit/simplyperms/preventions/interact/Fish.java @@ -0,0 +1,21 @@ +package net.crystalyx.bukkit.simplyperms.preventions.interact; + +import net.crystalyx.bukkit.simplyperms.SimplyPlugin; +import net.crystalyx.bukkit.simplyperms.SimplyPrevents; + +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.player.PlayerFishEvent; + +public class Fish extends SimplyPrevents { + + public Fish(SimplyPlugin plugin) { + super(plugin); + } + + @EventHandler(priority = EventPriority.LOWEST) + public void fish(PlayerFishEvent event) { + prevent(event, event.getPlayer(), "fish,interact"); + } + +} diff --git a/net/crystalyx/bukkit/simplyperms/preventions/interact/Jukebox.java b/net/crystalyx/bukkit/simplyperms/preventions/interact/Jukebox.java new file mode 100755 index 0000000..ac66f95 --- /dev/null +++ b/net/crystalyx/bukkit/simplyperms/preventions/interact/Jukebox.java @@ -0,0 +1,27 @@ +package net.crystalyx.bukkit.simplyperms.preventions.interact; + +import net.crystalyx.bukkit.simplyperms.SimplyPlugin; +import net.crystalyx.bukkit.simplyperms.SimplyPrevents; + +import org.bukkit.Material; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.block.Action; +import org.bukkit.event.player.PlayerInteractEvent; + +public class Jukebox extends SimplyPrevents { + + public Jukebox(SimplyPlugin plugin) { + super(plugin); + } + + @EventHandler(priority = EventPriority.LOWEST) + public void jukebox(PlayerInteractEvent event) { + if (event.getAction() == Action.RIGHT_CLICK_BLOCK) { + if (event.getClickedBlock().getType() == Material.JUKEBOX) { + prevent(event, event.getPlayer(), "jukebox,interact"); + } + } + } + +} diff --git a/net/crystalyx/bukkit/simplyperms/preventions/interact/Lever.java b/net/crystalyx/bukkit/simplyperms/preventions/interact/Lever.java new file mode 100755 index 0000000..bc924b8 --- /dev/null +++ b/net/crystalyx/bukkit/simplyperms/preventions/interact/Lever.java @@ -0,0 +1,29 @@ +package net.crystalyx.bukkit.simplyperms.preventions.interact; + +import net.crystalyx.bukkit.simplyperms.SimplyPlugin; +import net.crystalyx.bukkit.simplyperms.SimplyPrevents; + +import org.bukkit.Material; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.block.Action; +import org.bukkit.event.player.PlayerInteractEvent; + +public class Lever extends SimplyPrevents { + + public Lever(SimplyPlugin plugin) { + super(plugin); + } + + @EventHandler(priority = EventPriority.LOWEST) + public void lever(PlayerInteractEvent event) { + Action action = event.getAction(); + if (action == Action.LEFT_CLICK_BLOCK + || action == Action.RIGHT_CLICK_BLOCK) { + if (event.getClickedBlock().getType() == Material.LEVER) { + prevent(event, event.getPlayer(), "lever,interact"); + } + } + } + +} diff --git a/net/crystalyx/bukkit/simplyperms/preventions/interact/Noteblock.java b/net/crystalyx/bukkit/simplyperms/preventions/interact/Noteblock.java new file mode 100755 index 0000000..64831a8 --- /dev/null +++ b/net/crystalyx/bukkit/simplyperms/preventions/interact/Noteblock.java @@ -0,0 +1,29 @@ +package net.crystalyx.bukkit.simplyperms.preventions.interact; + +import net.crystalyx.bukkit.simplyperms.SimplyPlugin; +import net.crystalyx.bukkit.simplyperms.SimplyPrevents; + +import org.bukkit.Material; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.block.Action; +import org.bukkit.event.player.PlayerInteractEvent; + +public class Noteblock extends SimplyPrevents { + + public Noteblock(SimplyPlugin plugin) { + super(plugin); + } + + @EventHandler(priority = EventPriority.LOWEST) + public void noteblock(PlayerInteractEvent event) { + Action action = event.getAction(); + if (action == Action.LEFT_CLICK_BLOCK + || action == Action.RIGHT_CLICK_BLOCK) { + if (event.getClickedBlock().getType() == Material.NOTE_BLOCK) { + prevent(event, event.getPlayer(), "noteblock,interact"); + } + } + } + +} diff --git a/net/crystalyx/bukkit/simplyperms/preventions/interact/Pressureplate.java b/net/crystalyx/bukkit/simplyperms/preventions/interact/Pressureplate.java new file mode 100755 index 0000000..1c3fbd9 --- /dev/null +++ b/net/crystalyx/bukkit/simplyperms/preventions/interact/Pressureplate.java @@ -0,0 +1,29 @@ +package net.crystalyx.bukkit.simplyperms.preventions.interact; + +import net.crystalyx.bukkit.simplyperms.SimplyPlugin; +import net.crystalyx.bukkit.simplyperms.SimplyPrevents; + +import org.bukkit.Material; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.block.Action; +import org.bukkit.event.player.PlayerInteractEvent; + +public class Pressureplate extends SimplyPrevents { + + public Pressureplate(SimplyPlugin plugin) { + super(plugin); + } + + @EventHandler(priority = EventPriority.LOWEST) + public void pressureplate(PlayerInteractEvent event) { + if (event.getAction() == Action.PHYSICAL) { + Material material = event.getClickedBlock().getType(); + if (material == Material.STONE_PLATE + || material == Material.WOOD_PLATE) { + prevent(event, event.getPlayer(), "pressureplate,interact"); + } + } + } + +} diff --git a/net/crystalyx/bukkit/simplyperms/preventions/interact/Repeater.java b/net/crystalyx/bukkit/simplyperms/preventions/interact/Repeater.java new file mode 100755 index 0000000..eb95ee7 --- /dev/null +++ b/net/crystalyx/bukkit/simplyperms/preventions/interact/Repeater.java @@ -0,0 +1,29 @@ +package net.crystalyx.bukkit.simplyperms.preventions.interact; + +import net.crystalyx.bukkit.simplyperms.SimplyPlugin; +import net.crystalyx.bukkit.simplyperms.SimplyPrevents; + +import org.bukkit.Material; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.block.Action; +import org.bukkit.event.player.PlayerInteractEvent; + +public class Repeater extends SimplyPrevents { + + public Repeater(SimplyPlugin plugin) { + super(plugin); + } + + @EventHandler(priority = EventPriority.LOWEST) + public void repeater(PlayerInteractEvent event) { + if (event.getAction() == Action.RIGHT_CLICK_BLOCK) { + Material material = event.getClickedBlock().getType(); + if (material == Material.DIODE_BLOCK_ON + || material == Material.DIODE_BLOCK_OFF) { + prevent(event, event.getPlayer(), "repeater,interact"); + } + } + } + +} diff --git a/net/crystalyx/bukkit/simplyperms/preventions/loot/Drop.java b/net/crystalyx/bukkit/simplyperms/preventions/loot/Drop.java new file mode 100755 index 0000000..5b5947c --- /dev/null +++ b/net/crystalyx/bukkit/simplyperms/preventions/loot/Drop.java @@ -0,0 +1,21 @@ +package net.crystalyx.bukkit.simplyperms.preventions.loot; + +import net.crystalyx.bukkit.simplyperms.SimplyPlugin; +import net.crystalyx.bukkit.simplyperms.SimplyPrevents; + +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.player.PlayerDropItemEvent; + +public class Drop extends SimplyPrevents { + + public Drop(SimplyPlugin plugin) { + super(plugin); + } + + @EventHandler(priority = EventPriority.LOWEST) + public void drop(PlayerDropItemEvent event) { + prevent(event, event.getPlayer(), "drop." + event.getItemDrop().getItemStack().getTypeId() + ",loot." + event.getItemDrop().getItemStack().getTypeId()); + } + +} diff --git a/net/crystalyx/bukkit/simplyperms/preventions/loot/Pickup.java b/net/crystalyx/bukkit/simplyperms/preventions/loot/Pickup.java new file mode 100755 index 0000000..fd39ee9 --- /dev/null +++ b/net/crystalyx/bukkit/simplyperms/preventions/loot/Pickup.java @@ -0,0 +1,21 @@ +package net.crystalyx.bukkit.simplyperms.preventions.loot; + +import net.crystalyx.bukkit.simplyperms.SimplyPlugin; +import net.crystalyx.bukkit.simplyperms.SimplyPrevents; + +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.player.PlayerPickupItemEvent; + +public class Pickup extends SimplyPrevents { + + public Pickup(SimplyPlugin plugin) { + super(plugin); + } + + @EventHandler(priority = EventPriority.LOWEST) + public void pickup(PlayerPickupItemEvent event) { + prevent(event, event.getPlayer(), "pickup." + event.getItem().getItemStack().getTypeId() + ",loot." + event.getItem().getItemStack().getTypeId()); + } + +} diff --git a/net/crystalyx/bukkit/simplyperms/preventions/projectile/Egg.java b/net/crystalyx/bukkit/simplyperms/preventions/projectile/Egg.java new file mode 100755 index 0000000..4d6be9b --- /dev/null +++ b/net/crystalyx/bukkit/simplyperms/preventions/projectile/Egg.java @@ -0,0 +1,29 @@ +package net.crystalyx.bukkit.simplyperms.preventions.projectile; + +import net.crystalyx.bukkit.simplyperms.SimplyPlugin; +import net.crystalyx.bukkit.simplyperms.SimplyPrevents; + +import org.bukkit.Material; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.block.Action; +import org.bukkit.event.player.PlayerInteractEvent; + +public class Egg extends SimplyPrevents { + + public Egg(SimplyPlugin plugin) { + super(plugin); + } + + @EventHandler(priority = EventPriority.LOWEST) + public void egg(PlayerInteractEvent event) { + if (event.getAction() == Action.RIGHT_CLICK_AIR + || event.getAction() == Action.RIGHT_CLICK_BLOCK) { + if (event.getPlayer().getItemInHand().getTypeId() == Material.MONSTER_EGG.getId() + || event.getPlayer().getItemInHand().getType() == Material.EGG) { + prevent(event, event.getPlayer(), "egg,projectile"); + } + } + } + +} diff --git a/net/crystalyx/bukkit/simplyperms/preventions/projectile/Potion.java b/net/crystalyx/bukkit/simplyperms/preventions/projectile/Potion.java new file mode 100755 index 0000000..8602620 --- /dev/null +++ b/net/crystalyx/bukkit/simplyperms/preventions/projectile/Potion.java @@ -0,0 +1,29 @@ +package net.crystalyx.bukkit.simplyperms.preventions.projectile; + +import net.crystalyx.bukkit.simplyperms.SimplyPlugin; +import net.crystalyx.bukkit.simplyperms.SimplyPrevents; + +import org.bukkit.Material; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.block.Action; +import org.bukkit.event.player.PlayerInteractEvent; + +public class Potion extends SimplyPrevents { + + public Potion(SimplyPlugin plugin) { + super(plugin); + } + + @EventHandler(priority = EventPriority.LOWEST) + public void potion(PlayerInteractEvent event) { + if (event.getAction() == Action.RIGHT_CLICK_AIR + || event.getAction() == Action.RIGHT_CLICK_BLOCK) { + if (event.getPlayer().getItemInHand().getTypeId() == Material.POTION.getId() + || event.getPlayer().getItemInHand().getType() == Material.EXP_BOTTLE) { + prevent(event, event.getPlayer(), "potion,projectile"); + } + } + } + +} diff --git a/net/crystalyx/bukkit/simplyperms/preventions/projectile/Snowball.java b/net/crystalyx/bukkit/simplyperms/preventions/projectile/Snowball.java new file mode 100755 index 0000000..1fa7db8 --- /dev/null +++ b/net/crystalyx/bukkit/simplyperms/preventions/projectile/Snowball.java @@ -0,0 +1,28 @@ +package net.crystalyx.bukkit.simplyperms.preventions.projectile; + +import net.crystalyx.bukkit.simplyperms.SimplyPlugin; +import net.crystalyx.bukkit.simplyperms.SimplyPrevents; + +import org.bukkit.Material; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.block.Action; +import org.bukkit.event.player.PlayerInteractEvent; + +public class Snowball extends SimplyPrevents { + + public Snowball(SimplyPlugin plugin) { + super(plugin); + } + + @EventHandler(priority = EventPriority.LOWEST) + public void snowball(PlayerInteractEvent event) { + if (event.getAction() == Action.RIGHT_CLICK_AIR + || event.getAction() == Action.RIGHT_CLICK_BLOCK) { + if (event.getPlayer().getItemInHand().getType() == Material.SNOW_BALL) { + prevent(event, event.getPlayer(), "snowball,projectile"); + } + } + } + +} diff --git a/net/crystalyx/bukkit/simplyperms/preventions/spam/CapsLock.java b/net/crystalyx/bukkit/simplyperms/preventions/spam/CapsLock.java new file mode 100755 index 0000000..caabe07 --- /dev/null +++ b/net/crystalyx/bukkit/simplyperms/preventions/spam/CapsLock.java @@ -0,0 +1,30 @@ +package net.crystalyx.bukkit.simplyperms.preventions.spam; + +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.player.PlayerChatEvent; + +import net.crystalyx.bukkit.simplyperms.SimplyPlugin; +import net.crystalyx.bukkit.simplyperms.SimplyPrevents; + +public class CapsLock extends SimplyPrevents { + + public CapsLock(SimplyPlugin plugin) { + super(plugin); + } + + @EventHandler(priority = EventPriority.LOW) + public void capslock(PlayerChatEvent event) { + String message = event.getMessage(); + for (Player player : super.plugin.getServer().getOnlinePlayers()) { + message.replace(player.getName(), ""); + } + String nocaps = message.replaceAll("[A-Z]*", ""); + if (message.length() > 5 + && message.length() - nocaps.length() > message.length() / 2) { + prevent(event, event.getPlayer(), "capslock,spam"); + } + } + +} diff --git a/net/crystalyx/bukkit/simplyperms/preventions/spam/Flood.java b/net/crystalyx/bukkit/simplyperms/preventions/spam/Flood.java new file mode 100755 index 0000000..343a147 --- /dev/null +++ b/net/crystalyx/bukkit/simplyperms/preventions/spam/Flood.java @@ -0,0 +1,45 @@ +package net.crystalyx.bukkit.simplyperms.preventions.spam; + +import java.util.HashMap; + +import net.crystalyx.bukkit.simplyperms.SimplyPlugin; +import net.crystalyx.bukkit.simplyperms.SimplyPrevents; + +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.player.PlayerChatEvent; + +public class Flood extends SimplyPrevents { + + private HashMap chatTimestamps = new HashMap(); + + public Flood(SimplyPlugin plugin) { + super(plugin); + } + + @EventHandler(priority = EventPriority.LOW) + public void chat(PlayerChatEvent event) { + Player player = event.getPlayer(); + if (isChatLocked(player)) { + prevent(event, player, "flood,spam"); + } else { + setChatLock(player); + } + } + + private void setChatLock(Player player) { + chatTimestamps.put(player, Long.valueOf(System.currentTimeMillis() + 2000)); + } + + private boolean isChatLocked(Player player) { + Long nextPossible = chatTimestamps.get(player); + if (nextPossible == null) { + return false; + } + + long currentTime = System.currentTimeMillis(); + return nextPossible.longValue() >= currentTime; + } + +} diff --git a/plugin.yml b/plugin.yml new file mode 100755 index 0000000..87b75a3 --- /dev/null +++ b/plugin.yml @@ -0,0 +1,99 @@ +name: SimplyPerms +main: net.crystalyx.bukkit.simplyperms.SimplyPlugin +author: Xefir Destiny +website: http://www.crystalyx.net/ +version: 1.6.1 +commands: + permissions: + aliases: [ perms, perm, p ] + description: Commands for manipulating permissions. + usage: | + / reload - reload the configuration from disk. + / check [player] - check if a player or the sender has a permission (any plugin). + / info - prints information on a specific permission. + / dump [player] [page] - prints info about a player's (or the sender's) permissions. + / import - Import data from database or others permissions plugins + / group - list group-related commands. + / group list - list all groups. + / group players - list players in a group. + / group setperm <[world:]node> [true|false] - set a permission on a group. + / group unsetperm <[world:]node> - unset a permission on a group. + / player - list player-related commands. + / player groups - list groups a player is in. + / player setgroup - set a player to be in only the given groups. + / player addgroup - add a player to a group. + / player removegroup - remove a player from a group. + / player remove - remove a player from config file. + / player setperm <[world:]node> [true|false] - set a permission on a player. + / player unsetperm <[world:]node> - unset a permission on a player. +permissions: + permissions.*: + default: op + description: Allows use of all PermissionsBukkit administration commands. + children: + permissions.help: true + permissions.reload: true + permissions.check: true + permissions.info: true + permissions.dump: true + permissions.import: true + permissions.group.*: true + permissions.player.*: true + permissions.allow.*: true + permissions.help: + description: Allows viewing of usage for /permissions. + permissions.reload: + description: Allows use of /permissions reload. + permissions.check: + description: Allows use of /permissions check. + permissions.info: + description: Allows use of /permissions info. + permissions.dump: + description: Allows use of /permissions dump. + permissions.import: + description: Allows use of /permissions import. + permissions.group.*: + description: Allows use of all /permissions group commands. + children: + permissions.group.help: true + permissions.group.list: true + permissions.group.players: true + permissions.group.setperm: true + permissions.group.unsetperm: true + permissions.group.help: + description: Allows viewing of usage for /permissions group. + permissions.group.list: + description: Allows use of /permissions group list. + permissions.group.players: + description: Allows use of /permissions group players. + permissions.group.setperm: + description: Allows use of /permissions group setperm. + permissions.group.unsetperm: + description: Allows use of /permissions group unsetperm. + permissions.player.*: + description: Allows use of all /permissions player commands. + children: + permissions.player.help: true + permissions.player.groups: true + permissions.player.setgroup: true + permissions.player.addgroup: true + permissions.player.removegroup: true + permissions.player.remove: true + permissions.player.setperm: true + permissions.player.unsetperm: true + permissions.player.help: + description: Allows viewing of usage for /permissions player. + permissions.player.groups: + description: Allows use of /permissions player groups. + permissions.player.setgroup: + description: Allows use of /permissions player setgroup. + permissions.player.addgroup: + description: Allows use of /permissions player addgroup. + permissions.player.removegroup: + description: Allows use of /permissions player removegroup. + permissions.player.remove: + description: Allows use of /permissions player remove. + permissions.player.setperm: + description: Allows use of /permissions player setperm. + permissions.player.unsetperm: + description: Allows use of /permissions player unsetperm.