git-svn-id: https://svn.java.net/svn/essentials~svn/trunk@1035 e251c2fe-e539-e718-e476-b85c1f46cddb
This commit is contained in:
ementalo 2011-03-30 14:22:14 +00:00
parent d4973ae644
commit c2f7853ec9
3 changed files with 45 additions and 31 deletions

View File

@ -48,15 +48,17 @@ public class EssentialsProtect extends JavaPlugin
playerListener = new EssentialsProtectPlayerListener(this);
blockListener = new EssentialsProtectBlockListener(this);
entityListener = new EssentialsProtectEntityListener(this);
pm.registerEvent(Type.PLAYER_INTERACT, playerListener, Priority.Low, this);
pm.registerEvent(Type.PLAYER_ITEM, playerListener, Priority.Low, this);
// Why is this commented?
//pm.registerEvent(Type.BLOCK_DAMAGED, blockListener, Priority.High, this);
pm.registerEvent(Type.BLOCK_PLACE, blockListener, Priority.Highest, this);
pm.registerEvent(Type.BLOCK_FROMTO, blockListener, Priority.Highest, this);
pm.registerEvent(Type.BLOCK_RIGHTCLICKED, blockListener, Priority.Low, this);
pm.registerEvent(Type.BLOCK_PLACED, blockListener, Priority.Highest, this);
pm.registerEvent(Type.BLOCK_INTERACT, blockListener, Priority.Highest, this);
pm.registerEvent(Type.BLOCK_FLOW, blockListener, Priority.Highest, this);
pm.registerEvent(Type.BLOCK_IGNITE, blockListener, Priority.Highest, this);
pm.registerEvent(Type.BLOCK_BURN, blockListener, Priority.Highest, this);
pm.registerEvent(Type.ENTITY_EXPLODE, entityListener, Priority.Highest, this);
pm.registerEvent(Type.ENTITY_DAMAGE, entityListener, Priority.Highest, this);
pm.registerEvent(Type.ENTITY_DAMAGED, entityListener, Priority.Highest, this);
pm.registerEvent(Type.BLOCK_BREAK, blockListener, Priority.Highest, this);
pm.registerEvent(Type.CREATURE_SPAWN, entityListener, Priority.Highest, this);

View File

@ -37,6 +37,23 @@ public class EssentialsProtectBlockListener extends BlockListener
spData = new EssentialsProtectData();
}
@Override
public void onBlockRightClick(BlockRightClickEvent event)
{
initialize();
User user = User.get(event.getPlayer());
if (user.isAuthorized("essentials.protect.admin"))
{
String ownerName = spData.getBlockOwner(user.getWorld().getName(), user.getName(),
event.getBlock());
if (ownerName != null)
{
user.sendMessage(ChatColor.GOLD + "[EssentialsProtect] Protection owner: "
+ ownerName);
}
}
}
@Override
public void onBlockPlace(BlockPlaceEvent event)
{
@ -162,6 +179,22 @@ public class EssentialsProtectBlockListener extends BlockListener
}
}
@Override
public void onBlockInteract(BlockInteractEvent event)
{
if (event.isCancelled()) return;
if (!event.isPlayer()) return;
User user = User.get((Player)event.getEntity());
if (EssentialsProtect.playerSettings.get("protect.disable.build") && !user.canBuild())
{
event.setCancelled(true);
return;
}
}
@Override
public void onBlockBurn(BlockBurnEvent event)
{

View File

@ -2,9 +2,7 @@ package com.earth2me.essentials.protect;
import com.earth2me.essentials.Essentials;
import com.earth2me.essentials.User;
import org.bukkit.ChatColor;
import org.bukkit.block.Block;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerItemEvent;
import org.bukkit.event.player.PlayerListener;
import org.bukkit.inventory.ItemStack;
@ -31,36 +29,18 @@ public class EssentialsProtectPlayerListener extends PlayerListener
}
@Override
public void onPlayerInteract(PlayerInteractEvent event)
public void onPlayerItem(PlayerItemEvent event)
{
initialize();
if (event.isCancelled()) return;
if(event.isCancelled()) return;
ItemStack item = event.getItem();
User user = User.get(event.getPlayer());
Block blockClicked = event.getClickedBlock();
if (EssentialsProtect.playerSettings.get("protect.disable.build") && !user.canBuild())
{
event.setCancelled(true);
return;
}
Block blockPlaced = event.getBlockClicked();
if (EssentialsProtect.checkProtectionItems(EssentialsProtect.usageList, item.getTypeId()) && !user.isAuthorized("essentials.protect.exemptusage"))
{
event.setCancelled(true);
return;
}
if (user.isAuthorized("essentials.protect.admin"))
{
String ownerName = spData.getBlockOwner(user.getWorld().getName(), user.getName(),
blockClicked);
if (ownerName != null)
{
user.sendMessage(ChatColor.GOLD + "[EssentialsProtect] Protection owner: "
+ ownerName);
}
}
if (EssentialsProtect.onUseAlert.contains(String.valueOf(item.getTypeId())))
{
parent.alert(user, item.getType().toString(), "used: ");
@ -73,9 +53,9 @@ public class EssentialsProtectPlayerListener extends PlayerListener
if (user.isAuthorized("essentials.protect"))
{
signBlockX = blockClicked.getX();
signBlockY = blockClicked.getY();
signBlockZ = blockClicked.getZ();
signBlockX = blockPlaced.getX();
signBlockY = blockPlaced.getY();
signBlockZ = blockPlaced.getZ();
initialize();
spData.insertProtectionIntoDb(user.getWorld().getName(), user.getName(), signBlockX,
@ -89,6 +69,5 @@ public class EssentialsProtectPlayerListener extends PlayerListener
}
}
}
}
}