Skip to content

Commit fb61b4c

Browse files
committed
Update LocketteProAPI and remove duplicate code
1 parent 6ea53b2 commit fb61b4c

File tree

5 files changed

+19
-33
lines changed

5 files changed

+19
-33
lines changed

src/me/crafter/mc/lockettepro/BlockEnvironmentListener.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public class BlockEnvironmentListener implements Listener{
2222
// Prevent explosion break block
2323
@EventHandler(priority = EventPriority.HIGH)
2424
public void onEntityExplode(EntityExplodeEvent event){
25-
if (Config.isProtectionExempted("explosion") || Config.isDisabledWorld(event.getLocation())) return;
25+
if (Config.isProtectionExempted("explosion")) return;
2626
Iterator<Block> it = event.blockList().iterator();
2727
while (it.hasNext()) {
2828
Block block = it.next();
@@ -33,7 +33,7 @@ public void onEntityExplode(EntityExplodeEvent event){
3333
// Prevent bed break block
3434
@EventHandler(priority = EventPriority.HIGH)
3535
public void onBlockExplode(BlockExplodeEvent event){
36-
if (Config.isProtectionExempted("explosion") || Config.isDisabledWorld(event.getBlock())) return;
36+
if (Config.isProtectionExempted("explosion")) return;
3737
Iterator<Block> it = event.blockList().iterator();
3838
while (it.hasNext()) {
3939
Block block = it.next();
@@ -44,7 +44,7 @@ public void onBlockExplode(BlockExplodeEvent event){
4444
// Prevent tree break block
4545
@EventHandler(priority = EventPriority.HIGH)
4646
public void onStructureGrow(StructureGrowEvent event){
47-
if (Config.isProtectionExempted("growth") || Config.isDisabledWorld(event.getWorld().getName())) return;
47+
if (Config.isProtectionExempted("growth")) return;
4848
for (BlockState blockstate : event.getBlocks()){
4949
if (LocketteProAPI.isProtected(blockstate.getBlock())){
5050
event.setCancelled(true);
@@ -56,7 +56,7 @@ public void onStructureGrow(StructureGrowEvent event){
5656
// Prevent piston extend break lock
5757
@EventHandler(priority = EventPriority.HIGH)
5858
public void onPistonExtend(BlockPistonExtendEvent event){
59-
if (Config.isProtectionExempted("piston") || Config.isDisabledWorld(event.getBlock())) return;
59+
if (Config.isProtectionExempted("piston")) return;
6060
for (Block block : event.getBlocks()){
6161
if (LocketteProAPI.isProtected(block)){
6262
event.setCancelled(true);
@@ -68,7 +68,7 @@ public void onPistonExtend(BlockPistonExtendEvent event){
6868
// Prevent piston retract break lock
6969
@EventHandler(priority = EventPriority.HIGH)
7070
public void onPistonRetract(BlockPistonRetractEvent event){
71-
if (Config.isProtectionExempted("piston") || Config.isDisabledWorld(event.getBlock())) return;
71+
if (Config.isProtectionExempted("piston")) return;
7272
for (Block block : event.getBlocks()){
7373
if (LocketteProAPI.isProtected(block)){
7474
event.setCancelled(true);
@@ -80,7 +80,7 @@ public void onPistonRetract(BlockPistonRetractEvent event){
8080
// Prevent redstone current open doors
8181
@EventHandler(priority = EventPriority.HIGH)
8282
public void onBlockRedstoneChange(BlockRedstoneEvent event){
83-
if (Config.isProtectionExempted("redstone") || Config.isDisabledWorld(event.getBlock())) return;
83+
if (Config.isProtectionExempted("redstone")) return;
8484
if (LocketteProAPI.isProtected(event.getBlock())){
8585
event.setNewCurrent(event.getOldCurrent());
8686
}
@@ -89,7 +89,7 @@ public void onBlockRedstoneChange(BlockRedstoneEvent event){
8989
// Prevent villager open door
9090
@EventHandler(priority = EventPriority.HIGH)
9191
public void onVillagerOpenDoor(EntityInteractEvent event){
92-
if (Config.isProtectionExempted("villager") || Config.isDisabledWorld(event.getBlock())) return;
92+
if (Config.isProtectionExempted("villager")) return;
9393
// Explicitly to villager vs all doors
9494
if (event.getEntity() instanceof Villager &&
9595
(LocketteProAPI.isSingleDoorBlock(event.getBlock()) || LocketteProAPI.isDoubleDoorBlock(event.getBlock())) &&
@@ -101,7 +101,7 @@ public void onVillagerOpenDoor(EntityInteractEvent event){
101101
// Prevent Enderman take block
102102
@EventHandler(priority = EventPriority.HIGH)
103103
public void onEndermanGreif(EntityInteractEvent event){
104-
if (Config.isProtectionExempted("enderman") || Config.isDisabledWorld(event.getBlock())) return;
104+
if (Config.isProtectionExempted("enderman")) return;
105105
if (event.getEntity() instanceof Enderman && LocketteProAPI.isProtected(event.getBlock())){
106106
event.setCancelled(true);
107107
}

src/me/crafter/mc/lockettepro/BlockInventoryMoveListener.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ public class BlockInventoryMoveListener implements Listener {
1515

1616
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGH)
1717
public void onInventoryMove(InventoryMoveItemEvent event){
18-
if (event.getSource() != null && Config.isDisabledWorld(event.getSource().getLocation().getWorld().getName())) return;
1918
if (Config.isItemTransferOutBlocked() || Config.getHopperMinecartAction() != (byte)0){
2019
if (isInventoryLocked(event.getSource())){
2120
if (Config.isItemTransferOutBlocked()){

src/me/crafter/mc/lockettepro/BlockPlayerListener.java

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,8 @@
2323
public class BlockPlayerListener implements Listener {
2424

2525
// Quick protect for chests
26-
@EventHandler(priority = EventPriority.NORMAL)
26+
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
2727
public void onPlayerQuickLockChest(PlayerInteractEvent event){
28-
if (event.isCancelled()) return;
2928
// Check quick lock enabled
3029
if (Config.getQuickProtectAction() == (byte)0) return;
3130
// Check world enabled
@@ -98,7 +97,7 @@ public void onPlayerQuickLockChest(PlayerInteractEvent event){
9897
// Manual protection
9998
@EventHandler(priority = EventPriority.NORMAL)
10099
public void onManualLock(SignChangeEvent event){
101-
if (event.getBlock().getType() != Material.WALL_SIGN || Config.isDisabledWorld(event.getBlock())) return;
100+
if (event.getBlock().getType() != Material.WALL_SIGN) return;
102101
String topline = event.getLine(0);
103102
Player player = event.getPlayer();
104103
/* Issue #46 - Old version of Minecraft trim signs in unexpected way.
@@ -167,9 +166,8 @@ public void onManualLock(SignChangeEvent event){
167166
}
168167

169168
// Player select sign
170-
@EventHandler(priority = EventPriority.LOW)
169+
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
171170
public void playerSelectSign(PlayerInteractEvent event){
172-
if (event.isCancelled() || Config.isDisabledWorld(event.getClickedBlock())) return;
173171
if (event.getAction() == Action.RIGHT_CLICK_BLOCK && event.getClickedBlock().getType() == Material.WALL_SIGN){
174172
Block block = event.getClickedBlock();
175173
Player player = event.getPlayer();
@@ -183,9 +181,8 @@ public void playerSelectSign(PlayerInteractEvent event){
183181
}
184182

185183
// Player break sign
186-
@EventHandler(priority = EventPriority.HIGH)
184+
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
187185
public void onAttemptBreakSign(BlockBreakEvent event){
188-
if (event.isCancelled() || Config.isDisabledWorld(event.getBlock())) return;
189186
Block block = event.getBlock();
190187
Player player = event.getPlayer();
191188
if (player.hasPermission("lockettepro.admin.break")) return;
@@ -217,9 +214,8 @@ public void onAttemptBreakSign(BlockBreakEvent event){
217214
}
218215

219216
// Protect block from being destroyed
220-
@EventHandler(priority = EventPriority.HIGH)
217+
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
221218
public void onAttemptBreakLockedBlocks(BlockBreakEvent event){
222-
if (event.isCancelled() || Config.isDisabledWorld(event.getBlock())) return;
223219
Block block = event.getBlock();
224220
Player player = event.getPlayer();
225221
if (LocketteProAPI.isLocked(block) || LocketteProAPI.isUpDownLockedDoor(block)){
@@ -232,7 +228,6 @@ public void onAttemptBreakLockedBlocks(BlockBreakEvent event){
232228
// Protect block from being used & handle double doors
233229
@EventHandler(priority = EventPriority.HIGH)
234230
public void onAttemptInteractLockedBlocks(PlayerInteractEvent event){
235-
if (Config.isDisabledWorld(event.getClickedBlock())) return;
236231
Action action = event.getAction();
237232
Block block = event.getClickedBlock();
238233
if (LockettePro.needCheckHand()){
@@ -289,9 +284,8 @@ public void onAttemptInteractLockedBlocks(PlayerInteractEvent event){
289284
}
290285

291286
// Protect block from interfere block
292-
@EventHandler(priority = EventPriority.HIGH)
287+
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
293288
public void onAttemptPlaceInterfereBlocks(BlockPlaceEvent event){
294-
if (event.isCancelled() || Config.isDisabledWorld(event.getBlock())) return;
295289
Block block = event.getBlock();
296290
Player player = event.getPlayer();
297291
if (player.hasPermission("lockettepro.admin.interfere")) return;
@@ -303,9 +297,8 @@ public void onAttemptPlaceInterfereBlocks(BlockPlaceEvent event){
303297
}
304298

305299
// Tell player about lockettepro
306-
@EventHandler(priority = EventPriority.MONITOR)
300+
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
307301
public void onPlaceFirstBlockNotify(BlockPlaceEvent event){
308-
if (event.isCancelled() || Config.isDisabledWorld(event.getBlock())) return;
309302
Block block = event.getBlock();
310303
Player player = event.getPlayer();
311304
if (!player.hasPermission("lockettepro.lock")) return;

src/me/crafter/mc/lockettepro/Config.java

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,7 @@
88
import java.util.Set;
99

1010
import org.bukkit.ChatColor;
11-
import org.bukkit.Location;
1211
import org.bukkit.Material;
13-
import org.bukkit.block.Block;
1412
import org.bukkit.configuration.file.FileConfiguration;
1513
import org.bukkit.configuration.file.YamlConfiguration;
1614
import org.bukkit.plugin.Plugin;
@@ -296,12 +294,4 @@ public static boolean isDisabledWorld(String worldName){
296294
return disableWorlds.contains(worldName);
297295
}
298296

299-
public static boolean isDisabledWorld(Block block){
300-
return block != null && block.getWorld() != null && isDisabledWorld(block.getWorld().getName());
301-
}
302-
303-
public static boolean isDisabledWorld(Location location){
304-
return location != null && location.getWorld() != null && isDisabledWorld(location.getWorld().getName());
305-
}
306-
307297
}

src/me/crafter/mc/lockettepro/LocketteProAPI.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ public class LocketteProAPI {
1717

1818
public static boolean isLocked(Block block){
1919
if (block == null) return false;
20+
// World check
21+
if (Config.isDisabledWorld(block.getWorld().getName())) return false;
2022
switch (block.getType()){
2123
// Double Doors
2224
case WOODEN_DOOR:
@@ -208,6 +210,8 @@ public static boolean isOwnerOfSign(Block block, Player player){ // Requires isS
208210
}
209211

210212
public static boolean isLockable(Block block){
213+
// World check
214+
if (block != null && Config.isDisabledWorld(block.getWorld().getName())) return false;
211215
Material material = block.getType();
212216
//Bad blocks
213217
switch (material){

0 commit comments

Comments
 (0)