use of com.massivecraft.massivecore.MassiveException in project MassiveCore by MassiveCraft.
the class MassiveCommand method execute.
// -------------------------------------------- //
// EXECUTOR
// -------------------------------------------- //
public void execute(CommandSender sender, List<String> args) {
try {
// Sender Field - Setup
this.senderFieldsOuter(sender);
// Apply Puzzler
args = this.applyPuzzler(args, sender);
this.setArgs(args);
// Requirements
if (!this.isRequirementsMet(sender, true))
return;
// Child Execution
if (this.isParent() && args.size() > 0) {
// Get matches
String token = args.get(0);
Set<MassiveCommand> matches = this.getChildren(token, false, null, true);
// Score!
if (matches.size() == 1) {
MassiveCommand child = matches.iterator().next();
args.remove(0);
child.execute(sender, args);
} else // Crap!
{
Mson base = null;
Collection<MassiveCommand> suggestions = null;
if (matches.isEmpty()) {
base = Lang.COMMAND_CHILD_NONE;
suggestions = this.getChildren(token, true, sender, false);
} else {
base = Lang.COMMAND_CHILD_AMBIGUOUS;
suggestions = this.getChildren(token, false, sender, false);
}
// Message: "The sub command X couldn't be found."
// OR
// Message: "The sub command X is ambiguous."
Mson bluetoken = mson(token).color(ChatColor.AQUA);
MixinMessage.get().messageOne(sender, base.replaceAll(Lang.COMMAND_REPLACEMENT, bluetoken).command(this));
// Message: "/f ally ..."
for (MassiveCommand suggestion : suggestions) {
MixinMessage.get().messageOne(sender, suggestion.getTemplate(false, false, sender));
}
// Message: "Use /Y to see all commands."
MixinMessage.get().messageOne(sender, Lang.COMMAND_CHILD_HELP.replaceAll(Lang.COMMAND_REPLACEMENT, this.getTemplate(false, false, sender)).command(this));
}
// NOTE: This return statement will jump to the finally block.
return;
}
// Self Execution > Arguments Valid
if (!this.isArgsValid(this.getArgs(), this.sender))
return;
// Self Execution > Perform
this.perform();
} catch (MassiveException ex) {
// Sometimes Types (or commands themselves) throw exceptions, to stop executing and notify the user.
if (ex.hasMessages()) {
MixinMessage.get().messageOne(sender, ex.getMessages());
}
} finally {
// Sender Sender - Cleanup
this.senderFieldsOuter(null);
}
}
use of com.massivecraft.massivecore.MassiveException in project MassiveCore by MassiveCraft.
the class MassiveCommandSet method perform.
// -------------------------------------------- //
// OVERRIDE
// -------------------------------------------- //
@Override
public void perform() throws MassiveException {
// Args
T after = this.readArg();
String senderId = IdUtil.getId(sender);
String targetId = this.readArg(senderId);
boolean other = !targetId.equals(senderId);
// Check other
if (other && this.hasPermSetOther()) {
if (!PermissionUtil.hasPermission(sender, this.getPermSetOther(), true))
return;
}
T before = this.getValue(targetId);
String afterDesc = this.getType().getVisual(after, sender);
String targetDesc = this.getTargetDesc(targetId, senderId);
// NoChange
if (after == before) {
throw new MassiveException().addMsg("%s<i> is already <h>%s<i>.", targetDesc, afterDesc);
}
// Apply
this.setValue(after, targetId);
// Inform
msg("%s<i> is now <h>%s<i>.", targetDesc, afterDesc);
// Inform target
if (!targetId.equals(senderId)) {
MixinMessage.get().msgOne(targetId, "%s<i> is now <h>%s<i>.", getTargetDesc(targetId, targetId), afterDesc);
}
}
use of com.massivecraft.massivecore.MassiveException in project MassiveCore by MassiveCraft.
the class TypeAbstractSelect method read.
// -------------------------------------------- //
// OVERRIDE
// -------------------------------------------- //
@Override
public T read(String arg, CommandSender sender) throws MassiveException {
T result = this.select(arg, sender);
if (result != null)
return result;
MassiveException exception = createExceptionForInvalidArg(arg, sender);
throw exception;
}
use of com.massivecraft.massivecore.MassiveException in project MassiveCore by MassiveCraft.
the class TypeColor method readInnerHex.
public Color readInnerHex(String arg) throws MassiveException {
boolean verbose = false;
// Explicit verbose hex
if (arg.startsWith("#")) {
arg = arg.substring(1);
verbose = true;
}
// Length check
if (arg.length() != 6) {
if (verbose)
throw new MassiveException().addMsg("<b>Hex must be 6 hexadecimals.");
return null;
}
try {
int red = Integer.parseInt(arg.substring(0, 2), 16);
int green = Integer.parseInt(arg.substring(2, 4), 16);
int blue = Integer.parseInt(arg.substring(4, 6), 16);
return Color.fromRGB(red, green, blue);
} catch (IllegalArgumentException e) {
if (verbose)
throw new MassiveException().addMsg("<b>\"<h>%s<b>\" is not valid hexadecimal.", arg);
return null;
}
}
use of com.massivecraft.massivecore.MassiveException in project MassiveCore by MassiveCraft.
the class TypeColor method read.
// -------------------------------------------- //
// READ
// -------------------------------------------- //
@Override
public Color read(String arg, CommandSender sender) throws MassiveException {
Color ret;
// Try RGB
ret = readInnerRgb(arg);
if (ret != null)
return ret;
// Try Hex
ret = readInnerHex(arg);
if (ret != null)
return ret;
// Try DyeColor
ret = readInnerDyeColor(arg);
if (ret != null)
return ret;
throw new MassiveException().addMsg("<b>No color matches \"<h>%s<b>\".", arg);
}
Aggregations