Skip to content

Commit 70af742

Browse files
committed
Code cleanup
1 parent 0463700 commit 70af742

File tree

72 files changed

+3416
-3456
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

72 files changed

+3416
-3456
lines changed

VotingPlugin/src/com/bencodez/votingplugin/BungeeHandler.java

Lines changed: 139 additions & 139 deletions
Original file line numberDiff line numberDiff line change
@@ -78,29 +78,6 @@ public BungeeHandler(VotingPluginMain plugin) {
7878
this.plugin = plugin;
7979
}
8080

81-
public void close() {
82-
if (socketHandler != null) {
83-
socketHandler.closeConnection();
84-
}
85-
if (clientHandler != null) {
86-
clientHandler.stopConnection();
87-
}
88-
plugin.getServerData().setBungeeVotePartyCurrent(bungeeVotePartyCurrent);
89-
plugin.getServerData().setBungeeVotePartyRequired(bungeeVotePartyRequired);
90-
if (globalDataHandler != null) {
91-
globalDataHandler.getGlobalMysql().close();
92-
}
93-
}
94-
95-
/*
96-
* @EventHandler public void onDateChange(DateChangedEvent event) { if
97-
* (method.equals(BungeeMethod.PLUGINMESSAGING)) {
98-
* plugin.getPluginMessaging().sendPluginMessage("timeupdate",
99-
* plugin.getServerDataFile().getPrevMonth() + "//" +
100-
* plugin.getServerDataFile().getPrevDay() + "//" +
101-
* plugin.getServerDataFile().getPrevWeekDay()); } }
102-
*/
103-
10481
public void checkGlobalData() {
10582
HashMap<String, DataValue> data = globalDataHandler.getExact(plugin.getBungeeSettings().getServer());
10683
// plugin.debug(data.toString());
@@ -131,19 +108,21 @@ public void checkGlobalData() {
131108
}
132109

133110
if (forceUpdate) {
134-
HashMap<String, DataValue> dataToSet = new HashMap<String, DataValue>();
111+
HashMap<String, DataValue> dataToSet = new HashMap<>();
135112
dataToSet.put("FinishedProcessing", new DataValueBoolean(true));
136113
dataToSet.put("Processing", new DataValueBoolean(false));
137114
globalDataHandler.setData(plugin.getBungeeSettings().getServer(), dataToSet);
138115
}
139116
}
140117

141-
public boolean checkGlobalDataTimeValue(DataValue data) {
142-
if (data.isBoolean()) {
143-
return data.getBoolean();
144-
}
145-
return Boolean.valueOf(data.getString());
146-
}
118+
/*
119+
* @EventHandler public void onDateChange(DateChangedEvent event) { if
120+
* (method.equals(BungeeMethod.PLUGINMESSAGING)) {
121+
* plugin.getPluginMessaging().sendPluginMessage("timeupdate",
122+
* plugin.getServerDataFile().getPrevMonth() + "//" +
123+
* plugin.getServerDataFile().getPrevDay() + "//" +
124+
* plugin.getServerDataFile().getPrevWeekDay()); } }
125+
*/
147126

