Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code Cleanup #437

Merged
merged 14 commits into from
Jul 26, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Arrays;

public class ChatAlertsManager {
static String DATA_PATH_NAME = "./config/partly-sane-skies/chatAlertsData.json";
Expand Down Expand Up @@ -58,76 +57,76 @@ public static void load() throws IOException {

public static void registerCommand() {
new PSSCommand("chatalerts")
.addAlias("ca")
.addAlias("chatAlert")
.addAlias("chal")
.setDescription("Operates the chat alerts feature: /chatalerts <add/remove/list> ")
.setRunnable(args -> {
// If the user doesn't provide any arguments whatsoever print message
if (args.length == 0) {
ChatUtils.INSTANCE.sendClientMessage("§cIncorrect usage. Correct usage: /chatalerts add/remove/list");
return;
}

// Looks at the first argument given
switch (args[0]) {
// If the user does /chatalerts list
case "list":
ChatAlertsManager.listAlerts();
.addAlias("ca")
.addAlias("chatAlert")
.addAlias("chal")
.setDescription("Operates the chat alerts feature: /chatalerts <add/remove/list> ")
.setRunnable(args -> {
// If the user doesn't provide any arguments whatsoever print message
if (args.length == 0) {
ChatUtils.INSTANCE.sendClientMessage("§cIncorrect usage. Correct usage: /chatalerts add/remove/list");
return;
}

// Looks at the first argument given
switch (args[0]) {
// If the user does /chatalerts list
case "list":
ChatAlertsManager.listAlerts();
break;

// If the user does /chatalerts add
case "add":
// Prints error message if no message alert is given
if (args.length == 1) {
ChatUtils.INSTANCE.sendClientMessage("§cIncorrect usage. Correct usage: /chatalerts add [alert]");
break;
}

// If the user does /chatalerts add
case "add":
// Prints error message if no message alert is given
if (args.length == 1) {
ChatUtils.INSTANCE.sendClientMessage("§cIncorrect usage. Correct usage: /chatalerts add [alert]");
break;
}
// Adds each argument as a space
StringBuilder alert = new StringBuilder();
for (int i = 1; i < args.length; i++) {
alert.append(args[i]);
alert.append(" ");
}

// Adds each argument as a space
StringBuilder alert = new StringBuilder();
for (int i = 1; i < args.length; i++) {
alert.append(args[i]);
alert.append(" ");
}
// Removes any leading or trailing spaces
alert = new StringBuilder(StringUtils.INSTANCE.stripLeading(alert.toString()));
alert = new StringBuilder(StringUtils.INSTANCE.stripTrailing(alert.toString()));

// Removes any leading or trailing spaces
alert = new StringBuilder(StringUtils.INSTANCE.stripLeading(alert.toString()));
alert = new StringBuilder(StringUtils.INSTANCE.stripTrailing(alert.toString()));
ChatAlertsManager.addAlert(alert.toString());

ChatAlertsManager.addAlert(alert.toString());
break;

// If the user does /chatalerts remove
case "remove":
// If no number is given
if (args.length == 1) {
ChatUtils.INSTANCE.sendClientMessage("§cIncorrect usage. Correct usage: /chatalerts remove [number]");
break;

// If the user does /chatalerts remove
case "remove":
// If no number is given
if (args.length == 1) {
ChatUtils.INSTANCE.sendClientMessage("§cIncorrect usage. Correct usage: /chatalerts remove [number]");
break;
}

// Tries to parse the number given as a number
int id;
try {
id = Integer.parseInt(args[1]);
} catch (
NumberFormatException e) { // If the number cannot be parsed, prints an error message
ChatUtils.INSTANCE.sendClientMessage("§c\"" + args[1] + "\" could not be read as a number. Correct Usage: /chatalerts remove [number]");
break;
}

// Removes the chat alert
ChatAlertsManager.removeAlert(id);
}

// Tries to parse the number given as a number
int id;
try {
id = Integer.parseInt(args[1]);
} catch (
NumberFormatException e) { // If the number cannot be parsed, prints an error message
ChatUtils.INSTANCE.sendClientMessage("§c\"" + args[1] + "\" could not be read as a number. Correct Usage: /chatalerts remove [number]");
break;
}

// If none of the above are given
default:
ChatUtils.INSTANCE.sendClientMessage("§cIncorrect usage. Correct usage: /chatalerts add/remove/list");
break;
}
})
.register();
// Removes the chat alert
ChatAlertsManager.removeAlert(id);
break;

// If none of the above are given
default:
ChatUtils.INSTANCE.sendClientMessage("§cIncorrect usage. Correct usage: /chatalerts add/remove/list");
break;
}
})
.register();
}

// Saves all the chat alerts data
Expand Down Expand Up @@ -174,7 +173,7 @@ public static int getChatAlertCount() {
public static void listAlerts() {
// Creates header message
StringBuilder message = new StringBuilder("§d§m-----------------------------------------------------\n§bChat Alerts:" +
"\n§d§m-----------------------------------------------------\n");
"\n§d§m-----------------------------------------------------\n");

// Creates the index number on the left of the message
int i = 1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,41 +9,41 @@
public class OwO {
public static String owoify(String text) {
return text
.replace("r", "w")
.replace("l", "w")
.replace("R", "W")
.replace("L", "W")
.replace("no", "nyo")
.replace("No", "Nyo")
.replace("NO", "NYO")
.replace("na", "nya")
.replace("Na", "Nya")
.replace("NA", "NYA")
.replace("ne", "nye")
.replace("Ne", "Nye")
.replace("NE", "NYE")
.replace("ni", "nyi")
.replace("Ni", "Nyi")
.replace("NI", "NYI")
.replace("nu", "nyu")
.replace("Nu", "Nyu")
.replace("NU", "NYU")
.replace("ne", "nye")
.replace("Ne", "Nye")
.replace("NE", "NYE")
.replace("no", "nyo")
.replace("No", "Nyo")
.replace("NO", "NYO")
.replace("n", "ny")
.replace("N", "Ny")
.replace("ove", "uv")
.replace("Ove", "Uv")
.replace("OVE", "UV")
.replace("o", "owo")
.replace("O", "OwO")
.replace("!", " >w<")
.replace("?", " owo?")
.replace(".", " owo.")
.replace(",", " owo,");
.replace("r", "w")
.replace("l", "w")
.replace("R", "W")
.replace("L", "W")
.replace("no", "nyo")
.replace("No", "Nyo")
.replace("NO", "NYO")
.replace("na", "nya")
.replace("Na", "Nya")
.replace("NA", "NYA")
.replace("ne", "nye")
.replace("Ne", "Nye")
.replace("NE", "NYE")
.replace("ni", "nyi")
.replace("Ni", "Nyi")
.replace("NI", "NYI")
.replace("nu", "nyu")
.replace("Nu", "Nyu")
.replace("NU", "NYU")
.replace("ne", "nye")
.replace("Ne", "Nye")
.replace("NE", "NYE")
.replace("no", "nyo")
.replace("No", "Nyo")
.replace("NO", "NYO")
.replace("n", "ny")
.replace("N", "Ny")
.replace("ove", "uv")
.replace("Ove", "Uv")
.replace("OVE", "UV")
.replace("o", "owo")
.replace("O", "OwO")
.replace("!", " >w<")
.replace("?", " owo?")
.replace(".", " owo.")
.replace(",", " owo,");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -104,70 +104,70 @@ public static void listWords() {

public static void registerWordEditorCommand() {
new PSSCommand("wordeditor")
.addAlias("wordedit")
.addAlias("we")
.addAlias("wordreplace")
.addAlias("wr")
.setDescription("Operates the word editor: /wordeditor add <word> <replacement>, /wordeditor list or /wordeditor remove <index>")
.setRunnable(args -> {
if (args.length == 0 || args[0].equalsIgnoreCase("list")) {
.addAlias("wordedit")
.addAlias("we")
.addAlias("wordreplace")
.addAlias("wr")
.setDescription("Operates the word editor: /wordeditor add <word> <replacement>, /wordeditor list or /wordeditor remove <index>")
.setRunnable(args -> {
if (args.length == 0 || args[0].equalsIgnoreCase("list")) {

ChatUtils.INSTANCE.sendClientMessage("§7To add a word to replace, run §b/wordeditor add <word> <replacement>§7. To remove a word, run §b/wordeditor remove <index>§7. To list all of the words, run §b/wordeditor list§7.");

WordEditor.listWords();
return;
}

if (args[0].equalsIgnoreCase("remove")) {
if (args.length == 1) {
ChatUtils.INSTANCE.sendClientMessage("§cError: Must provide an index to remove");
return;
}

ChatUtils.INSTANCE.sendClientMessage("§7To add a word to replace, run §b/wordeditor add <word> <replacement>§7. To remove a word, run §b/wordeditor remove <index>§7. To list all of the words, run §b/wordeditor list§7.");
int i;
try {
i = Integer.parseInt(args[1]);
} catch (NumberFormatException e) {
ChatUtils.INSTANCE.sendClientMessage("§cPlease enter a valid number index and try again.");
return;
}

WordEditor.listWords();
if (i > WordEditor.wordsToEdit.length || i < 1) {
ChatUtils.INSTANCE.sendClientMessage("§cPlease select a valid index and try again.");
return;
}
ChatUtils.INSTANCE.sendClientMessage("§aRemoving: §b" + WordEditor.wordsToEdit[i - 1][0] + " §8-> §b" + WordEditor.wordsToEdit[i - 1][1]);
WordEditor.wordsToEdit = ArrayUtils.removeElement(WordEditor.wordsToEdit, WordEditor.wordsToEdit[i - 1]); // Removes the element from the array
try {
WordEditor.save();
} catch (IOException e) {
e.printStackTrace();
}
}

if (args[0].equalsIgnoreCase("add")) {
if (args.length < 3) {
ChatUtils.INSTANCE.sendClientMessage("§cError: Must provide a word and a replacement");
return;
}

String word = args[1];
String replacement = args[2];

if (args[0].equalsIgnoreCase("remove")) {
if (args.length == 1) {
ChatUtils.INSTANCE.sendClientMessage("§cError: Must provide an index to remove");
return;
}

int i;
try {
i = Integer.parseInt(args[1]);
} catch (NumberFormatException e) {
ChatUtils.INSTANCE.sendClientMessage("§cPlease enter a valid number index and try again.");
return;
}

if (i > WordEditor.wordsToEdit.length || i < 1) {
ChatUtils.INSTANCE.sendClientMessage("§cPlease select a valid index and try again.");
return;
}
ChatUtils.INSTANCE.sendClientMessage("§aRemoving: §b" + WordEditor.wordsToEdit[i - 1][0] + " §8-> §b" + WordEditor.wordsToEdit[i - 1][1]);
WordEditor.wordsToEdit = ArrayUtils.removeElement(WordEditor.wordsToEdit, WordEditor.wordsToEdit[i - 1]); // Removes the element from the array
try {
WordEditor.save();
} catch (IOException e) {
e.printStackTrace();
}
for (int i = 3; i < args.length; i++) {
replacement += " " + args[i];
}

if (args[0].equalsIgnoreCase("add")) {
if (args.length < 3) {
ChatUtils.INSTANCE.sendClientMessage("§cError: Must provide a word and a replacement");
return;
}

String word = args[1];
String replacement = args[2];

for (int i = 3; i < args.length; i++) {
replacement += " " + args[i];
}

ChatUtils.INSTANCE.sendClientMessage("§aAdding: §b" + word + " §8-> §b" + replacement);
WordEditor.wordsToEdit = ArrayUtils.add(WordEditor.wordsToEdit, new String[]{word, replacement});
try {
WordEditor.save();
} catch (IOException e) {
e.printStackTrace();
}
ChatUtils.INSTANCE.sendClientMessage("§aAdding: §b" + word + " §8-> §b" + replacement);
WordEditor.wordsToEdit = ArrayUtils.add(WordEditor.wordsToEdit, new String[]{word, replacement});
try {
WordEditor.save();
} catch (IOException e) {
e.printStackTrace();
}
})
.register();
}
})
.register();
}


Expand All @@ -178,9 +178,9 @@ public static void save() throws IOException {
file.createNewFile();
// Creates a new Gson object to save the data
Gson gson = new GsonBuilder()
.setPrettyPrinting()
.serializeSpecialFloatingPointValues()
.create();
.setPrettyPrinting()
.serializeSpecialFloatingPointValues()
.create();
// Saves teh data to the file
String json = gson.toJson(wordsToEdit);
FileWriter writer = new FileWriter(file);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ public static void startPartyManager() {

public static void registerCommand() {
new PSSCommand("friendparty")
.addAlias("fp")
.addAlias("pf")
.setDescription("Parties all friends in the friend list")
.setRunnable(a -> {
PartyFriendManager.startPartyManager();
})
.register();
.addAlias("fp")
.addAlias("pf")
.setDescription("Parties all friends in the friend list")
.setRunnable(a -> {
PartyFriendManager.startPartyManager();
})
.register();
}

public static void partyAll() {
Expand Down
Loading
Loading