-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
180 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
src/main/java/com/artillexstudios/axsellwands/utils/CommandMessages.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package com.artillexstudios.axsellwands.utils; | ||
|
||
import com.artillexstudios.axapi.utils.StringUtils; | ||
import revxrsal.commands.locales.LocaleReader; | ||
|
||
import java.util.Locale; | ||
|
||
import static com.artillexstudios.axsellwands.AxSellwands.CONFIG; | ||
import static com.artillexstudios.axsellwands.AxSellwands.LANG; | ||
|
||
public class CommandMessages implements LocaleReader { | ||
@Override | ||
public boolean containsKey(String s) { | ||
return true; | ||
} | ||
|
||
@Override | ||
public String get(String s) { | ||
String res; | ||
switch (s) { | ||
case "invalid-enum", "invalid-number", "invalid-uuid", "invalid-url", "invalid-boolean": { | ||
res = LANG.getString("commands.invalid-value") | ||
.replace("%value%", "{0}"); | ||
break; | ||
} | ||
case "missing-argument": { | ||
res = LANG.getString("commands.missing-argument") | ||
.replace("%value%", "{0}"); | ||
break; | ||
} | ||
case "no-permission": { | ||
res = LANG.getString("commands.no-permission"); | ||
break; | ||
} | ||
case "number-not-in-range": { | ||
res = LANG.getString("commands.out-of-range") | ||
.replace("%number%", "{0}") | ||
.replace("%min%", "{1}") | ||
.replace("%max%", "{2}"); | ||
break; | ||
} | ||
case "must-be-player": { | ||
res = LANG.getString("commands.player-only"); | ||
break; | ||
} | ||
case "must-be-console": { | ||
res = LANG.getString("commands.console-only"); | ||
break; | ||
} | ||
case "invalid-player": { | ||
res = LANG.getString("commands.invalid-player") | ||
.replace("%player%", "{0}"); | ||
break; | ||
} | ||
case "invalid-selector": { | ||
res = LANG.getString("commands.invalid-selector"); | ||
break; | ||
} | ||
default: { | ||
res = LANG.getString("commands.invalid-command"); | ||
break; | ||
} | ||
} | ||
return StringUtils.formatToString(CONFIG.getString("prefix", "") + res); | ||
} | ||
|
||
private final Locale locale = new Locale("en", "US"); | ||
|
||
@Override | ||
public Locale getLocale() { | ||
return locale; | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
src/main/java/com/artillexstudios/axsellwands/utils/HistoryUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package com.artillexstudios.axsellwands.utils; | ||
|
||
import com.artillexstudios.axsellwands.AxSellwands; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
import java.io.File; | ||
import java.io.FileWriter; | ||
import java.io.IOException; | ||
import java.io.PrintWriter; | ||
import java.time.ZonedDateTime; | ||
|
||
public class HistoryUtils { | ||
|
||
public static void writeToHistory(@NotNull String txt) { | ||
final ZonedDateTime zdt = ZonedDateTime.now(); | ||
final File subdir = new File(AxSellwands.getInstance().getDataFolder().getPath() + System.getProperty("file.separator") + "logs"); | ||
subdir.mkdirs(); | ||
final File file = new File(subdir.getPath() + "/" + zdt.getYear() + "-" + twoDigit(zdt.getMonthValue()) + "-" + twoDigit(zdt.getDayOfMonth()) + ".log"); | ||
|
||
try (FileWriter fr = new FileWriter(file.getAbsoluteFile(), true)) { | ||
try (PrintWriter pr = new PrintWriter(fr)) { | ||
pr.print("[" + twoDigit(zdt.getHour()) + ":" + twoDigit(zdt.getMinute()) + ":" + twoDigit(zdt.getSecond()) + "] "); | ||
pr.println(txt); | ||
} | ||
} catch (IOException ex) { | ||
ex.printStackTrace(); | ||
} | ||
} | ||
|
||
private static @NotNull String twoDigit(int i) { | ||
return i > 9 ? Integer.toString(i) : "0" + i; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters