Skip to content

Commit 8aa59ca

Browse files
committed
[Refactor/Feature/Feature] Convert all getName() references to UUID./Start of Custom Event addition./Add TabCompletion of Commands.
1 parent 9f8c4fc commit 8aa59ca

21 files changed

Lines changed: 644 additions & 495 deletions

pom.xml

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<name>MChat</name>
77
<artifactId>MChat</artifactId>
88
<packaging>jar</packaging>
9-
<version>1.7.2-R0.0.1-SNAPSHOT</version>
9+
<version>1.7.2-R0.0.2-SNAPSHOT</version>
1010
<url>https://github.com/Q0rDev/MChat</url>
1111
<description>Chat Formatting for Bukkit</description>
1212

@@ -42,7 +42,7 @@
4242
<dependency>
4343
<groupId>org.bukkit</groupId>
4444
<artifactId>bukkit</artifactId>
45-
<version>1.7.2-R0.3</version>
45+
<version>1.7.5-R0.1-SNAPSHOT</version>
4646
<type>jar</type>
4747
<scope>compile</scope>
4848
</dependency>
@@ -74,13 +74,6 @@
7474
<type>jar</type>
7575
<scope>compile</scope>
7676
</dependency>
77-
<dependency>
78-
<groupId>me.desmin88</groupId>
79-
<artifactId>MobDisguise</artifactId>
80-
<version>1.63</version>
81-
<type>jar</type>
82-
<scope>compile</scope>
83-
</dependency>
8477
<dependency>
8578
<groupId>com.herocraftonline</groupId>
8679
<artifactId>Heroes</artifactId>

