|
12 | 12 | import com.onarandombox.MultiverseCore.destination.DestinationFactory; |
13 | 13 | import com.onarandombox.MultiverseCore.enums.TeleportResult; |
14 | 14 | import com.onarandombox.MultiverseCore.utils.MVPermissions; |
15 | | -import com.onarandombox.MultiverseCore.utils.MVTravelAgent; |
16 | 15 | import com.onarandombox.MultiverseCore.api.SafeTTeleporter; |
17 | 16 | import com.onarandombox.MultiverseSignPortals.MultiverseSignPortals; |
18 | 17 | import com.onarandombox.MultiverseSignPortals.exceptions.MoreThanOneSignFoundException; |
|
29 | 28 | import org.bukkit.event.player.PlayerPortalEvent; |
30 | 29 | import org.bukkit.permissions.PermissionDefault; |
31 | 30 |
|
32 | | -import java.util.logging.Level; |
33 | | - |
34 | 31 | public class MVSPPlayerListener implements Listener { |
35 | 32 |
|
36 | | - private MultiverseSignPortals plugin; |
37 | | - private MVPermissions permissions; |
38 | | - private PortalDetector pd; |
| 33 | + private static final String USE_PERMISSION = "multiverse.signportal.use"; |
| 34 | + private static final String VALIDATE_PERMISSION = "multiverse.signportal.validate"; |
| 35 | + private final MultiverseSignPortals plugin; |
| 36 | + private final MVPermissions permissions; |
| 37 | + private final PortalDetector pd; |
39 | 38 |
|
40 | 39 | public MVSPPlayerListener(MultiverseSignPortals plugin) { |
41 | 40 | this.plugin = plugin; |
42 | 41 | this.permissions = this.plugin.getCore().getMVPerms(); |
43 | | - this.permissions.addPermission("multiverse.signportal.validate", PermissionDefault.OP); |
| 42 | + this.permissions.addPermission(VALIDATE_PERMISSION, PermissionDefault.OP); |
| 43 | + this.permissions.addPermission(USE_PERMISSION, PermissionDefault.TRUE); |
44 | 44 | this.pd = new PortalDetector(this.plugin); |
45 | 45 | } |
46 | 46 |
|
@@ -83,28 +83,46 @@ public void playerPortal(PlayerPortalEvent event) { |
83 | 83 | */ |
84 | 84 | @EventHandler |
85 | 85 | public void playerInteract(PlayerInteractEvent event) { |
| 86 | + // The event must not be canceled... |
86 | 87 | if (event.isCancelled()) { |
87 | 88 | return; |
88 | 89 | } |
89 | | - if (event.getAction() == Action.RIGHT_CLICK_BLOCK) { |
90 | | - if (event.getClickedBlock().getState() instanceof Sign) { |
91 | | - Logging.finer("Found a Sign!"); |
92 | | - Sign s = (Sign) event.getClickedBlock().getState(); |
93 | | - SignStatus status = this.pd.getSignStatus(s); |
94 | | - if (status == SignStatus.SignPortal) { |
| 90 | + |
| 91 | + // We must be right-clicking... |
| 92 | + if (event.getAction() != Action.RIGHT_CLICK_BLOCK) { |
| 93 | + return; |
| 94 | + } |
| 95 | + |
| 96 | + // And it must be a sign |
| 97 | + if (!(event.getClickedBlock().getState() instanceof Sign)) { |
| 98 | + return; |
| 99 | + } |
| 100 | + |
| 101 | + Logging.finer("Found a Sign!"); |
| 102 | + Sign s = (Sign) event.getClickedBlock().getState(); |
| 103 | + SignStatus status = this.pd.getSignStatus(s); |
| 104 | + |
| 105 | + Player player = event.getPlayer(); |
| 106 | + switch (status) { |
| 107 | + case SignPortal: |
| 108 | + if (permissions.hasPermission(player, USE_PERMISSION, false)) { |
95 | 109 | String destString = this.pd.processSign(s); |
96 | | - this.takePlayerToDestination(event.getPlayer(), destString); |
97 | | - event.setCancelled(true); |
98 | | - } else if (status == SignStatus.Disabled) { |
99 | | - this.pd.activateSignPortal(event.getPlayer(), ChatColor.RED + "Disabled", s); |
100 | | - event.setCancelled(true); |
101 | | - } else if (status == SignStatus.Legacy) { |
102 | | - this.pd.activateSignPortal(event.getPlayer(), ChatColor.AQUA + "Legacy", s); |
103 | | - event.setCancelled(true); |
104 | | - } else if (status == SignStatus.NetherPortalSign) { |
105 | | - event.setCancelled(true); |
| 110 | + this.takePlayerToDestination(player, destString); |
| 111 | + } else { |
| 112 | + player.sendMessage(ChatColor.RED + "You do not have the required permission to use SignPortals (" + USE_PERMISSION + ")"); |
106 | 113 | } |
107 | | - } |
| 114 | + event.setCancelled(true); |
| 115 | + break; |
| 116 | + case Legacy: |
| 117 | + this.pd.activateSignPortal(player, ChatColor.AQUA + "Legacy", s); |
| 118 | + event.setCancelled(true); |
| 119 | + break; |
| 120 | + case Disabled: |
| 121 | + this.pd.activateSignPortal(player, ChatColor.RED + "Disabled", s); |
| 122 | + event.setCancelled(true); |
| 123 | + break; |
| 124 | + case NetherPortalSign: |
| 125 | + event.setCancelled(true); |
108 | 126 | } |
109 | 127 | } |
110 | 128 |
|
|
0 commit comments