2011-03-30 06:03:21 +02:00
|
|
|
package com.earth2me.essentials.protect;
|
|
|
|
|
2011-11-21 02:55:26 +01:00
|
|
|
import static com.earth2me.essentials.I18n._;
|
2011-06-06 22:29:08 +02:00
|
|
|
import com.earth2me.essentials.IEssentials;
|
2011-11-21 02:55:26 +01:00
|
|
|
import com.earth2me.essentials.User;
|
2011-03-30 14:56:34 +02:00
|
|
|
import org.bukkit.block.Block;
|
2012-01-20 05:20:37 +01:00
|
|
|
import org.bukkit.event.EventHandler;
|
|
|
|
import org.bukkit.event.EventPriority;
|
|
|
|
import org.bukkit.event.Listener;
|
2011-11-21 02:55:26 +01:00
|
|
|
import org.bukkit.event.block.Action;
|
2011-03-30 16:28:46 +02:00
|
|
|
import org.bukkit.event.player.PlayerInteractEvent;
|
2011-03-30 06:03:21 +02:00
|
|
|
|
2011-06-06 22:29:08 +02:00
|
|
|
|
2012-01-20 05:20:37 +01:00
|
|
|
public class EssentialsProtectPlayerListener implements Listener
|
2011-03-30 06:03:21 +02:00
|
|
|
{
|
2011-06-06 22:29:08 +02:00
|
|
|
private final transient IProtect prot;
|
|
|
|
private final transient IEssentials ess;
|
2011-03-30 14:56:34 +02:00
|
|
|
|
2011-06-06 22:29:08 +02:00
|
|
|
public EssentialsProtectPlayerListener(final IProtect prot)
|
2011-03-30 06:03:21 +02:00
|
|
|
{
|
2011-06-06 22:29:08 +02:00
|
|
|
this.prot = prot;
|
2011-11-30 21:25:11 +01:00
|
|
|
this.ess = prot.getEssentialsConnect().getEssentials();
|
2011-03-30 06:03:21 +02:00
|
|
|
}
|
|
|
|
|
2012-01-20 05:52:35 +01:00
|
|
|
@EventHandler(priority = EventPriority.LOW)
|
2011-06-06 22:29:08 +02:00
|
|
|
public void onPlayerInteract(final PlayerInteractEvent event)
|
2011-03-30 06:03:21 +02:00
|
|
|
{
|
2011-11-17 14:23:35 +01:00
|
|
|
// Do not return if cancelled, because the interact event has 2 cancelled states.
|
2011-06-06 22:29:08 +02:00
|
|
|
final User user = ess.getUser(event.getPlayer());
|
2011-03-30 16:28:46 +02:00
|
|
|
|
2011-06-12 14:32:28 +02:00
|
|
|
if (user.isAuthorized("essentials.protect.ownerinfo") && event.getAction() == Action.RIGHT_CLICK_BLOCK)
|
2011-03-30 16:28:46 +02:00
|
|
|
{
|
2011-06-06 22:29:08 +02:00
|
|
|
final StringBuilder stringBuilder = new StringBuilder();
|
2011-06-03 01:09:59 +02:00
|
|
|
boolean first = true;
|
2011-06-06 22:29:08 +02:00
|
|
|
final Block blockClicked = event.getClickedBlock();
|
|
|
|
for (String owner : prot.getStorage().getOwners(blockClicked))
|
2011-06-03 01:09:59 +02:00
|
|
|
{
|
|
|
|
if (!first)
|
|
|
|
{
|
2011-06-06 22:29:08 +02:00
|
|
|
stringBuilder.append(", ");
|
2011-06-03 01:09:59 +02:00
|
|
|
}
|
|
|
|
first = false;
|
2011-06-06 22:29:08 +02:00
|
|
|
stringBuilder.append(owner);
|
2011-06-03 01:09:59 +02:00
|
|
|
}
|
2011-06-06 22:29:08 +02:00
|
|
|
final String ownerNames = stringBuilder.toString();
|
2011-06-03 01:09:59 +02:00
|
|
|
if (ownerNames != null && !ownerNames.isEmpty())
|
2011-03-30 16:28:46 +02:00
|
|
|
{
|
2011-11-21 02:55:26 +01:00
|
|
|
user.sendMessage(_("protectionOwner", ownerNames));
|
2011-03-30 16:28:46 +02:00
|
|
|
}
|
|
|
|
}
|
2011-03-30 06:03:21 +02:00
|
|
|
}
|
|
|
|
}
|