mirror of
https://github.com/EngineHub/WorldGuard.git
synced 2025-01-12 11:21:34 +01:00
Route XP drops through the event abstraction.
This commit is contained in:
parent
5ff9f5c175
commit
416006dbde
@ -72,9 +72,11 @@
|
|||||||
import org.bukkit.event.entity.EntityDamageByBlockEvent;
|
import org.bukkit.event.entity.EntityDamageByBlockEvent;
|
||||||
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||||
import org.bukkit.event.entity.EntityDamageEvent;
|
import org.bukkit.event.entity.EntityDamageEvent;
|
||||||
|
import org.bukkit.event.entity.EntityDeathEvent;
|
||||||
import org.bukkit.event.entity.EntityExplodeEvent;
|
import org.bukkit.event.entity.EntityExplodeEvent;
|
||||||
import org.bukkit.event.entity.EntityTameEvent;
|
import org.bukkit.event.entity.EntityTameEvent;
|
||||||
import org.bukkit.event.entity.EntityUnleashEvent;
|
import org.bukkit.event.entity.EntityUnleashEvent;
|
||||||
|
import org.bukkit.event.entity.ExpBottleEvent;
|
||||||
import org.bukkit.event.entity.PotionSplashEvent;
|
import org.bukkit.event.entity.PotionSplashEvent;
|
||||||
import org.bukkit.event.hanging.HangingBreakByEntityEvent;
|
import org.bukkit.event.hanging.HangingBreakByEntityEvent;
|
||||||
import org.bukkit.event.hanging.HangingBreakEvent;
|
import org.bukkit.event.hanging.HangingBreakEvent;
|
||||||
@ -83,6 +85,7 @@
|
|||||||
import org.bukkit.event.player.PlayerBucketEmptyEvent;
|
import org.bukkit.event.player.PlayerBucketEmptyEvent;
|
||||||
import org.bukkit.event.player.PlayerBucketFillEvent;
|
import org.bukkit.event.player.PlayerBucketFillEvent;
|
||||||
import org.bukkit.event.player.PlayerDropItemEvent;
|
import org.bukkit.event.player.PlayerDropItemEvent;
|
||||||
|
import org.bukkit.event.player.PlayerFishEvent;
|
||||||
import org.bukkit.event.player.PlayerInteractEntityEvent;
|
import org.bukkit.event.player.PlayerInteractEntityEvent;
|
||||||
import org.bukkit.event.player.PlayerInteractEvent;
|
import org.bukkit.event.player.PlayerInteractEvent;
|
||||||
import org.bukkit.event.player.PlayerPickupItemEvent;
|
import org.bukkit.event.player.PlayerPickupItemEvent;
|
||||||
@ -443,7 +446,28 @@ public void onBlockExp(BlockExpEvent event) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: XP pickup is an entity destroy event
|
@EventHandler
|
||||||
|
public void onPlayerFish(PlayerFishEvent event) {
|
||||||
|
if (Events.fireAndTestCancel(new SpawnEntityEvent(event, create(event.getPlayer(), event.getHook()), event.getCaught().getLocation(), EntityType.EXPERIENCE_ORB))) {
|
||||||
|
event.setExpToDrop(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onExpBottle(ExpBottleEvent event) {
|
||||||
|
if (Events.fireAndTestCancel(new SpawnEntityEvent(event, create(event.getEntity()), event.getEntity().getLocation(), EntityType.EXPERIENCE_ORB))) {
|
||||||
|
event.setExperience(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onEntityDeath(EntityDeathEvent event) {
|
||||||
|
if (event.getDroppedExp() > 0) {
|
||||||
|
if (Events.fireAndTestCancel(new SpawnEntityEvent(event, create(event.getEntity()), event.getEntity().getLocation(), EntityType.EXPERIENCE_ORB))) {
|
||||||
|
event.setDroppedExp(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//-------------------------------------------------------------------------
|
//-------------------------------------------------------------------------
|
||||||
// Entity external interaction
|
// Entity external interaction
|
||||||
|
@ -72,7 +72,6 @@
|
|||||||
import org.bukkit.event.entity.EntityExplodeEvent;
|
import org.bukkit.event.entity.EntityExplodeEvent;
|
||||||
import org.bukkit.event.entity.EntityInteractEvent;
|
import org.bukkit.event.entity.EntityInteractEvent;
|
||||||
import org.bukkit.event.entity.EntityRegainHealthEvent;
|
import org.bukkit.event.entity.EntityRegainHealthEvent;
|
||||||
import org.bukkit.event.entity.ExpBottleEvent;
|
|
||||||
import org.bukkit.event.entity.ExplosionPrimeEvent;
|
import org.bukkit.event.entity.ExplosionPrimeEvent;
|
||||||
import org.bukkit.event.entity.FoodLevelChangeEvent;
|
import org.bukkit.event.entity.FoodLevelChangeEvent;
|
||||||
import org.bukkit.event.entity.PigZapEvent;
|
import org.bukkit.event.entity.PigZapEvent;
|
||||||
@ -124,26 +123,10 @@ public void onEntityInteract(EntityInteractEvent event) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
|
|
||||||
public void onExpBottle(ExpBottleEvent event) {
|
|
||||||
WorldConfiguration wcfg = plugin.getGlobalStateManager().get(event.getEntity().getWorld());
|
|
||||||
|
|
||||||
if (wcfg.disableExpDrops || !plugin.getGlobalRegionManager().allows(DefaultFlag.EXP_DROPS,
|
|
||||||
event.getEntity().getLocation())) {
|
|
||||||
event.setExperience(0);
|
|
||||||
// event.setShowEffect(false); // don't want to cancel the bottle entirely I suppose, just the exp
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.HIGH)
|
@EventHandler(priority = EventPriority.HIGH)
|
||||||
public void onEntityDeath(EntityDeathEvent event) {
|
public void onEntityDeath(EntityDeathEvent event) {
|
||||||
WorldConfiguration wcfg = plugin.getGlobalStateManager().get(event.getEntity().getWorld());
|
WorldConfiguration wcfg = plugin.getGlobalStateManager().get(event.getEntity().getWorld());
|
||||||
|
|
||||||
if (wcfg.disableExpDrops || !plugin.getGlobalRegionManager().allows(DefaultFlag.EXP_DROPS,
|
|
||||||
event.getEntity().getLocation())) {
|
|
||||||
event.setDroppedExp(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (event instanceof PlayerDeathEvent && wcfg.disableDeathMessages) {
|
if (event instanceof PlayerDeathEvent && wcfg.disableDeathMessages) {
|
||||||
((PlayerDeathEvent) event).setDeathMessage("");
|
((PlayerDeathEvent) event).setDeathMessage("");
|
||||||
}
|
}
|
||||||
|
@ -46,7 +46,6 @@
|
|||||||
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
||||||
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
|
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
|
||||||
import org.bukkit.event.player.PlayerDropItemEvent;
|
import org.bukkit.event.player.PlayerDropItemEvent;
|
||||||
import org.bukkit.event.player.PlayerFishEvent;
|
|
||||||
import org.bukkit.event.player.PlayerGameModeChangeEvent;
|
import org.bukkit.event.player.PlayerGameModeChangeEvent;
|
||||||
import org.bukkit.event.player.PlayerInteractEvent;
|
import org.bukkit.event.player.PlayerInteractEvent;
|
||||||
import org.bukkit.event.player.PlayerItemHeldEvent;
|
import org.bukkit.event.player.PlayerItemHeldEvent;
|
||||||
@ -580,16 +579,6 @@ public void onPlayerDropItem(PlayerDropItemEvent event) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
|
|
||||||
public void onPlayerFish(PlayerFishEvent event) {
|
|
||||||
WorldConfiguration wcfg = plugin.getGlobalStateManager().get(event.getPlayer().getWorld());
|
|
||||||
|
|
||||||
if (wcfg.disableExpDrops || !plugin.getGlobalRegionManager().allows(DefaultFlag.EXP_DROPS,
|
|
||||||
event.getPlayer().getLocation())) {
|
|
||||||
event.setExpToDrop(0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.HIGHEST)
|
@EventHandler(priority = EventPriority.HIGHEST)
|
||||||
public void onPlayerRespawn(PlayerRespawnEvent event) {
|
public void onPlayerRespawn(PlayerRespawnEvent event) {
|
||||||
Player player = event.getPlayer();
|
Player player = event.getPlayer();
|
||||||
|
@ -0,0 +1,55 @@
|
|||||||
|
/*
|
||||||
|
* WorldGuard, a suite of tools for Minecraft
|
||||||
|
* Copyright (C) sk89q <http://www.sk89q.com>
|
||||||
|
* Copyright (C) WorldGuard team and contributors
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify it
|
||||||
|
* under the terms of the GNU Lesser General Public License as published by the
|
||||||
|
* Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
||||||
|
* for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.sk89q.worldguard.bukkit.listener;
|
||||||
|
|
||||||
|
import com.sk89q.worldguard.bukkit.WorldConfiguration;
|
||||||
|
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
|
||||||
|
import com.sk89q.worldguard.bukkit.event.entity.SpawnEntityEvent;
|
||||||
|
import org.bukkit.entity.EntityType;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.EventPriority;
|
||||||
|
|
||||||
|
public class WorldRulesListener extends AbstractListener {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Construct the listener.
|
||||||
|
*
|
||||||
|
* @param plugin an instance of WorldGuardPlugin
|
||||||
|
*/
|
||||||
|
public WorldRulesListener(WorldGuardPlugin plugin) {
|
||||||
|
super(plugin);
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
|
||||||
|
public void onSpawnEntity(final SpawnEntityEvent event) {
|
||||||
|
WorldConfiguration config = getWorldConfig(event.getWorld());
|
||||||
|
|
||||||
|
// ================================================================
|
||||||
|
// EXP_DROPS flag
|
||||||
|
// ================================================================
|
||||||
|
|
||||||
|
if (event.getEffectiveType() == EntityType.EXPERIENCE_ORB) {
|
||||||
|
if (config.disableExpDrops) {
|
||||||
|
event.setCancelled(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user