src/main/java/ca/q0r/mchat/MChat.java

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
import ca.q0r.mchat.yml.YmlType;
1919
import ca.q0r.mchat.yml.config.ConfigType;
2020
import org.bukkit.Bukkit;
21-
import org.bukkit.command.CommandExecutor;
21+
import org.bukkit.command.TabExecutor;
2222
import org.bukkit.entity.Player;
2323
import org.bukkit.plugin.Plugin;
2424
import org.bukkit.plugin.PluginDescriptionFile;
@@ -71,9 +71,9 @@ public void run() {
7171

7272
// Add All Players To Info.yml
7373
if (ConfigType.INFO_ADD_NEW_PLAYERS.getBoolean()) {
74-
for (Player players : getServer().getOnlinePlayers()) {
75-
if (YmlManager.getYml(YmlType.INFO_YML).getConfig().get("users." + players.getName()) == null) {
76-
Writer.addBase(players.getName(), ConfigType.INFO_DEFAULT_GROUP.getString(), false);
74+
for (Player player : getServer().getOnlinePlayers()) {
75+
if (YmlManager.getYml(YmlType.INFO_YML).getConfig().get("users." + player.getUniqueId().toString()) == null) {
76+
Writer.addBase(player.getUniqueId().toString(), InfoType.USER);
7777
}
7878
}
7979
}
@@ -124,11 +124,9 @@ public void onDisable() {
124124

125125
private void registerEvents() {
126126
if (!ConfigType.MCHAT_API_ONLY.getBoolean()) {
127-
pm.registerEvents(new PlayerListener(this), this);
128-
129127
pm.registerEvents(new ChatListener(this), this);
130-
131128
pm.registerEvents(new CommandListener(), this);
129+
pm.registerEvents(new PlayerListener(this), this);
132130
}
133131
}
134132

@@ -146,12 +144,13 @@ private void setupCommands() {
146144
regCommands("mchatuser", new InfoAlterCommand("mchatuser", InfoType.USER));
147145
regCommands("mchatgroup", new InfoAlterCommand("mchatgroup", InfoType.GROUP));
148146

149-
regCommands("mchatme", new MeCommand(this));
147+
regCommands("mchatme", new MeCommand());
150148
}
151149

152-
private void regCommands(String command, CommandExecutor executor) {
150+
private void regCommands(String command, TabExecutor executor) {
153151
if (getCommand(command) != null) {
154152
getCommand(command).setExecutor(executor);
153+
getCommand(command).setTabCompleter(executor);
155154
}
156155
}
157156

src/main/java/ca/q0r/mchat/api/API.java

Lines changed: 45 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ public class API {
4949
static Boolean pBukkitB;
5050

5151
// Var Map
52-
private static final SortedMap<String, Object> gVarMap = Collections.synchronizedSortedMap(new TreeMap<String, Object>());
53-
private static final SortedMap<String, Object> pVarMap = Collections.synchronizedSortedMap(new TreeMap<String, Object>());
52+
private static final SortedMap<String, String> gVarMap = Collections.synchronizedSortedMap(new TreeMap<String, String>());
53+
private static final SortedMap<String, String> pVarMap = Collections.synchronizedSortedMap(new TreeMap<String, String>());
5454

5555
// Maps
5656
private static HashMap<String, Boolean> spying;
@@ -70,7 +70,7 @@ public static void initialize() {
7070
* @param var Name of Variable being added.
7171
* @param value Value of Variable being added.
7272
*/
73-
public static void addGlobalVar(String var, Object value) {
73+
public static void addGlobalVar(String var, String value) {
7474
if (var == null || var.isEmpty()) {
7575
return;
7676
}
@@ -115,11 +115,11 @@ public static SortedMap<String, Object> getGlobalVarMap() {
115115
/**
116116
* Player Variable Addition
117117
*
118-
* @param pName Name of Player this Variable is being added for.
118+
* @param uuid UUID of Player this Variable is being added for.
119119
* @param var Name of Variable being added.
120120
* @param value Value of Variable being added.
121121
*/
122-
public static void addPlayerVar(String pName, String var, Object value) {
122+
public static void addUuidVar(UUID uuid, String var, String value) {
123123
if (var == null || var.isEmpty()) {
124124
return;
125125
}
@@ -129,20 +129,20 @@ public static void addPlayerVar(String pName, String var, Object value) {
129129
}
130130

131131
synchronized (pVarMap) {
132-
pVarMap.put(pName + "|" + var, value);
132+
pVarMap.put(uuid.toString() + "|" + var, value);
133133
}
134134
}
135135

136136
/**
137137
* Player Variable Removal
138138
*
139-
* @param pName Name of Player this Variable is being removed from.
140-
* @param var Name of Variable being removed.
139+
* @param uuid UUID of Player this Variable is being removed from.
140+
* @param var Name of Variable being removed.
141141
*/
142-
public static void removePlayerVar(String pName, String var) {
142+
public static void removeUuidVar(UUID uuid, String var) {
143143
synchronized (pVarMap) {
144-
if (pVarMap.get(pName + "|" + var) != null) {
145-
pVarMap.remove(pName + "|" + var);
144+
if (pVarMap.get(uuid.toString() + "|" + var) != null) {
145+
pVarMap.remove(uuid.toString() + "|" + var);
146146
}
147147
}
148148
}
@@ -152,8 +152,8 @@ public static void removePlayerVar(String pName, String var) {
152152
*
153153
* @return Map of Custom Variables.
154154
*/
155-
public static SortedMap<String, Object> getPlayerVarMap() {
156-
SortedMap<String, Object> map = new TreeMap<>();
155+
public static SortedMap<String, String> getUuidVarMap() {
156+
SortedMap<String, String> map = new TreeMap<>();
157157

158158
synchronized (pVarMap) {
159159
map.putAll(Collections.unmodifiableSortedMap(pVarMap));
@@ -227,7 +227,7 @@ public static String createBasicBar(float currentValue, float maxValue, float ba
227227
* @return Player has Node.
228228
*/
229229
public static Boolean checkPermissions(Player player, World world, String node) {
230-
return checkPermissions(player.getName(), world.getName(), node) || player.hasPermission(node) || player.isOp();
230+
return checkPermissions(player.getUniqueId(), world.getName(), node) || player.hasPermission(node) || player.isOp();
231231
}
232232

233233
/**
@@ -245,6 +245,18 @@ public static Boolean checkPermissions(String pName, String world, String node)
245245
|| Bukkit.getServer().getPlayer(pName) != null && Bukkit.getServer().getPlayer(pName).hasPermission(node);
246246
}
247247

248+
/**
249+
* Permission Checking
250+
*
251+
* @param uuid UUID of Player being checked.
252+
* @param world Name of Player's World.
253+
* @param node Permission Node being checked.
254+
* @return Player has Node.
255+
*/
256+
public static Boolean checkPermissions(UUID uuid, String world, String node) {
257+
return checkPermissions(Bukkit.getPlayer(uuid).getName(), world, node);
258+
}
259+
248260
/**
249261
* Permission Checking
250262
*
@@ -328,12 +340,29 @@ public static Boolean isPluginEnabled(PluginType type) {
328340
/**
329341
* Spying HashMap.
330342
*
331-
* @return Map of Player's Spying status.
343+
* @return Map of Spying statuses.
332344
*/
333-
public static HashMap<String, Boolean> isSpying() {
345+
public static HashMap<String, Boolean> getSpying() {
334346
return spying;
335347
}
336348

349+
/**
350+
* Gets Player based on partial UUID.
351+
*
352+
* @param uuid Partial or complete UUID to lookup.
353+
* @return Player object or null if not found.
354+
*/
355+
public static Player getPlayer(String uuid) {
356+
for (Player player : Bukkit.getServer().getOnlinePlayers()) {
357+
if (player.getUniqueId().toString().startsWith(uuid.toLowerCase())) {
358+
return player;
359+
}
360+
}
361+
362+
return null;
363+
}
364+
365+
337366
private static void setupPlugins() {
338367
PluginManager pm = Bukkit.getServer().getPluginManager();
339368
Plugin pluginTest;

src/main/java/ca/q0r/mchat/api/Parser.java

Lines changed: 29 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import ca.q0r.mchat.yml.locale.LocaleType;
1212

1313
import java.util.Map;
14+
import java.util.UUID;
1415
import java.util.regex.Matcher;
1516
import java.util.regex.Pattern;
1617

@@ -21,16 +22,16 @@ public class Parser {
2122
/**
2223
* Core Formatting
2324
*
24-
* @param pName Name of Player being reflected upon.
25+
* @param uuid Name of Player being reflected upon.
2526
* @param world Player's World.
2627
* @param msg Message being displayed.
2728
* @param format Resulting Format.
2829
* @return Formatted Message.
2930
*/
30-
public static String parseMessage(String pName, String world, String msg, String format) {
31+
public static String parseMessage(UUID uuid, String world, String msg, String format) {
3132
msg = msg != null ? msg : "";
3233

33-
format = parseVars(format, pName, world);
34+
format = parseVars(format, uuid, world);
3435

3536
msg = msg.replaceAll("%", "%%");
3637

@@ -40,95 +41,95 @@ public static String parseMessage(String pName, String world, String msg, String
4041

4142
Integer cInt = ConfigType.MCHAT_CAPS_LOCK_RANGE.getInteger();
4243

43-
if (!API.checkPermissions(pName, world, "mchat.bypass.clock") && cInt > 0) {
44+
if (!API.checkPermissions(uuid, world, "mchat.bypass.clock") && cInt > 0) {
4445
msg = fixCaps(msg, cInt);
4546
}
4647

4748
if (format == null) {
4849
return msg;
4950
}
5051

51-
if (API.checkPermissions(pName, world, "mchat.coloredchat")) {
52+
if (API.checkPermissions(uuid, world, "mchat.coloredchat")) {
5253
msg = MessageUtil.addColour(msg);
5354
}
5455

55-
if (!API.checkPermissions(pName, world, "mchat.censorbypass")) {
56+
if (!API.checkPermissions(uuid, world, "mchat.censorbypass")) {
5657
msg = replaceCensoredWords(msg);
5758
}
5859

59-
format = VariableManager.replaceCustVars(pName, format);
60-
format = VariableManager.replaceVars(format, pName, msg, true);
60+
format = VariableManager.replaceCustVars(uuid, format);
61+
format = VariableManager.replaceVars(format, uuid, msg, true);
6162

6263
return format;
6364
}
6465

6566
/**
6667
* Chat Formatting
6768
*
68-
* @param pName Name of Player being reflected upon.
69+
* @param uuid UUID of Player being reflected upon.
6970
* @param world Name of Player's World.
7071
* @param msg Message being displayed.
7172
* @return Formatted Chat Message.
7273
*/
73-
public static String parseChatMessage(String pName, String world, String msg) {
74-
return parseMessage(pName, world, msg, LocaleType.FORMAT_CHAT.getRaw());
74+
public static String parseChatMessage(UUID uuid, String world, String msg) {
75+
return parseMessage(uuid, world, msg, LocaleType.FORMAT_CHAT.getRaw());
7576
}
7677

7778
/**
7879
* Player Name Formatting
7980
*
80-
* @param pName Name of Player being reflected upon.
81+
* @param uuid UUID of Player being reflected upon.
8182
* @param world Name of Player's World.
8283
* @return Formatted Player Name.
8384
*/
84-
public static String parsePlayerName(String pName, String world) {
85-
return parseMessage(pName, world, "", LocaleType.FORMAT_NAME.getRaw());
85+
public static String parsePlayerName(UUID uuid, String world) {
86+
return parseMessage(uuid, world, "", LocaleType.FORMAT_NAME.getRaw());
8687
}
8788

8889
/**
8990
* Event Message Formatting
9091
*
91-
* @param pName Name of Player being reflected upon.
92+
* @param uuid UUID of Player being reflected upon.
9293
* @param world Name of Player's World.
9394
* @param type Event Type being formatted.
9495
* @return Formatted Event Message.
9596
*/
96-
public static String parseEvent(String pName, String world, EventType type) {
97-
return parseMessage(pName, world, "", API.replace(Reader.getEventMessage(type), "player", parsePlayerName(pName, world), IndicatorType.LOCALE_VAR));
97+
public static String parseEvent(UUID uuid, String world, EventType type) {
98+
return parseMessage(uuid, world, "", API.replace(Reader.getEventMessage(type), "player", parsePlayerName(uuid, world), IndicatorType.LOCALE_VAR));
9899
}
99100

100101
/**
101102
* TabbedList Formatting
102103
*
103-
* @param pName Name of Player being reflected upon.
104+
* @param uuid UUID of Player being reflected upon.
104105
* @param world Name of Player's World.
105106
* @return Formatted TabbedList Name.
106107
*/
107-
public static String parseTabbedList(String pName, String world) {
108-
return parseMessage(pName, world, "", LocaleType.FORMAT_TABBED_LIST.getRaw());
108+
public static String parseTabbedList(UUID uuid, String world) {
109+
return parseMessage(uuid, world, "", LocaleType.FORMAT_TABBED_LIST.getRaw());
109110
}
110111

111112
/**
112113
* ListCommand Formatting.
113114
*
114-
* @param pName Name of Player being reflected upon.
115+
* @param uuid UUID of Player being reflected upon.
115116
* @param world Name of Player's World.
116117
* @return Formatted ListCommand Name.
117118
*/
118-
public static String parseListCmd(String pName, String world) {
119-
return parseMessage(pName, world, "", LocaleType.FORMAT_LIST_CMD.getRaw());
119+
public static String parseListCmd(UUID uuid, String world) {
120+
return parseMessage(uuid, world, "", LocaleType.FORMAT_LIST_CMD.getRaw());
120121
}
121122

122123
/**
123124
* Me Formatting.
124125
*
125-
* @param pName Name of Player being reflected upon.
126+
* @param uuid UUID of Player being reflected upon.
126127
* @param world Name of Player's World.
127128
* @param msg Message being displayed.
128129
* @return Formatted Me Message.
129130
*/
130-
public static String parseMe(String pName, String world, String msg) {
131-
return parseMessage(pName, world, msg, LocaleType.FORMAT_ME.getRaw());
131+
public static String parseMe(UUID uuid, String world, String msg) {
132+
return parseMessage(uuid, world, msg, LocaleType.FORMAT_ME.getRaw());
132133
}
133134

134135
private static String fixCaps(String format, Integer range) {
@@ -151,14 +152,14 @@ private static String fixCaps(String format, Integer range) {
151152
return format;
152153
}
153154

154-
private static String parseVars(String format, String pName, String world) {
155+
private static String parseVars(String format, UUID uuid, String world) {
155156
String vI = "\\" + IndicatorType.MISC_VAR.getValue();
156157
Pattern pattern = Pattern.compile(vI + "<(.*?)>");
157158
Matcher matcher = pattern.matcher(format);
158159
StringBuffer sb = new StringBuffer();
159160

160161
while (matcher.find()) {
161-
String var = Reader.getRawInfo(pName, InfoType.USER, world, matcher.group(1)).toString();
162+
String var = Reader.getRawInfo(uuid, InfoType.USER, world, matcher.group(1));
162163
matcher.appendReplacement(sb, Matcher.quoteReplacement(var));
163164
}
164165

0 commit comments

Comments
 (0)