Skip to content

Commit

Permalink
UpdateManager encoding fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
DevLeoko committed Jul 25, 2020
1 parent ff6a1cf commit d81c222
Showing 1 changed file with 61 additions and 57 deletions.
118 changes: 61 additions & 57 deletions src/main/java/me/leoko/advancedban/manager/UpdateManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,64 @@ public static UpdateManager get() {
public void setup() {
MethodInterface mi = Universal.get().getMethods();

if(mi.isUnitTesting()) return;
if (mi.isUnitTesting()) return;

if (!mi.contains(mi.getMessages(), "UnNote.Usage")) {
try {
addMessage("Check:", " Note: \"&cNotes &8» &7%COUNT%\"", 1);
FileUtils.writeLines(new File(mi.getDataFolder(), "Messages.yml"), "UTF8", Arrays.asList(
"",
"# Automatically added by v2.2.1 update process",
"UnNote:",
" Usage: \"&cUsage &8» &7&o/unwarn [ID] or /unnote clear [Name]\"",
" NotFound: \"&cCould not find note #%ID%\"",
" Done: \"&7Note &a&o#%ID% &7was successfully deleted!\"",
" Notification: \"&e&o%OPERATOR% &7unnoted &c&o%NAME%\"",
" Clear:",
" Empty:\"&c&o%NAME% &7has no notes!\"",
" Done:\"&7Cleared &a&o%COUNT% &7notes\"",
"",
"Note:",
" Usage: \"&cUsage &8» &7&o/note [Name] [Reason]\"",
" Done: \"&c&o%NAME% &7was successfully noted!\"",
" Exempt: \"&7You are not able to note &c&o%NAME%\"",
" Notification:",
" - \"&c&o%NAME% &7got noted by &e&o%OPERATOR%\"",
" - \"&7For the reason &o%REASON%\"",
"",
"Notes:",
" Usage: \"&cUsage &8» &7&o/notes [Name] <Page> &cor &7&o/notes <Page>\"",
" OutOfIndex: \"&cThere is no page %PAGE%!\"",
" NoEntries: \"&c&o%NAME% has no notes yet\"",
" Header:",
" - \"&7\"",
" - \"%PREFIX% &7Notes for %NAME%:\"",
" - \"&7\"",
" Entry:",
" - \"&7%DATE% &8| &7By &o%OPERATOR% &7(&c#%ID%&7)\"",
" - \"&8> &e%REASON%\"",
" - \"&7\"",
" Footer: \"&7Page &e&o%CURRENT_PAGE% &7of &e&o%TOTAL_PAGES% &8| &7Notes: &e&o%COUNT%\"",
" PageFooter: \"&7Use &e&o/notes %NAME% %NEXT_PAGE% &7to see the next page\"",
"",
"NotesOwn:",
" OutOfIndex: \"&cThere is no page %PAGE%!\"",
" NoEntries: \"&c&oYou have no notes yet\"",
" Header:",
" - \"&7\"",
" - \"%PREFIX% &7Your notes:\"",
" - \"&7\"",
" Entry:",
" - \"&7%DATE% &8| &7By &o%OPERATOR% &7(&c#%ID%&7)\"",
" - \"&8> &e%REASON%\"",
" - \"&7\"",
" Footer: \"&7Page &e&o%CURRENT_PAGE% &7of &e&o%TOTAL_PAGES% &8| &7Notes: &e&o%COUNT%\"",
" PageFooter: \"&7Use &e&o/notes %NEXT_PAGE% &7to see the next page\""
), true);
} catch (IOException e) {
e.printStackTrace();
}
}

if (!mi.contains(mi.getMessages(), "WarnsOwn")) {
addMessage("ChangeReason:", "", 0);
Expand All @@ -60,60 +117,7 @@ public void setup() {
addMessage("UnMute:", " Notification: \"&e&o%OPERATOR% &7unmuted &c&o%NAME%\"", 1);
addMessage("UnWarn:", " Notification: \"&e&o%OPERATOR% &7unwarned &c&o%NAME%\"", 1);
}

if (!mi.contains(mi.getMessages(), "UnNote.Usage")) { try {
FileUtils.writeLines(new File(mi.getDataFolder(), "Messages.yml"), Arrays.asList(
"UnNote:",
" Usage: \"&cUsage &8» &7&o/unwarn [ID] or /unnote clear [Name]\"",
" NotFound: \"&cCould not find note #%ID%\"",
" Done: \"&7Note &a&o#%ID% &7was successfully deleted!\"",
" Notification: \"&e&o%OPERATOR% &7unnoted &c&o%NAME%\"",
" Clear:",
" Empty:\"&c&o%NAME% &7has no notes!\"",
" Done:\"&7Cleared &a&o%COUNT% &7notes\"",
"",
"Note:",
" Usage: \"&cUsage &8» &7&o/note [Name] [Reason]\"",
" Done: \"&c&o%NAME% &7was successfully noted!\"",
" Exempt: \"&7You are not able to note &c&o%NAME%\"",
" Notification:",
" - \"&c&o%NAME% &7got noted by &e&o%OPERATOR%\"",
" - \"&7For the reason &o%REASON%\"",
"",
"Notes:",
" Usage: \"&cUsage &8» &7&o/notes [Name] <Page> &cor &7&o/notes <Page>\"",
" OutOfIndex: \"&cThere is no page %PAGE%!\"",
" NoEntries: \"&c&o%NAME% has no notes yet\"",
" Header:",
" - \"&7\"",
" - \"%PREFIX% &7Notes for %NAME%:\"",
" - \"&7\"",
" Entry:",
" - \"&7%DATE% &8| &7By &o%OPERATOR% &7(&c#%ID%&7)\"",
" - \"&8> &e%REASON%\"",
" - \"&7\"",
" Footer: \"&7Page &e&o%CURRENT_PAGE% &7of &e&o%TOTAL_PAGES% &8| &7Notes: &e&o%COUNT%\"",
" PageFooter: \"&7Use &e&o/notes %NAME% %NEXT_PAGE% &7to see the next page\"",
"",
"NotesOwn:",
" OutOfIndex: \"&cThere is no page %PAGE%!\"",
" NoEntries: \"&c&oYou have no notes yet\"",
" Header:",
" - \"&7\"",
" - \"%PREFIX% &7Your notes:\"",
" - \"&7\"",
" Entry:",
" - \"&7%DATE% &8| &7By &o%OPERATOR% &7(&c#%ID%&7)\"",
" - \"&8> &e%REASON%\"",
" - \"&7\"",
" Footer: \"&7Page &e&o%CURRENT_PAGE% &7of &e&o%TOTAL_PAGES% &8| &7Notes: &e&o%COUNT%\"",
" PageFooter: \"&7Use &e&o/notes %NEXT_PAGE% &7to see the next page\""
), true);
} catch (IOException e) {
e.printStackTrace();
}
}


if (!mi.contains(mi.getMessages(), "Check.MuteReason")) {
try {
File file = new File(mi.getDataFolder(), "Messages.yml");
Expand Down Expand Up @@ -236,10 +240,10 @@ public void setup() {
private void addMessage(String search, String insert, int indexOffset) {
try {
File file = new File(Universal.get().getMethods().getDataFolder(), "Messages.yml");
List<String> lines = FileUtils.readLines(file, Charset.defaultCharset());
List<String> lines = FileUtils.readLines(file, "UTF8");
int index = lines.indexOf(search);
lines.add(index + indexOffset, insert);
FileUtils.writeLines(file, lines);
FileUtils.writeLines(file, "UTF8", lines);
} catch (IOException ex) {
ex.printStackTrace();
}
Expand Down

0 comments on commit d81c222

Please sign in to comment.