org.spongepowered.api.event.Order Java Examples

The following examples show how to use org.spongepowered.api.event.Order. 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: BuildPermListener.java    From Nations with MIT License 6 votes vote down vote up
@Listener(order=Order.FIRST, beforeModifications = true)
public void onPlayerPlacesBlock(ChangeBlockEvent.Place event, @First Player player)
{
	if (player.hasPermission("nations.admin.bypass.perm.build"))
	{
		return;
	}
	event
	.getTransactions()
	.stream()
	.forEach(trans -> trans.getOriginal().getLocation().ifPresent(loc -> {
		if (ConfigHandler.getNode("worlds").getNode(trans.getFinal().getLocation().get().getExtent().getName()).getNode("enabled").getBoolean()
				&& !ConfigHandler.isWhitelisted("build", trans.getFinal().getState().getType().getId())
				&& !DataHandler.getPerm("build", player.getUniqueId(), loc))
		{
			trans.setValid(false);
			try {
				player.sendMessage(Text.of(TextColors.RED, LanguageHandler.ERROR_PERM_BUILD));
			} catch (Exception e) {}
		}
	}));
}
 
Example #2
Source File: PlayerListener.java    From RedProtect with GNU General Public License v3.0 6 votes vote down vote up
@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 #3
Source File: SignListener.java    From UltimateCore with MIT License 6 votes vote down vote up
@Listener(order = Order.EARLY)
public void onSignCreate(ChangeSignEvent event, @Root Player p) {
    //Sign colors
    List<Text> lines = event.getText().lines().get();
    lines.set(0, TextUtil.replaceColors(lines.get(0), p, "uc.sign"));
    lines.set(1, TextUtil.replaceColors(lines.get(1), p, "uc.sign"));
    lines.set(2, TextUtil.replaceColors(lines.get(2), p, "uc.sign"));
    lines.set(3, TextUtil.replaceColors(lines.get(3), p, "uc.sign"));
    event.getText().setElements(lines);

    //Registered signs
    for (UCSign sign : UltimateCore.get().getSignService().get().getRegisteredSigns()) {
        if (event.getText().get(0).orElse(Text.of()).toPlain().equalsIgnoreCase("[" + sign.getIdentifier() + "]")) {
            if (!p.hasPermission(sign.getCreatePermission().get())) {
                Messages.send(p, "core.nopermissions");
            }
            SignCreateEvent cevent = new SignCreateEvent(sign, event.getTargetTile().getLocation(), Cause.builder().append(UltimateCore.getContainer()).append(p).build(EventContext.builder().build()));
            Sponge.getEventManager().post(cevent);
            if (!cevent.isCancelled() && sign.onCreate(p, event)) {
                //Color sign
                event.getTargetTile().offer(Keys.SIGN_LINES, event.getText().setElement(0, Text.of(TextColors.AQUA, "[" + StringUtil.firstUpperCase(sign.getIdentifier()) + "]")).asList());
                Messages.send(p, "sign.create", "%sign%", sign.getIdentifier());
            }
        }
    }
}
 
Example #4
Source File: EntityListener.java    From RedProtect with GNU General Public License v3.0 6 votes vote down vote up
@Listener(order = Order.FIRST, beforeModifications = true)
public void onInteractEvent(InteractEntityEvent.Secondary e, @First Player p) {
    Entity et = e.getTargetEntity();
    Location<World> l = et.getLocation();
    Region r = RedProtect.get().rm.getTopRegion(l, this.getClass().getName());

    RedProtect.get().logger.debug(LogLevel.ENTITY, "EntityListener - InteractEntityEvent.Secondary entity " + et.getType().getName());

    if (r != null && !r.canInteractPassives(p) && (et instanceof Animal || et instanceof Villager || et instanceof Golem || et instanceof Ambient)) {
        if (RedProtect.get().getVersionHelper().checkHorseOwner(et, p)) {
            return;
        }
        e.setCancelled(true);
        RedProtect.get().lang.sendMessage(p, "entitylistener.region.cantinteract");
    }
}
 
