From bf214afe2e0fa1b25a5a06b57a9fe8044a26e5fd Mon Sep 17 00:00:00 2001 From: Adam Date: Sat, 19 Sep 2020 17:14:11 -0400 Subject: [PATCH] Use enhanced for loop where applicable (#1016) --- .../GriefPrevention/BlockEventHandler.java | 7 +- .../ryanhamshire/GriefPrevention/Claim.java | 27 +++---- .../CleanupUnusedClaimTask.java | 12 ++-- .../GriefPrevention/CustomLogger.java | 3 +- .../GriefPrevention/DataStore.java | 33 ++++----- .../GriefPrevention/EntityCleanupTask.java | 4 +- .../GriefPrevention/EntityEventHandler.java | 4 +- .../GriefPrevention/FlatFileDataStore.java | 16 ++--- .../GriefPrevention/GriefPrevention.java | 72 +++++++++---------- .../GriefPrevention/PlayerEventHandler.java | 3 +- .../RestoreNatureExecutionTask.java | 3 +- .../RestoreNatureProcessingTask.java | 4 +- .../GriefPrevention/UUIDFetcher.java | 5 +- 13 files changed, 76 insertions(+), 117 deletions(-) diff --git a/src/main/java/me/ryanhamshire/GriefPrevention/BlockEventHandler.java b/src/main/java/me/ryanhamshire/GriefPrevention/BlockEventHandler.java index 097337b..bd26ea3 100644 --- a/src/main/java/me/ryanhamshire/GriefPrevention/BlockEventHandler.java +++ b/src/main/java/me/ryanhamshire/GriefPrevention/BlockEventHandler.java @@ -233,10 +233,8 @@ public class BlockEventHandler implements Listener if (block.getType() == Material.FIRE && !doesAllowFireProximityInWorld(block.getWorld())) { List players = block.getWorld().getPlayers(); - for (int i = 0; i < players.size(); i++) + for (Player otherPlayer : players) { - Player otherPlayer = players.get(i); - // Ignore players in creative or spectator mode to avoid users from checking if someone is spectating near them if (otherPlayer.getGameMode() == GameMode.CREATIVE || otherPlayer.getGameMode() == GameMode.SPECTATOR) { @@ -784,9 +782,8 @@ public class BlockEventHandler implements Listener }; //pro-actively put out any fires adjacent the burning block, to reduce future processing here - for (int i = 0; i < adjacentBlocks.length; i++) + for (Block adjacentBlock : adjacentBlocks) { - Block adjacentBlock = adjacentBlocks[i]; if (adjacentBlock.getType() == Material.FIRE && adjacentBlock.getRelative(BlockFace.DOWN).getType() != Material.NETHERRACK) { adjacentBlock.setType(Material.AIR); diff --git a/src/main/java/me/ryanhamshire/GriefPrevention/Claim.java b/src/main/java/me/ryanhamshire/GriefPrevention/Claim.java index 7a4dea5..40ea03c 100644 --- a/src/main/java/me/ryanhamshire/GriefPrevention/Claim.java +++ b/src/main/java/me/ryanhamshire/GriefPrevention/Claim.java @@ -33,7 +33,6 @@ import java.util.Calendar; import java.util.Date; import java.util.EnumSet; import java.util.HashMap; -import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.UUID; @@ -597,15 +596,15 @@ public class Claim if (this.allowEdit(player) == null) return null; //anyone who's in the managers (/PermissionTrust) list can do this - for (int i = 0; i < this.managers.size(); i++) + for (String managerID : this.managers) { - String managerID = this.managers.get(i); + if (managerID == null) continue; if (player.getUniqueId().toString().equals(managerID)) return null; else if (managerID.startsWith("[") && managerID.endsWith("]")) { managerID = managerID.substring(1, managerID.length() - 1); - if (managerID == null || managerID.isEmpty()) continue; + if (managerID.isEmpty()) continue; if (player.hasPermission(managerID)) return null; } } @@ -675,11 +674,8 @@ public class Claim public void getPermissions(ArrayList builders, ArrayList containers, ArrayList accessors, ArrayList managers) { //loop through all the entries in the hash map - Iterator> mappingsIterator = this.playerIDToClaimPermissionMap.entrySet().iterator(); - while (mappingsIterator.hasNext()) + for (Map.Entry entry : this.playerIDToClaimPermissionMap.entrySet()) { - Map.Entry entry = mappingsIterator.next(); - //build up a list for each permission level if (entry.getValue() == ClaimPermission.Build) { @@ -696,10 +692,7 @@ public class Claim } //managers are handled a little differently - for (int i = 0; i < this.managers.size(); i++) - { - managers.add(this.managers.get(i)); - } + managers.addAll(this.managers); } //returns a copy of the location representing lower x, y, z limits @@ -761,10 +754,10 @@ public class Claim else if (excludeSubdivisions) { //search all subdivisions to see if the location is in any of them - for (int i = 0; i < this.children.size(); i++) + for (Claim child : this.children) { //if we find such a subdivision, return false - if (this.children.get(i).contains(location, ignoreHeight, true)) + if (child.contains(location, ignoreHeight, true)) { return false; } @@ -814,9 +807,8 @@ public class Claim for (Chunk chunk : chunks) { Entity[] entities = chunk.getEntities(); - for (int i = 0; i < entities.length; i++) + for (Entity entity : entities) { - Entity entity = entities[i]; if (!(entity instanceof Player) && this.contains(entity.getLocation(), false, false)) { totalEntities++; @@ -846,9 +838,8 @@ public class Claim for (Chunk chunk : chunks) { BlockState[] actives = chunk.getTileEntities(); - for (int i = 0; i < actives.length; i++) + for (BlockState active : actives) { - BlockState active = actives[i]; if (BlockEventHandler.isActiveBlock(active)) { if (this.contains(active.getLocation(), false, false)) diff --git a/src/main/java/me/ryanhamshire/GriefPrevention/CleanupUnusedClaimTask.java b/src/main/java/me/ryanhamshire/GriefPrevention/CleanupUnusedClaimTask.java index e092b36..abf620e 100644 --- a/src/main/java/me/ryanhamshire/GriefPrevention/CleanupUnusedClaimTask.java +++ b/src/main/java/me/ryanhamshire/GriefPrevention/CleanupUnusedClaimTask.java @@ -86,11 +86,7 @@ class CleanupUnusedClaimTask implements Runnable if (expireEventCanceled()) return; //make a copy of this player's claim list - Vector claims = new Vector<>(); - for (int i = 0; i < ownerData.getClaims().size(); i++) - { - claims.add(ownerData.getClaims().get(i)); - } + Vector claims = new Vector<>(ownerData.getClaims()); //delete them GriefPrevention.instance.dataStore.deleteClaimsForPlayer(claim.ownerID, true); @@ -98,12 +94,12 @@ class CleanupUnusedClaimTask implements Runnable GriefPrevention.AddLogEntry("earliestPermissibleLastLogin#getTime: " + earliestPermissibleLastLogin.getTime(), CustomLogEntryTypes.Debug, true); GriefPrevention.AddLogEntry("ownerInfo#getLastPlayed: " + ownerInfo.getLastPlayed(), CustomLogEntryTypes.Debug, true); - for (int i = 0; i < claims.size(); i++) + for (Claim claim : claims) { //if configured to do so, restore the land to natural - if (GriefPrevention.instance.creativeRulesApply(claims.get(i).getLesserBoundaryCorner()) || GriefPrevention.instance.config_claims_survivalAutoNatureRestoration) + if (GriefPrevention.instance.creativeRulesApply(claim.getLesserBoundaryCorner()) || GriefPrevention.instance.config_claims_survivalAutoNatureRestoration) { - GriefPrevention.instance.restoreClaim(claims.get(i), 0); + GriefPrevention.instance.restoreClaim(claim, 0); } } } diff --git a/src/main/java/me/ryanhamshire/GriefPrevention/CustomLogger.java b/src/main/java/me/ryanhamshire/GriefPrevention/CustomLogger.java index 6db2083..afc4b6d 100644 --- a/src/main/java/me/ryanhamshire/GriefPrevention/CustomLogger.java +++ b/src/main/java/me/ryanhamshire/GriefPrevention/CustomLogger.java @@ -131,9 +131,8 @@ class CustomLogger int daysToKeepLogs = GriefPrevention.instance.config_logs_daysToKeep; Calendar expirationBoundary = Calendar.getInstance(); expirationBoundary.add(Calendar.DATE, -daysToKeepLogs); - for (int i = 0; i < files.length; i++) + for (File file : files) { - File file = files[i]; if (file.isDirectory()) continue; //skip any folders String filename = file.getName().replace(".log", ""); diff --git a/src/main/java/me/ryanhamshire/GriefPrevention/DataStore.java b/src/main/java/me/ryanhamshire/GriefPrevention/DataStore.java index 33d4a10..fe67c44 100644 --- a/src/main/java/me/ryanhamshire/GriefPrevention/DataStore.java +++ b/src/main/java/me/ryanhamshire/GriefPrevention/DataStore.java @@ -348,16 +348,17 @@ public abstract class DataStore //this will return 0 when he's offline, and the correct number when online. synchronized public int getGroupBonusBlocks(UUID playerID) { + Player player = GriefPrevention.instance.getServer().getPlayer(playerID); + + if (player == null) return 0; + int bonusBlocks = 0; - Set keys = permissionToBonusBlocksMap.keySet(); - Iterator iterator = keys.iterator(); - while (iterator.hasNext()) + + for (Map.Entry groupEntry : this.permissionToBonusBlocksMap.entrySet()) { - String groupName = iterator.next(); - Player player = GriefPrevention.instance.getServer().getPlayer(playerID); - if (player != null && player.hasPermission(groupName)) + if (player.hasPermission(groupEntry.getKey())) { - bonusBlocks += this.permissionToBonusBlocksMap.get(groupName); + bonusBlocks += groupEntry.getValue(); } } @@ -923,10 +924,8 @@ public abstract class DataStore claimsToCheck = this.claims; } - for (int i = 0; i < claimsToCheck.size(); i++) + for (Claim otherClaim : claimsToCheck) { - Claim otherClaim = claimsToCheck.get(i); - //if we find an existing claim which will be overlapped if (otherClaim.id != newClaim.id && otherClaim.inDataStore && otherClaim.overlaps(newClaim)) { @@ -1187,10 +1186,9 @@ public abstract class DataStore //drop any remainder on the ground at his feet Object[] keys = wontFitItems.keySet().toArray(); Location winnerLocation = winner.getLocation(); - for (int i = 0; i < keys.length; i++) + for (Map.Entry wontFitItem : wontFitItems.entrySet()) { - Integer key = (Integer) keys[i]; - winnerLocation.getWorld().dropItemNaturally(winnerLocation, wontFitItems.get(key)); + winner.getWorld().dropItemNaturally(winnerLocation, wontFitItem.getValue()); } } @@ -1276,17 +1274,15 @@ public abstract class DataStore { //make a list of the player's claims ArrayList claimsToDelete = new ArrayList<>(); - for (int i = 0; i < this.claims.size(); i++) + for (Claim claim : this.claims) { - Claim claim = this.claims.get(i); if ((playerID == claim.ownerID || (playerID != null && playerID.equals(claim.ownerID)))) claimsToDelete.add(claim); } //delete them one by one - for (int i = 0; i < claimsToDelete.size(); i++) + for (Claim claim : claimsToDelete) { - Claim claim = claimsToDelete.get(i); claim.removeSurfaceFluids(null); this.deleteClaim(claim, releasePets); @@ -1737,10 +1733,9 @@ public abstract class DataStore FileConfiguration config = YamlConfiguration.loadConfiguration(new File(messagesFilePath)); //for each message ID - for (int i = 0; i < messageIDs.length; i++) + for (Messages messageID : messageIDs) { //get default for this message - Messages messageID = messageIDs[i]; CustomizableMessage messageData = defaults.get(messageID.name()); //if default is missing, log an error and use some fake data for now so that the plugin can run diff --git a/src/main/java/me/ryanhamshire/GriefPrevention/EntityCleanupTask.java b/src/main/java/me/ryanhamshire/GriefPrevention/EntityCleanupTask.java index 5df141d..35e2399 100644 --- a/src/main/java/me/ryanhamshire/GriefPrevention/EntityCleanupTask.java +++ b/src/main/java/me/ryanhamshire/GriefPrevention/EntityCleanupTask.java @@ -54,10 +54,8 @@ class EntityCleanupTask implements Runnable } } - for (int i = 0; i < worlds.size(); i++) + for (World world : worlds) { - World world = worlds.get(i); - List entities = world.getEntities(); //starting and stopping point. each execution of the task scans 10% of the server's (loaded) entities diff --git a/src/main/java/me/ryanhamshire/GriefPrevention/EntityEventHandler.java b/src/main/java/me/ryanhamshire/GriefPrevention/EntityEventHandler.java index 50e32b5..f8e293d 100644 --- a/src/main/java/me/ryanhamshire/GriefPrevention/EntityEventHandler.java +++ b/src/main/java/me/ryanhamshire/GriefPrevention/EntityEventHandler.java @@ -344,10 +344,8 @@ public class EntityEventHandler implements Listener //make a list of blocks which were allowed to explode List explodedBlocks = new ArrayList<>(); Claim cachedClaim = null; - for (int i = 0; i < blocks.size(); i++) + for (Block block : blocks) { - Block block = blocks.get(i); - //always ignore air blocks if (block.getType() == Material.AIR) continue; diff --git a/src/main/java/me/ryanhamshire/GriefPrevention/FlatFileDataStore.java b/src/main/java/me/ryanhamshire/GriefPrevention/FlatFileDataStore.java index 248bcf7..9d21dd6 100644 --- a/src/main/java/me/ryanhamshire/GriefPrevention/FlatFileDataStore.java +++ b/src/main/java/me/ryanhamshire/GriefPrevention/FlatFileDataStore.java @@ -39,6 +39,7 @@ import java.util.Arrays; import java.util.Date; import java.util.Iterator; import java.util.List; +import java.util.Map; import java.util.UUID; import java.util.concurrent.ConcurrentHashMap; import java.util.regex.Matcher; @@ -85,9 +86,8 @@ public class FlatFileDataStore extends DataStore //load group data into memory File[] files = playerDataFolder.listFiles(); - for (int i = 0; i < files.length; i++) + for (File file : files) { - File file = files[i]; if (!file.isFile()) continue; //avoids folders //all group data files start with a dollar sign. ignoring the rest, which are player data files. @@ -801,9 +801,8 @@ public class FlatFileDataStore extends DataStore synchronized void migrateData(DatabaseDataStore databaseStore) { //migrate claims - for (int i = 0; i < this.claims.size(); i++) + for (Claim claim : this.claims) { - Claim claim = this.claims.get(i); databaseStore.addClaim(claim, true); for (Claim child : claim.children) { @@ -812,19 +811,16 @@ public class FlatFileDataStore extends DataStore } //migrate groups - Iterator groupNamesEnumerator = this.permissionToBonusBlocksMap.keySet().iterator(); - while (groupNamesEnumerator.hasNext()) + for (Map.Entry groupEntry : this.permissionToBonusBlocksMap.entrySet()) { - String groupName = groupNamesEnumerator.next(); - databaseStore.saveGroupBonusBlocks(groupName, this.permissionToBonusBlocksMap.get(groupName)); + databaseStore.saveGroupBonusBlocks(groupEntry.getKey(), groupEntry.getValue()); } //migrate players File playerDataFolder = new File(playerDataFolderPath); File[] files = playerDataFolder.listFiles(); - for (int i = 0; i < files.length; i++) + for (File file : files) { - File file = files[i]; if (!file.isFile()) continue; //avoids folders if (file.isHidden()) continue; //avoid hidden files, which are likely not created by GriefPrevention diff --git a/src/main/java/me/ryanhamshire/GriefPrevention/GriefPrevention.java b/src/main/java/me/ryanhamshire/GriefPrevention/GriefPrevention.java index 8bbf398..16c8689 100644 --- a/src/main/java/me/ryanhamshire/GriefPrevention/GriefPrevention.java +++ b/src/main/java/me/ryanhamshire/GriefPrevention/GriefPrevention.java @@ -541,11 +541,11 @@ public class GriefPrevention extends JavaPlugin //sea level this.config_seaLevelOverride = new HashMap<>(); - for (int i = 0; i < worlds.size(); i++) + for (World world : worlds) { - int seaLevelOverride = config.getInt("GriefPrevention.SeaLevelOverrides." + worlds.get(i).getName(), -1); - outConfig.set("GriefPrevention.SeaLevelOverrides." + worlds.get(i).getName(), seaLevelOverride); - this.config_seaLevelOverride.put(worlds.get(i).getName(), seaLevelOverride); + int seaLevelOverride = config.getInt("GriefPrevention.SeaLevelOverrides." + world.getName(), -1); + outConfig.set("GriefPrevention.SeaLevelOverrides." + world.getName(), seaLevelOverride); + this.config_seaLevelOverride.put(world.getName(), seaLevelOverride); } this.config_claims_preventGlobalMonsterEggs = config.getBoolean("GriefPrevention.Claims.PreventGlobalMonsterEggs", true); @@ -690,9 +690,8 @@ public class GriefPrevention extends JavaPlugin //validate that list this.config_siege_enabledWorlds = new ArrayList<>(); - for (int i = 0; i < siegeEnabledWorldNames.size(); i++) + for (String worldName : siegeEnabledWorldNames) { - String worldName = siegeEnabledWorldNames.get(i); World world = this.getServer().getWorld(worldName); if (world == null) { @@ -742,9 +741,9 @@ public class GriefPrevention extends JavaPlugin //build a default config entry ArrayList defaultBreakableBlocksList = new ArrayList<>(); - for (int i = 0; i < this.config_siege_blocks.size(); i++) + for (Material siegeBlock : this.config_siege_blocks) { - defaultBreakableBlocksList.add(this.config_siege_blocks.get(i).name()); + defaultBreakableBlocksList.add(siegeBlock.name()); } //try to load the list from the config file @@ -758,9 +757,8 @@ public class GriefPrevention extends JavaPlugin //parse the list of siege-breakable blocks this.config_siege_blocks = new ArrayList<>(); - for (int i = 0; i < breakableBlocksList.size(); i++) + for (String blockName : breakableBlocksList) { - String blockName = breakableBlocksList.get(i); Material material = Material.getMaterial(blockName); if (material == null) { @@ -950,36 +948,36 @@ public class GriefPrevention extends JavaPlugin //try to parse the list of commands requiring access trust in land claims this.config_claims_commandsRequiringAccessTrust = new ArrayList<>(); String[] commands = accessTrustSlashCommands.split(";"); - for (int i = 0; i < commands.length; i++) + for (String command : commands) { - if (!commands[i].isEmpty()) + if (!command.isEmpty()) { - this.config_claims_commandsRequiringAccessTrust.add(commands[i].trim().toLowerCase()); + this.config_claims_commandsRequiringAccessTrust.add(command.trim().toLowerCase()); } } //try to parse the list of commands which should be monitored for spam this.config_spam_monitorSlashCommands = new ArrayList<>(); commands = slashCommandsToMonitor.split(";"); - for (int i = 0; i < commands.length; i++) + for (String command : commands) { - this.config_spam_monitorSlashCommands.add(commands[i].trim().toLowerCase()); + this.config_spam_monitorSlashCommands.add(command.trim().toLowerCase()); } //try to parse the list of commands which should be included in eavesdropping this.config_eavesdrop_whisperCommands = new ArrayList<>(); commands = whisperCommandsToMonitor.split(";"); - for (int i = 0; i < commands.length; i++) + for (String command : commands) { - this.config_eavesdrop_whisperCommands.add(commands[i].trim().toLowerCase()); + this.config_eavesdrop_whisperCommands.add(command.trim().toLowerCase()); } //try to parse the list of commands which should be banned during pvp combat this.config_pvp_blockedCommands = new ArrayList<>(); commands = bannedPvPCommandsList.split(";"); - for (int i = 0; i < commands.length; i++) + for (String command : commands) { - this.config_pvp_blockedCommands.add(commands[i].trim().toLowerCase()); + this.config_pvp_blockedCommands.add(command.trim().toLowerCase()); } } @@ -1501,8 +1499,8 @@ public class GriefPrevention extends JavaPlugin if (managers.size() > 0) { - for (int i = 0; i < managers.size(); i++) - permissions.append(this.trustEntryToPlayerName(managers.get(i)) + " "); + for (String manager : managers) + permissions.append(this.trustEntryToPlayerName(manager) + " "); } player.sendMessage(permissions.toString()); @@ -1511,8 +1509,8 @@ public class GriefPrevention extends JavaPlugin if (builders.size() > 0) { - for (int i = 0; i < builders.size(); i++) - permissions.append(this.trustEntryToPlayerName(builders.get(i)) + " "); + for (String builder : builders) + permissions.append(this.trustEntryToPlayerName(builder) + " "); } player.sendMessage(permissions.toString()); @@ -1521,8 +1519,8 @@ public class GriefPrevention extends JavaPlugin if (containers.size() > 0) { - for (int i = 0; i < containers.size(); i++) - permissions.append(this.trustEntryToPlayerName(containers.get(i)) + " "); + for (String container : containers) + permissions.append(this.trustEntryToPlayerName(container) + " "); } player.sendMessage(permissions.toString()); @@ -1531,8 +1529,8 @@ public class GriefPrevention extends JavaPlugin if (accessors.size() > 0) { - for (int i = 0; i < accessors.size(); i++) - permissions.append(this.trustEntryToPlayerName(accessors.get(i)) + " "); + for (String accessor : accessors) + permissions.append(this.trustEntryToPlayerName(accessor) + " "); } player.sendMessage(permissions.toString()); @@ -2252,9 +2250,8 @@ public class GriefPrevention extends JavaPlugin if (claims.size() > 0) { GriefPrevention.sendMessage(player, TextMode.Instr, Messages.ClaimsListHeader); - for (int i = 0; i < claims.size(); i++) + for (Claim claim : claims) { - Claim claim = claims.get(i); GriefPrevention.sendMessage(player, TextMode.Instr, getfriendlyLocationString(claim.getLesserBoundaryCorner())); } } @@ -3008,10 +3005,7 @@ public class GriefPrevention extends JavaPlugin if (claim == null) { PlayerData playerData = this.dataStore.getPlayerData(player.getUniqueId()); - for (int i = 0; i < playerData.getClaims().size(); i++) - { - targetClaims.add(playerData.getClaims().get(i)); - } + targetClaims.addAll(playerData.getClaims()); } else { @@ -3088,10 +3082,8 @@ public class GriefPrevention extends JavaPlugin } //apply changes - for (int i = 0; i < targetClaims.size(); i++) + for (Claim currentClaim : targetClaims) { - Claim currentClaim = targetClaims.get(i); - if (permissionLevel == null) { if (!currentClaim.managers.contains(identifierToAdd)) @@ -3310,16 +3302,16 @@ public class GriefPrevention extends JavaPlugin ItemStack[] armorStacks = inventory.getArmorContents(); //check armor slots, stop if any items are found - for (int i = 0; i < armorStacks.length; i++) + for (ItemStack armorStack : armorStacks) { - if (!(armorStacks[i] == null || armorStacks[i].getType() == Material.AIR)) return false; + if (!(armorStack == null || armorStack.getType() == Material.AIR)) return false; } //check other slots, stop if any items are found ItemStack[] generalStacks = inventory.getContents(); - for (int i = 0; i < generalStacks.length; i++) + for (ItemStack generalStack : generalStacks) { - if (!(generalStacks[i] == null || generalStacks[i].getType() == Material.AIR)) return false; + if (!(generalStack == null || generalStack.getType() == Material.AIR)) return false; } return true; diff --git a/src/main/java/me/ryanhamshire/GriefPrevention/PlayerEventHandler.java b/src/main/java/me/ryanhamshire/GriefPrevention/PlayerEventHandler.java index 2b53ca1..5a05352 100644 --- a/src/main/java/me/ryanhamshire/GriefPrevention/PlayerEventHandler.java +++ b/src/main/java/me/ryanhamshire/GriefPrevention/PlayerEventHandler.java @@ -1498,9 +1498,8 @@ class PlayerEventHandler implements Listener if (bucketEvent.getBucket() == Material.LAVA_BUCKET) { List players = block.getWorld().getPlayers(); - for (int i = 0; i < players.size(); i++) + for (Player otherPlayer : players) { - Player otherPlayer = players.get(i); Location location = otherPlayer.getLocation(); if (!otherPlayer.equals(player) && otherPlayer.getGameMode() == GameMode.SURVIVAL && player.canSee(otherPlayer) && block.getY() >= location.getBlockY() - 1 && location.distanceSquared(block.getLocation()) < minLavaDistance * minLavaDistance) { diff --git a/src/main/java/me/ryanhamshire/GriefPrevention/RestoreNatureExecutionTask.java b/src/main/java/me/ryanhamshire/GriefPrevention/RestoreNatureExecutionTask.java index 99646f8..583b66e 100644 --- a/src/main/java/me/ryanhamshire/GriefPrevention/RestoreNatureExecutionTask.java +++ b/src/main/java/me/ryanhamshire/GriefPrevention/RestoreNatureExecutionTask.java @@ -97,9 +97,8 @@ class RestoreNatureExecutionTask implements Runnable //clean up any entities in the chunk, ensure no players are suffocated Chunk chunk = this.lesserCorner.getChunk(); Entity[] entities = chunk.getEntities(); - for (int i = 0; i < entities.length; i++) + for (Entity entity : entities) { - Entity entity = entities[i]; if (!(entity instanceof Player || entity instanceof Animals)) { //hanging entities (paintings, item frames) are protected when they're in land claims diff --git a/src/main/java/me/ryanhamshire/GriefPrevention/RestoreNatureProcessingTask.java b/src/main/java/me/ryanhamshire/GriefPrevention/RestoreNatureProcessingTask.java index fea3e63..361afd0 100644 --- a/src/main/java/me/ryanhamshire/GriefPrevention/RestoreNatureProcessingTask.java +++ b/src/main/java/me/ryanhamshire/GriefPrevention/RestoreNatureProcessingTask.java @@ -28,6 +28,7 @@ import org.bukkit.block.data.type.Leaves; import org.bukkit.entity.Player; import java.util.ArrayList; +import java.util.Arrays; //non-main-thread task which processes world data to repair the unnatural //after processing is complete, creates a main thread task to make the necessary changes to the world @@ -390,8 +391,7 @@ class RestoreNatureProcessingTask implements Runnable Material.LILY_PAD }; - ArrayList excludedBlocks = new ArrayList<>(); - for (int i = 0; i < excludedBlocksArray.length; i++) excludedBlocks.add(excludedBlocksArray[i]); + ArrayList excludedBlocks = new ArrayList<>(Arrays.asList(excludedBlocksArray)); excludedBlocks.addAll(Tag.SAPLINGS.getValues()); excludedBlocks.addAll(Tag.LEAVES.getValues()); diff --git a/src/main/java/me/ryanhamshire/GriefPrevention/UUIDFetcher.java b/src/main/java/me/ryanhamshire/GriefPrevention/UUIDFetcher.java index 620bdae..e690133 100644 --- a/src/main/java/me/ryanhamshire/GriefPrevention/UUIDFetcher.java +++ b/src/main/java/me/ryanhamshire/GriefPrevention/UUIDFetcher.java @@ -167,10 +167,9 @@ class UUIDFetcher { GriefPrevention.AddLogEntry("Generating offline mode UUIDs for remaining unresolved players..."); - for (int i = 0; i < names.size(); i++) + for (String name : names) { - String name = names.get(i); - UUID uuid = java.util.UUID.nameUUIDFromBytes(("OfflinePlayer:" + name).getBytes(Charsets.UTF_8)); + UUID uuid = UUID.nameUUIDFromBytes(("OfflinePlayer:" + name).getBytes(Charsets.UTF_8)); GriefPrevention.AddLogEntry(name + " --> " + uuid.toString()); lookupCache.put(name, uuid); lookupCache.put(name.toLowerCase(), uuid);