9
0
mirror of https://github.com/Xiao-MoMi/Custom-Crops.git synced 2025-12-22 16:39:36 +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' group = 'net.momirealms'
version = '2.0-r4' version = '2.0-r6'
repositories { repositories {
mavenCentral() mavenCentral()

View File

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

View File

@@ -254,11 +254,11 @@ public abstract class HandlerP extends Function {
if (instant) { if (instant) {
Bukkit.getScheduler().runTaskLater(CustomCrops.plugin, ()-> { Bukkit.getScheduler().runTaskLater(CustomCrops.plugin, ()-> {
if (location.getBlock().getType() != Material.AIR) return; if (location.getBlock().getType() != Material.AIR) return;
cropManager.proceedHarvest(crop, player, location, fertilizer); cropManager.proceedHarvest(crop, player, location, fertilizer, false);
},1); },1);
} }
else { 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; if (customWorld == null) return;
Fertilizer fertilizer = customWorld.getFertilizer(location.clone().subtract(0,1,0)); 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) { if (crop.getReturnStage() == null) {
customWorld.removeCrop(location); customWorld.removeCrop(location);

View File

@@ -117,7 +117,9 @@ public class ItemsAdderWireHandler extends ItemsAdderHandler {
ItemStack itemInHand = event.getItem(); ItemStack itemInHand = event.getItem();
if (!blockID.equals(BasicItemConfig.deadCrop)) { if (!blockID.equals(BasicItemConfig.deadCrop)) {
if (!hasNextStage(blockID)) { 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; if (!AntiGrief.testBreak(player, location)) return;
CustomBlock.remove(location); CustomBlock.remove(location);
this.onInteractRipeCrop(location, blockID, player); this.onInteractRipeCrop(location, blockID, player);
@@ -307,7 +309,7 @@ public class ItemsAdderWireHandler extends ItemsAdderHandler {
if (customWorld == null) return; if (customWorld == null) return;
Fertilizer fertilizer = customWorld.getFertilizer(location.clone().subtract(0,1,0)); 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) { if (crop.getReturnStage() == null) {
customWorld.removeCrop(location); customWorld.removeCrop(location);

View File

@@ -266,7 +266,7 @@ public class OraxenFrameHandler extends OraxenHandler {
if (customWorld == null) return; if (customWorld == null) return;
Fertilizer fertilizer = customWorld.getFertilizer(location.clone().subtract(0,1,0)); 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) { if (crop.getReturnStage() == null) {
customWorld.removeCrop(location); customWorld.removeCrop(location);
return; return;

View File

@@ -304,7 +304,7 @@ public class OraxenWireHandler extends OraxenHandler{
if (customWorld == null) return; if (customWorld == null) return;
Fertilizer fertilizer = customWorld.getFertilizer(location.clone().subtract(0,1,0)); 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) { if (crop.getReturnStage() == null) {
customWorld.removeCrop(location); customWorld.removeCrop(location);

View File

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

View File

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