From a2ad1b65bb0ed40489d3bf956439251d9ecc7a0d Mon Sep 17 00:00:00 2001 From: Jascha Starke Date: Tue, 17 Jan 2012 21:52:39 +0100 Subject: [PATCH] pvp disable chest access disable --- .../limitedcreative/Configuration.java | 6 ++ .../minecraft/limitedcreative/Inventory.java | 4 +- .../minecraft/limitedcreative/Listener.java | 77 ++++++++++++++++++- .../WorldGuardIntegration.java | 2 +- .../limitedcreative/serialize/Items.java | 2 - 5 files changed, 82 insertions(+), 9 deletions(-) diff --git a/LimitedCreative/src/de/jaschastarke/minecraft/limitedcreative/Configuration.java b/LimitedCreative/src/de/jaschastarke/minecraft/limitedcreative/Configuration.java index 64d80c2..99f43c3 100644 --- a/LimitedCreative/src/de/jaschastarke/minecraft/limitedcreative/Configuration.java +++ b/LimitedCreative/src/de/jaschastarke/minecraft/limitedcreative/Configuration.java @@ -12,4 +12,10 @@ public class Configuration { public boolean getDropInCreative() { return false; } + public String getInventoryFolder() { + return "inventories"; + } + public boolean getSignBlock() { + return true; + } } diff --git a/LimitedCreative/src/de/jaschastarke/minecraft/limitedcreative/Inventory.java b/LimitedCreative/src/de/jaschastarke/minecraft/limitedcreative/Inventory.java index 5829cbd..c4745fa 100644 --- a/LimitedCreative/src/de/jaschastarke/minecraft/limitedcreative/Inventory.java +++ b/LimitedCreative/src/de/jaschastarke/minecraft/limitedcreative/Inventory.java @@ -46,9 +46,9 @@ public class Inventory { private String getFileName(Player player, GameMode gm) { if (gm != GameMode.SURVIVAL) { - return player.getName()+"_"+gm.toString()+".yml"; + return LimitedCreativeCore.plugin.config.getInventoryFolder() + File.separator + player.getName()+"_"+gm.toString()+".yml"; } else { - return player.getName()+".yml"; + return LimitedCreativeCore.plugin.config.getInventoryFolder() + File.separator + player.getName()+".yml"; } } diff --git a/LimitedCreative/src/de/jaschastarke/minecraft/limitedcreative/Listener.java b/LimitedCreative/src/de/jaschastarke/minecraft/limitedcreative/Listener.java index 7c5400e..69d5654 100644 --- a/LimitedCreative/src/de/jaschastarke/minecraft/limitedcreative/Listener.java +++ b/LimitedCreative/src/de/jaschastarke/minecraft/limitedcreative/Listener.java @@ -1,9 +1,22 @@ package de.jaschastarke.minecraft.limitedcreative; + import org.bukkit.GameMode; +import org.bukkit.block.Block; +import org.bukkit.block.ContainerBlock; +import org.bukkit.block.Sign; +import org.bukkit.entity.Entity; +import org.bukkit.entity.Player; +import org.bukkit.entity.StorageMinecart; import org.bukkit.event.Event; import org.bukkit.event.Event.Priority; +import org.bukkit.event.block.Action; +import org.bukkit.event.entity.EntityDamageByEntityEvent; +import org.bukkit.event.entity.EntityDamageEvent; +import org.bukkit.event.entity.EntityListener; import org.bukkit.event.player.PlayerDropItemEvent; import org.bukkit.event.player.PlayerGameModeChangeEvent; +import org.bukkit.event.player.PlayerInteractEntityEvent; +import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.event.player.PlayerListener; import org.bukkit.event.player.PlayerPickupItemEvent; import org.bukkit.plugin.PluginManager; @@ -35,19 +48,75 @@ public final class Listener { if (event.getPlayer().getGameMode() == GameMode.CREATIVE && !plugin.config.getDropInCreative()) { event.setCancelled(true); } + } + + @Override + public void onPlayerInteract(PlayerInteractEvent event) { + if (event.isCancelled() || event.getPlayer().getGameMode() == GameMode.SURVIVAL) + return; + + if (event.getAction() != Action.RIGHT_CLICK_BLOCK) + return; + + Block block = event.getClickedBlock(); + + if (block.getState() instanceof ContainerBlock) { + event.getPlayer().sendMessage("Access to chests is not allowed in creative mode"); + event.setCancelled(true); + } + if (plugin.config.getSignBlock() && block.getState() instanceof Sign) { + event.getPlayer().sendMessage("Access to interact with signs is not allowed in creative mode"); + event.setCancelled(true); + } + } + + @Override + public void onPlayerInteractEntity(PlayerInteractEntityEvent event) { + if (event.isCancelled() || event.getPlayer().getGameMode() == GameMode.SURVIVAL) + return; + + Entity entity = event.getRightClicked(); + + if (entity instanceof StorageMinecart) { + event.getPlayer().sendMessage("Access to chests is not allowed in creative mode"); + event.setCancelled(true); + } + } + + private void register() { + pm.registerEvent(Event.Type.PLAYER_GAME_MODE_CHANGE, this, Priority.Normal, plugin); + pm.registerEvent(Event.Type.PLAYER_DROP_ITEM, this, Priority.Normal, plugin); + pm.registerEvent(Event.Type.PLAYER_PICKUP_ITEM, this, Priority.Normal, plugin); + pm.registerEvent(Event.Type.PLAYER_INTERACT, this, Priority.Lowest, plugin); + pm.registerEvent(Event.Type.PLAYER_INTERACT_ENTITY, this, Priority.Lowest, plugin); + } + } + + public static class EntityListen extends EntityListener { + @Override + public void onEntityDamage(EntityDamageEvent meta_event) { + if (meta_event instanceof EntityDamageByEntityEvent) { + EntityDamageByEntityEvent event = (EntityDamageByEntityEvent) meta_event; + if (event.getEntity() instanceof Player && event.getDamager() instanceof Player) { + // its PVP + if (((Player) event.getEntity()).getGameMode() == GameMode.CREATIVE || + ((Player) event.getDamager()).getGameMode() == GameMode.CREATIVE) { // one of them is creative + event.setCancelled(true); + } + } + } } private void register() { - pm.registerEvent(Event.Type.PLAYER_GAME_MODE_CHANGE, this, Priority.Low, plugin); - pm.registerEvent(Event.Type.PLAYER_DROP_ITEM, this, Priority.High, plugin); - pm.registerEvent(Event.Type.PLAYER_PICKUP_ITEM, this, Priority.High, plugin); + pm.registerEvent(Event.Type.ENTITY_DAMAGE, this, Priority.Normal, plugin); } } - + public static void register(LimitedCreativeCore pplugin) { plugin = pplugin; pm = plugin.getServer().getPluginManager(); new PlayerListen().register(); + new EntityListen().register(); } } diff --git a/LimitedCreative/src/de/jaschastarke/minecraft/limitedcreative/WorldGuardIntegration.java b/LimitedCreative/src/de/jaschastarke/minecraft/limitedcreative/WorldGuardIntegration.java index 8889ddc..7760944 100644 --- a/LimitedCreative/src/de/jaschastarke/minecraft/limitedcreative/WorldGuardIntegration.java +++ b/LimitedCreative/src/de/jaschastarke/minecraft/limitedcreative/WorldGuardIntegration.java @@ -1,7 +1,7 @@ package de.jaschastarke.minecraft.limitedcreative; import com.sk89q.worldguard.bukkit.WorldGuardPlugin; -import com.sk89q.worldguard.protection.flags.DefaultFlag; +//import com.sk89q.worldguard.protection.flags.DefaultFlag; import com.sk89q.worldguard.protection.flags.StateFlag; public class WorldGuardIntegration { diff --git a/LimitedCreative/src/de/jaschastarke/minecraft/limitedcreative/serialize/Items.java b/LimitedCreative/src/de/jaschastarke/minecraft/limitedcreative/serialize/Items.java index 761bb35..e694cf5 100644 --- a/LimitedCreative/src/de/jaschastarke/minecraft/limitedcreative/serialize/Items.java +++ b/LimitedCreative/src/de/jaschastarke/minecraft/limitedcreative/serialize/Items.java @@ -3,8 +3,6 @@ package de.jaschastarke.minecraft.limitedcreative.serialize; import org.bukkit.configuration.ConfigurationSection; import org.bukkit.inventory.PlayerInventory; -import de.jaschastarke.minecraft.limitedcreative.LimitedCreativeCore; - public class Items implements Storeable { private PlayerInventory inv; public Items(PlayerInventory pi) {