9
0
mirror of https://github.com/Xiao-MoMi/Custom-Crops.git synced 2025-12-22 00:19:24 +00:00
This commit is contained in:
Xiao-MoMi
2022-10-14 14:36:07 +08:00
parent 19de99dc3e
commit 3edf08f5b3
9 changed files with 40 additions and 29 deletions

View File

@@ -4,7 +4,7 @@ plugins {
}
group = 'net.momirealms'
version = '2.0-r4'
version = '2.0-r6'
repositories {
mavenCentral()

View File

@@ -70,6 +70,7 @@ public class ConfigUtil {
SprinklerConfig.load();
WaterCanConfig.load();
SoundConfig.load();
// would not be activated when enabling
if (CustomCrops.plugin.getPlaceholderManager() != null) {
CustomCrops.plugin.getPlaceholderManager().unload();
CustomCrops.plugin.getPlaceholderManager().load();

View File

@@ -254,11 +254,11 @@ public abstract class HandlerP extends Function {
if (instant) {
Bukkit.getScheduler().runTaskLater(CustomCrops.plugin, ()-> {
if (location.getBlock().getType() != Material.AIR) return;
cropManager.proceedHarvest(crop, player, location, fertilizer);
cropManager.proceedHarvest(crop, player, location, fertilizer, false);
},1);
}
else {
cropManager.proceedHarvest(crop, player, location, fertilizer);
cropManager.proceedHarvest(crop, player, location, fertilizer, false);
}
}

View File

@@ -299,7 +299,7 @@ public class ItemsAdderFrameHandler extends ItemsAdderHandler {
if (customWorld == null) return;
Fertilizer fertilizer = customWorld.getFertilizer(location.clone().subtract(0,1,0));
cropManager.proceedHarvest(crop, player, location, fertilizer);
cropManager.proceedHarvest(crop, player, location, fertilizer, true);
if (crop.getReturnStage() == null) {
customWorld.removeCrop(location);

View File

@@ -117,7 +117,9 @@ public class ItemsAdderWireHandler extends ItemsAdderHandler {
ItemStack itemInHand = event.getItem();
if (!blockID.equals(BasicItemConfig.deadCrop)) {
if (!hasNextStage(blockID)) {
if (MainConfig.canRightClickHarvest && !(MainConfig.emptyHand && itemInHand != null && itemInHand.getType() != Material.AIR)) {
ItemStack mainHand = player.getInventory().getItemInMainHand();
ItemStack offHand = player.getInventory().getItemInOffHand();
if (MainConfig.canRightClickHarvest && !(MainConfig.emptyHand && (mainHand.getType() != Material.AIR || offHand.getType() != Material.AIR))) {
if (!AntiGrief.testBreak(player, location)) return;
CustomBlock.remove(location);
this.onInteractRipeCrop(location, blockID, player);
@@ -307,7 +309,7 @@ public class ItemsAdderWireHandler extends ItemsAdderHandler {
if (customWorld == null) return;
Fertilizer fertilizer = customWorld.getFertilizer(location.clone().subtract(0,1,0));
cropManager.proceedHarvest(crop, player, location, fertilizer);
cropManager.proceedHarvest(crop, player, location, fertilizer, true);
if (crop.getReturnStage() == null) {
customWorld.removeCrop(location);

View File

@@ -266,7 +266,7 @@ public class OraxenFrameHandler extends OraxenHandler {
if (customWorld == null) return;
Fertilizer fertilizer = customWorld.getFertilizer(location.clone().subtract(0,1,0));
cropManager.proceedHarvest(crop, player, location, fertilizer);
cropManager.proceedHarvest(crop, player, location, fertilizer, true);
if (crop.getReturnStage() == null) {
customWorld.removeCrop(location);
return;

View File

@@ -304,7 +304,7 @@ public class OraxenWireHandler extends OraxenHandler{
if (customWorld == null) return;
Fertilizer fertilizer = customWorld.getFertilizer(location.clone().subtract(0,1,0));
cropManager.proceedHarvest(crop, player, location, fertilizer);
cropManager.proceedHarvest(crop, player, location, fertilizer, true);
if (crop.getReturnStage() == null) {
customWorld.removeCrop(location);

View File

@@ -138,12 +138,23 @@ public class CropManager extends Function {
public void loadSeason() {
if (SeasonConfig.enable) {
for (CustomWorld customWorld : customWorlds.values()) {
customWorld.unloadSeason();
}
if (seasonInterface != null) {
seasonInterface.unload();
this.seasonInterface = null;
}
if (MainConfig.realisticSeasonHook) seasonInterface = new RealisticSeasonsHook();
else seasonInterface = new InternalSeason();
seasonInterface.load();
//empty when enabling
for (CustomWorld customWorld : customWorlds.values()) {
customWorld.loadSeason();
}
else if (this.seasonInterface != null) {
this.seasonInterface.unload();
return;
}
if (seasonInterface != null) {
seasonInterface.unload();
this.seasonInterface = null;
}
}
@@ -300,12 +311,12 @@ public class CropManager extends Function {
return customWorlds.get(world);
}
public void proceedHarvest(Crop crop, Player player, Location location, @Nullable Fertilizer fertilizer) {
public void proceedHarvest(Crop crop, Player player, Location location, @Nullable Fertilizer fertilizer, boolean isRightClick) {
//Call harvest event
CropHarvestEvent cropHarvestEvent = new CropHarvestEvent(player, crop, location, fertilizer);
Bukkit.getPluginManager().callEvent(cropHarvestEvent);
if (cropHarvestEvent.isCancelled()) return;
if (!isRightClick && player.getGameMode() == GameMode.CREATIVE) return;
ActionInterface[] actions = crop.getActions();
if (actions != null) performActions(actions, player);
@@ -317,9 +328,6 @@ public class CropManager extends Function {
1,1
);
}
if (player.getGameMode() == GameMode.CREATIVE) return;
QualityLoot qualityLoot = crop.getQualityLoot();
if (qualityLoot != null) {
int amount = ThreadLocalRandom.current().nextInt(qualityLoot.getMin(), qualityLoot.getMax() + 1);

View File

@@ -120,7 +120,7 @@ public class CustomWorld {
backUp(world.getName());
}
private void backUp(String worldName) {
public void backUp(String worldName) {
if (!MainConfig.autoBackUp) return;
Date date = new Date();
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss");
@@ -138,7 +138,7 @@ public class CustomWorld {
}
}
private void loadScarecrow() {
public void loadScarecrow() {
if (!MainConfig.enableCrow) return;
try {
JsonParser jsonParser = new JsonParser();
@@ -161,7 +161,7 @@ public class CustomWorld {
}
}
private void unloadScarecrow() {
public void unloadScarecrow() {
if (!MainConfig.enableCrow) return;
JsonObject jsonObject = new JsonObject();
for (Map.Entry<String, HashSet<SimpleLocation>> entry : scarecrowCache.entrySet()) {
@@ -180,7 +180,7 @@ public class CustomWorld {
}
}
private void loadSeason() {
public void loadSeason() {
if (!SeasonConfig.enable) return;
try {
JsonParser jsonParser = new JsonParser();
@@ -203,7 +203,7 @@ public class CustomWorld {
}
}
private void unloadSeason() {
public void unloadSeason() {
if (!SeasonConfig.enable) return;
JsonObject jsonObject = new JsonObject();
JsonPrimitive jsonPrimitive = new JsonPrimitive(SeasonUtils.getSeason(world).name());
@@ -216,7 +216,7 @@ public class CustomWorld {
SeasonUtils.unloadSeason(world);
}
private void loadPot() {
public void loadPot() {
try {
JsonParser jsonParser = new JsonParser();
JsonElement json= jsonParser.parse(new FileReader(new File(CustomCrops.plugin.getDataFolder().getParentFile().getParentFile(), world.getName() + File.separator + "customcrops_data" + File.separator + "pot.json")));
@@ -238,7 +238,7 @@ public class CustomWorld {
}
}
private void unloadPot() {
public void unloadPot() {
JsonObject jsonObject = new JsonObject();
JsonArray jsonArray = new JsonArray();
watered.addAll(playerWatered);
@@ -254,7 +254,7 @@ public class CustomWorld {
}
}
private void loadFertilizerCache() {
public void loadFertilizerCache() {
YamlConfiguration data = loadData("fertilizers", world.getName());
for (String key : data.getKeys(false)) {
String[] loc = StringUtils.split(key, ",");
@@ -268,7 +268,7 @@ public class CustomWorld {
}
}
private void unloadFertilizer() {
public void unloadFertilizer() {
YamlConfiguration data = new YamlConfiguration();
for (Map.Entry<SimpleLocation, Fertilizer> en : fertilizerCache.entrySet()) {
SimpleLocation location = en.getKey();
@@ -285,7 +285,7 @@ public class CustomWorld {
}
}
private void loadSprinklerCache() {
public void loadSprinklerCache() {
YamlConfiguration data = loadData("sprinklers", world.getName());
for (String key : data.getKeys(false)) {
String[] loc = StringUtils.split(key, ",");
@@ -301,7 +301,7 @@ public class CustomWorld {
}
}
private void unloadSprinkler() {
public void unloadSprinkler() {
YamlConfiguration data = new YamlConfiguration();
for (Map.Entry<SimpleLocation, Sprinkler> en : sprinklerCache.entrySet()) {
SimpleLocation location = en.getKey();
@@ -318,11 +318,11 @@ public class CustomWorld {
}
}
private void loadCropCache() {
public void loadCropCache() {
cropData = loadData("crops", world.getName());
}
private void unloadCrop() {
public void unloadCrop() {
try {
cropData.save(new File(CustomCrops.plugin.getDataFolder().getParentFile().getParentFile(), world.getName() + File.separator + "customcrops_data" + File.separator + "crops.yml"));
}