Search in sources :

Example 6 with MassiveException

use of com.massivecraft.massivecore.MassiveException in project MassiveCore by MassiveCraft.

the class TypeItemStack method read.

@Override
public ItemStack read(String arg, CommandSender sender) throws MassiveException {
    if (!(sender instanceof Player))
        throw new MassiveException().addMsg("<b>You must be a player to hold an item in your hand.");
    Player player = (Player) sender;
    ItemStack ret = InventoryUtil.getWeapon(player);
    if (InventoryUtil.isNothing(ret))
        throw new MassiveException().addMsg("<b>You must hold an item in your hand.");
    Material material = ret.getType();
    if (!this.materialsAllowed.contains(material))
        throw new MassiveException().addMsg("<h>%s <b>is not allowed.", Txt.getNicedEnum(material));
    ret = new ItemStack(ret);
    return ret;
}
Also used : Player(org.bukkit.entity.Player) MassiveException(com.massivecraft.massivecore.MassiveException) Material(org.bukkit.Material) ItemStack(org.bukkit.inventory.ItemStack)

Example 7 with MassiveException

use of com.massivecraft.massivecore.MassiveException in project MassiveCore by MassiveCraft.

the class TypePS method read.

@Override
public PS read(String arg, CommandSender sender) throws MassiveException {
    // Ellador 34 13 78.6 (standard one)
    // 34 13 79 (standard one)
    // pitch14.5
    // worldEllador,yaw14,
    // lx15,ly18,lz8003
    // lx15 ly32 lz99 wEllador
    // lx:15 ly:32 lz:99 w:Ellador
    // We get the sender ps (note only pitch, yaw, and world is implicit)
    PS defaultPs = PS.NULL;
    if (sender instanceof Entity) {
        Location loc = ((Entity) sender).getLocation();
        defaultPs = new PSBuilder().world(PS.calcWorldName(loc.getWorld())).pitch(loc.getPitch()).yaw(loc.getYaw()).build();
    }
    // We remove all commas optionally followed by spaces
    String argInner = arg.replaceAll("\\:\\s*", "");
    // We split on comma and space to get the list of raw entries.
    List<String> parts = Arrays.asList(argInner.split("[\\s,]+"));
    // Then we test the standard ones
    if (parts.size() == 4) {
        try {
            String world = TypeWorldId.get().read(parts.get(0), sender);
            double locationX = TypeDouble.get().read(parts.get(1), sender);
            double locationY = TypeDouble.get().read(parts.get(2), sender);
            double locationZ = TypeDouble.get().read(parts.get(3), sender);
            return new PSBuilder(defaultPs).world(world).locationX(locationX).locationY(locationY).locationZ(locationZ).build();
        } catch (Exception e) {
        }
        try {
            double locationX = TypeDouble.get().read(parts.get(0), sender);
            double locationY = TypeDouble.get().read(parts.get(1), sender);
            double locationZ = TypeDouble.get().read(parts.get(2), sender);
            String world = TypeWorldId.get().read(parts.get(3), sender);
            return new PSBuilder(defaultPs).world(world).locationX(locationX).locationY(locationY).locationZ(locationZ).build();
        } catch (Exception e) {
        }
    } else if (parts.size() == 3) {
        try {
            double locationX = TypeDouble.get().read(parts.get(0), sender);
            double locationY = TypeDouble.get().read(parts.get(1), sender);
            double locationZ = TypeDouble.get().read(parts.get(2), sender);
            return new PSBuilder(defaultPs).locationX(locationX).locationY(locationY).locationZ(locationZ).build();
        } catch (Exception e) {
        }
    }
    // Then we split each entry using known prefixes and append the ps builder.
    PSBuilder ret = new PSBuilder(defaultPs);
    boolean something = false;
    for (String part : parts) {
        String value;
        value = getValue(part, PS.NAME_SERIALIZED_WORLD, PS.NAME_FULL_WORLD);
        if (value != null) {
            ret.world(TypeWorldId.get().read(value, sender));
            something = true;
        }
        value = getValue(part, PS.NAME_SERIALIZED_BLOCKX, PS.NAME_FULL_BLOCKX);
        if (value != null) {
            ret.blockX(TypeInteger.get().read(value, sender));
            something = true;
        }
        value = getValue(part, PS.NAME_SERIALIZED_BLOCKY, PS.NAME_FULL_BLOCKY);
        if (value != null) {
            ret.blockY(TypeInteger.get().read(value, sender));
            something = true;
        }
        value = getValue(part, PS.NAME_SERIALIZED_BLOCKZ, PS.NAME_FULL_BLOCKZ);
        if (value != null) {
            ret.blockZ(TypeInteger.get().read(value, sender));
            something = true;
        }
        value = getValue(part, PS.NAME_SERIALIZED_LOCATIONX, PS.NAME_FULL_LOCATIONX);
        if (value != null) {
            ret.locationX(TypeDouble.get().read(value, sender));
            something = true;
        }
        value = getValue(part, PS.NAME_SERIALIZED_LOCATIONY, PS.NAME_FULL_LOCATIONY);
        if (value != null) {
            ret.locationY(TypeDouble.get().read(value, sender));
            something = true;
        }
        value = getValue(part, PS.NAME_SERIALIZED_LOCATIONZ, PS.NAME_FULL_LOCATIONZ);
        if (value != null) {
            ret.locationZ(TypeDouble.get().read(value, sender));
            something = true;
        }
        value = getValue(part, PS.NAME_SERIALIZED_CHUNKX, PS.NAME_FULL_CHUNKX);
        if (value != null) {
            ret.chunkX(TypeInteger.get().read(value, sender));
            something = true;
        }
        value = getValue(part, PS.NAME_SERIALIZED_CHUNKZ, PS.NAME_FULL_CHUNKZ);
        if (value != null) {
            ret.chunkZ(TypeInteger.get().read(value, sender));
            something = true;
        }
        value = getValue(part, PS.NAME_SERIALIZED_PITCH, PS.NAME_FULL_PITCH);
        if (value != null) {
            ret.pitch(TypeFloat.get().read(value, sender));
            something = true;
        }
        value = getValue(part, PS.NAME_SERIALIZED_YAW, PS.NAME_FULL_YAW);
        if (value != null) {
            ret.yaw(TypeFloat.get().read(value, sender));
            something = true;
        }
        value = getValue(part, PS.NAME_SERIALIZED_VELOCITYX, PS.NAME_FULL_VELOCITYX);
        if (value != null) {
            ret.velocityX(TypeDouble.get().read(value, sender));
            something = true;
        }
        value = getValue(part, PS.NAME_SERIALIZED_VELOCITYY, PS.NAME_FULL_VELOCITYY);
        if (value != null) {
            ret.velocityY(TypeDouble.get().read(value, sender));
            something = true;
        }
        value = getValue(part, PS.NAME_SERIALIZED_VELOCITYZ, PS.NAME_FULL_VELOCITYZ);
        if (value != null) {
            ret.velocityZ(TypeDouble.get().read(value, sender));
            something = true;
        }
    }
    if (!something) {
        throw new MassiveException().addMsg("<b>Invalid physical state \"<h>%s<b>\".", arg);
    }
    return ret.build();
}
Also used : Entity(org.bukkit.entity.Entity) PS(com.massivecraft.massivecore.ps.PS) PSBuilder(com.massivecraft.massivecore.ps.PSBuilder) MassiveException(com.massivecraft.massivecore.MassiveException) MassiveException(com.massivecraft.massivecore.MassiveException) Location(org.bukkit.Location)

