Skip to content

Commit a42ca62

Browse files
committed
[Bug Fix/Feature] Fix small bug when compiling unofficially. Fix MessageUtil not logging colours correctly. Fix ConfigYml reloading not working. Fix Metrics using while loop instead of for loop./Enable Metrics.
1 parent 2e273e9 commit a42ca62

7 files changed

Lines changed: 75 additions & 53 deletions

File tree

pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@
44
<!-- Project information -->
55
<groupId>ca.q0r</groupId>
66
<artifactId>MChat</artifactId>
7-
<version>1.6.4-R0.7</version>
7+
<version>1.6.4-R0.8</version>
88
<name>MChat</name>
99
<url>http://mdev.in/</url>
1010
<description>Chat Formatting for Bukkit</description>
1111

1212
<properties>
1313
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
14-
<build.number>Unknown</build.number>
14+
<build.number>b0jnks</build.number>
1515
</properties>
1616

1717
<!-- Source code -->

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import ca.q0r.mchat.events.ChatListener;
99
import ca.q0r.mchat.events.CommandListener;
1010
import ca.q0r.mchat.events.PlayerListener;
11+
import ca.q0r.mchat.metrics.Metrics;
1112
import ca.q0r.mchat.types.InfoType;
1213
import ca.q0r.mchat.updater.Updater;
1314
import ca.q0r.mchat.util.MessageUtil;
@@ -44,16 +45,16 @@ public void onEnable() {
4445
killEss();
4546

4647
// Initialize Metrics
47-
/*getServer().getScheduler().runTaskLater(this, new BukkitRunnable(){
48+
getServer().getScheduler().runTaskLater(this, new BukkitRunnable(){
4849
@Override
4950
public void run() {
5051
try {
5152
Metrics metrics = new Metrics(Bukkit.getPluginManager().getPlugin("MChat"));
5253
metrics.findCustomData();
5354
metrics.start();
54-
} catch (IOException ignored) {}
55+
} catch (Exception ignored) {}
5556
}
56-
}, 200);*/
57+
}, 200);
5758

5859
// Load Yml
5960
YmlManager.initialize();

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ public boolean onCommand(CommandSender sender, Command command, String label, St
4646
return true;
4747
}
4848

