Skip to content

Commit 8a24885

Browse files
committed
[Cleanup/Bug Fix/Update] Cleanup some code to make it more readable./Possible fix for NPE onJoin./Update Vault dependency.
1 parent c42da76 commit 8a24885

16 files changed

Lines changed: 292 additions & 96 deletions

pom.xml

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,16 @@
6464
<updatePolicy>always</updatePolicy>
6565
</snapshots>
6666
</repository>
67+
<repository>
68+
<id>vault-repo</id>
69+
<url>http://ci.herocraftonline.com/plugin/repository/everything</url>
70+
<releases>
71+
<updatePolicy>always</updatePolicy>
72+
</releases>
73+
<snapshots>
74+
<updatePolicy>always</updatePolicy>
75+
</snapshots>
76+
</repository>
6777
</repositories>
6878

6979
<build>
@@ -152,9 +162,9 @@
152162
<scope>compile</scope>
153163
</dependency>
154164
<dependency>
155-
<groupId>net.milkbowl</groupId>
156-
<artifactId>vault</artifactId>
157-
<version>1.2.20</version>
165+
<groupId>net.milkbowl.vault</groupId>
166+
<artifactId>Vault</artifactId>
167+
<version>1.2.27</version>
158168
<type>jar</type>
159169
<scope>compile</scope>
160170
</dependency>

src/main/java/ca/q0r/mchat/commands/MChatCommand.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public boolean onCommand(CommandSender sender, Command command, String label, St
3434
MessageUtil.sendMessage(sender, "&6Full Version: &1" + plugin.pdfFile.getVersion());
3535
MessageUtil.sendMessage(sender, "&6MineCraft Version: &2" + vArray[0]);
3636
MessageUtil.sendMessage(sender, "&6Release Version: &2" + vArray[1]);
37-
MessageUtil.sendMessage(sender, "&6Jenkins Build &5#&2: " + (vArray.length < 4 ? vArray[2] : vArray[3]));
37+
MessageUtil.sendMessage(sender, "&6Jenkins Build &5#&6:&2 " + (vArray.length < 4 ? vArray[2] : vArray[3]));
3838
MessageUtil.sendMessage(sender, "&6Release: &2" + (vArray.length < 4));
3939

4040
return true;

src/main/java/ca/q0r/mchat/events/ChatListener.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@ private void setListName(Player player, String listName) {
7373
}
7474

7575
player.setPlayerListName(listName);
76-
} catch (Exception ignored) {
77-
}
76+
} catch (Exception ignored) { }
7877
}
7978
}

