Search in sources :

Example 56 with Location

use of org.spongepowered.api.world.Location in project modules-extra by CubeEngine.

the class ListenerHanging method onHangingBreak.

@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onHangingBreak(HangingBreakEvent event) {
    if (event.getCause() == HangingBreakEvent.RemoveCause.PHYSICS) {
        Hanging hanging = event.getEntity();
        Location location = hanging.getLocation();
        BaseAction cause = this.plannedHangingBreak.get(location);
        if (cause != null) {
            if (cause instanceof ActionPlayerBlock) {
                HangingBreak action;
                if (hanging instanceof ItemFrame) {
                    action = this.newAction(ItemframeBreak.class, location.getWorld());
                    ItemStack item = ((ItemFrame) hanging).getItem();
                    if (action != null && item != null) {
                        ((ItemframeBreak) action).item = item;
                    }
                } else if (hanging instanceof Painting) {
                    action = this.newAction(PaintingBreak.class, location.getWorld());
                    ((PaintingBreak) action).art = ((Painting) hanging).getArt();
                } else {
                    action = this.newAction(HangingBreak.class, location.getWorld());
                }
                if (action != null) {
                    action.setLocation(location);
                    action.setHanging(hanging);
                    action.player = ((ActionPlayerBlock) cause).player;
                    action.setCause(cause);
                    this.logAction(action);
                }
            }
        // else // TODO
        }
    // else TODO this.module.getLog().info("Unexpected HangingBreakEvent");
    }
}
Also used : ActionPlayerBlock(org.cubeengine.module.log.action.block.player.ActionPlayerBlock) Hanging(org.bukkit.entity.Hanging) BaseAction(org.cubeengine.module.log.action.BaseAction) ItemFrame(org.bukkit.entity.ItemFrame) ItemStack(org.spongepowered.api.item.inventory.ItemStack) Location(org.spongepowered.api.world.Location) Painting(org.bukkit.entity.Painting) EventHandler(org.bukkit.event.EventHandler)

Example 57 with Location

use of org.spongepowered.api.world.Location in project modules-extra by CubeEngine.

the class ListenerHanging method onHangingBreakByEntity.

@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onHangingBreakByEntity(HangingBreakByEntityEvent event) {
    Entity causer;
    if (event.getRemover() instanceof Projectile) {
        ProjectileSource shooter = ((Projectile) event.getRemover()).getShooter();
        if (shooter instanceof Entity) {
            causer = (Entity) shooter;
        } else {
            // TODO other ProjectileSources
            return;
        }
    } else {
        causer = event.getRemover();
    }
    Hanging hanging = event.getEntity();
    Location location = hanging.getLocation();
    if (causer instanceof Player) {
        HangingBreak action;
        if (hanging instanceof ItemFrame) {
            action = this.newAction(ItemframeBreak.class, location.getWorld());
            ItemStack item = ((ItemFrame) hanging).getItem();
            if (action != null && item != null) {
                ((ItemframeBreak) action).item = item;
            }
        } else if (hanging instanceof Painting) {
            action = this.newAction(PaintingBreak.class, location.getWorld());
            if (action != null) {
                ((PaintingBreak) action).art = ((Painting) hanging).getArt();
            }
        } else {
            action = this.newAction(HangingBreak.class, location.getWorld());
        }
        if (action != null) {
            action.setLocation(location);
            action.setHanging(hanging);
            action.setPlayer((Player) causer);
            this.logAction(action);
        }
    } else {
    // TODO
    }
}
Also used : Entity(org.spongepowered.api.entity.Entity) Player(org.spongepowered.api.entity.player.Player) Hanging(org.bukkit.entity.Hanging) ProjectileSource(org.bukkit.projectiles.ProjectileSource) ItemFrame(org.bukkit.entity.ItemFrame) ItemStack(org.spongepowered.api.item.inventory.ItemStack) Projectile(org.bukkit.entity.Projectile) Location(org.spongepowered.api.world.Location) Painting(org.bukkit.entity.Painting) EventHandler(org.bukkit.event.EventHandler)

Example 58 with Location

use of org.spongepowered.api.world.Location in project modules-extra by CubeEngine.

the class PlayerActionListener method onTeleport.

@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onTeleport(PlayerTeleportEvent event) {
    Location from = event.getFrom();
    Location to = event.getTo();
    PlayerTeleport action = this.newAction(PlayerTeleport.class, from.getWorld());
    if (action != null) {
        action.setLocation(from);
        action.setOtherLocation(to, true);
        action.setPlayer(event.getPlayer());
        this.logAction(action);
    }
    PlayerTeleport action2 = this.newAction(PlayerTeleport.class, to.getWorld());
    if (action2 != null) {
        action2.setLocation(to);
        action2.setOtherLocation(from, false);
        action2.setPlayer(event.getPlayer());
        this.logAction(action2);
    }
}
Also used : Location(org.spongepowered.api.world.Location) EventHandler(org.bukkit.event.EventHandler)

Example 59 with Location

use of org.spongepowered.api.world.Location in project SpongeAPI by SpongePowered.

the class ChildCommandElementExecutor method complete.

