Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Changed: Create local variables on the heap -> faster dying

Added: Custom colors
  • Loading branch information...
commit f118ea20f58b197ae2fd45cb4f2c93a80a86fa8b 1 parent 0ef87b0
@timbru31 authored
View
11 src/config.yml
@@ -9,6 +9,8 @@ ColorMe:
displayName: true
tabList: true
playerTitle: true
+ signColors: true
+ chatColors: true
colors:
black: true
dark_blue: true
@@ -29,7 +31,14 @@ colors:
magic: true
random: true
rainbow: true
+ bold: true
+ strikethrough: true
+ underline: true
+ italic: true
+ custom: true
global_default:
prefix: ''
suffix: ''
- color: ''
+ color: ''
+updateConfig: false
+chatBrackets: true
View
80 src/de/xghostkillerx/colorme/Actions.java
@@ -12,10 +12,6 @@ public Actions(ColorMe instance) {
plugin = instance;
}
- private static String actualValue, color, colorChar, displayName, cleanDisplayName, newName, msg, message, sub, updatedString;
- private static int i, z = 0;
- private static char ch;
-
// Checks if the player is itself
static boolean self(CommandSender sender, String name) {
return (sender.equals(Bukkit.getServer().getPlayerExact(name))) ? true : false;
@@ -26,7 +22,7 @@ public static String get(String name, String world, String pluginPart) {
// Player in the config? Yes -> get the config, no -> nothing
if (ColorMe.players.contains(name + "." + pluginPart + "." + world)) {
String string = ColorMe.players.getString(name + "." + pluginPart + "." + world);
- updatedString = replaceThings(string);
+ String updatedString = replaceThings(string);
return updatedString;
}
else return "";
@@ -35,12 +31,13 @@ public static String get(String name, String world, String pluginPart) {
// Get global default
public static String getGlobal(String pluginPart) {
String string = ColorMe.config.getString("global_default." + pluginPart);
- updatedString = replaceThings(string);
+ String updatedString = replaceThings(string);
return updatedString;
}
public static String replaceThings(String string) {
// While random is in there
+ String sub;
while (string.contains("&random")) {
// Without random
int i = string.indexOf("&random") + 7;
@@ -123,7 +120,7 @@ public static String replaceThings(String string) {
// Set player's color/prefix/suffix
static boolean set(String name, String value, String world, String pluginPart) {
- actualValue = get(name, world, pluginPart);
+ String actualValue = get(name, world, pluginPart);
// If the colors are the same return false
if (actualValue.equalsIgnoreCase(value)) {
return false;
@@ -171,11 +168,13 @@ static boolean removeGlobal(String pluginPart) {
}
// Update the displayName, tabName, title, prefix & suffix in a specific world (after setting, removing, onJoin and onChat)
+ @SuppressWarnings("null")
static void updateName(String name, String color) {
Player player = Bukkit.getServer().getPlayerExact(name);
if (player != null) {
- displayName = player.getDisplayName();
- cleanDisplayName = ChatColor.stripColor(displayName);
+ String displayName = player.getDisplayName();
+ String cleanDisplayName = ChatColor.stripColor(displayName);
+ String newName;
boolean tabList = ColorMe.config.getBoolean("ColorMe.tabList");
boolean playerTitle = ColorMe.config.getBoolean("ColorMe.playerTitle");
// Name color
@@ -190,7 +189,7 @@ else if (color.equalsIgnoreCase("rainbow")) {
}
// Custom colors
else if (ColorMe.colors.contains(color) && (ColorMe.colors.getString(color).trim().length() > 1 ? true : false) == true) {
- player.sendMessage("DEBUG");
+ player.setDisplayName(updateCustomColor(color, cleanDisplayName, player) + ChatColor.WHITE);
}
// Normal
else {
@@ -206,7 +205,7 @@ else if (color.equalsIgnoreCase("rainbow")) {
newName = rainbowColor(cleanDisplayName);
}
else if (ColorMe.colors.contains(color) && (ColorMe.colors.getString(color).trim().length() > 1 ? true : false) == true) {
- player.sendMessage("DEBUG 2");
+ newName = updateCustomColor(color, cleanDisplayName, player);
}
else newName = ChatColor.valueOf(color.toUpperCase()) + cleanDisplayName;
// Shorten it, if too long
@@ -229,7 +228,7 @@ else if (color.equalsIgnoreCase("rainbow")) {
spoutPlayer.setTitle(rainbowColor(cleanDisplayName));
}
else if (ColorMe.colors.contains(color) && (ColorMe.colors.getString(color).trim().length() > 1 ? true : false) == true) {
- player.sendMessage("DEBUG 3");
+ spoutPlayer.setTitle(updateCustomColor(color, cleanDisplayName, player));
}
// Normal color
else spoutPlayer.setTitle(ChatColor.valueOf(color.toUpperCase()) + cleanDisplayName);
@@ -237,19 +236,41 @@ else if (ColorMe.colors.contains(color) && (ColorMe.colors.getString(color).trim
}
}
+ static String updateCustomColor(String color, String text, Player player) {
+ /* How to: Get Color. Color one char. Get next value, color next char. Same char = Multiple values.
+ * Beispiel: &c&e&c&e, name -> ChatColor.RED + "n" + ChatColor.YELLOW + "a". RAINBOW/RANDOM?!
+ */
+ String updatedText = "";
+ String colorChars = ColorMe.colors.getString(color).replaceAll("&([0-9a-fk-or])", "\u00A7$1");
+ if (!colorChars.contains("§") || colorChars.contains("&") || !colorChars.startsWith("§")) return text;
+ String sub = colorChars, sub2 = "";
+ for (int i = 0; i < text.length(); i++) {
+ // If substring is empty of values, reset
+ if (!sub.contains("§")) sub = colorChars;
+ // Get the § extracted
+ if (sub.contains("§")) {
+ sub2 = sub.substring(0, 2);
+ }
+ updatedText += sub2 + text.charAt(i);
+ sub = sub.replaceFirst(sub2, "");
+ }
+
+ return updatedText;
+ }
+
// Restore the "clean", white name
static void restoreName(String name) {
Player player = Bukkit.getServer().getPlayerExact(name);
if (player != null) {
- displayName = player.getDisplayName();
- cleanDisplayName = ChatColor.stripColor(displayName);
+ String displayName = player.getDisplayName();
+ String cleanDisplayName = ChatColor.stripColor(displayName);
boolean tabList = ColorMe.config.getBoolean("tabList");
boolean playerTitle = ColorMe.config.getBoolean("playerTitle");
// No name -> back to white
player.setDisplayName(ChatColor.WHITE + cleanDisplayName);
if (tabList == true) {
// If the TAB name is longer than 16 shorten it!
- newName = cleanDisplayName;
+ String newName = cleanDisplayName;
if (newName.length() > 16) {
newName = cleanDisplayName.substring(0, 12) + ChatColor.WHITE + "..";
}
@@ -264,14 +285,14 @@ static void restoreName(String name) {
// The list of colors
static void listColors(CommandSender sender) {
- message = ColorMe.localization.getString("color_list");
+ String message = ColorMe.localization.getString("color_list");
ColorMe.message(sender, null, message, null, null, null, null);
- msg = "";
+ String msg = "";
// As long as all colors aren't reached, including magic manual
for (ChatColor value : ChatColor.values()) {
// get the name from the integer
- color = value.name().toLowerCase();
- colorChar = Character.toString(value.getChar());
+ String color = value.name().toLowerCase();
+ String colorChar = Character.toString(value.getChar());
if (colorChar.equalsIgnoreCase("r")) continue;
if (colorChar.equalsIgnoreCase("n")) continue;
if (colorChar.equalsIgnoreCase("m")) continue;
@@ -296,12 +317,12 @@ static void listColors(CommandSender sender) {
// Used to create a random effect
static String randomColor(String name) {
- newName = "";
+ String newName = "";
// As long as the length of the name isn't reached
- for (i = 0; i < name.length(); i++) {
+ for (int i = 0; i < name.length(); i++) {
// Roll the dice between 0 and 16 ;)
int x = (int)(Math.random()*ChatColor.values().length);
- ch = name.charAt(i);
+ char ch = name.charAt(i);
// Color the character
newName += ChatColor.values()[x] + Character.toString(ch);
}
@@ -311,14 +332,14 @@ static String randomColor(String name) {
// Used to create a rainbow effect
static String rainbowColor(String name) {
// Had to store the rainbow manually. Why did Mojang store it so..., forget it
- newName = "";
- z = 0;
+ String newName = "";
+ int z = 0;
String rainbow[] = {"DARK_RED", "RED", "GOLD", "YELLOW", "GREEN", "DARK_GREEN", "AQUA", "DARK_AQUA", "BLUE", "DARK_BLUE", "LIGHT_PURPLE", "DARK_PURPLE"};
// As long as the length of the name isn't reached
- for (i = 0; i < name.length(); i++) {
+ for (int i = 0; i < name.length(); i++) {
// Reset if z reaches 12
if (z == 12) z = 0;
- ch = name.charAt(i);
+ char ch = name.charAt(i);
// Add to the new name the colored character
newName += ChatColor.valueOf(rainbow[z]) + Character.toString(ch);
z++;
@@ -358,8 +379,8 @@ static boolean isDisabled(String color) {
// Displays the specific help
static boolean help(CommandSender sender, String pluginPart) {
- for (i = 1; i <= 9; i++) {
- message = ColorMe.localization.getString("help_" + pluginPart + "_" + Integer.toString(i));
+ for (int i = 1; i <= 9; i++) {
+ String message = ColorMe.localization.getString("help_" + pluginPart + "_" + Integer.toString(i));
ColorMe.message(sender, null, message, null, null, null, null);
}
return true;
@@ -368,13 +389,14 @@ static boolean help(CommandSender sender, String pluginPart) {
// Reloads the plugin
static boolean reload(CommandSender sender) {
ColorMe.loadConfigsAgain();
- message = ColorMe.localization.getString("reload");
+ String message = ColorMe.localization.getString("reload");
ColorMe.message(sender, null, message, null, null, null, null);
return true;
}
// Update the name
static void checkNames(String name, String world) {
+ String color;
// Check for color and valid ones, else restore
if (Actions.has(name, world, "colors")) {
if (Actions.validColor(ColorMe.players.getString(name + ".colors." + world)) == true) {
View
7 src/de/xghostkillerx/colorme/ColorMeCommands.java
@@ -25,11 +25,10 @@
public ColorMeCommands(ColorMe instance) {
plugin = instance;
}
- private String pluginPart = "colors", message, target, color, senderName, world = "default", globalColor;
- private Double cost;
-
+
// Commands for coloring
public boolean onCommand (CommandSender sender, Command command, String commandLabel, String[] args) {
+ String pluginPart = "colors", message, target, color, senderName, world = "default", globalColor;
// Returns the color list
if (args.length > 0 && args[0].equalsIgnoreCase("list")) {
if (sender.hasPermission("colorme.list") || sender.hasPermission("prefixer.list") || sender.hasPermission("suffixer.list")) {
@@ -287,7 +286,7 @@ public boolean onCommand (CommandSender sender, Command command, String commandL
// Self coloring
if (sender.hasPermission("colorme.self." + color.toLowerCase()) && Actions.self(sender, target)) {
// Without economy or costs are null
- cost = ColorMe.config.getDouble("costs.color");
+ Double cost = ColorMe.config.getDouble("costs.color");
if (plugin.economy == null || cost == 0) {
Actions.set(senderName, color, world, pluginPart);
message = ColorMe.localization.getString("changed_color_self");
View
29 src/de/xghostkillerx/colorme/ColorMePlayerListener.java
@@ -27,15 +27,13 @@ public ColorMePlayerListener(ColorMe instance) {
plugin = instance;
}
private String[] pluginPart = {"colors", "prefix", "suffix"};
- private String actualPart, name, world, sub1, sub2, suffix = null, prefix = null, brackets;
- private int i, length;
// Loads the the values and set them to default one if not known
@EventHandler
public void onPlayerJoin(PlayerJoinEvent event) {
Player player = event.getPlayer();
- name = player.getName().toLowerCase();
- world = player.getWorld().getName().toLowerCase();
+ String name = player.getName().toLowerCase();
+ String world = player.getWorld().getName().toLowerCase();
CheckRoutine(player, name, world);
}
@@ -44,8 +42,9 @@ public void onPlayerJoin(PlayerJoinEvent event) {
@EventHandler
public void onPlayerChat(PlayerChatEvent event) {
Player player = event.getPlayer();
- name = player.getName().toLowerCase();
- world = player.getWorld().getName().toLowerCase();
+ String name = player.getName().toLowerCase();
+ String world = player.getWorld().getName().toLowerCase();
+ String prefix = "", suffix = "";
CheckRoutine(player, name, world);
if (ColorMe.Prefixer) {
// Get world prefix if available
@@ -83,11 +82,11 @@ else if (ColorMe.globalSuffix) {
if (suffix != null) {
// Search the bracket
if (event.getFormat().contains(">")) {
- i = event.getFormat().lastIndexOf(">") + 1;
- length = event.getFormat().length();
+ int i = event.getFormat().lastIndexOf(">") + 1;
+ int length = event.getFormat().length();
// Substring 1 until the bracket, substring 2 after the bracket
- sub1 = event.getFormat().substring(0, i);
- sub2 = event.getFormat().substring(i, length);
+ String sub1 = event.getFormat().substring(0, i);
+ String sub2 = event.getFormat().substring(i, length);
// Insert the suffix between ;)
event.setFormat(sub1 + " " + suffix + ChatColor.WHITE + ":" + sub2);
}
@@ -95,7 +94,7 @@ else if (ColorMe.globalSuffix) {
}
// Remove the chat brackets if wanted
if (!ColorMe.chatBrackets) {
- brackets = event.getFormat();
+ String brackets = event.getFormat();
brackets = brackets.replaceAll("<", " ")
.replaceAll(">", "");
event.setFormat(brackets);
@@ -104,10 +103,6 @@ else if (ColorMe.globalSuffix) {
if (ColorMe.chatColors) {
event.setMessage(Actions.replaceThings(event.getMessage()));
}
-
- prefix = null;
- suffix = null;
- brackets = null;
}
// Check for the player and update the file is values are unknown
@@ -122,8 +117,8 @@ private void CheckRoutine(Player player, String name, String world) {
ColorMe.players.set(name + ".suffix." + world, "");
ColorMe.savePlayers();
}
- for (i = 0; i <= 2; i++) {
- actualPart = pluginPart[i];
+ for (int i = 0; i <= 2; i++) {
+ String actualPart = pluginPart[i];
if (!ColorMe.players.contains(name + "." + actualPart + "." + world)) {
ColorMe.players.set(name + "." + actualPart + "." + world, "");
ColorMe.savePlayers();
View
5 src/de/xghostkillerx/colorme/PrefixCommands.java
@@ -12,11 +12,10 @@
public PrefixCommands(ColorMe instance) {
plugin = instance;
}
- private String pluginPart = "prefix", message, target, prefix, senderName, world = "default", globalPrefix;
- private Double cost;
// Commands for prefixing
public boolean onCommand (CommandSender sender, Command command, String commandLabel, String[] args) {
+ String message, globalPrefix, target, senderName, prefix = "", pluginPart = "prefix", world = "default";
// Reloads the configs
if (args.length > 0 && args[0].equalsIgnoreCase("reload")) {
if (sender.hasPermission("prefixer.reload")) {
@@ -248,7 +247,7 @@ public boolean onCommand (CommandSender sender, Command command, String commandL
// Self prefixing
if (sender.hasPermission("prefixer.self") && Actions.self(sender, target)) {
// Without economy or costs are null
- cost = ColorMe.config.getDouble("costs.prefix");
+ Double cost = ColorMe.config.getDouble("costs.prefix");
if (plugin.economy == null || cost == 0) {
Actions.set(senderName, prefix, world, pluginPart);
message = ColorMe.localization.getString("changed_prefix_self");
View
5 src/de/xghostkillerx/colorme/SuffixCommands.java
@@ -12,11 +12,10 @@
public SuffixCommands(ColorMe instance) {
plugin = instance;
}
- private String pluginPart = "suffix", message, target, suffix, senderName, world = "default", globalSuffix;
- private Double cost;
// Commands for suffixing
public boolean onCommand (CommandSender sender, Command command, String commandLabel, String[] args) {
+ String pluginPart = "suffix", message, target, suffix = "", senderName, world = "default", globalSuffix;
// Reloads the configs
if (args.length > 0 && args[0].equalsIgnoreCase("reload")) {
if (sender.hasPermission("suffixer.reload")) {
@@ -248,7 +247,7 @@ public boolean onCommand (CommandSender sender, Command command, String commandL
// Self suffixing
if (sender.hasPermission("suffixer.self") && Actions.self(sender, target)) {
// Without economy or costs are null
- cost = ColorMe.config.getDouble("costs.suffix");
+ Double cost = ColorMe.config.getDouble("costs.suffix");
if (plugin.economy == null || cost == 0) {
Actions.set(senderName, suffix, world, pluginPart);
message = ColorMe.localization.getString("changed_suffix_self");
Please sign in to comment.
Something went wrong with that request. Please try again.