Example 8 with MassiveException

use of com.massivecraft.massivecore.MassiveException in project MassiveCore by MassiveCraft.

the class EngineMassiveCoreCommandSet method setValue.

public <T extends Serializable> void setValue(EventMassiveCoreCommandSet<T> event) throws MassiveException {
    String senderId = event.getSenderId();
    String targetId = event.getTargetId();
    T after = event.getValue();
    PlayerValue<T> playerValue = event.getPlayerValue();
    String name = event.getName();
    Player player = IdUtil.getPlayer(targetId);
    if (player == null)
        return;
    T before = playerValue.getValue(player);
    Type<T> type = (Type<T>) RegistryType.getType(after.getClass());
    String afterDesc = type.getVisual(after);
    String targetDesc = this.getTargetDesc(targetId, senderId, name);
    // NoChange
    if (after == before) {
        throw new MassiveException().addMsg("%s<i> is already <h>%s<i>.", targetDesc, afterDesc);
    }
    // Apply
    playerValue.setValue(after, player);
    // Inform
    MixinMessage.get().msgOne(senderId, "%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, name), afterDesc);
    }
}
Also used : Player(org.bukkit.entity.Player) RegistryType(com.massivecraft.massivecore.command.type.RegistryType) Type(com.massivecraft.massivecore.command.type.Type) MassiveException(com.massivecraft.massivecore.MassiveException)

