Skip to content

Commit 9b9d8c5

Browse files
committed
Split UltraStaffChatCommand into multiple parts for Codefactor.
1 parent 05fb0b6 commit 9b9d8c5

1 file changed

Lines changed: 75 additions & 64 deletions

File tree

src/main/java/dev/hypera/ultrastaffchat/commands/impl/UltraStaffChatCommand.java

Lines changed: 75 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -58,74 +58,12 @@ public void execute(CommandSender sender, String[] args) {
5858
}
5959

6060
if(args[0].matches("(?i:(r(eload)?))")) {
61-
if(!sender.hasPermission(UltraStaffChat.getConfig().getString("permission-reload"))) {
62-
audience.sendMessage(Common.adventurise(UltraStaffChat.getConfig().getString("no-permission")));
63-
return;
64-
}
65-
66-
audience.sendMessage(Component.text().append(Component.text().content("[").color(NamedTextColor.GRAY), Component.text().content("UltraStaffChat").color(NamedTextColor.RED).decorate(TextDecoration.BOLD), Component.text().content("] ").color(NamedTextColor.GRAY), Component.text().content("Reloading configuration files...").color(NamedTextColor.GREEN)));
67-
68-
UltraStaffChat.getConfig().reload();
69-
Discord.reload();
70-
71-
audience.sendMessage(Component.text().append(Component.text().content("[").color(NamedTextColor.GRAY), Component.text().content("UltraStaffChat").color(NamedTextColor.RED).decorate(TextDecoration.BOLD), Component.text().content("] ").color(NamedTextColor.GRAY), Component.text().content("Successfully reloaded configuration files").color(NamedTextColor.GREEN)));
61+
reload(sender, audience);
7262
return;
7363
}
7464

7565
if(args[0].matches("(?i:(debug))")) {
76-
if(!sender.hasPermission(UltraStaffChat.getConfig().getString("permission-debug"))) {
77-
audience.sendMessage(Common.adventurise(UltraStaffChat.getConfig().getString("no-permission")));
78-
return;
79-
}
80-
81-
String log;
82-
String filename = "USC-" + TimeUtils.formatFileDateTime(Date.from(Instant.now())) + "-Debug.txt";
83-
84-
boolean advanced = false;
85-
if(args.length > 1) {
86-
for(String arg : args) {
87-
if(arg.matches("(?i:(--a(dv(anced)?)?))")) {
88-
advanced = true;
89-
break;
90-
}
91-
}
92-
}
93-
94-
if(advanced) {
95-
audience.sendMessage(Component.text().append(Component.text().content("[").color(NamedTextColor.GRAY), Component.text().content("UltraStaffChat").color(NamedTextColor.RED).decorate(TextDecoration.BOLD), Component.text().content("] ").color(NamedTextColor.GRAY), Component.text().content("Generating advanced debug log...").color(NamedTextColor.WHITE)));
96-
log = generateAdvancedDebugLog();
97-
} else {
98-
audience.sendMessage(Component.text().append(Component.text().content("[").color(NamedTextColor.GRAY), Component.text().content("UltraStaffChat").color(NamedTextColor.RED).decorate(TextDecoration.BOLD), Component.text().content("] ").color(NamedTextColor.GRAY), Component.text().content("Generating debug log...").color(NamedTextColor.WHITE)));
99-
log = generateDebugLog();
100-
}
101-
102-
try {
103-
File logFolder = new File(UltraStaffChat.getInstance().getDataFolder() + "/logs");
104-
if(!logFolder.exists())
105-
logFolder.mkdirs();
106-
107-
File logFile = new File(logFolder + "/" + filename);
108-
if(logFile.createNewFile()) {
109-
FileWriter logWriter = new FileWriter(logFile);
110-
logWriter.write(log);
111-
logWriter.close();
112-
} else {
113-
throw new Exception();
114-
}
115-
116-
String pasteURL = PasteUtils.createPaste(log);
117-
if(pasteURL == null)
118-
throw new Exception();
119-
if(advanced) {
120-
audience.sendMessage(Component.text().append(Component.text().content("[").color(NamedTextColor.GRAY), Component.text().content("UltraStaffChat").color(NamedTextColor.RED).decorate(TextDecoration.BOLD), Component.text().content("] ").color(NamedTextColor.GRAY), Component.text().content("Successfully generated debug log ").color(NamedTextColor.GREEN), Component.text().content("[View]").color(NamedTextColor.GRAY).clickEvent(ClickEvent.openUrl(pasteURL)).hoverEvent(HoverEvent.showText(Component.text().content(pasteURL)))));
121-
} else {
122-
audience.sendMessage(Component.text().append(LegacyComponentSerializer.legacy('&').deserialize(log).clickEvent(ClickEvent.openUrl(pasteURL))));
123-
}
124-
} catch (Exception e) {
125-
Common.logPrefix("Failed to generate debug log!");
126-
audience.sendMessage(Component.text().append(Component.text().content("[").color(NamedTextColor.GRAY), Component.text().content("UltraStaffChat").color(NamedTextColor.RED).decorate(TextDecoration.BOLD), Component.text().content("] ").color(NamedTextColor.GRAY), Component.text().content("Failed to generate debug log").color(NamedTextColor.RED)));
127-
return;
128-
}
66+
debug(sender, args, audience);
12967
}
13068
}
13169

