diff --git a/pom.xml b/pom.xml
index b553efe..8c35783 100644
--- a/pom.xml
+++ b/pom.xml
@@ -4,7 +4,7 @@
com.programmerdan.minecraft
cropcontrol
- 1.1.4
+ 1.2.0
jar
CropControl
https://github.com/DevotedMC/CropControl
@@ -64,25 +64,25 @@
org.spigotmc
spigot-api
- 1.12-R0.1-SNAPSHOT
+ 1.14.4-R0.1-SNAPSHOT
provided
vg.civcraft.mc.civmodcore
CivModCore
- 1.6.0
+ 1.7.5
provided
com.untamedears
RealisticBiomes
- 1.4.0
+ 2.0.1
provided
vg.civcraft.mc.citadel
Citadel
- 3.9.0
+ 4.0.1
provided
diff --git a/src/main/java/com/programmerdan/minecraft/cropcontrol/CropControl.java b/src/main/java/com/programmerdan/minecraft/cropcontrol/CropControl.java
index 4185bbb..41f6403 100644
--- a/src/main/java/com/programmerdan/minecraft/cropcontrol/CropControl.java
+++ b/src/main/java/com/programmerdan/minecraft/cropcontrol/CropControl.java
@@ -3,7 +3,6 @@
import com.programmerdan.minecraft.cropcontrol.data.DAO;
import com.programmerdan.minecraft.cropcontrol.handler.CastleGatesEventHandler;
import com.programmerdan.minecraft.cropcontrol.handler.CitadelEventHandler;
-import com.programmerdan.minecraft.cropcontrol.handler.CropControlCommandHandler;
import com.programmerdan.minecraft.cropcontrol.handler.CropControlDatabaseHandler;
import com.programmerdan.minecraft.cropcontrol.handler.CropControlEventHandler;
import com.programmerdan.minecraft.cropcontrol.handler.RealisticBiomesEventHandler;
@@ -36,10 +35,11 @@ public void onEnable() {
CropControl.instance = this;
connectDatabase();
- if (!this.isEnabled()) return;
+ if (!this.isEnabled()) {
+ return;
+ }
registerEventHandler();
- registerCommandHandler();
}
@Override
@@ -59,7 +59,9 @@ private void connectDatabase() {
}
private void registerEventHandler() {
- if (!this.isEnabled()) return;
+ if (!this.isEnabled()) {
+ return;
+ }
try {
this.eventHandler = new CropControlEventHandler(getConfig());
this.getServer().getPluginManager().registerEvents(eventHandler, this);
@@ -80,12 +82,6 @@ private void registerEventHandler() {
this.setEnabled(false);
}
}
-
- private void registerCommandHandler() {
- if (!this.isEnabled()) return;
- this.setCommandHandler(new CropControlCommandHandler());
- this.getCommandHandler().registerCommands();
- }
/**
*
@@ -102,15 +98,6 @@ public static CropControl getPlugin() {
public static DAO getDAO() {
return CropControlDatabaseHandler.getDAO();
}
-
- /**
- *
- * @return the name of this plugin.
- */
- @Override
- protected String getPluginName() {
- return "CropControl";
- }
public CropControlEventHandler getEventHandler() {
return this.eventHandler;
diff --git a/src/main/java/com/programmerdan/minecraft/cropcontrol/commands/CropControlCommand.java b/src/main/java/com/programmerdan/minecraft/cropcontrol/commands/CropControlCommand.java
new file mode 100644
index 0000000..00b2db1
--- /dev/null
+++ b/src/main/java/com/programmerdan/minecraft/cropcontrol/commands/CropControlCommand.java
@@ -0,0 +1,31 @@
+package com.programmerdan.minecraft.cropcontrol.commands;
+
+import java.util.List;
+
+import org.bukkit.command.CommandSender;
+
+import com.programmerdan.minecraft.cropcontrol.config.DropConfig;
+import com.programmerdan.minecraft.cropcontrol.config.RootConfig;
+import com.programmerdan.minecraft.cropcontrol.config.ToolConfig;
+
+import vg.civcraft.mc.civmodcore.command.CivCommand;
+import vg.civcraft.mc.civmodcore.command.StandaloneCommand;
+
+@CivCommand(id = "cropcontrol")
+public class CropControlCommand extends StandaloneCommand{
+
+ @Override
+ public boolean execute(CommandSender sender, String[] args) {
+ RootConfig.reload();
+ DropConfig.reload();
+ ToolConfig.clear();
+ sender.sendMessage("Configuration cleared, will progressively reload.");
+ return true;
+ }
+
+ @Override
+ public List tabComplete(CommandSender sender, String[] args) {
+ return null;
+ }
+
+}
diff --git a/src/main/java/com/programmerdan/minecraft/cropcontrol/commands/CropControlGenCommand.java b/src/main/java/com/programmerdan/minecraft/cropcontrol/commands/CropControlGenCommand.java
new file mode 100644
index 0000000..dbda9cf
--- /dev/null
+++ b/src/main/java/com/programmerdan/minecraft/cropcontrol/commands/CropControlGenCommand.java
@@ -0,0 +1,95 @@
+package com.programmerdan.minecraft.cropcontrol.commands;
+
+import java.util.LinkedList;
+import java.util.List;
+
+import org.bukkit.Bukkit;
+import org.bukkit.command.CommandSender;
+import org.bukkit.configuration.ConfigurationSection;
+import org.bukkit.configuration.file.FileConfiguration;
+import org.bukkit.entity.Item;
+import org.bukkit.entity.Player;
+import org.bukkit.inventory.ItemStack;
+
+import com.programmerdan.minecraft.cropcontrol.CropControl;
+import com.programmerdan.minecraft.cropcontrol.config.DropConfig;
+import com.programmerdan.minecraft.cropcontrol.config.RootConfig;
+
+import vg.civcraft.mc.civmodcore.command.CivCommand;
+import vg.civcraft.mc.civmodcore.command.StandaloneCommand;
+
+@CivCommand(id = "ccgen")
+public class CropControlGenCommand extends StandaloneCommand {
+
+ @Override
+ public boolean execute(CommandSender sender, String[] args) {
+ Player player = (Player) sender;
+ double mult = 1;
+ try {
+ mult = Integer.parseInt(args[0]);
+ } catch (Exception e) {
+ mult = 1;
+ }
+ final double vmult = mult;
+
+ sender.sendMessage("Force loading all configs and generating all drops, this could cause lag");
+
+ Bukkit.getScheduler().runTaskAsynchronously(CropControl.getPlugin(), () -> {
+ long delay = 0L;
+ FileConfiguration config = CropControl.getPlugin().getConfig();
+ ConfigurationSection crops = config.getConfigurationSection("crops");
+ ConfigurationSection saplings = config.getConfigurationSection("saplings");
+ ConfigurationSection trees = config.getConfigurationSection("trees");
+
+ List indexMap = new LinkedList<>();
+
+ for (String crop : crops.getKeys(false)) {
+ ConfigurationSection cropConfig = crops.getConfigurationSection(crop);
+ if (!cropConfig.isConfigurationSection("drops")) {
+ for (String subtype : cropConfig.getKeys(false)) {
+ indexMap.add("crops." + crop + "." + subtype);
+ }
+ } else {
+ indexMap.add("crops." + crop);
+ }
+ }
+
+ for (String sapling : saplings.getKeys(false)) {
+ indexMap.add("saplings." + sapling);
+ }
+ for (String tree : trees.getKeys(false)) {
+ indexMap.add("trees." + tree);
+ }
+
+ for (String index : indexMap) {
+ RootConfig rootConfig = RootConfig.from(index);
+ if (rootConfig != null) {
+ for (String drop : rootConfig.getDropList()) {
+ DropConfig dropConfig = DropConfig.byIdent(drop);
+ List drops = dropConfig.getDrops((int) vmult);
+ if (drops != null && !drops.isEmpty()) {
+ for (ItemStack item : drops) {
+ Bukkit.getScheduler().runTaskLater(CropControl.getPlugin(), () -> {
+ sender.sendMessage(
+ String.format("Root: %s, drop: %s, item: %s", index, drop, item.getType()));
+ Item dropped = player.getWorld().dropItem(player.getLocation().add(0, 1.0, 0),
+ item);
+ dropped.setPickupDelay(20);
+ }, delay++);
+ }
+ }
+ }
+ }
+ }
+ });
+
+ return false;
+ }
+
+ @Override
+ public List tabComplete(CommandSender sender, String[] args) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+}
diff --git a/src/main/java/com/programmerdan/minecraft/cropcontrol/config/DropConfig.java b/src/main/java/com/programmerdan/minecraft/cropcontrol/config/DropConfig.java
index 984000f..0bf6f69 100644
--- a/src/main/java/com/programmerdan/minecraft/cropcontrol/config/DropConfig.java
+++ b/src/main/java/com/programmerdan/minecraft/cropcontrol/config/DropConfig.java
@@ -16,7 +16,7 @@
*
*/
public class DropConfig {
- private static ConcurrentHashMap configs = new ConcurrentHashMap();
+ private static ConcurrentHashMap configs = new ConcurrentHashMap<>();
private static DropConfig nonce = new DropConfig();
private ConfigurationSection dropSection = null;
@@ -25,7 +25,7 @@ public class DropConfig {
private String command = null;
- private double chance = 0.0d;
+ private double chance = 0.0D;
private int lowMult = 1;
private int highMult = 1;
@@ -50,7 +50,7 @@ public static DropConfig byIdent(String ident) {
config.command = config.dropSection.getString("command");
- config.chance = config.dropSection.getDouble("base.chance", 0.0d);
+ config.chance = config.dropSection.getDouble("base.chance", 0.0D);
config.lowMult = config.dropSection.getInt("base.min", 1);
config.highMult = config.dropSection.getInt("base.max", 1);
@@ -76,10 +76,10 @@ public int getMutliplierMax() {
}
public List getDrops(int multiplier) {
- if (template == null || template.size() == 0) {
- return new ArrayList();
+ if (template == null || template.isEmpty()) {
+ return new ArrayList<>();
}
- ArrayList drops = new ArrayList(template.size());
+ ArrayList drops = new ArrayList<>(template.size());
for (ItemStack i : template) {
int newSize = i.getAmount() * multiplier;
if (newSize <= 0) {
diff --git a/src/main/java/com/programmerdan/minecraft/cropcontrol/config/RootConfig.java b/src/main/java/com/programmerdan/minecraft/cropcontrol/config/RootConfig.java
index 2e4ad00..646e7a0 100644
--- a/src/main/java/com/programmerdan/minecraft/cropcontrol/config/RootConfig.java
+++ b/src/main/java/com/programmerdan/minecraft/cropcontrol/config/RootConfig.java
@@ -1,7 +1,6 @@
package com.programmerdan.minecraft.cropcontrol.config;
import java.util.ArrayList;
-import java.util.Collection;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
@@ -30,9 +29,9 @@
* @author Programmerdan
*
*/
-public class RootConfig {
+public final class RootConfig {
- private static ConcurrentHashMap rootConfigs = new ConcurrentHashMap();
+ private static ConcurrentHashMap rootConfigs = new ConcurrentHashMap<>();
private RootConfig() {};
private ConfigurationSection baseSection = null;
@@ -78,7 +77,7 @@ public static RootConfig from(String index) {
if (config.baseSection != null) {
ConfigurationSection drops = config.baseSection.getConfigurationSection("drops");
if (drops != null) {
- config.baseDrops = new ConcurrentHashMap();
+ config.baseDrops = new ConcurrentHashMap<>();
for (String key : drops.getKeys(false)) {
DropConfig.byIdent(key); // preload it.
config.baseDrops.put(key, config.new DropModifiers(drops.getConfigurationSection(key)));
@@ -90,12 +89,12 @@ public static RootConfig from(String index) {
}
public String predictDrops(BreakType breakType, UUID placer, UUID breaker, boolean harvestable, Biome biome, ItemStack tool, World world) {
- if (baseDrops == null || baseDrops.size() == 0) {
+ if (baseDrops == null || baseDrops.isEmpty()) {
return "No drops configured for " + index;
}
- StringBuffer message = new StringBuffer("Drops configured for " + index + ":\n");
- double cumChance = 0.0d;
- double localChance = 0.0d;
+ StringBuilder message = new StringBuilder("Drops configured for " + index + ":\n");
+ double cumChance = 0.0D;
+ double localChance = 0.0D;
int localMin = 0;
int localMax = 0;
int counted = 0;
@@ -139,7 +138,7 @@ public String predictDrops(BreakType breakType, UUID placer, UUID breaker, boole
// TODO: adjust chance based on tool.
- if (BreakType.PLAYER.equals(breakType)) { // player (if applies)
+ if (BreakType.PLAYER == breakType) { // player (if applies)
if (placer != null && placer.equals(breaker)) {
localChance *= dropMod.samePlayer.chanceMod;
localMin += dropMod.samePlayer.stackAdjust;
@@ -151,7 +150,9 @@ public String predictDrops(BreakType breakType, UUID placer, UUID breaker, boole
}
}
- if (localMax < localMin) localMax = localMin;
+ if (localMax < localMin) {
+ localMax = localMin;
+ }
// If no chance of drop or drop size would be * 0, move on.
if (localChance <= 0) {
@@ -175,12 +176,12 @@ public String predictDrops(BreakType breakType, UUID placer, UUID breaker, boole
}
public List realizeDrops(BreakType breakType, UUID placer, UUID breaker, boolean harvestable, Biome biome, ItemStack tool, World world, List commandBuffer) {
- LinkedList outcome = new LinkedList();
- if (baseDrops == null || baseDrops.size() == 0) {
+ LinkedList outcome = new LinkedList<>();
+ if (baseDrops == null || baseDrops.isEmpty()) {
return outcome;
}
- double cumChance = 0.0d;
- double localChance = 0.0d;
+ double cumChance = 0.0D;
+ double localChance = 0.0D;
int localMin = 0;
int localMax = 0;
int counted = 0;
@@ -246,7 +247,7 @@ public List realizeDrops(BreakType breakType, UUID placer, UUID break
localMax += modifier.stackExpand;
}
- if (BreakType.PLAYER.equals(breakType)) { // player (if applies)
+ if (BreakType.PLAYER == breakType) { // player (if applies)
if (placer != null && placer.equals(breaker)) {
localChance *= dropMod.samePlayer.chanceMod;
localMin += dropMod.samePlayer.stackAdjust;
@@ -258,10 +259,14 @@ public List realizeDrops(BreakType breakType, UUID placer, UUID break
}
}
- if (localMax < localMin) localMax = localMin;
+ if (localMax < localMin) {
+ localMax = localMin;
+ }
// If no chance of drop or drop size would be * 0, move on.
- if (localChance <= 0) continue;
+ if (localChance <= 0) {
+ continue;
+ }
if (localMin <= localMax && localMax <= 0) {
cumChance += localChance;
counted ++;
@@ -269,7 +274,7 @@ public List realizeDrops(BreakType breakType, UUID placer, UUID break
}
if (dice >= cumChance && dice < cumChance + localChance) {
- int multiplier = (int) (Math.round(Math.random() * ((double) (localMax - localMin))) + localMin);
+ int multiplier = (int) (Math.round(Math.random() * (localMax - localMin)) + localMin);
//CropControl.getPlugin().debug("Generated a drop for {0} at chance {1} with multiplier {2}", dropIdent, localChance, multiplier);
outcome.addAll(dropConfig.getDrops(multiplier));
if (dropConfig.getCommand() != null) {
@@ -287,19 +292,19 @@ public List realizeDrops(BreakType breakType, UUID placer, UUID break
class DropModifiers {
// so for tools we keep a list based on declaration order, and a set to connect to configs.
String toolCatchall = null;
- Map tools = new ConcurrentHashMap();
- Map> toolsByType = new ConcurrentHashMap>();
+ Map tools = new ConcurrentHashMap<>();
+ Map> toolsByType = new ConcurrentHashMap<>();
- Map biomes = new ConcurrentHashMap();
+ Map biomes = new ConcurrentHashMap<>();
//per-world support
- Map worlds = new ConcurrentHashMap();
+ Map worlds = new ConcurrentHashMap<>();
ModifierConfig base = null;
boolean requireHarvestable = true;
- Map breaks = new ConcurrentHashMap();
+ Map breaks = new ConcurrentHashMap<>();
ModifierConfig differentPlayer = null;
ModifierConfig samePlayer = null;
@@ -414,12 +419,14 @@ class DropModifiers {
}
class ModifierConfig {
- double chanceMod = 1.0d;
+ double chanceMod = 1.0D;
int stackExpand = 0;
int stackAdjust = 0;
public ModifierConfig(ConfigurationSection config) {
- if (config == null) return; // leave as no-op default.
+ if (config == null) {
+ return; // leave as no-op default.
+ }
chanceMod = config.getDouble("chance", chanceMod);
stackExpand = config.getInt("expand", stackExpand);
stackAdjust = config.getInt("adjust", stackAdjust);
diff --git a/src/main/java/com/programmerdan/minecraft/cropcontrol/config/ToolConfig.java b/src/main/java/com/programmerdan/minecraft/cropcontrol/config/ToolConfig.java
index 978dfb2..04ce98f 100644
--- a/src/main/java/com/programmerdan/minecraft/cropcontrol/config/ToolConfig.java
+++ b/src/main/java/com/programmerdan/minecraft/cropcontrol/config/ToolConfig.java
@@ -40,7 +40,6 @@
public class ToolConfig {
private ItemStack template;
private boolean ignoreAmount;
- private boolean ignoreDurability;
private boolean ignoreEnchants;
private boolean ignoreOtherEnchants;
private boolean ignoreEnchantsLvl;
@@ -48,14 +47,13 @@ public class ToolConfig {
private boolean ignoreName;
private boolean ignoreMeta;
- private static ConcurrentHashMap tools = new ConcurrentHashMap();
+ private static ConcurrentHashMap tools = new ConcurrentHashMap<>();
- protected ToolConfig(ItemStack template, boolean ignoreAmount, boolean ignoreDurability,
+ protected ToolConfig(ItemStack template, boolean ignoreAmount,
boolean ignoreEnchants, boolean ignoreOtherEnchants, boolean ignoreEnchantsLvl,
boolean ignoreLore, boolean ignoreName) {
this.template = template;
this.ignoreAmount = ignoreAmount;
- this.ignoreDurability = ignoreDurability;
this.ignoreEnchants = ignoreEnchants;
this.ignoreOtherEnchants = ignoreOtherEnchants;
this.ignoreEnchantsLvl = ignoreEnchantsLvl;
@@ -66,19 +64,30 @@ protected ToolConfig(ItemStack template, boolean ignoreAmount, boolean ignoreDur
@Override
public String toString() {
- StringBuffer sb = new StringBuffer();
+ StringBuilder sb = new StringBuilder();
sb.append(template);
sb.append(",ignore:");
- if (this.ignoreAmount) sb.append("amount");
- if (this.ignoreDurability) sb.append("durability");
+ if (this.ignoreAmount) {
+ sb.append("amount");
+ }
if (this.ignoreMeta) {
sb.append("meta");
} else {
- if (this.ignoreEnchants) sb.append("enchants");
- if (this.ignoreOtherEnchants) sb.append("otherench");
- if (this.ignoreEnchantsLvl) sb.append("enchantslvl");
- if (this.ignoreLore) sb.append("lore");
- if (this.ignoreName) sb.append("name");
+ if (this.ignoreEnchants) {
+ sb.append("enchants");
+ }
+ if (this.ignoreOtherEnchants) {
+ sb.append("otherench");
+ }
+ if (this.ignoreEnchantsLvl) {
+ sb.append("enchantslvl");
+ }
+ if (this.ignoreLore) {
+ sb.append("lore");
+ }
+ if (this.ignoreName) {
+ sb.append("name");
+ }
}
return sb.toString();
@@ -92,10 +101,6 @@ public boolean ignoreAmount() {
return ignoreAmount;
}
- public boolean ignoreDurability() {
- return ignoreDurability;
- }
-
public boolean ignoreEnchants() {
return ignoreEnchants;
}
@@ -125,7 +130,9 @@ public static void clear() {
}
public static void initTool(ConfigurationSection tool) {
- if (tools == null) clear();
+ if (tools == null) {
+ clear();
+ }
if (!tool.contains("template")) {
if (!tool.contains("ignore.all")) {
return;
@@ -143,7 +150,6 @@ public static void initTool(ConfigurationSection tool) {
tools.put(tool.getName(),
new ToolConfig(temp,
tool.getBoolean("ignore.amount", true),
- tool.getBoolean("ignore.durability", true),
tool.getBoolean("ignore.enchants", true),
tool.getBoolean("ignore.otherEnchants", true),
tool.getBoolean("ignore.enchantsLvl", true),
@@ -163,10 +169,12 @@ public boolean matches(ItemStack tool) {
if (compare == null) {
return true; // this is catchall! matches everything.
}
- if (compare.getType() != tool.getType()) return false;
- if (!ignoreDurability() &&
- compare.getDurability() != tool.getDurability()) return false;
- if (!ignoreAmount() && compare.getAmount() != tool.getAmount()) return false;
+ if (compare.getType() != tool.getType()) {
+ return false;
+ }
+ if (!ignoreAmount() && compare.getAmount() != tool.getAmount()) {
+ return false;
+ }
// Short circuit of metachecks.
if (ignoreMeta()) return true;
@@ -174,15 +182,23 @@ public boolean matches(ItemStack tool) {
// Metachecks.
ItemMeta compmeta = compare.getItemMeta();
ItemMeta toolmeta = tool.getItemMeta();
- if (toolmeta == null && toolmeta == compmeta) return true; // equal but no further compare
+ if (toolmeta == null && toolmeta == compmeta) {
+ return true; // equal but no further compare
+ }
- if (compmeta == null) return false; // toolmeta != null but compmeta == null
+ if (compmeta == null) {
+ return false; // toolmeta != null but compmeta == null
+ }
// both non-null.
if (!ignoreName() && !(toolmeta.hasDisplayName() ?
- toolmeta.getDisplayName().equals(compmeta.getDisplayName()) : !compmeta.hasDisplayName() ) ) return false;
+ toolmeta.getDisplayName().equals(compmeta.getDisplayName()) : !compmeta.hasDisplayName() ) ) {
+ return false;
+ }
if (!ignoreLore() &&
- !(toolmeta.hasLore() ? toolmeta.getLore().equals(compmeta.getLore()) : !compmeta.hasLore())) return false;
+ !(toolmeta.hasLore() ? toolmeta.getLore().equals(compmeta.getLore()) : !compmeta.hasLore())) {
+ return false;
+ }
// Expensive enchantment checks.
if (!ignoreEnchants()) {
@@ -191,11 +207,15 @@ public boolean matches(ItemStack tool) {
// check that set of enchants is same (both null or both not null and same) else bail
if (!ignoreOtherEnchants() && !((compench == null && toolench == null) ||
- (compench != null && toolench != null && compench.keySet().equals(toolench.keySet()) ) ) ) return false;
+ (compench != null && toolench != null && compench.keySet().equals(toolench.keySet()) ) ) ) {
+ return false;
+ }
// check that tool has at least the enchantments specified; ignore the rest.
if (ignoreOtherEnchants() && !(compench == null ||
- (toolench != null && toolench.keySet().containsAll(compench.keySet()) ) ) ) return false;
+ (toolench != null && toolench.keySet().containsAll(compench.keySet()) ) ) ) {
+ return false;
+ }
// also check _level_ of enchants
if (!ignoreEnchantsLvl() && compench != null) {
@@ -206,7 +226,9 @@ public boolean matches(ItemStack tool) {
break;
}
}
- if (fail) return false;
+ if (fail) {
+ return false;
+ }
}
}
return true;
diff --git a/src/main/java/com/programmerdan/minecraft/cropcontrol/data/Crop.java b/src/main/java/com/programmerdan/minecraft/cropcontrol/data/Crop.java
index f617e72..5437629 100644
--- a/src/main/java/com/programmerdan/minecraft/cropcontrol/data/Crop.java
+++ b/src/main/java/com/programmerdan/minecraft/cropcontrol/data/Crop.java
@@ -14,6 +14,8 @@
import java.util.UUID;
import java.util.concurrent.ConcurrentLinkedQueue;
+import org.bukkit.Material;
+
import com.programmerdan.minecraft.cropcontrol.CreationError;
import com.programmerdan.minecraft.cropcontrol.CropControl;
import com.programmerdan.minecraft.cropcontrol.handler.CropControlDatabaseHandler;
@@ -34,7 +36,7 @@ public class Crop extends Locatable {
private static ConcurrentLinkedQueue> dirties = new ConcurrentLinkedQueue>();
private long cropID;
- private String cropType;
+ private Material cropType;
private String cropState;
private UUID placer;
private Timestamp timeStamp;
@@ -46,10 +48,10 @@ public class Crop extends Locatable {
private Crop() {}
- public static Crop create(WorldChunk chunk, int x, int y, int z, String cropType, String cropState, UUID placer, long timeStamp, boolean harvestable) {
+ public static Crop create(WorldChunk chunk, int x, int y, int z, Material cropType, String cropState, UUID placer, long timeStamp, boolean harvestable) {
return create(chunk, x, y, z, cropType, cropState, placer, new Timestamp(timeStamp), harvestable);
}
- public static Crop create(WorldChunk chunk, int x, int y, int z, String cropType, String cropState, UUID placer, Timestamp timeStamp, boolean harvestable) {
+ public static Crop create(WorldChunk chunk, int x, int y, int z, Material cropType, String cropState, UUID placer, Timestamp timeStamp, boolean harvestable) {
Crop crop = new Crop();
crop.chunkID = chunk.getChunkID();
crop.x = x;
@@ -74,7 +76,7 @@ public static Crop create(WorldChunk chunk, int x, int y, int z, String cropType
if (crop.cropType == null) {
statement.setNull(5, Types.VARCHAR);
} else {
- statement.setString(5, crop.cropType);
+ statement.setString(5, crop.cropType.toString());
}
if (crop.cropState == null) {
statement.setNull(6, Types.VARCHAR);
@@ -111,7 +113,7 @@ public long getCropID() {
return cropID;
}
- public String getCropType() {
+ public Material getCropType() {
return cropType;
}
@@ -235,7 +237,7 @@ public static int saveDirty() {
}
public static List preload(WorldChunk chunk) {
- List crops = new ArrayList();
+ List crops = new ArrayList<>();
try (Connection connection = CropControlDatabaseHandler.getInstanceData().getConnection();
PreparedStatement statement = connection.prepareStatement(
"SELECT * FROM crops_crop WHERE (crop_id, x, y, z) IN (SELECT max(crop_id), x, y, z FROM crops_crop WHERE chunk_id = ? AND removed = FALSE GROUP BY x, y, z);");) {
@@ -248,7 +250,7 @@ public static List preload(WorldChunk chunk) {
crop.x = results.getInt(3);
crop.y = results.getInt(4);
crop.z = results.getInt(5);
- crop.cropType = results.getString(6);
+ crop.cropType = Material.valueOf(results.getString(6));
crop.cropState = results.getString(7);
try {
crop.placer = UUID.fromString(results.getString(8));
diff --git a/src/main/java/com/programmerdan/minecraft/cropcontrol/data/DAO.java b/src/main/java/com/programmerdan/minecraft/cropcontrol/data/DAO.java
index e5c0001..5fb310a 100644
--- a/src/main/java/com/programmerdan/minecraft/cropcontrol/data/DAO.java
+++ b/src/main/java/com/programmerdan/minecraft/cropcontrol/data/DAO.java
@@ -57,13 +57,11 @@ public Tree getTree(TreeComponent component) {
}
public List getTreeComponents(long treeID) {
- List components = WorldChunk.getTreeComponents(treeID);
- return components;
+ return WorldChunk.getTreeComponents(treeID);
}
public List getTreeComponents(Tree tree) {
- List components = WorldChunk.getTreeComponents(tree);
- return components;
+ return WorldChunk.getTreeComponents(tree);
}
public boolean isTreeComponent(Tree tree, TreeComponent component) {
diff --git a/src/main/java/com/programmerdan/minecraft/cropcontrol/data/Locatable.java b/src/main/java/com/programmerdan/minecraft/cropcontrol/data/Locatable.java
index d76238b..91ae073 100644
--- a/src/main/java/com/programmerdan/minecraft/cropcontrol/data/Locatable.java
+++ b/src/main/java/com/programmerdan/minecraft/cropcontrol/data/Locatable.java
@@ -1,5 +1,7 @@
package com.programmerdan.minecraft.cropcontrol.data;
+import java.util.Objects;
+
/**
* At the core of fast hashing is Locatable, which gives us O(1) lookups of specific location objects without resorting to
* other cuboid sorting methods.
@@ -54,8 +56,7 @@ public boolean equals(Object o) {
@Override
public int hashCode() {
- int base = 31*31*31*x + 31*31*y + 31*z + (int)chunkID;
- return base;
+ return Objects.hash(x, y, z, chunkID);
}
@Override
diff --git a/src/main/java/com/programmerdan/minecraft/cropcontrol/data/Sapling.java b/src/main/java/com/programmerdan/minecraft/cropcontrol/data/Sapling.java
index 23fa813..38a9f83 100644
--- a/src/main/java/com/programmerdan/minecraft/cropcontrol/data/Sapling.java
+++ b/src/main/java/com/programmerdan/minecraft/cropcontrol/data/Sapling.java
@@ -14,6 +14,8 @@
import java.util.UUID;
import java.util.concurrent.ConcurrentLinkedQueue;
+import org.bukkit.Material;
+
import com.programmerdan.minecraft.cropcontrol.CreationError;
import com.programmerdan.minecraft.cropcontrol.CropControl;
import com.programmerdan.minecraft.cropcontrol.handler.CropControlDatabaseHandler;
@@ -32,7 +34,7 @@ public class Sapling extends Locatable {
private static ConcurrentLinkedQueue> dirties = new ConcurrentLinkedQueue>();
private long saplingID;
- private String saplingType;
+ private Material saplingType;
private UUID placer;
private Timestamp timeStamp;
private boolean harvestable;
@@ -43,11 +45,11 @@ public class Sapling extends Locatable {
private Sapling() {
}
- public static Sapling create(WorldChunk chunk, int x, int y, int z, String saplingType, UUID placer,
+ public static Sapling create(WorldChunk chunk, int x, int y, int z, Material saplingType, UUID placer,
long timeStamp, boolean harvestable) {
return create(chunk, x, y, z, saplingType, placer, new Timestamp(timeStamp), harvestable);
}
- public static Sapling create(WorldChunk chunk, int x, int y, int z, String saplingType, UUID placer,
+ public static Sapling create(WorldChunk chunk, int x, int y, int z, Material saplingType, UUID placer,
Timestamp timeStamp, boolean harvestable) {
Sapling sapling = new Sapling();
sapling.chunkID = chunk.getChunkID();
@@ -72,7 +74,7 @@ public static Sapling create(WorldChunk chunk, int x, int y, int z, String sapli
if (sapling.saplingType == null) {
statement.setNull(5, Types.VARCHAR);
} else {
- statement.setString(5, sapling.saplingType);
+ statement.setString(5, sapling.saplingType.toString());
}
if (sapling.placer == null) {
statement.setNull(6, Types.VARCHAR);
@@ -105,7 +107,7 @@ public long getSaplingID() {
return saplingID;
}
- public String getSaplingType() {
+ public Material getSaplingType() {
return saplingType;
}
@@ -230,7 +232,7 @@ public static List preload(WorldChunk chunk) {
sapling.x = results.getInt(3);
sapling.y = results.getInt(4);
sapling.z = results.getInt(5);
- sapling.saplingType = results.getString(6);
+ sapling.saplingType = Material.valueOf(results.getString(6));
try {
sapling.placer = UUID.fromString(results.getString(7));
} catch (IllegalArgumentException iae) {
diff --git a/src/main/java/com/programmerdan/minecraft/cropcontrol/data/Tree.java b/src/main/java/com/programmerdan/minecraft/cropcontrol/data/Tree.java
index ff72d6f..029245c 100644
--- a/src/main/java/com/programmerdan/minecraft/cropcontrol/data/Tree.java
+++ b/src/main/java/com/programmerdan/minecraft/cropcontrol/data/Tree.java
@@ -14,6 +14,8 @@
import java.util.UUID;
import java.util.concurrent.ConcurrentLinkedQueue;
+import org.bukkit.TreeType;
+
import com.programmerdan.minecraft.cropcontrol.CreationError;
import com.programmerdan.minecraft.cropcontrol.CropControl;
import com.programmerdan.minecraft.cropcontrol.handler.CropControlDatabaseHandler;
@@ -36,7 +38,7 @@ public class Tree extends Locatable {
private static ConcurrentLinkedQueue> dirties = new ConcurrentLinkedQueue>();
private long treeID;
- private String treeType;
+ private TreeType treeType;
private UUID placer;
private Timestamp timeStamp;
@@ -47,11 +49,11 @@ public class Tree extends Locatable {
private Tree() {
}
- public static Tree create(WorldChunk chunk, int x, int y, int z, String treeType, UUID placer,
+ public static Tree create(WorldChunk chunk, int x, int y, int z, TreeType treeType, UUID placer,
long timeStamp) {
return create(chunk, x, y, z, treeType, placer, new Timestamp(timeStamp));
}
- public static Tree create(WorldChunk chunk, int x, int y, int z, String treeType, UUID placer,
+ public static Tree create(WorldChunk chunk, int x, int y, int z, TreeType treeType, UUID placer,
Timestamp timeStamp) {
Tree tree = new Tree();
tree.chunkID = chunk.getChunkID();
@@ -75,7 +77,7 @@ public static Tree create(WorldChunk chunk, int x, int y, int z, String treeType
if (tree.treeType == null) {
statement.setNull(5, Types.VARCHAR);
} else {
- statement.setString(5, tree.treeType);
+ statement.setString(5, tree.treeType.toString());
}
if (tree.placer == null) {
statement.setNull(6, Types.VARCHAR);
@@ -118,7 +120,7 @@ public long getTreeID() {
return treeID;
}
- public String getTreeType() {
+ public TreeType getTreeType() {
return treeType;
}
@@ -248,7 +250,7 @@ public static List preload(WorldChunk chunk) {
tree.x = results.getInt(3);
tree.y = results.getInt(4);
tree.z = results.getInt(5);
- tree.treeType = results.getString(6);
+ tree.treeType = TreeType.valueOf(results.getString(6));
try {
tree.placer = UUID.fromString(results.getString(7));
} catch (IllegalArgumentException iae) {
@@ -285,7 +287,7 @@ public static Tree byId(long treeID) {
tree.x = results.getInt(3);
tree.y = results.getInt(4);
tree.z = results.getInt(5);
- tree.treeType = results.getString(6);
+ tree.treeType = TreeType.valueOf(results.getString(6));
try {
tree.placer = UUID.fromString(results.getString(7));
} catch (IllegalArgumentException iae) {
diff --git a/src/main/java/com/programmerdan/minecraft/cropcontrol/data/TreeComponent.java b/src/main/java/com/programmerdan/minecraft/cropcontrol/data/TreeComponent.java
index 7defc18..eb9665b 100644
--- a/src/main/java/com/programmerdan/minecraft/cropcontrol/data/TreeComponent.java
+++ b/src/main/java/com/programmerdan/minecraft/cropcontrol/data/TreeComponent.java
@@ -12,6 +12,8 @@
import java.util.UUID;
import java.util.concurrent.ConcurrentLinkedQueue;
+import org.bukkit.TreeType;
+
import com.programmerdan.minecraft.cropcontrol.CreationError;
import com.programmerdan.minecraft.cropcontrol.CropControl;
import com.programmerdan.minecraft.cropcontrol.handler.CropControlDatabaseHandler;
@@ -31,7 +33,7 @@ public class TreeComponent extends Locatable {
private long treeComponentID;
private long treeID;
- private String treeType;
+ private TreeType treeType;
private UUID placer;
private boolean harvestable;
@@ -42,12 +44,12 @@ public class TreeComponent extends Locatable {
private TreeComponent() {
}
- public static TreeComponent create(Tree tree, WorldChunk chunk, int x, int y, int z, String treeType, UUID placer,
+ public static TreeComponent create(Tree tree, WorldChunk chunk, int x, int y, int z, TreeType treeType, UUID placer,
boolean harvestable) {
return create(tree.getTreeID(), chunk, x, y, z, treeType, placer, harvestable);
}
- public static TreeComponent create(long treeId, WorldChunk chunk, int x, int y, int z, String treeType, UUID placer, boolean harvestable) {
+ public static TreeComponent create(long treeId, WorldChunk chunk, int x, int y, int z, TreeType treeType, UUID placer, boolean harvestable) {
TreeComponent component = new TreeComponent();
component.treeID = treeId;
component.chunkID = chunk.getChunkID();
@@ -72,7 +74,7 @@ public static TreeComponent create(long treeId, WorldChunk chunk, int x, int y,
if (component.treeType == null) {
statement.setNull(6, Types.VARCHAR);
} else {
- statement.setString(6, component.treeType);
+ statement.setString(6, component.treeType.toString());
}
if (component.placer == null) {
statement.setNull(7, Types.VARCHAR);
@@ -120,7 +122,7 @@ public void updateLocation(long chunkID, int x, int y, int z) {
TreeComponent.dirties.offer(new WeakReference(this));
}
- public String getTreeType() {
+ public TreeType getTreeType() {
return treeType;
}
@@ -245,7 +247,7 @@ public static int saveDirty() {
}
public static List preload(WorldChunk chunk) {
- List components = new ArrayList();
+ List components = new ArrayList<>();
try (Connection connection = CropControlDatabaseHandler.getInstanceData().getConnection();
PreparedStatement statement = connection.prepareStatement(
"SELECT * FROM crops_tree_component WHERE (tree_component_id, x, y, z) IN (SELECT max(tree_component_id), x, y, z FROM crops_tree_component WHERE chunk_id = ? AND removed = FALSE GROUP BY x, y, z);");) {
@@ -259,7 +261,7 @@ public static List preload(WorldChunk chunk) {
component.x = results.getInt(4);
component.y = results.getInt(5);
component.z = results.getInt(6);
- component.treeType = results.getString(7);
+ component.treeType = TreeType.valueOf(results.getString(7));
try {
component.placer = UUID.fromString(results.getString(8));
} catch (IllegalArgumentException iae) {
diff --git a/src/main/java/com/programmerdan/minecraft/cropcontrol/data/WorldChunk.java b/src/main/java/com/programmerdan/minecraft/cropcontrol/data/WorldChunk.java
index 3157aa1..a99dd4b 100644
--- a/src/main/java/com/programmerdan/minecraft/cropcontrol/data/WorldChunk.java
+++ b/src/main/java/com/programmerdan/minecraft/cropcontrol/data/WorldChunk.java
@@ -1,6 +1,5 @@
package com.programmerdan.minecraft.cropcontrol.data;
-import java.lang.ref.WeakReference;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
@@ -35,40 +34,37 @@
public class WorldChunk {
// consider locating all related to the chunk into the chunk, load as chunk, etc.
- private Map cropCacheID = new ConcurrentHashMap();
- private Map cropCacheLoc = new ConcurrentHashMap();
+ private Map cropCacheID = new ConcurrentHashMap<>();
+ private Map cropCacheLoc = new ConcurrentHashMap<>();
- private Map saplingCacheID = new ConcurrentHashMap();
- private Map saplingCacheLoc = new ConcurrentHashMap();
+ private Map saplingCacheID = new ConcurrentHashMap<>();
+ private Map saplingCacheLoc = new ConcurrentHashMap<>();
- private static Map universalTreeCache = new ConcurrentHashMap();
- private static Map> universalTreeComponentCache = new ConcurrentHashMap>();
+ private static Map universalTreeCache = new ConcurrentHashMap<>();
+ private static Map> universalTreeComponentCache = new ConcurrentHashMap<>();
- private Map treeCacheID = new ConcurrentHashMap();
- private Map treeCacheLoc = new ConcurrentHashMap();
+ private Map treeCacheID = new ConcurrentHashMap<>();
+ private Map treeCacheLoc = new ConcurrentHashMap<>();
- private Map componentCacheID = new ConcurrentHashMap();
- private Map componentCacheLoc = new ConcurrentHashMap();
+ private Map componentCacheID = new ConcurrentHashMap<>();
+ private Map componentCacheLoc = new ConcurrentHashMap<>();
- private static Map chunkCacheID = new ConcurrentHashMap();
- private static Map> chunkCacheLoc = new ConcurrentHashMap>(); // using transposed x,z
+ private static Map chunkCacheID = new ConcurrentHashMap<>();
+ private static Map> chunkCacheLoc = new ConcurrentHashMap<>(); // using transposed x,z
- private static ConcurrentLinkedQueue unloadQueue = new ConcurrentLinkedQueue();
+ private static ConcurrentLinkedQueue unloadQueue = new ConcurrentLinkedQueue<>();
- private ConcurrentLinkedQueue removedCropQueue = new ConcurrentLinkedQueue();
- private ConcurrentLinkedQueue removedSaplingQueue = new ConcurrentLinkedQueue();
- private ConcurrentLinkedQueue removedTreeComponentQueue = new ConcurrentLinkedQueue();
- private ConcurrentLinkedQueue removedTreeQueue = new ConcurrentLinkedQueue();
+ private ConcurrentLinkedQueue removedCropQueue = new ConcurrentLinkedQueue<>();
+ private ConcurrentLinkedQueue removedSaplingQueue = new ConcurrentLinkedQueue<>();
+ private ConcurrentLinkedQueue removedTreeComponentQueue = new ConcurrentLinkedQueue<>();
+ private ConcurrentLinkedQueue removedTreeQueue = new ConcurrentLinkedQueue<>();
private long chunkID;
private UUID worldID;
private int chunkX;
private int chunkZ;
- private transient long retrieveTime;
-
private WorldChunk() {
- retrieveTime = System.currentTimeMillis();
}
public long getChunkID() {
@@ -88,9 +84,7 @@ public int getChunkZ() {
}
public long getChunkLocID() {
- long chunk_id = ((long) chunkX << 32L) + (long) chunkZ;
-
- return chunk_id;
+ return ((long) chunkX << 32L) + chunkZ;
}
@@ -133,19 +127,19 @@ private void stuff() {
public void register(Crop crop) {
- Crop preExist = cropCacheLoc.remove((Locatable) crop); // did we have one here already?
+ Crop preExist = cropCacheLoc.remove(crop); // did we have one here already?
if (preExist != null) {
- CropControl.getPlugin().debug("Replacing crop at {0}: {1}", (Locatable) crop, crop);
+ CropControl.getPlugin().debug("Replacing crop at {0}: {1}", crop, crop);
cropCacheID.remove(preExist.getCropID());
} else {
- CropControl.getPlugin().debug("Putting crop at {0}: {1}", (Locatable) crop, crop);
+ CropControl.getPlugin().debug("Putting crop at {0}: {1}", crop, crop);
}
cropCacheLoc.put(new Locatable(crop.getChunkID(), crop.getX(), crop.getY(), crop.getZ()), crop);
cropCacheID.put(crop.getCropID(), crop);
}
public void unregister(Crop crop) {
- Crop preExist = cropCacheLoc.remove((Locatable) crop); // did we have one here already?
+ Crop preExist = cropCacheLoc.remove(crop); // did we have one here already?
if (preExist != null) {
cropCacheID.remove(preExist.getCropID());
removedCropQueue.offer(preExist);
@@ -160,19 +154,19 @@ public Crop getCrop(int x, int y, int z) {
}
public void register(Sapling sapling) {
- Sapling preExist = saplingCacheLoc.remove((Locatable) sapling); // did we have one here already?
+ Sapling preExist = saplingCacheLoc.remove(sapling); // did we have one here already?
if (preExist != null) {
- CropControl.getPlugin().debug("Replacing sapling at {0}: {1}", (Locatable) sapling, sapling);
+ CropControl.getPlugin().debug("Replacing sapling at {0}: {1}", sapling, sapling);
saplingCacheID.remove(preExist.getSaplingID());
} else {
- CropControl.getPlugin().debug("Putting sapling at {0}: {1}", (Locatable) sapling, sapling);
+ CropControl.getPlugin().debug("Putting sapling at {0}: {1}", sapling, sapling);
}
saplingCacheLoc.put(new Locatable(sapling.getChunkID(), sapling.getX(), sapling.getY(), sapling.getZ()), sapling);
saplingCacheID.put(sapling.getSaplingID(), sapling);
}
public void unregister(Sapling sapling) {
- Sapling preExist = saplingCacheLoc.remove((Locatable) sapling); // did we have one here already?
+ Sapling preExist = saplingCacheLoc.remove(sapling); // did we have one here already?
if (preExist != null) {
saplingCacheID.remove(preExist.getSaplingID());
removedSaplingQueue.offer(preExist);
@@ -188,12 +182,12 @@ public Sapling getSapling(int x, int y, int z) {
}
public void register(Tree tree) {
- Tree preExist = treeCacheLoc.remove((Locatable) tree); // did we have one here already?
+ Tree preExist = treeCacheLoc.remove(tree); // did we have one here already?
if (preExist != null) {
- CropControl.getPlugin().debug("Replacing tree at {0}: {1}", (Locatable) tree, tree);
+ CropControl.getPlugin().debug("Replacing tree at {0}: {1}", tree, tree);
treeCacheID.remove(preExist.getTreeID());
} else {
- CropControl.getPlugin().debug("Putting tree at {0}: {1}", (Locatable) tree, tree);
+ CropControl.getPlugin().debug("Putting tree at {0}: {1}", tree, tree);
}
treeCacheLoc.put(new Locatable(tree.getChunkID(), tree.getX(), tree.getY(), tree.getZ()), tree);
treeCacheID.put(tree.getTreeID(), tree);
@@ -201,7 +195,7 @@ public void register(Tree tree) {
}
public void unregister(Tree tree) {
- Tree preExist = treeCacheLoc.remove((Locatable) tree); // did we have one here already?
+ Tree preExist = treeCacheLoc.remove(tree); // did we have one here already?
if (preExist != null) {
treeCacheID.remove(preExist.getTreeID());
removedTreeQueue.offer(preExist);
@@ -230,12 +224,12 @@ public static void remove(Tree tree) {
}
public void register(TreeComponent component) {
- TreeComponent preExist = componentCacheLoc.remove((Locatable) component); // did we have one here already?
+ TreeComponent preExist = componentCacheLoc.remove(component); // did we have one here already?
if (preExist != null) {
- CropControl.getPlugin().debug("Replacing treecomponent at {0}: {1}", (Locatable) component, component);
+ CropControl.getPlugin().debug("Replacing treecomponent at {0}: {1}", component, component);
componentCacheID.remove(preExist.getTreeComponentID());
} else {
- CropControl.getPlugin().debug("Putting treecomponent at {0}: {1}", (Locatable) component, component);
+ CropControl.getPlugin().debug("Putting treecomponent at {0}: {1}", component, component);
}
componentCacheLoc.put(new Locatable(component.getChunkID(), component.getX(), component.getY(), component.getZ()), component);
componentCacheID.put(component.getTreeComponentID(), component);
@@ -249,7 +243,7 @@ public void register(TreeComponent component) {
}
public void unregister(TreeComponent component) {
- TreeComponent preExist = componentCacheLoc.remove((Locatable) component); // did we have one here already?
+ TreeComponent preExist = componentCacheLoc.remove(component); // did we have one here already?
if (preExist != null) {
componentCacheID.remove(preExist.getTreeID());
removedTreeComponentQueue.offer(preExist);
@@ -297,7 +291,7 @@ public static boolean isTreeComponent(Tree tree, TreeComponent component) {
}
public static void unloadChunk(Chunk chunk) {
- long chunk_id = ((long) chunk.getX() << 32L) + (long) chunk.getZ();
+ long chunk_id = ((long) chunk.getX() << 32L) + chunk.getZ();
UUID world_uuid = chunk.getWorld().getUID();
//CropControl.getPlugin().debug("Registering unload for chunk {0}:{1}", world_uuid, chunk_id);
Map chunks = chunkCacheLoc.get(world_uuid);
@@ -313,7 +307,7 @@ public static void unloadChunk(Chunk chunk) {
// Should be in an async thread.
public static void doUnloads() {
- doUnloads(500l);// don't spend more then half a second unloading.
+ doUnloads(500L);// don't spend more then half a second unloading.
}
public static void doAllUnloads() {
@@ -323,15 +317,17 @@ public static void doAllUnloads() {
public static void doUnloads(Long maxTime) {
int unloads = 0;
long start = System.currentTimeMillis();
- long cropz = 0l;
- long saplingz = 0l;
- long treez = 0l;
- long componentz = 0l;
+ long cropz = 0L;
+ long saplingz = 0L;
+ long treez = 0L;
+ long componentz = 0L;
while (!unloadQueue.isEmpty()) {
WorldChunk unload = unloadQueue.poll();
- if (unload == null) continue;
+ if (unload == null) {
+ continue;
+ }
// extract crops and such
Iterable crops = unload.cropCacheID.values();
@@ -340,14 +336,14 @@ public static void doUnloads(Long maxTime) {
Iterable components = unload.componentCacheID.values();
// remove from cache
- long chunk_id = ((long) unload.getChunkX() << 32L) + (long) unload.getChunkZ();
- UUID world_uuid = unload.getWorldID();
- Map chunks = chunkCacheLoc.get(world_uuid);
+ long chunkId = ((long) unload.getChunkX() << 32L) + unload.getChunkZ();
+ UUID worldUuid = unload.getWorldID();
+ Map chunks = chunkCacheLoc.get(worldUuid);
if (chunks == null) {
continue;
}
- WorldChunk cacheChunk = chunks.remove(chunk_id);
+ WorldChunk cacheChunk = chunks.remove(chunkId);
if (cacheChunk != null) {
chunkCacheID.remove(unload.getChunkID());
}
@@ -397,14 +393,14 @@ public static void doUnloads(Long maxTime) {
public static WorldChunk getChunk(Chunk chunk) {
WorldChunk cacheChunk = null;
- long chunk_id = ((long) chunk.getX() << 32L) + (long) chunk.getZ();
- UUID world_uuid = chunk.getWorld().getUID();
- Map chunks = chunkCacheLoc.get(world_uuid);
+ long chunkId = ((long) chunk.getX() << 32L) + chunk.getZ();
+ UUID worldUuid = chunk.getWorld().getUID();
+ Map chunks = chunkCacheLoc.get(worldUuid);
if (chunks == null) {
- chunks = new ConcurrentHashMap();
- chunkCacheLoc.put(world_uuid, chunks);
+ chunks = new ConcurrentHashMap<>();
+ chunkCacheLoc.put(worldUuid, chunks);
}
- cacheChunk = chunks.get(chunk_id);
+ cacheChunk = chunks.get(chunkId);
if (cacheChunk != null) {
// remove from removal list -- tiny possibility of race condition here. Not sure ATM how to address.
unloadQueue.remove(cacheChunk);
@@ -415,7 +411,7 @@ public static WorldChunk getChunk(Chunk chunk) {
try (Connection connection = CropControlDatabaseHandler.getInstanceData().getConnection();
PreparedStatement statement = connection.prepareStatement(
"SELECT * FROM crops_chunk WHERE world = ? and x = ? and z = ?;")) {
- statement.setString(1, world_uuid.toString());
+ statement.setString(1, worldUuid.toString());
statement.setInt(2, chunk.getX());
statement.setInt(3, chunk.getZ());
try (ResultSet rs = statement.executeQuery();) {
@@ -425,7 +421,7 @@ public static WorldChunk getChunk(Chunk chunk) {
cacheChunk.chunkX = chunk.getX();
cacheChunk.chunkZ = chunk.getZ();
cacheChunk.chunkID = rs.getLong(1);
- cacheChunk.worldID = world_uuid;
+ cacheChunk.worldID = worldUuid;
/*CropControl.getPlugin().debug("Loaded existing chunk {0}:{1},{2}:{3}:{4}", world_uuid, cacheChunk.chunkX,
cacheChunk.chunkZ, chunk_id, cacheChunk.chunkID);*/
}
@@ -440,19 +436,19 @@ public static WorldChunk getChunk(Chunk chunk) {
try (Connection connection = CropControlDatabaseHandler.getInstanceData().getConnection();
PreparedStatement statement = connection.prepareStatement(
"INSERT INTO crops_chunk(world, x, z) VALUES (?, ?, ?);", Statement.RETURN_GENERATED_KEYS)) {
- statement.setString(1, world_uuid.toString());
+ statement.setString(1, worldUuid.toString());
statement.setInt(2, chunk.getX());
statement.setInt(3, chunk.getZ());
statement.execute();
try (ResultSet rs = statement.getGeneratedKeys()) {
if (rs.next()) {
- CropControl.getPlugin().debug("Registered new chunk {0}:{1},{2}:{3}:{4}", world_uuid, chunk.getX(),
- chunk.getZ(), chunk_id, rs.getLong(1));
+ CropControl.getPlugin().debug("Registered new chunk {0}:{1},{2}:{3}:{4}", worldUuid, chunk.getX(),
+ chunk.getZ(), chunkId, rs.getLong(1));
cacheChunk = new WorldChunk();
cacheChunk.chunkX = chunk.getX();
cacheChunk.chunkZ = chunk.getZ();
cacheChunk.chunkID = rs.getLong(1);
- cacheChunk.worldID = world_uuid;
+ cacheChunk.worldID = worldUuid;
} else {
throw new CreationError(WorldChunk.class, "ID assignment of chunk failed!");
}
@@ -463,7 +459,7 @@ public static WorldChunk getChunk(Chunk chunk) {
}
}
cacheChunk.stuff();
- chunks.put(chunk_id, cacheChunk);
+ chunks.put(chunkId, cacheChunk);
WorldChunk.chunkCacheID.put(cacheChunk.getChunkID(), cacheChunk);
return cacheChunk;
}
@@ -508,7 +504,7 @@ public static WorldChunk byId(long chunkID) {
WorldChunk.chunkCacheID.put(chunkID, cacheChunk);
Map chunks = chunkCacheLoc.get(cacheChunk.getWorldID());
if (chunks == null) {
- chunks = new ConcurrentHashMap();
+ chunks = new ConcurrentHashMap<>();
chunkCacheLoc.put(cacheChunk.getWorldID(), chunks);
}
chunks.put(cacheChunk.getChunkLocID(), cacheChunk);
diff --git a/src/main/java/com/programmerdan/minecraft/cropcontrol/handler/CastleGatesEventHandler.java b/src/main/java/com/programmerdan/minecraft/cropcontrol/handler/CastleGatesEventHandler.java
index 4e95124..ab13444 100644
--- a/src/main/java/com/programmerdan/minecraft/cropcontrol/handler/CastleGatesEventHandler.java
+++ b/src/main/java/com/programmerdan/minecraft/cropcontrol/handler/CastleGatesEventHandler.java
@@ -12,7 +12,6 @@
import com.aleksey.castlegates.events.CastleGatesUndrawGateEvent;
import com.programmerdan.minecraft.cropcontrol.CropControl;
import com.programmerdan.minecraft.cropcontrol.handler.CropControlEventHandler.BreakType;
-import com.untamedears.realisticbiomes.events.RealisticBiomesBlockGrowEvent;
/**
* CastleGates voids a bunch of blocks temporarily. This can cause secondary breaks.
@@ -32,7 +31,7 @@ public class CastleGatesEventHandler implements Listener {
@EventHandler
public void onDrawEvent(CastleGatesDrawGateEvent e) {
try {
- List blocks = new ArrayList();
+ List blocks = new ArrayList<>();
for (Location location : e.getImpacted()) {
blocks.add(location.getBlock());
}
@@ -50,7 +49,7 @@ public void onDrawEvent(CastleGatesDrawGateEvent e) {
@EventHandler
public void onDrawEvent(CastleGatesUndrawGateEvent e) {
try {
- List blocks = new ArrayList();
+ List blocks = new ArrayList<>();
for (Location location : e.getImpacted()) {
blocks.add(location.getBlock());
}
diff --git a/src/main/java/com/programmerdan/minecraft/cropcontrol/handler/CitadelEventHandler.java b/src/main/java/com/programmerdan/minecraft/cropcontrol/handler/CitadelEventHandler.java
index 5586191..50c1007 100644
--- a/src/main/java/com/programmerdan/minecraft/cropcontrol/handler/CitadelEventHandler.java
+++ b/src/main/java/com/programmerdan/minecraft/cropcontrol/handler/CitadelEventHandler.java
@@ -8,7 +8,7 @@
import com.programmerdan.minecraft.cropcontrol.CropControl;
-import vg.civcraft.mc.citadel.events.AcidBlockEvent;
+import vg.civcraft.mc.citadel.events.ReinforcementAcidBlockedEvent;
/**
* ACID block breaks are an interesting edge case. Citadel directly sets the reinforced block to air.
@@ -21,9 +21,9 @@
public class CitadelEventHandler implements Listener {
@EventHandler(priority=EventPriority.HIGHEST, ignoreCancelled=true)
- public void handleAcidBreak(AcidBlockEvent e) {
+ public void handleAcidBreak(ReinforcementAcidBlockedEvent e) {
try {
- Location acided = e.getDestroyedBlockReinforcement().getLocation();
+ Location acided = e.getReinforcement().getLocation();
CropControl.getPlugin().getEventHandler().onBlockBreak(new BlockBreakEvent( acided.getBlock(), e.getPlayer() ) );
} catch (Exception g) {
diff --git a/src/main/java/com/programmerdan/minecraft/cropcontrol/handler/CropControlCommandHandler.java b/src/main/java/com/programmerdan/minecraft/cropcontrol/handler/CropControlCommandHandler.java
deleted file mode 100644
index 9ca71ef..0000000
--- a/src/main/java/com/programmerdan/minecraft/cropcontrol/handler/CropControlCommandHandler.java
+++ /dev/null
@@ -1,147 +0,0 @@
-package com.programmerdan.minecraft.cropcontrol.handler;
-
-import java.util.LinkedList;
-import java.util.List;
-
-import org.bukkit.Bukkit;
-import org.bukkit.command.CommandSender;
-import org.bukkit.configuration.ConfigurationSection;
-import org.bukkit.configuration.file.FileConfiguration;
-import org.bukkit.entity.Item;
-import org.bukkit.entity.Player;
-import org.bukkit.inventory.ItemStack;
-
-import com.programmerdan.minecraft.cropcontrol.config.DropConfig;
-import com.programmerdan.minecraft.cropcontrol.CropControl;
-import com.programmerdan.minecraft.cropcontrol.config.RootConfig;
-import com.programmerdan.minecraft.cropcontrol.config.ToolConfig;
-
-import vg.civcraft.mc.civmodcore.command.Command;
-import vg.civcraft.mc.civmodcore.command.CommandHandler;
-import vg.civcraft.mc.civmodcore.command.PlayerCommand;
-
-public class CropControlCommandHandler extends CommandHandler {
-
- @Override
- public void registerCommands() {
- this.addCommands( new Generate("ccgen") );
- this.addCommands( new CropControlCommand("cropcontrol") );
- }
-
- private class Generate extends PlayerCommand {
-
- public Generate(String name) {
- super(name);
- setIdentifier("ccgen");
- setDescription("Generates all CC drops around calling player");
- setUsage("/ccgen");
- setArguments(0,1);
- setSenderMustBePlayer(true);
- }
-
- @Override
- public boolean execute(CommandSender sender, String[] args) {
- if (!(sender instanceof Player)) {
- sender.sendMessage("Cannot be run as console");
- }
- Player player = (Player) sender;
- double mult = 1;
- try {
- mult = Integer.parseInt(args[0]);
- } catch (Exception e) {mult = 1;}
- final double vmult = mult;
-
- sender.sendMessage("Force loading all configs and generating all drops, this could cause lag");
-
- Bukkit.getScheduler().runTaskAsynchronously(CropControl.getPlugin(), new Runnable() {
- @Override
- public void run() {
- long delay = 0l;
- FileConfiguration config = CropControl.getPlugin().getConfig();
- ConfigurationSection crops = config.getConfigurationSection("crops");
- ConfigurationSection saplings = config.getConfigurationSection("saplings");
- ConfigurationSection trees = config.getConfigurationSection("trees");
-
- List indexMap = new LinkedList();
-
- for (String crop : crops.getKeys(false)) {
- ConfigurationSection cropConfig = crops.getConfigurationSection(crop);
- if (!cropConfig.isConfigurationSection("drops")) {
- for (String subtype : cropConfig.getKeys(false)) {
- indexMap.add("crops." + crop + "." + subtype);
- }
- } else {
- indexMap.add("crops." + crop);
- }
- }
-
- for (String sapling : saplings.getKeys(false)) {
- indexMap.add("saplings." + sapling);
- }
-
- for (String tree : trees.getKeys(false)) {
- indexMap.add("trees." + tree);
- }
-
- for (String index : indexMap) {
- RootConfig rootConfig = RootConfig.from(index);
- if (rootConfig != null) {
- for (String drop : rootConfig.getDropList()) {
- DropConfig dropConfig = DropConfig.byIdent(drop);
- List drops = dropConfig.getDrops((int) vmult);
- if (drops != null && !drops.isEmpty()) {
- for (ItemStack item : drops) {
- Bukkit.getScheduler().runTaskLater(CropControl.getPlugin(), new Runnable() {
- @Override
- public void run() {
- sender.sendMessage(String.format("Root: %s, drop: %s, item: %s", index, drop, item.getType()));
- Item dropped = player.getWorld().dropItem(player.getLocation().add(0, 1.0, 0), item);
- dropped.setPickupDelay(20);
- }
- }, delay++);
- }
- }
- }
- }
- }
- }
- });
-
-
- return false;
- }
-
- @Override
- public List tabComplete(CommandSender arg0, String[] arg1) {
- return null;
- }
- }
-
- private class CropControlCommand extends PlayerCommand {
-
- public CropControlCommand(String name) {
- super(name);
- setIdentifier("cropcontrol");
- setDescription("Reloads the configuration");
- setUsage("/cropcontrol");
- setArguments(0,0);
- setSenderMustBePlayer(false);
- }
-
- @Override
- public boolean execute(CommandSender sender, String[] arg1) {
- RootConfig.reload();
- DropConfig.reload();
- ToolConfig.clear();
- sender.sendMessage("Configuration cleared, will progressively reload.");
-
- return true;
- }
-
- @Override
- public List tabComplete(CommandSender arg0, String[] arg1) {
- return null;
- }
-
- }
-}
diff --git a/src/main/java/com/programmerdan/minecraft/cropcontrol/handler/CropControlDatabaseHandler.java b/src/main/java/com/programmerdan/minecraft/cropcontrol/handler/CropControlDatabaseHandler.java
index 334d0d8..3cc65be 100644
--- a/src/main/java/com/programmerdan/minecraft/cropcontrol/handler/CropControlDatabaseHandler.java
+++ b/src/main/java/com/programmerdan/minecraft/cropcontrol/handler/CropControlDatabaseHandler.java
@@ -97,8 +97,8 @@ private boolean configureData(ConfigurationSection config) {
}
private void activateDirtySave(ConfigurationSection config) {
- long period = 5*60*1000l;
- long delay = 5*60*1000l;
+ long period = 5 * 60 * 1000L;
+ long delay = 5 * 60 * 1000L;
if (config != null) {
period = config.getLong("period", period);
delay = config.getLong("delay", delay);
diff --git a/src/main/java/com/programmerdan/minecraft/cropcontrol/handler/CropControlEventHandler.java b/src/main/java/com/programmerdan/minecraft/cropcontrol/handler/CropControlEventHandler.java
index fd5e393..6c172fc 100644
--- a/src/main/java/com/programmerdan/minecraft/cropcontrol/handler/CropControlEventHandler.java
+++ b/src/main/java/com/programmerdan/minecraft/cropcontrol/handler/CropControlEventHandler.java
@@ -1,7 +1,7 @@
package com.programmerdan.minecraft.cropcontrol.handler;
import java.util.ArrayList;
-import java.util.HashMap;
+import java.util.EnumMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
@@ -14,12 +14,14 @@
import org.bukkit.Chunk;
import org.bukkit.Location;
import org.bukkit.Material;
+import org.bukkit.Tag;
import org.bukkit.TreeType;
import org.bukkit.World;
import org.bukkit.block.Biome;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.block.BlockState;
+import org.bukkit.block.data.Ageable;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.entity.Player;
@@ -47,10 +49,6 @@
import org.bukkit.event.world.StructureGrowEvent;
import org.bukkit.inventory.EquipmentSlot;
import org.bukkit.inventory.ItemStack;
-import org.bukkit.inventory.meta.ItemMeta;
-import org.bukkit.material.CocoaPlant;
-import org.bukkit.material.Crops;
-import org.bukkit.material.NetherWarts;
import org.bukkit.util.Vector;
import com.google.common.collect.Sets;
@@ -69,6 +67,8 @@
import net.md_5.bungee.api.chat.BaseComponent;
import net.md_5.bungee.api.chat.ComponentBuilder;
import net.md_5.bungee.api.chat.HoverEvent;
+import vg.civcraft.mc.civmodcore.api.BlockAPI;
+import vg.civcraft.mc.civmodcore.api.TreeTypeAPI;
/**
* Monitor for all growth, placement, spread, and break events and such.
@@ -92,9 +92,6 @@ public class CropControlEventHandler implements Listener {
private Set pendingChecks;
- public static final BlockFace[] directions = new BlockFace[] {
- BlockFace.NORTH, BlockFace.SOUTH, BlockFace.EAST, BlockFace.WEST };
-
public static final BlockFace[] traverse = new BlockFace[] {
BlockFace.DOWN, BlockFace.SELF, BlockFace.UP
};
@@ -107,8 +104,8 @@ public CropControlEventHandler(FileConfiguration config) {
baseDropMessage = (this.config.getBoolean("alert.enable", false) ? this.config.getString("alert.message") : null);
- harvestableCrops = new HashMap();
- trackedMaterials = new HashSet();
+ harvestableCrops = new EnumMap<>(Material.class);
+ trackedMaterials = new HashSet<>();
pendingChecks = Sets.newConcurrentHashSet();
fillHarvestableCropsList();
@@ -119,42 +116,40 @@ public CropControlEventHandler(FileConfiguration config) {
}
public void fillHarvestableCropsList() {
- harvestableCrops.put(Material.CROPS, true);
+ harvestableCrops.put(Material.WHEAT_SEEDS, true);
harvestableCrops.put(Material.CARROT, true);
harvestableCrops.put(Material.POTATO, true);
- harvestableCrops.put(Material.NETHER_WARTS, true);
- harvestableCrops.put(Material.BEETROOT_BLOCK, true);
+ harvestableCrops.put(Material.NETHER_WART, true);
+ harvestableCrops.put(Material.BEETROOT_SEEDS, true);
harvestableCrops.put(Material.COCOA, true);
harvestableCrops.put(Material.PUMPKIN_STEM, false);
harvestableCrops.put(Material.MELON_STEM, false);
harvestableCrops.put(Material.CACTUS, false);
harvestableCrops.put(Material.BROWN_MUSHROOM, false);
harvestableCrops.put(Material.RED_MUSHROOM, false);
- harvestableCrops.put(Material.SUGAR_CANE_BLOCK, false);
+ harvestableCrops.put(Material.SUGAR_CANE, false);
- trackedMaterials.add(Material.CROPS);
+ trackedMaterials.add(Material.WHEAT_SEEDS);
trackedMaterials.add(Material.CARROT);
trackedMaterials.add(Material.POTATO);
- trackedMaterials.add(Material.NETHER_WARTS);
- trackedMaterials.add(Material.BEETROOT_BLOCK);
+ trackedMaterials.add(Material.NETHER_WART);
+ trackedMaterials.add(Material.BEETROOTS);
trackedMaterials.add(Material.COCOA);
trackedMaterials.add(Material.PUMPKIN_STEM);
trackedMaterials.add(Material.PUMPKIN);
trackedMaterials.add(Material.MELON_STEM);
- trackedMaterials.add(Material.MELON_BLOCK);
+ trackedMaterials.add(Material.MELON);
trackedMaterials.add(Material.CACTUS);
- trackedMaterials.add(Material.SUGAR_CANE_BLOCK);
+ trackedMaterials.add(Material.SUGAR_CANE);
trackedMaterials.add(Material.BROWN_MUSHROOM);
trackedMaterials.add(Material.RED_MUSHROOM);
- trackedMaterials.add(Material.SAPLING);
+ trackedMaterials.addAll(Tag.SAPLINGS.getValues());
trackedMaterials.add(Material.CHORUS_PLANT);
trackedMaterials.add(Material.CHORUS_FLOWER);
- trackedMaterials.add(Material.HUGE_MUSHROOM_1);
- trackedMaterials.add(Material.HUGE_MUSHROOM_2);
- trackedMaterials.add(Material.LOG);
- trackedMaterials.add(Material.LOG_2);
- trackedMaterials.add(Material.LEAVES);
- trackedMaterials.add(Material.LEAVES_2);
+ trackedMaterials.add(Material.BROWN_MUSHROOM_BLOCK);
+ trackedMaterials.add(Material.RED_MUSHROOM_BLOCK);
+ trackedMaterials.addAll(Tag.LOGS.getValues());
+ trackedMaterials.addAll(Tag.LEAVES.getValues());
}
/**
@@ -192,7 +187,7 @@ public String getBaseCropState(Material material) {
return null;
case RED_MUSHROOM:
return null;
- case SUGAR_CANE_BLOCK:
+ case SUGAR_CANE:
return null;
default:
return "SEEDED";
@@ -202,129 +197,40 @@ public String getBaseCropState(Material material) {
public String getCropState(BlockState blockState) {
switch (blockState.getType()) { // .getBlock().getType()) {
case COCOA:
- return ((CocoaPlant) blockState.getData()).getSize().toString();
- case NETHER_WARTS:
- return ((NetherWarts) blockState.getData()).getState().toString();
+ case NETHER_WART:
case MELON_STEM:
- return (int) blockState.getBlock().getData() + "";
case PUMPKIN_STEM:
- return (int) blockState.getBlock().getData() + "";
+ Ageable ageable = (Ageable) blockState.getBlockData();
+ return String.valueOf(ageable.getAge());
case CACTUS:
return null;
case BROWN_MUSHROOM:
return null;
case RED_MUSHROOM:
return null;
- case SUGAR_CANE_BLOCK:
+ case SUGAR_CANE:
return null;
default:
//CropControl.getPlugin().debug("Unable to find CropState match for {0}", blockState);
- return ((Crops) blockState.getData()).getState().toString();
+ return blockState.getBlockData().getAsString();
}
}
- public String getSaplingType(Byte data) {
- switch (data) {
- case 0:
- return "OAK_SAPLING";
- case 1:
- return "SPRUCE_SAPLING";
- case 2:
- return "BIRCH_SAPLING";
- case 3:
- return "JUNGLE_SAPLING";
- case 4:
- return "ACACIA_SAPLING";
- case 5:
- return "DARK_OAK_SAPLING";
- default:
- CropControl.getPlugin().debug("Unknown sapling type {0}", data);
- return null;
- }
- }
-
- public Material getTrackedTypeMaterial(String trackedType) {
- for (Material material : harvestableCrops.keySet()) {
- if (material.toString().equals(trackedType))
- return material;
- }
-
- if (Material.MELON_BLOCK.toString().equals(trackedType))
- return Material.MELON_BLOCK;
- else if (Material.PUMPKIN.toString().equals(trackedType))
- return Material.PUMPKIN;
-
- for (Byte i = 0; i < 6; i++) {
- if (getSaplingType(i).equals(trackedType)) // TODO: odd structure here
- return Material.SAPLING;
- }
-
- for (TreeType treeType : TreeType.values()) {
- if (treeType.toString().equals(trackedType)) {
- if (treeType == TreeType.ACACIA || treeType == TreeType.DARK_OAK)
- return Material.LOG_2;
- else if (treeType == TreeType.BROWN_MUSHROOM)
- return Material.HUGE_MUSHROOM_1;
- else if (treeType == TreeType.RED_MUSHROOM)
- return Material.HUGE_MUSHROOM_2;
- else
- return Material.LOG;
- }
- }
-
- if (Material.CHORUS_PLANT.toString().equals(trackedType))
- return Material.CHORUS_PLANT;
-
- CropControl.getPlugin().debug("Unable to match tracked type material {0}", trackedType);
- return null;
- }
-
- public Material getTrackedCropMaterial(String _trackedType) {
- Material trackedType = Material.getMaterial(_trackedType);
- if (Material.MELON_BLOCK.equals(trackedType))
- return Material.MELON_BLOCK;
- else if (Material.PUMPKIN.equals(trackedType))
+ public Material getTrackedCropMaterial(String trackedStringType) {
+ Material trackedType = Material.getMaterial(trackedStringType);
+ if (Material.MELON == trackedType)
+ return Material.MELON;
+ else if (Material.PUMPKIN == trackedType)
return Material.PUMPKIN;
else {
for (Material material : harvestableCrops.keySet()) {
- if (material.equals(trackedType))
+ if (material == trackedType)
return material;
}
}
CropControl.getPlugin().debug("Unable to match tracked crop type material {0}", trackedType);
return null;
}
-
- public Material getTrackedSaplingMaterial(String trackedType) {
- for (Byte i = 0; i < 6; i++) {
- if (getSaplingType(i).equals(trackedType))
- return Material.SAPLING;
- }
- CropControl.getPlugin().debug("Unable to match tracked sapling type material {0}", trackedType);
- return null;
- }
-
- public Material getTrackedTreeMaterial(String trackedType) {
- if (Material.CHORUS_PLANT.toString().equals(trackedType))
- return Material.CHORUS_PLANT;
- else {
- for (TreeType treeType : TreeType.values()) {
- if (treeType.toString().equals(trackedType)) {
- if (treeType == TreeType.ACACIA || treeType == TreeType.DARK_OAK)
- return Material.LOG_2;
- else if (treeType == TreeType.BROWN_MUSHROOM)
- return Material.HUGE_MUSHROOM_1;
- else if (treeType == TreeType.RED_MUSHROOM)
- return Material.HUGE_MUSHROOM_2;
- else
- return Material.LOG;
- }
- }
- }
- CropControl.getPlugin().debug("Unable to match tracked tree type material {0}", trackedType);
-
- return null;
- }
public boolean maybeTracked(Material type) {
return trackedMaterials.contains(type);
@@ -337,7 +243,9 @@ public void onInteract(PlayerInteractEvent e) {
Player p = e.getPlayer();
- if (!p.hasPermission("cropcontrol.debug") ) return;
+ if (!p.hasPermission("cropcontrol.debug") ) {
+ return;
+ }
Block block = e.getClickedBlock();
int x = block.getX();
@@ -363,7 +271,9 @@ public void onInteract(PlayerInteractEvent e) {
Sapling sapling = chunk.getSapling(x, y, z);
TreeComponent component = chunk.getTreeComponent(x, y, z);
- if (crop == null && sapling == null && component == null) return;
+ if (crop == null && sapling == null && component == null) {
+ return;
+ }
p.sendMessage(ChatColor.GREEN + "Fier's fancy debug system:");
@@ -530,7 +440,7 @@ public void onPlaceBlock(BlockPlaceEvent e) {
int z = block.getZ();
WorldChunk chunk = CropControl.getDAO().getChunk(block.getChunk());
- if (CropControl.getDAO().isTracked(block) == true) {
+ if (CropControl.getDAO().isTracked(block)) {
// We've got a replacement
CropControl.getPlugin().debug("Ghost object? Placement is overtop a tracked object at {0}, {1}, {2}", x, y, z);
handleRemoval(block, chunk);
@@ -545,9 +455,9 @@ public void onPlaceBlock(BlockPlaceEvent e) {
}*/
// We've placed a crop!
- Crop.create(chunk, x, y, z, blockMaterial.toString(), getBaseCropState(blockMaterial),
+ Crop.create(chunk, x, y, z, blockMaterial, blockMaterial.toString(),
e.getPlayer().getUniqueId(), System.currentTimeMillis(), harvestableCrops.get(blockMaterial));
- } else if (blockMaterial == Material.SAPLING) {
+ } else if (Tag.SAPLINGS.isTagged(blockMaterial)) {
// we placed a block overtop an existing sapling. TODO: Do I need to remove sapling here, or will there be a break event?
/*Sapling sapling = chunk.getSapling(x, y, z);
if (sapling != null) {
@@ -556,7 +466,7 @@ public void onPlaceBlock(BlockPlaceEvent e) {
//return;
}*/
// We've placed a sapling!
- Sapling.create(chunk, x, y, z, getSaplingType(block.getData()),
+ Sapling.create(chunk, x, y, z, block.getType(),
e.getPlayer().getUniqueId(), System.currentTimeMillis(), false);
} else if (blockMaterial == Material.CHORUS_FLOWER) {
/*if (CropControl.getDAO().isTracked(block) == true) {
@@ -567,16 +477,16 @@ public void onPlaceBlock(BlockPlaceEvent e) {
// TODO: Check if connected to an existing chorus tree.
// First register the "tree"
- Tree chorusPlant = Tree.create(chunk, x, y, z, Material.CHORUS_PLANT.toString(),
+ Tree chorusPlant = Tree.create(chunk, x, y, z, TreeType.CHORUS_PLANT,
e.getPlayer().getUniqueId(), System.currentTimeMillis());
// Then the component in the tree.
- TreeComponent.create(chorusPlant, chunk, x, y, z, Material.CHORUS_PLANT.toString(),
+ TreeComponent.create(chorusPlant, chunk, x, y, z, TreeType.CHORUS_PLANT,
e.getPlayer().getUniqueId(), false);
} else if (blockMaterial.isSolid()){ // check for cactus.
- for (BlockFace face : CropControlEventHandler.directions) {
+ for (BlockFace face : BlockAPI.PLANAR_SIDES) {
Block adj = block.getRelative(face);
- if (Material.CACTUS.equals(adj.getType())) {
+ if (Material.CACTUS == adj.getType()) {
Location loc = adj.getLocation();
if (!pendingChecks.contains(loc)) {
pendingChecks.add(loc);
@@ -630,9 +540,7 @@ private void handleRemoval(final Block block, WorldChunk chunk) {
public void onCropGrow(BlockGrowEvent e) {
Block block = e.getNewState().getBlock();
- Bukkit.getServer().getScheduler().runTaskAsynchronously(CropControl.getPlugin(), new Runnable() {
- @Override
- public void run() {
+ Bukkit.getServer().getScheduler().runTaskAsynchronously(CropControl.getPlugin(),() -> {
WorldChunk chunk = CropControl.getDAO().getChunk(block.getChunk());
int x = block.getX();
int y = block.getY();
@@ -641,8 +549,8 @@ public void run() {
if (crop != null) {
crop.setCropState(getCropState(e.getNewState()));
} else {
- if (block.getType() == Material.MELON_BLOCK || block.getType() == Material.PUMPKIN) {
- for (BlockFace blockFace : CropControlEventHandler.directions) {
+ if (block.getType() == Material.MELON || block.getType() == Material.PUMPKIN) {
+ for (BlockFace blockFace : BlockAPI.PLANAR_SIDES) {
Block otherBlock = block.getRelative(blockFace);
WorldChunk otherChunk = CropControl.getDAO().getChunk(otherBlock.getChunk());
int otherX = otherBlock.getX();
@@ -652,12 +560,12 @@ public void run() {
if (otherCrop != null) {
UUID placerUUID = otherCrop.getPlacer();
- Crop.create(chunk, x,y,z, block.getType().toString(), null,
+ Crop.create(chunk, x,y,z, block.getType(), null,
placerUUID, System.currentTimeMillis(), true);
break;
}
}
- } else if (block.getType() == Material.CACTUS || block.getType() == Material.SUGAR_CANE_BLOCK) {
+ } else if (block.getType() == Material.CACTUS || block.getType() == Material.SUGAR_CANE) {
Block otherBlock = block.getRelative(BlockFace.DOWN);
int otherX = otherBlock.getX();
int otherY = otherBlock.getY();
@@ -666,21 +574,20 @@ public void run() {
if (otherCrop != null) {
UUID placerUUID = otherCrop.getPlacer();
- Crop.create(chunk, x,y,z, block.getType().toString(), null,
+ Crop.create(chunk, x,y,z, block.getType(), null,
placerUUID, System.currentTimeMillis(), true);
} else { // go one lower, might have been async out of order ..
Block finalCheck = otherBlock.getRelative(BlockFace.DOWN);
- if (block.getType().equals(finalCheck.getType())) { // same ballpark
+ if (block.getType() == finalCheck.getType()) { // same ballpark
Crop finalCrop = chunk.getCrop(finalCheck.getX(), finalCheck.getY(), finalCheck.getZ());
if (finalCrop != null) {
UUID placerUUID = finalCrop.getPlacer();
- Crop.create(chunk, x,y,z, block.getType().toString(), null,
+ Crop.create(chunk, x,y,z, block.getType(), null,
placerUUID, System.currentTimeMillis(), true);
}
}
}
- }
}
}
});
@@ -709,7 +616,7 @@ public void onBlockSpread(BlockSpreadEvent e) {
Crop sourceCrop = sourceChunk.getCrop(sourceX, sourceY, sourceZ);
if (sourceCrop != null) {
UUID placerUUID = sourceCrop.getPlacer();
- Crop.create(chunk, x, y, z, source.getType().toString(), null, placerUUID,
+ Crop.create(chunk, x, y, z, source.getType(), null, placerUUID,
System.currentTimeMillis(), true);
return;
}
@@ -719,7 +626,7 @@ public void onBlockSpread(BlockSpreadEvent e) {
treeComponent.setHarvestable(true);
// TODO: should we differentiate between flower and plant here?
- TreeComponent.create(treeComponent.getTreeID(), chunk, x, y, z, Material.CHORUS_PLANT.toString(),
+ TreeComponent.create(treeComponent.getTreeID(), chunk, x, y, z, TreeType.CHORUS_PLANT,
treeComponent.getPlacer(), true);
}
@@ -740,25 +647,24 @@ public void onTreeGrow(StructureGrowEvent e) {
return;
}
- List blocks = new ArrayList();
+ List blocks = new ArrayList<>();
if (sapling != null) {
sapling.setRemoved();
// Because dirt & saplings are part of the structure
for (BlockState state : e.getBlocks()) {
- if (state.getType() == Material.LOG || state.getType() == Material.LOG_2
- || state.getType() == Material.LEAVES || state.getType() == Material.LEAVES_2) {
+ if (Tag.LOGS.isTagged(state.getType()) || Tag.LEAVES.isTagged(state.getType())) {
blocks.add(state);
}
}
- if (blocks.size() == 0) {
+ if (blocks.isEmpty()) {
CropControl.getPlugin().debug("Ignoring tree grow that has no logs or leaves at {0}, {1}, {2}", x, y, z);
// TODO: do we remove the sapling?
return;
}
- Tree tree = Tree.create(sourceChunk, x, y, z, e.getSpecies().toString(), sapling.getPlacer(), System.currentTimeMillis());
+ Tree tree = Tree.create(sourceChunk, x, y, z, e.getSpecies(), sapling.getPlacer(), System.currentTimeMillis());
// Done in the case of Multiple saplings (Big Jungle trees etc)
for (BlockState state : e.getBlocks()) {
@@ -773,7 +679,7 @@ public void onTreeGrow(StructureGrowEvent e) {
testSapling.setRemoved();
}
}
- Set treesStolen = new HashSet();
+ Set treesStolen = new HashSet<>();
for (BlockState state : blocks) {
WorldChunk partChunk = CropControl.getDAO().getChunk(state.getChunk());
// TODO: differentiate between leaves and trunks
@@ -783,10 +689,10 @@ public void onTreeGrow(StructureGrowEvent e) {
treesStolen.add(exists.getTreeID());
exists.setRemoved();
}
- TreeComponent.create(tree, partChunk, state.getX(), state.getY(), state.getZ(), e.getSpecies().toString(),
+ TreeComponent.create(tree, partChunk, state.getX(), state.getY(), state.getZ(), e.getSpecies(),
tree.getPlacer(), true);
}
- if (treesStolen.size() > 0) {
+ if (!treesStolen.isEmpty()) {
// Check we didn't just override the last leaves of an old tree or something
for (Long treeID : treesStolen) {
List remainder = CropControl.getDAO().getTreeComponents(treeID);
@@ -802,22 +708,22 @@ public void onTreeGrow(StructureGrowEvent e) {
if (crop != null) {
// Because dirt & saplings are part of the structure
for (BlockState state : e.getBlocks()) {
- if (state.getType() == Material.HUGE_MUSHROOM_1 || state.getType() == Material.HUGE_MUSHROOM_2)
+ if (state.getType() == Material.BROWN_MUSHROOM || state.getType() == Material.RED_MUSHROOM_BLOCK)
blocks.add(state);
}
- if (blocks.size() == 0) {
+ if (blocks.isEmpty()) {
CropControl.getPlugin().debug("Ignoring mushroom? grow that has no mushroom parts at {0}, {1}, {2}", x, y, z);
return;
}
- Tree tree = Tree.create(sourceChunk, x, y, z, e.getSpecies().toString(), crop.getPlacer(), System.currentTimeMillis());
+ Tree tree = Tree.create(sourceChunk, x, y, z, e.getSpecies(), crop.getPlacer(), System.currentTimeMillis());
crop.setRemoved();
for (BlockState state : blocks) {
WorldChunk partChunk = CropControl.getDAO().getChunk(state.getChunk());
- TreeComponent.create(tree, partChunk, state.getX(), state.getY(), state.getZ(), e.getSpecies().toString(),
+ TreeComponent.create(tree, partChunk, state.getX(), state.getY(), state.getZ(), e.getSpecies(),
tree.getPlacer(), true);
}
}
@@ -848,15 +754,15 @@ public void onTreeGrow(StructureGrowEvent e) {
* @return True if any of the conditions are met.
*/
private boolean maybeBelowTracked(Block block) {
- if (Material.SOIL.equals(block.getType()) || // wheat, carrots, potatoes, beetroot, melon stalk, pumpkin stalk
- Material.NETHERRACK.equals(block.getType()) || // netherwart
- Material.SAND.equals(block.getType()) || // cactus, sugarcane
- Material.ENDER_STONE.equals(block.getType())) { // chorus fruit
+ if (Material.FARMLAND == block.getType() || // wheat, carrots, potatoes, beetroot, melon stalk, pumpkin stalk
+ Material.NETHERRACK == block.getType() || // netherwart
+ Material.SAND == block.getType() || // cactus, sugarcane
+ Material.END_STONE == block.getType()) { // chorus fruit
return true;
}
Block up = block.getRelative(BlockFace.UP);
- if (Material.BROWN_MUSHROOM.equals(up.getType()) || Material.RED_MUSHROOM.equals(up.getType()) || // mushrooms
- Material.SAPLING.equals(up.getType())) { // saplings
+ if (Material.BROWN_MUSHROOM == up.getType() || Material.RED_MUSHROOM == up.getType() || // mushrooms
+ Tag.SAPLINGS.isTagged(up.getType())) { // saplings
return true;
}
return false;
@@ -868,13 +774,8 @@ private boolean maybeBelowTracked(Block block) {
* @param block The block to test type on
* @return True if maybe could possible contain cocoa
*/
- @SuppressWarnings("deprecation")
private boolean maybeSideTracked(Block block) {
- if (Material.LOG.equals(block.getType()) && block.getData() == 3) {
- return true;
- } else {
- return false;
- }
+ return block.getType() == Material.JUNGLE_LOG;
}
/**
@@ -885,10 +786,10 @@ private boolean maybeSideTracked(Block block) {
* @param player
*/
private void trySideBreak(Block block, BreakType type, UUID player) {
- for (BlockFace face : directions) {
+ for (BlockFace face : BlockAPI.PLANAR_SIDES) {
Block faceBlock = block.getRelative(face);
Location loc = faceBlock.getLocation();
- if (Material.COCOA.equals(faceBlock.getType()) && !pendingChecks.contains(loc)) {
+ if (Material.COCOA == faceBlock.getType() && !pendingChecks.contains(loc)) {
pendingChecks.add(loc);
handleBreak(faceBlock, type, player, null);
}
@@ -912,7 +813,6 @@ private void trySideBreak(Block block, BreakType type, UUID player) {
*
* @param e The physics event.
*/
- @SuppressWarnings("deprecation")
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled=true)
public void onPhysics(BlockPhysicsEvent e) {
Block block = e.getBlock();
@@ -921,16 +821,16 @@ public void onPhysics(BlockPhysicsEvent e) {
boolean checkBreak = false;
if (maybeTracked(chMat) && !pendingChecks.contains(loc)) { // do we even slightly care?
// Check light levels.
- if (Material.CROPS.equals(chMat) || Material.POTATO.equals(chMat) || Material.CARROT.equals(chMat) || Material.BEETROOT.equals(chMat)) {
+ if (Material.WHEAT == chMat || Material.POTATOES == chMat || Material.CARROTS == chMat || Material.BEETROOTS == chMat) {
if (block.getLightLevel() < 8) {
checkBreak = true;
}
- } else if (Material.RED_MUSHROOM.equals(chMat) || Material.BROWN_MUSHROOM.equals(chMat)) {
+ } else if (Material.RED_MUSHROOM == chMat || Material.BROWN_MUSHROOM == chMat) {
Block below = block.getRelative(BlockFace.DOWN);
Material belowM = below.getType();
- if (!Material.MYCEL.equals(belowM) && !Material.DIRT.equals(belowM)) {
+ if (Material.MYCELIUM != belowM && Material.DIRT != belowM) {
checkBreak = true;
- } else if (Material.DIRT.equals(belowM) && below.getData() != 2) {
+ } else if (Material.PODZOL == belowM) {
checkBreak = true;
}
}
@@ -941,46 +841,47 @@ public void onPhysics(BlockPhysicsEvent e) {
} else { // we haven't found a break condition yet. However, what follows aren't light level checks but rather
// block checks, so these are controlled by a variety of rules. Some involve physics firing _adjacent_ to the block.
// Basically it's a crapshoot.
- if (Material.SUGAR_CANE_BLOCK.equals(e.getChangedType())) {
+ if (Material.SUGAR_CANE == e.getChangedType()) {
// Sugarcane winds up being weird. I'm still not sure what event fires and removes the bottom block but for
// unattended (non-player) breaks physics events remove middle and top blocks. So, we just register
// breaks for lower and upper blocks and if they are gone, we know it then.
//
// Note this will leave singular base blocks undetected. TODO
- if (chMat.equals(e.getChangedType())) {
+ if (chMat == e.getChangedType()) {
for (BlockFace a : CropControlEventHandler.traverse) {
Location adjL = block.getRelative(a).getLocation();
if (!pendingChecks.contains(adjL)) {
pendingChecks.add(adjL);
// So, the physics check can take a tick to resolve. We mark our interest but defer resolution.
- Bukkit.getScheduler().runTaskLater(CropControl.getPlugin(), new Runnable() {
- public void run() {
+ Bukkit.getScheduler().runTaskLater(CropControl.getPlugin(), () -> {
handleBreak(adjL.getBlock(), BreakType.PHYSICS, null, null);
- }
- }, 1L);
+ }, 1L);
}
}
}
- } else if (Material.CACTUS.equals(e.getChangedType())) {
- if (chMat.equals(e.getChangedType())) return; // handled elsewhere
+ } else if (Material.CACTUS == e.getChangedType()) {
+ if (chMat == e.getChangedType()) {
+ return; // handled elsewhere
+ }
// Cactus is a little simpler. It breaks on adjacent placements; that's what would trigger this event.
- for (BlockFace face : CropControlEventHandler.directions) {
+ for (BlockFace face : BlockAPI.PLANAR_SIDES) {
// We look around face-adjacent places and trigger a break-check for any cactus found.
Block adj = block.getRelative(face);
Material adjM = adj.getType();
Location adjL = adj.getLocation();
- if (Material.CACTUS.equals(adjM) && !pendingChecks.contains(adjL)) {
+ if (Material.CACTUS == adjM && !pendingChecks.contains(adjL)) {
pendingChecks.add(adjL);
// So, the physics check can take a tick to resolve. We mark our interest but defer resolution.
Bukkit.getScheduler().runTaskLater(CropControl.getPlugin(), new Runnable() {
+ @Override
public void run() {
handleBreak(adj, BreakType.PHYSICS, null, null);
}
}, 1L);
}
}
- } else if (Material.CHORUS_FLOWER.equals(e.getChangedType()) || Material.CHORUS_PLANT.equals(e.getChangedType())) {
+ } else if (Material.CHORUS_FLOWER == e.getChangedType() || Material.CHORUS_PLANT == e.getChangedType()) {
// TODO: this one is complicated; it's more like sugarcane I guess? Still need rules.
}
}
@@ -1057,7 +958,7 @@ public void onBlockExplode(BlockExplodeEvent e) {
* @param player Who triggered it (if applicable)
*/
public void doMultiblockHandler(List blockList, BreakType breakType, UUID player) {
- Set toBreakList = new HashSet();
+ Set toBreakList = new HashSet<>();
for (Block block : blockList) {
WorldChunk chunk = CropControl.getDAO().getChunk(block.getChunk());
@@ -1066,7 +967,7 @@ public void doMultiblockHandler(List blockList, BreakType breakType, UUID
int z = block.getZ();
TreeComponent component = chunk.getTreeComponent(x, y, z);
if (component != null) {
- if (getTrackedTreeMaterial(component.getTreeType()) == Material.CHORUS_PLANT) {
+ if (component.getTreeType() == TreeType.CHORUS_PLANT) {
for (Location location : returnUpwardsChorusBlocks(block)) {
if (!toBreakList.contains(location)) {
toBreakList.add(location);
@@ -1085,8 +986,8 @@ public void doMultiblockHandler(List blockList, BreakType breakType, UUID
}
Crop crop = chunk.getCrop(x, y, z);
if (crop != null) {
- Material type = getTrackedCropMaterial(crop.getCropType());
- if (type == Material.SUGAR_CANE_BLOCK || type == Material.CACTUS) {
+ Material type = crop.getCropType();
+ if (type == Material.SUGAR_CANE || type == Material.CACTUS) {
for (Location location : returnUpwardsBlocks(block, type)) {
if (!toBreakList.contains(location)) {
toBreakList.add(location);
@@ -1105,9 +1006,9 @@ public void doMultiblockHandler(List blockList, BreakType breakType, UUID
}
if (maybeSideTracked(block)) {
- for (BlockFace face : directions) {
+ for (BlockFace face : BlockAPI.PLANAR_SIDES) {
Block faceBlock = block.getRelative(face);
- if (Material.COCOA.equals(faceBlock.getType())) {
+ if (Material.COCOA == faceBlock.getType()) {
toBreakList.add(faceBlock.getLocation());
}
}
@@ -1123,7 +1024,7 @@ public void doMultiblockHandler(List blockList, BreakType breakType, UUID
}
}
}
- if (toBreakList.size() > 0) {
+ if (!toBreakList.isEmpty()) {
handleBreak(null, breakType, player, toBreakList);
}
}
@@ -1186,14 +1087,14 @@ public void onPlayerBucketEmpty(PlayerBucketEmptyEvent e) {
@EventHandler(priority=EventPriority.HIGHEST, ignoreCancelled = true)
public void onBlockFromTo(BlockFromToEvent e) {
Material toBlock = e.getToBlock().getType();
- if (toBlock == Material.WATER || toBlock == Material.STATIONARY_WATER) {
+ if (toBlock == Material.WATER) {
Block block = e.getBlock();
Location loc = block.getLocation();
if (!pendingChecks.contains(loc)) {
pendingChecks.add(loc);
handleBreak(block, BreakType.WATER, null, null);
}
- } else if (toBlock == Material.LAVA || toBlock == Material.STATIONARY_LAVA) {
+ } else if (toBlock == Material.LAVA) {
Block block = e.getBlock();
Location loc = block.getLocation();
if (!pendingChecks.contains(loc)) {
@@ -1204,9 +1105,9 @@ public void onBlockFromTo(BlockFromToEvent e) {
}
@EventHandler(priority=EventPriority.HIGHEST, ignoreCancelled = true)
- public void onPistionExtend(BlockPistonExtendEvent e) {
+ public void onPistonExtend(BlockPistonExtendEvent e) {
// We need to order movements of moved components from furthest to nearest
- TreeMap movements = new TreeMap();
+ TreeMap movements = new TreeMap<>();
for (Block block : e.getBlocks()) {
// handle tree breaks
WorldChunk chunk = CropControl.getDAO().getChunk(block.getChunk());
@@ -1224,7 +1125,7 @@ public void onPistionExtend(BlockPistonExtendEvent e) {
if (component != null) {
// chorus fruit tree break
- if (getTrackedTreeMaterial(component.getTreeType()) == Material.CHORUS_PLANT) {
+ if (component.getTreeType() == TreeType.CHORUS_PLANT) {
Location loc = block.getLocation();
if (!pendingChecks.contains(loc)) {
pendingChecks.add(loc);
@@ -1238,25 +1139,19 @@ public void onPistionExtend(BlockPistonExtendEvent e) {
Tree tree = chunk.getTree(x, y, z);
if (tree == null) {
movements.put(e.getBlock().getLocation().distance(block.getLocation()),
- new Runnable() {
- @Override
- public void run() {
+ () -> {
component.updateLocation(newChunk.getChunkID(), newX, newY, newZ);
CropControl.getPlugin().debug("Moved tree component from {0} {1} {2} to {3}", x, y, z, component);
}
- }
);
} else {
movements.put(e.getBlock().getLocation().distance(block.getLocation()),
- new Runnable() {
- @Override
- public void run() {
+ () -> {
component.updateLocation(newChunk.getChunkID(), newX, newY, newZ);
CropControl.getPlugin().debug("Moved tree component from {0} {1} {2} to {3}", x, y, z, component);
tree.updateLocation(newChunk.getChunkID(), newX, newY, newZ);
CropControl.getPlugin().debug("Moved tree from {0} {1} {2} to {3}", x, y, z, tree);
}
- }
);
}
// if tree base, move the whole tree
@@ -1287,7 +1182,7 @@ public void run() {
@EventHandler(priority=EventPriority.HIGHEST, ignoreCancelled = true)
public void onPistonRetract(BlockPistonRetractEvent e) {
// We need to order movements of moved components from furthest to nearest
- TreeMap movements = new TreeMap();
+ TreeMap movements = new TreeMap<>();
for (Block block : e.getBlocks()) {
// handle tree breaks
@@ -1305,7 +1200,7 @@ public void onPistonRetract(BlockPistonRetractEvent e) {
int newZ = nextBlock.getZ();
if (component != null) {
- if (getTrackedTreeMaterial(component.getTreeType()) == Material.CHORUS_PLANT) {
+ if (component.getTreeType() == TreeType.CHORUS_PLANT) {
Location loc = block.getLocation();
if (!pendingChecks.contains(loc)) {
pendingChecks.add(loc);
@@ -1319,25 +1214,19 @@ public void onPistonRetract(BlockPistonRetractEvent e) {
Tree tree = chunk.getTree(x, y, z);
if (tree == null) {
movements.put(e.getBlock().getLocation().distance(block.getLocation()),
- new Runnable() {
- @Override
- public void run() {
- component.updateLocation(newChunk.getChunkID(), newX, newY, newZ);
- CropControl.getPlugin().debug("Moved tree component from {0} {1} {2} to {3}", x, y, z, component);
- }
+ () -> {
+ component.updateLocation(newChunk.getChunkID(), newX, newY, newZ);
+ CropControl.getPlugin().debug("Moved tree component from {0} {1} {2} to {3}", x, y, z, component);
}
);
} else {
movements.put(e.getBlock().getLocation().distance(block.getLocation()),
- new Runnable() {
- @Override
- public void run() {
+ () -> {
component.updateLocation(newChunk.getChunkID(), newX, newY, newZ);
CropControl.getPlugin().debug("Moved tree component from {0} {1} {2} to {3}", x, y, z, component);
tree.updateLocation(newChunk.getChunkID(), newX, newY, newZ);
CropControl.getPlugin().debug("Moved tree from {0} {1} {2} to {3}", x, y, z, tree);
}
- }
);
}
// if tree base, move the whole tree
@@ -1366,20 +1255,20 @@ public void run() {
}
public Set returnUpwardsBlocks(Block startBlock, Material upwardBlockMaterial) {
- Set checkedLocations = new HashSet();
+ Set checkedLocations = new HashSet<>();
- Set uncheckedLocations = new HashSet();
+ Set uncheckedLocations = new HashSet<>();
Crop crop = CropControl.getDAO().getChunk(startBlock.getChunk()).getCrop(startBlock.getX(), startBlock.getY(), startBlock.getZ());
if (crop != null) {
- if (getTrackedCropMaterial(crop.getCropType()) == upwardBlockMaterial) {
+ if (crop.getCropType() == upwardBlockMaterial) {
uncheckedLocations.add(startBlock.getLocation());
}
} else {
return checkedLocations; // failfast
}
- Set toAddLocations = new HashSet();
+ Set toAddLocations = new HashSet<>();
do {
for (Location unchecked : uncheckedLocations) {
@@ -1396,9 +1285,8 @@ public Set returnUpwardsBlocks(Block startBlock, Material upwardBlockM
&& !toAddLocations.contains(up)
&& !checkedLocations.contains(up)) {
- if (getTrackedCropMaterial(
- CropControl.getDAO().getChunk(upBlock.getChunk()).getCrop(upBlock.getX(), upBlock.getY(), upBlock.getZ())
- .getCropType()) == upwardBlockMaterial)
+ if (CropControl.getDAO().getChunk(upBlock.getChunk()).getCrop(upBlock.getX(), upBlock.getY(), upBlock.getZ())
+ .getCropType() == upwardBlockMaterial)
toAddLocations.add(up);
}
}
@@ -1415,14 +1303,14 @@ public Set returnUpwardsBlocks(Block startBlock, Material upwardBlockM
}
public Set returnUpwardsChorusBlocks(Block startBlock) {
- Set checkedLocations = new HashSet();
+ Set checkedLocations = new HashSet<>();
- Set uncheckedLocations = new HashSet();
+ Set uncheckedLocations = new HashSet<>();
TreeComponent component = CropControl.getDAO().getChunk(startBlock.getChunk())
.getTreeComponent(startBlock.getX(), startBlock.getY(), startBlock.getZ());
if (component != null) {
- if (getTrackedTreeMaterial(component.getTreeType()) == Material.CHORUS_PLANT) {
+ if (component.getTreeType() == TreeType.CHORUS_PLANT) {
uncheckedLocations.add(startBlock.getLocation());
}
} else {
@@ -1431,7 +1319,7 @@ public Set returnUpwardsChorusBlocks(Block startBlock) {
Tree tree = CropControl.getDAO().getTree(component);
- Set toAddLocations = new HashSet();
+ Set toAddLocations = new HashSet<>();
do {
for (Location unchecked : uncheckedLocations) {
if (CropControl.getDAO().isTracked(unchecked.getBlock())
@@ -1449,7 +1337,7 @@ public Set returnUpwardsChorusBlocks(Block startBlock) {
&& !checkedLocations.contains(rel)) {
TreeComponent relComponent = CropControl.getDAO().getChunk(relBlock.getChunk())
.getTreeComponent(relBlock.getX(), relBlock.getY(), relBlock.getZ());
- if (getTrackedTreeMaterial(relComponent.getTreeType()) == Material.CHORUS_PLANT
+ if (relComponent.getTreeType() == TreeType.CHORUS_PLANT
&& CropControl.getDAO().isTreeComponent(tree, relComponent)) {
toAddLocations.add(rel);
}
@@ -1478,9 +1366,7 @@ public void handleBreak(final Block startBlock, final BreakType breakType, final
}
// TODO does it need to be 1 tick? more? less?
Bukkit.getScheduler().runTaskLater(CropControl.getPlugin(),
- new Runnable() {
- @Override
- public void run() {
+ () -> {
if (startBlock != null) { // no altBlocks.
try {
WorldChunk chunk = CropControl.getDAO().getChunk(startBlock.getChunk());
@@ -1490,13 +1376,13 @@ public void run() {
Crop crop = chunk.getCrop(x, y, z);
if (crop != null) {
- Material type = getTrackedCropMaterial(crop.getCropType());
+ Material type = crop.getCropType();
if (type == startBlock.getType()) { // Still there.
//CropControl.getPlugin().debug("Ignoring cancelled Crop {3} track vs. actual {4} type {0}, {1}, {2}", x, y, z, type, startBlock.getType());
return;
}
- if (type == Material.SUGAR_CANE_BLOCK || type == Material.CACTUS) {
+ if (type == Material.SUGAR_CANE || type == Material.CACTUS) {
for (Location location : returnUpwardsBlocks(startBlock, type)) {
WorldChunk upChunk = CropControl.getDAO().getChunk(location.getChunk());
Crop upCrop = upChunk.getCrop(location.getBlockX(), location.getBlockY(), location.getBlockZ());
@@ -1516,7 +1402,7 @@ public void run() {
Sapling sapling = chunk.getSapling(x, y, z);
if (sapling != null) {
- if (getTrackedSaplingMaterial(sapling.getSaplingType()) == startBlock.getType()) {
+ if (sapling.getSaplingType() == startBlock.getType()) {
//CropControl.getPlugin().debug("Ignoring cancelled Sapling {3} track vs. actual {4} type {0}, {1}, {2}", x, y, z, sapling.getSaplingType(), startBlock.getType());
return;
}
@@ -1529,17 +1415,13 @@ public void run() {
TreeComponent treeComponent = chunk.getTreeComponent(x, y, z);
if (treeComponent != null) {
Tree tree = CropControl.getDAO().getTree(treeComponent);
- Material type = getTrackedTreeMaterial(treeComponent.getTreeType());
- if (type ==
- (startBlock.getType() == Material.LEAVES ? Material.LOG :
- startBlock.getType() == Material.LEAVES_2 ? Material.LOG_2 :
- startBlock.getType() == Material.CHORUS_FLOWER ? Material.CHORUS_PLANT :
- startBlock.getType())) {
+ TreeType type = treeComponent.getTreeType();
+ if (type == TreeTypeAPI.getMatchingTreeType(startBlock.getType())) {
//CropControl.getPlugin().debug("Ignoring cancelled Tree Component {3} track vs. actual {4} type {0}, {1}, {2}", x, y, z, type, startBlock.getType());
return;
}
- if (type == Material.CHORUS_PLANT) {
+ if (type == TreeType.CHORUS_PLANT) {
for (Location location : returnUpwardsChorusBlocks(startBlock)) {
TreeComponent upComponent = CropControl.getDAO().getChunk(location.getChunk())
.getTreeComponent(location.getBlockX(), location.getBlockY(), location.getBlockZ());
@@ -1600,7 +1482,6 @@ public void run() {
if (CropControl.getDAO().getTreeComponents(treeComponent.getTreeID()).isEmpty()) {
CropControl.getPlugin().debug("Tree at {0} broken as {1} by {2}",
location, breakType, breaker);
-
CropControl.getDAO().getTree(treeComponent).setRemoved();
}
@@ -1612,8 +1493,7 @@ public void run() {
}
}
}
- }
- }, 1L);
+ }, 1L);
}
private void drop(Block block, Locatable dropable, UUID player, BreakType breakType) {
@@ -1649,13 +1529,13 @@ private void drop(Block block, Locatable dropable, UUID player, BreakType breakT
toolUsed = p.getInventory().getItemInMainHand();
}
}
- List commandBuffer = new LinkedList();
+ List commandBuffer = new LinkedList<>();
List items = config.realizeDrops(breakType, placePlayer, player, harvestable, biome, toolUsed, world, commandBuffer);
if (items != null) {
CropControlDropEvent event = new CropControlDropEvent(bLoc, breakType, dropable, player, items, commandBuffer);
Bukkit.getPluginManager().callEvent(event);
- if (!event.isCancelled() && ((event.getItems() != null && event.getItems().size() > 0) || (event.getCommands() != null && !event.getCommands().isEmpty()))) {
+ if (!event.isCancelled() && ((event.getItems() != null && !event.getItems().isEmpty()) || (event.getCommands() != null && !event.getCommands().isEmpty()))) {
if (!event.getItems().isEmpty()) {
if (player != null) {
CropControl.getPlugin().info("Dropping {0} items at {1} due to break {2} caused by player {3}: {4}",
@@ -1701,12 +1581,11 @@ private void drop(Block block, Locatable dropable, UUID player, BreakType breakT
}
public String summarizeDrops(List items) {
- StringBuffer toString = new StringBuffer();
+ StringBuilder toString = new StringBuilder();
for (ItemStack itemStack: items) {
toString.append("[");
Material material = itemStack.getType();
int amount = itemStack.getAmount();
- short durability = itemStack.getDurability();
if (amount != 1) {
toString.append(amount).append("x");
@@ -1714,7 +1593,6 @@ public String summarizeDrops(List items) {
toString.append(itemStack.hasItemMeta() && itemStack.getItemMeta().hasDisplayName() ?
itemStack.getItemMeta().getDisplayName() : material.toString());
- toString.append(":").append(durability);
toString.append("]");
}
return toString.toString();
@@ -1723,27 +1601,26 @@ public String summarizeDrops(List items) {
public String friendlyCropName(Locatable dropable) {
if (dropable instanceof Crop) {
Crop crop = (Crop) dropable;
- return crop.getCropType();
+ return crop.getCropType().toString();
}
if (dropable instanceof Sapling) {
Sapling sapling = (Sapling) dropable;
- return sapling.getSaplingType();
+ return sapling.getSaplingType().toString();
}
if (dropable instanceof TreeComponent) {
TreeComponent component = (TreeComponent) dropable;
- return component.getTreeType();
+ return component.getTreeType().toString();
}
return "Unknown";
}
public String friendlySummarizeDrops(List items) {
- StringBuffer toString = new StringBuffer();
+ StringBuilder toString = new StringBuilder();
for (ItemStack itemStack: items) {
toString.append(" ");
Material material = itemStack.getType();
int amount = itemStack.getAmount();
- short durability = itemStack.getDurability();
if (amount != 1) {
toString.append(amount).append(" x ");
@@ -1751,9 +1628,6 @@ public String friendlySummarizeDrops(List items) {
toString.append(itemStack.hasItemMeta() && itemStack.getItemMeta().hasDisplayName() ?
itemStack.getItemMeta().getDisplayName() : material.toString());
- if (durability > 0) {
- toString.append(":").append(durability);
- }
}
return toString.toString();
}
@@ -1764,7 +1638,7 @@ public void realDrop(Location location, List items) {
}
}
- public static enum BreakType {
+ public enum BreakType {
PLAYER, WATER, LAVA, PISTON, EXPLOSION, NATURAL, FIRE, PHYSICS;
}
diff --git a/src/main/java/com/programmerdan/minecraft/cropcontrol/handler/RealisticBiomesEventHandler.java b/src/main/java/com/programmerdan/minecraft/cropcontrol/handler/RealisticBiomesEventHandler.java
index a9269b3..1c595c2 100644
--- a/src/main/java/com/programmerdan/minecraft/cropcontrol/handler/RealisticBiomesEventHandler.java
+++ b/src/main/java/com/programmerdan/minecraft/cropcontrol/handler/RealisticBiomesEventHandler.java
@@ -4,12 +4,11 @@
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
+import com.programmerdan.minecraft.cropcontrol.CropControl;
import com.untamedears.realisticbiomes.events.RealisticBiomesBlockBreakEvent;
import com.untamedears.realisticbiomes.events.RealisticBiomesBlockGrowEvent;
import com.untamedears.realisticbiomes.events.RealisticBiomesStructureGrowEvent;
-import com.programmerdan.minecraft.cropcontrol.CropControl;
-
/**
* Realistic Biomes cancels all the normal bukkit events; I've layered in shadow events called after RB's manipulations
* that mirror the underlying Bukkit events. These are captured and processed here, calling their counterparts in the
diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml
index c3ac6f4..e5af962 100644
--- a/src/main/resources/plugin.yml
+++ b/src/main/resources/plugin.yml
@@ -14,6 +14,7 @@ commands:
description: Generates all configured drops in-game for testing
usage: /ccgen [items]
permission: cropcontrol.adv
+ player-only: true
permissions:
cropcontrol.*:
description: Gives access to all CropControl commands
@@ -27,3 +28,4 @@ permissions:
cropcontrol.debug:
description: Enables the CropControl debug interface.
default: op
+api-version: 1.14
\ No newline at end of file