Example 9 with MassiveException

use of com.massivecraft.massivecore.MassiveException in project MassiveCore by MassiveCraft.

the class EngineMassiveCoreDestination method destinationArg.

public Destination destinationArg(String arg, CommandSender sender) throws MassiveException {
    // Prepare
    arg = arg.toLowerCase();
    List<String> parts = Arrays.asList(arg.split("[\\s\\,\\:]+", 2));
    String first = parts.get(0);
    String rest = null;
    if (parts.size() > 1)
        rest = parts.get(1);
    arg = arg.replace("\\s+", "");
    // TOP
    if (ALIASES_TOP.contains(arg)) {
        Player player = DestinationUtil.getPlayer(sender);
        return new DestinationTop(player);
    }
    // THERE
    if (ALIASES_THERE.contains(arg)) {
        Player player = DestinationUtil.getPlayer(sender);
        return new DestinationThere(player);
    }
    // THAT
    if (ALIASES_THAT.contains(arg)) {
        Player player = DestinationUtil.getPlayer(sender);
        return new DestinationThat(player);
    }
    // JUMP
    if (ALIASES_JUMP.contains(arg)) {
        Player player = DestinationUtil.getPlayer(sender);
        return new DestinationJump(player);
    }
    // World Explicit
    if (ALIASES_WORLD.contains(first)) {
        String worldId;
        if (rest != null) {
            worldId = TypeWorldId.get().read(rest, sender);
        } else {
            Player player = DestinationUtil.getPlayer(sender);
            World world = player.getWorld();
            worldId = world.getName();
        }
        return new DestinationWorld(worldId);
    }
    // World Implicit
    try {
        String worldId = TypeWorldId.get().read(arg, sender);
        return new DestinationWorld(worldId);
    } catch (Exception e) {
    }
    // Player Explicit
    if (ALIASES_PLAYER.contains(first)) {
        String playerId;
        if (rest != null) {
            playerId = TypeSenderId.get().read(rest, sender);
        } else {
            Player player = DestinationUtil.getPlayer(sender);
            playerId = IdUtil.getId(player);
        }
        return new DestinationPlayer(playerId);
    }
    // Player Implicit
    try {
        String playerId = TypeSenderId.get().read(arg, sender);
        return new DestinationPlayer(playerId);
    } catch (Exception e) {
    }
    // Null
    return null;
}
Also used : DestinationThat(com.massivecraft.massivecore.teleport.DestinationThat) Player(org.bukkit.entity.Player) DestinationPlayer(com.massivecraft.massivecore.teleport.DestinationPlayer) DestinationJump(com.massivecraft.massivecore.teleport.DestinationJump) DestinationTop(com.massivecraft.massivecore.teleport.DestinationTop) DestinationThere(com.massivecraft.massivecore.teleport.DestinationThere) DestinationWorld(com.massivecraft.massivecore.teleport.DestinationWorld) World(org.bukkit.World) DestinationPlayer(com.massivecraft.massivecore.teleport.DestinationPlayer) DestinationWorld(com.massivecraft.massivecore.teleport.DestinationWorld) MassiveException(com.massivecraft.massivecore.MassiveException)

Example 10 with MassiveException

use of com.massivecraft.massivecore.MassiveException in project MassiveCore by MassiveCraft.

the class EngineMassiveCoreDestination method destinationArg.

@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void destinationArg(EventMassiveCoreDestination event) {
    final String arg = event.getArg().toLowerCase();
    final CommandSender sender = event.getSender();
    try {
        Destination destination = destinationArg(arg, sender);
        if (destination == null)
            return;
        event.setDestination(destination);
    } catch (MassiveException e) {
        event.setException(e);
    } catch (Exception e) {
        event.setException(new MassiveException().addMsg("<b>%s", e.getMessage()));
    }
    event.setCancelled(true);
}
Also used : EventMassiveCoreDestination(com.massivecraft.massivecore.event.EventMassiveCoreDestination) Destination(com.massivecraft.massivecore.teleport.Destination) MassiveException(com.massivecraft.massivecore.MassiveException) CommandSender(org.bukkit.command.CommandSender) MassiveException(com.massivecraft.massivecore.MassiveException) EventHandler(org.bukkit.event.EventHandler)

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