@Override
public List<String> complete(final CommandSource src, CommandArgs args, CommandContext context) {
    List<String> completions = Lists.newArrayList();
    if (this.fallbackElements != null) {
        Object state = args.getState();
        completions.addAll(this.fallbackElements.complete(src, args, context));
        args.setState(state);
    }
    final Optional<String> commandComponent = args.nextIfPresent();
    if (!commandComponent.isPresent()) {
        return ImmutableList.copyOf(filterCommands(src));
    }
    if (args.hasNext()) {
        Optional<CommandMapping> child = this.dispatcher.get(commandComponent.get(), src);
        if (!child.isPresent()) {
            return ImmutableList.of();
        }
        if (child.get().getCallable() instanceof CommandSpec) {
            return ((CommandSpec) child.get().getCallable()).complete(src, args, context);
        }
        args.nextIfPresent();
        final String arguments = args.getRaw().substring(args.getRawPosition());
        while (args.hasNext()) {
            args.nextIfPresent();
        }
        try {
            return child.get().getCallable().getSuggestions(src, arguments, context.<Location<World>>getOne(CommandContext.TARGET_BLOCK_ARG).orElse(null));
        } catch (CommandException e) {
            Text eText = e.getText();
            if (eText != null) {
                src.sendMessage(error(eText));
            }
            return ImmutableList.of();
        }
    }
    completions.addAll(filterCommands(src).stream().filter(new StartsWithPredicate(commandComponent.get())).collect(ImmutableList.toImmutableList()));
    return completions;
}
Also used : CommandSpec(org.spongepowered.api.command.spec.CommandSpec) CommandMapping(org.spongepowered.api.command.CommandMapping) Text(org.spongepowered.api.text.Text) CommandException(org.spongepowered.api.command.CommandException) StartsWithPredicate(org.spongepowered.api.util.StartsWithPredicate) Location(org.spongepowered.api.world.Location)

Example 60 with Location

use of org.spongepowered.api.world.Location in project Nucleus by NucleusPowered.

the class JailHandler method unjailPlayer.

public boolean unjailPlayer(User user, Cause cause) {
    final ModularUserService modularUserService = plugin.getUserDataManager().getUnchecked(user);
    final JailUserDataModule jailUserDataModule = modularUserService.get(JailUserDataModule.class);
    Optional<JailData> ojd = jailUserDataModule.getJailData();
    if (!ojd.isPresent()) {
        return false;
    }
    Optional<Location<World>> ow = ojd.get().getPreviousLocation();
    jailDataCache.put(user.getUniqueId(), null);
    if (user.isOnline()) {
        Player player = user.getPlayer().get();
        Sponge.getScheduler().createSyncExecutor(plugin).execute(() -> {
            NucleusTeleportHandler.setLocation(player, ow.orElseGet(() -> player.getWorld().getSpawnLocation()));
            player.sendMessage(NucleusPlugin.getNucleus().getMessageProvider().getTextMessageWithFormat("jail.elapsed"));
            // Remove after the teleport for the back data.
            jailUserDataModule.removeJailData();
        });
    } else {
        modularUserService.get(CoreUserDataModule.class).sendToLocationOnLogin(ow.orElseGet(() -> new Location<>(Sponge.getServer().getWorld(Sponge.getServer().getDefaultWorld().get().getUniqueId()).get(), Sponge.getServer().getDefaultWorld().get().getSpawnPosition())));
        jailUserDataModule.removeJailData();
    }
    Sponge.getEventManager().post(new JailEvent.Unjailed(user, cause));
    return true;
}
Also used : Player(org.spongepowered.api.entity.living.player.Player) JailData(io.github.nucleuspowered.nucleus.modules.jail.data.JailData) JailEvent(io.github.nucleuspowered.nucleus.modules.jail.events.JailEvent) ModularUserService(io.github.nucleuspowered.nucleus.dataservices.modular.ModularUserService) JailUserDataModule(io.github.nucleuspowered.nucleus.modules.jail.datamodules.JailUserDataModule) CoreUserDataModule(io.github.nucleuspowered.nucleus.modules.core.datamodules.CoreUserDataModule) Location(org.spongepowered.api.world.Location) NamedLocation(io.github.nucleuspowered.nucleus.api.nucleusdata.NamedLocation)

Aggregations

Location (org.spongepowered.api.world.Location)166 World (org.spongepowered.api.world.World)96 Listener (org.spongepowered.api.event.Listener)44 Player (org.spongepowered.api.entity.living.player.Player)40 Vector3d (com.flowpowered.math.vector.Vector3d)38 BlockSnapshot (org.spongepowered.api.block.BlockSnapshot)32 Vector3i (com.flowpowered.math.vector.Vector3i)31 Optional (java.util.Optional)28 Entity (org.spongepowered.api.entity.Entity)27 BlockType (org.spongepowered.api.block.BlockType)24 BlockState (org.spongepowered.api.block.BlockState)23 ItemStack (org.spongepowered.api.item.inventory.ItemStack)23 Direction (org.spongepowered.api.util.Direction)21 ArrayList (java.util.ArrayList)20 Keys (org.spongepowered.api.data.key.Keys)20 List (java.util.List)19 Text (org.spongepowered.api.text.Text)19 BlockPos (net.minecraft.util.math.BlockPos)18 Sponge (org.spongepowered.api.Sponge)15 Map (java.util.Map)14