Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<groupId>com.programmerdan.minecraft</groupId>
<artifactId>cropcontrol</artifactId>
<version>1.1.4</version>
<version>1.2.0</version>
<packaging>jar</packaging>
<name>CropControl</name>
<url>https://github.com/DevotedMC/CropControl</url>
Expand Down Expand Up @@ -64,25 +64,25 @@
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.12-R0.1-SNAPSHOT</version>
<version>1.14.4-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>vg.civcraft.mc.civmodcore</groupId>
<artifactId>CivModCore</artifactId>
<version>1.6.0</version>
<version>1.7.5</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.untamedears</groupId>
<artifactId>RealisticBiomes</artifactId>
<version>1.4.0</version>
<version>2.0.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>vg.civcraft.mc.citadel</groupId>
<artifactId>Citadel</artifactId>
<version>3.9.0</version>
<version>4.0.1</version>
<scope>provided</scope>
</dependency>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -36,10 +35,11 @@ public void onEnable() {

CropControl.instance = this;
connectDatabase();
if (!this.isEnabled()) return;
if (!this.isEnabled()) {
return;
}

registerEventHandler();
registerCommandHandler();
}

@Override
Expand All @@ -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);
Expand All @@ -80,12 +82,6 @@ private void registerEventHandler() {
this.setEnabled(false);
}
}

private void registerCommandHandler() {
if (!this.isEnabled()) return;
this.setCommandHandler(new CropControlCommandHandler());
this.getCommandHandler().registerCommands();
}

/**
*
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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<String> tabComplete(CommandSender sender, String[] args) {
return null;
}

}
Original file line number Diff line number Diff line change
@@ -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<String> 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<ItemStack> 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<String> tabComplete(CommandSender sender, String[] args) {
// TODO Auto-generated method stub
return null;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
*
*/
public class DropConfig {
private static ConcurrentHashMap<String, DropConfig> configs = new ConcurrentHashMap<String, DropConfig>();
private static ConcurrentHashMap<String, DropConfig> configs = new ConcurrentHashMap<>();
private static DropConfig nonce = new DropConfig();

private ConfigurationSection dropSection = null;
Expand All @@ -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;

Expand All @@ -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);

Expand All @@ -76,10 +76,10 @@ public int getMutliplierMax() {
}

public List<ItemStack> getDrops(int multiplier) {
if (template == null || template.size() == 0) {
return new ArrayList<ItemStack>();
if (template == null || template.isEmpty()) {
return new ArrayList<>();
}
ArrayList<ItemStack> drops = new ArrayList<ItemStack>(template.size());
ArrayList<ItemStack> drops = new ArrayList<>(template.size());
for (ItemStack i : template) {
int newSize = i.getAmount() * multiplier;
if (newSize <= 0) {
Expand Down
Loading