Example #5
Source File: BuildPermListener.java    From Nations with MIT License 6 votes vote down vote up
@Listener(order = Order.FIRST, beforeModifications = true)
public void onSignChanged(ChangeSignEvent event, @First User player)
{
	if (!ConfigHandler.getNode("worlds").getNode(event.getTargetTile().getLocation().getExtent().getName()).getNode("enabled").getBoolean())
	{
		return;
	}
	if (player.hasPermission("nations.admin.bypass.perm.build"))
	{
		return;
	}
	if (!DataHandler.getPerm("build", player.getUniqueId(), event.getTargetTile().getLocation()))
	{
		event.setCancelled(true);
	}
}
 
Example #6
Source File: PlayerEventHandler.java    From GriefDefender with MIT License 6 votes vote down vote up
@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 #7
Source File: GlobalListener.java    From RedProtect with GNU General Public License v3.0 6 votes vote down vote up
@Listener(order = Order.FIRST, beforeModifications = true)
public void onFlow(ChangeBlockEvent.Pre e, @First LocatableBlock locatable) {
    RedProtect.get().logger.debug(LogLevel.BLOCKS, "Is BlockListener - onFlow event");

    BlockState sourceState = locatable.getBlockState();

    //liquid check
    MatterProperty mat = sourceState.getProperty(MatterProperty.class).orElse(null);
    if (mat != null && mat.getValue() == MatterProperty.Matter.LIQUID) {
        e.getLocations().forEach(loc -> {
            Region r = RedProtect.get().rm.getTopRegion(loc, this.getClass().getName());
            if (r == null) {
                boolean flow = RedProtect.get().config.globalFlagsRoot().worlds.get(locatable.getLocation().getExtent().getName()).allow_changes_of.liquid_flow;
                boolean allowWater = RedProtect.get().config.globalFlagsRoot().worlds.get(locatable.getLocation().getExtent().getName()).allow_changes_of.water_flow;
                boolean allowLava = RedProtect.get().config.globalFlagsRoot().worlds.get(locatable.getLocation().getExtent().getName()).allow_changes_of.lava_flow;

                if (!flow)
                    e.setCancelled(true);
                if (!allowWater && (loc.getBlockType() == BlockTypes.WATER || loc.getBlockType() == BlockTypes.FLOWING_WATER))
                    e.setCancelled(true);
                if (!allowLava && (loc.getBlockType() == BlockTypes.LAVA || loc.getBlockType() == BlockTypes.FLOWING_LAVA))
                    e.setCancelled(true);
            }
        });
    }
}
 
Example #8
Source File: DefaultListener.java    From UltimateCore with MIT License 6 votes vote down vote up
@Listener(order = Order.EARLY)
public void onJoin(ClientConnectionEvent.Join event) {
    Player p = event.getTargetEntity();

    //Player file
    PlayerDataFile config = new PlayerDataFile(event.getTargetEntity().getUniqueId());
    CommentedConfigurationNode node = config.get();
    node.getNode("lastconnect").setValue(System.currentTimeMillis());
    String ip = event.getTargetEntity().getConnection().getAddress().getAddress().toString().replace("/", "");
    node.getNode("lastip").setValue(ip);
    config.save(node);

    //Ipcache file
    GlobalDataFile file = new GlobalDataFile("ipcache");
    CommentedConfigurationNode node2 = file.get();
    node2.getNode(ip, "name").setValue(p.getName());
    node2.getNode(ip, "uuid").setValue(p.getUniqueId().toString());
    file.save(node2);
}
 
Example #9
Source File: PlayerEventHandler.java    From GriefDefender with MIT License 6 votes vote down vote up
@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 || !GDFlags.ITEM_DROP || !GriefDefenderPlugin.getInstance().claimsEnabledForWorld(player.getWorld().getUniqueId())) {
        return;
    }
    if (GriefDefenderPlugin.isTargetIdBlacklisted(Flags.ITEM_DROP.getName(), cursor, player.getWorld().getProperties())) {
        return;
    }

    GDTimings.PLAYER_INTERACT_INVENTORY_CLOSE_EVENT.startTimingIfSync();
    final Location<World> location = player.getLocation();
    final GDClaim claim = this.dataStore.getClaimAt(location);
    if (GDPermissionManager.getInstance().getFinalPermission(event, location, claim, Flags.ITEM_DROP, player, cursor, player, TrustTypes.ACCESSOR, true) == Tristate.FALSE) {
        final Component message = GriefDefenderPlugin.getInstance().messageData.getMessage(MessageStorage.PERMISSION_ITEM_DROP,
                ImmutableMap.of(
                "player", claim.getOwnerName(),
                "item", cursor.getType().getId()));
        GriefDefenderPlugin.sendClaimDenyMessage(claim, player, message);
        event.setCancelled(true);
    }

    GDTimings.PLAYER_INTERACT_INVENTORY_CLOSE_EVENT.stopTimingIfSync();
}
 
