Initial version : 1.6.2

This commit is contained in:
Michel Roux 2012-04-29 02:11:39 +02:00
parent 55fb978bf8
commit 0cc3fd6ada
59 changed files with 3317 additions and 0 deletions

2
META-INF/MANIFEST.MF Executable file
View File

@ -0,0 +1,2 @@
Manifest-Version: 1.0

44
config.yml Executable file
View File

@ -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.'

View File

@ -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<String> getPlayers(String group) {
return plugin.config.getPlayers(group);
}
@Override
public List<String> getPlayerGroups(String player) {
return plugin.config.getPlayerGroups(player);
}
@Override
public Map<String, Boolean> getPlayerPermissions(String player) {
return plugin.config.getPlayerPermissions(player);
}
@Override
public Map<String, Boolean> 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<String> getPlayerWorlds(String player) {
return plugin.config.getPlayerWorlds(player);
}
@Override
public List<String> getAllPlayers() {
return plugin.config.getAllPlayers();
}
public List<String> getAllGroups() {
if (plugin.getNode("groups") != null) {
return new ArrayList<String>(plugin.getNode("groups").getKeys(false));
}
else {
return new ArrayList<String>();
}
}
public List<String> getGroupWorlds(String group) {
if (group.isEmpty()) group = "default";
if (plugin.getNode("groups/" + group + "/worlds") != null) {
return new ArrayList<String>(plugin.getNode("groups/" + group + "/worlds").getKeys(false));
}
else {
return new ArrayList<String>();
}
}
public List<String> 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<String> 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<String> 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<String, Boolean> getGroupPermissions(String group, String world) {
if (group.isEmpty()) group = "default";
Map<String, Boolean> finalPerms = new HashMap<String, Boolean>();
String permNode = (!world.isEmpty()) ? "groups/" + group + "/worlds/" + world : "groups/" + group + "/permissions";
if (plugin.getNode(permNode) != null) {
for (Entry<String, Object> permGroup : plugin.getNode(permNode).getValues(false).entrySet()) {
finalPerms.put(permGroup.getKey(), (Boolean) permGroup.getValue());
}
}
return finalPerms;
}
public Map<String, Boolean> getGroupPermissions(String group) {
return getGroupPermissions(group, "");
}
public void addGroupPermission(String group, String world, String permission, boolean value) {
if (group.isEmpty()) group = "default";
Map<String, Boolean> 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<String, Boolean> 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<String, Object> getMessages() {
if (plugin.getNode("messages") != null) {
return plugin.getNode("messages").getValues(false);
}
else {
return new HashMap<String, Object>();
}
}
public void addMessage(String key, String message) {
Map<String, Object> messages = getMessages();
if (!messages.containsKey(key)) messages.put(key, message);
plugin.getConfig().set("messages", messages);
}
public void removeMessage(String key) {
Map<String, Object> messages = getMessages();
messages.remove(key);
plugin.getConfig().set("messages", messages);
}
public void refreshPermissions() {
plugin.refreshPermissions();
}
protected List<String> getKeys(YamlConfiguration config, String node) {
if (config.getConfigurationSection(node) != null) {
return new ArrayList<String>(config.getConfigurationSection(node).getKeys(false));
}
else {
return new ArrayList<String>();
}
}
}

View File

@ -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<PermissionAttachmentInfo> dump = new ArrayList<PermissionAttachmentInfo>(permissible.getEffectivePermissions());
Collections.sort(dump, new Comparator<PermissionAttachmentInfo>() {
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<String, Boolean> 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("/<command> group") && !line.startsWith("/<command> group -")) ||
(line.startsWith("/<command> player") && !line.startsWith("/<command> 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("/<command> " + 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("<command>", "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;
}
}

View File

@ -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());
}
}

View File

