use of com.massivecraft.massivecore.ps.PS 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.ps.PS in project MassiveCore by MassiveCraft.
the class ExtractorLogic method worldNameFromObject.
// -------------------------------------------- //
// WORLD NAME
// -------------------------------------------- //
public static String worldNameFromObject(Object o) {
if (o instanceof String) {
String string = (String) o;
if (MUtil.isUuid(string)) {
String ret = worldNameViaPsMixin(string);
if (ret != null)
return ret;
}
return string;
}
if (o instanceof PS)
return ((PS) o).getWorld();
World world = worldFromObject(o);
if (world != null)
return world.getName();
String ret = worldNameViaPsMixin(o);
if (ret != null)
return ret;
return null;
}
use of com.massivecraft.massivecore.ps.PS in project RedProtect by FabioZumbi12.
the class RPFactions method onCreateFac.
@EventHandler(ignoreCancelled = true)
public void onCreateFac(EventFactionsChunksChange event) {
if (RPConfig.getBool("hooks.factions.claim-over-rps")) {
return;
}
for (PS chunk : event.getChunks()) {
Player p = event.getMPlayer().getPlayer();
Set<Region> regs = RedProtect.get().rm.getRegionsForChunk(chunk.asBukkitChunk());
if (regs.size() > 0 && !p.hasPermission("redprotect.bypass")) {
event.setCancelled(true);
RPLang.sendMessage(p, "rpfactions.cantclaim");
}
}
}
use of com.massivecraft.massivecore.ps.PS in project Conquer by xXAndrew28Xx.
the class MSEventForwarder method onClaimChange.
@EventHandler
public void onClaimChange(EventFactionsChunksChange event) {
ConquerFaction faction = MSFaction.get(plugin, event.getNewFaction());
ConquerPlayer player = MSPlayer.get(plugin, event.getMPlayer());
Set<PS> chunks = event.getChunks();
Map<PS, EventFactionsChunkChangeType> chunkTypeMap = event.getChunkType();
// Check if it's an unclaim all
if (chunks.size() == faction.getClaims().length && chunkTypeMap.values().stream().allMatch(type -> type == EventFactionsChunkChangeType.SELL)) {
ConquerUnclaimAllEvent forwardEvent = new ConquerUnclaimAllEvent(faction, player);
callEvent(forwardEvent);
if (forwardEvent.isCancelled()) {
event.setCancelled(true);
}
}
for (PS chunk : chunks) {
EventFactionsChunkChangeType type = chunkTypeMap.get(chunk);
ConquerClaim claim = MSClaim.get(plugin, chunk);
Event forwardEvent;
switch(type) {
case NONE:
continue;
case BUY:
forwardEvent = new ConquerLandClaimEvent(claim, true, faction, player);
break;
case CONQUER:
case PILLAGE:
forwardEvent = new ConquerLandClaimEvent(claim, false, faction, player);
break;
default:
return;
}
callEvent(forwardEvent);
if (((Cancellable) forwardEvent).isCancelled()) {
event.setCancelled(true);
return;
}
}
}
use of com.massivecraft.massivecore.ps.PS in project MassiveCore by MassiveCraft.
the class EngineMassiveCoreDestination method destinationPs.
// -------------------------------------------- //
// DESTINATION ARG
// -------------------------------------------- //
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void destinationPs(EventMassiveCoreDestination event) {
try {
PS ps = TypePS.get().read(event.getArg(), event.getSender());
Destination destination = new DestinationSimple(ps);
event.setDestination(destination);
} catch (MassiveException exception) {
event.setException(exception);
event.setCancelled(true);
}
}
Aggregations