Example #10
Source File: PlayerDisconnectListener.java    From EagleFactions with MIT License 6 votes vote down vote up
@Listener(order = Order.POST)
public void onDisconnect(ClientConnectionEvent.Disconnect event, @Root Player player)
{
    if (super.getPlugin().getPVPLogger().isActive() && EagleFactionsPlugin.getPlugin().getPVPLogger().isPlayerBlocked(player))
    {
        player.damage(1000, DamageSource.builder().type(DamageTypes.ATTACK).build());
        super.getPlugin().getPVPLogger().removePlayer(player);
    }

    EagleFactionsPlugin.REGEN_CONFIRMATION_MAP.remove(player.getUniqueId());

    final Optional<Faction> optionalFaction = getPlugin().getFactionLogic().getFactionByPlayerUUID(player.getUniqueId());
    optionalFaction.ifPresent(faction -> getPlugin().getFactionLogic().setLastOnline(faction, Instant.now()));

    //TODO: Unload player cache...
    FactionsCache.removePlayer(player.getUniqueId());
}
 
Example #11
Source File: PlayerEventHandler.java    From GriefDefender with MIT License 6 votes vote down vote up
@Listener(order = Order.LAST, beforeModifications = true)
public void onPlayerPickupItem(ChangeInventoryEvent.Pickup.Pre event, @Root Player player) {
    if (!GDFlags.ITEM_PICKUP || !GriefDefenderPlugin.getInstance().claimsEnabledForWorld(player.getWorld().getUniqueId())) {
        return;
    }
    if (GriefDefenderPlugin.isTargetIdBlacklisted(Flags.ITEM_PICKUP.getName(), event.getTargetEntity(), player.getWorld().getProperties())) {
        return;
    }

    GDTimings.PLAYER_PICKUP_ITEM_EVENT.startTimingIfSync();
    final World world = player.getWorld();
    GDPlayerData playerData = this.dataStore.getOrCreatePlayerData(world, player.getUniqueId());
    Location<World> location = player.getLocation();
    GDClaim claim = this.dataStore.getClaimAtPlayer(playerData, location);
    if (GDPermissionManager.getInstance().getFinalPermission(event, location, claim, Flags.ITEM_PICKUP, player, event.getTargetEntity(), player, true) == Tristate.FALSE) {
        event.setCancelled(true);
    }

    GDTimings.PLAYER_PICKUP_ITEM_EVENT.stopTimingIfSync();
}
 
Example #12
Source File: EntityListener.java    From RedProtect with GNU General Public License v3.0 6 votes vote down vote up
@Listener(order = Order.FIRST, beforeModifications = true)
public void onBlockExplode(ExplosionEvent.Detonate e) {
    RedProtect.get().logger.debug(LogLevel.DEFAULT, "Is BlockListener - BlockExplodeEvent event");

    for (Location<World> bex : e.getAffectedLocations()) {
        Region r = RedProtect.get().rm.getTopRegion(bex, this.getClass().getName());
        if (!cont.canWorldBreak(bex.createSnapshot())) {
            e.setCancelled(true);
            return;
        }
        if (r != null && !r.canFire()) {
            e.setCancelled(true);
            return;
        }
    }
}
 