@ -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<String, PermissionAttachment> permissions = new HashMap<String, PermissionAttachment>();
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<String, Boolean> getAllPerms(String desc, String path) {
HashMap<String, Boolean> result = new HashMap<String, Boolean>();
ConfigurationSection node = getNode(path);
int failures = 0;
String firstFailure = "";
Set<String> 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<String, Boolean> entry : calculatePlayerPermissions(player.getName().toLowerCase(), player.getWorld().getName()).entrySet()) {
attachment.setPermission(entry.getKey(), entry.getValue());
}
player.recalculatePermissions();
}
// -- Private stuff
private Map<String, Boolean> calculatePlayerPermissions(String player, String world) {
if (!config.isPlayerInDB(player)) {
return calculateGroupPermissions("default", world);
}
Map<String, Boolean> perms = new HashMap<String, Boolean>();
List<String> groups = config.getPlayerGroups(player);
if (groups.isEmpty()) groups.add("default");
for (Entry<String, Boolean> entry : config.getPlayerPermissions(player).entrySet()) {
perms.put(entry.getKey(), entry.getValue());
}
for (Entry<String, Boolean> 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<String, Boolean> entry : calculateGroupPermissions(group, world).entrySet()) {
if (!perms.containsKey(entry.getKey())) { // User overrides group
perms.put(entry.getKey(), entry.getValue());
}
}
}
return perms;
}
private Map<String, Boolean> calculateGroupPermissions(String group, String world) {
if (getNode("groups/" + group) == null) {
return new HashMap<String, Boolean>();
}
Map<String, Boolean> perms = getNode("groups/" + group + "/permissions") == null ?
new HashMap<String, Boolean>() :
getAllPerms("group " + group, "groups/" + group + "/permissions");
if (getNode("groups/" + group + "/worlds/" + world) != null) {
for (Map.Entry<String, Boolean> 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<String, Boolean> 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());
}
}
}
}

View File

@ -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<Player, Long> throttleTimestamps = new HashMap<Player, Long>();
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;
}
}

View File

@ -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<String, Boolean> permission : importSQL.getPlayerPermissions(player).entrySet()) {
importFile.addPlayerPermission(player, permission.getKey(), permission.getValue());
}
for (String world : importSQL.getPlayerWorlds(player)) {
for (Entry<String, Boolean> permission : importSQL.getPlayerPermissions(player, world).entrySet()) {
importFile.addPlayerPermission(player, world, permission.getKey(), permission.getValue());
}
}
}
} catch (Exception e) {
throw e;
}
}
}

View File

@ -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<String, Boolean> permission : importFile.getPlayerPermissions(player).entrySet()) {
importSQL.addPlayerPermission(player, permission.getKey(), permission.getValue());
}
for (String world : importFile.getPlayerWorlds(player)) {
for (Entry<String, Boolean> permission : importFile.getPlayerPermissions(player, world).entrySet()) {
importSQL.addPlayerPermission(player, world, permission.getKey(), permission.getValue());
}
}
}
} catch (Exception e) {
throw e;
}
}
}

View File

@ -0,0 +1,7 @@
package net.crystalyx.bukkit.simplyperms.imports;
public interface ImportManager {
public void run() throws Exception;
}

View File

@ -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<String, Object> 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<String, Object> 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<String, Object> 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<String, Object> 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;
}
}
}

View File

@ -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;
}
}
}

View File

@ -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<String> 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<String> 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<String, Boolean> 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<String, Boolean> 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<String> getPlayers(String group) {
List<String> players = new ArrayList<String>();
for (String player : getAllPlayers()) {
for (String groupName : getPlayerGroups(player)) {
if (groupName.equals(group)) {
players.add(player);
}
}
}
return players;
}
@Override
public List<String> getPlayerGroups(String player) {
return plugin.getConfig().getStringList("users/" + player + "/groups");
}
@Override
public Map<String, Boolean> getPlayerPermissions(String player) {
return getPlayerPermissions(player, "");
}
@Override
public Map<String, Boolean> getPlayerPermissions(String player, String world) {
Map<String, Boolean> finalPerms = new HashMap<String, Boolean>();
String permNode = (!world.isEmpty()) ? "users/" + player + "/worlds/" + world : "users/" + player + "/permissions";
if (plugin.getConfig().getConfigurationSection(permNode) != null) {
for (Entry<String, Object> 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<String> getPlayerWorlds(String player) {
if (plugin.getConfig().getConfigurationSection("users/" + player + "/worlds") != null) {
return new ArrayList<String>(plugin.getConfig().getConfigurationSection("users/" + player + "/worlds").getKeys(false));
}
else {
return new ArrayList<String>();
}
}
@Override
public List<String> getAllPlayers() {
if (plugin.getConfig().getConfigurationSection("users") != null) {
return new ArrayList<String>(plugin.getConfig().getConfigurationSection("users").getKeys(false));
}
else {
return new ArrayList<String>();
}
}
}

View File

@ -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<String> getPlayers(String group) {
List<String> results = new ArrayList<String>();
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<String> getPlayerGroups(String player) {
List<String> results = new ArrayList<String>();
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<String, Boolean> getPlayerPermissions(String player) {
return getPlayerPermissions(player, "");
}
@Override
public Map<String, Boolean> getPlayerPermissions(String player, String world) {
Map<String, Boolean> results = new HashMap<String, Boolean>();
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<String> getPlayerWorlds(String player) {
List<String> results = new ArrayList<String>();
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<String> getAllPlayers() {
List<String> results = new ArrayList<String>();
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;
}
}

View File

@ -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<String> getPlayers(String group);
public List<String> getPlayerGroups(String player);
public Map<String, Boolean> getPlayerPermissions(String player);
public Map<String, Boolean> getPlayerPermissions(String player, String world);
public boolean isPlayerInDB(String player);
public List<String> getPlayerWorlds(String player);
public List<String> getAllPlayers();
}

View File

@ -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");
}
}
}

View File

@ -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");
}
}

