Fixed interaction checks for paintings and soil. issue #24

This commit is contained in:
t3hk0d3 2011-10-01 20:59:42 +04:00
parent b4c4897b2c
commit 578e491263
3 changed files with 67 additions and 39 deletions

View File

@ -18,8 +18,13 @@
*/
package ru.tehkode.modifyworld.handlers;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.Event.Type;
import org.bukkit.event.block.*;
import org.bukkit.event.painting.PaintingBreakByEntityEvent;
import org.bukkit.event.painting.PaintingBreakEvent;
import org.bukkit.event.painting.PaintingPlaceEvent;
import org.bukkit.plugin.Plugin;
import org.bukkit.util.config.ConfigurationNode;
import ru.tehkode.modifyworld.EventHandler;
@ -31,23 +36,46 @@ import ru.tehkode.modifyworld.ModifyworldListener;
*/
public class BlockListener extends ModifyworldListener {
public BlockListener(Plugin plugin, ConfigurationNode config) {
super(plugin, config);
}
@EventHandler(Type.BLOCK_BREAK)
public void onBlockBreak(BlockBreakEvent event) {
if (!canInteractWithMaterial(event.getPlayer(), "modifyworld.blocks.destroy.", event.getBlock().getType())) {
informPlayerAboutDenial(event.getPlayer());
event.setCancelled(true);
}
}
public BlockListener(Plugin plugin, ConfigurationNode config) {
super(plugin, config);
}
@EventHandler(Type.BLOCK_PLACE)
public void onBlockPlace(BlockPlaceEvent event) {
if (!canInteractWithMaterial(event.getPlayer(), "modifyworld.blocks.place.", event.getBlock().getType())) {
informPlayerAboutDenial(event.getPlayer());
event.setCancelled(true);
}
}
@EventHandler(Type.BLOCK_BREAK)
public void onBlockBreak(BlockBreakEvent event) {
if (!canInteractWithMaterial(event.getPlayer(), "modifyworld.blocks.destroy.", event.getBlock().getType())) {
informPlayerAboutDenial(event.getPlayer());
event.setCancelled(true);
}
}
@EventHandler(Type.BLOCK_PLACE)
public void onBlockPlace(BlockPlaceEvent event) {
if (!canInteractWithMaterial(event.getPlayer(), "modifyworld.blocks.place.", event.getBlock().getType())) {
informPlayerAboutDenial(event.getPlayer());
event.setCancelled(true);
}
}
@EventHandler(Type.PAINTING_BREAK)
public void onPaintingBreak(PaintingBreakEvent event) {
if (!(event instanceof PaintingBreakByEntityEvent)) {
return;
}
PaintingBreakByEntityEvent pbee = (PaintingBreakByEntityEvent) event;
if (pbee.getRemover() instanceof Player
&& !canInteractWithMaterial((Player) pbee.getRemover(), "modifyworld.blocks.destroy.", Material.PAINTING)) {
informPlayerAboutDenial((Player) pbee.getRemover());
event.setCancelled(true);
}
}
@EventHandler(Type.PAINTING_PLACE)
public void onPaintingPlace(PaintingPlaceEvent event) {
if (!canInteractWithMaterial(event.getPlayer(), "modifyworld.blocks.place.", Material.PAINTING)) {
informPlayerAboutDenial(event.getPlayer());
event.setCancelled(true);
}
}
}

View File

@ -39,26 +39,6 @@ public class EntityListener extends ModifyworldListener {
super(plugin, config);
}
protected boolean canMessWithEntity(Player player, String basePermission, Entity entity) {
if (entity instanceof Player) {
PermissionUser entityUser = permissionsManager.getUser(((Player) entity).getName());
if (entityUser == null) {
return false;
}
for (PermissionGroup group : entityUser.getGroups()) {
if (permissionsManager.has(player, basePermission + "group." + group.getName())) {
return true;
}
}
return permissionsManager.has(player, basePermission + "player." + entityUser.getName());
}
return permissionsManager.has(player, basePermission + getEntityName(entity));
}
@EventHandler(Type.ENTITY_DAMAGE)
public void onEntityDamage(EntityDamageEvent event) {
if (event instanceof EntityDamageByEntityEvent) {
@ -134,4 +114,24 @@ public class EntityListener extends ModifyworldListener {
}
}
}
protected boolean canMessWithEntity(Player player, String basePermission, Entity entity) {
if (entity instanceof Player) {
PermissionUser entityUser = permissionsManager.getUser(((Player) entity).getName());
if (entityUser == null) {
return false;
}
for (PermissionGroup group : entityUser.getGroups()) {
if (permissionsManager.has(player, basePermission + "group." + group.getName())) {
return true;
}
}
return permissionsManager.has(player, basePermission + "player." + entityUser.getName());
}
return permissionsManager.has(player, basePermission + getEntityName(entity));
}
}

View File

@ -165,7 +165,7 @@ public class PlayerListener extends ModifyworldListener {
@EventHandler(Type.PLAYER_INTERACT)
public void onPlayerInteract(PlayerInteractEvent event) {
Action action = event.getAction();
if (action != Action.LEFT_CLICK_BLOCK && action != Action.RIGHT_CLICK_BLOCK) {
if (action != Action.LEFT_CLICK_BLOCK && action != Action.RIGHT_CLICK_BLOCK && action != Action.PHYSICAL) {
return;
}