blob: 393376b6f1226c5f6cb3585e713ee5510bd26c25 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
package com.earth2me.essentials.protect;
import static com.earth2me.essentials.I18n._;
import com.earth2me.essentials.IEssentials;
import com.earth2me.essentials.User;
import org.bukkit.block.Block;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.block.Action;
import org.bukkit.event.player.PlayerInteractEvent;
public class EssentialsProtectPlayerListener implements Listener
{
private final transient IProtect prot;
private final transient IEssentials ess;
public EssentialsProtectPlayerListener(final IProtect prot)
{
this.prot = prot;
this.ess = prot.getEssentialsConnect().getEssentials();
}
@EventHandler(priority = EventPriority.LOW)
public void onPlayerInteract(final PlayerInteractEvent event)
{
// Do not return if cancelled, because the interact event has 2 cancelled states.
final User user = ess.getUser(event.getPlayer());
if (user.isAuthorized("essentials.protect.ownerinfo") && event.getAction() == Action.RIGHT_CLICK_BLOCK)
{
final StringBuilder stringBuilder = new StringBuilder();
boolean first = true;
final Block blockClicked = event.getClickedBlock();
for (String owner : prot.getStorage().getOwners(blockClicked))
{
if (!first)
{
stringBuilder.append(", ");
}
first = false;
stringBuilder.append(owner);
}
final String ownerNames = stringBuilder.toString();
if (ownerNames != null && !ownerNames.isEmpty())
{
user.sendMessage(_("protectionOwner", ownerNames));
}
}
}
}
|