From 6d5fa7158f59a345c5698e01710d5d94895e8ec6 Mon Sep 17 00:00:00 2001 From: Robert Wilson Date: Sat, 3 Dec 2011 22:06:36 +0000 Subject: [PATCH 1/3] Added Coloured Tab Menu Option (Configurable) Renamed DARK_AQUA to DARK_GREY as required --- src/uk/co/oliwali/WhoAreYou/Config.java | 2 ++ src/uk/co/oliwali/WhoAreYou/Util.java | 3 ++- src/uk/co/oliwali/WhoAreYou/WAYPlayerListener.java | 6 ++++++ src/uk/co/oliwali/WhoAreYou/WhoAreYou.java | 2 +- 4 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/uk/co/oliwali/WhoAreYou/Config.java b/src/uk/co/oliwali/WhoAreYou/Config.java index af1e1a4..f2cf8c4 100644 --- a/src/uk/co/oliwali/WhoAreYou/Config.java +++ b/src/uk/co/oliwali/WhoAreYou/Config.java @@ -11,6 +11,7 @@ public class Config { public WhoAreYou plugin; private Configuration config; public boolean onlineMsg; + public boolean tablist; public Config (WhoAreYou instance) { @@ -35,6 +36,7 @@ public Config (WhoAreYou instance) { aliases.put(world, config.getString("aliases." + world)); onlineMsg = config.getBoolean("msg-online-on-join", true); + tablist = config.getBoolean("colour-tab-menu", true); //Attempt save if (!config.save()) diff --git a/src/uk/co/oliwali/WhoAreYou/Util.java b/src/uk/co/oliwali/WhoAreYou/Util.java index 744fdd2..c3f6585 100644 --- a/src/uk/co/oliwali/WhoAreYou/Util.java +++ b/src/uk/co/oliwali/WhoAreYou/Util.java @@ -88,7 +88,7 @@ private enum CustomColor { GREEN("a", 0xA), DARK_GREEN("2", 0x2), AQUA("b", 0xB), - DARK_AQUA("8", 0x8), + DARK_GREY("8", 0x8), BLUE("9", 0x9), DARK_BLUE("1", 0x1), LIGHT_PURPLE("d", 0xD), @@ -98,6 +98,7 @@ private enum CustomColor { GRAY("7", 0x7), WHITE("f", 0xf), DARK_AQUA("3", 0x3); + private String custom; private int code; diff --git a/src/uk/co/oliwali/WhoAreYou/WAYPlayerListener.java b/src/uk/co/oliwali/WhoAreYou/WAYPlayerListener.java index d675170..4803c8a 100644 --- a/src/uk/co/oliwali/WhoAreYou/WAYPlayerListener.java +++ b/src/uk/co/oliwali/WhoAreYou/WAYPlayerListener.java @@ -1,5 +1,6 @@ package uk.co.oliwali.WhoAreYou; +import org.bukkit.entity.Player; import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.event.player.PlayerListener; @@ -14,6 +15,11 @@ public WAYPlayerListener(WhoAreYou instance) { public void onPlayerJoin(PlayerJoinEvent event) { if (plugin.config.onlineMsg) plugin.who(event.getPlayer()); + if (plugin.config.tablist) { + Player player = event.getPlayer(); + player.setPlayerListName(plugin.permissions.getPrefix(player) + player.getName() + plugin.permissions.getSuffix(player)); + } } + } \ No newline at end of file diff --git a/src/uk/co/oliwali/WhoAreYou/WhoAreYou.java b/src/uk/co/oliwali/WhoAreYou/WhoAreYou.java index 8f7acf0..cf9e4eb 100644 --- a/src/uk/co/oliwali/WhoAreYou/WhoAreYou.java +++ b/src/uk/co/oliwali/WhoAreYou/WhoAreYou.java @@ -17,7 +17,7 @@ public class WhoAreYou extends JavaPlugin { public static String name; public static String version; - private Permission permissions; + public Permission permissions; public Config config; private WAYPlayerListener playerListener = new WAYPlayerListener(this); From 5b6387a5deb1637cd55a7b2157517fd4822e198c Mon Sep 17 00:00:00 2001 From: Robert Wilson Date: Sun, 4 Dec 2011 12:31:48 +0000 Subject: [PATCH 2/3] Fix Tab Colored List --- src/uk/co/oliwali/WhoAreYou/WAYPlayerListener.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/uk/co/oliwali/WhoAreYou/WAYPlayerListener.java b/src/uk/co/oliwali/WhoAreYou/WAYPlayerListener.java index 4803c8a..e28bd17 100644 --- a/src/uk/co/oliwali/WhoAreYou/WAYPlayerListener.java +++ b/src/uk/co/oliwali/WhoAreYou/WAYPlayerListener.java @@ -17,7 +17,11 @@ public void onPlayerJoin(PlayerJoinEvent event) { plugin.who(event.getPlayer()); if (plugin.config.tablist) { Player player = event.getPlayer(); - player.setPlayerListName(plugin.permissions.getPrefix(player) + player.getName() + plugin.permissions.getSuffix(player)); + String prefix = plugin.permissions.getPrefix(player); + int lastcolor = prefix.lastIndexOf("&"); + + String coloredname = "&" + prefix.charAt(lastcolor + 1) + player.getName(); + player.setPlayerListName(coloredname.replaceAll("(&([a-f0-9]))", "\u00A7$2")); } } From abbc64b7b54586261ce0ed90f19eaa8d23b35d06 Mon Sep 17 00:00:00 2001 From: Rob4001 Date: Mon, 5 Mar 2012 18:12:56 +0000 Subject: [PATCH 3/3] Update to 1.1-R6 Now uses Vault and New Config --- src/uk/co/oliwali/WhoAreYou/Config.java | 29 +++--- src/uk/co/oliwali/WhoAreYou/Permission.java | 93 ------------------- .../co/oliwali/WhoAreYou/WAUPermission.java | 52 +++++++++++ .../oliwali/WhoAreYou/WAYPlayerListener.java | 9 +- src/uk/co/oliwali/WhoAreYou/WhoAreYou.java | 36 ++++++- 5 files changed, 103 insertions(+), 116 deletions(-) delete mode 100644 src/uk/co/oliwali/WhoAreYou/Permission.java create mode 100644 src/uk/co/oliwali/WhoAreYou/WAUPermission.java diff --git a/src/uk/co/oliwali/WhoAreYou/Config.java b/src/uk/co/oliwali/WhoAreYou/Config.java index f2cf8c4..02c24a6 100644 --- a/src/uk/co/oliwali/WhoAreYou/Config.java +++ b/src/uk/co/oliwali/WhoAreYou/Config.java @@ -3,44 +3,43 @@ import java.util.HashMap; import org.bukkit.World; -import org.bukkit.util.config.Configuration; +import org.bukkit.configuration.file.FileConfiguration; + public class Config { private HashMap aliases = new HashMap(); public WhoAreYou plugin; - private Configuration config; + private FileConfiguration config; public boolean onlineMsg; public boolean tablist; public Config (WhoAreYou instance) { this.plugin = instance; - this.config = plugin.getConfiguration(); - config.load(); + this.config = plugin.getConfig(); + plugin.reloadConfig(); //If there are no aliases yet - if (config.getKeys("aliases") == null) { - World[] worlds = (World[]) plugin.getServer().getWorlds().toArray(new World[0]); - for (World world : worlds) - config.setProperty("aliases." + world.getName(), world.getName()); + for(World world : plugin.getServer().getWorlds()){ + config.addDefault("aliases."+ world.getName(), world.getName()); } //Message players on join - if (config.getProperty("msg-online-on-join") == null) - config.setProperty("msg-online-on-join", true); + config.addDefault("msg-online-on-join", true); + + config.options().copyDefaults(true); //Load aliasess into hashmap - String[] worlds = (String[]) config.getKeys("aliases").toArray(new String[0]); - for (String world : worlds) - aliases.put(world, config.getString("aliases." + world)); + for(World world : plugin.getServer().getWorlds()){ + aliases.put(world.getName(), config.getString("aliases."+world.getName())); + } onlineMsg = config.getBoolean("msg-online-on-join", true); tablist = config.getBoolean("colour-tab-menu", true); //Attempt save - if (!config.save()) - Util.severe("Error while writing to config.yml"); + plugin.saveConfig(); } diff --git a/src/uk/co/oliwali/WhoAreYou/Permission.java b/src/uk/co/oliwali/WhoAreYou/Permission.java deleted file mode 100644 index 09efe44..0000000 --- a/src/uk/co/oliwali/WhoAreYou/Permission.java +++ /dev/null @@ -1,93 +0,0 @@ -package uk.co.oliwali.WhoAreYou; - -import org.bukkit.entity.Player; -import org.bukkit.plugin.Plugin; - -import com.nijiko.permissions.PermissionHandler; -import com.nijikokun.bukkit.Permissions.Permissions; - -public class Permission { - - private WhoAreYou plugin; - private PermissionPlugin handler = PermissionPlugin.OP; - private PermissionHandler permissionPlugin; - - public Permission(WhoAreYou instance) { - plugin = instance; - Plugin permissions = plugin.getServer().getPluginManager().getPlugin("Permissions"); - - if (permissions != null) { - permissionPlugin = ((Permissions)permissions).getHandler(); - handler = PermissionPlugin.PERMISSIONS; - Util.info("Using Permissions for user permissions"); - } - else { - Util.info("No permission handler detected, only ops can use commands"); - } - } - - private boolean hasPermission(Player player, String node) { - switch (handler) { - case PERMISSIONS: - return permissionPlugin.has(player, node); - case OP: - return player.isOp(); - } - return false; - } - - public boolean list(Player player) { - return hasPermission(player, "whoareyou.list"); - } - public boolean player(Player player) { - return hasPermission(player, "whoareyou.player"); - } - public boolean world(Player player) { - return hasPermission(player, "whoareyou.world"); - } - - public String getPrefix(Player player) { - String prefix = "&f"; - switch (handler) { - case PERMISSIONS: - String permPrefix = permissionPlugin.getGroupPrefix(player.getWorld().getName(), getGroup(player)); - if (permPrefix != null) - prefix = permPrefix; - break; - case OP: - if (player.isOp()) - prefix = "&c"; - break; - } - if (prefix.length() == 0) - return "&f"; - return prefix; - } - - public String getSuffix(Player player) { - String prefix = ""; - switch (handler) { - case PERMISSIONS: - prefix = permissionPlugin.getGroupPrefix(player.getWorld().getName(), getGroup(player)); - break; - } - return prefix; - } - - public String getGroup(Player player) { - switch (handler) { - case PERMISSIONS: - return permissionPlugin.getGroup(player.getWorld().getName(), player.getName()); - case OP: - if (player.isOp()) - return "op"; - } - return "regular"; - } - - private enum PermissionPlugin { - PERMISSIONS, - OP - } - -} diff --git a/src/uk/co/oliwali/WhoAreYou/WAUPermission.java b/src/uk/co/oliwali/WhoAreYou/WAUPermission.java new file mode 100644 index 0000000..0b982e9 --- /dev/null +++ b/src/uk/co/oliwali/WhoAreYou/WAUPermission.java @@ -0,0 +1,52 @@ +package uk.co.oliwali.WhoAreYou; + +import org.bukkit.entity.Player; + + +public class WAUPermission { + + private WhoAreYou plugin; + + + public WAUPermission(WhoAreYou instance) { + plugin = instance; + } + + private boolean hasPermission(Player player, String node) { + return player.hasPermission(node); + } + + public boolean list(Player player) { + return hasPermission(player, "whoareyou.list"); + } + public boolean player(Player player) { + return hasPermission(player, "whoareyou.player"); + } + public boolean world(Player player) { + return hasPermission(player, "whoareyou.world"); + } + + public String getPrefix(Player player) { + String prefix = "&f"; + prefix = plugin.chat.getGroupPrefix(player.getWorld(),getGroup(player)); + + if (prefix.length() == 0) + return "&f"; + return prefix; + } + + public String getSuffix(Player player) { + String prefix = ""; + prefix = plugin.chat.getGroupSuffix(player.getWorld(), getGroup(player)); + return prefix; + } + + public String getGroup(Player playerInfo) { + return plugin.permission.getPrimaryGroup(playerInfo); + } + + + + + +} diff --git a/src/uk/co/oliwali/WhoAreYou/WAYPlayerListener.java b/src/uk/co/oliwali/WhoAreYou/WAYPlayerListener.java index e28bd17..7b74585 100644 --- a/src/uk/co/oliwali/WhoAreYou/WAYPlayerListener.java +++ b/src/uk/co/oliwali/WhoAreYou/WAYPlayerListener.java @@ -1,17 +1,20 @@ package uk.co.oliwali.WhoAreYou; import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.Listener; import org.bukkit.event.player.PlayerJoinEvent; -import org.bukkit.event.player.PlayerListener; -public class WAYPlayerListener extends PlayerListener { + +public class WAYPlayerListener implements Listener { public WhoAreYou plugin; public WAYPlayerListener(WhoAreYou instance) { plugin = instance; } - + @EventHandler(priority = EventPriority.MONITOR) public void onPlayerJoin(PlayerJoinEvent event) { if (plugin.config.onlineMsg) plugin.who(event.getPlayer()); diff --git a/src/uk/co/oliwali/WhoAreYou/WhoAreYou.java b/src/uk/co/oliwali/WhoAreYou/WhoAreYou.java index cf9e4eb..64c6bea 100644 --- a/src/uk/co/oliwali/WhoAreYou/WhoAreYou.java +++ b/src/uk/co/oliwali/WhoAreYou/WhoAreYou.java @@ -3,23 +3,36 @@ import java.util.ArrayList; import java.util.List; +import net.milkbowl.vault.chat.Chat; +import net.milkbowl.vault.permission.Permission; + import org.bukkit.Location; import org.bukkit.World; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; -import org.bukkit.event.Event; -import org.bukkit.event.Event.Type; import org.bukkit.plugin.PluginManager; +import org.bukkit.plugin.RegisteredServiceProvider; import org.bukkit.plugin.java.JavaPlugin; public class WhoAreYou extends JavaPlugin { public static String name; public static String version; - public Permission permissions; + public WAUPermission permissions; public Config config; private WAYPlayerListener playerListener = new WAYPlayerListener(this); + public Chat chat; + public Permission permission; + + private Boolean setupPermissions() + { + RegisteredServiceProvider permissionProvider = getServer().getServicesManager().getRegistration(net.milkbowl.vault.permission.Permission.class); + if (permissionProvider != null) { + permission = permissionProvider.getProvider(); + } + return (permission != null); + } public void onDisable() { Util.info("Version " + version + " disabled!"); @@ -29,15 +42,28 @@ public void onEnable() { name = this.getDescription().getName(); version = this.getDescription().getVersion(); config = new Config(this); - permissions = new Permission(this); + permissions = new WAUPermission(this); // Register events PluginManager pm = getServer().getPluginManager(); - pm.registerEvent(Type.PLAYER_JOIN, playerListener, Event.Priority.Monitor, this); + pm.registerEvents(playerListener, this); + + setupChat(); + setupPermissions(); Util.info("Version " + version + " enabled!"); } + private Boolean setupChat() + { + RegisteredServiceProvider chatProvider = getServer().getServicesManager().getRegistration(net.milkbowl.vault.chat.Chat.class); + if (chatProvider != null) { + chat = chatProvider.getProvider(); + } + + return (chat != null); + } + private void sendPlayerList(CommandSender sender, String message, List players) { for (Player player : players.toArray(new Player[0])) message = message + " " + permissions.getPrefix(player) + player.getName() + permissions.getSuffix(player);