Search in sources :

Example 1 with EntitySnapshot

use of org.spongepowered.api.entity.EntitySnapshot in project SpongeCommon by SpongePowered.

the class DamageableDataProcessor method set.

@SuppressWarnings("unchecked")
@Override
protected boolean set(EntityLivingBase dataHolder, Map<Key<?>, Object> keyValues) {
    final Optional<EntitySnapshot> lastAttacker = (Optional<EntitySnapshot>) keyValues.get(Keys.LAST_ATTACKER);
    if (lastAttacker == null || !lastAttacker.isPresent()) {
        dataHolder.setRevengeTarget(null);
        return true;
    }
    if (lastAttacker.get().getUniqueId().isPresent()) {
        final Optional<Entity> optionalEntity = lastAttacker.get().restore();
        if (optionalEntity.isPresent()) {
            final Entity entity = optionalEntity.get();
            if (entity.isLoaded() && entity instanceof EntityLivingBase) {
                dataHolder.setRevengeTarget((EntityLivingBase) entity);
                ((IMixinEntityLivingBase) dataHolder).setLastDamage(((Optional<Double>) keyValues.get(Keys.LAST_DAMAGE)).orElse(0D));
                return true;
            }
        }
    }
    return false;
}
Also used : Entity(org.spongepowered.api.entity.Entity) EntitySnapshot(org.spongepowered.api.entity.EntitySnapshot) Optional(java.util.Optional) EntityLivingBase(net.minecraft.entity.EntityLivingBase) IMixinEntityLivingBase(org.spongepowered.common.interfaces.entity.IMixinEntityLivingBase) IMixinEntityLivingBase(org.spongepowered.common.interfaces.entity.IMixinEntityLivingBase)

Example 2 with EntitySnapshot

use of org.spongepowered.api.entity.EntitySnapshot in project RedProtect by FabioZumbi12.

the class RPPlayerListener method onPlayerMovement.

