Search in sources :

Example 1 with MassiveException

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);
    }
}
Also used : Mson(com.massivecraft.massivecore.mson.Mson) MassiveException(com.massivecraft.massivecore.MassiveException)

Example 2 with MassiveException

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);
    }
}
Also used : MassiveException(com.massivecraft.massivecore.MassiveException)

Example 3 with MassiveException

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;
}
Also used : MassiveException(com.massivecraft.massivecore.MassiveException)

Example 4 with MassiveException

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;
    }
}
Also used : MassiveException(com.massivecraft.massivecore.MassiveException)

Example 5 with MassiveException

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);
}
Also used : TypeDyeColor(com.massivecraft.massivecore.command.type.enumeration.TypeDyeColor) ChatColor(org.bukkit.ChatColor) DyeColor(org.bukkit.DyeColor) Color(org.bukkit.Color) MassiveException(com.massivecraft.massivecore.MassiveException)

Aggregations

MassiveException (com.massivecraft.massivecore.MassiveException)18 Player (org.bukkit.entity.Player)4 EventMassiveCoreDestination (com.massivecraft.massivecore.event.EventMassiveCoreDestination)3 Destination (com.massivecraft.massivecore.teleport.Destination)3 Mson (com.massivecraft.massivecore.mson.Mson)2 PS (com.massivecraft.massivecore.ps.PS)2 EventHandler (org.bukkit.event.EventHandler)2 MassiveList (com.massivecraft.massivecore.collections.MassiveList)1 MassiveSet (com.massivecraft.massivecore.collections.MassiveSet)1 RequirementIsPlayer (com.massivecraft.massivecore.command.requirement.RequirementIsPlayer)1 RegistryType (com.massivecraft.massivecore.command.type.RegistryType)1 Type (com.massivecraft.massivecore.command.type.Type)1 TypePS (com.massivecraft.massivecore.command.type.TypePS)1 TypeDyeColor (com.massivecraft.massivecore.command.type.enumeration.TypeDyeColor)1 TypeString (com.massivecraft.massivecore.command.type.primitive.TypeString)1 PSBuilder (com.massivecraft.massivecore.ps.PSBuilder)1 DestinationJump (com.massivecraft.massivecore.teleport.DestinationJump)1 DestinationPlayer (com.massivecraft.massivecore.teleport.DestinationPlayer)1 DestinationSimple (com.massivecraft.massivecore.teleport.DestinationSimple)1 DestinationThat (com.massivecraft.massivecore.teleport.DestinationThat)1