pvp disable

chest access disable
This commit is contained in:
Jascha Starke 2012-01-17 21:52:39 +01:00
parent 078fd69e08
commit a2ad1b65bb
5 changed files with 82 additions and 9 deletions

View file

@ -12,4 +12,10 @@ public class Configuration {
public boolean getDropInCreative() { public boolean getDropInCreative() {
return false; return false;
} }
public String getInventoryFolder() {
return "inventories";
}
public boolean getSignBlock() {
return true;
}
} }

View file

@ -46,9 +46,9 @@ public class Inventory {
private String getFileName(Player player, GameMode gm) { private String getFileName(Player player, GameMode gm) {
if (gm != GameMode.SURVIVAL) { if (gm != GameMode.SURVIVAL) {
return player.getName()+"_"+gm.toString()+".yml"; return LimitedCreativeCore.plugin.config.getInventoryFolder() + File.separator + player.getName()+"_"+gm.toString()+".yml";
} else { } else {
return player.getName()+".yml"; return LimitedCreativeCore.plugin.config.getInventoryFolder() + File.separator + player.getName()+".yml";
} }
} }

View file

@ -1,9 +1,22 @@
package de.jaschastarke.minecraft.limitedcreative; package de.jaschastarke.minecraft.limitedcreative;
import org.bukkit.GameMode; 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;
import org.bukkit.event.Event.Priority; 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.PlayerDropItemEvent;
import org.bukkit.event.player.PlayerGameModeChangeEvent; 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.PlayerListener;
import org.bukkit.event.player.PlayerPickupItemEvent; import org.bukkit.event.player.PlayerPickupItemEvent;
import org.bukkit.plugin.PluginManager; import org.bukkit.plugin.PluginManager;
@ -35,19 +48,75 @@ public final class Listener {
if (event.getPlayer().getGameMode() == GameMode.CREATIVE && !plugin.config.getDropInCreative()) { if (event.getPlayer().getGameMode() == GameMode.CREATIVE && !plugin.config.getDropInCreative()) {
event.setCancelled(true); 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() { private void register() {
pm.registerEvent(Event.Type.PLAYER_GAME_MODE_CHANGE, this, Priority.Low, plugin); pm.registerEvent(Event.Type.ENTITY_DAMAGE, this, Priority.Normal, plugin);
pm.registerEvent(Event.Type.PLAYER_DROP_ITEM, this, Priority.High, plugin);
pm.registerEvent(Event.Type.PLAYER_PICKUP_ITEM, this, Priority.High, plugin);
} }
} }
public static void register(LimitedCreativeCore pplugin) { public static void register(LimitedCreativeCore pplugin) {
plugin = pplugin; plugin = pplugin;
pm = plugin.getServer().getPluginManager(); pm = plugin.getServer().getPluginManager();
new PlayerListen().register(); new PlayerListen().register();
new EntityListen().register();
} }
} }

View file

@ -1,7 +1,7 @@
package de.jaschastarke.minecraft.limitedcreative; package de.jaschastarke.minecraft.limitedcreative;
import com.sk89q.worldguard.bukkit.WorldGuardPlugin; 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; import com.sk89q.worldguard.protection.flags.StateFlag;
public class WorldGuardIntegration { public class WorldGuardIntegration {

View file

@ -3,8 +3,6 @@ package de.jaschastarke.minecraft.limitedcreative.serialize;
import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.inventory.PlayerInventory; import org.bukkit.inventory.PlayerInventory;
import de.jaschastarke.minecraft.limitedcreative.LimitedCreativeCore;
public class Items implements Storeable { public class Items implements Storeable {
private PlayerInventory inv; private PlayerInventory inv;
public Items(PlayerInventory pi) { public Items(PlayerInventory pi) {