Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
FrankHeijden committed May 27, 2019
1 parent 461af6f commit 16904b6
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 27 deletions.
33 changes: 30 additions & 3 deletions src/main/java/net/frankheijden/blocklimiter/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@
import org.apache.commons.lang.StringUtils;
import org.bukkit.*;
import org.bukkit.block.Block;
import org.bukkit.block.BlockState;
import org.bukkit.command.CommandSender;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;

import java.io.File;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.*;

public class Utils {
private BlockLimiter plugin;
Expand All @@ -21,6 +21,33 @@ public class Utils {
this.plugin = plugin;
}

public Set<Map.Entry<String, Integer>> getEntitiesInChunk(Chunk chunk) {
TreeMap<String, Integer> entryTreeMap = new TreeMap<>();
for (Entity entity : chunk.getEntities()) {
entryTreeMap.merge(entity.getType().name(), 1, Integer::sum);
}
return entryTreeMap.entrySet();
}

public Set<Map.Entry<String, Integer>> getTilesInChunk(Chunk chunk) {
TreeMap<String, Integer> entryTreeMap = new TreeMap<>();
for (BlockState bs : chunk.getTileEntities()) {
entryTreeMap.merge(bs.getType().name(), 1, Integer::sum);
}
return entryTreeMap.entrySet();
}

public Set<Map.Entry<String, Integer>> getEntitiesAndTilesInChunk(Chunk chunk) {
TreeMap<String, Integer> entryTreeMap = new TreeMap<>();
for (Entity entity : chunk.getEntities()) {
entryTreeMap.merge(entity.getType().name(), 1, Integer::sum);
}
for (BlockState bs : chunk.getTileEntities()) {
entryTreeMap.merge(bs.getType().name(), 1, Integer::sum);
}
return entryTreeMap.entrySet();
}

public int getAmountInChunk(Chunk chunk, Material material, Boolean isBreak) {
String chunkName = chunk.getX() + "_" + chunk.getZ();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,10 @@

import net.frankheijden.blocklimiter.BlockLimiter;
import org.bukkit.Chunk;
import org.bukkit.Material;
import org.bukkit.block.BlockState;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabExecutor;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.util.StringUtil;

Expand All @@ -34,14 +31,7 @@ public boolean onCommand(CommandSender sender, Command cmd, String label, String
if (entityCount > 1 || tileCount > 0) {
plugin.utils.sendMessage(player, "messages.scan.both.header");

TreeMap<String, Integer> entryTreeMap = new TreeMap<>();
for (Entity entity : chunk.getEntities()) {
entryTreeMap.merge(entity.getType().name(), 1, Integer::sum);
}
for (BlockState bs : chunk.getTileEntities()) {
entryTreeMap.merge(bs.getType().name(), 1, Integer::sum);
}
for (Map.Entry<String, Integer> entry : entryTreeMap.entrySet()) {
for (Map.Entry<String, Integer> entry : plugin.utils.getEntitiesAndTilesInChunk(chunk)) {
String name = plugin.utils.capitalizeName(entry.getKey().toLowerCase());
plugin.utils.sendMessage(player, "messages.scan.both.format", "%entry%", name, "%count%", String.valueOf(entry.getValue()));
}
Expand All @@ -62,11 +52,7 @@ public boolean onCommand(CommandSender sender, Command cmd, String label, String
if (entityCount > 1) {
plugin.utils.sendMessage(player, "messages.scan.entity.header");

TreeMap<String, Integer> entityTreeMap = new TreeMap<>();
for (Entity entity : player.getLocation().getChunk().getEntities()) {
entityTreeMap.merge(entity.getType().name(), 1, Integer::sum);
}
for (Map.Entry<String, Integer> entry : entityTreeMap.entrySet()) {
for (Map.Entry<String, Integer> entry : plugin.utils.getEntitiesInChunk(player.getLocation().getChunk())) {
String name = plugin.utils.capitalizeName(entry.getKey().toLowerCase());
plugin.utils.sendMessage(player, "messages.scan.entity.format", "%entity%", name, "%count%", String.valueOf(entry.getValue()));
}
Expand All @@ -86,12 +72,7 @@ public boolean onCommand(CommandSender sender, Command cmd, String label, String
if (tileCount > 0) {
plugin.utils.sendMessage(player, "messages.scan.tile.header");

TreeMap<String, Integer> tileTreeMap = new TreeMap<>();
for (BlockState bs : player.getLocation().getChunk().getTileEntities()) {
tileTreeMap.merge(bs.getType().name(), 1, Integer::sum);
}

for (Map.Entry<String, Integer> entry : tileTreeMap.entrySet()) {
for (Map.Entry<String, Integer> entry : plugin.utils.getTilesInChunk(player.getLocation().getChunk())) {
String name = plugin.utils.capitalizeName(entry.getKey().toLowerCase());
plugin.utils.sendMessage(player, "messages.scan.tile.format", "%tile%", name, "%count%", String.valueOf(entry.getValue()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import net.frankheijden.blocklimiter.BlockLimiter;
import org.bukkit.Chunk;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.block.BlockState;
import org.bukkit.command.Command;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import net.frankheijden.blocklimiter.BlockLimiter;
import org.bukkit.Bukkit;
import org.bukkit.Chunk;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.block.BlockState;
import org.bukkit.command.Command;
Expand Down

0 comments on commit 16904b6

Please sign in to comment.