View File

@ -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");
}
}
}

View File

@ -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);
}
}
}
}

View File

@ -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<LivingEntity> affectedEntities = event.getAffectedEntities();
for (LivingEntity entity : affectedEntities) {
if (entity instanceof Player) {
Player affectedPlayer = (Player) entity;
if (prevent(event, affectedPlayer, "damage")) {
affectedEntities.remove(entity);
}
}
}
}
}

View File

@ -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");
}
}
}
}

View File

@ -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");
}
}
}

View File

@ -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);
}
}
}
}
}

View File

@ -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");
}
}
}

View File

@ -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");
}
}
}
}

View File

@ -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");
}
}
}
}

View File

@ -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");
}
}

View File

@ -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");
}
}
}

View File

@ -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");
}
}
}

View File

@ -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");
}
}
}

View File

@ -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");
}
}
}

View File

@ -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);
}
}
}
}
}

View File

@ -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());
}
}

View File

@ -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");
}
}
}
}

View File

@ -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);
}
}
}
}

View File

@ -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");
}
}
}
}

View File

@ -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");
}
}
}
}

View File

@ -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");
}
}
}
}

View File

@ -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");
}
}
}
}

View File

@ -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");
}
}
}
}

View File

@ -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");
}
}
}
}

View File

@ -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");
}
}

View File

@ -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");
}
}
}
}

View File

@ -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");
}
}
}
}

View File

@ -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");
}
}
}
}

View File

@ -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");
}
}

View File

@ -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");
}
}
}
}

View File

@ -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");
}
}
}
}

View File

@ -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");
}
}
}
}

View File

@ -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");
}
}
}
}

View File

@ -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");
}
}
}
}

View File

@ -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());
}
}

View File

@ -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());
}
}

View File

@ -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");
}
}
}
}

View File

@ -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");
}
}
}
}

View File

@ -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");
}
}
}
}

View File

@ -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");
}
}
}

View File

@ -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<Player, Long> chatTimestamps = new HashMap<Player, Long>();
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;
}
}

99
plugin.yml Executable file
View File

@ -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: |
/<command> reload - reload the configuration from disk.
/<command> check <node> [player] - check if a player or the sender has a permission (any plugin).
/<command> info <node> - prints information on a specific permission.
/<command> dump [player] [page] - prints info about a player's (or the sender's) permissions.
/<command> import <type> - Import data from database or others permissions plugins
/<command> group - list group-related commands.
/<command> group list - list all groups.
/<command> group players <group> - list players in a group.
/<command> group setperm <group> <[world:]node> [true|false] - set a permission on a group.
/<command> group unsetperm <group> <[world:]node> - unset a permission on a group.
/<command> player - list player-related commands.
/<command> player groups <player> - list groups a player is in.
/<command> player setgroup <player> <group,...> - set a player to be in only the given groups.
/<command> player addgroup <player> <group> - add a player to a group.
/<command> player removegroup <player> <group> - remove a player from a group.
/<command> player remove <player> - remove a player from config file.
/<command> player setperm <player> <[world:]node> [true|false] - set a permission on a player.
/<command> player unsetperm <player> <[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.