Skip to content
This repository has been archived by the owner on Apr 9, 2024. It is now read-only.

Commit

Permalink
get rid of abstraction in ExpressionResult + better command output
Browse files Browse the repository at this point in the history
  • Loading branch information
Andre601 committed Sep 2, 2022
1 parent dd970cf commit ecaaf7b
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,41 +37,45 @@ public CommandHandler(AdvancedServerList core){
}

public void handle(CmdSender sender, String[] args){
String errorPrefix = "<grey>[<gradient:dark_red:red>AdvancedServerList</gradient>]";
String prefix = "<grey>[<gradient:aqua:white>AdvancedServerList</gradient>]";

if(args.length == 0 || args[0].equalsIgnoreCase("help")){
if(sender.hasPermission("advancedserverlist.command.help")){
sender.sendMsg("AdvancedServerList Commands");
sender.sendMsg("%s - Commands", prefix);
sender.sendMsg();
sender.sendMsg("<aqua>/asl help <grey>- Shows this help.");
sender.sendMsg("<gradient:aqua:white>/asl help</gradient> <grey>- Shows this Help");
sender.sendMsg();
sender.sendMsg("<aqua>/asl reload <grey>- Reloads the config and profiles.");
sender.sendMsg("<gradient:aqua:white>/asl reload</gradient> <grey>- Reloads the plugin");
}else{
sender.sendMsg("<red>You do not have the permissions to execute this command!");
sender.sendMsg("%s <red>You do not have permissions to execute this command!", errorPrefix);
}
}else
if(args[0].equalsIgnoreCase("reload")){
if(sender.hasPermission("advancedserverlist.command.reload")){
sender.sendMsg("<grey>Reloading config.yml...");
sender.sendMsg("%s Reloading plugin...", prefix);

if(core.getFileHandler().reloadConfig()){
sender.sendMsg("<green>Successfully reloaded <grey>config.yml</grey>!");
sender.sendMsg("%s <green>Reloaded <grey>config.yml</grey>!", prefix);
}else{
sender.sendMsg("<red>Error while reloading the config.yml.");
sender.sendMsg("%s <red>Error while reloading the <grey>config.yml</grey>!", errorPrefix);
}

sender.sendMsg("<grey>Reloading Profiles...");
if(core.getFileHandler().reloadProfiles()){
sender.sendMsg("<green>Successfully loaded <grey>%d</grey> Profiles!", core.getFileHandler().getProfiles().size());
sender.sendMsg("%s <green>Loaded <grey>%s Profile(s)</grey>!", prefix, core.getFileHandler().getProfiles());
}else{
sender.sendMsg("<red>Error while reloading Profiles. No profiles have been loaded.");
sender.sendMsg("%s <red>Cannot load Profiles!", errorPrefix);
}

sender.sendMsg("<grey>Clearing Favicon cache...");
core.clearFaviconCache();
sender.sendMsg("<green>Successfully cleared Favicon cache!");
sender.sendMsg("%s <green>Successfully cleared Favicon cache!", prefix);

sender.sendMsg("<green>Reload complete!");
sender.sendMsg("%s <green>Reload complete!", prefix);
}else{
sender.sendMsg("%s <red>You do not have permissions to execute this command!", errorPrefix);
}
}else{
sender.sendMsg("<red>Unknown subcommand <grey>%s</grey>. Use <grey>/asl help</grey> for a list of commands.", args[0]);
sender.sendMsg("%s <red>Unknown subcommand <grey>%s</grey>. Use <grey>/asl help</grey> for a list of commands.", prefix, args[0]);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,6 @@

public class FileHandler{

private final FilenameFilter profileFilter = (dir, name) -> name.endsWith(".yml");

private final AdvancedServerList plugin;
private final PluginLogger logger;

Expand Down Expand Up @@ -119,7 +117,7 @@ public boolean reloadConfig(){
public boolean reloadProfiles(){
profiles.clear();

File[] files = profilesFolder.toFile().listFiles(profileFilter);
File[] files = profilesFolder.toFile().listFiles(((dir, name) -> name.endsWith(".yml")));
if(files == null || files.length == 0){
logger.warn("Cannot load files from profiles folder! No valid YAML files present.");
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,32 +191,20 @@ private static int getInt(String text){
}

public enum ExpressionResult{
VALID{
@Override
public String getMessage(){
return null;
}
},
VALID(null),

INVALID_NO_EXPRESSION{
@Override
public String getMessage(){
return "Received empty condition which isn't allowed!";
}
},
INVALID_DOUBLE_OPERATOR{
@Override
public String getMessage(){
return "Condition contained two operands.";
}
},
INVALID_EMPTY_PARTS{
@Override
public String getMessage(){
return "Received condition with either left or right part being empty.";
}
};
INVALID_NO_EXPRESSION ("Received empty condition which isn't allowed!"),
INVALID_DOUBLE_OPERATOR("Condition contained two operands."),
INVALID_EMPTY_PARTS ("Received condition with either left or right part being empty.");

public abstract String getMessage();
private final String message;

ExpressionResult(String message){
this.message = message;
}

public String getMessage(){
return message;
}
}
}

0 comments on commit ecaaf7b

Please sign in to comment.