Example #13
Source File: BuildPermListener.java    From Nations with MIT License 6 votes vote down vote up
@Listener(order=Order.FIRST, beforeModifications = true)
public void onPlayerChangeBlock(ChangeBlockEvent.Pre event, @First Player player)
{
	if (player.hasPermission("nations.admin.bypass.perm.build"))
	{
		return;
	}
	if (Utils.isFakePlayer(event)) {
		return;
	}
	for (Location<World> loc : event.getLocations()) {
		if (ConfigHandler.getNode("worlds").getNode(loc.getExtent().getName()).getNode("enabled").getBoolean()
				&& !ConfigHandler.isWhitelisted("break", loc.getBlock().getId())
				&& !DataHandler.getPerm("build", player.getUniqueId(), loc))
		{
			event.setCancelled(true);
			try {
				player.sendMessage(Text.of(TextColors.RED, LanguageHandler.ERROR_PERM_BUILD));
			} catch (Exception e) {}
			return;
		}
	}
}
 
Example #14
Source File: GlobalListener.java    From RedProtect with GNU General Public License v3.0 6 votes vote down vote up
@Listener(order = Order.FIRST, beforeModifications = true)
public void onFireSpread(ChangeBlockEvent.Break e, @First LocatableBlock locatable) {
    RedProtect.get().logger.debug(LogLevel.BLOCKS, "GlobalListener - Is onBlockBreakGeneric event");

    BlockState sourceState = locatable.getBlockState();

    if (sourceState.getType() == BlockTypes.FIRE) {
        BlockSnapshot b = e.getTransactions().get(0).getOriginal();
        boolean fireDamage = RedProtect.get().config.globalFlagsRoot().worlds.get(locatable.getLocation().getExtent().getName()).fire_block_damage;
        if (!fireDamage && b.getState().getType() != BlockTypes.FIRE) {
            Region r = RedProtect.get().rm.getTopRegion(b.getLocation().get(), this.getClass().getName());
            if (r == null) {
                RedProtect.get().logger.debug(LogLevel.BLOCKS, "Tryed to break from FIRE!");
                e.setCancelled(true);
            }
        }
    }
}
 
Example #15
Source File: ChatUILib.java    From ChatUI with MIT License 5 votes vote down vote up
@Listener(order = Order.PRE, beforeModifications = true)
@IsCancelled(Tristate.UNDEFINED)
public void onIncomingMessage(MessageChannelEvent.Chat event, @Root Player player) {
    if (getView(player).handleIncoming(event.getRawMessage())) {
        // No plugins should interpret this as chat
        event.setCancelled(true);
        event.setChannel(MessageChannel.TO_NONE);
    }
}
 
Example #16
Source File: ConnectionListener.java    From FlexibleLogin with MIT License 5 votes vote down vote up
@Listener(order = Order.FIRST)
public void verifyPlayerName(Auth authEvent, @First GameProfile profile) {
    if (!namePredicate.test(profile.getName().get())) {
        //validate invalid characters
        authEvent.setMessage(settings.getText().getInvalidUsername());
        authEvent.setCancelled(true);
    }
}
 
Example #17
Source File: PlayerOnlineListener.java    From Plan with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Listener(order = Order.POST)
public void onQuit(ClientConnectionEvent.Disconnect event) {
    try {
        actOnQuitEvent(event);
    } catch (Exception e) {
        errorLogger.log(L.ERROR, e, ErrorContext.builder().related(event).build());
    }
}
 
Example #18
Source File: LPSpongeBootstrap.java    From LuckPerms with MIT License 5 votes vote down vote up
@Listener(order = Order.FIRST)
public void onEnable(GamePreInitializationEvent event) {
    this.startTime = Instant.now();
    try {
        this.plugin.load();
    } finally {
        this.loadLatch.countDown();
    }

    try {
        this.plugin.enable();
    } finally {
        this.enableLatch.countDown();
    }
}
 
Example #19
Source File: PlayerOnlineListener.java    From Plan with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Listener(order = Order.DEFAULT)
public void beforeQuit(ClientConnectionEvent.Disconnect event) {
    Player player = event.getTargetEntity();
    UUID playerUUID = player.getUniqueId();
    String playerName = player.getName();
    processing.submitNonCritical(() -> extensionService.updatePlayerValues(playerUUID, playerName, CallEvents.PLAYER_LEAVE));
}
 