148127
public boolean checkGlobalDataTime(TimeType type, HashMap<String, DataValue> data) {
149128
boolean isProcessing = false;
@@ -174,106 +153,24 @@ public boolean checkGlobalDataTime(TimeType type, HashMap<String, DataValue> dat
174153
return isProcessing;
175154
}
176155

177-
public void loadGlobalMysql() {
178-
if (plugin.getBungeeSettings().isGloblalDataEnabled()) {
179-
if (timer != null) {
180-
timer.shutdown();
181-
try {
182-
timer.awaitTermination(5, TimeUnit.SECONDS);
183-
} catch (InterruptedException e) {
184-
e.printStackTrace();
185-
}
186-
timer.shutdownNow();
187-
}
188-
timer = Executors.newScheduledThreadPool(1);
189-
timer.scheduleWithFixedDelay(new Runnable() {
190-
191-
@Override
192-
public void run() {
193-
checkGlobalData();
194-
}
195-
}, 60, 10, TimeUnit.SECONDS);
196-
timer.scheduleWithFixedDelay(new Runnable() {
197-
198-
@Override
199-
public void run() {
200-
globalDataHandler.setString(plugin.getBungeeSettings().getServer(), "LastOnline",
201-
"" + LocalDateTime.now().atZone(ZoneOffset.UTC).toInstant().toEpochMilli());
202-
}
203-
}, 1, 60, TimeUnit.MINUTES);
204-
if (globalDataHandler != null) {
205-
globalDataHandler.getGlobalMysql().close();
206-
}
207-
if (plugin.getBungeeSettings().isGloblalDataUseMainMySQL()
208-
&& plugin.getStorageType().equals(UserStorage.MYSQL)) {
209-
globalDataHandler = new GlobalDataHandler(
210-
new GlobalMySQL("VotingPlugin_GlobalData", plugin.getMysql().getMysql()) {
211-
212-
@Override
213-
public void warning(String text) {
214-
plugin.getLogger().warning(text);
215-
}
216-
217-
@Override
218-
public void severe(String text) {
219-
plugin.getLogger().severe(text);
220-
}
221-
222-
@Override
223-
public void debug(Exception e) {
224-
plugin.debug(e);
225-
}
226-
227-
@Override
228-
public void debug(String text) {
229-
plugin.debug(text);
230-
}
231-
232-
@Override
233-
public void info(String text) {
234-
plugin.getLogger().info(text);
235-
}
236-
});
237-
} else {
238-
globalDataHandler = new GlobalDataHandler(
239-
new GlobalMySQL("VotingPlugin_GlobalData", new MysqlConfigSpigot(
240-
plugin.getBungeeSettings().getData().getConfigurationSection("GlobalData"))) {
241-
242-
@Override
243-
public void warning(String text) {
244-
plugin.getLogger().warning(text);
245-
}
246-
247-
@Override
248-
public void severe(String text) {
249-
plugin.getLogger().severe(text);
250-
}
251-
252-
@Override
253-
public void debug(Exception e) {
254-
plugin.debug(e);
255-
}
256-
257-
@Override
258-
public void debug(String text) {
259-
plugin.debug(text);
260-
}
156+
public boolean checkGlobalDataTimeValue(DataValue data) {
157+
if (data.isBoolean()) {
158+
return data.getBoolean();
159+
}
160+
return Boolean.valueOf(data.getString());
161+
}
261162

262-
@Override
263-
public void info(String text) {
264-
plugin.getLogger().info(text);
265-
}
266-
});
267-
}
268-
globalDataHandler.getGlobalMysql().alterColumnType("IgnoreTime", "VARCHAR(5)");
269-
globalDataHandler.getGlobalMysql().alterColumnType("MONTH", "VARCHAR(5)");
270-
globalDataHandler.getGlobalMysql().alterColumnType("WEEK", "VARCHAR(5)");
271-
globalDataHandler.getGlobalMysql().alterColumnType("DAY", "VARCHAR(5)");
272-
globalDataHandler.getGlobalMysql().alterColumnType("FinishedProcessing", "VARCHAR(5)");
273-
globalDataHandler.getGlobalMysql().alterColumnType("Processing", "VARCHAR(5)");
274-
globalDataHandler.getGlobalMysql().alterColumnType("LastUpdated", "MEDIUMTEXT");
275-
globalDataHandler.getGlobalMysql().alterColumnType("ForceUpdate", "VARCHAR(5)");
276-
plugin.getTimeChecker().setProcessingEnabled(false);
163+
public void close() {
164+
if (socketHandler != null) {
165+
socketHandler.closeConnection();
166+
}
167+
if (clientHandler != null) {
168+
clientHandler.stopConnection();
169+
}
170+
plugin.getServerData().setBungeeVotePartyCurrent(bungeeVotePartyCurrent);
171+
plugin.getServerData().setBungeeVotePartyRequired(bungeeVotePartyRequired);
172+
if (globalDataHandler != null) {
173+
globalDataHandler.getGlobalMysql().close();
277174
}
278175
}
279176

@@ -295,12 +192,12 @@ public void sendMessage(String subChannel, String... messageData) {
295192
} else if (method.equals(BungeeMethod.PLUGINMESSAGING)) {
296193
plugin.getPluginMessaging().sendPluginMessage(subChannel, messageData);
297194
} else if (method.equals(BungeeMethod.SOCKETS)) {
298-
ArrayList<String> list = new ArrayList<String>();
195+
ArrayList<String> list = new ArrayList<>();
299196
list.add(subChannel);
300197
list.addAll(ArrayUtils.convert(messageData));
301198
sendData(ArrayUtils.convert(list));
302199
} else if (method.equals(BungeeMethod.REDIS)) {
303-
ArrayList<String> list = new ArrayList<String>();
200+
ArrayList<String> list = new ArrayList<>();
304201
list.add(subChannel);
305202
list.addAll(ArrayUtils.convert(messageData));
306203
redisHandler.sendMessage(plugin.getBungeeSettings().getRedisPrefix() + "VotingPlugin",
@@ -614,24 +511,24 @@ public void onReceive(ArrayList<String> args) {
614511
plugin.getBungeeSettings().getRedisPort(), plugin.getBungeeSettings().getRedisUsername(),
615512
plugin.getBungeeSettings().getRedisPassword()) {
616513

514+
@Override
515+
public void debug(String message) {
516+
if (plugin.getBungeeSettings().isBungeeDebug()) {
517+
plugin.debug(message);
518+
}
519+
}
520+
617521
@Override
618522
protected void onMessage(String channel, String[] message) {
619523
plugin.getLogger().info(channel + ArrayUtils.makeStringList(ArrayUtils.convert(message)));
620524
if (message.length > 0) {
621-
ArrayList<String> list = new ArrayList<String>();
525+
ArrayList<String> list = new ArrayList<>();
622526
for (int i = 1; i < message.length; i++) {
623527
list.add(message[i]);
624528
}
625529
globalMessageHandler.onMessage(message[0], list);
626530
}
627531
}
628-
629-
@Override
630-
public void debug(String message) {
631-
if (plugin.getBungeeSettings().isBungeeDebug()) {
632-
plugin.debug(message);
633-
}
634-
}
635532
};
636533
redisThread = new Thread(new Runnable() {
637534

@@ -895,6 +792,109 @@ public void onReceive(String[] data) {
895792

896793
}
897794

795+
public void loadGlobalMysql() {
796+
if (plugin.getBungeeSettings().isGloblalDataEnabled()) {
797+
if (timer != null) {
798+
timer.shutdown();
799+
try {
800+
timer.awaitTermination(5, TimeUnit.SECONDS);
801+
} catch (InterruptedException e) {
802+
e.printStackTrace();
803+
}
804+
timer.shutdownNow();
805+
}
806+
timer = Executors.newScheduledThreadPool(1);
807+
timer.scheduleWithFixedDelay(new Runnable() {
808+
809+
@Override
810+
public void run() {
811+
checkGlobalData();
812+
}
813+
}, 60, 10, TimeUnit.SECONDS);
814+
timer.scheduleWithFixedDelay(new Runnable() {
815+
816+
@Override
817+
public void run() {
818+
globalDataHandler.setString(plugin.getBungeeSettings().getServer(), "LastOnline",
819+
"" + LocalDateTime.now().atZone(ZoneOffset.UTC).toInstant().toEpochMilli());
820+
}
821+
}, 1, 60, TimeUnit.MINUTES);
822+
if (globalDataHandler != null) {
823+
globalDataHandler.getGlobalMysql().close();
824+
}
825+
if (plugin.getBungeeSettings().isGloblalDataUseMainMySQL()
826+
&& plugin.getStorageType().equals(UserStorage.MYSQL)) {
827+
globalDataHandler = new GlobalDataHandler(
828+
new GlobalMySQL("VotingPlugin_GlobalData", plugin.getMysql().getMysql()) {
829+
830+
@Override
831+
public void debug(Exception e) {
832+
plugin.debug(e);
833+
}
834+
835+
@Override
836+
public void debug(String text) {
837+
plugin.debug(text);
838+
}
839+
840+
@Override
841+
public void info(String text) {
842+
plugin.getLogger().info(text);
843+
}
844+
845+
@Override
846+
public void severe(String text) {
847+
plugin.getLogger().severe(text);
848+
}
849+
850+
@Override
851+
public void warning(String text) {
852+
plugin.getLogger().warning(text);
853+
}
854+
});
855+
} else {
856+
globalDataHandler = new GlobalDataHandler(
857+
new GlobalMySQL("VotingPlugin_GlobalData", new MysqlConfigSpigot(
858+
plugin.getBungeeSettings().getData().getConfigurationSection("GlobalData"))) {
859+
860+
@Override
861+
public void debug(Exception e) {
862+
plugin.debug(e);
863+
}
864+
865+
@Override
866+
public void debug(String text) {
867+
plugin.debug(text);
868+
}
869+
870+
@Override
871+
public void info(String text) {
872+
plugin.getLogger().info(text);
873+
}
874+
875+
@Override
876+
public void severe(String text) {
877+
plugin.getLogger().severe(text);
878+
}
879+
880+
@Override
881+
public void warning(String text) {
882+
plugin.getLogger().warning(text);
883+
}
884+
});
885+
}
886+
globalDataHandler.getGlobalMysql().alterColumnType("IgnoreTime", "VARCHAR(5)");
887+
globalDataHandler.getGlobalMysql().alterColumnType("MONTH", "VARCHAR(5)");
888+
globalDataHandler.getGlobalMysql().alterColumnType("WEEK", "VARCHAR(5)");
889+
globalDataHandler.getGlobalMysql().alterColumnType("DAY", "VARCHAR(5)");
890+
globalDataHandler.getGlobalMysql().alterColumnType("FinishedProcessing", "VARCHAR(5)");
891+
globalDataHandler.getGlobalMysql().alterColumnType("Processing", "VARCHAR(5)");
892+
globalDataHandler.getGlobalMysql().alterColumnType("LastUpdated", "MEDIUMTEXT");
893+
globalDataHandler.getGlobalMysql().alterColumnType("ForceUpdate", "VARCHAR(5)");
894+
plugin.getTimeChecker().setProcessingEnabled(false);
895+
}
896+
}
897+
898898
public void sendData(String... strings) {
899899
clientHandler.sendMessage(strings);
900900
}

0 commit comments

Comments
 (0)