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;
}
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();
}
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);
}
}
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;
}
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);
}
Aggregations