Skip to content

Commit 6ea53b2

Browse files
committed
Update config method
1 parent 1b63c02 commit 6ea53b2

File tree

3 files changed

+27
-30
lines changed

3 files changed

+27
-30
lines changed

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

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +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")) return;
26-
if (event.getLocation() != null && Config.isDisabledWorld(event.getLocation().getWorld().getName())) return;
25+
if (Config.isProtectionExempted("explosion") || Config.isDisabledWorld(event.getLocation())) return;
2726
Iterator<Block> it = event.blockList().iterator();
2827
while (it.hasNext()) {
2928
Block block = it.next();
@@ -34,8 +33,7 @@ public void onEntityExplode(EntityExplodeEvent event){
3433
// Prevent bed break block
3534
@EventHandler(priority = EventPriority.HIGH)
3635
public void onBlockExplode(BlockExplodeEvent event){
37-
if (Config.isProtectionExempted("explosion")) return;
38-
if (event.getBlock() != null && Config.isDisabledWorld(event.getBlock().getWorld().getName())) return;
36+
if (Config.isProtectionExempted("explosion") || Config.isDisabledWorld(event.getBlock())) return;
3937
Iterator<Block> it = event.blockList().iterator();
4038
while (it.hasNext()) {
4139
Block block = it.next();
@@ -46,8 +44,7 @@ public void onBlockExplode(BlockExplodeEvent event){
4644
// Prevent tree break block
4745
@EventHandler(priority = EventPriority.HIGH)
4846
public void onStructureGrow(StructureGrowEvent event){
49-
if (Config.isProtectionExempted("growth")) return;
50-
if (event.getWorld() != null && Config.isDisabledWorld(event.getWorld().getName())) return;
47+
if (Config.isProtectionExempted("growth") || Config.isDisabledWorld(event.getWorld().getName())) return;
5148
for (BlockState blockstate : event.getBlocks()){
5249
if (LocketteProAPI.isProtected(blockstate.getBlock())){
5350
event.setCancelled(true);
@@ -59,8 +56,7 @@ public void onStructureGrow(StructureGrowEvent event){
5956
// Prevent piston extend break lock
6057
@EventHandler(priority = EventPriority.HIGH)
6158
public void onPistonExtend(BlockPistonExtendEvent event){
62-
if (Config.isProtectionExempted("piston")) return;
63-
if (event.getBlock() != null && Config.isDisabledWorld(event.getBlock().getWorld().getName())) return;
59+
if (Config.isProtectionExempted("piston") || Config.isDisabledWorld(event.getBlock())) return;
6460
for (Block block : event.getBlocks()){
6561
if (LocketteProAPI.isProtected(block)){
6662
event.setCancelled(true);
@@ -72,8 +68,7 @@ public void onPistonExtend(BlockPistonExtendEvent event){
7268
// Prevent piston retract break lock
7369
@EventHandler(priority = EventPriority.HIGH)
7470
public void onPistonRetract(BlockPistonRetractEvent event){
75-
if (Config.isProtectionExempted("piston")) return;
76-
if (event.getBlock() != null && Config.isDisabledWorld(event.getBlock().getWorld().getName())) return;
71+
if (Config.isProtectionExempted("piston") || Config.isDisabledWorld(event.getBlock())) return;
7772
for (Block block : event.getBlocks()){
7873
if (LocketteProAPI.isProtected(block)){
7974
event.setCancelled(true);
@@ -85,8 +80,7 @@ public void onPistonRetract(BlockPistonRetractEvent event){
8580
// Prevent redstone current open doors
8681
@EventHandler(priority = EventPriority.HIGH)
8782
public void onBlockRedstoneChange(BlockRedstoneEvent event){
88-
if (Config.isProtectionExempted("redstone")) return;
89-
if (event.getBlock() != null && Config.isDisabledWorld(event.getBlock().getWorld().getName())) return;
83+
if (Config.isProtectionExempted("redstone") || Config.isDisabledWorld(event.getBlock())) return;
9084
if (LocketteProAPI.isProtected(event.getBlock())){
9185
event.setNewCurrent(event.getOldCurrent());
9286
}
@@ -95,8 +89,7 @@ public void onBlockRedstoneChange(BlockRedstoneEvent event){
9589
// Prevent villager open door
9690
@EventHandler(priority = EventPriority.HIGH)
9791
public void onVillagerOpenDoor(EntityInteractEvent event){
98-
if (Config.isProtectionExempted("villager")) return;
99-
if (event.getBlock() != null && Config.isDisabledWorld(event.getBlock().getWorld().getName())) return;
92+
if (Config.isProtectionExempted("villager") || Config.isDisabledWorld(event.getBlock())) return;
10093
// Explicitly to villager vs all doors
10194
if (event.getEntity() instanceof Villager &&
10295
(LocketteProAPI.isSingleDoorBlock(event.getBlock()) || LocketteProAPI.isDoubleDoorBlock(event.getBlock())) &&
@@ -108,8 +101,7 @@ public void onVillagerOpenDoor(EntityInteractEvent event){
108101
// Prevent Enderman take block
109102
@EventHandler(priority = EventPriority.HIGH)
110103
public void onEndermanGreif(EntityInteractEvent event){
111-
if (Config.isProtectionExempted("enderman")) return;
112-
if (event.getBlock() != null && Config.isDisabledWorld(event.getBlock().getWorld().getName())) return;
104+
if (Config.isProtectionExempted("enderman") || Config.isDisabledWorld(event.getBlock())) return;
113105
if (event.getEntity() instanceof Enderman && LocketteProAPI.isProtected(event.getBlock())){
114106
event.setCancelled(true);
115107
}

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

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public void onPlayerQuickLockChest(PlayerInteractEvent event){
2929
// Check quick lock enabled
3030
if (Config.getQuickProtectAction() == (byte)0) return;
3131
// Check world enabled
32-
if (event.getPlayer() != null && event.getPlayer().getWorld() != null && Config.isDisabledWorld(event.getPlayer().getWorld().getName())) return;
32+
if (Config.isDisabledWorld(event.getPlayer().getWorld().getName())) return;
3333
// Get player and action info
3434
Action action = event.getAction();
3535
Player player = event.getPlayer();
@@ -98,8 +98,7 @@ public void onPlayerQuickLockChest(PlayerInteractEvent event){
9898
// Manual protection
9999
@EventHandler(priority = EventPriority.NORMAL)
100100
public void onManualLock(SignChangeEvent event){
101-
if (event.getBlock().getType() != Material.WALL_SIGN) return;
102-
if (event.getPlayer() != null && event.getPlayer().getWorld() != null && Config.isDisabledWorld(event.getPlayer().getWorld().getName())) return;
101+
if (event.getBlock().getType() != Material.WALL_SIGN || Config.isDisabledWorld(event.getBlock())) return;
103102
String topline = event.getLine(0);
104103
Player player = event.getPlayer();
105104
/* Issue #46 - Old version of Minecraft trim signs in unexpected way.
@@ -170,7 +169,7 @@ public void onManualLock(SignChangeEvent event){
170169
// Player select sign
171170
@EventHandler(priority = EventPriority.LOW)
172171
public void playerSelectSign(PlayerInteractEvent event){
173-
if (event.getPlayer() != null && Config.isDisabledWorld(event.getPlayer().getWorld().getName())) return;
172+
if (event.isCancelled() || Config.isDisabledWorld(event.getClickedBlock())) return;
174173
if (event.getAction() == Action.RIGHT_CLICK_BLOCK && event.getClickedBlock().getType() == Material.WALL_SIGN){
175174
Block block = event.getClickedBlock();
176175
Player player = event.getPlayer();
@@ -186,8 +185,7 @@ public void playerSelectSign(PlayerInteractEvent event){
186185
// Player break sign
187186
@EventHandler(priority = EventPriority.HIGH)
188187
public void onAttemptBreakSign(BlockBreakEvent event){
189-
if (event.isCancelled()) return;
190-
if (event.getPlayer() != null && event.getPlayer().getWorld() != null && Config.isDisabledWorld(event.getPlayer().getWorld().getName())) return;
188+
if (event.isCancelled() || Config.isDisabledWorld(event.getBlock())) return;
191189
Block block = event.getBlock();
192190
Player player = event.getPlayer();
193191
if (player.hasPermission("lockettepro.admin.break")) return;
@@ -221,8 +219,7 @@ public void onAttemptBreakSign(BlockBreakEvent event){
221219
// Protect block from being destroyed
222220
@EventHandler(priority = EventPriority.HIGH)
223221
public void onAttemptBreakLockedBlocks(BlockBreakEvent event){
224-
if (event.isCancelled()) return;
225-
if (event.getPlayer() != null && event.getPlayer().getWorld() != null && Config.isDisabledWorld(event.getPlayer().getWorld().getName())) return;
222+
if (event.isCancelled() || Config.isDisabledWorld(event.getBlock())) return;
226223
Block block = event.getBlock();
227224
Player player = event.getPlayer();
228225
if (LocketteProAPI.isLocked(block) || LocketteProAPI.isUpDownLockedDoor(block)){
@@ -235,7 +232,7 @@ public void onAttemptBreakLockedBlocks(BlockBreakEvent event){
235232
// Protect block from being used & handle double doors
236233
@EventHandler(priority = EventPriority.HIGH)
237234
public void onAttemptInteractLockedBlocks(PlayerInteractEvent event){
238-
if (event.getPlayer() != null && event.getPlayer().getWorld() != null && Config.isDisabledWorld(event.getPlayer().getWorld().getName())) return;
235+
if (Config.isDisabledWorld(event.getClickedBlock())) return;
239236
Action action = event.getAction();
240237
Block block = event.getClickedBlock();
241238
if (LockettePro.needCheckHand()){
@@ -294,8 +291,7 @@ public void onAttemptInteractLockedBlocks(PlayerInteractEvent event){
294291
// Protect block from interfere block
295292
@EventHandler(priority = EventPriority.HIGH)
296293
public void onAttemptPlaceInterfereBlocks(BlockPlaceEvent event){
297-
if (event.isCancelled()) return;
298-
if (event.getPlayer() != null && event.getPlayer().getWorld() != null && Config.isDisabledWorld(event.getPlayer().getWorld().getName())) return;
294+
if (event.isCancelled() || Config.isDisabledWorld(event.getBlock())) return;
299295
Block block = event.getBlock();
300296
Player player = event.getPlayer();
301297
if (player.hasPermission("lockettepro.admin.interfere")) return;
@@ -309,8 +305,7 @@ public void onAttemptPlaceInterfereBlocks(BlockPlaceEvent event){
309305
// Tell player about lockettepro
310306
@EventHandler(priority = EventPriority.MONITOR)
311307
public void onPlaceFirstBlockNotify(BlockPlaceEvent event){
312-
if (event.isCancelled()) return;
313-
if (event.getPlayer() != null && event.getPlayer().getWorld() != null && Config.isDisabledWorld(event.getPlayer().getWorld().getName())) return;
308+
if (event.isCancelled() || Config.isDisabledWorld(event.getBlock())) return;
314309
Block block = event.getBlock();
315310
Player player = event.getPlayer();
316311
if (!player.hasPermission("lockettepro.lock")) return;

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

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

1010
import org.bukkit.ChatColor;
11+
import org.bukkit.Location;
1112
import org.bukkit.Material;
13+
import org.bukkit.block.Block;
1214
import org.bukkit.configuration.file.FileConfiguration;
1315
import org.bukkit.configuration.file.YamlConfiguration;
1416
import org.bukkit.plugin.Plugin;
@@ -202,7 +204,7 @@ public static void initDefaultConfig(){
202204
}
203205

204206
public static void initAdditionalFiles(){
205-
String[] availablefiles = {"lang.yml", "lang_zh-cn.yml", "lang_es.yml", "lang_it.yml"};
207+
String[] availablefiles = {"lang.yml", "lang_zh-cn.yml", "lang_zh-tw.yml", "lang_es.yml", "lang_it.yml"};
206208
for (String filename : availablefiles){
207209
File langfile = new File(plugin.getDataFolder(), filename);
208210
if (!langfile.exists()){
@@ -294,4 +296,12 @@ public static boolean isDisabledWorld(String worldName){
294296
return disableWorlds.contains(worldName);
295297
}
296298

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+
297307
}

0 commit comments

Comments
 (0)