Have DisguiseParseException throw a properly formatted (colored) error.
This commit is contained in:
parent
9a91b91966
commit
0a7a2a5276
@ -47,9 +47,7 @@ public class DisguiseCommand extends DisguiseBaseCommand implements TabCompleter
|
|||||||
disguise = DisguiseParser
|
disguise = DisguiseParser
|
||||||
.parseDisguise(sender, (Entity) sender, getPermNode(), DisguiseUtilities.split(StringUtils.join(args, " ")), getPermissions(sender));
|
.parseDisguise(sender, (Entity) sender, getPermNode(), DisguiseUtilities.split(StringUtils.join(args, " ")), getPermissions(sender));
|
||||||
} catch (DisguiseParseException ex) {
|
} catch (DisguiseParseException ex) {
|
||||||
if (ex.getMessage() != null) {
|
ex.send(sender);
|
||||||
DisguiseUtilities.sendMessage(sender, ex.getMessage());
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
} catch (Throwable ex) {
|
} catch (Throwable ex) {
|
||||||
|
@ -51,9 +51,7 @@ public class DisguiseEntityCommand extends DisguiseBaseCommand implements TabCom
|
|||||||
try {
|
try {
|
||||||
testDisguise = DisguiseParser.parseTestDisguise(sender, getPermNode(), disguiseArgs, getPermissions(sender));
|
testDisguise = DisguiseParser.parseTestDisguise(sender, getPermNode(), disguiseArgs, getPermissions(sender));
|
||||||
} catch (DisguiseParseException ex) {
|
} catch (DisguiseParseException ex) {
|
||||||
if (ex.getMessage() != null) {
|
ex.send(sender);
|
||||||
DisguiseUtilities.sendMessage(sender, ex.getMessage());
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
} catch (Throwable ex) {
|
} catch (Throwable ex) {
|
||||||
|
@ -81,9 +81,7 @@ public class DisguisePlayerCommand extends DisguiseBaseCommand implements TabCom
|
|||||||
try {
|
try {
|
||||||
disguise = DisguiseParser.parseDisguise(sender, entityTarget, getPermNode(), DisguiseUtilities.split(StringUtils.join(newArgs, " ")), permissions);
|
disguise = DisguiseParser.parseDisguise(sender, entityTarget, getPermNode(), DisguiseUtilities.split(StringUtils.join(newArgs, " ")), permissions);
|
||||||
} catch (DisguiseParseException ex) {
|
} catch (DisguiseParseException ex) {
|
||||||
if (ex.getMessage() != null) {
|
ex.send(sender);
|
||||||
DisguiseUtilities.sendMessage(sender, ex.getMessage());
|
|
||||||
}
|
|
||||||
return true;
|
return true;
|
||||||
} catch (Throwable ex) {
|
} catch (Throwable ex) {
|
||||||
ex.printStackTrace();
|
ex.printStackTrace();
|
||||||
|
@ -215,9 +215,7 @@ public class DisguiseRadiusCommand extends DisguiseBaseCommand implements TabCom
|
|||||||
LibsMsg.DRADIUS_MISCDISG.send(sender, miscDisguises);
|
LibsMsg.DRADIUS_MISCDISG.send(sender, miscDisguises);
|
||||||
}
|
}
|
||||||
} catch (DisguiseParseException ex) {
|
} catch (DisguiseParseException ex) {
|
||||||
if (ex.getMessage() != null) {
|
ex.send(sender);
|
||||||
DisguiseUtilities.sendMessage(sender, ex.getMessage());
|
|
||||||
}
|
|
||||||
} catch (Throwable ex) {
|
} catch (Throwable ex) {
|
||||||
ex.printStackTrace();
|
ex.printStackTrace();
|
||||||
}
|
}
|
||||||
|
@ -38,10 +38,7 @@ public class DisguiseEntityInteraction implements LibsEntityInteract {
|
|||||||
try {
|
try {
|
||||||
disguise = DisguiseParser.parseDisguise(p, entity, "disguiseentity", disguiseArgs, DisguiseParser.getPermissions(p, "disguiseentity"));
|
disguise = DisguiseParser.parseDisguise(p, entity, "disguiseentity", disguiseArgs, DisguiseParser.getPermissions(p, "disguiseentity"));
|
||||||
} catch (DisguiseParseException e) {
|
} catch (DisguiseParseException e) {
|
||||||
if (e.getMessage() != null) {
|
e.send(p);
|
||||||
DisguiseUtilities.sendMessage(p, e.getMessage());
|
|
||||||
}
|
|
||||||
|
|
||||||
return;
|
return;
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
@ -56,9 +56,7 @@ public class DisguiseModifyInteraction implements LibsEntityInteract {
|
|||||||
DisguiseParser.callMethods(p, disguise, perms, disguisePerm, new ArrayList<>(Arrays.asList(options)), options, "DisguiseModifyEntity");
|
DisguiseParser.callMethods(p, disguise, perms, disguisePerm, new ArrayList<>(Arrays.asList(options)), options, "DisguiseModifyEntity");
|
||||||
LibsMsg.LISTENER_MODIFIED_DISG.send(p);
|
LibsMsg.LISTENER_MODIFIED_DISG.send(p);
|
||||||
} catch (DisguiseParseException ex) {
|
} catch (DisguiseParseException ex) {
|
||||||
if (ex.getMessage() != null) {
|
ex.send(p);
|
||||||
DisguiseUtilities.sendMessage(p, ex.getMessage());
|
|
||||||
}
|
|
||||||
} catch (Throwable ex) {
|
} catch (Throwable ex) {
|
||||||
ex.printStackTrace();
|
ex.printStackTrace();
|
||||||
}
|
}
|
||||||
|
@ -62,9 +62,7 @@ public class DisguiseModifyCommand extends DisguiseBaseCommand implements TabCom
|
|||||||
"DisguiseModify");
|
"DisguiseModify");
|
||||||
}
|
}
|
||||||
catch (DisguiseParseException ex) {
|
catch (DisguiseParseException ex) {
|
||||||
if (ex.getMessage() != null) {
|
ex.send(sender);
|
||||||
DisguiseUtilities.sendMessage(sender, ex.getMessage());
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -91,9 +91,7 @@ public class DisguiseModifyPlayerCommand extends DisguiseBaseCommand implements
|
|||||||
"DisguiseModifyPlayer");
|
"DisguiseModifyPlayer");
|
||||||
}
|
}
|
||||||
catch (DisguiseParseException ex) {
|
catch (DisguiseParseException ex) {
|
||||||
if (ex.getMessage() != null) {
|
ex.send(sender);
|
||||||
DisguiseUtilities.sendMessage(sender, ex.getMessage());
|
|
||||||
}
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -168,9 +168,7 @@ public class DisguiseModifyRadiusCommand extends DisguiseBaseCommand implements
|
|||||||
DisguiseParser.callMethods(sender, disguise, permissions, disguisePerm, new ArrayList<>(), tempArgs, "DisguiseModifyRadius");
|
DisguiseParser.callMethods(sender, disguise, permissions, disguisePerm, new ArrayList<>(), tempArgs, "DisguiseModifyRadius");
|
||||||
modifiedDisguises++;
|
modifiedDisguises++;
|
||||||
} catch (DisguiseParseException ex) {
|
} catch (DisguiseParseException ex) {
|
||||||
if (ex.getMessage() != null) {
|
ex.send(sender);
|
||||||
DisguiseUtilities.sendMessage(sender, ex.getMessage());
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
} catch (Throwable ex) {
|
} catch (Throwable ex) {
|
||||||
|
@ -72,7 +72,7 @@ public class SaveDisguiseCommand implements CommandExecutor {
|
|||||||
LibsMsg.CUSTOM_DISGUISE_SAVED.send(sender, name);
|
LibsMsg.CUSTOM_DISGUISE_SAVED.send(sender, name);
|
||||||
} catch (DisguiseParseException e) {
|
} catch (DisguiseParseException e) {
|
||||||
if (e.getMessage() != null) {
|
if (e.getMessage() != null) {
|
||||||
DisguiseUtilities.sendMessage(sender, e.getMessage());
|
e.send(sender);
|
||||||
} else {
|
} else {
|
||||||
LibsMsg.PARSE_CANT_LOAD.send(sender);
|
LibsMsg.PARSE_CANT_LOAD.send(sender);
|
||||||
}
|
}
|
||||||
@ -171,7 +171,7 @@ public class SaveDisguiseCommand implements CommandExecutor {
|
|||||||
DisguiseUtilities.setSaveDisguiseCommandUsed();
|
DisguiseUtilities.setSaveDisguiseCommandUsed();
|
||||||
} catch (DisguiseParseException e) {
|
} catch (DisguiseParseException e) {
|
||||||
if (e.getMessage() != null) {
|
if (e.getMessage() != null) {
|
||||||
DisguiseUtilities.sendMessage(sender, e.getMessage());
|
e.send(sender);
|
||||||
} else {
|
} else {
|
||||||
LibsMsg.PARSE_CANT_LOAD.send(sender);
|
LibsMsg.PARSE_CANT_LOAD.send(sender);
|
||||||
}
|
}
|
||||||
|
@ -1,19 +1,27 @@
|
|||||||
package me.libraryaddict.disguise.utilities.parser;
|
package me.libraryaddict.disguise.utilities.parser;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
import me.libraryaddict.disguise.utilities.translations.LibsMsg;
|
import me.libraryaddict.disguise.utilities.translations.LibsMsg;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by libraryaddict on 7/09/2018.
|
* Created by libraryaddict on 7/09/2018.
|
||||||
*/
|
*/
|
||||||
|
@Getter
|
||||||
public class DisguiseParseException extends Exception {
|
public class DisguiseParseException extends Exception {
|
||||||
private static final long serialVersionUID = 1276971370793124510L;
|
private static final long serialVersionUID = 1276971370793124510L;
|
||||||
|
private LibsMsg msg;
|
||||||
|
private String[] params;
|
||||||
|
|
||||||
public DisguiseParseException() {
|
public DisguiseParseException() {
|
||||||
super();
|
super();
|
||||||
}
|
}
|
||||||
|
|
||||||
public DisguiseParseException(LibsMsg message, String... params) {
|
public DisguiseParseException(LibsMsg message, String... params) {
|
||||||
super(message.get(params));
|
super(message.getVanillaFormat(params));
|
||||||
|
|
||||||
|
this.msg = message;
|
||||||
|
this.params = params;
|
||||||
}
|
}
|
||||||
|
|
||||||
public DisguiseParseException(String message) {
|
public DisguiseParseException(String message) {
|
||||||
@ -27,4 +35,12 @@ public class DisguiseParseException extends Exception {
|
|||||||
public DisguiseParseException(Throwable throwable) {
|
public DisguiseParseException(Throwable throwable) {
|
||||||
super(throwable);
|
super(throwable);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void send(CommandSender sender) {
|
||||||
|
if (this.getMsg() == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.msg.send(sender, (Object[]) params);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -302,6 +302,16 @@ public enum LibsMsg {
|
|||||||
this.string = string;
|
this.string = string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getVanillaFormat(String[] params) {
|
||||||
|
String raw = get((Object[]) params);
|
||||||
|
|
||||||
|
for (ChatColor c : ChatColor.values()) {
|
||||||
|
raw = raw.replace("<" + c.name().toLowerCase(Locale.ROOT) + ">", "§" + c.getChar());
|
||||||
|
}
|
||||||
|
|
||||||
|
return raw;
|
||||||
|
}
|
||||||
|
|
||||||
public String getVanillaFormat() {
|
public String getVanillaFormat() {
|
||||||
String raw = getRaw();
|
String raw = getRaw();
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user