Java Code Examples for org.spongepowered.api.event.Order#FIRST
The following examples show how to use
org.spongepowered.api.event.Order#FIRST .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PlayerEventHandler.java From GriefPrevention with MIT License | 6 votes |
@Listener(order = Order.FIRST, beforeModifications = true) public void onPlayerInteractInventoryClose(InteractInventoryEvent.Close event, @Root Player player) { final ItemStackSnapshot cursor = event.getCursorTransaction().getOriginal(); if (cursor == ItemStackSnapshot.NONE || !GPFlags.ITEM_DROP || !GriefPreventionPlugin.instance.claimsEnabledForWorld(player.getWorld().getProperties())) { return; } if (GriefPreventionPlugin.isTargetIdBlacklisted(ClaimFlag.ITEM_DROP.toString(), cursor, player.getWorld().getProperties())) { return; } GPTimings.PLAYER_INTERACT_INVENTORY_CLOSE_EVENT.startTimingIfSync(); final Location<World> location = player.getLocation(); final GPClaim claim = this.dataStore.getClaimAt(location); if (GPPermissionHandler.getClaimPermission(event, location, claim, GPPermissions.ITEM_DROP, player, cursor, player, TrustType.ACCESSOR, true) == Tristate.FALSE) { Text message = GriefPreventionPlugin.instance.messageData.permissionItemDrop .apply(ImmutableMap.of( "owner", claim.getOwnerName(), "item", cursor.getType().getId())).build(); GriefPreventionPlugin.sendClaimDenyMessage(claim, player, message); event.setCancelled(true); } GPTimings.PLAYER_INTERACT_INVENTORY_CLOSE_EVENT.stopTimingIfSync(); }
Example 2
Source File: BlockListener.java From RedProtect with GNU General Public License v3.0 | 6 votes |
@Listener(order = Order.FIRST, beforeModifications = true) public void onInteractBlock(InteractBlockEvent event, @First Player p) { BlockSnapshot b = event.getTargetBlock(); Location<World> l; RedProtect.get().logger.debug(LogLevel.PLAYER, "BlockListener - Is InteractBlockEvent event"); if (!b.getState().getType().equals(BlockTypes.AIR)) { l = b.getLocation().get(); RedProtect.get().logger.debug(LogLevel.PLAYER, "BlockListener - Is InteractBlockEvent event. The block is " + b.getState().getType().getName()); } else { l = p.getLocation(); } Region r = RedProtect.get().rm.getTopRegion(l, this.getClass().getName()); if (r != null) { ItemType itemInHand = RedProtect.get().getVersionHelper().getItemInHand(p); if (itemInHand.equals(ItemTypes.ARMOR_STAND) && !r.canBuild(p)) { RedProtect.get().lang.sendMessage(p, "blocklistener.region.cantbuild"); event.setCancelled(true); } } }
Example 3
Source File: InteractPermListener.java From Nations with MIT License | 6 votes |
@Listener(order=Order.FIRST, beforeModifications = true) public void onInteract(InteractBlockEvent event, @First Player player) { if (!ConfigHandler.getNode("worlds").getNode(player.getWorld().getName()).getNode("enabled").getBoolean()) { return; } if (player.hasPermission("nations.admin.bypass.perm.interact")) { return; } Optional<ItemStack> optItem = player.getItemInHand(HandTypes.MAIN_HAND); if (optItem.isPresent() && (ConfigHandler.isWhitelisted("use", optItem.get().getItem().getId()) || optItem.get().getItem().equals(ItemTypes.GOLDEN_AXE) && ConfigHandler.getNode("others", "enableGoldenAxe").getBoolean(true))) return; event.getTargetBlock().getLocation().ifPresent(loc -> { if (!DataHandler.getPerm("interact", player.getUniqueId(), loc)) { event.setCancelled(true); if (loc.getBlockType() != BlockTypes.STANDING_SIGN && loc.getBlockType() != BlockTypes.WALL_SIGN) player.sendMessage(Text.of(TextColors.RED, LanguageHandler.ERROR_PERM_INTERACT)); } }); }
Example 4
Source File: PlayerListener.java From RedProtect with GNU General Public License v3.0 | 6 votes |
@Listener(order = Order.FIRST, beforeModifications = true) public void onPlayerHarvest(HarvestEntityEvent.TargetPlayer e) { RedProtect.get().logger.debug(LogLevel.PLAYER, "RPLayerListener: Is HarvestEntityEvent"); Player p = e.getTargetEntity(); Region r = RedProtect.get().rm.getTopRegion(p.getLocation(), this.getClass().getName()); if (r != null) { if (r.keepInventory()) { e.setKeepsInventory(true); } if (r.keepLevels()) { e.setKeepsLevel(true); } } }
Example 5
Source File: PlayerEventHandler.java From GriefDefender with MIT License | 6 votes |
@Listener(order = Order.FIRST, beforeModifications = true) public void onPlayerDeath(DestructEntityEvent.Death event) { if (!(event.getTargetEntity() instanceof Player)) { return; } final Player player = (Player) event.getTargetEntity(); GDCauseStackManager.getInstance().pushCause(player); final GDPlayerData playerData = GriefDefenderPlugin.getInstance().dataStore.getOrCreatePlayerData(player.getWorld(), player.getUniqueId()); final GDClaim claim = GriefDefenderPlugin.getInstance().dataStore.getClaimAtPlayer(playerData, player.getLocation()); Tristate keepInventory = Tristate.UNDEFINED; if (GDOptions.isOptionEnabled(Options.PLAYER_KEEP_INVENTORY)) { keepInventory = GDPermissionManager.getInstance().getInternalOptionValue(TypeToken.of(Tristate.class), playerData.getSubject(), Options.PLAYER_KEEP_INVENTORY, claim); } if (keepInventory != Tristate.UNDEFINED) { event.setKeepInventory(keepInventory.asBoolean()); } /*Tristate keepLevel = Tristate.UNDEFINED; if (GDOptions.isOptionEnabled(Options.PLAYER_KEEP_LEVEL)) { keepLevel = GDPermissionManager.getInstance().getInternalOptionValue(TypeToken.of(Tristate.class), playerData.getSubject(), Options.PLAYER_KEEP_LEVEL, claim); } if (keepLevel != Tristate.UNDEFINED) { event.setKeepLevel(keepLevel.asBoolean()); }*/ }
Example 6
Source File: BlockListener.java From RedProtect with GNU General Public License v3.0 | 5 votes |
@Listener(order = Order.FIRST, beforeModifications = true) public void onLightning(LightningEvent.Pre e, @First Lightning light) { RedProtect.get().logger.debug(LogLevel.BLOCKS, "Is LightningStrikeEvent event"); Location<World> l = light.getLocation(); Region r = RedProtect.get().rm.getTopRegion(l, this.getClass().getName()); if (r != null && !r.canFire()) { e.setCancelled(true); } }
Example 7
Source File: BuildPermListener.java From Nations with MIT License | 5 votes |
@Listener(order=Order.FIRST, beforeModifications = true) public void onPlayerBreaksBlock(ChangeBlockEvent.Break event) { User user = Utils.getUser(event); if (user != null && user.hasPermission("nations.admin.bypass.perm.build")) { return; } event .getTransactions() .stream() .forEach(trans -> trans.getOriginal().getLocation().ifPresent(loc -> { if (!ConfigHandler.isWhitelisted("break", trans.getFinal().getState().getType().getId()) && ConfigHandler.getNode("worlds").getNode(trans.getFinal().getLocation().get().getExtent().getName()).getNode("enabled").getBoolean()) { if (user == null || !DataHandler.getPerm("build", user.getUniqueId(), loc)) { trans.setValid(false); if (user != null && user instanceof Player) { try { ((Player) user).sendMessage(Text.of(TextColors.RED, LanguageHandler.ERROR_PERM_BUILD)); } catch (Exception e) {} } } } })); }
Example 8
Source File: PlayerListener.java From RedProtect with GNU General Public License v3.0 | 5 votes |
@Listener(order = Order.FIRST, beforeModifications = true) public void PlayerDropItemGui(DropItemEvent.Pre e, @Root Player p) { e.getDroppedItems().forEach(item -> { if (RedProtect.get().getUtil().isGuiItem(item.createStack())) { RedProtect.get().getVersionHelper().removeGuiItem(p); e.setCancelled(true); } }); }
Example 9
Source File: PlayerEventHandler.java From GriefPrevention with MIT License | 5 votes |
@Listener(order = Order.FIRST, beforeModifications = true) public void onPlayerInteractEntity(InteractEntityEvent.Primary event, @First Player player) { if (!GPFlags.INTERACT_ENTITY_PRIMARY || !GriefPreventionPlugin.instance.claimsEnabledForWorld(player.getWorld().getProperties())) { return; } final Entity targetEntity = event.getTargetEntity(); final HandType handType = event.getHandType(); final ItemStack itemInHand = player.getItemInHand(handType).orElse(ItemStack.empty()); final Object source = !itemInHand.isEmpty() ? itemInHand : player; if (GriefPreventionPlugin.isTargetIdBlacklisted(ClaimFlag.INTERACT_ENTITY_PRIMARY.toString(), targetEntity, player.getWorld().getProperties())) { return; } GPTimings.PLAYER_INTERACT_ENTITY_PRIMARY_EVENT.startTimingIfSync(); Location<World> location = targetEntity.getLocation(); GPClaim claim = this.dataStore.getClaimAt(location); if (event.isCancelled() && claim.getData().getPvpOverride() == Tristate.TRUE && targetEntity instanceof Player) { event.setCancelled(false); } Tristate result = GPPermissionHandler.getClaimPermission(event, location, claim, GPPermissions.INTERACT_ENTITY_PRIMARY, source, targetEntity, player, TrustType.ACCESSOR, true); if (result == Tristate.FALSE) { final Text message = GriefPreventionPlugin.instance.messageData.claimProtectedEntity .apply(ImmutableMap.of( "owner", claim.getOwnerName())).build(); GriefPreventionPlugin.sendMessage(player, message); event.setCancelled(true); this.sendInteractEntityDenyMessage(itemInHand, targetEntity, claim, player, handType); GPTimings.PLAYER_INTERACT_ENTITY_PRIMARY_EVENT.stopTimingIfSync(); return; } }
Example 10
Source File: PlayerListener.java From RedProtect with GNU General Public License v3.0 | 5 votes |
@Listener(order = Order.FIRST, beforeModifications = true) public void PlayerDropItem(DropItemEvent.Dispense e, @Root Player p) { RedProtect.get().logger.debug(LogLevel.PLAYER, "Is DropItemEvent.Dispense event."); for (Entity ent : e.getEntities()) { Location<World> l = ent.getLocation(); Region r = RedProtect.get().rm.getTopRegion(l, this.getClass().getName()); if (r != null && ((!r.canExit(p) && !r.canDrop(p)) || !r.canDrop(p))) { e.setCancelled(true); RedProtect.get().lang.sendMessage(p, "playerlistener.region.cantdrop"); } } }
Example 11
Source File: PreventListener.java From FlexibleLogin with MIT License | 5 votes |
@Listener(order = Order.FIRST, beforeModifications = true) public void onPlayerMove(MoveEntityEvent playerMoveEvent, @First Player player) { if (playerMoveEvent instanceof MoveEntityEvent.Teleport) { return; } Vector3i oldLocation = playerMoveEvent.getFromTransform().getPosition().toInt(); Vector3i newLocation = playerMoveEvent.getToTransform().getPosition().toInt(); if (oldLocation.getX() != newLocation.getX() || oldLocation.getZ() != newLocation.getZ()) { checkLoginStatus(playerMoveEvent, player); } }
Example 12
Source File: PlayerEventHandler.java From GriefDefender with MIT License | 5 votes |
@Listener(order = Order.FIRST, beforeModifications = true) public void onPlayerRespawn(RespawnPlayerEvent event) { final World world = event.getToTransform().getExtent(); if (!GriefDefenderPlugin.getInstance().claimsEnabledForWorld(world.getUniqueId())) { return; } final GDPlayerData playerData = GriefDefenderPlugin.getInstance().dataStore.getOrCreatePlayerData(event.getTargetEntity().getWorld(), event.getTargetEntity().getUniqueId()); playerData.lastPvpTimestamp = null; }
Example 13
Source File: BlockListener.java From RedProtect with GNU General Public License v3.0 | 5 votes |
@Listener(order = Order.FIRST, beforeModifications = true) public void onBlockGrow(ChangeBlockEvent.Grow e) { RedProtect.get().logger.debug(LogLevel.BLOCKS, "BlockListener - Is ChangeBlockEvent.Grow event"); BlockSnapshot b = e.getTransactions().get(0).getOriginal(); Region r = RedProtect.get().rm.getTopRegion(b.getLocation().get(), this.getClass().getName()); if (r != null && !r.canGrow()) { e.setCancelled(true); RedProtect.get().logger.debug(LogLevel.BLOCKS, "Cancel grow " + b.getState().getName()); } }
Example 14
Source File: EntityListener.java From RedProtect with GNU General Public License v3.0 | 5 votes |
@Listener(order = Order.FIRST, beforeModifications = true) public void onAttemptInteractAS(InteractEntityEvent e, @First Player p) { Entity ent = e.getTargetEntity(); Location<World> l = ent.getLocation(); Region r = RedProtect.get().rm.getTopRegion(l, this.getClass().getName()); if (r == null) { //global flags if (ent.getType().equals(EntityTypes.ARMOR_STAND)) { if (!RedProtect.get().config.globalFlagsRoot().worlds.get(l.getExtent().getName()).build) { e.setCancelled(true); return; } } return; } ItemType itemInHand = RedProtect.get().getVersionHelper().getItemInHand(p); if (!itemInHand.equals(ItemTypes.NONE) && itemInHand.getType().equals(ItemTypes.ARMOR_STAND)) { if (!r.canBuild(p)) { e.setCancelled(true); RedProtect.get().lang.sendMessage(p, "blocklistener.region.cantbuild"); return; } } //TODO Not working! if (ent.getType().equals(EntityTypes.ARMOR_STAND)) { if (!r.canBuild(p)) { if (!RedProtect.get().ph.hasPerm(p, "redprotect.bypass")) { RedProtect.get().lang.sendMessage(p, "playerlistener.region.cantedit"); e.setCancelled(true); } } } }
Example 15
Source File: BlockListener.java From RedProtect with GNU General Public License v3.0 | 5 votes |
@Listener(order = Order.FIRST, beforeModifications = true) public void onBlockStartBurn(IgniteEntityEvent e) { Entity b = e.getTargetEntity(); Cause ignit = e.getCause(); RedProtect.get().logger.debug(LogLevel.BLOCKS, "Is BlockIgniteEvent event."); Region r = RedProtect.get().rm.getTopRegion(b.getLocation(), this.getClass().getName()); if (r != null && !r.canFire()) { if (ignit.first(Player.class).isPresent()) { Player p = ignit.first(Player.class).get(); if (!r.canBuild(p)) { RedProtect.get().lang.sendMessage(p, "blocklistener.region.cantplace"); e.setCancelled(true); return; } } else { e.setCancelled(true); return; } if (ignit.first(BlockSnapshot.class).isPresent() && (ignit.first(BlockSnapshot.class).get().getState().getType().equals(BlockTypes.FIRE) || ignit.first(BlockSnapshot.class).get().getState().getType().getName().contains("lava"))) { e.setCancelled(true); return; } if (ignit.first(Lightning.class).isPresent() || ignit.first(Explosion.class).isPresent() || ignit.first(Fireball.class).isPresent()) { e.setCancelled(true); } } }
Example 16
Source File: PreventListener.java From FlexibleLogin with MIT License | 4 votes |
@Listener(order = Order.FIRST, beforeModifications = true) public void onPlayerInteractEntity(InteractEntityEvent interactEntityEvent, @First Player player) { checkLoginStatus(interactEntityEvent, player); }
Example 17
Source File: PreventListener.java From FlexibleLogin with MIT License | 4 votes |
@Listener(order = Order.FIRST, beforeModifications = true) public void onDamagePlayer(DamageEntityEvent damageEntityEvent, @Getter("getTargetEntity") Player player) { //player is damage target checkLoginStatus(damageEntityEvent, player); }
Example 18
Source File: BlockEventHandler.java From GriefPrevention with MIT License | 4 votes |
@Listener(order = Order.FIRST, beforeModifications = true) public void onSignChanged(ChangeSignEvent event) { final User user = CauseContextHelper.getEventUser(event); if (user == null) { return; } if (!GriefPreventionPlugin.instance.claimsEnabledForWorld(event.getTargetTile().getLocation().getExtent().getProperties())) { return; } GPTimings.SIGN_CHANGE_EVENT.startTimingIfSync(); Location<World> location = event.getTargetTile().getLocation(); // Prevent users exploiting signs GPClaim claim = GriefPreventionPlugin.instance.dataStore.getClaimAt(location); if (GPPermissionHandler.getClaimPermission(event, location, claim, GPPermissions.INTERACT_BLOCK_SECONDARY, user, location.getBlock(), user, TrustType.ACCESSOR, true) == Tristate.FALSE) { if (user instanceof Player) { event.setCancelled(true); final Text message = GriefPreventionPlugin.instance.messageData.permissionAccess .apply(ImmutableMap.of( "player", Text.of(claim.getOwnerName()))).build(); GriefPreventionPlugin.sendClaimDenyMessage(claim, (Player) user, message); return; } } // send sign content to online administrators if (!GriefPreventionPlugin.getActiveConfig(location.getExtent().getProperties()) .getConfig().general.generalAdminSignNotifications) { GPTimings.SIGN_CHANGE_EVENT.stopTimingIfSync(); return; } World world = location.getExtent(); StringBuilder lines = new StringBuilder(" placed a sign @ " + GriefPreventionPlugin.getfriendlyLocationString(event.getTargetTile().getLocation())); boolean notEmpty = false; for (int i = 0; i < event.getText().lines().size(); i++) { String withoutSpaces = Text.of(event.getText().lines().get(i)).toPlain().replace(" ", ""); if (!withoutSpaces.isEmpty()) { notEmpty = true; lines.append("\n " + event.getText().lines().get(i)); } } String signMessage = lines.toString(); // prevent signs with blocked IP addresses if (!user.hasPermission(GPPermissions.OVERRIDE_SPAM) && GriefPreventionPlugin.instance.containsBlockedIP(signMessage)) { event.setCancelled(true); GPTimings.SIGN_CHANGE_EVENT.stopTimingIfSync(); return; } // if not empty and wasn't the same as the last sign, log it and remember it for later GPPlayerData playerData = this.dataStore.getOrCreatePlayerData(world, user.getUniqueId()); if (notEmpty && playerData.lastMessage != null && !playerData.lastMessage.equals(signMessage)) { GriefPreventionPlugin.addLogEntry(user.getName() + lines.toString().replace("\n ", ";"), null); //PlayerEventHandler.makeSocialLogEntry(player.get().getName(), signMessage); playerData.lastMessage = signMessage; if (!user.hasPermission(GPPermissions.EAVES_DROP_SIGNS)) { Collection<Player> players = (Collection<Player>) Sponge.getGame().getServer().getOnlinePlayers(); for (Player otherPlayer : players) { if (otherPlayer.hasPermission(GPPermissions.EAVES_DROP_SIGNS)) { otherPlayer.sendMessage(Text.of(TextColors.GRAY, user.getName(), signMessage)); } } } } GPTimings.SIGN_CHANGE_EVENT.stopTimingIfSync(); }
Example 19
Source File: BlockEventHandler.java From GriefDefender with MIT License | 4 votes |
@Listener(order = Order.FIRST, beforeModifications = true) public void onExplosionDetonate(ExplosionEvent.Detonate event) { final World world = event.getExplosion().getWorld(); if (!GDFlags.EXPLOSION_BLOCK || !GriefDefenderPlugin.getInstance().claimsEnabledForWorld(world.getUniqueId())) { return; } Object source = event.getSource(); if (source instanceof Explosion) { final Explosion explosion = (Explosion) source; if (explosion.getSourceExplosive().isPresent()) { source = explosion.getSourceExplosive().get(); } else { Entity exploder = event.getCause().first(Entity.class).orElse(null); if (exploder != null) { source = exploder; } } } if (GriefDefenderPlugin.isSourceIdBlacklisted(Flags.EXPLOSION_BLOCK.getName(), source, event.getExplosion().getWorld().getProperties())) { return; } GDTimings.EXPLOSION_EVENT.startTimingIfSync(); final User user = CauseContextHelper.getEventUser(event); GDClaim targetClaim = null; final List<Location<World>> filteredLocations = new ArrayList<>(); final String sourceId = GDPermissionManager.getInstance().getPermissionIdentifier(source); final int cancelBlockLimit = GriefDefenderPlugin.getGlobalConfig().getConfig().claim.explosionCancelBlockLimit; boolean denySurfaceExplosion = GriefDefenderPlugin.getActiveConfig(world.getUniqueId()).getConfig().claim.explosionBlockSurfaceBlacklist.contains(sourceId); if (!denySurfaceExplosion) { denySurfaceExplosion = !GriefDefenderPlugin.getActiveConfig(world.getUniqueId()).getConfig().claim.explosionBlockSurfaceBlacklist.contains("any"); } for (Location<World> location : event.getAffectedLocations()) { targetClaim = GriefDefenderPlugin.getInstance().dataStore.getClaimAt(location, targetClaim); if (denySurfaceExplosion && world.getDimension().getType() != DimensionTypes.NETHER && location.getBlockY() >= world.getSeaLevel()) { filteredLocations.add(location); GDPermissionManager.getInstance().processEventLog(event, location, targetClaim, Flags.EXPLOSION_BLOCK.getPermission(), source, location.getBlock(), user, "explosion-surface", Tristate.FALSE); continue; } Tristate result = GDPermissionManager.getInstance().getFinalPermission(event, location, targetClaim, Flags.EXPLOSION_BLOCK, source, location.getBlock(), user, true); if (result == Tristate.FALSE) { // Avoid lagging server from large explosions. if (event.getAffectedLocations().size() > cancelBlockLimit) { event.setCancelled(true); break; } filteredLocations.add(location); } } // Workaround for SpongeForge bug if (event.isCancelled()) { event.getAffectedLocations().clear(); } else if (!filteredLocations.isEmpty()) { event.getAffectedLocations().removeAll(filteredLocations); } GDTimings.EXPLOSION_EVENT.stopTimingIfSync(); }
Example 20
Source File: ExplosionListener.java From EagleFactions with MIT License | 4 votes |
@Listener(order = Order.FIRST, beforeModifications = true) public void onExplosionPre(final ExplosionEvent.Pre event) { final EventContext context = event.getContext(); final Cause cause = event.getCause(); User user = null; if (cause.root() instanceof TileEntity) { user = context.get(EventContextKeys.OWNER) .orElse(context.get(EventContextKeys.NOTIFIER) .orElse(context.get(EventContextKeys.CREATOR) .orElse(null))); } else { user = context.get(EventContextKeys.NOTIFIER) .orElse(context.get(EventContextKeys.OWNER) .orElse(context.get(EventContextKeys.CREATOR) .orElse(null))); } if(event.getCause().containsType(Player.class)) { user = event.getCause().first(Player.class).get(); } else if(event.getCause().containsType(User.class)) { user = event.getCause().first(User.class).get(); } final Location<World> location = event.getExplosion().getLocation(); if (user == null) { if(!super.getPlugin().getProtectionManager().canExplode(location).hasAccess()) { event.setCancelled(true); return; } } else { if (!super.getPlugin().getProtectionManager().canExplode(location, user, false).hasAccess()) { event.setCancelled(true); return; } } }