49+
YmlManager.reloadYml(YmlType.CONFIG_YML);
4950
MessageUtil.sendMessage(sender, "Config Reloaded.");
5051
return true;
5152
} else if (args[1].equalsIgnoreCase("info")

src/main/java/ca/q0r/mchat/metrics/Metrics.java

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -471,11 +471,7 @@ private void postPlugin(final boolean isPing) throws IOException {
471471

472472
boolean firstGraph = true;
473473

474-
final Iterator<Graph> iter = graphs.iterator();
475-
476-
while (iter.hasNext()) {
477-
Graph graph = iter.next();
478-
474+
for (Graph graph : graphs) {
479475
StringBuilder graphJson = new StringBuilder();
480476
graphJson.append('{');
481477

@@ -560,11 +556,7 @@ private void postPlugin(final boolean isPing) throws IOException {
560556
// Is this the first update this hour?
561557
if (response.equals("1") || response.contains("This is your first update this hour")) {
562558
synchronized (graphs) {
563-
final Iterator<Graph> iter = graphs.iterator();
564-
565-
while (iter.hasNext()) {
566-
final Graph graph = iter.next();
567-
559+
for (Graph graph : graphs) {
568560
for (Plotter plotter : graph.getPlotters()) {
569561
plotter.reset();
570562
}
@@ -681,7 +673,7 @@ private static String escapeJSON(String text) {
681673
default:
682674
if (chr < ' ') {
683675
String t = "000" + Integer.toHexString(chr);
684-
builder.append("\\u" + t.substring(t.length() - 4));
676+
builder.append("\\u").append(t.substring(t.length() - 4));
685677
} else {
686678
builder.append(chr);
687679
}

src/main/java/ca/q0r/mchat/util/MessageUtil.java

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package ca.q0r.mchat.util;
22

3+
import org.bukkit.Bukkit;
34
import org.bukkit.command.CommandSender;
45

56
import java.util.logging.Level;
@@ -41,24 +42,15 @@ public static void sendMessage(CommandSender sender, String message) {
4142
* @param message Object being Logged.
4243
*/
4344
public static void log(Object message) {
44-
System.out.println(message);
45-
}
46-
47-
/**
48-
* Logger.
49-
* @param level Level to be logged at.
50-
* @param message Object being Logged.
51-
*/
52-
public static void log(Level level, Object message) {
53-
Logger.getLogger("Minecraft").log(level, message.toString());
45+
Bukkit.getConsoleSender().sendMessage(message.toString());
5446
}
5547

5648
/**
5749
* Logger.
5850
* @param message Object being Logged.
5951
*/
6052
public static void logFormatted(Object message) {
61-
System.out.println(format(message.toString()));
53+
log(format(message.toString()));
6254
}
6355
/**
6456
* Colour Formatting.

src/main/java/ca/q0r/mchat/util/Timer.java

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
package ca.q0r.mchat.util;
22

3-
import java.util.Date;
4-
53
/**
64
* Class used when a Timer is needed.
75
*/
@@ -13,7 +11,7 @@ public class Timer {
1311
* Class Initializer, also starts timer.
1412
*/
1513
public Timer() {
16-
start = new Date().getTime();
14+
start = System.nanoTime();
1715
}
1816

1917
/**
@@ -28,21 +26,53 @@ public void reset() {
2826
* Starts timer.
2927
*/
3028
public void start() {
31-
start = new Date().getTime();
29+
start = System.nanoTime();
3230
}
3331

3432
/**
3533
* Stops timer.
3634
*/
3735
public void stop() {
38-
end = new Date().getTime();
36+
end = System.nanoTime();
3937
}
4038

4139
/**
4240
* Calculates Difference.
43-
* @return Difference between start and end values.
41+
* @return Difference between start and end values in milliseconds.
4442
*/
4543
public long difference() {
44+
return differenceInMillis();
45+
}
46+
47+
/**
48+
* Calculates Difference.
49+
* @return Difference between start and end values in seconds.
50+
*/
51+
public long differenceInSeconds() {
52+
return differenceInMillis() / 1000;
53+
}
54+
55+
/**
56+
* Calculates Difference.
57+
* @return Difference between start and end values in milliseconds.
58+
*/
59+
public long differenceInMillis() {
60+
return differenceInMicros() / 1000;
61+
}
62+
63+
/**
64+
* Calculates Difference.
65+
* @return Difference between start and end values in microseconds.
66+
*/
67+
public long differenceInMicros() {
68+
return differenceInNanos() / 1000;
69+
}
70+
71+
/**
72+
* Calculates Difference.
73+
* @return Difference between start and end values in nanoseconds.
74+
*/
75+
public long differenceInNanos() {
4676
return end - start;
4777
}
4878
}

src/main/java/ca/q0r/mchat/yml/YmlManager.java

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,15 @@ public static void initialize() {
3737
* @return YML Config.
3838
*/
3939
public static Yml getYml(YmlType type) {
40-
if (type == YmlType.CENSOR_YML) {
41-
return censorYml;
42-
} else if (type == YmlType.CONFIG_YML) {
43-
return configYml;
44-
} else if (type == YmlType.INFO_YML) {
45-
return infoYml;
46-
} else if (type == YmlType.LOCALE_YML) {
47-
return localeYml;
40+
switch(type) {
41+
case CENSOR_YML:
42+
return censorYml;
43+
case CONFIG_YML:
44+
return configYml;
45+
case INFO_YML:
46+
return infoYml;
47+
case LOCALE_YML:
48+
return localeYml;
4849
}
4950

5051
return null;
@@ -55,18 +56,23 @@ public static Yml getYml(YmlType type) {
5556
* @param type Type of Config to reload.
5657
*/
5758
public static void reloadYml(YmlType type) {
58-
if (type == YmlType.CENSOR_YML) {
59-
censorYml = new CensorYml();
60-
censorYml.loadDefaults();
61-
} else if (type == YmlType.CONFIG_YML) {
62-
configYml = new ConfigYml();
63-
configYml.loadDefaults();
64-
} else if (type == YmlType.INFO_YML) {
65-
infoYml = new InfoYml();
66-
infoYml.loadDefaults();
67-
} else if (type == YmlType.LOCALE_YML) {
68-
localeYml = new LocaleYml();
69-
localeYml.loadDefaults();
59+
switch(type) {
60+
case CENSOR_YML:
61+
censorYml = new CensorYml();
62+
censorYml.loadDefaults();
63+
break;
64+
case CONFIG_YML:
65+
configYml = new ConfigYml();
66+
configYml.loadDefaults();
67+
break;
68+
case INFO_YML:
69+
infoYml = new InfoYml();
70+
infoYml.loadDefaults();
71+
break;
72+
case LOCALE_YML:
73+
localeYml = new LocaleYml();
74+
localeYml.loadDefaults();
75+
break;
7076
}
7177
}
7278

0 commit comments

Comments
 (0)