Search in sources :

Example 1 with PS

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();
}
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 2 with PS

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;
}
Also used : PS(com.massivecraft.massivecore.ps.PS) World(org.bukkit.World)

Example 3 with PS

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");
        }
    }
}
Also used : Player(org.bukkit.entity.Player) PS(com.massivecraft.massivecore.ps.PS) Region(br.net.fabiozumbi12.RedProtect.Bukkit.Region) EventHandler(org.bukkit.event.EventHandler)

Example 4 with PS

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;
        }
    }
}
Also used : EventForwarder(me.andrew28.addons.conquer.api.EventForwarder) Cancellable(org.bukkit.event.Cancellable) ConquerUnclaimAllEvent(me.andrew28.addons.conquer.api.events.ConquerUnclaimAllEvent) EventFactionsCreate(com.massivecraft.factions.event.EventFactionsCreate) EventFactionsRelationChange(com.massivecraft.factions.event.EventFactionsRelationChange) Event(org.bukkit.event.Event) ConquerFactionRelationEvent(me.andrew28.addons.conquer.api.events.ConquerFactionRelationEvent) EventHandler(org.bukkit.event.EventHandler) EventFactionsDisband(com.massivecraft.factions.event.EventFactionsDisband) ConquerClaim(me.andrew28.addons.conquer.api.ConquerClaim) Map(java.util.Map) EventFactionsMembershipChange(com.massivecraft.factions.event.EventFactionsMembershipChange) ConquerFactionLeaveEvent(me.andrew28.addons.conquer.api.events.ConquerFactionLeaveEvent) ConquerFaction(me.andrew28.addons.conquer.api.ConquerFaction) ConquerPowerLossEvent(me.andrew28.addons.conquer.api.events.ConquerPowerLossEvent) EventFactionsChunkChangeType(com.massivecraft.factions.event.EventFactionsChunkChangeType) ConquerFactionDisbandEvent(me.andrew28.addons.conquer.api.events.ConquerFactionDisbandEvent) Relation(me.andrew28.addons.conquer.api.Relation) PS(com.massivecraft.massivecore.ps.PS) ConquerFactionRelationWishEvent(me.andrew28.addons.conquer.api.events.ConquerFactionRelationWishEvent) ConquerLandClaimEvent(me.andrew28.addons.conquer.api.events.ConquerLandClaimEvent) EventFactionsPowerChange(com.massivecraft.factions.event.EventFactionsPowerChange) Set(java.util.Set) ConquerFactionJoinEvent(me.andrew28.addons.conquer.api.events.ConquerFactionJoinEvent) EventFactionsChunksChange(com.massivecraft.factions.event.EventFactionsChunksChange) ConquerPlayer(me.andrew28.addons.conquer.api.ConquerPlayer) ConquerFactionCreateEvent(me.andrew28.addons.conquer.api.events.ConquerFactionCreateEvent) PS(com.massivecraft.massivecore.ps.PS) ConquerFaction(me.andrew28.addons.conquer.api.ConquerFaction) Cancellable(org.bukkit.event.Cancellable) ConquerUnclaimAllEvent(me.andrew28.addons.conquer.api.events.ConquerUnclaimAllEvent) Event(org.bukkit.event.Event) ConquerFactionRelationEvent(me.andrew28.addons.conquer.api.events.ConquerFactionRelationEvent) ConquerFactionLeaveEvent(me.andrew28.addons.conquer.api.events.ConquerFactionLeaveEvent) ConquerPowerLossEvent(me.andrew28.addons.conquer.api.events.ConquerPowerLossEvent) ConquerFactionDisbandEvent(me.andrew28.addons.conquer.api.events.ConquerFactionDisbandEvent) ConquerFactionRelationWishEvent(me.andrew28.addons.conquer.api.events.ConquerFactionRelationWishEvent) ConquerLandClaimEvent(me.andrew28.addons.conquer.api.events.ConquerLandClaimEvent) ConquerFactionJoinEvent(me.andrew28.addons.conquer.api.events.ConquerFactionJoinEvent) ConquerFactionCreateEvent(me.andrew28.addons.conquer.api.events.ConquerFactionCreateEvent) ConquerUnclaimAllEvent(me.andrew28.addons.conquer.api.events.ConquerUnclaimAllEvent) ConquerLandClaimEvent(me.andrew28.addons.conquer.api.events.ConquerLandClaimEvent) ConquerPlayer(me.andrew28.addons.conquer.api.ConquerPlayer) ConquerClaim(me.andrew28.addons.conquer.api.ConquerClaim) EventFactionsChunkChangeType(com.massivecraft.factions.event.EventFactionsChunkChangeType) EventHandler(org.bukkit.event.EventHandler)

Example 5 with PS

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);
    }
}
Also used : EventMassiveCoreDestination(com.massivecraft.massivecore.event.EventMassiveCoreDestination) Destination(com.massivecraft.massivecore.teleport.Destination) TypePS(com.massivecraft.massivecore.command.type.TypePS) PS(com.massivecraft.massivecore.ps.PS) MassiveException(com.massivecraft.massivecore.MassiveException) DestinationSimple(com.massivecraft.massivecore.teleport.DestinationSimple) EventHandler(org.bukkit.event.EventHandler)

Aggregations

PS (com.massivecraft.massivecore.ps.PS)7 EventHandler (org.bukkit.event.EventHandler)3 MassiveException (com.massivecraft.massivecore.MassiveException)2 World (org.bukkit.World)2 Player (org.bukkit.entity.Player)2 Region (br.net.fabiozumbi12.RedProtect.Bukkit.Region)1 EventFactionsChunkChangeType (com.massivecraft.factions.event.EventFactionsChunkChangeType)1 EventFactionsChunksChange (com.massivecraft.factions.event.EventFactionsChunksChange)1 EventFactionsCreate (com.massivecraft.factions.event.EventFactionsCreate)1 EventFactionsDisband (com.massivecraft.factions.event.EventFactionsDisband)1 EventFactionsMembershipChange (com.massivecraft.factions.event.EventFactionsMembershipChange)1 EventFactionsPowerChange (com.massivecraft.factions.event.EventFactionsPowerChange)1 EventFactionsRelationChange (com.massivecraft.factions.event.EventFactionsRelationChange)1 TypePS (com.massivecraft.massivecore.command.type.TypePS)1 EventMassiveCoreDestination (com.massivecraft.massivecore.event.EventMassiveCoreDestination)1 EventMassiveCorePlayerPSTeleport (com.massivecraft.massivecore.event.EventMassiveCorePlayerPSTeleport)1 PSBuilder (com.massivecraft.massivecore.ps.PSBuilder)1 Destination (com.massivecraft.massivecore.teleport.Destination)1 DestinationSimple (com.massivecraft.massivecore.teleport.DestinationSimple)1 ScheduledTeleport (com.massivecraft.massivecore.teleport.ScheduledTeleport)1