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