@@ -137,4 +75,77 @@ public boolean isDisabled() {
13775
return false;
13876
}
13977

78+
private void reload(CommandSender sender, Audience audience) {
79+
if(!sender.hasPermission(UltraStaffChat.getConfig().getString("permission-reload"))) {
80+
audience.sendMessage(Common.adventurise(UltraStaffChat.getConfig().getString("no-permission")));
81+
return;
82+
}
83+
84+
audience.sendMessage(Component.text().append(Component.text().content("[").color(NamedTextColor.GRAY), Component.text().content("UltraStaffChat").color(NamedTextColor.RED).decorate(TextDecoration.BOLD), Component.text().content("] ").color(NamedTextColor.GRAY), Component.text().content("Reloading configuration files...").color(NamedTextColor.GREEN)));
85+
86+
UltraStaffChat.getConfig().reload();
87+
Discord.reload();
88+
89+
audience.sendMessage(Component.text().append(Component.text().content("[").color(NamedTextColor.GRAY), Component.text().content("UltraStaffChat").color(NamedTextColor.RED).decorate(TextDecoration.BOLD), Component.text().content("] ").color(NamedTextColor.GRAY), Component.text().content("Successfully reloaded configuration files").color(NamedTextColor.GREEN)));
90+
}
91+
92+
private void debug(CommandSender sender, String[] args, Audience audience) {
93+
if(!sender.hasPermission(UltraStaffChat.getConfig().getString("permission-debug"))) {
94+
audience.sendMessage(Common.adventurise(UltraStaffChat.getConfig().getString("no-permission")));
95+
return;
96+
}
97+
98+
String log;
99+
100+
boolean advanced = false;
101+
if(args.length > 1) {
102+
for(String arg : args) {
103+
if(arg.matches("(?i:(--a(dv(anced)?)?))")) {
104+
advanced = true;
105+
break;
106+
}
107+
}
108+
}
109+
110+
if(advanced) {
111+
audience.sendMessage(Component.text().append(Component.text().content("[").color(NamedTextColor.GRAY), Component.text().content("UltraStaffChat").color(NamedTextColor.RED).decorate(TextDecoration.BOLD), Component.text().content("] ").color(NamedTextColor.GRAY), Component.text().content("Generating advanced debug log...").color(NamedTextColor.WHITE)));
112+
log = generateAdvancedDebugLog();
113+
} else {
114+
audience.sendMessage(Component.text().append(Component.text().content("[").color(NamedTextColor.GRAY), Component.text().content("UltraStaffChat").color(NamedTextColor.RED).decorate(TextDecoration.BOLD), Component.text().content("] ").color(NamedTextColor.GRAY), Component.text().content("Generating debug log...").color(NamedTextColor.WHITE)));
115+
log = generateDebugLog();
116+
}
117+
118+
logDebug(audience, log, advanced);
119+
}
120+
121+
private void logDebug(Audience audience, String log, boolean advanced) {
122+
try {
123+
String filename = "USC-" + TimeUtils.formatFileDateTime(Date.from(Instant.now())) + "-Debug.txt";
124+
File logFolder = new File(UltraStaffChat.getInstance().getDataFolder() + "/logs");
125+
if(!logFolder.exists())
126+
logFolder.mkdirs();
127+
128+
File logFile = new File(logFolder + "/" + filename);
129+
if(logFile.createNewFile()) {
130+
FileWriter logWriter = new FileWriter(logFile);
131+
logWriter.write(log);
132+
logWriter.close();
133+
} else {
134+
throw new Exception();
135+
}
136+
137+
String pasteURL = PasteUtils.createPaste(log);
138+
if(pasteURL == null)
139+
throw new Exception();
140+
if(advanced) {
141+
audience.sendMessage(Component.text().append(Component.text().content("[").color(NamedTextColor.GRAY), Component.text().content("UltraStaffChat").color(NamedTextColor.RED).decorate(TextDecoration.BOLD), Component.text().content("] ").color(NamedTextColor.GRAY), Component.text().content("Successfully generated debug log ").color(NamedTextColor.GREEN), Component.text().content("[View]").color(NamedTextColor.GRAY).clickEvent(ClickEvent.openUrl(pasteURL)).hoverEvent(HoverEvent.showText(Component.text().content(pasteURL)))));
142+
} else {
143+
audience.sendMessage(Component.text().append(LegacyComponentSerializer.legacy('&').deserialize(log).clickEvent(ClickEvent.openUrl(pasteURL))));
144+
}
145+
} catch (Exception e) {
146+
Common.logPrefix("Failed to generate debug log!");
147+
audience.sendMessage(Component.text().append(Component.text().content("[").color(NamedTextColor.GRAY), Component.text().content("UltraStaffChat").color(NamedTextColor.RED).decorate(TextDecoration.BOLD), Component.text().content("] ").color(NamedTextColor.GRAY), Component.text().content("Failed to generate debug log").color(NamedTextColor.RED)));
148+
}
149+
}
150+
140151
}

0 commit comments

Comments
 (0)