src/main/java/ca/q0r/mchat/events/PlayerListener.java

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import ca.q0r.mchat.yml.YmlManager;
1111
import ca.q0r.mchat.yml.YmlType;
1212
import ca.q0r.mchat.yml.config.ConfigType;
13+
import org.bukkit.Bukkit;
1314
import org.bukkit.entity.Player;
1415
import org.bukkit.event.EventHandler;
1516
import org.bukkit.event.EventPriority;
@@ -28,18 +29,22 @@ public PlayerListener(MChat instance) {
2829

2930
@EventHandler(priority = EventPriority.LOWEST)
3031
public void onPlayerJoin(PlayerJoinEvent event) {
31-
final Player player = event.getPlayer();
32-
final String world = player.getWorld().getName();
32+
Player player = event.getPlayer();
33+
String world = player.getWorld().getName();
34+
String msg = event.getJoinMessage();
3335

3436
final String pName = player.getName();
35-
String msg = event.getJoinMessage();
3637

3738
if (plugin.update && API.checkPermissions(pName, world, "mchat.update")) {
3839
plugin.getServer().getScheduler().runTaskLater(plugin, new BukkitRunnable() {
3940
@Override
4041
public void run() {
41-
MessageUtil.sendMessage(player, "An update is available! Please check");
42-
MessageUtil.sendMessage(player, "http://goo.gl/dCwFac for details!");
42+
Player player = Bukkit.getPlayer(pName);
43+
44+
if (player != null) {
45+
MessageUtil.sendMessage(player, "An update is available! Please check");
46+
MessageUtil.sendMessage(player, "http://goo.gl/dCwFac for details!");
47+
}
4348
}
4449

4550
}, 50);
@@ -57,7 +62,7 @@ public void run() {
5762

5863
plugin.getServer().getScheduler().runTaskLater(plugin, new BukkitRunnable() {
5964
public void run() {
60-
setListName(player, Parser.parseTabbedList(pName, world));
65+
setListName(pName);
6166
}
6267
}, 20L);
6368

@@ -140,15 +145,20 @@ private void suppressEventMessage(String format, String permNode, String overrid
140145
MessageUtil.log(format);
141146
}
142147

143-
private void setListName(Player player, String listName) {
144-
try {
145-
if (listName.length() > 15) {
146-
listName = listName.substring(0, 16);
147-
player.setPlayerListName(listName);
148-
}
148+
private void setListName(String pName) {
149+
Player player = Bukkit.getPlayer(pName);
149150

150-
player.setPlayerListName(listName);
151-
} catch (Exception ignored) {
151+
if (player != null) {
152+
String listName = Parser.parseTabbedList(player.getName(), player.getWorld().getName());
153+
154+
try {
155+
if (listName.length() > 15) {
156+
listName = listName.substring(0, 16);
157+
player.setPlayerListName(listName);
158+
}
159+
160+
player.setPlayerListName(listName);
161+
} catch (Exception ignored) { }
152162
}
153163
}
154164
}

src/main/java/ca/q0r/mchat/types/EventType.java

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,20 @@
44
* Enum for Different Event Types.
55
*/
66
public enum EventType {
7-
/** Player Join Event. */ JOIN,
8-
/** Player Quit Event. */ QUIT,
9-
/** Player Leave Event. */ LEAVE,
10-
/** Player Kick Event. */ KICK
7+
/**
8+
* Player Join Event.
9+
*/
10+
JOIN,
11+
/**
12+
* Player Quit Event.
13+
*/
14+
QUIT,
15+
/**
16+
* Player Leave Event.
17+
*/
18+
LEAVE,
19+
/**
20+
* Player Kick Event.
21+
*/
22+
KICK
1123
}

src/main/java/ca/q0r/mchat/types/IndicatorType.java

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,18 @@
66
* Enum for Different Indicator Types.
77
*/
88
public enum IndicatorType {
9-
/** Miscellaneous Variable Type. */ MISC_VAR(ConfigType.MCHAT_VAR_INDICATOR),
10-
/** Custom Variable Type. */ CUS_VAR(ConfigType.MCHAT_CUS_VAR_INDICATOR),
11-
/** Locale Variable Type. */ LOCALE_VAR(ConfigType.MCHAT_LOCALE_VAR_INDICATOR);
9+
/**
10+
* Miscellaneous Variable Type.
11+
*/
12+
MISC_VAR(ConfigType.MCHAT_VAR_INDICATOR),
13+
/**
14+
* Custom Variable Type.
15+
*/
16+
CUS_VAR(ConfigType.MCHAT_CUS_VAR_INDICATOR),
17+
/**
18+
* Locale Variable Type.
19+
*/
20+
LOCALE_VAR(ConfigType.MCHAT_LOCALE_VAR_INDICATOR);
1221

1322
private ConfigType type;
1423

src/main/java/ca/q0r/mchat/types/InfoEditType.java

Lines changed: 36 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,42 @@
77
* Enum for Different <b>info.yml</b> Edit Types.
88
*/
99
public enum InfoEditType {
10-
/** Add Info Variable Command. */ ADD_INFO_VAR(5, "/%cmd add ivar <%Type> <Variable> [Value]"),
11-
/** Add Base Command. */ ADD_BASE(3, "/%cmd add %type <%Type>"),
12-
/** Add World Command. */ ADD_WORLD(4, "/%cmd add world <%Type> <World>"),
13-
/** Add World Variable Command. */ ADD_WORLD_VAR(6, "/%cmd add wvar <%Type> <World> <Variable> [Value]"),
14-
/** Remove Info Variable Command. */ REMOVE_INFO_VAR(4, "/%cmd remove ivar <%Type> <Variable>"),
15-
/** Remove Base Command. */ REMOVE_BASE(3, "/%cmd remove %type <%Type>"),
16-
/** Remove World Command. */ REMOVE_WORLD(4, "/%cmd remove world <%Type> <World>"),
17-
/** Remove World Variable Command. */ REMOVE_WORLD_VAR(5, "/%cmd remove wvar <%Type> <World> <Variable>"),
18-
/** Set Group Command. */ SET_GROUP(4, "/%cmd set group <Player> <Group>");
10+
/**
11+
* Add Info Variable Command.
12+
*/
13+
ADD_INFO_VAR(5, "/%cmd add ivar <%Type> <Variable> [Value]"),
14+
/**
15+
* Add Base Command.
16+
*/
17+
ADD_BASE(3, "/%cmd add %type <%Type>"),
18+
/**
19+
* Add World Command.
20+
*/
21+
ADD_WORLD(4, "/%cmd add world <%Type> <World>"),
22+
/**
23+
* Add World Variable Command.
24+
*/
25+
ADD_WORLD_VAR(6, "/%cmd add wvar <%Type> <World> <Variable> [Value]"),
26+
/**
27+
* Remove Info Variable Command.
28+
*/
29+
REMOVE_INFO_VAR(4, "/%cmd remove ivar <%Type> <Variable>"),
30+
/**
31+
* Remove Base Command.
32+
*/
33+
REMOVE_BASE(3, "/%cmd remove %type <%Type>"),
34+
/**
35+
* Remove World Command.
36+
*/
37+
REMOVE_WORLD(4, "/%cmd remove world <%Type> <World>"),
38+
/**
39+
* Remove World Variable Command.
40+
*/
41+
REMOVE_WORLD_VAR(5, "/%cmd remove wvar <%Type> <World> <Variable>"),
42+
/**
43+
* Set Group Command.
44+
*/
45+
SET_GROUP(4, "/%cmd set group <Player> <Group>");
1946

2047
private Integer length;
2148
private String msg;

src/main/java/ca/q0r/mchat/types/InfoType.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,14 @@
44
* Enum for Different Info Types.
55
*/
66
public enum InfoType {
7-
/** Group Info Type. */ GROUP("groups"),
8-
/** User Info Type. */ USER("users");
7+
/**
8+
* Group Info Type.
9+
*/
10+
GROUP("groups"),
11+
/**
12+
* User Info Type.
13+
*/
14+
USER("users");
915

1016
private final String name;
1117

src/main/java/ca/q0r/mchat/types/PluginType.java

Lines changed: 40 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,44 @@
44
* Enum for Different Plugin Types.
55
*/
66
public enum PluginType {
7-
/** Vault Plugin. */ VAULT,
8-
/** Vault Chat Plugin. */ VAULT_CHAT,
9-
/** GroupManager Plugin. */ GROUP_MANAGER,
10-
/** PermissionsEx Plugin. */ PERMISSIONS_EX,
11-
/** bPermissions Plugin. */ BPERMISSIONS,
12-
/** Privileges Plugin. */ PRIVILEGES,
13-
/** PermissionsBukkit Plugin. */ PERMISSIONS_BUKKIT,
14-
/** Leveled Nodes MChat Plugin. */ LEVELED_NODES,
15-
/** Old Nodes MChat Plugin. */ OLD_NODES,
16-
/** New Info MChat Plugin. */ NEW_INFO
7+
/**
8+
* Vault Plugin.
9+
*/
10+
VAULT,
11+
/**
12+
* Vault Chat Plugin.
13+
*/
14+
VAULT_CHAT,
15+
/**
16+
* GroupManager Plugin.
17+
*/
18+
GROUP_MANAGER,
19+
/**
20+
* PermissionsEx Plugin.
21+
*/
22+
PERMISSIONS_EX,
23+
/**
24+
* bPermissions Plugin.
25+
*/
26+
BPERMISSIONS,
27+
/**
28+
* Privileges Plugin.
29+
*/
30+
PRIVILEGES,
31+
/**
32+
* PermissionsBukkit Plugin.
33+
*/
34+
PERMISSIONS_BUKKIT,
35+
/**
36+
* Leveled Nodes MChat Plugin.
37+
*/
38+
LEVELED_NODES,
39+
/**
40+
* Old Nodes MChat Plugin.
41+
*/
42+
OLD_NODES,
43+
/**
44+
* New Info MChat Plugin.
45+
*/
46+
NEW_INFO
1747
}

src/main/java/ca/q0r/mchat/updater/Updater.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public class Updater {
6161
private static final String QUERY = "/servermods/files?projectIds="; // Path to GET
6262
private static final String HOST = "https://api.curseforge.com"; // Slugs will be appended to this to get to the project's RSS feed
6363

64-
private static final String[] NO_UPDATE_TAG = { "-DEV", "-PRE", "-SNAPSHOT" }; // If the version number contains one of these, don't update.
64+
private static final String[] NO_UPDATE_TAG = {"-DEV", "-PRE", "-SNAPSHOT"}; // If the version number contains one of these, don't update.
6565
private static final int BYTE_SIZE = 1024; // Used for downloading files
6666
private YamlConfiguration config; // Config file
6767
private String updateFolder;// The folder that downloads will be placed in

0 commit comments

Comments
 (0)