mirror of
https://github.com/Xiao-MoMi/Custom-Crops.git
synced 2025-12-25 09:59:20 +00:00
2.1.2
This commit is contained in:
@@ -25,6 +25,7 @@ import net.momirealms.customcrops.config.ConfigUtil;
|
||||
import net.momirealms.customcrops.config.MainConfig;
|
||||
import net.momirealms.customcrops.helper.LibraryLoader;
|
||||
import net.momirealms.customcrops.integrations.papi.PlaceholderManager;
|
||||
import net.momirealms.customcrops.integrations.protection.WorldGuardHook;
|
||||
import net.momirealms.customcrops.managers.CropManager;
|
||||
import net.momirealms.customcrops.utils.AdventureUtil;
|
||||
import org.bstats.bukkit.Metrics;
|
||||
@@ -67,6 +68,9 @@ public final class CustomCrops extends JavaPlugin {
|
||||
plugin = this;
|
||||
LibraryLoader.load("dev.dejvokep","boosted-yaml","1.3","https://repo.maven.apache.org/maven2/");
|
||||
LibraryLoader.load("commons-io","commons-io","2.11.0","https://repo.maven.apache.org/maven2/");
|
||||
if (Bukkit.getPluginManager().getPlugin("WorldGuard") != null) {
|
||||
WorldGuardHook.initialize();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -124,6 +124,8 @@ public class MainConfig {
|
||||
public static HashMap<Material, String> vanilla2Crops;
|
||||
public static boolean enableEvents;
|
||||
public static int saveInterval;
|
||||
public static boolean dryMakesCropDead;
|
||||
public static double dryDeadChance;
|
||||
|
||||
public static void load() {
|
||||
ConfigUtil.update("config.yml");
|
||||
@@ -166,6 +168,9 @@ public class MainConfig {
|
||||
dryGrowChance = config.getDouble("mechanics.dry-pot-grow-chance", 0.5);
|
||||
dropLootsInAllWorlds = config.getBoolean("mechanics.drop-loots-in-all-worlds", false);
|
||||
|
||||
dryMakesCropDead = config.getBoolean("mechanics.dry-pot-makes-crop-dead.enable", false);
|
||||
dryDeadChance = config.getDouble("mechanics.dry-pot-makes-crop-dead.chance", 0.6);
|
||||
|
||||
waterBucketToSprinkler = config.getInt("mechanics.fill.water-bucket-to-sprinkler", 3);
|
||||
waterToWaterCan = config.getInt("mechanics.fill.waterblock-to-watering-can", 1);
|
||||
wateringCanToSprinkler = config.getInt("mechanics.fill.watering-can-to-sprinkler", 1);
|
||||
|
||||
@@ -17,7 +17,6 @@
|
||||
|
||||
package net.momirealms.customcrops.integrations.customplugin.oraxen;
|
||||
|
||||
import io.th0rgal.oraxen.OraxenPlugin;
|
||||
import io.th0rgal.oraxen.api.OraxenItems;
|
||||
import io.th0rgal.oraxen.api.events.*;
|
||||
import io.th0rgal.oraxen.mechanics.provided.gameplay.furniture.FurnitureFactory;
|
||||
@@ -34,17 +33,14 @@ import net.momirealms.customcrops.integrations.AntiGrief;
|
||||
import net.momirealms.customcrops.managers.CropManager;
|
||||
import net.momirealms.customcrops.objects.Sprinkler;
|
||||
import net.momirealms.customcrops.utils.AdventureUtil;
|
||||
import net.momirealms.customcrops.utils.FurnitureUtil;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.entity.ItemFrame;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.persistence.PersistentDataType;
|
||||
|
||||
public class OraxenWireHandler extends OraxenHandler{
|
||||
|
||||
|
||||
@@ -24,7 +24,8 @@ import com.sk89q.worldguard.LocalPlayer;
|
||||
import com.sk89q.worldguard.WorldGuard;
|
||||
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
|
||||
import com.sk89q.worldguard.internal.platform.WorldGuardPlatform;
|
||||
import com.sk89q.worldguard.protection.flags.Flags;
|
||||
import com.sk89q.worldguard.protection.flags.StateFlag;
|
||||
import com.sk89q.worldguard.protection.flags.registry.FlagRegistry;
|
||||
import com.sk89q.worldguard.protection.managers.RegionManager;
|
||||
import com.sk89q.worldguard.protection.regions.RegionContainer;
|
||||
import com.sk89q.worldguard.protection.regions.RegionQuery;
|
||||
@@ -34,6 +35,21 @@ import org.bukkit.entity.Player;
|
||||
|
||||
public class WorldGuardHook implements AntiGrief {
|
||||
|
||||
public static StateFlag HARVEST_FLAG;
|
||||
public static StateFlag PLACE_FLAG;
|
||||
|
||||
public static void initialize() {
|
||||
FlagRegistry registry = WorldGuard.getInstance().getFlagRegistry();
|
||||
if (HARVEST_FLAG == null) {
|
||||
HARVEST_FLAG = new StateFlag("customcrops-harvest", false);
|
||||
registry.register(HARVEST_FLAG);
|
||||
}
|
||||
if (PLACE_FLAG == null) {
|
||||
PLACE_FLAG = new StateFlag("customcrops-place", false);
|
||||
registry.register(PLACE_FLAG);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canPlace(Location location, Player player) {
|
||||
LocalPlayer localPlayer = WorldGuardPlugin.inst().wrapPlayer(player);
|
||||
@@ -41,7 +57,7 @@ public class WorldGuardHook implements AntiGrief {
|
||||
WorldGuardPlatform platform = WorldGuard.getInstance().getPlatform();
|
||||
if (hasRegion(world, BukkitAdapter.asBlockVector(location))){
|
||||
RegionQuery query = platform.getRegionContainer().createQuery();
|
||||
return query.testBuild(BukkitAdapter.adapt(location), localPlayer, Flags.BUILD);
|
||||
return query.testBuild(BukkitAdapter.adapt(location), localPlayer, PLACE_FLAG);
|
||||
}
|
||||
else return true;
|
||||
}
|
||||
@@ -53,7 +69,7 @@ public class WorldGuardHook implements AntiGrief {
|
||||
WorldGuardPlatform platform = WorldGuard.getInstance().getPlatform();
|
||||
if (hasRegion(world, BukkitAdapter.asBlockVector(location))){
|
||||
RegionQuery query = platform.getRegionContainer().createQuery();
|
||||
return query.testBuild(BukkitAdapter.adapt(location), localPlayer, Flags.BLOCK_BREAK);
|
||||
return query.testBuild(BukkitAdapter.adapt(location), localPlayer, HARVEST_FLAG);
|
||||
}
|
||||
else return true;
|
||||
}
|
||||
|
||||
@@ -485,6 +485,13 @@ public class CropManager extends Function {
|
||||
if (potID == null) return true;
|
||||
|
||||
boolean certainGrow = potID.equals(BasicItemConfig.wetPot);
|
||||
if (MainConfig.dryMakesCropDead && !certainGrow && Math.random() < MainConfig.dryDeadChance) {
|
||||
Bukkit.getScheduler().runTask(CustomCrops.plugin, () -> {
|
||||
customInterface.removeBlock(location);
|
||||
customInterface.placeWire(location, BasicItemConfig.deadCrop);
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
||||
String temp = CropConfig.namespace + growingCrop.getType() + "_stage_";
|
||||
|
||||
@@ -543,6 +550,10 @@ public class CropManager extends Function {
|
||||
if (potID == null) return true;
|
||||
|
||||
boolean certainGrow = potID.equals(BasicItemConfig.wetPot);
|
||||
if (MainConfig.dryMakesCropDead && !certainGrow && Math.random() < MainConfig.dryDeadChance) {
|
||||
itemFrame.setItem(customInterface.getItemStack(BasicItemConfig.deadCrop), false);
|
||||
return true;
|
||||
}
|
||||
|
||||
String temp = CropConfig.namespace + growingCrop.getType() + "_stage_";
|
||||
if (fertilizer instanceof SpeedGrow speedGrow && Math.random() < speedGrow.getChance() && current_stage+2 <= crop.getMax_stage()) {
|
||||
|
||||
Reference in New Issue
Block a user