@Listener(order = Order.FIRST, beforeModifications = true)
public void onPlayerMovement(MoveEntityEvent e) {
    if (RedProtect.get().cfgs.getBool("performance.disable-onPlayerMoveEvent-handler")) {
        return;
    }
    Entity ent = e.getTargetEntity();
    Player p = null;
    if (ent instanceof Player) {
        p = (Player) ent;
    } else if (ent.get(Keys.PASSENGERS).isPresent()) {
        for (Object uuidEnt : ent.get(Keys.PASSENGERS).get()) {
            if (uuidEnt instanceof UUID) {
                if (Sponge.getServer().getPlayer((UUID) uuidEnt).isPresent()) {
                    p = Sponge.getServer().getPlayer((UUID) uuidEnt).get();
                }
            } else if (uuidEnt instanceof EntitySnapshot) {
                if (Sponge.getServer().getPlayer(((EntitySnapshot) uuidEnt).getUniqueId().get()).isPresent()) {
                    p = Sponge.getServer().getPlayer(((EntitySnapshot) uuidEnt).getUniqueId().get()).get();
                }
            }
        }
    } else {
        return;
    }
    if (p == null) {
        return;
    }
    RedProtect.get().logger.debug("player", "PlayerMoveEvent - Entity name: " + ent.getType().getName());
    if (e.getFromTransform() != e.getToTransform() && RedProtect.get().tpWait.contains(p.getName())) {
        RedProtect.get().tpWait.remove(p.getName());
        RPLang.sendMessage(p, "cmdmanager.region.tpcancelled");
    }
    Transform<World> lfromForm = e.getFromTransform();
    Transform<World> ltoForm = e.getToTransform();
    Location<World> lfrom = e.getFromTransform().getLocation();
    Location<World> lto = e.getToTransform().getLocation();
    // teleport player to coord/world if playerup 128 y
    int NetherY = RedProtect.get().cfgs.getInt("netherProtection.maxYsize");
    if (lto.getExtent().getDimension().getType().equals(DimensionTypes.NETHER) && NetherY != -1 && lto.getBlockY() >= NetherY && !p.hasPermission("RedProtect.get().bypass.nether-roof")) {
        for (String cmd : RedProtect.get().cfgs.getStringList("netherProtection.execute-cmd")) {
            RedProtect.get().game.getCommandManager().process(RedProtect.get().serv.getConsole(), cmd.replace("{player}", p.getName()));
        }
        RPLang.sendMessage(p, RPLang.get("playerlistener.upnethery").replace("{location}", NetherY + ""));
    }
    Region r = RedProtect.get().rm.getTopRegion(lto);
    /*
        //deny enter if no perm doors
    	String door = lto.getBlock().getType().getName();
    	if (r != null && (door.contains("DOOR") || door.contains("_GATE")) && !r.canDoor(p)){
    		if (RPDoor.isDoorClosed(p.getWorld().getBlockAt(lto))){
    			e.setCancelled(true);
    		}
    	}*/
    World w = lfrom.getExtent();
    if (r != null) {
        // enter max players flag
        if (r.maxPlayers() != -1) {
            if (!checkMaxPlayer(p, r)) {
                e.setToTransform(DenyEnterPlayer(w, lfromForm, ltoForm, p, r));
                RPLang.sendMessage(p, RPLang.get("playerlistener.region.maxplayers").replace("{players}", String.valueOf(r.maxPlayers())));
            }
        }
        // remove pots
        if (!r.allowEffects(p) && p.get(Keys.POTION_EFFECTS).isPresent()) {
            for (PotionEffect pot : p.get(Keys.POTION_EFFECTS).get()) {
                if (pot.getDuration() < 36000) {
                    p.offer(Keys.POTION_EFFECTS, new ArrayList<>());
                }
            }
        }
        // Enter flag
        if (!r.canEnter(p)) {
            e.setToTransform(DenyEnterPlayer(w, lfromForm, ltoForm, p, r));
            RPLang.sendMessage(p, "playerlistener.region.cantregionenter");
        }
        // Allow enter with items
        if (!r.canEnterWithItens(p)) {
            e.setToTransform(DenyEnterPlayer(w, lfromForm, ltoForm, p, r));
            RPLang.sendMessage(p, RPLang.get("playerlistener.region.onlyenter.withitems").replace("{items}", r.flags.get("allow-enter-items").toString()));
        }
        // Deny enter with item
        if (!r.denyEnterWithItens(p)) {
            e.setToTransform(DenyEnterPlayer(w, lfromForm, ltoForm, p, r));
            RPLang.sendMessage(p, RPLang.get("playerlistener.region.denyenter.withitems").replace("{items}", r.flags.get("deny-enter-items").toString()));
        }
        // Deny Fly
        if (!p.get(Keys.GAME_MODE).get().getName().equalsIgnoreCase("SPECTATOR") && !r.canFly(p) && p.get(Keys.IS_FLYING).get()) {
            p.offer(Keys.IS_FLYING, false);
            // p.setAllowFlight(false);
            RPLang.sendMessage(p, "playerlistener.region.cantfly");
        }
        // update region admin or leander visit
        if (RedProtect.get().cfgs.getString("region-settings.record-player-visit-method").equalsIgnoreCase("ON-REGION-ENTER")) {
            if (r.isLeader(p) || r.isAdmin(p)) {
                if (r.getDate() == null || (!r.getDate().equals(RPUtil.DateNow()))) {
                    r.setDate(RPUtil.DateNow());
                }
            }
        }
        if (Ownerslist.get(p) != r.getName()) {
            Region er = RedProtect.get().rm.getRegion(Ownerslist.get(p), p.getWorld());
            Ownerslist.put(p, r.getName());
            // Execute listener:
            EnterExitRegionEvent event = new EnterExitRegionEvent(er, r, p);
            if (Sponge.getEventManager().post(event)) {
                return;
            }
            // --
            RegionFlags(r, er, p);
            if (!r.getWelcome().equalsIgnoreCase("hide ")) {
                EnterExitNotify(r, p);
            }
        } else {
            RegionFlags(r, null, p);
        }
    } else {
        // if (r == null) >>
        if (Ownerslist.get(p) != null) {
            Region er = RedProtect.get().rm.getRegion(Ownerslist.get(p), p.getWorld());
            if (Ownerslist.containsKey(p)) {
                Ownerslist.remove(p);
            }
            // Execute listener:
            EnterExitRegionEvent event = new EnterExitRegionEvent(er, null, p);
            if (Sponge.getEventManager().post(event)) {
                return;
            }
            // ---
            if (er == null) {
                // remove all if no regions
                List<String> toRemove = new ArrayList<>();
                for (String taskId : PlayertaskID.keySet()) {
                    if (PlayertaskID.get(taskId).equals(p.getName())) {
                        if (taskId.contains("forcefly")) {
                            p.offer(Keys.CAN_FLY, false);
                            p.offer(Keys.IS_FLYING, false);
                        } else {
                            p.remove(Keys.POTION_EFFECTS);
                        }
                        toRemove.add(taskId);
                        stopTaskPlayer(taskId);
                    }
                }
                for (String key : toRemove) {
                    PlayertaskID.remove(key);
                }
            } else {
                noRegionFlags(er, p);
                if (!er.getWelcome().equalsIgnoreCase("hide ") && RedProtect.get().cfgs.getBool("notify.region-exit")) {
                    SendNotifyMsg(p, RPLang.get("playerlistener.region.wilderness"));
                }
            }
        }
    }
}
Also used : Entity(org.spongepowered.api.entity.Entity) Player(org.spongepowered.api.entity.living.player.Player) PotionEffect(org.spongepowered.api.effect.potion.PotionEffect) World(org.spongepowered.api.world.World) EntitySnapshot(org.spongepowered.api.entity.EntitySnapshot) Region(br.net.fabiozumbi12.RedProtect.Sponge.Region) EnterExitRegionEvent(br.net.fabiozumbi12.RedProtect.Sponge.events.EnterExitRegionEvent) Listener(org.spongepowered.api.event.Listener)