Example #20
Source File: SpongePlugin.java    From ViaBackwards with MIT License 5 votes vote down vote up
@Listener(order = Order.LATE)
public void onGameStart(GameInitializationEvent e) {
    // Setup Logger
    this.logger = new LoggerWrapper(loggerSlf4j);
    // Init!
    this.init(configPath.resolve("config.yml").toFile());
}
 
Example #21
Source File: ChatLoggerListener.java    From FlexibleLogin with MIT License 5 votes vote down vote up
@Listener(order = Order.POST)
@IsCancelled(Tristate.TRUE)
public void onPostCommand(SendCommandEvent commandEvent) {
    String command = commandEvent.getCommand();
    if (isOurCommand(command)) {
        //re-enable it
        commandEvent.getContext();
        commandEvent.setCancelled(false);
    }
}
 
Example #22
Source File: PlayerListener.java    From RedProtect with GNU General Public License v3.0 5 votes vote down vote up
@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 #23
Source File: PlayerDeathListener.java    From EagleFactions with MIT License 5 votes vote down vote up
@Listener(order = Order.POST)
public void onPlayerDeath(final DestructEntityEvent.Death event, final @Getter("getTargetEntity") Player player)
{
    CompletableFuture.runAsync(() -> super.getPlugin().getPowerManager().decreasePower(player.getUniqueId()))
            .thenRun(() -> player.sendMessage(Text.of(PluginInfo.PLUGIN_PREFIX, MessageLoader.parseMessage(Messages.YOUR_POWER_HAS_BEEN_DECREASED_BY, TextColors.RESET, ImmutableMap.of(Placeholders.NUMBER, Text.of(TextColors.GOLD, this.powerConfig.getPowerDecrement()))), "\n",
            TextColors.GRAY, Messages.CURRENT_POWER + " ", super.getPlugin().getPowerManager().getPlayerPower(player.getUniqueId()) + "/" + super.getPlugin().getPowerManager().getPlayerMaxPower(player.getUniqueId()))));

    final Optional<Faction> optionalChunkFaction = super.getPlugin().getFactionLogic().getFactionByChunk(player.getWorld().getUniqueId(), player.getLocation().getChunkPosition());
    if (this.protectionConfig.getWarZoneWorldNames().contains(player.getWorld().getName()) || (optionalChunkFaction.isPresent() && optionalChunkFaction.get().isWarZone()))
    {
        super.getPlugin().getPlayerManager().setDeathInWarZone(player.getUniqueId(), true);
    }

    if (this.factionsConfig.shouldBlockHomeAfterDeathInOwnFaction())
    {
        final Optional<Faction> optionalPlayerFaction = super.getPlugin().getFactionLogic().getFactionByPlayerUUID(player.getUniqueId());
        if (optionalChunkFaction.isPresent() && optionalPlayerFaction.isPresent() && optionalChunkFaction.get().getName().equals(optionalPlayerFaction.get().getName()))
        {
            super.getPlugin().getAttackLogic().blockHome(player.getUniqueId());
        }
    }

    if(super.getPlugin().getPVPLogger().isActive() && super.getPlugin().getPVPLogger().isPlayerBlocked(player))
    {
        super.getPlugin().getPVPLogger().removePlayer(player);
    }
}
 
Example #24
Source File: GriefPreventionPlugin.java    From GriefPrevention with MIT License 5 votes vote down vote up
@Listener(order = Order.LAST)
public void onGameReload(GameReloadEvent event) {
    this.loadConfig();
    if (event.getSource() instanceof CommandSource) {
        sendMessage((CommandSource) event.getSource(), this.messageData.pluginReload.toText());
    }
}
 
Example #25
Source File: EntityListener.java    From RedProtect with GNU General Public License v3.0 5 votes vote down vote up
@Listener(order = Order.FIRST, beforeModifications = true)
public void WitherBlockBreak(ChangeBlockEvent.Break event, @First Entity e) {
    if (e instanceof Monster) {
        BlockSnapshot b = event.getTransactions().get(0).getOriginal();
        RedProtect.get().logger.debug(LogLevel.ENTITY, "EntityListener - Is EntityChangeBlockEvent event! Block " + b.getState().getType().getName());
        Region r = RedProtect.get().rm.getTopRegion(b.getLocation().get(), this.getClass().getName());
        if (!cont.canWorldBreak(b)) {
            event.setCancelled(true);
            return;
        }
        if (r != null && !r.canMobLoot()) {
            event.setCancelled(true);
        }
    }
}
 
