mirror of
https://github.com/EngineHub/WorldGuard.git
synced 2024-11-07 19:39:47 +01:00
Protected against using (right-clicking) paintings and item frames.
This commit is contained in:
parent
dd0c1a5ab5
commit
e9361022d2
@ -25,6 +25,7 @@
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.Creeper;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Hanging;
|
||||
import org.bukkit.entity.ItemFrame;
|
||||
import org.bukkit.entity.Painting;
|
||||
@ -35,6 +36,7 @@
|
||||
import org.bukkit.event.hanging.HangingBreakByEntityEvent;
|
||||
import org.bukkit.event.hanging.HangingBreakEvent;
|
||||
import org.bukkit.event.hanging.HangingPlaceEvent;
|
||||
import org.bukkit.event.player.PlayerInteractEntityEvent;
|
||||
|
||||
import com.sk89q.worldedit.blocks.ItemID;
|
||||
import com.sk89q.worldguard.blacklist.events.BlockBreakBlacklistEvent;
|
||||
@ -164,4 +166,31 @@ public void onHangingPlace(HangingPlaceEvent event) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
|
||||
public void onEntityInteract(PlayerInteractEntityEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
Entity entity = event.getRightClicked();
|
||||
|
||||
ConfigurationManager cfg = plugin.getGlobalStateManager();
|
||||
WorldConfiguration wcfg = cfg.get(entity.getWorld());
|
||||
|
||||
if (wcfg.useRegions && (entity instanceof ItemFrame || entity instanceof Painting)) {
|
||||
if (!plugin.getGlobalRegionManager().canBuild(player, entity.getLocation())) {
|
||||
player.sendMessage(ChatColor.DARK_RED + "You don't have permission for this area.");
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (entity instanceof ItemFrame
|
||||
&& ((!plugin.getGlobalRegionManager().allows(
|
||||
DefaultFlag.ENTITY_ITEM_FRAME_DESTROY, entity.getLocation())))) {
|
||||
event.setCancelled(true);
|
||||
} else if (entity instanceof Painting
|
||||
&& ((!plugin.getGlobalRegionManager().allows(
|
||||
DefaultFlag.ENTITY_PAINTING_DESTROY, entity.getLocation())))) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -22,9 +22,11 @@
|
||||
import static com.sk89q.worldguard.bukkit.BukkitUtil.toVector;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Warning;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.Creeper;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Painting;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
@ -33,12 +35,12 @@
|
||||
import org.bukkit.event.painting.PaintingBreakByEntityEvent;
|
||||
import org.bukkit.event.painting.PaintingBreakEvent;
|
||||
import org.bukkit.event.painting.PaintingPlaceEvent;
|
||||
import org.bukkit.event.player.PlayerInteractEntityEvent;
|
||||
|
||||
import com.sk89q.worldedit.blocks.ItemID;
|
||||
import com.sk89q.worldguard.blacklist.events.BlockBreakBlacklistEvent;
|
||||
import com.sk89q.worldguard.blacklist.events.ItemUseBlacklistEvent;
|
||||
import com.sk89q.worldguard.protection.flags.DefaultFlag;
|
||||
import org.bukkit.Warning;
|
||||
|
||||
/**
|
||||
* Listener for painting related events.
|
||||
@ -146,4 +148,27 @@ public void onPaintingPlace(PaintingPlaceEvent event) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
|
||||
public void onEntityInteract(PlayerInteractEntityEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
Entity entity = event.getRightClicked();
|
||||
|
||||
ConfigurationManager cfg = plugin.getGlobalStateManager();
|
||||
WorldConfiguration wcfg = cfg.get(entity.getWorld());
|
||||
|
||||
if (wcfg.useRegions && entity instanceof Painting) {
|
||||
if (!plugin.getGlobalRegionManager().canBuild(player, entity.getLocation())) {
|
||||
player.sendMessage(ChatColor.DARK_RED + "You don't have permission for this area.");
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (entity instanceof Painting
|
||||
&& ((!plugin.getGlobalRegionManager().allows(
|
||||
DefaultFlag.ENTITY_PAINTING_DESTROY, entity.getLocation())))) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user