Example 3 with EntitySnapshot

use of org.spongepowered.api.entity.EntitySnapshot in project SpongeAPI by SpongePowered.

the class AbstractAffectEntityEvent method getEntitySnapshots.

@Override
public List<EntitySnapshot> getEntitySnapshots() {
    if (this.entitySnapshots == null) {
        if (this.currentOrder == Order.PRE) {
            ImmutableList.Builder<EntitySnapshot> builder = ImmutableList.builder();
            for (Entity entity : this.entities) {
                builder.add(entity.createSnapshot());
            }
            this.entitySnapshots = builder.build();
        } else {
            throw new IllegalStateException("Can't initialize entity snapshots after PRE!");
        }
    }
    return this.entitySnapshots;
}
Also used : Entity(org.spongepowered.api.entity.Entity) EntitySnapshot(org.spongepowered.api.entity.EntitySnapshot) ImmutableList(com.google.common.collect.ImmutableList)

Example 4 with EntitySnapshot

use of org.spongepowered.api.entity.EntitySnapshot in project SpongeCommon by SpongePowered.

the class VehicleDataProcessor method remove.

@Override
public DataTransactionResult remove(DataHolder dataHolder) {
    if (supports(dataHolder)) {
        net.minecraft.entity.Entity entity = ((net.minecraft.entity.Entity) dataHolder);
        if (entity.ridingEntity != null) {
            final EntitySnapshot previousVehicle = ((Entity) entity.getRidingEntity()).createSnapshot();
            entity.dismountRidingEntity();
            return DataTransactionResult.successResult(new ImmutableSpongeValue<>(Keys.VEHICLE, previousVehicle));
        }
        return DataTransactionResult.builder().result(DataTransactionResult.Type.SUCCESS).build();
    }
    return DataTransactionResult.failNoData();
}
Also used : Entity(org.spongepowered.api.entity.Entity) EntitySnapshot(org.spongepowered.api.entity.EntitySnapshot)

Example 5 with EntitySnapshot

use of org.spongepowered.api.entity.EntitySnapshot in project SpongeCommon by SpongePowered.

the class VehicleDataProcessor method fill.

@Override
public Optional<VehicleData> fill(DataContainer container, final VehicleData vehicleData) {
    if (!container.contains(Keys.VEHICLE.getQuery(), Keys.BASE_VEHICLE.getQuery())) {
        return Optional.empty();
    }
    EntitySnapshot vehicle = container.getSerializable(Keys.VEHICLE.getQuery(), EntitySnapshot.class).get();
    EntitySnapshot baseVehicle = container.getSerializable(Keys.BASE_VEHICLE.getQuery(), EntitySnapshot.class).get();
    return Optional.of(vehicleData.set(Keys.VEHICLE, vehicle).set(Keys.BASE_VEHICLE, baseVehicle));
}
Also used : EntitySnapshot(org.spongepowered.api.entity.EntitySnapshot)

Aggregations

EntitySnapshot (org.spongepowered.api.entity.EntitySnapshot)8 Entity (org.spongepowered.api.entity.Entity)5 Listener (org.spongepowered.api.event.Listener)2 ItemStackSnapshot (org.spongepowered.api.item.inventory.ItemStackSnapshot)2 Region (br.net.fabiozumbi12.RedProtect.Sponge.Region)1 EnterExitRegionEvent (br.net.fabiozumbi12.RedProtect.Sponge.events.EnterExitRegionEvent)1 ImmutableList (com.google.common.collect.ImmutableList)1 Optional (java.util.Optional)1 EntityLivingBase (net.minecraft.entity.EntityLivingBase)1 Action (org.cubeengine.module.vigil.report.Action)1 PotionEffect (org.spongepowered.api.effect.potion.PotionEffect)1 Living (org.spongepowered.api.entity.living.Living)1 Player (org.spongepowered.api.entity.living.player.Player)1 ItemStack (org.spongepowered.api.item.inventory.ItemStack)1 Text (org.spongepowered.api.text.Text)1 TextActions.showText (org.spongepowered.api.text.action.TextActions.showText)1 World (org.spongepowered.api.world.World)1 IMixinEntityLivingBase (org.spongepowered.common.interfaces.entity.IMixinEntityLivingBase)1