Example #26
Source File: PlayerListener.java    From RedProtect with GNU General Public License v3.0 5 votes vote down vote up
@Listener(order = Order.FIRST, beforeModifications = true)
public void onPlayerDie(DestructEntityEvent.Death e, @First Player p) {
    RedProtect.get().logger.debug(LogLevel.PLAYER, "RPLayerListener: Is DestructEntityEvent.Death");

    if (RedProtect.get().tpWait.contains(p.getName())) {
        RedProtect.get().tpWait.remove(p.getName());
        RedProtect.get().lang.sendMessage(p, "cmdmanager.region.tpcancelled");
    }
}
 
Example #27
Source File: EntityEventHandler.java    From GriefPrevention with MIT License 5 votes vote down vote up
@Listener(order = Order.FIRST, beforeModifications = true)
public void onEntityCollideEntity(CollideEntityEvent event) {
    if (!GPFlags.ENTITY_COLLIDE_ENTITY || event instanceof CollideEntityEvent.Impact) {
        return;
    }
    //if (GriefPreventionPlugin.isSourceIdBlacklisted(ClaimFlag.ENTITY_COLLIDE_ENTITY.toString(), event.getSource(), event.getEntities().get(0).getWorld().getProperties())) {
    //    return;
    //}

    Object rootCause = event.getCause().root();
    final boolean isRootEntityItemFrame = rootCause instanceof EntityItemFrame;
    if (!isRootEntityItemFrame) {
        return;
    }

    GPTimings.ENTITY_COLLIDE_EVENT.startTimingIfSync();
    event.filterEntities(new Predicate<Entity>() {
        @Override
        public boolean test(Entity entity) {
            // Avoid living entities breaking itemframes
            if (isRootEntityItemFrame && entity instanceof EntityLiving) {
                return false;
            }

            return true;
        }
    });
    GPTimings.ENTITY_COLLIDE_EVENT.stopTimingIfSync();
}
 
Example #28
Source File: FactionJoinListener.java    From EagleFactions with MIT License 5 votes vote down vote up
@Listener(order = Order.POST)
@IsCancelled(value = Tristate.FALSE)
public void onFactionJoin(final FactionJoinEvent event, @Root final Player player)
{
	//Notify other faction members about someone joining the faction.
	final Faction faction = event.getFaction();
	final List<Player> factionPlayers = super.getPlugin().getFactionLogic().getOnlinePlayers(faction);
	for (final Player factionPlayer : factionPlayers)
	{
		if (factionPlayer.getName().equals(player.getName()))
			continue;
		factionPlayer.sendMessage(Text.of(PluginInfo.PLUGIN_PREFIX, TextColors.GOLD, player.getName(), TextColors.AQUA, " joined your faction."));
	}
}
 
Example #29
Source File: WebHookService.java    From Web-API with MIT License 5 votes vote down vote up
@Listener(order = Order.PRE)
public void onEntityDespawn(DestructEntityEvent event) {
    Entity ent = event.getTargetEntity();
    if (ent instanceof Player) {
        notifyHooks(WebHookService.WebHookType.PLAYER_DEATH, event);
    } else {
        notifyHooks(WebHookService.WebHookType.ENTITY_DESPAWN, event);
    }
}
 
Example #30
Source File: CacheService.java    From Web-API with MIT License 5 votes vote down vote up
@Listener(order = Order.POST)
public void onMessage(MessageChannelEvent event) {
    Optional<Player> player = event.getCause().first(Player.class);

    MessageChannel channel = event.getChannel().orElse(event.getOriginalChannel());
    CachedMessage msg = player.isPresent() ?
            new CachedChatMessage(player.get(), channel.getMembers(), event.getMessage()) :
            new CachedMessage(channel.getMembers(), event.getMessage());
    messages.add(msg);

    while (messages.size() > numChatMessages) {
        messages.poll();
    }
}