9
0
mirror of https://github.com/Xiao-MoMi/Custom-Crops.git synced 2025-12-22 08:29:35 +00:00
This commit is contained in:
Xiao-MoMi
2022-10-14 21:40:21 +08:00
parent 3edf08f5b3
commit 9cc1abfc44
28 changed files with 492 additions and 303 deletions

View File

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

View File

@@ -0,0 +1,55 @@
/*
* Copyright (C) <2022> <XiaoMoMi>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package net.momirealms.customcrops.api.event;
import org.bukkit.Location;
import org.bukkit.event.Cancellable;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
import org.jetbrains.annotations.NotNull;
public class CrowAttackEvent extends Event implements Cancellable {
private final Location location;
private boolean cancelled;
private static final HandlerList handlers = new HandlerList();
public CrowAttackEvent(Location location) {
this.location = location;
this.cancelled = false;
}
@Override
public @NotNull HandlerList getHandlers() {
return handlers;
}
@Override
public boolean isCancelled() {
return cancelled;
}
@Override
public void setCancelled(boolean cancel) {
cancelled = cancel;
}
public Location getLocation() {
return location;
}
}

View File

@@ -17,6 +17,7 @@
package net.momirealms.customcrops.commands;
import net.momirealms.customcrops.commands.subcmd.GrowCommand;
import net.momirealms.customcrops.commands.subcmd.ReloadCommand;
import net.momirealms.customcrops.commands.subcmd.SetSeasonCommand;
import net.momirealms.customcrops.commands.subcmd.SimulateCommand;
@@ -59,6 +60,7 @@ public class PluginCommand implements TabExecutor {
regSubCommand(ReloadCommand.INSTANCE);
regSubCommand(SetSeasonCommand.INSTANCE);
regSubCommand(SimulateCommand.INSTANCE);
regSubCommand(GrowCommand.INSTANCE);
}
public void regSubCommand(SubCommand executor) {

View File

@@ -0,0 +1,81 @@
/*
* Copyright (C) <2022> <XiaoMoMi>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package net.momirealms.customcrops.commands.subcmd;
import net.momirealms.customcrops.CustomCrops;
import net.momirealms.customcrops.commands.AbstractSubCommand;
import net.momirealms.customcrops.commands.SubCommand;
import net.momirealms.customcrops.config.MessageConfig;
import net.momirealms.customcrops.utils.AdventureUtil;
import org.bukkit.Bukkit;
import org.bukkit.World;
import org.bukkit.command.CommandSender;
import java.util.List;
public class GrowCommand extends AbstractSubCommand {
public static final SubCommand INSTANCE = new GrowCommand();
public GrowCommand() {
super("grow", null);
}
@Override
public boolean onCommand(CommandSender sender, List<String> args) {
if (args.size() < 2) {
AdventureUtil.sendMessage(sender, MessageConfig.prefix + MessageConfig.lackArgs);
}
else {
World world = Bukkit.getWorld(args.get(0));
if (world == null) {
AdventureUtil.sendMessage(sender, MessageConfig.prefix + MessageConfig.worldNotExists);
return true;
}
int growTime;
try {
growTime = Integer.parseInt(args.get(1));
if (growTime <= 0 || growTime > 23999) {
AdventureUtil.sendMessage(sender, MessageConfig.prefix + "Time should be a positive number between 1-23999");
return true;
}
}
catch (IllegalArgumentException e) {
AdventureUtil.sendMessage(sender, MessageConfig.prefix + "Time should be a positive number between 1-23999");
e.printStackTrace();
return true;
}
Bukkit.getScheduler().runTaskAsynchronously(CustomCrops.plugin, () -> {
CustomCrops.plugin.getCropManager().grow(world, growTime, 0, 0, false, true);
});
AdventureUtil.sendMessage(sender, MessageConfig.prefix + MessageConfig.growSimulation);
}
return true;
}
@Override
public List<String> onTabComplete(CommandSender sender, List<String> args) {
if (args.size() == 1) {
return getWorlds(args);
}
if (args.size() == 2) {
return List.of("<CropGrowTime>");
}
return super.onTabComplete(sender, args);
}
}

View File

@@ -65,7 +65,7 @@ public class SimulateCommand extends AbstractSubCommand {
return true;
}
Bukkit.getScheduler().runTaskAsynchronously(CustomCrops.plugin, () -> {
CustomCrops.plugin.getCropManager().grow(world, growTime, sprinklerTime, dryTime, false);
CustomCrops.plugin.getCropManager().grow(world, growTime, sprinklerTime, dryTime, false, false);
});
AdventureUtil.sendMessage(sender, MessageConfig.prefix + MessageConfig.growSimulation);
}

View File

@@ -79,6 +79,7 @@ public class ConfigUtil {
CustomCrops.plugin.getCropManager().loadMode();
CustomCrops.plugin.getCropManager().loadSeason();
CustomCrops.plugin.getCropManager().loadPacket();
CustomCrops.plugin.getCropManager().loadVanillaMechanic();
}
}
}

View File

@@ -26,11 +26,14 @@ import net.momirealms.customcrops.objects.QualityRatio;
import net.momirealms.customcrops.utils.AdventureUtil;
import org.apache.commons.lang.StringUtils;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.Particle;
import org.bukkit.World;
import org.bukkit.configuration.file.YamlConfiguration;
import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
public class MainConfig {
@@ -103,6 +106,12 @@ public class MainConfig {
public static String[] summerMsg;
public static String[] autumnMsg;
public static String[] winterMsg;
public static String worldFolder;
public static boolean rightHarvestVanilla;
public static boolean preventPlantVanilla;
public static Material[] preventPlantVanillaArray;
public static boolean enableConvert;
public static HashMap<Material, String> vanilla2Crops;
public static void load() {
ConfigUtil.update("config.yml");
@@ -126,6 +135,7 @@ public class MainConfig {
}
worlds = worldList.toArray(new World[0]);
worldFolder = StringUtils.replace(config.getString("worlds.worlds-folder",""), "\\", File.separator);
cropMode = config.getString("mechanics.crops-mode", "tripwire").equals("tripwire");
limitation = config.getBoolean("optimization.limitation.enable", true);
@@ -215,6 +225,36 @@ public class MainConfig {
waterBarEmpty = config.getString("watering-can-lore.water-bar.empty", "뀁뀄");
waterBarRight = config.getString("watering-can-lore.water-bar.right", "뀁뀅</font>");
rightHarvestVanilla = config.getBoolean("mechanics.vanilla-crops.right-click-harvest", false);
preventPlantVanilla = config.getBoolean("mechanics.vanilla-crops.prevent-plant.enable", false);
List<Material> preventPlantVanillaList = new ArrayList<>();
for (String key : config.getStringList("mechanics.vanilla-crops.prevent-plant.list")) {
try {
preventPlantVanillaList.add(Material.valueOf(key.toUpperCase()));
}
catch (Exception e) {
AdventureUtil.consoleMessage("<red>[CustomCrops] Vanilla Block " + key + " doesn't exist");
}
}
preventPlantVanillaArray = preventPlantVanillaList.toArray(new Material[0]);
enableConvert = config.getBoolean("mechanics.vanilla-crops.convert-to-customcrops.enable", false);
if (enableConvert) {
vanilla2Crops = new HashMap<>();
for (String key : config.getConfigurationSection("mechanics.vanilla-crops.convert-to-customcrops.list").getKeys(false)) {
try {
Material material = Material.valueOf(key.toUpperCase());
vanilla2Crops.put(material, config.getString("mechanics.vanilla-crops.convert-to-customcrops.list." + key));
}
catch (Exception e) {
AdventureUtil.consoleMessage("<red>[CustomCrops] Vanilla Item " + key + " doesn't exist");
}
}
} else {
vanilla2Crops = null;
}
antiGriefs = new ArrayList<>();
if (config.getBoolean("integration.Residence",false)){
if (Bukkit.getPluginManager().getPlugin("Residence") == null) Log.warn("Failed to initialize Residence!");

View File

@@ -22,16 +22,19 @@ import de.tr7zw.changeme.nbtapi.NBTItem;
import net.kyori.adventure.text.minimessage.MiniMessage;
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
import net.momirealms.customcrops.CustomCrops;
import net.momirealms.customcrops.Function;
import net.momirealms.customcrops.api.crop.Crop;
import net.momirealms.customcrops.api.event.*;
import net.momirealms.customcrops.config.*;
import net.momirealms.customcrops.integrations.season.CCSeason;
import net.momirealms.customcrops.managers.CropManager;
import net.momirealms.customcrops.managers.CustomWorld;
import net.momirealms.customcrops.managers.listener.InteractListener;
import net.momirealms.customcrops.objects.Function;
import net.momirealms.customcrops.objects.Sprinkler;
import net.momirealms.customcrops.objects.WaterCan;
import net.momirealms.customcrops.objects.fertilizer.Fertilizer;
import net.momirealms.customcrops.objects.requirements.PlantingCondition;
import net.momirealms.customcrops.objects.requirements.RequirementInterface;
import net.momirealms.customcrops.utils.AdventureUtil;
import net.momirealms.customcrops.utils.FurnitureUtil;
import net.momirealms.customcrops.utils.HologramUtil;
@@ -39,6 +42,7 @@ import net.momirealms.customcrops.utils.LimitationUtil;
import org.apache.commons.lang.StringUtils;
import org.bukkit.*;
import org.bukkit.block.Block;
import org.bukkit.entity.ItemFrame;
import org.bukkit.entity.Player;
import org.bukkit.event.HandlerList;
import org.bukkit.event.player.PlayerInteractEvent;
@@ -530,4 +534,69 @@ public abstract class HandlerP extends Function {
}
}
}
protected void plantSeed(Location seedLoc, String cropName, Player player, ItemStack itemInHand, boolean isOraxen, boolean isWire) {
Crop crop = CropConfig.CROPS.get(cropName);
if (crop == null) return;
CustomWorld customWorld = cropManager.getCustomWorld(seedLoc.getWorld());
if (customWorld == null) return;
if (!isOraxen && FurnitureUtil.hasFurniture(seedLoc.clone().add(0.5,0.5,0.5))) return;
if (isOraxen && FurnitureUtil.hasFurniture(seedLoc.clone().add(0.5,0.03125,0.5))) return;
if (seedLoc.getBlock().getType() != Material.AIR) return;
PlantingCondition plantingCondition = new PlantingCondition(seedLoc, player);
CCSeason[] seasons = crop.getSeasons();
if (SeasonConfig.enable && seasons != null) {
if (cropManager.isWrongSeason(seedLoc, seasons)) {
if (MainConfig.notifyInWrongSeason) AdventureUtil.playerMessage(player, MessageConfig.prefix + MessageConfig.wrongSeason);
if (MainConfig.preventInWrongSeason) return;
}
}
if (crop.getRequirements() != null) {
for (RequirementInterface requirement : crop.getRequirements()) {
if (!requirement.isConditionMet(plantingCondition)) {
return;
}
}
}
if (MainConfig.limitation ) {
if (isWire && LimitationUtil.reachWireLimit(seedLoc)) {
AdventureUtil.playerMessage(player, MessageConfig.prefix + MessageConfig.limitWire.replace("{max}", String.valueOf(MainConfig.wireAmount)));
return;
}
if (!isWire && LimitationUtil.reachFrameLimit(seedLoc)) {
AdventureUtil.playerMessage(player, MessageConfig.prefix + MessageConfig.limitFrame.replace("{max}", String.valueOf(MainConfig.frameAmount)));
return;
}
}
SeedPlantEvent seedPlantEvent = new SeedPlantEvent(player, seedLoc, crop);
Bukkit.getPluginManager().callEvent(seedPlantEvent);
if (seedPlantEvent.isCancelled()) {
return;
}
if (SoundConfig.plantSeed.isEnable()) {
AdventureUtil.playerSound(
player,
SoundConfig.plantSeed.getSource(),
SoundConfig.plantSeed.getKey(),
1,1
);
}
if (player.getGameMode() != GameMode.CREATIVE) itemInHand.setAmount(itemInHand.getAmount() - 1);
if (isWire) customInterface.placeWire(seedLoc, cropName + "_stage_1");
else {
ItemFrame itemFrame = customInterface.placeFurniture(seedLoc, cropName + "_stage_1");
if (itemFrame == null) return;
itemFrame.setRotation(FurnitureUtil.getRandomRotation());
}
customWorld.addCrop(seedLoc, cropName);
}
}

View File

@@ -23,7 +23,6 @@ import net.momirealms.customcrops.api.crop.Crop;
import net.momirealms.customcrops.config.BasicItemConfig;
import net.momirealms.customcrops.config.CropConfig;
import net.momirealms.customcrops.config.MainConfig;
import net.momirealms.customcrops.helper.Log;
import net.momirealms.customcrops.integrations.customplugin.CustomInterface;
import net.momirealms.customcrops.managers.CropManager;
import net.momirealms.customcrops.managers.CropModeInterface;

View File

@@ -24,20 +24,17 @@ import dev.lone.itemsadder.api.Events.CustomBlockBreakEvent;
import dev.lone.itemsadder.api.Events.FurnitureBreakEvent;
import dev.lone.itemsadder.api.Events.FurnitureInteractEvent;
import net.momirealms.customcrops.api.crop.Crop;
import net.momirealms.customcrops.api.event.SeedPlantEvent;
import net.momirealms.customcrops.config.*;
import net.momirealms.customcrops.config.BasicItemConfig;
import net.momirealms.customcrops.config.MainConfig;
import net.momirealms.customcrops.config.SoundConfig;
import net.momirealms.customcrops.config.SprinklerConfig;
import net.momirealms.customcrops.integrations.AntiGrief;
import net.momirealms.customcrops.integrations.season.CCSeason;
import net.momirealms.customcrops.managers.CropManager;
import net.momirealms.customcrops.managers.CustomWorld;
import net.momirealms.customcrops.objects.Sprinkler;
import net.momirealms.customcrops.objects.fertilizer.Fertilizer;
import net.momirealms.customcrops.objects.requirements.PlantingCondition;
import net.momirealms.customcrops.objects.requirements.RequirementInterface;
import net.momirealms.customcrops.utils.AdventureUtil;
import net.momirealms.customcrops.utils.FurnitureUtil;
import net.momirealms.customcrops.utils.LimitationUtil;
import org.bukkit.Bukkit;
import org.bukkit.GameMode;
import org.bukkit.Location;
import org.bukkit.Material;
@@ -187,65 +184,17 @@ public class ItemsAdderFrameHandler extends ItemsAdderHandler {
if (event.getBlockFace() != BlockFace.UP) return;
CustomStack customStack = CustomStack.byItemStack(itemInHand);
if (customStack == null) return;
if (customStack != null) {
String namespacedID = customStack.getNamespacedID();
if (namespacedID.endsWith("_seeds")) {
String cropName = customStack.getId().substring(0, customStack.getId().length() - 6);
Crop crop = CropConfig.CROPS.get(cropName);
if (crop == null) return;
CustomWorld customWorld = cropManager.getCustomWorld(seedLoc.getWorld());
if (customWorld == null) return;
if (FurnitureUtil.hasFurniture(seedLoc.clone().add(0.5,0.5,0.5))) return;
if (seedLoc.getBlock().getType() != Material.AIR) return;
PlantingCondition plantingCondition = new PlantingCondition(seedLoc, player);
if (crop.getRequirements() != null) {
for (RequirementInterface requirement : crop.getRequirements()) {
if (!requirement.isConditionMet(plantingCondition)) {
return;
plantSeed(seedLoc, cropName, player, itemInHand, false, false);
}
}
}
if (MainConfig.limitation && LimitationUtil.reachFrameLimit(potLoc)) {
AdventureUtil.playerMessage(player, MessageConfig.prefix + MessageConfig.limitFrame.replace("{max}", String.valueOf(MainConfig.frameAmount)));
return;
}
CCSeason[] seasons = crop.getSeasons();
if (SeasonConfig.enable && seasons != null) {
if (cropManager.isWrongSeason(seedLoc, seasons)) {
if (MainConfig.notifyInWrongSeason) AdventureUtil.playerMessage(player, MessageConfig.prefix + MessageConfig.wrongSeason);
if (MainConfig.preventInWrongSeason) return;
}
}
SeedPlantEvent seedPlantEvent = new SeedPlantEvent(player, seedLoc, crop);
Bukkit.getPluginManager().callEvent(seedPlantEvent);
if (seedPlantEvent.isCancelled()) {
return;
}
if (SoundConfig.plantSeed.isEnable()) {
AdventureUtil.playerSound(
player,
SoundConfig.plantSeed.getSource(),
SoundConfig.plantSeed.getKey(),
1,1
);
}
if (player.getGameMode() != GameMode.CREATIVE) itemInHand.setAmount(itemInHand.getAmount() - 1);
CustomFurniture customFurniture = CustomFurniture.spawn(namespacedID.substring(0, namespacedID.length() - 5) + "stage_1", seedLoc.getBlock());
if (customFurniture != null) {
if (customFurniture.getArmorstand() instanceof ItemFrame itemFrame) {
itemFrame.setRotation(FurnitureUtil.getRandomRotation());
}
}
customWorld.addCrop(seedLoc, cropName);
else if (MainConfig.enableConvert) {
String cropName = MainConfig.vanilla2Crops.get(itemInHand.getType());
if (cropName == null) return;
plantSeed(seedLoc, cropName, player, itemInHand, false, false);
}
}
}

View File

@@ -24,20 +24,16 @@ import dev.lone.itemsadder.api.Events.CustomBlockInteractEvent;
import dev.lone.itemsadder.api.Events.FurnitureBreakEvent;
import dev.lone.itemsadder.api.Events.FurnitureInteractEvent;
import net.momirealms.customcrops.api.crop.Crop;
import net.momirealms.customcrops.api.event.SeedPlantEvent;
import net.momirealms.customcrops.config.*;
import net.momirealms.customcrops.config.BasicItemConfig;
import net.momirealms.customcrops.config.MainConfig;
import net.momirealms.customcrops.config.SoundConfig;
import net.momirealms.customcrops.config.SprinklerConfig;
import net.momirealms.customcrops.integrations.AntiGrief;
import net.momirealms.customcrops.integrations.season.CCSeason;
import net.momirealms.customcrops.managers.CropManager;
import net.momirealms.customcrops.managers.CustomWorld;
import net.momirealms.customcrops.objects.Sprinkler;
import net.momirealms.customcrops.objects.fertilizer.Fertilizer;
import net.momirealms.customcrops.objects.requirements.PlantingCondition;
import net.momirealms.customcrops.objects.requirements.RequirementInterface;
import net.momirealms.customcrops.utils.AdventureUtil;
import net.momirealms.customcrops.utils.FurnitureUtil;
import net.momirealms.customcrops.utils.LimitationUtil;
import org.bukkit.Bukkit;
import org.bukkit.GameMode;
import org.bukkit.Location;
import org.bukkit.Material;
@@ -161,65 +157,23 @@ public class ItemsAdderWireHandler extends ItemsAdderHandler {
if (event.getBlockFace() != BlockFace.UP) return;
Location seedLoc = location.clone().add(0,1,0);
CustomStack customStack = CustomStack.byItemStack(itemInHand);
if (customStack == null) return;
if (customStack != null) {
String namespacedID = customStack.getNamespacedID();
if (namespacedID.endsWith("_seeds")) {
String cropName = customStack.getId().substring(0, customStack.getId().length() - 6);
Crop crop = CropConfig.CROPS.get(cropName);
if (crop == null) return;
Location seedLoc = location.clone().add(0,1,0);
CustomWorld customWorld = cropManager.getCustomWorld(seedLoc.getWorld());
if (customWorld == null) return;
if (FurnitureUtil.hasFurniture(seedLoc.clone().add(0.5,0.5,0.5))) return;
if (seedLoc.getBlock().getType() != Material.AIR) return;
PlantingCondition plantingCondition = new PlantingCondition(seedLoc, player);
if (crop.getRequirements() != null) {
for (RequirementInterface requirement : crop.getRequirements()) {
if (!requirement.isConditionMet(plantingCondition)) {
return;
plantSeed(seedLoc, cropName, player, itemInHand, false, true);
}
}
else if (MainConfig.enableConvert) {
String cropName = MainConfig.vanilla2Crops.get(itemInHand.getType());
if (cropName == null) return;
plantSeed(seedLoc, cropName, player, itemInHand, false, true);
}
}
}
if (MainConfig.limitation && LimitationUtil.reachWireLimit(location)) {
AdventureUtil.playerMessage(player, MessageConfig.prefix + MessageConfig.limitWire.replace("{max}", String.valueOf(MainConfig.wireAmount)));
return;
}
CCSeason[] seasons = crop.getSeasons();
if (SeasonConfig.enable && seasons != null) {
if (cropManager.isWrongSeason(seedLoc, seasons)) {
if (MainConfig.notifyInWrongSeason) AdventureUtil.playerMessage(player, MessageConfig.prefix + MessageConfig.wrongSeason);
if (MainConfig.preventInWrongSeason) return;
}
}
SeedPlantEvent seedPlantEvent = new SeedPlantEvent(player, seedLoc, crop);
Bukkit.getPluginManager().callEvent(seedPlantEvent);
if (seedPlantEvent.isCancelled()) {
return;
}
if (SoundConfig.plantSeed.isEnable()) {
AdventureUtil.playerSound(
player,
SoundConfig.plantSeed.getSource(),
SoundConfig.plantSeed.getKey(),
1,1
);
}
if (player.getGameMode() != GameMode.CREATIVE) itemInHand.setAmount(itemInHand.getAmount() - 1);
CustomBlock.place(namespacedID.substring(0, namespacedID.length() - 5) + "stage_1", seedLoc);
customWorld.addCrop(seedLoc, cropName);
}
}
}
public void onInteractBlock(CustomBlockInteractEvent event) {

View File

@@ -17,30 +17,26 @@
package net.momirealms.customcrops.integrations.customplugin.oraxen;
import de.tr7zw.changeme.nbtapi.NBTCompound;
import de.tr7zw.changeme.nbtapi.NBTItem;
import io.th0rgal.oraxen.events.OraxenFurnitureBreakEvent;
import io.th0rgal.oraxen.events.OraxenFurnitureInteractEvent;
import io.th0rgal.oraxen.events.OraxenNoteBlockBreakEvent;
import io.th0rgal.oraxen.events.OraxenNoteBlockInteractEvent;
import io.th0rgal.oraxen.items.OraxenItems;
import io.th0rgal.oraxen.mechanics.provided.gameplay.furniture.FurnitureFactory;
import io.th0rgal.oraxen.mechanics.provided.gameplay.furniture.FurnitureMechanic;
import io.th0rgal.oraxen.utils.drops.Drop;
import net.momirealms.customcrops.api.crop.Crop;
import net.momirealms.customcrops.api.event.SeedPlantEvent;
import net.momirealms.customcrops.config.*;
import net.momirealms.customcrops.config.BasicItemConfig;
import net.momirealms.customcrops.config.MainConfig;
import net.momirealms.customcrops.config.SoundConfig;
import net.momirealms.customcrops.config.SprinklerConfig;
import net.momirealms.customcrops.integrations.AntiGrief;
import net.momirealms.customcrops.integrations.season.CCSeason;
import net.momirealms.customcrops.managers.CropManager;
import net.momirealms.customcrops.managers.CustomWorld;
import net.momirealms.customcrops.objects.Sprinkler;
import net.momirealms.customcrops.objects.fertilizer.Fertilizer;
import net.momirealms.customcrops.objects.requirements.PlantingCondition;
import net.momirealms.customcrops.objects.requirements.RequirementInterface;
import net.momirealms.customcrops.utils.AdventureUtil;
import net.momirealms.customcrops.utils.FurnitureUtil;
import net.momirealms.customcrops.utils.LimitationUtil;
import org.bukkit.Bukkit;
import org.bukkit.GameMode;
import org.bukkit.Location;
import org.bukkit.Material;
@@ -114,7 +110,7 @@ public class OraxenFrameHandler extends OraxenHandler {
super.removeScarecrow(event.getBlock().getLocation());
return;
}
//TODO check if event.getBlock()
if (id.contains("_stage_")) {
if (id.equals(BasicItemConfig.deadCrop)) return;
if (hasNextStage(id)) {
@@ -142,63 +138,18 @@ public class OraxenFrameHandler extends OraxenHandler {
if (super.tryMisc(player, itemInHand, potLoc)) return;
if (event.getBlockFace() != BlockFace.UP) return;
NBTItem nbtItem = new NBTItem(itemInHand);
NBTCompound bukkitCompound = nbtItem.getCompound("PublicBukkitValues");
if (bukkitCompound == null) return;
String id = bukkitCompound.getString("oraxen:id");
if (id == null || !id.endsWith("_seeds")) return;
String id = OraxenItems.getIdByItem(itemInHand);
if (id != null) {
if (id.endsWith("_seeds")) {
String cropName = id.substring(0, id.length() - 6);
Crop crop = CropConfig.CROPS.get(cropName);
if (crop == null) return;
CustomWorld customWorld = cropManager.getCustomWorld(seedLoc.getWorld());
if (customWorld == null) return;
if (FurnitureUtil.hasFurniture(seedLoc.clone().add(0.5,0.03125,0.5))) return;
if (seedLoc.getBlock().getType() != Material.AIR) return;
PlantingCondition plantingCondition = new PlantingCondition(seedLoc, player);
if (crop.getRequirements() != null) {
for (RequirementInterface requirement : crop.getRequirements()) {
if (!requirement.isConditionMet(plantingCondition)) {
return;
plantSeed(seedLoc, cropName, player, itemInHand, true, false);
}
}
else if (MainConfig.enableConvert) {
String cropName = MainConfig.vanilla2Crops.get(itemInHand.getType());
if (cropName == null) return;
plantSeed(seedLoc, cropName, player, itemInHand, true, false);
}
if (MainConfig.limitation && LimitationUtil.reachFrameLimit(potLoc)) {
AdventureUtil.playerMessage(player, MessageConfig.prefix + MessageConfig.limitFrame.replace("{max}", String.valueOf(MainConfig.frameAmount)));
return;
}
CCSeason[] seasons = crop.getSeasons();
if (SeasonConfig.enable && seasons != null) {
if (cropManager.isWrongSeason(seedLoc, seasons)) {
if (MainConfig.notifyInWrongSeason) AdventureUtil.playerMessage(player, MessageConfig.prefix + MessageConfig.wrongSeason);
if (MainConfig.preventInWrongSeason) return;
}
}
SeedPlantEvent seedPlantEvent = new SeedPlantEvent(player, seedLoc, crop);
Bukkit.getPluginManager().callEvent(seedPlantEvent);
if (seedPlantEvent.isCancelled()) {
return;
}
if (SoundConfig.plantSeed.isEnable()) {
AdventureUtil.playerSound(
player,
SoundConfig.plantSeed.getSource(),
SoundConfig.plantSeed.getKey(),
1,1
);
}
if (player.getGameMode() != GameMode.CREATIVE) itemInHand.setAmount(itemInHand.getAmount() - 1);
ItemFrame itemFrame = customInterface.placeFurniture(seedLoc, id.substring(0, id.length() - 5) + "stage_1");
if (itemFrame != null) {
itemFrame.setRotation(FurnitureUtil.getRandomRotation());
}
customWorld.addCrop(seedLoc, cropName);
}
}

View File

@@ -24,20 +24,16 @@ import io.th0rgal.oraxen.mechanics.provided.gameplay.stringblock.StringBlockMech
import io.th0rgal.oraxen.mechanics.provided.gameplay.stringblock.StringBlockMechanicFactory;
import io.th0rgal.oraxen.utils.drops.Drop;
import net.momirealms.customcrops.api.crop.Crop;
import net.momirealms.customcrops.api.event.SeedPlantEvent;
import net.momirealms.customcrops.config.*;
import net.momirealms.customcrops.config.BasicItemConfig;
import net.momirealms.customcrops.config.MainConfig;
import net.momirealms.customcrops.config.SoundConfig;
import net.momirealms.customcrops.config.SprinklerConfig;
import net.momirealms.customcrops.integrations.AntiGrief;
import net.momirealms.customcrops.integrations.season.CCSeason;
import net.momirealms.customcrops.managers.CropManager;
import net.momirealms.customcrops.managers.CustomWorld;
import net.momirealms.customcrops.objects.Sprinkler;
import net.momirealms.customcrops.objects.fertilizer.Fertilizer;
import net.momirealms.customcrops.objects.requirements.PlantingCondition;
import net.momirealms.customcrops.objects.requirements.RequirementInterface;
import net.momirealms.customcrops.utils.AdventureUtil;
import net.momirealms.customcrops.utils.FurnitureUtil;
import net.momirealms.customcrops.utils.LimitationUtil;
import org.bukkit.Bukkit;
import org.bukkit.GameMode;
import org.bukkit.Location;
import org.bukkit.Material;
@@ -182,61 +178,19 @@ public class OraxenWireHandler extends OraxenHandler{
if (super.tryMisc(event.getPlayer(), itemInHand, potLoc)) return;
if (event.getBlockFace() != BlockFace.UP) return;
Location seedLoc = potLoc.clone().add(0,1,0);
String id = OraxenItems.getIdByItem(itemInHand);
if (id == null) return;
if (id != null) {
if (id.endsWith("_seeds")) {
String cropName = id.substring(0, id.length() - 6);
Crop crop = CropConfig.CROPS.get(cropName);
if (crop == null) return;
Location seedLoc = potLoc.clone().add(0,1,0);
CustomWorld customWorld = cropManager.getCustomWorld(seedLoc.getWorld());
if (customWorld == null) return;
if (FurnitureUtil.hasFurniture(seedLoc.clone().add(0.5,0.03125,0.5))) return;
if (seedLoc.getBlock().getType() != Material.AIR) return;
PlantingCondition plantingCondition = new PlantingCondition(seedLoc, player);
if (crop.getRequirements() != null) {
for (RequirementInterface requirement : crop.getRequirements()) {
if (!requirement.isConditionMet(plantingCondition)) {
return;
plantSeed(seedLoc, cropName, player, itemInHand, true, true);
}
}
}
if (MainConfig.limitation && LimitationUtil.reachWireLimit(potLoc)) {
AdventureUtil.playerMessage(player, MessageConfig.prefix + MessageConfig.limitWire.replace("{max}", String.valueOf(MainConfig.wireAmount)));
return;
}
CCSeason[] seasons = crop.getSeasons();
if (SeasonConfig.enable && seasons != null) {
if (cropManager.isWrongSeason(seedLoc, seasons)) {
if (MainConfig.notifyInWrongSeason) AdventureUtil.playerMessage(player, MessageConfig.prefix + MessageConfig.wrongSeason);
if (MainConfig.preventInWrongSeason) return;
}
}
SeedPlantEvent seedPlantEvent = new SeedPlantEvent(player, seedLoc, crop);
Bukkit.getPluginManager().callEvent(seedPlantEvent);
if (seedPlantEvent.isCancelled()) {
return;
}
if (SoundConfig.plantSeed.isEnable()) {
AdventureUtil.playerSound(
player,
SoundConfig.plantSeed.getSource(),
SoundConfig.plantSeed.getKey(),
1,1
);
}
if (player.getGameMode() != GameMode.CREATIVE) itemInHand.setAmount(itemInHand.getAmount() - 1);
StringBlockMechanicFactory.setBlockModel(seedLoc.getBlock(), id.substring(0, id.length() - 5) + "stage_1");
customWorld.addCrop(seedLoc, cropName);
else if (MainConfig.enableConvert) {
String cropName = MainConfig.vanilla2Crops.get(itemInHand.getType());
if (cropName == null) return;
plantSeed(seedLoc, cropName, player, itemInHand, true, true);
}
}

View File

@@ -18,8 +18,8 @@
package net.momirealms.customcrops.integrations.papi;
import me.clip.placeholderapi.PlaceholderAPI;
import net.momirealms.customcrops.Function;
import net.momirealms.customcrops.config.SeasonConfig;
import net.momirealms.customcrops.objects.Function;
import org.bukkit.entity.Player;
public class PlaceholderManager extends Function {

View File

@@ -18,9 +18,9 @@
package net.momirealms.customcrops.integrations.season;
import net.momirealms.customcrops.CustomCrops;
import net.momirealms.customcrops.Function;
import net.momirealms.customcrops.config.MainConfig;
import net.momirealms.customcrops.config.SeasonConfig;
import net.momirealms.customcrops.objects.Function;
import net.momirealms.customcrops.utils.AdventureUtil;
import org.bukkit.Bukkit;
import org.bukkit.World;

View File

@@ -18,8 +18,8 @@
package net.momirealms.customcrops.integrations.season;
import me.casperge.realisticseasons.api.SeasonsAPI;
import net.momirealms.customcrops.Function;
import net.momirealms.customcrops.config.MainConfig;
import net.momirealms.customcrops.objects.Function;
import org.bukkit.World;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

View File

@@ -18,9 +18,9 @@
package net.momirealms.customcrops.managers;
import net.momirealms.customcrops.CustomCrops;
import net.momirealms.customcrops.Function;
import net.momirealms.customcrops.api.crop.Crop;
import net.momirealms.customcrops.api.event.CropHarvestEvent;
import net.momirealms.customcrops.api.event.CrowAttackEvent;
import net.momirealms.customcrops.config.BasicItemConfig;
import net.momirealms.customcrops.config.MainConfig;
import net.momirealms.customcrops.config.SeasonConfig;
@@ -36,6 +36,7 @@ import net.momirealms.customcrops.integrations.season.SeasonInterface;
import net.momirealms.customcrops.managers.listener.*;
import net.momirealms.customcrops.managers.timer.CrowTask;
import net.momirealms.customcrops.managers.timer.TimerTask;
import net.momirealms.customcrops.objects.Function;
import net.momirealms.customcrops.objects.OtherLoot;
import net.momirealms.customcrops.objects.QualityLoot;
import net.momirealms.customcrops.objects.QualityRatio;
@@ -46,10 +47,8 @@ import net.momirealms.customcrops.objects.fertilizer.RetainingSoil;
import net.momirealms.customcrops.objects.fertilizer.YieldIncreasing;
import net.momirealms.customcrops.utils.AdventureUtil;
import net.momirealms.customcrops.utils.ArmorStandUtil;
import org.bukkit.Bukkit;
import org.bukkit.GameMode;
import org.bukkit.Location;
import org.bukkit.World;
import net.momirealms.customcrops.utils.MiscUtils;
import org.bukkit.*;
import org.bukkit.entity.Item;
import org.bukkit.entity.ItemFrame;
import org.bukkit.entity.Player;
@@ -73,6 +72,8 @@ public class CropManager extends Function {
private ContainerListener containerListener;
private PlayerModeListener playerModeListener;
private PlayerContainerListener playerContainerListener;
private VanillaCropPlaceListener vanillaCropPlaceListener;
private VanillaCropHarvestListener vanillaCropHarvestListener;
private HandlerP handler;
public CropManager() {
@@ -90,6 +91,7 @@ public class CropManager extends Function {
loadMode();
loadSeason();
loadPacket();
loadVanillaMechanic();
//load Worlds
for (World world : Bukkit.getWorlds()) {
@@ -100,6 +102,23 @@ public class CropManager extends Function {
this.timerTask.runTaskTimerAsynchronously(CustomCrops.plugin, 1,100);
}
public void loadVanillaMechanic() {
if (this.vanillaCropHarvestListener != null) {
HandlerList.unregisterAll(vanillaCropHarvestListener);
}
if (this.vanillaCropPlaceListener != null) {
HandlerList.unregisterAll(vanillaCropPlaceListener);
}
if (MainConfig.preventPlantVanilla) {
this.vanillaCropPlaceListener = new VanillaCropPlaceListener();
Bukkit.getPluginManager().registerEvents(vanillaCropPlaceListener, CustomCrops.plugin);
}
if (MainConfig.rightHarvestVanilla) {
this.vanillaCropHarvestListener = new VanillaCropHarvestListener();
Bukkit.getPluginManager().registerEvents(vanillaCropHarvestListener, CustomCrops.plugin);
}
}
public void loadMode() {
if (this.handler != null) {
@@ -210,7 +229,7 @@ public class CropManager extends Function {
customWorlds.put(world, customWorld);
if (MainConfig.autoGrow && MainConfig.enableCompensation) {
if (world.getTime() > 1200) {
Bukkit.getScheduler().runTaskLaterAsynchronously(CustomCrops.plugin, () -> grow(world, MainConfig.timeToGrow, MainConfig.timeToWork, MainConfig.timeToDry, true), 100);
Bukkit.getScheduler().runTaskLaterAsynchronously(CustomCrops.plugin, () -> grow(world, MainConfig.timeToGrow, 0, 0, true, false), 100);
}
}
}
@@ -224,11 +243,11 @@ public class CropManager extends Function {
seasonInterface.unloadWorld(world);
}
public void grow(World world, int cropTime, int sprinklerTime, int dryTime, boolean compensation) {
public void grow(World world, int cropTime, int sprinklerTime, int dryTime, boolean compensation, boolean force) {
CustomWorld customWorld = customWorlds.get(world);
if (customWorld == null) return;
if (MainConfig.cropMode) customWorld.growWire(cropTime, sprinklerTime, dryTime, compensation);
else customWorld.growFrame(cropTime, sprinklerTime, dryTime, compensation);
if (MainConfig.cropMode) customWorld.growWire(cropTime, sprinklerTime, dryTime, compensation, force);
else customWorld.growFrame(cropTime, sprinklerTime, dryTime, compensation, force);
}
public CropModeInterface getCropMode() {
@@ -358,7 +377,7 @@ public class CropManager extends Function {
for (OtherLoot otherLoot : otherLoots) {
if (Math.random() < otherLoot.getChance()) {
int random = ThreadLocalRandom.current().nextInt(otherLoot.getMin(), otherLoot.getMax() + 1);
ItemStack drop = customInterface.getItemStack(otherLoot.getItemID());
ItemStack drop = getLoot(otherLoot.getItemID());
if (drop == null) continue;
drop.setAmount(random);
location.getWorld().dropItemNaturally(location, drop);
@@ -372,23 +391,28 @@ public class CropManager extends Function {
double random = Math.random();
World world = location.getWorld();
if (random < qualityRatio.getQuality_1()) {
ItemStack drop = customInterface.getItemStack(qualityLoot.getQuality_1());
ItemStack drop = getLoot(qualityLoot.getQuality_1());
if (drop == null) continue;
world.dropItemNaturally(location, drop);
}
else if(random > qualityRatio.getQuality_2()){
ItemStack drop = customInterface.getItemStack(qualityLoot.getQuality_2());
ItemStack drop = getLoot(qualityLoot.getQuality_2());
if (drop == null) continue;
world.dropItemNaturally(location, drop);
}
else {
ItemStack drop = customInterface.getItemStack(qualityLoot.getQuality_3());
ItemStack drop = getLoot(qualityLoot.getQuality_3());
if (drop == null) continue;
world.dropItemNaturally(location, drop);
}
}
}
private ItemStack getLoot(String id) {
if (MiscUtils.isVanillaItem(id)) return new ItemStack(Material.valueOf(id));
else return customInterface.getItemStack(id);
}
public boolean crowJudge(Location location, ItemFrame itemFrame) {
if (Math.random() < MainConfig.crowChance && !hasScarecrow(location)) {
for (Player player : location.getNearbyPlayers(48)) {
@@ -405,15 +429,24 @@ public class CropManager extends Function {
public boolean crowJudge(Location location) {
if (Math.random() < MainConfig.crowChance && !hasScarecrow(location)) {
CrowAttackEvent crowAttackEvent = new CrowAttackEvent(location);
Bukkit.getPluginManager().callEvent(crowAttackEvent);
if (crowAttackEvent.isCancelled()) {
return false;
}
Bukkit.getScheduler().runTask(CustomCrops.plugin, () -> {
for (Player player : location.getNearbyPlayers(48)) {
CrowTask crowTask = new CrowTask(player, location.clone().add(0.4,0,0.4), getArmorStandUtil());
crowTask.runTaskTimerAsynchronously(CustomCrops.plugin, 1, 1);
}
});
Bukkit.getScheduler().runTaskLater(CustomCrops.plugin, () -> {
customInterface.removeBlock(location);
}, 125);
return true;
}
return false;

View File

@@ -22,7 +22,6 @@ import net.momirealms.customcrops.CustomCrops;
import net.momirealms.customcrops.api.event.CustomWorldEvent;
import net.momirealms.customcrops.api.utils.SeasonUtils;
import net.momirealms.customcrops.config.*;
import net.momirealms.customcrops.helper.Log;
import net.momirealms.customcrops.integrations.season.CCSeason;
import net.momirealms.customcrops.objects.SimpleLocation;
import net.momirealms.customcrops.objects.Sprinkler;
@@ -39,7 +38,6 @@ import org.bukkit.World;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitScheduler;
import org.bukkit.scheduler.BukkitTask;
import org.jetbrains.annotations.Nullable;
import java.io.*;
@@ -125,7 +123,7 @@ public class CustomWorld {
Date date = new Date();
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss");
try {
File file = new File(CustomCrops.plugin.getDataFolder().getParentFile().getParentFile(), worldName + File.separator + "customcrops_data");
File file = new File(CustomCrops.plugin.getDataFolder().getParentFile().getParentFile(), MainConfig.worldFolder + worldName + File.separator + "customcrops_data");
File[] files = file.listFiles();
if (files == null) return;
for (File data : files) {
@@ -142,7 +140,7 @@ public class CustomWorld {
if (!MainConfig.enableCrow) return;
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 + "scarecrow.json")));
JsonElement json= jsonParser.parse(new FileReader(new File(CustomCrops.plugin.getDataFolder().getParentFile().getParentFile(), MainConfig.worldFolder + world.getName() + File.separator + "customcrops_data" + File.separator + "scarecrow.json")));
if (json.isJsonObject()) {
JsonObject jsonObject = json.getAsJsonObject();
for (Map.Entry<String, JsonElement> en : jsonObject.entrySet()) {
@@ -173,7 +171,7 @@ public class CustomWorld {
}
jsonObject.add(entry.getKey(), jsonArray);
}
try (FileWriter fileWriter = new FileWriter(new File(CustomCrops.plugin.getDataFolder().getParentFile().getParentFile(), world.getName() + File.separator + "customcrops_data" + File.separator + "scarecrow.json"))){
try (FileWriter fileWriter = new FileWriter(new File(CustomCrops.plugin.getDataFolder().getParentFile().getParentFile(), MainConfig.worldFolder + world.getName() + File.separator + "customcrops_data" + File.separator + "scarecrow.json"))){
fileWriter.write(jsonObject.toString().replace("\\\\", "\\"));
} catch (IOException e) {
e.printStackTrace();
@@ -184,7 +182,7 @@ public class CustomWorld {
if (!SeasonConfig.enable) return;
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 + "season.json")));
JsonElement json= jsonParser.parse(new FileReader(new File(CustomCrops.plugin.getDataFolder().getParentFile().getParentFile(), MainConfig.worldFolder + world.getName() + File.separator + "customcrops_data" + File.separator + "season.json")));
if (json.isJsonObject()) {
JsonObject jsonObject = json.getAsJsonObject();
if (jsonObject.has("season")) {
@@ -208,7 +206,7 @@ public class CustomWorld {
JsonObject jsonObject = new JsonObject();
JsonPrimitive jsonPrimitive = new JsonPrimitive(SeasonUtils.getSeason(world).name());
jsonObject.add("season", jsonPrimitive);
try (FileWriter fileWriter = new FileWriter(new File(CustomCrops.plugin.getDataFolder().getParentFile().getParentFile(), world.getName() + File.separator + "customcrops_data" + File.separator + "season.json"))){
try (FileWriter fileWriter = new FileWriter(new File(CustomCrops.plugin.getDataFolder().getParentFile().getParentFile(), MainConfig.worldFolder + world.getName() + File.separator + "customcrops_data" + File.separator + "season.json"))){
fileWriter.write(jsonObject.toString().replace("\\\\", "\\"));
} catch (IOException e) {
e.printStackTrace();
@@ -219,7 +217,7 @@ public class CustomWorld {
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")));
JsonElement json= jsonParser.parse(new FileReader(new File(CustomCrops.plugin.getDataFolder().getParentFile().getParentFile(), MainConfig.worldFolder + world.getName() + File.separator + "customcrops_data" + File.separator + "pot.json")));
if (json.isJsonObject()) {
JsonObject jsonObject = json.getAsJsonObject();
if (jsonObject.has("pot")) {
@@ -247,7 +245,7 @@ public class CustomWorld {
}
watered.clear();
jsonObject.add("pot", jsonArray);
try (FileWriter fileWriter = new FileWriter(new File(CustomCrops.plugin.getDataFolder().getParentFile().getParentFile(), world.getName() + File.separator + "customcrops_data" + File.separator + "pot.json"))){
try (FileWriter fileWriter = new FileWriter(new File(CustomCrops.plugin.getDataFolder().getParentFile().getParentFile(), MainConfig.worldFolder + world.getName() + File.separator + "customcrops_data" + File.separator + "pot.json"))){
fileWriter.write(jsonObject.toString().replace("\\\\", "\\"));
} catch (IOException e) {
e.printStackTrace();
@@ -277,7 +275,7 @@ public class CustomWorld {
data.set(loc + ".type", en.getValue().getKey());
}
try {
data.save(new File(CustomCrops.plugin.getDataFolder().getParentFile().getParentFile(), world.getName() + File.separator + "customcrops_data" + File.separator + "fertilizers.yml"));
data.save(new File(CustomCrops.plugin.getDataFolder().getParentFile().getParentFile(), MainConfig.worldFolder + world.getName() + File.separator + "customcrops_data" + File.separator + "fertilizers.yml"));
}
catch (IOException e) {
e.printStackTrace();
@@ -310,7 +308,7 @@ public class CustomWorld {
data.set(loc + ".type", en.getValue().getKey());
}
try {
data.save(new File(CustomCrops.plugin.getDataFolder().getParentFile().getParentFile(), world.getName() + File.separator + "customcrops_data" + File.separator + "sprinklers.yml"));
data.save(new File(CustomCrops.plugin.getDataFolder().getParentFile().getParentFile(), MainConfig.worldFolder + world.getName() + File.separator + "customcrops_data" + File.separator + "sprinklers.yml"));
}
catch (IOException e) {
e.printStackTrace();
@@ -324,7 +322,7 @@ public class CustomWorld {
public void unloadCrop() {
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(), MainConfig.worldFolder + world.getName() + File.separator + "customcrops_data" + File.separator + "crops.yml"));
}
catch (IOException e) {
e.printStackTrace();
@@ -332,11 +330,16 @@ public class CustomWorld {
}
}
public void growWire(int cropTime, int sprinklerTime, int dryTime, boolean compensation) {
public void growWire(int cropTime, int sprinklerTime, int dryTime, boolean compensation, boolean force) {
Random randomGenerator = new Random();
if (!compensation) {
if (force) {
cropData.getKeys(false).forEach(key -> {
Location location = MiscUtils.getLocation(key, world);
growSingleWire(location, randomGenerator.nextInt(cropTime), key);
});
}
else if (!compensation) {
route(sprinklerTime);
potDryJudge(sprinklerTime + randomGenerator.nextInt(dryTime));
cropData.getKeys(false).forEach(key -> {
@@ -364,11 +367,16 @@ public class CustomWorld {
}, delay);
}
public void growFrame(int cropTime, int sprinklerTime, int dryTime, boolean compensation) {
public void growFrame(int cropTime, int sprinklerTime, int dryTime, boolean compensation, boolean force) {
Random randomGenerator = new Random();
if (!compensation) {
if (force) {
cropData.getKeys(false).forEach(key -> {
Location location = MiscUtils.getLocation(key, world);
growSingleFrame(location, randomGenerator.nextInt(cropTime), key);
});
}
else if (!compensation) {
route(sprinklerTime);
potDryJudge(sprinklerTime + randomGenerator.nextInt(dryTime));
cropData.getKeys(false).forEach(key -> {
@@ -428,7 +436,7 @@ public class CustomWorld {
}
public YamlConfiguration loadData(String data, String worldName) {
return ConfigUtil.readData(new File(CustomCrops.plugin.getDataFolder().getParentFile().getParentFile(), worldName + File.separator + "customcrops_data" + File.separator + data +".yml"));
return ConfigUtil.readData(new File(CustomCrops.plugin.getDataFolder().getParentFile().getParentFile(), MainConfig.worldFolder + worldName + File.separator + "customcrops_data" + File.separator + data +".yml"));
}
/**

View File

@@ -33,6 +33,7 @@ public class ItemSpawnListener implements Listener {
@EventHandler
public void onItemSpawn(EntitySpawnEvent event) {
if (event.isCancelled()) return;
if (event.getEntity() instanceof Item item) {
cropManager.onItemSpawn(item);
}

View File

@@ -10,6 +10,7 @@ public class PlayerModeListener implements Listener {
@EventHandler
public void onModeChange(PlayerGameModeChangeEvent event) {
if (event.isCancelled()) return;
Bukkit.getScheduler().runTaskLater(CustomCrops.plugin, () -> {
event.getPlayer().updateInventory();
}, 1);

View File

@@ -0,0 +1,40 @@
package net.momirealms.customcrops.managers.listener;
import net.momirealms.customcrops.config.MainConfig;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.data.Ageable;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.Action;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.inventory.PlayerInventory;
public class VanillaCropHarvestListener implements Listener {
@EventHandler
public void onInteractRipeCrop(PlayerInteractEvent event) {
if (event.getAction() != Action.RIGHT_CLICK_BLOCK) return;
Block block = event.getClickedBlock();
if (block == null) return;
Material material = block.getType();
if (material == Material.COCOA) return;
if (block.getBlockData() instanceof Ageable ageable) {
if (ageable.getMaximumAge() == ageable.getAge()) {
final Player player = event.getPlayer();
if (MainConfig.emptyHand) {
final PlayerInventory inventory = player.getInventory();
if (!(inventory.getItemInMainHand().getType() != Material.AIR || inventory.getItemInOffHand().getType() != Material.AIR)) {
if (player.breakBlock(block)) {
block.setType(material);
}
}
}
else if (player.breakBlock(block)) {
block.setType(material);
}
}
}
}
}

View File

@@ -0,0 +1,22 @@
package net.momirealms.customcrops.managers.listener;
import net.momirealms.customcrops.config.MainConfig;
import org.bukkit.Material;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockPlaceEvent;
public class VanillaCropPlaceListener implements Listener {
@EventHandler
public void onPlant(BlockPlaceEvent event) {
if (event.isCancelled()) return;
Material type = event.getBlockPlaced().getType();
for (Material vanillaCrop : MainConfig.preventPlantVanillaArray) {
if (type == vanillaCrop) {
event.setCancelled(true);
return;
}
}
}
}

View File

@@ -23,13 +23,7 @@ import org.bukkit.event.Listener;
import org.bukkit.event.world.WorldLoadEvent;
import org.bukkit.event.world.WorldUnloadEvent;
public class WorldListener implements Listener {
private final CropManager cropManager;
public WorldListener(CropManager cropManager) {
this.cropManager = cropManager;
}
public record WorldListener(CropManager cropManager) implements Listener {
@EventHandler
public void onWorldUnload(WorldLoadEvent event) {

View File

@@ -36,7 +36,7 @@ public class TimerTask extends BukkitRunnable {
for (World world : MainConfig.getWorldsList()) {
long time = world.getTime();
if (time > 950 && time < 1051) {
cropManager.grow(world, MainConfig.timeToGrow, MainConfig.timeToWork, MainConfig.timeToDry, false);
cropManager.grow(world, MainConfig.timeToGrow, MainConfig.timeToWork, MainConfig.timeToDry, false, false);
}
}
}

View File

@@ -15,7 +15,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package net.momirealms.customcrops;
package net.momirealms.customcrops.objects;
public class Function {

View File

@@ -50,4 +50,14 @@ public class MiscUtils {
public static String getStringLocation(Location location) {
return location.getBlockX() + "," + location.getBlockY() + "," + location.getBlockZ();
}
public static boolean isVanillaItem(String item) {
char[] chars = item.toCharArray();
for (char character : chars) {
if ((character < 65 || character > 90) && character != 95) {
return false;
}
}
return true;
}
}

View File

@@ -1,5 +1,5 @@
#Don't change
config-version: '12'
config-version: '13'
# lang: english / spanish / chinese
lang: english
@@ -26,7 +26,10 @@ integration:
RealisticSeasons: false
worlds:
# This is designed for servers that using a separate folder for worlds
worlds-folder: ''
# Mode: whitelist/blacklist
# Requires a restart when changing this
mode: whitelist
list:
- world
@@ -125,6 +128,28 @@ mechanics:
enable: true
level: 10
vanilla-crops:
# Can vanilla crops be harvest with right clicks
right-click-harvest: false
# Totally prevent player from planting these vanilla crops in farmland
prevent-plant:
enable: false
list:
- WHEAT
- CARROTS
- POTATOES
- BEETROOTS
# Convert vanilla items into CustomCrops crops
# You need to make extra CustomCrops/IA/Oraxen configs/models for these crops
# This makes it possible to make vanilla crops have a better mechanic
convert-to-customcrops:
enable: false
list:
WHEAT_SEEDS: wheat
CARROT: carrot
POTATO: potato
BEETROOT_SEEDS: beetroot
sounds:
water-pot:

View File

@@ -27,9 +27,9 @@ tomato:
chance: 0.01
harvest-actions:
# https://docs.adventure.kyori.net/minimessage/format.html
messages:
- 'Hello, {player}! <u><click:open_url:xxx.xxx>Click here to read the CustomCrops wiki'
- '<u>This plugin uses MiniMessage Format, check it here</u><click:open_url:https://docs.adventure.kyori.net/minimessage/format.html> <gold>[Click Me]'
- 'Hello, {player}! <u><click:open_url:https://www.yuque.com/docs/share/3e23f953-ccf0-4de5-bfe6-23868380c599>Click here to read the CustomCrops wiki'
commands:
- 'say {player} harvested a tomato! lol'
xp: 10