mirror of
https://github.com/Xiao-MoMi/Custom-Crops.git
synced 2025-12-24 01:19:28 +00:00
3.0.0-beta1
This commit is contained in:
49
build.gradle
49
build.gradle
@@ -4,48 +4,44 @@ plugins {
|
|||||||
}
|
}
|
||||||
|
|
||||||
group = 'net.momirealms'
|
group = 'net.momirealms'
|
||||||
version = '2.2.9.1'
|
version = '3.0.0-beta1'
|
||||||
|
|
||||||
repositories {
|
repositories {
|
||||||
mavenCentral()
|
mavenCentral()
|
||||||
maven {name = 'papermc-repo'; url = 'https://papermc.io/repo/repository/maven-public/'}
|
maven {name = "aliyun repo"; url = "https://maven.aliyun.com/repository/public/"}
|
||||||
|
maven {name = 'papermc repo'; url = 'https://papermc.io/repo/repository/maven-public/'}
|
||||||
maven {name = 'sonatype'; url = 'https://oss.sonatype.org/content/groups/public/'}
|
maven {name = 'sonatype'; url = 'https://oss.sonatype.org/content/groups/public/'}
|
||||||
maven {name = "sonatype-oss-snapshots1"; url = "https://s01.oss.sonatype.org/content/repositories/snapshots/"}
|
maven {name = "dmulloy2 repo"; url = "https://repo.dmulloy2.net/repository/public/"}
|
||||||
maven {name = "dmulloy2-repo"; url = "https://repo.dmulloy2.net/repository/public/"}
|
maven {name = "clip repo"; url = 'https://repo.extendedclip.com/content/repositories/placeholderapi/'}
|
||||||
maven {name = "clip-repo"; url = 'https://repo.extendedclip.com/content/repositories/placeholderapi/'}
|
maven {name = "codemc repo"; url = "https://repo.codemc.org/repository/maven-public/"}
|
||||||
maven {name = "NBT-API"; url = "https://repo.codemc.org/repository/maven-public/"}
|
maven {name = "enginehub repo"; url = "https://maven.enginehub.org/repo/"}
|
||||||
maven {name = "sk89q-repo"; url = "https://maven.enginehub.org/repo/"}
|
maven {name = "Lumine repo"; url = "https://mvn.lumine.io/repository/maven-public"}
|
||||||
maven {name = "Lumine Releases"; url = "https://mvn.lumine.io/repository/maven-public"}
|
maven {name = "jitpack repo"; url = "https://jitpack.io"}
|
||||||
maven {name = "jitpack-repo"; url = "https://jitpack.io"}
|
|
||||||
maven {name = 'glaremasters repo'; url = 'https://repo.glaremasters.me/repository/towny/'}
|
maven {name = 'glaremasters repo'; url = 'https://repo.glaremasters.me/repository/towny/'}
|
||||||
maven {name = 'superior skyblock repo'; url = 'https://repo.bg-software.com/repository/api/'}
|
maven {name = 'bg-software repo'; url = 'https://repo.bg-software.com/repository/api/'}
|
||||||
maven {name = 'bg-repo'; url = 'https://repo.bg-software.com/repository/api/'}
|
|
||||||
maven {name = "Lumine Releases"; url = "https://mvn.lumine.io/repository/maven-public"}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
compileOnly ('dev.dejvokep:boosted-yaml:1.3')
|
compileOnly ('dev.dejvokep:boosted-yaml:1.3')
|
||||||
compileOnly ('com.github.Archy-X:AureliumSkills:Beta1.3.6')
|
compileOnly ('com.github.Archy-X:AureliumSkills:Beta1.3.18')
|
||||||
compileOnly ('commons-io:commons-io:2.11.0')
|
compileOnly ('commons-io:commons-io:2.11.0')
|
||||||
compileOnly ('com.github.angeschossen:LandsAPI:6.26.18')
|
compileOnly ('com.github.angeschossen:LandsAPI:6.26.18')
|
||||||
compileOnly ('com.github.TechFortress:GriefPrevention:16.18')
|
compileOnly ('com.github.TechFortress:GriefPrevention:16.18')
|
||||||
compileOnly ('io.papermc.paper:paper-api:1.17.1-R0.1-SNAPSHOT')
|
compileOnly ('io.papermc.paper:paper-api:1.19.4-R0.1-SNAPSHOT')
|
||||||
compileOnly ('me.clip:placeholderapi:2.11.2')
|
compileOnly ('me.clip:placeholderapi:2.11.3')
|
||||||
compileOnly ('com.sk89q.worldguard:worldguard-bukkit:7.0.7')
|
compileOnly ('com.github.LoneDev6:api-itemsadder:3.4.1-r4')
|
||||||
compileOnly ('com.github.LoneDev6:api-itemsadder:3.2.3-r8')
|
|
||||||
compileOnly ('io.lumine:Mythic-Dist:5.0.3-SNAPSHOT')
|
compileOnly ('io.lumine:Mythic-Dist:5.0.3-SNAPSHOT')
|
||||||
compileOnly ('com.palmergames.bukkit.towny:towny:0.98.2.0')
|
compileOnly ('com.willfp:EcoSkills:2.2.6')
|
||||||
compileOnly ('com.willfp:EcoSkills:1.72.0')
|
compileOnly ('com.willfp:eco:6.53.1')
|
||||||
compileOnly ('com.willfp:eco:6.38.3')
|
compileOnly ('com.willfp:EcoJobs:3.2.5')
|
||||||
compileOnly ('com.bgsoftware:SuperiorSkyblockAPI:2022.9')
|
compileOnly('net.objecthunter:exp4j:0.4.8')
|
||||||
compileOnly ('com.github.Zrips:Jobs:4.17.2')
|
|
||||||
compileOnly ('com.willfp:EcoJobs:1.35.0')
|
|
||||||
compileOnly fileTree(dir:'libs',includes:['*.jar'])
|
compileOnly fileTree(dir:'libs',includes:['*.jar'])
|
||||||
implementation ('net.kyori:adventure-api:4.13.0')
|
implementation ('net.kyori:adventure-api:4.13.1')
|
||||||
implementation ('net.kyori:adventure-platform-bukkit:4.3.0')
|
implementation ('net.kyori:adventure-platform-bukkit:4.3.0')
|
||||||
implementation ('net.kyori:adventure-text-minimessage:4.13.0')
|
implementation ('net.kyori:adventure-text-minimessage:4.13.1')
|
||||||
implementation ("de.tr7zw:item-nbt-api:2.11.2")
|
implementation ("de.tr7zw:item-nbt-api:2.11.2")
|
||||||
implementation ('org.bstats:bstats-bukkit:3.0.1')
|
implementation ('org.bstats:bstats-bukkit:3.0.1')
|
||||||
|
implementation ('org.apache.commons:commons-pool2:2.11.1')
|
||||||
implementation fileTree(dir:'libs',includes:['BiomeAPI.jar'])
|
implementation fileTree(dir:'libs',includes:['BiomeAPI.jar'])
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -82,7 +78,8 @@ shadowJar {
|
|||||||
relocate ('de.tr7zw', 'net.momirealms.customcrops.libs.de.tr7zw')
|
relocate ('de.tr7zw', 'net.momirealms.customcrops.libs.de.tr7zw')
|
||||||
relocate ('net.kyori', 'net.momirealms.customcrops.libs.net.kyori')
|
relocate ('net.kyori', 'net.momirealms.customcrops.libs.net.kyori')
|
||||||
relocate ('org.bstats', 'net.momirealms.customcrops.libs.org.bstats')
|
relocate ('org.bstats', 'net.momirealms.customcrops.libs.org.bstats')
|
||||||
relocate 'net.momirealms.biomeapi', 'net.momirealms.customcrops.libs.net.momirealms.biomeapi'
|
relocate ('org.apache.commons.pool2', 'net.momirealms.customcrops.libs.org.apache.commons.pool2')
|
||||||
|
relocate ('net.momirealms.biomeapi', 'net.momirealms.customcrops.libs.net.momirealms.biomeapi')
|
||||||
}
|
}
|
||||||
|
|
||||||
tasks.register("delete", Delete).get().delete("build/libs/"+project.name+"-"+project.version+".jar")
|
tasks.register("delete", Delete).get().delete("build/libs/"+project.name+"-"+project.version+".jar")
|
||||||
|
|||||||
@@ -19,131 +19,185 @@ package net.momirealms.customcrops;
|
|||||||
|
|
||||||
import com.comphenix.protocol.ProtocolLibrary;
|
import com.comphenix.protocol.ProtocolLibrary;
|
||||||
import com.comphenix.protocol.ProtocolManager;
|
import com.comphenix.protocol.ProtocolManager;
|
||||||
import de.tr7zw.changeme.nbtapi.utils.VersionChecker;
|
|
||||||
import net.kyori.adventure.platform.bukkit.BukkitAudiences;
|
import net.kyori.adventure.platform.bukkit.BukkitAudiences;
|
||||||
import net.momirealms.customcrops.commands.PluginCommand;
|
import net.momirealms.customcrops.api.CustomCropsAPI;
|
||||||
import net.momirealms.customcrops.config.ConfigUtil;
|
import net.momirealms.customcrops.api.customplugin.Platform;
|
||||||
import net.momirealms.customcrops.config.MainConfig;
|
import net.momirealms.customcrops.api.customplugin.PlatformInterface;
|
||||||
|
import net.momirealms.customcrops.api.customplugin.PlatformManager;
|
||||||
|
import net.momirealms.customcrops.api.customplugin.itemsadder.ItemsAdderPluginImpl;
|
||||||
|
import net.momirealms.customcrops.api.customplugin.oraxen.OraxenPluginImpl;
|
||||||
|
import net.momirealms.customcrops.api.object.basic.ConfigManager;
|
||||||
|
import net.momirealms.customcrops.api.object.basic.MessageManager;
|
||||||
|
import net.momirealms.customcrops.api.object.crop.CropManager;
|
||||||
|
import net.momirealms.customcrops.api.object.pot.PotManager;
|
||||||
|
import net.momirealms.customcrops.api.object.fertilizer.FertilizerManager;
|
||||||
|
import net.momirealms.customcrops.api.object.season.SeasonManager;
|
||||||
|
import net.momirealms.customcrops.api.object.sprinkler.SprinklerManager;
|
||||||
|
import net.momirealms.customcrops.api.object.wateringcan.WateringCanManager;
|
||||||
|
import net.momirealms.customcrops.api.object.world.CCWorld;
|
||||||
|
import net.momirealms.customcrops.api.object.world.WorldDataManager;
|
||||||
|
import net.momirealms.customcrops.api.util.AdventureUtils;
|
||||||
|
import net.momirealms.customcrops.command.CustomCropsCommand;
|
||||||
import net.momirealms.customcrops.helper.LibraryLoader;
|
import net.momirealms.customcrops.helper.LibraryLoader;
|
||||||
import net.momirealms.customcrops.helper.VersionHelper;
|
import net.momirealms.customcrops.helper.VersionHelper;
|
||||||
import net.momirealms.customcrops.integrations.papi.PlaceholderManager;
|
import net.momirealms.customcrops.integration.IntegrationManager;
|
||||||
import net.momirealms.customcrops.integrations.protection.WorldGuardHook;
|
|
||||||
import net.momirealms.customcrops.managers.CropManager;
|
|
||||||
import net.momirealms.customcrops.integrations.quest.BattlePassCCQuest;
|
|
||||||
import net.momirealms.customcrops.integrations.quest.ClueScrollCCQuest;
|
|
||||||
import net.momirealms.customcrops.integrations.quest.NewBetonQuestCCQuest;
|
|
||||||
import net.momirealms.customcrops.integrations.quest.OldBetonQuestCCQuest;
|
|
||||||
import net.momirealms.customcrops.utils.AdventureUtil;
|
|
||||||
import org.bstats.bukkit.Metrics;
|
import org.bstats.bukkit.Metrics;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.World;
|
||||||
|
import org.bukkit.command.PluginCommand;
|
||||||
import org.bukkit.plugin.PluginManager;
|
import org.bukkit.plugin.PluginManager;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
import java.util.Objects;
|
|
||||||
import java.util.TimeZone;
|
import java.util.TimeZone;
|
||||||
|
|
||||||
public final class CustomCrops extends JavaPlugin {
|
public final class CustomCrops extends JavaPlugin {
|
||||||
|
|
||||||
public static BukkitAudiences adventure;
|
private static BukkitAudiences adventure;
|
||||||
public static CustomCrops plugin;
|
private static CustomCrops plugin;
|
||||||
public static ProtocolManager protocolManager;
|
private static ProtocolManager protocolManager;
|
||||||
|
private Platform platform;
|
||||||
private PlaceholderManager placeholderManager;
|
private PlatformInterface platformInterface;
|
||||||
private CropManager cropManager;
|
private CropManager cropManager;
|
||||||
|
private IntegrationManager integrationManager;
|
||||||
|
private WorldDataManager worldDataManager;
|
||||||
|
private SprinklerManager sprinklerManager;
|
||||||
|
private WateringCanManager wateringCanManager;
|
||||||
|
private FertilizerManager fertilizerManager;
|
||||||
|
private SeasonManager seasonManager;
|
||||||
|
private PotManager potManager;
|
||||||
|
private ConfigManager configManager;
|
||||||
|
private MessageManager messageManager;
|
||||||
|
private PlatformManager platformManager;
|
||||||
private VersionHelper versionHelper;
|
private VersionHelper versionHelper;
|
||||||
|
private CustomCropsAPI customCropsAPI;
|
||||||
// _ooOoo_
|
|
||||||
// o8888888o
|
|
||||||
// 88" . "88
|
|
||||||
// (| -_- |)
|
|
||||||
// O\ = /O
|
|
||||||
// ____/`---'\____
|
|
||||||
// .' \\| |// `.
|
|
||||||
// / \\||| : |||// \
|
|
||||||
// / _||||| -:- |||||_ \
|
|
||||||
// | | \\\ - /'| | |
|
|
||||||
// | \_| `\`---'// |_/ |
|
|
||||||
// \ .-\__ `-. -'__/-. /
|
|
||||||
// ___`. .' /--.--\ `. .'___
|
|
||||||
// ."" '< `.___\_<|>_/___.' _> \"".
|
|
||||||
// | | : `- \`. ;`. _/; .'/ / .' ; |
|
|
||||||
// \ \ `-. \_\_`. _.'_/_/ -' _.' /
|
|
||||||
// ================-.`___`-.__\ \___ /__.-'_.'_.-'================
|
|
||||||
// `=--=-'
|
|
||||||
// 佛祖保佑 永无BUG 永不卡服
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onLoad(){
|
public void onLoad(){
|
||||||
plugin = this;
|
plugin = this;
|
||||||
TimeZone timeZone = TimeZone.getDefault();
|
this.loadLibs();
|
||||||
String libRepo = timeZone.getID().startsWith("Asia") ? "https://maven.aliyun.com/repository/public/" : "https://repo.maven.apache.org/maven2/";
|
|
||||||
LibraryLoader.load("dev.dejvokep","boosted-yaml","1.3",libRepo);
|
|
||||||
LibraryLoader.load("commons-io","commons-io","2.11.0",libRepo);
|
|
||||||
if (Bukkit.getPluginManager().getPlugin("WorldGuard") != null) {
|
|
||||||
WorldGuardHook.initialize();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onEnable() {
|
public void onEnable() {
|
||||||
adventure = BukkitAudiences.create(plugin);
|
adventure = BukkitAudiences.create(this);
|
||||||
protocolManager = ProtocolLibrary.getProtocolManager();
|
protocolManager = ProtocolLibrary.getProtocolManager();
|
||||||
|
AdventureUtils.consoleMessage("[CustomCrops] Running on <white>" + Bukkit.getVersion());
|
||||||
|
this.registerCommands();
|
||||||
|
this.loadPlatform();
|
||||||
|
|
||||||
|
this.configManager = new ConfigManager(this);
|
||||||
|
this.messageManager = new MessageManager(this);
|
||||||
this.versionHelper = new VersionHelper(this);
|
this.versionHelper = new VersionHelper(this);
|
||||||
AdventureUtil.consoleMessage("[CustomCrops] Running on <white>" + Bukkit.getVersion());
|
this.cropManager = new CropManager(this);
|
||||||
VersionChecker.hideOk = true;
|
this.integrationManager = new IntegrationManager(this);
|
||||||
if (Bukkit.getPluginManager().getPlugin("ItemsAdder") != null) {
|
this.seasonManager = new SeasonManager(this);
|
||||||
MainConfig.customPlugin = "itemsadder";
|
this.worldDataManager = new WorldDataManager(this);
|
||||||
AdventureUtil.consoleMessage("[CustomCrops] Custom Item Plugin Platform: <#BA55D3><u>ItemsAdder");
|
this.sprinklerManager = new SprinklerManager(this);
|
||||||
}
|
this.wateringCanManager = new WateringCanManager(this);
|
||||||
else if (Bukkit.getPluginManager().getPlugin("Oraxen") != null) {
|
this.fertilizerManager = new FertilizerManager(this);
|
||||||
MainConfig.customPlugin = "oraxen";
|
this.potManager = new PotManager(this);
|
||||||
AdventureUtil.consoleMessage("[CustomCrops] Custom Item Plugin Platform: <#6495ED><u>Oraxen");
|
this.platformManager = new PlatformManager(this);
|
||||||
}
|
this.customCropsAPI = new CustomCropsAPI(this);
|
||||||
else {
|
|
||||||
AdventureUtil.consoleMessage("<red>[CustomCrops] You need either ItemsAdder or Oraxen as CustomCrops' dependency");
|
this.reload();
|
||||||
Bukkit.getPluginManager().disablePlugin(CustomCrops.plugin);
|
|
||||||
return;
|
for (World world : Bukkit.getWorlds()) {
|
||||||
|
this.worldDataManager.loadWorld(world);
|
||||||
}
|
}
|
||||||
|
|
||||||
ConfigUtil.reloadConfigs();
|
AdventureUtils.consoleMessage("[CustomCrops] Plugin Enabled!");
|
||||||
this.registerQuests();
|
if (ConfigManager.enableBStats) new Metrics(this, 16593);
|
||||||
|
if (ConfigManager.checkUpdate) this.versionHelper.checkUpdate();
|
||||||
|
}
|
||||||
|
|
||||||
PluginCommand pluginCommand = new PluginCommand();
|
public void reload() {
|
||||||
Objects.requireNonNull(Bukkit.getPluginCommand("customcrops")).setExecutor(pluginCommand);
|
this.configManager.unload();
|
||||||
Objects.requireNonNull(Bukkit.getPluginCommand("customcrops")).setTabCompleter(pluginCommand);
|
this.messageManager.unload();
|
||||||
|
this.cropManager.unload();
|
||||||
|
this.integrationManager.unload();
|
||||||
|
this.worldDataManager.unload();
|
||||||
|
this.sprinklerManager.unload();
|
||||||
|
this.wateringCanManager.unload();
|
||||||
|
this.fertilizerManager.unload();
|
||||||
|
this.potManager.unload();
|
||||||
|
this.seasonManager.unload();
|
||||||
|
this.platformManager.unload();
|
||||||
|
|
||||||
this.cropManager = new CropManager();
|
this.configManager.load();
|
||||||
|
this.messageManager.load();
|
||||||
if (Bukkit.getPluginManager().getPlugin("PlaceholderAPI") != null) {
|
this.integrationManager.load();
|
||||||
this.placeholderManager = new PlaceholderManager();
|
this.cropManager.load();
|
||||||
}
|
this.worldDataManager.load();
|
||||||
|
this.sprinklerManager.load();
|
||||||
AdventureUtil.consoleMessage("[CustomCrops] Plugin Enabled!");
|
this.wateringCanManager.load();
|
||||||
|
this.fertilizerManager.load();
|
||||||
if (MainConfig.metrics) {
|
this.potManager.load();
|
||||||
new Metrics(this, 16593);
|
this.seasonManager.load();
|
||||||
}
|
this.platformManager.load();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDisable() {
|
public void onDisable() {
|
||||||
if (adventure != null) {
|
if (adventure != null) adventure.close();
|
||||||
adventure.close();
|
if (this.cropManager != null) this.cropManager.unload();
|
||||||
}
|
if (this.worldDataManager != null) this.worldDataManager.disable();
|
||||||
if (this.placeholderManager != null) {
|
if (this.seasonManager != null) this.seasonManager.unload();
|
||||||
this.placeholderManager.unload();
|
if (this.sprinklerManager != null) this.sprinklerManager.unload();
|
||||||
}
|
if (this.wateringCanManager != null) this.wateringCanManager.unload();
|
||||||
if (this.cropManager != null) {
|
if (this.fertilizerManager != null) this.fertilizerManager.unload();
|
||||||
this.cropManager.unload();
|
if (this.platformManager != null) this.platformManager.unload();
|
||||||
|
if (this.potManager != null) this.potManager.unload();
|
||||||
|
if (this.messageManager != null) this.messageManager.unload();
|
||||||
|
if (this.configManager != null) this.configManager.unload();
|
||||||
|
if (this.integrationManager != null) this.integrationManager.unload();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void loadLibs() {
|
||||||
|
TimeZone timeZone = TimeZone.getDefault();
|
||||||
|
String libRepo = timeZone.getID().startsWith("Asia") ? "https://maven.aliyun.com/repository/public/" : "https://repo.maven.apache.org/maven2/";
|
||||||
|
LibraryLoader.load("dev.dejvokep","boosted-yaml","1.3", libRepo);
|
||||||
|
LibraryLoader.load("commons-io","commons-io","2.11.0", libRepo);
|
||||||
|
LibraryLoader.load("net.objecthunter","exp4j","0.4.8", libRepo);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void registerCommands() {
|
||||||
|
CustomCropsCommand customCropsCommand = new CustomCropsCommand();
|
||||||
|
PluginCommand pluginCommand = Bukkit.getPluginCommand("customcrops");
|
||||||
|
if (pluginCommand != null) {
|
||||||
|
pluginCommand.setExecutor(customCropsCommand);
|
||||||
|
pluginCommand.setTabCompleter(customCropsCommand);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public PlaceholderManager getPlaceholderManager() {
|
private void loadPlatform() {
|
||||||
return placeholderManager;
|
PluginManager pluginManager = Bukkit.getPluginManager();
|
||||||
|
if (pluginManager.isPluginEnabled("ItemsAdder")) {
|
||||||
|
this.platform = Platform.ItemsAdder;
|
||||||
|
this.platformInterface = new ItemsAdderPluginImpl();
|
||||||
|
}
|
||||||
|
else if (pluginManager.isPluginEnabled("Oraxen")) {
|
||||||
|
this.platform = Platform.Oraxen;
|
||||||
|
this.platformInterface = new OraxenPluginImpl();
|
||||||
|
}
|
||||||
|
if (this.platform == null) {
|
||||||
|
Bukkit.getPluginManager().disablePlugin(this);
|
||||||
|
AdventureUtils.consoleMessage("<red>[CustomCrops] Please install ItemsAdder/Oraxen");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
AdventureUtils.consoleMessage("[CustomCrops] Platform: " + platform.name());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean hasPapi() {
|
public static BukkitAudiences getAdventure() {
|
||||||
return placeholderManager != null;
|
return adventure;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static CustomCrops getInstance() {
|
||||||
|
return plugin;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ProtocolManager getProtocolManager() {
|
||||||
|
return protocolManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
public CropManager getCropManager() {
|
public CropManager getCropManager() {
|
||||||
@@ -154,18 +208,55 @@ public final class CustomCrops extends JavaPlugin {
|
|||||||
return versionHelper;
|
return versionHelper;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void registerQuests() {
|
public Platform getPlatform() {
|
||||||
PluginManager pluginManager = Bukkit.getPluginManager();
|
return platform;
|
||||||
if (pluginManager.isPluginEnabled("ClueScrolls")) {
|
}
|
||||||
ClueScrollCCQuest quest = new ClueScrollCCQuest();
|
|
||||||
Bukkit.getPluginManager().registerEvents(quest, plugin);
|
public IntegrationManager getIntegrationManager() {
|
||||||
}
|
return integrationManager;
|
||||||
if (pluginManager.isPluginEnabled("BetonQuest")) {
|
}
|
||||||
if (Bukkit.getPluginManager().getPlugin("BetonQuest").getDescription().getVersion().startsWith("2")) NewBetonQuestCCQuest.register();
|
|
||||||
else OldBetonQuestCCQuest.register();
|
public PlatformInterface getPlatformInterface() {
|
||||||
}
|
return platformInterface;
|
||||||
if (pluginManager.isPluginEnabled("BattlePass")) {
|
}
|
||||||
BattlePassCCQuest.register();
|
|
||||||
}
|
public WorldDataManager getWorldDataManager() {
|
||||||
|
return worldDataManager;
|
||||||
|
}
|
||||||
|
|
||||||
|
public SprinklerManager getSprinklerManager() {
|
||||||
|
return sprinklerManager;
|
||||||
|
}
|
||||||
|
|
||||||
|
public PotManager getPotManager() {
|
||||||
|
return potManager;
|
||||||
|
}
|
||||||
|
|
||||||
|
public WateringCanManager getWateringCanManager() {
|
||||||
|
return wateringCanManager;
|
||||||
|
}
|
||||||
|
|
||||||
|
public FertilizerManager getFertilizerManager() {
|
||||||
|
return fertilizerManager;
|
||||||
|
}
|
||||||
|
|
||||||
|
public SeasonManager getSeasonManager() {
|
||||||
|
return seasonManager;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ConfigManager getConfigManager() {
|
||||||
|
return configManager;
|
||||||
|
}
|
||||||
|
|
||||||
|
public MessageManager getMessageManager() {
|
||||||
|
return messageManager;
|
||||||
|
}
|
||||||
|
|
||||||
|
public PlatformManager getPlatformManager() {
|
||||||
|
return platformManager;
|
||||||
|
}
|
||||||
|
|
||||||
|
public CustomCropsAPI getAPI() {
|
||||||
|
return customCropsAPI;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,78 @@
|
|||||||
|
package net.momirealms.customcrops.api;
|
||||||
|
|
||||||
|
import net.momirealms.customcrops.CustomCrops;
|
||||||
|
import net.momirealms.customcrops.api.customplugin.PlatformInterface;
|
||||||
|
import net.momirealms.customcrops.api.object.crop.CropConfig;
|
||||||
|
import net.momirealms.customcrops.api.object.ItemMode;
|
||||||
|
import net.momirealms.customcrops.api.object.pot.Pot;
|
||||||
|
import net.momirealms.customcrops.api.object.season.CCSeason;
|
||||||
|
import net.momirealms.customcrops.api.object.world.SimpleLocation;
|
||||||
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
|
public class CustomCropsAPI {
|
||||||
|
|
||||||
|
private static CustomCropsAPI instance;
|
||||||
|
private final CustomCrops plugin;
|
||||||
|
|
||||||
|
public CustomCropsAPI(CustomCrops plugin) {
|
||||||
|
this.plugin = plugin;
|
||||||
|
instance = this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static CustomCropsAPI getInstance() {
|
||||||
|
return instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isCrop(String stage_id) {
|
||||||
|
return plugin.getCropManager().getCropConfigByStage(stage_id) != null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public CropConfig getCropConfig(String crop_config_id) {
|
||||||
|
return plugin.getCropManager().getCropConfigByID(crop_config_id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ItemStack buildItem(String id) {
|
||||||
|
return plugin.getIntegrationManager().build(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean removeCustomItem(Location location, ItemMode itemMode) {
|
||||||
|
if (itemMode == ItemMode.TRIPWIRE || itemMode == ItemMode.CHORUS)
|
||||||
|
return plugin.getPlatformInterface().removeCustomBlock(location);
|
||||||
|
else if (itemMode == ItemMode.ITEM_FRAME)
|
||||||
|
return plugin.getPlatformInterface().removeItemFrame(location);
|
||||||
|
else if (itemMode == ItemMode.ITEM_DISPLAY)
|
||||||
|
return plugin.getPlatformInterface().removeItemDisplay(location);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void placeCustomItem(Location location, String id, ItemMode itemMode) {
|
||||||
|
if (itemMode == ItemMode.TRIPWIRE)
|
||||||
|
plugin.getPlatformInterface().placeTripWire(location, id);
|
||||||
|
else if (itemMode == ItemMode.ITEM_FRAME)
|
||||||
|
plugin.getPlatformInterface().placeItemFrame(location, id);
|
||||||
|
else if (itemMode == ItemMode.ITEM_DISPLAY)
|
||||||
|
plugin.getPlatformInterface().placeItemDisplay(location, id);
|
||||||
|
else if (itemMode == ItemMode.CHORUS)
|
||||||
|
plugin.getPlatformInterface().placeChorus(location, id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void changePotModel(SimpleLocation simpleLocation, Pot pot) {
|
||||||
|
Location location = simpleLocation.getBukkitLocation();
|
||||||
|
if (location == null) return;
|
||||||
|
PlatformInterface platform = plugin.getPlatformInterface();
|
||||||
|
if (platform.removeCustomBlock(location)) {
|
||||||
|
platform.placeNoteBlock(location, pot.isWet() ? pot.getConfig().getWetPot(pot.getFertilizer()) : pot.getConfig().getDryPot(pot.getFertilizer()));
|
||||||
|
} else {
|
||||||
|
CustomCrops.getInstance().getWorldDataManager().removePotData(simpleLocation);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isGreenhouse(SimpleLocation simpleLocation) {
|
||||||
|
return plugin.getWorldDataManager().isGreenhouse(simpleLocation);
|
||||||
|
}
|
||||||
|
|
||||||
|
public CCSeason getCurrentSeason(String world) {
|
||||||
|
return plugin.getIntegrationManager().getSeasonInterface().getSeason(world);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,50 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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.crop;
|
|
||||||
|
|
||||||
import net.momirealms.customcrops.api.utils.CCSeason;
|
|
||||||
import net.momirealms.customcrops.objects.GiganticCrop;
|
|
||||||
import net.momirealms.customcrops.objects.OtherLoot;
|
|
||||||
import net.momirealms.customcrops.objects.QualityLoot;
|
|
||||||
import net.momirealms.customcrops.objects.actions.ActionInterface;
|
|
||||||
import net.momirealms.customcrops.objects.requirements.RequirementInterface;
|
|
||||||
|
|
||||||
public interface Crop {
|
|
||||||
|
|
||||||
CCSeason[] getSeasons();
|
|
||||||
|
|
||||||
RequirementInterface[] getPlantRequirements();
|
|
||||||
|
|
||||||
RequirementInterface[] getHarvestRequirements();
|
|
||||||
|
|
||||||
String getReturnStage();
|
|
||||||
|
|
||||||
QualityLoot getQualityLoot();
|
|
||||||
|
|
||||||
GiganticCrop getGiganticCrop();
|
|
||||||
|
|
||||||
OtherLoot[] getOtherLoots();
|
|
||||||
|
|
||||||
ActionInterface[] getActions();
|
|
||||||
|
|
||||||
String getKey();
|
|
||||||
|
|
||||||
boolean canRotate();
|
|
||||||
|
|
||||||
int getMax_stage();
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
package net.momirealms.customcrops.api.customplugin;
|
||||||
|
|
||||||
|
import net.momirealms.customcrops.CustomCrops;
|
||||||
|
import net.momirealms.customcrops.api.object.Function;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.HandlerList;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
import org.bukkit.event.player.PlayerInteractEvent;
|
||||||
|
|
||||||
|
public abstract class Handler extends Function implements Listener {
|
||||||
|
|
||||||
|
protected PlatformManager platformManager;
|
||||||
|
|
||||||
|
public Handler(PlatformManager platformManager) {
|
||||||
|
this.platformManager = platformManager;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void load() {
|
||||||
|
Bukkit.getPluginManager().registerEvents(this, CustomCrops.getInstance());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void unload() {
|
||||||
|
HandlerList.unregisterAll(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onInteract(PlayerInteractEvent event) {
|
||||||
|
platformManager.onInteractBlock(event);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
package net.momirealms.customcrops.api.customplugin;
|
||||||
|
|
||||||
|
public enum Platform {
|
||||||
|
ItemsAdder,
|
||||||
|
Oraxen
|
||||||
|
}
|
||||||
@@ -0,0 +1,96 @@
|
|||||||
|
package net.momirealms.customcrops.api.customplugin;
|
||||||
|
|
||||||
|
import net.momirealms.customcrops.CustomCrops;
|
||||||
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.block.Block;
|
||||||
|
import org.bukkit.entity.Entity;
|
||||||
|
import org.bukkit.entity.ItemDisplay;
|
||||||
|
import org.bukkit.entity.ItemFrame;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
|
||||||
|
public interface PlatformInterface {
|
||||||
|
|
||||||
|
boolean removeCustomBlock(Location location);
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
String getCustomBlockID(Location location);
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
ItemStack getItemStack(String id);
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
ItemFrame placeItemFrame(Location location, String id);
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
ItemDisplay placeItemDisplay(Location location, String id);
|
||||||
|
|
||||||
|
void placeNoteBlock(Location location, String id);
|
||||||
|
|
||||||
|
void placeTripWire(Location location, String id);
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
String getBlockID(Block block);
|
||||||
|
|
||||||
|
boolean doesItemExist(String id);
|
||||||
|
|
||||||
|
void dropBlockLoot(Block block);
|
||||||
|
|
||||||
|
boolean removeItemDisplay(Location location);
|
||||||
|
|
||||||
|
void placeChorus(Location location, String id);
|
||||||
|
|
||||||
|
Location getItemFrameLocation(Location location);
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
String getCustomItemAt(Location location);
|
||||||
|
|
||||||
|
default void removeCustomItemAt(Location location) {
|
||||||
|
removeCustomBlock(location);
|
||||||
|
removeItemFrame(location);
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
String getItemID(@NotNull ItemStack itemStack);
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
default ItemFrame getItemFrameAt(Location location) {
|
||||||
|
Collection<ItemFrame> itemFrames = getItemFrameLocation(location).getNearbyEntitiesByType(ItemFrame.class, 0, 0, 0);
|
||||||
|
int i = itemFrames.size();
|
||||||
|
int j = 1;
|
||||||
|
for (ItemFrame itemFrame : itemFrames) {
|
||||||
|
if (j != i) {
|
||||||
|
// To prevent item frames stack in one block
|
||||||
|
itemFrame.remove();
|
||||||
|
j++;
|
||||||
|
}
|
||||||
|
else return itemFrame;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
default boolean removeItemFrame(Location location) {
|
||||||
|
ItemFrame itemFrame = getItemFrameAt(location);
|
||||||
|
if (itemFrame != null) {
|
||||||
|
itemFrame.remove();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
default boolean detectAnyThing(Location location) {
|
||||||
|
Block block = location.getBlock();
|
||||||
|
if (block.getType() != Material.AIR) return true;
|
||||||
|
Collection<Entity> entities = location.clone().add(0.5,0.5,0.5).getNearbyEntitiesByType(ItemFrame.class, 0.5, 0.5, 0.5);
|
||||||
|
return entities.size() != 0 || (CustomCrops.getInstance().getVersionHelper().isVersionNewerThan1_19_R3() && detectItemDisplay(location));
|
||||||
|
}
|
||||||
|
|
||||||
|
default boolean detectItemDisplay(Location location) {
|
||||||
|
Collection<Entity> entities = location.clone().add(0.5,0.5,0.5).getNearbyEntitiesByType(ItemDisplay.class, 0.5, 0.5, 0.5);
|
||||||
|
return entities.size() != 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,709 @@
|
|||||||
|
package net.momirealms.customcrops.api.customplugin;
|
||||||
|
|
||||||
|
import net.momirealms.customcrops.CustomCrops;
|
||||||
|
import net.momirealms.customcrops.api.CustomCropsAPI;
|
||||||
|
import net.momirealms.customcrops.api.customplugin.itemsadder.ItemsAdderHandler;
|
||||||
|
import net.momirealms.customcrops.api.customplugin.oraxen.OraxenHandler;
|
||||||
|
import net.momirealms.customcrops.api.object.BoneMeal;
|
||||||
|
import net.momirealms.customcrops.api.object.Function;
|
||||||
|
import net.momirealms.customcrops.api.object.InteractWithItem;
|
||||||
|
import net.momirealms.customcrops.api.object.ItemType;
|
||||||
|
import net.momirealms.customcrops.api.object.fill.PassiveFillMethod;
|
||||||
|
import net.momirealms.customcrops.api.object.action.Action;
|
||||||
|
import net.momirealms.customcrops.api.object.basic.ConfigManager;
|
||||||
|
import net.momirealms.customcrops.api.object.basic.MessageManager;
|
||||||
|
import net.momirealms.customcrops.api.object.crop.CropConfig;
|
||||||
|
import net.momirealms.customcrops.api.object.crop.GrowingCrop;
|
||||||
|
import net.momirealms.customcrops.api.object.crop.StageConfig;
|
||||||
|
import net.momirealms.customcrops.api.object.fertilizer.Fertilizer;
|
||||||
|
import net.momirealms.customcrops.api.object.fertilizer.FertilizerConfig;
|
||||||
|
import net.momirealms.customcrops.api.object.fill.PositiveFillMethod;
|
||||||
|
import net.momirealms.customcrops.api.object.pot.Pot;
|
||||||
|
import net.momirealms.customcrops.api.object.pot.PotConfig;
|
||||||
|
import net.momirealms.customcrops.api.object.requirement.CurrentState;
|
||||||
|
import net.momirealms.customcrops.api.object.requirement.Requirement;
|
||||||
|
import net.momirealms.customcrops.api.object.sprinkler.SprinklerConfig;
|
||||||
|
import net.momirealms.customcrops.api.object.wateringcan.WateringCanConfig;
|
||||||
|
import net.momirealms.customcrops.api.object.world.SimpleLocation;
|
||||||
|
import net.momirealms.customcrops.api.util.AdventureUtils;
|
||||||
|
import org.bukkit.GameMode;
|
||||||
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.Particle;
|
||||||
|
import org.bukkit.Sound;
|
||||||
|
import org.bukkit.block.Block;
|
||||||
|
import org.bukkit.entity.Entity;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.Cancellable;
|
||||||
|
import org.bukkit.event.player.PlayerInteractEvent;
|
||||||
|
import org.bukkit.inventory.EquipmentSlot;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
public class PlatformManager extends Function {
|
||||||
|
|
||||||
|
private final CustomCrops plugin;
|
||||||
|
private final Handler handler;
|
||||||
|
|
||||||
|
public PlatformManager(CustomCrops plugin) {
|
||||||
|
this.plugin = plugin;
|
||||||
|
this.handler = switch (plugin.getPlatform()) {
|
||||||
|
case ItemsAdder -> new ItemsAdderHandler(this);
|
||||||
|
case Oraxen -> new OraxenHandler(this);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void load() {
|
||||||
|
this.handler.load();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void unload() {
|
||||||
|
this.handler.unload();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void onBreakTripWire(Player player, Block block, String id, Cancellable event) {
|
||||||
|
if (event.isCancelled()) return;
|
||||||
|
onBreakSomething(player, block.getLocation(), id, event);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void onBreakNoteBlock(Player player, Block block, String id, Cancellable event) {
|
||||||
|
if (event.isCancelled()) return;
|
||||||
|
onBreakSomething(player, block.getLocation(), id, event);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void onBreakItemDisplay(Player player, Entity entity, String id, Cancellable event) {
|
||||||
|
if (event.isCancelled()) return;
|
||||||
|
onBreakSomething(player, entity.getLocation().getBlock().getLocation(), id, event);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void onBreakItemFrame(Player player, Entity entity, String id, Cancellable event) {
|
||||||
|
if (event.isCancelled()) return;
|
||||||
|
onBreakSomething(player, entity.getLocation().getBlock().getLocation(), id, event);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void onPlaceFurniture(Location location, String id) {
|
||||||
|
onPlaceSomething(location, id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void onPlaceBlock(Location location, String id, Cancellable event) {
|
||||||
|
if (event.isCancelled()) return;
|
||||||
|
onPlaceSomething(location, id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void onInteractBlock(PlayerInteractEvent event) {
|
||||||
|
if (event.getHand() != EquipmentSlot.HAND) return;
|
||||||
|
if (event.getAction() == org.bukkit.event.block.Action.RIGHT_CLICK_AIR) {
|
||||||
|
onInteractAir(event.getPlayer());
|
||||||
|
} else if (event.getAction() == org.bukkit.event.block.Action.RIGHT_CLICK_BLOCK) {
|
||||||
|
Block block = event.getClickedBlock();
|
||||||
|
String id = plugin.getPlatformInterface().getBlockID(block);
|
||||||
|
assert block != null;
|
||||||
|
onInteractSomething(event.getPlayer(), block.getLocation(), id, event);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void onInteractFurniture(Player player, Entity entity, String id, Cancellable event) {
|
||||||
|
if (event.isCancelled()) return;
|
||||||
|
onInteractSomething(player, entity.getLocation().getBlock().getLocation(), id, event);
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
public ItemType onInteractAir(Player player) {
|
||||||
|
ItemStack item_in_hand = player.getInventory().getItemInMainHand();
|
||||||
|
String id = plugin.getPlatformInterface().getItemID(item_in_hand);
|
||||||
|
|
||||||
|
if (onInteractWithWateringCan(player, id, item_in_hand)) {
|
||||||
|
return ItemType.WATERINGCAN;
|
||||||
|
}
|
||||||
|
|
||||||
|
return ItemType.UNKNOWN;
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
public ItemType onBreakSomething(Player player, Location location, String id, Cancellable event) {
|
||||||
|
|
||||||
|
if (onBreakGlass(id, location)) {
|
||||||
|
return ItemType.GLASS;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (onBreakPot(player, id, location, event)) {
|
||||||
|
return ItemType.POT;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (onBreakCrop(player, id, location, event)) {
|
||||||
|
return ItemType.CROP;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (onBreakSprinkler(id, location)) {
|
||||||
|
return ItemType.SPRINKLER;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (onBreakScarecrow(id, location)) {
|
||||||
|
return ItemType.SCARECROW;
|
||||||
|
}
|
||||||
|
|
||||||
|
return ItemType.UNKNOWN;
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
public ItemType onPlaceSomething(Location location, String id) {
|
||||||
|
|
||||||
|
if (onPlaceGlass(id, location)) {
|
||||||
|
return ItemType.GLASS;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (onPlacePot(id, location)) {
|
||||||
|
return ItemType.POT;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (onPlaceScarecrow(id, location)) {
|
||||||
|
return ItemType.SCARECROW;
|
||||||
|
}
|
||||||
|
|
||||||
|
return ItemType.UNKNOWN;
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull ItemType onInteractSomething(Player player, Location location, String id, Cancellable event) {
|
||||||
|
|
||||||
|
ItemStack item_in_hand = player.getInventory().getItemInMainHand();
|
||||||
|
String item_in_hand_id = plugin.getPlatformInterface().getItemID(item_in_hand);
|
||||||
|
|
||||||
|
if (onInteractWithSprinkler(player, location, item_in_hand, item_in_hand_id)) {
|
||||||
|
return ItemType.SPRINKLER;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (onInteractSprinkler(player, id, location, item_in_hand, item_in_hand_id)) {
|
||||||
|
return ItemType.SPRINKLER;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (onInteractPot(player, id, location, item_in_hand, item_in_hand_id)) {
|
||||||
|
return ItemType.POT;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (onInteractCrop(player, id, location, item_in_hand, item_in_hand_id)) {
|
||||||
|
return ItemType.CROP;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (onInteractWithWateringCan(player, item_in_hand_id, item_in_hand)) {
|
||||||
|
return ItemType.WATERINGCAN;
|
||||||
|
}
|
||||||
|
|
||||||
|
return ItemType.UNKNOWN;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean onBreakGlass(String id, Location location) {
|
||||||
|
if (!id.equals(ConfigManager.greenhouseBlock)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
plugin.getWorldDataManager().removeGreenhouse(SimpleLocation.getByBukkitLocation(location));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean onPlaceGlass(String id, Location location) {
|
||||||
|
if (!id.equals(ConfigManager.greenhouseBlock)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
plugin.getWorldDataManager().addGreenhouse(SimpleLocation.getByBukkitLocation(location));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean onBreakScarecrow(String id, Location location) {
|
||||||
|
if (!id.equals(ConfigManager.scarecrow)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
plugin.getWorldDataManager().removeScarecrow(SimpleLocation.getByBukkitLocation(location));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean onPlaceScarecrow(String id, Location location) {
|
||||||
|
if (!id.equals(ConfigManager.scarecrow)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
plugin.getWorldDataManager().addScarecrow(SimpleLocation.getByBukkitLocation(location));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean onPlacePot(String id, Location location) {
|
||||||
|
String pot_id = plugin.getPotManager().getPotKeyByBlockID(id);
|
||||||
|
if (pot_id == null) return false;
|
||||||
|
|
||||||
|
plugin.getWorldDataManager().addPotData(SimpleLocation.getByBukkitLocation(location), new Pot(pot_id, null, 0));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean onInteractSprinkler(Player player, String id, Location location, ItemStack item_in_hand, String item_in_hand_id) {
|
||||||
|
SprinklerConfig sprinklerConfig = plugin.getSprinklerManager().getConfigByItemID(id);
|
||||||
|
if (sprinklerConfig == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// water
|
||||||
|
PassiveFillMethod[] passiveFillMethods = sprinklerConfig.getPassiveFillMethods();
|
||||||
|
for (PassiveFillMethod passiveFillMethod : passiveFillMethods) {
|
||||||
|
if (passiveFillMethod.isRightItem(item_in_hand_id)) {
|
||||||
|
doPassiveFillAction(player, item_in_hand, passiveFillMethod, location.clone().add(0,0.2,0));
|
||||||
|
plugin.getWorldDataManager().addWaterToSprinkler(SimpleLocation.getByBukkitLocation(location), passiveFillMethod.getAmount(), sprinklerConfig.getRange(), sprinklerConfig.getStorage());
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
WateringCanConfig wateringCanConfig = plugin.getWateringCanManager().getConfigByItemID(item_in_hand_id);
|
||||||
|
if (wateringCanConfig != null) {
|
||||||
|
String[] sprinkler_whitelist = wateringCanConfig.getSprinklerWhitelist();
|
||||||
|
if (sprinkler_whitelist != null) {
|
||||||
|
outer: {
|
||||||
|
for (String sprinkler_allowed : sprinkler_whitelist) {
|
||||||
|
if (sprinkler_allowed.equals(plugin.getSprinklerManager().getConfigKeyByItemID(id))) {
|
||||||
|
break outer;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
int current_water = plugin.getWateringCanManager().getCurrentWater(item_in_hand);
|
||||||
|
if (current_water <= 0) return true;
|
||||||
|
|
||||||
|
//TODO API Events
|
||||||
|
|
||||||
|
current_water--;
|
||||||
|
if (wateringCanConfig.hasActionBar()) {
|
||||||
|
AdventureUtils.playerActionbar(player, wateringCanConfig.getActionBarMsg(current_water));
|
||||||
|
}
|
||||||
|
if (wateringCanConfig.getSound() != null) {
|
||||||
|
AdventureUtils.playerSound(player, wateringCanConfig.getSound());
|
||||||
|
}
|
||||||
|
if (wateringCanConfig.getParticle() != null) {
|
||||||
|
location.getWorld().spawnParticle(wateringCanConfig.getParticle(), location.clone().add(0.5,0.4, 0.5),5,0.3,0.1,0.3);
|
||||||
|
}
|
||||||
|
|
||||||
|
plugin.getWateringCanManager().setWater(item_in_hand, current_water, wateringCanConfig);
|
||||||
|
plugin.getWorldDataManager().addWaterToSprinkler(SimpleLocation.getByBukkitLocation(location), 1, sprinklerConfig.getRange(), sprinklerConfig.getStorage());
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void doPassiveFillAction(Player player, ItemStack item_in_hand, PassiveFillMethod passiveFillMethod, Location location) {
|
||||||
|
if (player.getGameMode() != GameMode.CREATIVE) {
|
||||||
|
item_in_hand.setAmount(item_in_hand.getAmount() - 1);
|
||||||
|
ItemStack returned = passiveFillMethod.getReturnedItemStack();
|
||||||
|
if (returned != null) {
|
||||||
|
player.getInventory().addItem(returned);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (passiveFillMethod.getSound() != null) {
|
||||||
|
AdventureUtils.playerSound(player, passiveFillMethod.getSound());
|
||||||
|
}
|
||||||
|
if (passiveFillMethod.getParticle() != null) {
|
||||||
|
location.getWorld().spawnParticle(passiveFillMethod.getParticle(), location.clone().add(0.5,0.4, 0.5),5,0.3,0.1,0.3);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean onInteractWithSprinkler(Player player, Location location, ItemStack item_in_hand, String item_in_hand_id) {
|
||||||
|
SprinklerConfig sprinklerConfig = plugin.getSprinklerManager().getConfigByItemID(item_in_hand_id);
|
||||||
|
if (sprinklerConfig == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
Location sprinkler_loc = location.clone().add(0,1,0);
|
||||||
|
if (plugin.getPlatformInterface().detectAnyThing(sprinkler_loc)) return true;
|
||||||
|
|
||||||
|
if (player.getGameMode() != GameMode.CREATIVE) item_in_hand.setAmount(item_in_hand.getAmount() - 1);
|
||||||
|
CustomCropsAPI.getInstance().placeCustomItem(sprinkler_loc, sprinklerConfig.getThreeD(), sprinklerConfig.getItemMode());
|
||||||
|
if (sprinklerConfig.getSound() != null) {
|
||||||
|
AdventureUtils.playerSound(player, sprinklerConfig.getSound());
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean onInteractCrop(Player player, String id, Location location, ItemStack item_in_hand, String item_in_hand_id) {
|
||||||
|
CropConfig cropConfig = plugin.getCropManager().getCropConfigByStage(id);
|
||||||
|
if (cropConfig == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
StageConfig stageConfig = plugin.getCropManager().getStageConfig(id);
|
||||||
|
if (stageConfig == null) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (item_in_hand_id.equals("AIR")) {
|
||||||
|
Action[] actions = stageConfig.getInteractByHandActions();
|
||||||
|
if (actions != null) {
|
||||||
|
for (Action action : actions) {
|
||||||
|
action.doOn(player, SimpleLocation.getByBukkitLocation(location), cropConfig.getCropMode());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
WateringCanConfig wateringCanConfig = plugin.getWateringCanManager().getConfigByItemID(item_in_hand_id);
|
||||||
|
Pot potData = plugin.getWorldDataManager().getPotData(SimpleLocation.getByBukkitLocation(location).add(0,-1,0));
|
||||||
|
if (wateringCanConfig != null && potData != null) {
|
||||||
|
String[] pot_whitelist = wateringCanConfig.getPotWhitelist();
|
||||||
|
if (pot_whitelist != null) {
|
||||||
|
outer: {
|
||||||
|
for (String pot : pot_whitelist) {
|
||||||
|
if (pot.equals(potData.getPotKey())) {
|
||||||
|
break outer;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
int current_water = plugin.getWateringCanManager().getCurrentWater(item_in_hand);
|
||||||
|
if (current_water <= 0) return true;
|
||||||
|
|
||||||
|
//TODO API Events
|
||||||
|
|
||||||
|
current_water--;
|
||||||
|
this.waterPot(wateringCanConfig.getWidth(), wateringCanConfig.getLength(), location.clone().subtract(0,1,0), player.getLocation().getYaw(), potData.getPotKey(), wateringCanConfig.getParticle());
|
||||||
|
if (wateringCanConfig.hasActionBar()) {
|
||||||
|
AdventureUtils.playerActionbar(player, wateringCanConfig.getActionBarMsg(current_water));
|
||||||
|
}
|
||||||
|
if (wateringCanConfig.getSound() != null) {
|
||||||
|
AdventureUtils.playerSound(player, wateringCanConfig.getSound());
|
||||||
|
}
|
||||||
|
plugin.getWateringCanManager().setWater(item_in_hand, current_water, wateringCanConfig);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
BoneMeal[] boneMeals = cropConfig.getBoneMeals();
|
||||||
|
if (boneMeals != null) {
|
||||||
|
for (BoneMeal boneMeal : boneMeals) {
|
||||||
|
if (boneMeal.isRightItem(item_in_hand_id)) {
|
||||||
|
if (plugin.getWorldDataManager().addCropPointAt(SimpleLocation.getByBukkitLocation(location), boneMeal.getPoint())) {
|
||||||
|
if (player.getGameMode() != GameMode.CREATIVE) {
|
||||||
|
item_in_hand.setAmount(item_in_hand.getAmount() - 1);
|
||||||
|
if (boneMeal.getReturned() != null) {
|
||||||
|
player.getInventory().addItem(boneMeal.getReturned());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (boneMeal.getParticle() != null) {
|
||||||
|
location.getWorld().spawnParticle(boneMeal.getParticle(), location.clone().add(0.5,0.5, 0.5),3,0.4,0.4,0.4);
|
||||||
|
}
|
||||||
|
if (boneMeal.getSound() != null) {
|
||||||
|
AdventureUtils.playerSound(player, boneMeal.getSound());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
InteractWithItem[] interactActions = stageConfig.getInteractActions();
|
||||||
|
if (interactActions != null) {
|
||||||
|
for (InteractWithItem interactWithItem : interactActions) {
|
||||||
|
if (interactWithItem.isRightItem(item_in_hand_id)) {
|
||||||
|
if (player.getGameMode() != GameMode.CREATIVE) {
|
||||||
|
if (interactWithItem.isConsumed()) {
|
||||||
|
item_in_hand.setAmount(item_in_hand.getAmount() - 1);
|
||||||
|
}
|
||||||
|
if (interactWithItem.getReturned() != null) {
|
||||||
|
player.getInventory().addItem(interactWithItem.getReturned());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Action[] inAc = interactWithItem.getActions();
|
||||||
|
if (inAc != null) {
|
||||||
|
for (Action action : inAc) {
|
||||||
|
action.doOn(player, SimpleLocation.getByBukkitLocation(location), cropConfig.getCropMode());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean onInteractPot(Player player, String id, Location location, ItemStack item_in_hand, String item_in_hand_id) {
|
||||||
|
String pot_id = plugin.getPotManager().getPotKeyByBlockID(id);
|
||||||
|
if (pot_id == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
PotConfig potConfig = plugin.getPotManager().getPotConfig(pot_id);
|
||||||
|
if (potConfig == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// water
|
||||||
|
PassiveFillMethod[] passiveFillMethods = potConfig.getPassiveFillMethods();
|
||||||
|
for (PassiveFillMethod passiveFillMethod : passiveFillMethods) {
|
||||||
|
if (passiveFillMethod.isRightItem(item_in_hand_id)) {
|
||||||
|
doPassiveFillAction(player, item_in_hand, passiveFillMethod, location);
|
||||||
|
plugin.getWorldDataManager().addWaterToPot(SimpleLocation.getByBukkitLocation(location), passiveFillMethod.getAmount(), pot_id);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
CropConfig cropConfig = plugin.getCropManager().getCropConfigBySeed(item_in_hand_id);
|
||||||
|
if (cropConfig != null) {
|
||||||
|
String[] pot_whitelist = cropConfig.getBottom_blocks();
|
||||||
|
outer: {
|
||||||
|
for (String bottom_block : pot_whitelist) {
|
||||||
|
if (bottom_block.equals(pot_id)) {
|
||||||
|
break outer;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
AdventureUtils.playerMessage(player, MessageManager.prefix + MessageManager.unsuitablePot);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
Location crop_loc = location.clone().add(0,1,0);
|
||||||
|
Requirement[] requirements = cropConfig.getPlantRequirements();
|
||||||
|
if (requirements != null) {
|
||||||
|
CurrentState currentState = new CurrentState(crop_loc, player);
|
||||||
|
for (Requirement requirement : requirements) {
|
||||||
|
if (!requirement.isConditionMet(currentState)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (plugin.getPlatformInterface().detectAnyThing(crop_loc)) return true;
|
||||||
|
if (ConfigManager.enableLimitation && plugin.getWorldDataManager().getChunkCropAmount(SimpleLocation.getByBukkitLocation(crop_loc)) >= ConfigManager.maxCropPerChunk) {
|
||||||
|
AdventureUtils.playerMessage(player, MessageManager.prefix + MessageManager.reachChunkLimit);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (player.getGameMode() != GameMode.CREATIVE) item_in_hand.setAmount(item_in_hand.getAmount() - 1);
|
||||||
|
player.swingMainHand();
|
||||||
|
CustomCropsAPI.getInstance().placeCustomItem(crop_loc, Objects.requireNonNull(cropConfig.getStageConfig(0)).getModel(), cropConfig.getCropMode());
|
||||||
|
plugin.getWorldDataManager().addCropData(SimpleLocation.getByBukkitLocation(crop_loc), new GrowingCrop(cropConfig.getKey(), 0));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// use fertilizer
|
||||||
|
FertilizerConfig fertilizerConfig = plugin.getFertilizerManager().getConfigByItemID(item_in_hand_id);
|
||||||
|
if (fertilizerConfig != null) {
|
||||||
|
if (fertilizerConfig.isBeforePlant() && plugin.getCropManager().containsStage(plugin.getPlatformInterface().getCustomItemAt(location.clone().add(0,1,0)))) {
|
||||||
|
AdventureUtils.playerMessage(player, MessageManager.prefix + MessageManager.beforePlant);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (player.getGameMode() != GameMode.CREATIVE) item_in_hand.setAmount(item_in_hand.getAmount() - 1);
|
||||||
|
player.swingMainHand();
|
||||||
|
if (fertilizerConfig.getSound() != null) {
|
||||||
|
AdventureUtils.playerSound(player, fertilizerConfig.getSound());
|
||||||
|
}
|
||||||
|
if (fertilizerConfig.getParticle() != null) {
|
||||||
|
location.getWorld().spawnParticle(fertilizerConfig.getParticle(), location.clone().add(0.5,1.1,0.5), 5,0.25,0.1,0.25, 0);
|
||||||
|
}
|
||||||
|
plugin.getWorldDataManager().addFertilizerToPot(SimpleLocation.getByBukkitLocation(location), new Fertilizer(fertilizerConfig), pot_id);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// use watering can
|
||||||
|
WateringCanConfig wateringCanConfig = plugin.getWateringCanManager().getConfigByItemID(item_in_hand_id);
|
||||||
|
if (wateringCanConfig != null) {
|
||||||
|
String[] pot_whitelist = wateringCanConfig.getPotWhitelist();
|
||||||
|
if (pot_whitelist != null) {
|
||||||
|
outer: {
|
||||||
|
for (String pot : pot_whitelist) {
|
||||||
|
if (pot.equals(pot_id)) {
|
||||||
|
break outer;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int current_water = plugin.getWateringCanManager().getCurrentWater(item_in_hand);
|
||||||
|
if (current_water <= 0) return true;
|
||||||
|
|
||||||
|
//TODO API Events
|
||||||
|
|
||||||
|
current_water--;
|
||||||
|
this.waterPot(wateringCanConfig.getWidth(), wateringCanConfig.getLength(), location, player.getLocation().getYaw(), pot_id, wateringCanConfig.getParticle());
|
||||||
|
|
||||||
|
if (wateringCanConfig.hasActionBar()) {
|
||||||
|
AdventureUtils.playerActionbar(player, wateringCanConfig.getActionBarMsg(current_water));
|
||||||
|
}
|
||||||
|
if (wateringCanConfig.getSound() != null) {
|
||||||
|
AdventureUtils.playerSound(player, wateringCanConfig.getSound());
|
||||||
|
}
|
||||||
|
|
||||||
|
plugin.getWateringCanManager().setWater(item_in_hand, current_water, wateringCanConfig);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean onBreakPot(Player player, String id, Location location, Cancellable event) {
|
||||||
|
if (!plugin.getPotManager().containsPotBlock(id)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
Location above_loc = location.clone().add(0,1,0);
|
||||||
|
String above_id = plugin.getPlatformInterface().getCustomItemAt(above_loc);
|
||||||
|
// has item above
|
||||||
|
if (above_id != null) {
|
||||||
|
// is a crop
|
||||||
|
if (onBreakCrop(player, above_id, above_loc, event)) {
|
||||||
|
// The event might be cancelled if the player doesn't meet the break requirements
|
||||||
|
if (event.isCancelled()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
plugin.getPlatformInterface().removeCustomItemAt(above_loc);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
plugin.getWorldDataManager().removePotData(SimpleLocation.getByBukkitLocation(location));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean onBreakSprinkler(String id, Location location) {
|
||||||
|
if (!plugin.getSprinklerManager().containsSprinkler(id)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
plugin.getWorldDataManager().removeSprinklerData(SimpleLocation.getByBukkitLocation(location));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean onBreakCrop(Player player, String id, Location location, Cancellable event) {
|
||||||
|
if (plugin.getCropManager().isDeadCrop(id)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
CropConfig cropConfig = plugin.getCropManager().getCropConfigByStage(id);
|
||||||
|
if (cropConfig == null) return false;
|
||||||
|
|
||||||
|
if (!canBreak(player, cropConfig, location)) {
|
||||||
|
event.setCancelled(true);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (player.getGameMode() != GameMode.CREATIVE) {
|
||||||
|
StageConfig stageConfig = plugin.getCropManager().getStageConfig(id);
|
||||||
|
if (stageConfig != null) {
|
||||||
|
Action[] breakActions = stageConfig.getBreakActions();
|
||||||
|
if (breakActions != null) {
|
||||||
|
for (Action action : breakActions) {
|
||||||
|
action.doOn(player, SimpleLocation.getByBukkitLocation(location), cropConfig.getCropMode());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
plugin.getWorldDataManager().removeCropData(SimpleLocation.getByBukkitLocation(location));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean canBreak(Player player, CropConfig cropConfig, Location crop_loc) {
|
||||||
|
Requirement[] requirements = cropConfig.getBreakRequirements();
|
||||||
|
if (requirements == null) return true;
|
||||||
|
CurrentState currentState = new CurrentState(crop_loc, player);
|
||||||
|
for (Requirement requirement : requirements) {
|
||||||
|
if (!requirement.isConditionMet(currentState)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void waterPot(int width, int length, Location location, float yaw, String id, @Nullable Particle particle){
|
||||||
|
int extend = width / 2;
|
||||||
|
if (yaw < 45 && yaw > -135) {
|
||||||
|
if (yaw > -45) {
|
||||||
|
for (int i = -extend; i <= extend; i++) {
|
||||||
|
Location tempLoc = location.clone().add(i, 0, -1);
|
||||||
|
for (int j = 0; j < length; j++){
|
||||||
|
tempLoc.add(0,0,1);
|
||||||
|
tryToWaterPot(tempLoc, id, particle);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
for (int i = -extend; i <= extend; i++) {
|
||||||
|
Location tempLoc = location.clone().add(-1, 0, i);
|
||||||
|
for (int j = 0; j < length; j++){
|
||||||
|
tempLoc.add(1,0,0);
|
||||||
|
tryToWaterPot(tempLoc, id, particle);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
if (yaw > 45 && yaw < 135) {
|
||||||
|
for (int i = -extend; i <= extend; i++) {
|
||||||
|
Location tempLoc = location.clone().add(1, 0, i);
|
||||||
|
for (int j = 0; j < length; j++){
|
||||||
|
tempLoc.subtract(1,0,0);
|
||||||
|
tryToWaterPot(tempLoc, id, particle);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
for (int i = -extend; i <= extend; i++) {
|
||||||
|
Location tempLoc = location.clone().add(i, 0, 1);
|
||||||
|
for (int j = 0; j < length; j++){
|
||||||
|
tempLoc.subtract(0,0,1);
|
||||||
|
tryToWaterPot(tempLoc, id, particle);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void tryToWaterPot(Location location, String pot_id, @Nullable Particle particle) {
|
||||||
|
String blockID = plugin.getPlatformInterface().getBlockID(location.getBlock());
|
||||||
|
String current_id = plugin.getPotManager().getPotKeyByBlockID(blockID);
|
||||||
|
if (current_id != null && current_id.equals(pot_id)) {
|
||||||
|
plugin.getWorldDataManager().addWaterToPot(SimpleLocation.getByBukkitLocation(location), 1, pot_id);
|
||||||
|
if (particle != null)
|
||||||
|
location.getWorld().spawnParticle(particle, location.clone().add(0.5,1, 0.5),3,0.1,0.1,0.1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean onInteractWithWateringCan(Player player, String item_in_hand_id, ItemStack item_in_hand) {
|
||||||
|
WateringCanConfig wateringCanConfig = plugin.getWateringCanManager().getConfigByItemID(item_in_hand_id);
|
||||||
|
if (wateringCanConfig == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
int current = plugin.getWateringCanManager().getCurrentWater(item_in_hand);
|
||||||
|
if (current >= wateringCanConfig.getStorage()) return true;
|
||||||
|
List<Block> lineOfSight = player.getLineOfSight(null, 5);
|
||||||
|
List<String> blockIds = lineOfSight.stream().map(block -> plugin.getPlatformInterface().getBlockID(block)).toList();
|
||||||
|
|
||||||
|
int add = 0;
|
||||||
|
for (PositiveFillMethod positiveFillMethod : wateringCanConfig.getPositiveFillMethods()) {
|
||||||
|
if (positiveFillMethod.getType() == PositiveFillMethod.InteractType.BLOCK) {
|
||||||
|
int index = 0;
|
||||||
|
for (String blockId : blockIds) {
|
||||||
|
if (positiveFillMethod.getId().equals(blockId)) {
|
||||||
|
add = positiveFillMethod.getAmount();
|
||||||
|
if (positiveFillMethod.getSound() != null) {
|
||||||
|
AdventureUtils.playerSound(player, positiveFillMethod.getSound());
|
||||||
|
}
|
||||||
|
if (positiveFillMethod.getParticle() != null) {
|
||||||
|
Block block = lineOfSight.get(index);
|
||||||
|
block.getWorld().spawnParticle(positiveFillMethod.getParticle(), block.getLocation().add(0.5,1, 0.5),5,0.1,0.1,0.1);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
index++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (add == 0) return true;
|
||||||
|
int finalWater = Math.min(wateringCanConfig.getStorage(), add + current);
|
||||||
|
plugin.getWateringCanManager().setWater(item_in_hand, finalWater, wateringCanConfig);
|
||||||
|
if (wateringCanConfig.hasActionBar()) {
|
||||||
|
AdventureUtils.playerActionbar(player, wateringCanConfig.getActionBarMsg(finalWater));
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,48 @@
|
|||||||
|
package net.momirealms.customcrops.api.customplugin.itemsadder;
|
||||||
|
|
||||||
|
import dev.lone.itemsadder.api.Events.*;
|
||||||
|
import net.momirealms.customcrops.api.customplugin.Handler;
|
||||||
|
import net.momirealms.customcrops.api.customplugin.PlatformManager;
|
||||||
|
import org.bukkit.block.Block;
|
||||||
|
import org.bukkit.entity.Entity;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
|
||||||
|
public class ItemsAdderHandler extends Handler {
|
||||||
|
|
||||||
|
public ItemsAdderHandler(PlatformManager platformManager) {
|
||||||
|
super(platformManager);
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onBreakCustomBlock(CustomBlockBreakEvent event) {
|
||||||
|
Block block = event.getBlock();
|
||||||
|
switch (block.getType()) {
|
||||||
|
case NOTE_BLOCK -> platformManager.onBreakNoteBlock(event.getPlayer(), event.getBlock(), event.getNamespacedID(), event);
|
||||||
|
case TRIPWIRE -> platformManager.onBreakTripWire(event.getPlayer(), event.getBlock(), event.getNamespacedID(), event);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onBreakFurniture(FurnitureBreakEvent event) {
|
||||||
|
Entity entity = event.getBukkitEntity();
|
||||||
|
switch (entity.getType()) {
|
||||||
|
case ITEM_FRAME -> platformManager.onBreakItemFrame(event.getPlayer(), entity, event.getNamespacedID(), event);
|
||||||
|
case ITEM_DISPLAY -> platformManager.onBreakItemDisplay(event.getPlayer(), entity, event.getNamespacedID(), event);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onPlaceFurniture(FurniturePlaceSuccessEvent event) {
|
||||||
|
platformManager.onPlaceFurniture(event.getBukkitEntity().getLocation().getBlock().getLocation(), event.getNamespacedID());
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onPlaceCustomBlock(CustomBlockPlaceEvent event) {
|
||||||
|
platformManager.onPlaceBlock(event.getBlock().getLocation(), event.getNamespacedID(), event);
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onInteractFurniture(FurnitureInteractEvent event) {
|
||||||
|
platformManager.onInteractFurniture(event.getPlayer(), event.getBukkitEntity(), event.getNamespacedID(), event);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,134 @@
|
|||||||
|
package net.momirealms.customcrops.api.customplugin.itemsadder;
|
||||||
|
|
||||||
|
import de.tr7zw.changeme.nbtapi.NBTCompound;
|
||||||
|
import de.tr7zw.changeme.nbtapi.NBTItem;
|
||||||
|
import dev.lone.itemsadder.api.CustomBlock;
|
||||||
|
import dev.lone.itemsadder.api.CustomFurniture;
|
||||||
|
import dev.lone.itemsadder.api.CustomStack;
|
||||||
|
import net.momirealms.customcrops.api.customplugin.PlatformInterface;
|
||||||
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.block.Block;
|
||||||
|
import org.bukkit.entity.Entity;
|
||||||
|
import org.bukkit.entity.ItemDisplay;
|
||||||
|
import org.bukkit.entity.ItemFrame;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
public class ItemsAdderPluginImpl implements PlatformInterface {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean removeCustomBlock(Location location) {
|
||||||
|
return CustomBlock.remove(location);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
@Override
|
||||||
|
public String getCustomBlockID(Location location) {
|
||||||
|
CustomBlock customBlock = CustomBlock.byAlreadyPlaced(location.getBlock());
|
||||||
|
return customBlock == null ? null : customBlock.getNamespacedID();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
@Override
|
||||||
|
public ItemStack getItemStack(String id) {
|
||||||
|
CustomStack customStack = CustomStack.getInstance(id);
|
||||||
|
return customStack == null ? null : customStack.getItemStack();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
@Override
|
||||||
|
public ItemFrame placeItemFrame(Location location, String id) {
|
||||||
|
CustomFurniture customFurniture = CustomFurniture.spawn(id, location.getBlock());
|
||||||
|
Entity entity = customFurniture.getArmorstand();
|
||||||
|
if (entity instanceof ItemFrame itemFrame)
|
||||||
|
return itemFrame;
|
||||||
|
else {
|
||||||
|
customFurniture.remove(false);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
@Override
|
||||||
|
public ItemDisplay placeItemDisplay(Location location, String id) {
|
||||||
|
//TODO Not implemented
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void placeNoteBlock(Location location, String id) {
|
||||||
|
CustomBlock.place(id, location);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void placeTripWire(Location location, String id) {
|
||||||
|
CustomBlock.place(id, location);
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
@Override
|
||||||
|
public String getBlockID(Block block) {
|
||||||
|
CustomBlock customBlock = CustomBlock.byAlreadyPlaced(block);
|
||||||
|
return customBlock == null ? block.getType().name() : customBlock.getNamespacedID();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean doesItemExist(String id) {
|
||||||
|
return CustomStack.getInstance(id) != null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void dropBlockLoot(Block block) {
|
||||||
|
CustomBlock customBlock = CustomBlock.byAlreadyPlaced(block);
|
||||||
|
if (customBlock == null) return;
|
||||||
|
Location block_loc = block.getLocation();
|
||||||
|
for (ItemStack itemStack : customBlock.getLoot()) {
|
||||||
|
block_loc.getWorld().dropItemNaturally(block_loc, itemStack);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean removeItemDisplay(Location location) {
|
||||||
|
//TODO Not implemented
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void placeChorus(Location location, String id) {
|
||||||
|
CustomBlock.place(id, location);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Location getItemFrameLocation(Location location) {
|
||||||
|
return location.clone().add(0.5, 0.5, 0.5);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
@Override
|
||||||
|
public String getCustomItemAt(Location location) {
|
||||||
|
String block = getBlockID(location.getBlock());
|
||||||
|
if (!block.equals("AIR")) return block;
|
||||||
|
|
||||||
|
ItemFrame itemFrame = getItemFrameAt(location);
|
||||||
|
if (itemFrame != null) {
|
||||||
|
CustomFurniture customFurniture = CustomFurniture.byAlreadySpawned(itemFrame);
|
||||||
|
if (customFurniture != null) {
|
||||||
|
return customFurniture.getNamespacedID();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
@Override
|
||||||
|
public String getItemID(@NotNull ItemStack itemStack) {
|
||||||
|
if (itemStack.getType() != Material.AIR) {
|
||||||
|
NBTItem nbtItem = new NBTItem(itemStack);
|
||||||
|
NBTCompound nbtCompound = nbtItem.getCompound("itemsadder");
|
||||||
|
if (nbtCompound != null) return nbtCompound.getString("namespace") + ":" + nbtCompound.getString("id");
|
||||||
|
}
|
||||||
|
return itemStack.getType().name();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,53 @@
|
|||||||
|
package net.momirealms.customcrops.api.customplugin.oraxen;
|
||||||
|
|
||||||
|
import io.th0rgal.oraxen.api.events.*;
|
||||||
|
import net.momirealms.customcrops.api.customplugin.Handler;
|
||||||
|
import net.momirealms.customcrops.api.customplugin.PlatformManager;
|
||||||
|
import org.bukkit.entity.Entity;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
|
||||||
|
public class OraxenHandler extends Handler {
|
||||||
|
|
||||||
|
public OraxenHandler(PlatformManager platformManager) {
|
||||||
|
super(platformManager);
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onBreakNoteBlock(OraxenNoteBlockBreakEvent event) {
|
||||||
|
platformManager.onBreakNoteBlock(event.getPlayer(), event.getBlock(), event.getMechanic().getItemID(), event);
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onBreakStringBlock(OraxenStringBlockBreakEvent event) {
|
||||||
|
platformManager.onBreakTripWire(event.getPlayer(), event.getBlock(), event.getMechanic().getItemID(), event);
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onBreakFurniture(OraxenFurnitureBreakEvent event) {
|
||||||
|
Entity entity = event.getBaseEntity();
|
||||||
|
switch (entity.getType()) {
|
||||||
|
case ITEM_FRAME -> platformManager.onBreakItemFrame(event.getPlayer(), entity, event.getMechanic().getItemID(), event);
|
||||||
|
case ITEM_DISPLAY -> platformManager.onBreakItemDisplay(event.getPlayer(), entity, event.getMechanic().getItemID(), event);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onPlaceFurniture(OraxenFurniturePlaceEvent event) {
|
||||||
|
platformManager.onPlaceFurniture(event.getBaseEntity().getLocation().getBlock().getLocation(), event.getMechanic().getItemID());
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onPlaceStringBlock(OraxenStringBlockPlaceEvent event) {
|
||||||
|
platformManager.onPlaceBlock(event.getBlock().getLocation(), event.getMechanic().getItemID(), event);
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onPlaceNoteBlock(OraxenNoteBlockPlaceEvent event) {
|
||||||
|
platformManager.onPlaceBlock(event.getBlock().getLocation(), event.getMechanic().getItemID(), event);
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onInteractFurniture(OraxenFurnitureInteractEvent event) {
|
||||||
|
platformManager.onInteractFurniture(event.getPlayer(), event.getBaseEntity(), event.getMechanic().getItemID(), event);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,154 @@
|
|||||||
|
package net.momirealms.customcrops.api.customplugin.oraxen;
|
||||||
|
|
||||||
|
import de.tr7zw.changeme.nbtapi.NBTCompound;
|
||||||
|
import de.tr7zw.changeme.nbtapi.NBTItem;
|
||||||
|
import io.th0rgal.oraxen.api.OraxenBlocks;
|
||||||
|
import io.th0rgal.oraxen.api.OraxenFurniture;
|
||||||
|
import io.th0rgal.oraxen.api.OraxenItems;
|
||||||
|
import io.th0rgal.oraxen.items.ItemBuilder;
|
||||||
|
import io.th0rgal.oraxen.mechanics.Mechanic;
|
||||||
|
import io.th0rgal.oraxen.mechanics.provided.gameplay.block.BlockMechanic;
|
||||||
|
import io.th0rgal.oraxen.mechanics.provided.gameplay.block.BlockMechanicFactory;
|
||||||
|
import io.th0rgal.oraxen.mechanics.provided.gameplay.furniture.FurnitureFactory;
|
||||||
|
import io.th0rgal.oraxen.mechanics.provided.gameplay.furniture.FurnitureMechanic;
|
||||||
|
import io.th0rgal.oraxen.mechanics.provided.gameplay.noteblock.NoteBlockMechanicFactory;
|
||||||
|
import io.th0rgal.oraxen.mechanics.provided.gameplay.stringblock.StringBlockMechanicFactory;
|
||||||
|
import io.th0rgal.oraxen.utils.drops.Drop;
|
||||||
|
import net.momirealms.customcrops.api.customplugin.PlatformInterface;
|
||||||
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.Rotation;
|
||||||
|
import org.bukkit.block.Block;
|
||||||
|
import org.bukkit.block.BlockFace;
|
||||||
|
import org.bukkit.entity.Entity;
|
||||||
|
import org.bukkit.entity.ItemDisplay;
|
||||||
|
import org.bukkit.entity.ItemFrame;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
public class OraxenPluginImpl implements PlatformInterface {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean removeCustomBlock(Location location) {
|
||||||
|
return OraxenBlocks.remove(location, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
@Override
|
||||||
|
public String getCustomBlockID(Location location) {
|
||||||
|
Mechanic mechanic = OraxenBlocks.getOraxenBlock(location);
|
||||||
|
return mechanic == null ? null : mechanic.getItemID();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
@Override
|
||||||
|
public ItemStack getItemStack(String id) {
|
||||||
|
ItemBuilder itemBuilder = OraxenItems.getItemById(id);
|
||||||
|
return itemBuilder == null ? null : itemBuilder.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
@Override
|
||||||
|
public ItemFrame placeItemFrame(Location location, String id) {
|
||||||
|
FurnitureMechanic mechanic = (FurnitureMechanic) FurnitureFactory.getInstance().getMechanic(id);
|
||||||
|
Entity entity = mechanic.place(location, 0, Rotation.NONE, BlockFace.UP);
|
||||||
|
if (entity instanceof ItemFrame itemFrame)
|
||||||
|
return itemFrame;
|
||||||
|
else {
|
||||||
|
entity.remove();
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
@Override
|
||||||
|
public ItemDisplay placeItemDisplay(Location location, String id) {
|
||||||
|
FurnitureMechanic mechanic = (FurnitureMechanic) FurnitureFactory.getInstance().getMechanic(id);
|
||||||
|
Entity entity = mechanic.place(location);
|
||||||
|
if (entity instanceof ItemDisplay itemDisplay)
|
||||||
|
return itemDisplay;
|
||||||
|
else {
|
||||||
|
entity.remove();
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void placeNoteBlock(Location location, String id) {
|
||||||
|
NoteBlockMechanicFactory.setBlockModel(location.getBlock(), id);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void placeTripWire(Location location, String id) {
|
||||||
|
StringBlockMechanicFactory.setBlockModel(location.getBlock(), id);
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
@Override
|
||||||
|
public String getBlockID(Block block) {
|
||||||
|
Mechanic mechanic = OraxenBlocks.getOraxenBlock(block.getBlockData());
|
||||||
|
return mechanic == null ? block.getType().name() : mechanic.getItemID();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean doesItemExist(String id) {
|
||||||
|
return OraxenItems.getItemById(id) != null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void dropBlockLoot(Block block) {
|
||||||
|
BlockMechanic mechanic = BlockMechanicFactory.getBlockMechanic(block);
|
||||||
|
if (mechanic == null) return;
|
||||||
|
Drop drop = mechanic.getDrop();
|
||||||
|
if (drop != null)
|
||||||
|
drop.spawns(block.getLocation(), new ItemStack(Material.AIR));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean removeItemDisplay(Location location) {
|
||||||
|
//TODO Not implemented
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void placeChorus(Location location, String id) {
|
||||||
|
//TODO Not implemented
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Location getItemFrameLocation(Location location) {
|
||||||
|
return location.clone().add(0.5,0.03125,0.5);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
@Override
|
||||||
|
public String getCustomItemAt(Location location) {
|
||||||
|
String block = getBlockID(location.getBlock());
|
||||||
|
if (!block.equals("AIR")) return block;
|
||||||
|
|
||||||
|
ItemFrame itemFrame = getItemFrameAt(location);
|
||||||
|
if (itemFrame != null) {
|
||||||
|
FurnitureMechanic furnitureMechanic = OraxenFurniture.getFurnitureMechanic(itemFrame);
|
||||||
|
if (furnitureMechanic != null) {
|
||||||
|
return furnitureMechanic.getItemID();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
@Override
|
||||||
|
public String getItemID(@NotNull ItemStack itemStack) {
|
||||||
|
if (itemStack.getType() != Material.AIR) {
|
||||||
|
NBTItem nbtItem = new NBTItem(itemStack);
|
||||||
|
NBTCompound bukkitPublic = nbtItem.getCompound("PublicBukkitValues");
|
||||||
|
if (bukkitPublic != null) {
|
||||||
|
String id = bukkitPublic.getString("oraxen:id");
|
||||||
|
if (!id.equals("")) return id;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return itemStack.getType().name();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,83 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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 net.momirealms.customcrops.api.crop.Crop;
|
|
||||||
import net.momirealms.customcrops.objects.fertilizer.Fertilizer;
|
|
||||||
import org.bukkit.Location;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.event.Cancellable;
|
|
||||||
import org.bukkit.event.HandlerList;
|
|
||||||
import org.bukkit.event.player.PlayerEvent;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
import org.jetbrains.annotations.Nullable;
|
|
||||||
|
|
||||||
public class CropHarvestEvent extends PlayerEvent implements Cancellable {
|
|
||||||
|
|
||||||
private static final HandlerList handlers = new HandlerList();
|
|
||||||
private boolean cancelled;
|
|
||||||
private final Location location;
|
|
||||||
private final Crop crop;
|
|
||||||
private final Fertilizer fertilizer;
|
|
||||||
|
|
||||||
public CropHarvestEvent(@NotNull Player who, Crop crop, Location location, @Nullable Fertilizer fertilizer) {
|
|
||||||
super(who);
|
|
||||||
this.crop = crop;
|
|
||||||
this.location = location;
|
|
||||||
this.cancelled = false;
|
|
||||||
this.fertilizer = fertilizer;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isCancelled() {
|
|
||||||
return cancelled;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setCancelled(boolean cancel) {
|
|
||||||
this.cancelled = cancel;
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
public static HandlerList getHandlerList() {
|
|
||||||
return handlers;
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
@Override
|
|
||||||
public HandlerList getHandlers() {
|
|
||||||
return getHandlerList();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the crop player is harvesting
|
|
||||||
* @return crop
|
|
||||||
*/
|
|
||||||
public Crop getCrop() {
|
|
||||||
return crop;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Location getLocation() {
|
|
||||||
return location;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Nullable
|
|
||||||
public Fertilizer getFertilizer() {
|
|
||||||
return fertilizer;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,48 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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.Event;
|
|
||||||
import org.bukkit.event.HandlerList;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
|
|
||||||
public class CrowAttackEvent extends Event {
|
|
||||||
|
|
||||||
private final Location location;
|
|
||||||
private static final HandlerList handlers = new HandlerList();
|
|
||||||
|
|
||||||
public CrowAttackEvent(Location location) {
|
|
||||||
this.location = location;
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
public static HandlerList getHandlerList() {
|
|
||||||
return handlers;
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
@Override
|
|
||||||
public HandlerList getHandlers() {
|
|
||||||
return getHandlerList();
|
|
||||||
}
|
|
||||||
|
|
||||||
public Location getLocation() {
|
|
||||||
return location;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,51 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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 net.momirealms.customcrops.objects.WorldState;
|
|
||||||
import org.bukkit.World;
|
|
||||||
import org.bukkit.event.HandlerList;
|
|
||||||
import org.bukkit.event.world.WorldEvent;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
|
|
||||||
public class CustomWorldEvent extends WorldEvent {
|
|
||||||
|
|
||||||
private static final HandlerList handlers = new HandlerList();
|
|
||||||
private final WorldState state;
|
|
||||||
|
|
||||||
public CustomWorldEvent(@NotNull World world, WorldState worldState) {
|
|
||||||
super(world);
|
|
||||||
this.state = worldState;
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
public static HandlerList getHandlerList() {
|
|
||||||
return handlers;
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
@Override
|
|
||||||
public HandlerList getHandlers() {
|
|
||||||
return getHandlerList();
|
|
||||||
}
|
|
||||||
|
|
||||||
public WorldState getState() {
|
|
||||||
return state;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,78 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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 net.momirealms.customcrops.objects.fertilizer.Fertilizer;
|
|
||||||
import org.bukkit.Location;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.event.Cancellable;
|
|
||||||
import org.bukkit.event.HandlerList;
|
|
||||||
import org.bukkit.event.player.PlayerEvent;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
|
|
||||||
public class FertilizerUseEvent extends PlayerEvent implements Cancellable {
|
|
||||||
|
|
||||||
private static final HandlerList handlers = new HandlerList();
|
|
||||||
private boolean cancelled;
|
|
||||||
private Fertilizer fertilizer;
|
|
||||||
private final Location potLoc;
|
|
||||||
|
|
||||||
public FertilizerUseEvent(@NotNull Player who, Fertilizer fertilizer, Location potLoc) {
|
|
||||||
super(who);
|
|
||||||
this.cancelled = false;
|
|
||||||
this.potLoc = potLoc;
|
|
||||||
this.fertilizer = fertilizer;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isCancelled() {
|
|
||||||
return cancelled;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setCancelled(boolean cancel) {
|
|
||||||
this.cancelled = cancel;
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
public static HandlerList getHandlerList() {
|
|
||||||
return handlers;
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
@Override
|
|
||||||
public HandlerList getHandlers() {
|
|
||||||
return getHandlerList();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the fertilizer player is using
|
|
||||||
* @return fertilizer
|
|
||||||
*/
|
|
||||||
public Fertilizer getFertilizer() {
|
|
||||||
return fertilizer;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setFertilizer(Fertilizer fertilizer) {
|
|
||||||
this.fertilizer = fertilizer;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Location getPotLoc() {
|
|
||||||
return potLoc;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,81 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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 net.momirealms.customcrops.api.crop.Crop;
|
|
||||||
import org.bukkit.Location;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.event.Cancellable;
|
|
||||||
import org.bukkit.event.Event;
|
|
||||||
import org.bukkit.event.HandlerList;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
import org.jetbrains.annotations.Nullable;
|
|
||||||
|
|
||||||
public class SeedPlantEvent extends Event implements Cancellable {
|
|
||||||
|
|
||||||
private static final HandlerList handlers = new HandlerList();
|
|
||||||
private boolean cancelled;
|
|
||||||
private final Location seedLoc;
|
|
||||||
private final Crop crop;
|
|
||||||
private final Player player;
|
|
||||||
|
|
||||||
public SeedPlantEvent(@Nullable Player who, Location seedLoc, Crop crop) {
|
|
||||||
this.player = who;
|
|
||||||
this.cancelled = false;
|
|
||||||
this.seedLoc = seedLoc;
|
|
||||||
this.crop = crop;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isCancelled() {
|
|
||||||
return cancelled;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setCancelled(boolean cancel) {
|
|
||||||
this.cancelled = cancel;
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
public static HandlerList getHandlerList() {
|
|
||||||
return handlers;
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
@Override
|
|
||||||
public HandlerList getHandlers() {
|
|
||||||
return getHandlerList();
|
|
||||||
}
|
|
||||||
|
|
||||||
public Location getSeedLoc() {
|
|
||||||
return seedLoc;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Crop getCrop() {
|
|
||||||
return crop;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* return null if this is not triggered by a player
|
|
||||||
*/
|
|
||||||
@Nullable
|
|
||||||
public Player getPlayer() {
|
|
||||||
return player;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,64 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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.entity.Player;
|
|
||||||
import org.bukkit.event.Cancellable;
|
|
||||||
import org.bukkit.event.HandlerList;
|
|
||||||
import org.bukkit.event.player.PlayerEvent;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
|
|
||||||
public class SprinklerPlaceEvent extends PlayerEvent implements Cancellable {
|
|
||||||
|
|
||||||
private static final HandlerList handlers = new HandlerList();
|
|
||||||
private boolean cancelled;
|
|
||||||
private final Location location;
|
|
||||||
|
|
||||||
public SprinklerPlaceEvent(@NotNull Player who, Location location) {
|
|
||||||
super(who);
|
|
||||||
this.cancelled = false;
|
|
||||||
this.location = location;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isCancelled() {
|
|
||||||
return cancelled;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setCancelled(boolean cancel) {
|
|
||||||
this.cancelled = cancel;
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
public static HandlerList getHandlerList() {
|
|
||||||
return handlers;
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
@Override
|
|
||||||
public HandlerList getHandlers() {
|
|
||||||
return getHandlerList();
|
|
||||||
}
|
|
||||||
|
|
||||||
public Location getLocation() {
|
|
||||||
return location;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,73 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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 net.momirealms.customcrops.objects.fertilizer.Fertilizer;
|
|
||||||
import org.bukkit.Location;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.event.Cancellable;
|
|
||||||
import org.bukkit.event.HandlerList;
|
|
||||||
import org.bukkit.event.player.PlayerEvent;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
import org.jetbrains.annotations.Nullable;
|
|
||||||
|
|
||||||
public class SurveyorUseEvent extends PlayerEvent implements Cancellable {
|
|
||||||
|
|
||||||
private static final HandlerList handlers = new HandlerList();
|
|
||||||
private boolean cancelled;
|
|
||||||
private final Fertilizer fertilizer;
|
|
||||||
private final Location potLoc;
|
|
||||||
|
|
||||||
public SurveyorUseEvent(@NotNull Player who, @Nullable Fertilizer fertilizer, Location potLoc) {
|
|
||||||
super(who);
|
|
||||||
this.cancelled = false;
|
|
||||||
this.fertilizer = fertilizer;
|
|
||||||
this.potLoc = potLoc;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isCancelled() {
|
|
||||||
return cancelled;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setCancelled(boolean cancel) {
|
|
||||||
this.cancelled = cancel;
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
public static HandlerList getHandlerList() {
|
|
||||||
return handlers;
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
@Override
|
|
||||||
public HandlerList getHandlers() {
|
|
||||||
return getHandlerList();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Nullable
|
|
||||||
public Fertilizer getFertilizer() {
|
|
||||||
return fertilizer;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Location getPotLoc() {
|
|
||||||
return potLoc;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,45 +0,0 @@
|
|||||||
package net.momirealms.customcrops.api.event;
|
|
||||||
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.event.Cancellable;
|
|
||||||
import org.bukkit.event.HandlerList;
|
|
||||||
import org.bukkit.event.player.PlayerEvent;
|
|
||||||
import org.bukkit.inventory.ItemStack;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
|
|
||||||
public class WaterBucketFillSprinklerEvent extends PlayerEvent implements Cancellable {
|
|
||||||
|
|
||||||
private final ItemStack itemStack;
|
|
||||||
private boolean cancelled;
|
|
||||||
private static final HandlerList handlers = new HandlerList();
|
|
||||||
|
|
||||||
public WaterBucketFillSprinklerEvent(@NotNull Player who, ItemStack itemStack) {
|
|
||||||
super(who);
|
|
||||||
this.itemStack = itemStack;
|
|
||||||
this.cancelled = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isCancelled() {
|
|
||||||
return cancelled;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setCancelled(boolean cancel) {
|
|
||||||
cancelled = cancel;
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
public static HandlerList getHandlerList() {
|
|
||||||
return handlers;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public @NotNull HandlerList getHandlers() {
|
|
||||||
return handlers;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ItemStack getItemStack() {
|
|
||||||
return itemStack;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,63 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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 de.tr7zw.changeme.nbtapi.NBTItem;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.event.Cancellable;
|
|
||||||
import org.bukkit.event.HandlerList;
|
|
||||||
import org.bukkit.event.player.PlayerEvent;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
|
|
||||||
public class WaterCanFillSprinklerEvent extends PlayerEvent implements Cancellable {
|
|
||||||
|
|
||||||
private static final HandlerList handlers = new HandlerList();
|
|
||||||
private boolean cancelled;
|
|
||||||
private final NBTItem nbtItem;
|
|
||||||
|
|
||||||
public WaterCanFillSprinklerEvent(@NotNull Player who, NBTItem nbtItem) {
|
|
||||||
super(who);
|
|
||||||
this.cancelled = false;
|
|
||||||
this.nbtItem = nbtItem;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isCancelled() {
|
|
||||||
return cancelled;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setCancelled(boolean cancel) {
|
|
||||||
this.cancelled = cancel;
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
public static HandlerList getHandlerList() {
|
|
||||||
return handlers;
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
@Override
|
|
||||||
public HandlerList getHandlers() {
|
|
||||||
return getHandlerList();
|
|
||||||
}
|
|
||||||
|
|
||||||
public NBTItem getNbtItem() {
|
|
||||||
return nbtItem;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,83 +1,4 @@
|
|||||||
/*
|
|
||||||
* 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;
|
package net.momirealms.customcrops.api.event;
|
||||||
|
|
||||||
import org.bukkit.Location;
|
public class WaterPotEvent {
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.event.Cancellable;
|
|
||||||
import org.bukkit.event.HandlerList;
|
|
||||||
import org.bukkit.event.player.PlayerEvent;
|
|
||||||
import org.bukkit.inventory.ItemStack;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
|
|
||||||
public class WaterPotEvent extends PlayerEvent implements Cancellable {
|
|
||||||
|
|
||||||
private static final HandlerList handlers = new HandlerList();
|
|
||||||
private boolean cancelled;
|
|
||||||
private final ItemStack itemStack;
|
|
||||||
private int currentWater;
|
|
||||||
private final Location location;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* ItemStack can be a water-bucket or a watering-can
|
|
||||||
*/
|
|
||||||
public WaterPotEvent(@NotNull Player who, Location location, ItemStack itemStack, int currentWater) {
|
|
||||||
super(who);
|
|
||||||
this.cancelled = false;
|
|
||||||
this.itemStack = itemStack;
|
|
||||||
this.currentWater = currentWater;
|
|
||||||
this.location = location;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isCancelled() {
|
|
||||||
return cancelled;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setCancelled(boolean cancel) {
|
|
||||||
this.cancelled = cancel;
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
public static HandlerList getHandlerList() {
|
|
||||||
return handlers;
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
@Override
|
|
||||||
public HandlerList getHandlers() {
|
|
||||||
return getHandlerList();
|
|
||||||
}
|
|
||||||
|
|
||||||
public ItemStack getItemStack() {
|
|
||||||
return itemStack;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getCurrentWater() {
|
|
||||||
return currentWater;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setCurrentWater(int currentWater) {
|
|
||||||
this.currentWater = currentWater;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Location getLocation() {
|
|
||||||
return location;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,73 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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 de.tr7zw.changeme.nbtapi.NBTItem;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.event.Cancellable;
|
|
||||||
import org.bukkit.event.HandlerList;
|
|
||||||
import org.bukkit.event.player.PlayerEvent;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
|
|
||||||
public class WateringCanFillEvent extends PlayerEvent implements Cancellable {
|
|
||||||
|
|
||||||
private static final HandlerList handlers = new HandlerList();
|
|
||||||
private boolean cancelled;
|
|
||||||
private final NBTItem nbtItem;
|
|
||||||
private int currentWater;
|
|
||||||
|
|
||||||
public WateringCanFillEvent(@NotNull Player who, NBTItem nbtItem, int currentWater) {
|
|
||||||
super(who);
|
|
||||||
this.cancelled = false;
|
|
||||||
this.nbtItem = nbtItem;
|
|
||||||
this.currentWater = currentWater;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isCancelled() {
|
|
||||||
return cancelled;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setCancelled(boolean cancel) {
|
|
||||||
this.cancelled = cancel;
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
public static HandlerList getHandlerList() {
|
|
||||||
return handlers;
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
@Override
|
|
||||||
public HandlerList getHandlers() {
|
|
||||||
return getHandlerList();
|
|
||||||
}
|
|
||||||
|
|
||||||
public NBTItem getNbtItem() {
|
|
||||||
return nbtItem;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getCurrentWater() {
|
|
||||||
return currentWater;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setCurrentWater(int currentWater) {
|
|
||||||
this.currentWater = currentWater;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,55 @@
|
|||||||
|
package net.momirealms.customcrops.api.object;
|
||||||
|
|
||||||
|
import net.kyori.adventure.sound.Sound;
|
||||||
|
import net.momirealms.customcrops.CustomCrops;
|
||||||
|
import org.bukkit.Particle;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
public class BoneMeal {
|
||||||
|
|
||||||
|
private final String item;
|
||||||
|
private final String returned;
|
||||||
|
private final ArrayList<Pair<Double, Integer>> pairs;
|
||||||
|
private final Sound sound;
|
||||||
|
private final Particle particle;
|
||||||
|
|
||||||
|
public BoneMeal(String item, @Nullable String returned, @NotNull ArrayList<Pair<Double, Integer>> pairs, @Nullable Sound sound, @Nullable Particle particle) {
|
||||||
|
this.item = item;
|
||||||
|
this.returned = returned;
|
||||||
|
this.pairs = pairs;
|
||||||
|
this.sound = sound;
|
||||||
|
this.particle = particle;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isRightItem(String id) {
|
||||||
|
return item.equals(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ItemStack getReturned() {
|
||||||
|
if (returned == null) return null;
|
||||||
|
return CustomCrops.getInstance().getIntegrationManager().build(returned);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getPoint() {
|
||||||
|
for (Pair<Double, Integer> pair : pairs) {
|
||||||
|
if (Math.random() < pair.left()) {
|
||||||
|
return pair.right();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public Sound getSound() {
|
||||||
|
return sound;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public Particle getParticle() {
|
||||||
|
return particle;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -15,13 +15,14 @@
|
|||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package net.momirealms.customcrops.managers.timer;
|
package net.momirealms.customcrops.api.object;
|
||||||
|
|
||||||
|
import com.willfp.eco.core.items.Items;
|
||||||
import net.momirealms.customcrops.CustomCrops;
|
import net.momirealms.customcrops.CustomCrops;
|
||||||
import net.momirealms.customcrops.config.BasicItemConfig;
|
import net.momirealms.customcrops.api.util.ArmorStandUtils;
|
||||||
import net.momirealms.customcrops.utils.ArmorStandUtil;
|
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.bukkit.scheduler.BukkitRunnable;
|
import org.bukkit.scheduler.BukkitRunnable;
|
||||||
import org.bukkit.util.Vector;
|
import org.bukkit.util.Vector;
|
||||||
|
|
||||||
@@ -31,46 +32,44 @@ public class CrowTask extends BukkitRunnable {
|
|||||||
|
|
||||||
private int timer;
|
private int timer;
|
||||||
private final int entityID;
|
private final int entityID;
|
||||||
private final ArmorStandUtil armorStandUtil;
|
|
||||||
private final Vector vectorDown;
|
private final Vector vectorDown;
|
||||||
private final Vector vectorUp;
|
private final Vector vectorUp;
|
||||||
private final Location from;
|
private final Location from;
|
||||||
private final Player player;
|
private final Player player;
|
||||||
private final float yaw;
|
private final float yaw;
|
||||||
|
private final ItemStack fly;
|
||||||
|
private final ItemStack stand;
|
||||||
|
|
||||||
|
public CrowTask(Player player, Location crop, String fly_model, String stand_model) {
|
||||||
public CrowTask(Player player, Location crop, ArmorStandUtil armorStandUtil) {
|
|
||||||
this.timer = 0;
|
this.timer = 0;
|
||||||
|
this.fly = CustomCrops.getInstance().getIntegrationManager().build(fly_model);
|
||||||
|
this.stand = CustomCrops.getInstance().getIntegrationManager().build(stand_model);
|
||||||
this.player = player;
|
this.player = player;
|
||||||
this.armorStandUtil = armorStandUtil;
|
|
||||||
this.entityID = new Random().nextInt(10000000);
|
this.entityID = new Random().nextInt(10000000);
|
||||||
this.yaw = new Random().nextInt(361) - 180;
|
this.yaw = new Random().nextInt(361) - 180;
|
||||||
this.from = crop.clone().add(10 * Math.sin((Math.PI * yaw)/180), 10, - 10 * Math.cos((Math.PI * yaw)/180));
|
this.from = crop.clone().add(10 * Math.sin((Math.PI * yaw)/180), 10, - 10 * Math.cos((Math.PI * yaw)/180));
|
||||||
Location relative = crop.clone().subtract(from);
|
Location relative = crop.clone().subtract(from);
|
||||||
this.vectorDown = new Vector(relative.getX() / 100, -0.1, relative.getZ() / 100);
|
this.vectorDown = new Vector(relative.getX() / 100, -0.1, relative.getZ() / 100);
|
||||||
this.vectorUp = new Vector(relative.getX() / 100, 0.1, relative.getZ() / 100);
|
this.vectorUp = new Vector(relative.getX() / 100, 0.1, relative.getZ() / 100);
|
||||||
CustomCrops.protocolManager.sendServerPacket(player, armorStandUtil.getSpawnPacket(entityID, from));
|
CustomCrops.getProtocolManager().sendServerPacket(player, ArmorStandUtils.getSpawnPacket(entityID, from));
|
||||||
CustomCrops.protocolManager.sendServerPacket(player, armorStandUtil.getMetaPacket(entityID));
|
CustomCrops.getProtocolManager().sendServerPacket(player, ArmorStandUtils.getMetaPacket(entityID));
|
||||||
CustomCrops.protocolManager.sendServerPacket(player, armorStandUtil.getEquipPacket(entityID, armorStandUtil.getCropManager().getCustomInterface().getItemStack(BasicItemConfig.crowFly)));
|
CustomCrops.getProtocolManager().sendServerPacket(player, ArmorStandUtils.getEquipPacket(entityID, fly));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
timer++;
|
timer++;
|
||||||
if (timer < 100) {
|
if (timer < 100) {
|
||||||
CustomCrops.protocolManager.sendServerPacket(player, armorStandUtil.getTeleportPacket(entityID, from.add(vectorDown), yaw));
|
CustomCrops.getProtocolManager().sendServerPacket(player, ArmorStandUtils.getTeleportPacket(entityID, from.add(vectorDown), yaw));
|
||||||
}
|
} else if (timer == 100){
|
||||||
else if (timer == 100){
|
CustomCrops.getProtocolManager().sendServerPacket(player, ArmorStandUtils.getEquipPacket(entityID, stand));
|
||||||
CustomCrops.protocolManager.sendServerPacket(player, armorStandUtil.getEquipPacket(entityID, armorStandUtil.getCropManager().getCustomInterface().getItemStack(BasicItemConfig.crowLand)));
|
} else if (timer == 150) {
|
||||||
}
|
CustomCrops.getProtocolManager().sendServerPacket(player, ArmorStandUtils.getEquipPacket(entityID, fly));
|
||||||
else if (timer == 150) {
|
} else if (timer > 150) {
|
||||||
CustomCrops.protocolManager.sendServerPacket(player, armorStandUtil.getEquipPacket(entityID, armorStandUtil.getCropManager().getCustomInterface().getItemStack(BasicItemConfig.crowFly)));
|
CustomCrops.getProtocolManager().sendServerPacket(player, ArmorStandUtils.getTeleportPacket(entityID, from.add(vectorUp), yaw));
|
||||||
}
|
|
||||||
else if (timer > 150) {
|
|
||||||
CustomCrops.protocolManager.sendServerPacket(player, armorStandUtil.getTeleportPacket(entityID, from.add(vectorUp), yaw));
|
|
||||||
}
|
}
|
||||||
if (timer > 300) {
|
if (timer > 300) {
|
||||||
CustomCrops.protocolManager.sendServerPacket(player, armorStandUtil.getDestroyPacket(entityID));
|
CustomCrops.getProtocolManager().sendServerPacket(player, ArmorStandUtils.getDestroyPacket(entityID));
|
||||||
cancel();
|
cancel();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
package net.momirealms.customcrops.api.object;
|
||||||
|
|
||||||
|
public class Function {
|
||||||
|
|
||||||
|
public void load() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void unload() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void disable() {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,42 @@
|
|||||||
|
package net.momirealms.customcrops.api.object;
|
||||||
|
|
||||||
|
import net.kyori.adventure.sound.Sound;
|
||||||
|
import net.momirealms.customcrops.CustomCrops;
|
||||||
|
import net.momirealms.customcrops.api.object.action.Action;
|
||||||
|
import org.bukkit.Particle;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
public class InteractWithItem {
|
||||||
|
|
||||||
|
private final boolean consume;
|
||||||
|
private final String id;
|
||||||
|
private final String returned;
|
||||||
|
private final Action[] actions;
|
||||||
|
|
||||||
|
public InteractWithItem(@NotNull String id, boolean consume, @Nullable String returned, @Nullable Action[] actions) {
|
||||||
|
this.consume = consume;
|
||||||
|
this.id = id;
|
||||||
|
this.returned = returned;
|
||||||
|
this.actions = actions;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isRightItem(String item) {
|
||||||
|
return item.equals(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public ItemStack getReturned() {
|
||||||
|
if (returned == null) return null;
|
||||||
|
return CustomCrops.getInstance().getIntegrationManager().build(returned);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isConsumed() {
|
||||||
|
return consume;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Action[] getActions() {
|
||||||
|
return actions;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
package net.momirealms.customcrops.api.object;
|
||||||
|
|
||||||
|
public enum ItemMode {
|
||||||
|
|
||||||
|
TRIPWIRE,
|
||||||
|
ITEM_FRAME,
|
||||||
|
ITEM_DISPLAY,
|
||||||
|
CHORUS
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
package net.momirealms.customcrops.api.object;
|
||||||
|
|
||||||
|
public enum ItemType {
|
||||||
|
|
||||||
|
GLASS,
|
||||||
|
POT,
|
||||||
|
CROP,
|
||||||
|
SPRINKLER,
|
||||||
|
SCARECROW,
|
||||||
|
WATERINGCAN, UNKNOWN
|
||||||
|
}
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
package net.momirealms.customcrops.api.object;
|
||||||
|
|
||||||
|
public record Pair<L, R>(L left, R right) {
|
||||||
|
|
||||||
|
public static <L, R> Pair<L, R> of(final L left, final R right) {
|
||||||
|
return new Pair<>(left, right);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -15,14 +15,15 @@
|
|||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package net.momirealms.customcrops.integrations;
|
package net.momirealms.customcrops.api.object.action;
|
||||||
|
|
||||||
|
import net.momirealms.customcrops.api.object.ItemMode;
|
||||||
|
import net.momirealms.customcrops.api.object.world.SimpleLocation;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
public interface SkillInterface {
|
public interface Action {
|
||||||
|
|
||||||
void addXp(Player player, double amount);
|
void doOn(@Nullable Player player, @Nullable SimpleLocation crop_loc, ItemMode itemMode);
|
||||||
|
|
||||||
int getLevel(Player player);
|
}
|
||||||
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,42 @@
|
|||||||
|
package net.momirealms.customcrops.api.object.action;
|
||||||
|
|
||||||
|
import net.momirealms.customcrops.CustomCrops;
|
||||||
|
import net.momirealms.customcrops.api.CustomCropsAPI;
|
||||||
|
import net.momirealms.customcrops.api.object.ItemMode;
|
||||||
|
import net.momirealms.customcrops.api.object.crop.StageConfig;
|
||||||
|
import net.momirealms.customcrops.api.object.world.SimpleLocation;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
public class BreakImpl implements Action {
|
||||||
|
|
||||||
|
private final boolean triggerAction;
|
||||||
|
private final String stage_id;
|
||||||
|
|
||||||
|
public BreakImpl(boolean triggerAction, @Nullable String stage_id) {
|
||||||
|
this.triggerAction = triggerAction;
|
||||||
|
this.stage_id = stage_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void doOn(@Nullable Player player, @Nullable SimpleLocation crop_loc, ItemMode itemMode) {
|
||||||
|
if (crop_loc == null) return;
|
||||||
|
Bukkit.getScheduler().callSyncMethod(CustomCrops.getInstance(), () -> {
|
||||||
|
CustomCropsAPI.getInstance().removeCustomItem(crop_loc.getBukkitLocation(), itemMode);
|
||||||
|
CustomCrops.getInstance().getWorldDataManager().removeCropData(crop_loc);
|
||||||
|
return null;
|
||||||
|
});
|
||||||
|
if (triggerAction && stage_id != null) {
|
||||||
|
StageConfig stageConfig = CustomCrops.getInstance().getCropManager().getStageConfig(stage_id);
|
||||||
|
if (stageConfig != null) {
|
||||||
|
Action[] actions = stageConfig.getBreakActions();
|
||||||
|
if (actions != null) {
|
||||||
|
for (Action action : actions) {
|
||||||
|
action.doOn(player, crop_loc, itemMode);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
package net.momirealms.customcrops.api.object.action;
|
||||||
|
|
||||||
|
import net.momirealms.customcrops.api.object.ItemMode;
|
||||||
|
import net.momirealms.customcrops.api.object.world.SimpleLocation;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
public class ChainImpl implements Action {
|
||||||
|
|
||||||
|
private final Action[] actions;
|
||||||
|
private final double chance;
|
||||||
|
|
||||||
|
public ChainImpl(Action[] actions, double chance) {
|
||||||
|
this.actions = actions;
|
||||||
|
this.chance = chance;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void doOn(@Nullable Player player, @Nullable SimpleLocation crop_loc, ItemMode itemMode) {
|
||||||
|
if (Math.random() < chance) {
|
||||||
|
for (Action action : actions) {
|
||||||
|
action.doOn(player, crop_loc, itemMode);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,41 @@
|
|||||||
|
/*
|
||||||
|
* 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.object.action;
|
||||||
|
|
||||||
|
import net.momirealms.customcrops.api.object.ItemMode;
|
||||||
|
import net.momirealms.customcrops.api.object.world.SimpleLocation;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
public record CommandActionImpl(String[] commands, double chance) implements Action {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void doOn(@Nullable Player player, @Nullable SimpleLocation crop_loc, ItemMode itemMode) {
|
||||||
|
if (player == null || Math.random() > chance) return;
|
||||||
|
for (String command : commands) {
|
||||||
|
Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(),
|
||||||
|
command.replace("{player}", player.getName())
|
||||||
|
.replace("{x}", crop_loc == null ? "" : String.valueOf(crop_loc.getX()))
|
||||||
|
.replace("{y}", crop_loc == null ? "" : String.valueOf(crop_loc.getY()))
|
||||||
|
.replace("{z}", crop_loc == null ? "" : String.valueOf(crop_loc.getZ()))
|
||||||
|
.replace("{world}", player.getWorld().getName())
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
package net.momirealms.customcrops.api.object.action;
|
||||||
|
|
||||||
|
import net.momirealms.customcrops.api.object.ItemMode;
|
||||||
|
import net.momirealms.customcrops.api.object.loot.Loot;
|
||||||
|
import net.momirealms.customcrops.api.object.world.SimpleLocation;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
public record DropItemImpl(Loot[] loots) implements Action {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void doOn(@Nullable Player player, @Nullable SimpleLocation crop_loc, ItemMode itemMode) {
|
||||||
|
if (crop_loc == null) return;
|
||||||
|
for (Loot loot : loots) {
|
||||||
|
loot.drop(player, crop_loc.getBukkitLocation());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
package net.momirealms.customcrops.api.object.action;
|
||||||
|
|
||||||
|
import net.momirealms.customcrops.CustomCrops;
|
||||||
|
import net.momirealms.customcrops.api.object.ItemMode;
|
||||||
|
import net.momirealms.customcrops.api.object.world.SimpleLocation;
|
||||||
|
import net.momirealms.customcrops.integration.JobInterface;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
public record JobXPImpl(double amount, double chance) implements Action {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void doOn(@Nullable Player player, @Nullable SimpleLocation crop_loc, ItemMode itemMode) {
|
||||||
|
if (player == null || Math.random() > chance) return;
|
||||||
|
JobInterface jobInterface = CustomCrops.getInstance().getIntegrationManager().getJobInterface();
|
||||||
|
if (jobInterface == null) return;
|
||||||
|
jobInterface.addXp(player, amount);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,41 @@
|
|||||||
|
/*
|
||||||
|
* 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.object.action;
|
||||||
|
|
||||||
|
import net.momirealms.customcrops.api.object.ItemMode;
|
||||||
|
import net.momirealms.customcrops.api.object.world.SimpleLocation;
|
||||||
|
import net.momirealms.customcrops.api.util.AdventureUtils;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
public record MessageActionImpl(String[] messages, double chance) implements Action {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void doOn(@Nullable Player player, @Nullable SimpleLocation crop_loc, ItemMode itemMode) {
|
||||||
|
if (player == null || Math.random() > chance) return;
|
||||||
|
for (String message : messages) {
|
||||||
|
AdventureUtils.playerMessage(player,
|
||||||
|
message.replace("{player}", player.getName())
|
||||||
|
.replace("{world}", player.getWorld().getName())
|
||||||
|
.replace("{x}", crop_loc == null ? "" : String.valueOf(crop_loc.getX()))
|
||||||
|
.replace("{y}", crop_loc == null ? "" : String.valueOf(crop_loc.getY()))
|
||||||
|
.replace("{z}", crop_loc == null ? "" : String.valueOf(crop_loc.getZ()))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
package net.momirealms.customcrops.api.object.action;
|
||||||
|
|
||||||
|
import net.momirealms.customcrops.api.object.ItemMode;
|
||||||
|
import net.momirealms.customcrops.api.object.world.SimpleLocation;
|
||||||
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.Particle;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
public class ParticleImpl implements Action {
|
||||||
|
|
||||||
|
private final Particle particle;
|
||||||
|
private final int amount;
|
||||||
|
private final double offset;
|
||||||
|
|
||||||
|
public ParticleImpl(Particle particle, int amount, double offset) {
|
||||||
|
this.particle = particle;
|
||||||
|
this.amount = amount;
|
||||||
|
this.offset = offset;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void doOn(@Nullable Player player, @Nullable SimpleLocation crop_loc, ItemMode itemMode) {
|
||||||
|
if (crop_loc == null) return;
|
||||||
|
Location location = crop_loc.getBukkitLocation();
|
||||||
|
if (location == null) return;
|
||||||
|
location.getWorld().spawnParticle(particle, location.clone().add(0.5,0.5,0.5), amount, offset, offset, offset);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
/*
|
||||||
|
* 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.object.action;
|
||||||
|
|
||||||
|
import net.momirealms.customcrops.api.object.ItemMode;
|
||||||
|
import net.momirealms.customcrops.api.object.world.SimpleLocation;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.potion.PotionEffect;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
public record PotionEffectImpl(PotionEffect potionEffect, double chance) implements Action {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void doOn(@Nullable Player player, @Nullable SimpleLocation crop_loc, ItemMode itemMode) {
|
||||||
|
if (player == null || Math.random() > chance) return;
|
||||||
|
player.addPotionEffect(potionEffect);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,49 @@
|
|||||||
|
package net.momirealms.customcrops.api.object.action;
|
||||||
|
|
||||||
|
import net.momirealms.customcrops.CustomCrops;
|
||||||
|
import net.momirealms.customcrops.api.CustomCropsAPI;
|
||||||
|
import net.momirealms.customcrops.api.object.basic.ConfigManager;
|
||||||
|
import net.momirealms.customcrops.api.object.basic.MessageManager;
|
||||||
|
import net.momirealms.customcrops.api.object.crop.CropConfig;
|
||||||
|
import net.momirealms.customcrops.api.object.ItemMode;
|
||||||
|
import net.momirealms.customcrops.api.object.crop.GrowingCrop;
|
||||||
|
import net.momirealms.customcrops.api.object.world.SimpleLocation;
|
||||||
|
import net.momirealms.customcrops.api.util.AdventureUtils;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
public class ReplantImpl implements Action {
|
||||||
|
|
||||||
|
private final int point;
|
||||||
|
private final String crop;
|
||||||
|
private final String model;
|
||||||
|
|
||||||
|
public ReplantImpl(int point, String model, String crop) {
|
||||||
|
this.point = point;
|
||||||
|
this.crop = crop;
|
||||||
|
this.model = model;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void doOn(@Nullable Player player, @Nullable SimpleLocation crop_loc, ItemMode itemMode) {
|
||||||
|
CropConfig cropConfig = CustomCrops.getInstance().getCropManager().getCropConfigByID(crop);
|
||||||
|
if (crop_loc != null && cropConfig != null) {
|
||||||
|
ItemMode newCMode = cropConfig.getCropMode();
|
||||||
|
Bukkit.getScheduler().callSyncMethod(CustomCrops.getInstance(), () -> {
|
||||||
|
Location location = crop_loc.getBukkitLocation();
|
||||||
|
if (location == null) return null;
|
||||||
|
if (ConfigManager.enableLimitation && CustomCrops.getInstance().getWorldDataManager().getChunkCropAmount(crop_loc) >= ConfigManager.maxCropPerChunk) {
|
||||||
|
if (player != null)AdventureUtils.playerMessage(player, MessageManager.prefix + MessageManager.reachChunkLimit);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
if (!CustomCrops.getInstance().getPlatformInterface().detectAnyThing(location)) {
|
||||||
|
CustomCropsAPI.getInstance().placeCustomItem(location, model, newCMode);
|
||||||
|
CustomCrops.getInstance().getWorldDataManager().addCropData(crop_loc, new GrowingCrop(crop, point));
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,36 @@
|
|||||||
|
/*
|
||||||
|
* 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.object.action;
|
||||||
|
|
||||||
|
import net.momirealms.customcrops.CustomCrops;
|
||||||
|
import net.momirealms.customcrops.api.object.ItemMode;
|
||||||
|
import net.momirealms.customcrops.api.object.world.SimpleLocation;
|
||||||
|
import net.momirealms.customcrops.integration.SkillInterface;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
public record SkillXPImpl(double amount, double chance) implements Action {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void doOn(@Nullable Player player, @Nullable SimpleLocation crop_loc, ItemMode itemMode) {
|
||||||
|
if (player == null || Math.random() > chance) return;
|
||||||
|
SkillInterface skillInterface = CustomCrops.getInstance().getIntegrationManager().getSkillInterface();
|
||||||
|
if (skillInterface == null) return;
|
||||||
|
skillInterface.addXp(player, amount);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -15,32 +15,21 @@
|
|||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package net.momirealms.customcrops.objects;
|
package net.momirealms.customcrops.api.object.action;
|
||||||
|
|
||||||
import net.kyori.adventure.key.Key;
|
import net.kyori.adventure.key.Key;
|
||||||
import net.kyori.adventure.sound.Sound;
|
import net.kyori.adventure.sound.Sound;
|
||||||
|
import net.momirealms.customcrops.api.object.ItemMode;
|
||||||
|
import net.momirealms.customcrops.api.object.world.SimpleLocation;
|
||||||
|
import net.momirealms.customcrops.api.util.AdventureUtils;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
public class WrappedSound {
|
public record SoundActionImpl(String source, String sound, float volume, float pitch) implements Action {
|
||||||
|
|
||||||
private final Sound.Source source;
|
@Override
|
||||||
private final Key key;
|
public void doOn(@Nullable Player player, @Nullable SimpleLocation crop_loc, ItemMode itemMode) {
|
||||||
private final boolean enable;
|
if (player == null) return;
|
||||||
|
AdventureUtils.playerSound(player, Sound.Source.valueOf(source.toUpperCase()), Key.key(sound), volume, pitch);
|
||||||
public WrappedSound(Sound.Source source, Key key, boolean enable) {
|
|
||||||
this.source = source;
|
|
||||||
this.key = key;
|
|
||||||
this.enable = enable;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Sound.Source getSource() {
|
|
||||||
return source;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Key getKey() {
|
|
||||||
return key;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isEnable() {
|
|
||||||
return enable;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,49 @@
|
|||||||
|
/*
|
||||||
|
* 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.object.action;
|
||||||
|
|
||||||
|
import net.kyori.adventure.key.Key;
|
||||||
|
import net.kyori.adventure.sound.Sound;
|
||||||
|
import net.momirealms.customcrops.CustomCrops;
|
||||||
|
import net.momirealms.customcrops.api.object.ItemMode;
|
||||||
|
import net.momirealms.customcrops.api.object.world.SimpleLocation;
|
||||||
|
import net.momirealms.customcrops.api.util.AdventureUtils;
|
||||||
|
import org.bukkit.entity.ExperienceOrb;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
public record VanillaXPImpl(int amount, boolean mending, double chance) implements Action {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void doOn(@Nullable Player player, @Nullable SimpleLocation crop_loc, ItemMode itemMode) {
|
||||||
|
if (player == null || Math.random() > chance) return;
|
||||||
|
if (CustomCrops.getInstance().getVersionHelper().isSpigot()) {
|
||||||
|
if (mending) {
|
||||||
|
player.getLocation().getWorld().spawn(player.getLocation(), ExperienceOrb.class, e -> e.setExperience(amount));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
player.giveExp(amount);
|
||||||
|
AdventureUtils.playerSound(player, Sound.Source.PLAYER, Key.key("minecraft:entity.experience_orb.pickup"), 1, 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
player.giveExp(amount, mending);
|
||||||
|
AdventureUtils.playerSound(player, Sound.Source.PLAYER, Key.key("minecraft:entity.experience_orb.pickup"), 1, 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,60 @@
|
|||||||
|
package net.momirealms.customcrops.api.object.action;
|
||||||
|
|
||||||
|
import net.momirealms.customcrops.CustomCrops;
|
||||||
|
import net.momirealms.customcrops.api.CustomCropsAPI;
|
||||||
|
import net.momirealms.customcrops.api.object.ItemMode;
|
||||||
|
import net.momirealms.customcrops.api.object.crop.VariationCrop;
|
||||||
|
import net.momirealms.customcrops.api.object.fertilizer.Variation;
|
||||||
|
import net.momirealms.customcrops.api.object.pot.Pot;
|
||||||
|
import net.momirealms.customcrops.api.object.world.SimpleLocation;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
public record VariationImpl(VariationCrop[] variationCrops) implements Action {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void doOn(@Nullable Player player, @Nullable SimpleLocation crop_loc, ItemMode itemMode) {
|
||||||
|
if (crop_loc == null) return;
|
||||||
|
double bonus = 0;
|
||||||
|
Pot pot = CustomCrops.getInstance().getWorldDataManager().getPotData(crop_loc.add(0,-1,0));
|
||||||
|
if (pot != null && CustomCrops.getInstance().getFertilizerManager().getConfigByFertilizer(pot.getFertilizer()) instanceof Variation variation) {
|
||||||
|
bonus = variation.getChance();
|
||||||
|
}
|
||||||
|
for (VariationCrop variationCrop : variationCrops) {
|
||||||
|
if (Math.random() < variationCrop.getChance() + bonus) {
|
||||||
|
doVariation(crop_loc, itemMode, variationCrop);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean doOn(@Nullable SimpleLocation crop_loc, ItemMode itemMode) {
|
||||||
|
if (crop_loc == null) return false;
|
||||||
|
double bonus = 0;
|
||||||
|
Pot pot = CustomCrops.getInstance().getWorldDataManager().getPotData(crop_loc.add(0,-1,0));
|
||||||
|
if (pot != null && CustomCrops.getInstance().getFertilizerManager().getConfigByFertilizer(pot.getFertilizer()) instanceof Variation variation) {
|
||||||
|
bonus = variation.getChance();
|
||||||
|
}
|
||||||
|
for (VariationCrop variationCrop : variationCrops) {
|
||||||
|
if (Math.random() < variationCrop.getChance() + bonus) {
|
||||||
|
doVariation(crop_loc, itemMode, variationCrop);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void doVariation(@NotNull SimpleLocation crop_loc, ItemMode itemMode, VariationCrop variationCrop) {
|
||||||
|
Bukkit.getScheduler().callSyncMethod(CustomCrops.getInstance(), () -> {
|
||||||
|
Location location = crop_loc.getBukkitLocation();
|
||||||
|
if (CustomCropsAPI.getInstance().removeCustomItem(location, itemMode)) {
|
||||||
|
CustomCropsAPI.getInstance().placeCustomItem(location, variationCrop.getId(), variationCrop.getCropMode());
|
||||||
|
}
|
||||||
|
CustomCrops.getInstance().getWorldDataManager().removeCropData(crop_loc);
|
||||||
|
return null;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,98 @@
|
|||||||
|
package net.momirealms.customcrops.api.object.basic;
|
||||||
|
|
||||||
|
import net.momirealms.customcrops.CustomCrops;
|
||||||
|
import net.momirealms.customcrops.api.object.Function;
|
||||||
|
import net.momirealms.customcrops.api.util.AdventureUtils;
|
||||||
|
import net.momirealms.customcrops.api.util.ConfigUtils;
|
||||||
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
|
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
public class ConfigManager extends Function {
|
||||||
|
|
||||||
|
public static String lang;
|
||||||
|
public static boolean enableBStats;
|
||||||
|
public static boolean checkUpdate;
|
||||||
|
public static boolean enableSkillBonus;
|
||||||
|
public static String bonusFormula;
|
||||||
|
public static int greenhouseRange;
|
||||||
|
public static boolean whiteListWorlds;
|
||||||
|
public static HashSet<String> worldList;
|
||||||
|
public static String worldFolderPath;
|
||||||
|
public static boolean debug;
|
||||||
|
public static String greenhouseBlock;
|
||||||
|
public static String scarecrow;
|
||||||
|
public static boolean enableGreenhouse;
|
||||||
|
public static int pointGainInterval;
|
||||||
|
public static int corePoolSize;
|
||||||
|
public static double[] defaultRatio;
|
||||||
|
public static int maxPoolSize;
|
||||||
|
public static long keepAliveTime;
|
||||||
|
public static int seasonInterval;
|
||||||
|
public static boolean enableSeason;
|
||||||
|
public static boolean rsHook;
|
||||||
|
public static boolean enableScheduleSystem;
|
||||||
|
public static boolean syncSeason;
|
||||||
|
public static boolean autoSeasonChange;
|
||||||
|
public static String referenceWorld;
|
||||||
|
public static boolean enableLimitation;
|
||||||
|
public static int maxCropPerChunk;
|
||||||
|
public static boolean setUpMode;
|
||||||
|
|
||||||
|
private final CustomCrops plugin;
|
||||||
|
|
||||||
|
public ConfigManager(CustomCrops plugin) {
|
||||||
|
this.plugin = plugin;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void load() {
|
||||||
|
this.loadConfig();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void loadConfig() {
|
||||||
|
ConfigUtils.update("config.yml");
|
||||||
|
YamlConfiguration config = ConfigUtils.getConfig("config.yml");
|
||||||
|
enableBStats = config.getBoolean("metrics");
|
||||||
|
lang = config.getString("lang");
|
||||||
|
debug = config.getBoolean("debug");
|
||||||
|
setUpMode = config.getBoolean("set-up-mode", true);
|
||||||
|
loadWorlds(Objects.requireNonNull(config.getConfigurationSection("worlds")));
|
||||||
|
loadScheduleSystem(Objects.requireNonNull(config.getConfigurationSection("schedule-system")));
|
||||||
|
loadMechanic(Objects.requireNonNull(config.getConfigurationSection("mechanics")));
|
||||||
|
loadOtherSetting(Objects.requireNonNull(config.getConfigurationSection("other-settings")));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void loadWorlds(ConfigurationSection section) {
|
||||||
|
worldFolderPath = section.getString("folder", "");
|
||||||
|
whiteListWorlds = section.getString("mode", "whitelist").equalsIgnoreCase("whitelist");
|
||||||
|
worldList = new HashSet<>(section.getStringList("list"));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void loadScheduleSystem(ConfigurationSection section) {
|
||||||
|
enableScheduleSystem = section.getBoolean("enable");
|
||||||
|
pointGainInterval = section.getInt("point-gain-interval", 1000);
|
||||||
|
corePoolSize = section.getInt("thread-pool-settings.corePoolSize", 2);
|
||||||
|
maxPoolSize = section.getInt("thread-pool-settings.maximumPoolSize", 4);
|
||||||
|
keepAliveTime = section.getInt("thread-pool-settings.keepAliveTime", 10);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void loadMechanic(ConfigurationSection section) {
|
||||||
|
defaultRatio = ConfigUtils.getQualityRatio(section.getString("default-quality-ratio", "17/2/1"));
|
||||||
|
enableSeason = section.getBoolean("season.enable", true);
|
||||||
|
syncSeason = section.getBoolean("season.sync-season.enable", false);
|
||||||
|
referenceWorld = section.getString("season.sync-season.reference");
|
||||||
|
autoSeasonChange = section.getBoolean("season.auto-season-change.enable");
|
||||||
|
seasonInterval = section.getInt("season.auto-season-change.duration", 28);
|
||||||
|
enableGreenhouse = section.getBoolean("season.greenhouse.enable", true);
|
||||||
|
greenhouseRange = section.getInt("season.greenhouse.range", 5);
|
||||||
|
greenhouseBlock = section.getString("season.greenhouse.block");
|
||||||
|
}
|
||||||
|
|
||||||
|
private void loadOtherSetting(ConfigurationSection section) {
|
||||||
|
enableSkillBonus = section.getBoolean("skill-bonus.enable", false);
|
||||||
|
bonusFormula = section.getString("skill-bonus.formula");
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,69 @@
|
|||||||
|
package net.momirealms.customcrops.api.object.basic;
|
||||||
|
|
||||||
|
import com.gmail.nossr50.mcmmo.acf.ACFUtil;
|
||||||
|
import net.momirealms.customcrops.CustomCrops;
|
||||||
|
import net.momirealms.customcrops.api.object.Function;
|
||||||
|
import net.momirealms.customcrops.api.util.ConfigUtils;
|
||||||
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
|
||||||
|
public class MessageManager extends Function {
|
||||||
|
|
||||||
|
|
||||||
|
private CustomCrops plugin;
|
||||||
|
|
||||||
|
public static String prefix;
|
||||||
|
public static String reload;
|
||||||
|
public static String unavailableArgs;
|
||||||
|
public static String noConsole;
|
||||||
|
public static String notOnline;
|
||||||
|
public static String lackArgs;
|
||||||
|
public static String nonArgs;
|
||||||
|
public static String beforePlant;
|
||||||
|
public static String unsuitablePot;
|
||||||
|
public static String reachChunkLimit;
|
||||||
|
public static String spring;
|
||||||
|
public static String summer;
|
||||||
|
public static String autumn;
|
||||||
|
public static String winter;
|
||||||
|
public static String noPerm;
|
||||||
|
public static String noSeason;
|
||||||
|
public static String setSeason;
|
||||||
|
public static String setDate;
|
||||||
|
public static String worldNotExist;
|
||||||
|
public static String seasonNotExist;
|
||||||
|
|
||||||
|
public MessageManager(CustomCrops plugin) {
|
||||||
|
this.plugin =plugin;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void load() {
|
||||||
|
this.loadMessage();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void loadMessage() {
|
||||||
|
YamlConfiguration config = ConfigUtils.getConfig("messages" + File.separator + "messages_" + ConfigManager.lang + ".yml");
|
||||||
|
prefix = config.getString("prefix","<gradient:#ff206c:#fdee55>[CustomCrops] </gradient>");
|
||||||
|
reload = config.getString("reload", "<white>Reloaded! Took <green>{time}ms.");
|
||||||
|
unavailableArgs = config.getString("invalid-args", "<white>Invalid arguments.");
|
||||||
|
noConsole = config.getString("no-console", "This command can only be executed by a player.");
|
||||||
|
notOnline = config.getString("not-online", "<white>Player {player} is not online.");
|
||||||
|
lackArgs = config.getString("lack-args", "<white>Arguments are insufficient.");
|
||||||
|
nonArgs = config.getString("not-none-args", "<white>Not a none argument command.");
|
||||||
|
beforePlant = config.getString("before-plant", "<white>This fertilizer can only be used before planting.");
|
||||||
|
unsuitablePot = config.getString("unsuitable-pot", "<white>You can't plant the seed in this pot.");
|
||||||
|
reachChunkLimit = config.getString("reach-crop-limit", "<white>The number of crops has reached the limitation.");
|
||||||
|
noPerm = config.getString("no-perm", "<red>You don't have permission to do that.");
|
||||||
|
spring = config.getString("spring", "Spring");
|
||||||
|
summer = config.getString("summer", "Summer");
|
||||||
|
autumn = config.getString("autumn", "Autumn");
|
||||||
|
winter = config.getString("winter", "Winter");
|
||||||
|
noSeason = config.getString("no-season", "SEASON DISABLED IN THIS WORLD");
|
||||||
|
setSeason = config.getString("set-season", "<white>Successfully set {world}'s season to {season}.");
|
||||||
|
setDate = config.getString("set-date", "<white>Successfully set {world}'s date to {date}.");
|
||||||
|
worldNotExist = config.getString("world-not-exist", "<white>World {world} does not exist.");
|
||||||
|
seasonNotExist = config.getString("season-not-exist", "<white>Season {season} does not exist.");
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
package net.momirealms.customcrops.api.object.condition;
|
||||||
|
|
||||||
|
import net.momirealms.customcrops.api.object.world.SimpleLocation;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class AndCondition implements Condition {
|
||||||
|
|
||||||
|
private final List<Condition> deathConditions;
|
||||||
|
|
||||||
|
public AndCondition(List<Condition> deathConditions) {
|
||||||
|
this.deathConditions = deathConditions;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isMet(SimpleLocation simpleLocation) {
|
||||||
|
for (Condition condition : deathConditions) {
|
||||||
|
if (!condition.isMet(simpleLocation)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
package net.momirealms.customcrops.api.object.condition;
|
||||||
|
|
||||||
|
import net.momirealms.customcrops.api.object.world.SimpleLocation;
|
||||||
|
|
||||||
|
public interface Condition {
|
||||||
|
|
||||||
|
boolean isMet(SimpleLocation simpleLocation);
|
||||||
|
}
|
||||||
@@ -0,0 +1,35 @@
|
|||||||
|
package net.momirealms.customcrops.api.object.condition;
|
||||||
|
|
||||||
|
import net.momirealms.customcrops.CustomCrops;
|
||||||
|
import net.momirealms.customcrops.api.object.CrowTask;
|
||||||
|
import net.momirealms.customcrops.api.object.world.SimpleLocation;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
public class CrowAttack implements Condition {
|
||||||
|
|
||||||
|
private final double chance;
|
||||||
|
private final String fly_model;
|
||||||
|
private final String stand_model;
|
||||||
|
|
||||||
|
public CrowAttack(double chance, String fly_model, String stand_model) {
|
||||||
|
this.chance = chance;
|
||||||
|
this.fly_model = fly_model;
|
||||||
|
this.stand_model = stand_model;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isMet(SimpleLocation simpleLocation) {
|
||||||
|
if (Math.random() > chance) return false;
|
||||||
|
Location location = simpleLocation.getBukkitLocation();
|
||||||
|
if (location == null) return false;
|
||||||
|
Bukkit.getScheduler().runTask(CustomCrops.getInstance(), () -> {
|
||||||
|
for (Player player : location.getNearbyPlayers(48)) {
|
||||||
|
CrowTask crowTask = new CrowTask(player, location.clone().add(0.4,0,0.4), fly_model, stand_model);
|
||||||
|
crowTask.runTaskTimerAsynchronously(CustomCrops.getInstance(), 1, 1);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,42 @@
|
|||||||
|
package net.momirealms.customcrops.api.object.condition;
|
||||||
|
|
||||||
|
import net.momirealms.customcrops.CustomCrops;
|
||||||
|
import net.momirealms.customcrops.api.CustomCropsAPI;
|
||||||
|
import net.momirealms.customcrops.api.object.ItemMode;
|
||||||
|
import net.momirealms.customcrops.api.object.world.SimpleLocation;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.Location;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
public class DeathCondition {
|
||||||
|
|
||||||
|
private final String dead_model;
|
||||||
|
private final Condition[] conditions;
|
||||||
|
|
||||||
|
public DeathCondition(@Nullable String dead_model, @NotNull Condition[] conditions) {
|
||||||
|
this.dead_model = dead_model;
|
||||||
|
this.conditions = conditions;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean checkIfDead(SimpleLocation simpleLocation) {
|
||||||
|
for (Condition condition : conditions) {
|
||||||
|
if (condition.isMet(simpleLocation)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void applyDeadModel(SimpleLocation simpleLocation, ItemMode itemMode) {
|
||||||
|
Location location = simpleLocation.getBukkitLocation();
|
||||||
|
if (location == null) return;
|
||||||
|
Bukkit.getScheduler().callSyncMethod(CustomCrops.getInstance(), () -> {
|
||||||
|
CustomCropsAPI.getInstance().removeCustomItem(location, itemMode);
|
||||||
|
if (dead_model != null) {
|
||||||
|
CustomCropsAPI.getInstance().placeCustomItem(location, dead_model, itemMode);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
package net.momirealms.customcrops.api.object.condition;
|
||||||
|
|
||||||
|
import net.momirealms.customcrops.api.object.world.SimpleLocation;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class OrCondition implements Condition {
|
||||||
|
|
||||||
|
private final List<Condition> deathConditions;
|
||||||
|
|
||||||
|
public OrCondition(List<Condition> deathConditions) {
|
||||||
|
this.deathConditions = deathConditions;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isMet(SimpleLocation simpleLocation) {
|
||||||
|
for (Condition condition : deathConditions) {
|
||||||
|
if (condition.isMet(simpleLocation)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
package net.momirealms.customcrops.api.object.condition;
|
||||||
|
|
||||||
|
import net.momirealms.customcrops.api.object.world.SimpleLocation;
|
||||||
|
|
||||||
|
public class Random implements Condition {
|
||||||
|
|
||||||
|
private final double chance;
|
||||||
|
|
||||||
|
public Random(double chance) {
|
||||||
|
this.chance = chance;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isMet(SimpleLocation simpleLocation) {
|
||||||
|
return Math.random() < chance;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,36 @@
|
|||||||
|
package net.momirealms.customcrops.api.object.condition;
|
||||||
|
|
||||||
|
import net.momirealms.customcrops.CustomCrops;
|
||||||
|
import net.momirealms.customcrops.api.object.basic.ConfigManager;
|
||||||
|
import net.momirealms.customcrops.api.object.season.CCSeason;
|
||||||
|
import net.momirealms.customcrops.api.object.world.SimpleLocation;
|
||||||
|
import net.momirealms.customcrops.api.object.world.WorldDataManager;
|
||||||
|
|
||||||
|
public class RightSeason implements Condition {
|
||||||
|
|
||||||
|
private final CCSeason[] seasons;
|
||||||
|
|
||||||
|
public RightSeason(CCSeason[] seasons) {
|
||||||
|
this.seasons = seasons;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isMet(SimpleLocation simpleLocation) {
|
||||||
|
String world = simpleLocation.getWorldName();
|
||||||
|
CCSeason current = CustomCrops.getInstance().getIntegrationManager().getSeasonInterface().getSeason(world);
|
||||||
|
for (CCSeason allowed : seasons) {
|
||||||
|
if (current == allowed) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
WorldDataManager worldDataManager = CustomCrops.getInstance().getWorldDataManager();
|
||||||
|
if (ConfigManager.enableGreenhouse) {
|
||||||
|
for (int i = 0; i < ConfigManager.greenhouseRange; i++) {
|
||||||
|
if (worldDataManager.isGreenhouse(simpleLocation.add(0, i, 0))) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
package net.momirealms.customcrops.api.object.condition;
|
||||||
|
|
||||||
|
import net.momirealms.customcrops.CustomCrops;
|
||||||
|
import net.momirealms.customcrops.api.object.pot.Pot;
|
||||||
|
import net.momirealms.customcrops.api.object.world.SimpleLocation;
|
||||||
|
|
||||||
|
public class WaterLessThan implements Condition {
|
||||||
|
|
||||||
|
private final int amount;
|
||||||
|
|
||||||
|
public WaterLessThan(int amount) {
|
||||||
|
this.amount = amount;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isMet(SimpleLocation crop_loc) {
|
||||||
|
Pot pot = CustomCrops.getInstance().getWorldDataManager().getPotData(crop_loc.add(0,-1,0));
|
||||||
|
if (pot == null) return true;
|
||||||
|
return pot.getWater() < amount;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
package net.momirealms.customcrops.api.object.condition;
|
||||||
|
|
||||||
|
import net.momirealms.customcrops.CustomCrops;
|
||||||
|
import net.momirealms.customcrops.api.object.pot.Pot;
|
||||||
|
import net.momirealms.customcrops.api.object.world.SimpleLocation;
|
||||||
|
|
||||||
|
public class WaterMoreThan implements Condition {
|
||||||
|
|
||||||
|
private final int amount;
|
||||||
|
|
||||||
|
public WaterMoreThan(int amount) {
|
||||||
|
this.amount = amount;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isMet(SimpleLocation crop_loc) {
|
||||||
|
Pot pot = CustomCrops.getInstance().getWorldDataManager().getPotData(crop_loc.add(0,-1,0));
|
||||||
|
if (pot == null) return false;
|
||||||
|
return pot.getWater() > amount;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,36 @@
|
|||||||
|
package net.momirealms.customcrops.api.object.condition;
|
||||||
|
|
||||||
|
import net.momirealms.customcrops.CustomCrops;
|
||||||
|
import net.momirealms.customcrops.api.object.basic.ConfigManager;
|
||||||
|
import net.momirealms.customcrops.api.object.season.CCSeason;
|
||||||
|
import net.momirealms.customcrops.api.object.world.SimpleLocation;
|
||||||
|
import net.momirealms.customcrops.api.object.world.WorldDataManager;
|
||||||
|
|
||||||
|
public class WrongSeason implements Condition {
|
||||||
|
|
||||||
|
private final CCSeason[] seasons;
|
||||||
|
|
||||||
|
public WrongSeason(CCSeason[] seasons) {
|
||||||
|
this.seasons = seasons;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isMet(SimpleLocation simpleLocation) {
|
||||||
|
String world = simpleLocation.getWorldName();
|
||||||
|
CCSeason current = CustomCrops.getInstance().getIntegrationManager().getSeasonInterface().getSeason(world);
|
||||||
|
for (CCSeason bad : seasons) {
|
||||||
|
if (current == bad) {
|
||||||
|
WorldDataManager worldDataManager = CustomCrops.getInstance().getWorldDataManager();
|
||||||
|
if (ConfigManager.enableGreenhouse) {
|
||||||
|
for (int i = 0; i < ConfigManager.greenhouseRange; i++) {
|
||||||
|
if (worldDataManager.isGreenhouse(simpleLocation.add(0, i, 0))) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,109 @@
|
|||||||
|
package net.momirealms.customcrops.api.object.crop;
|
||||||
|
|
||||||
|
import net.momirealms.customcrops.api.object.BoneMeal;
|
||||||
|
import net.momirealms.customcrops.api.object.ItemMode;
|
||||||
|
import net.momirealms.customcrops.api.object.action.Action;
|
||||||
|
import net.momirealms.customcrops.api.object.condition.Condition;
|
||||||
|
import net.momirealms.customcrops.api.object.condition.DeathCondition;
|
||||||
|
import net.momirealms.customcrops.api.object.requirement.Requirement;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
|
||||||
|
public class CropConfig {
|
||||||
|
|
||||||
|
private String key;
|
||||||
|
private final ItemMode itemMode;
|
||||||
|
private final String[] bottom_blocks;
|
||||||
|
private final int max_points;
|
||||||
|
private final HashMap<Integer, StageConfig> stageMap;
|
||||||
|
private final Requirement[] plantRequirements;
|
||||||
|
private final Requirement[] breakRequirements;
|
||||||
|
private final DeathCondition[] deathConditions;
|
||||||
|
private final Condition[] growConditions;
|
||||||
|
private final BoneMeal[] boneMeals;
|
||||||
|
private final Action[] plantActions;
|
||||||
|
|
||||||
|
public CropConfig(String key,
|
||||||
|
ItemMode itemMode,
|
||||||
|
int max_points,
|
||||||
|
String[] bottom_blocks,
|
||||||
|
Requirement[] plantRequirements,
|
||||||
|
Requirement[] breakRequirements,
|
||||||
|
DeathCondition[] deathConditions,
|
||||||
|
Condition[] growConditions,
|
||||||
|
HashMap<Integer, StageConfig> stageMap,
|
||||||
|
BoneMeal[] boneMeals,
|
||||||
|
Action[] plantActions
|
||||||
|
) {
|
||||||
|
this.key = key;
|
||||||
|
this.itemMode = itemMode;
|
||||||
|
this.deathConditions = deathConditions;
|
||||||
|
this.plantRequirements = plantRequirements;
|
||||||
|
this.breakRequirements = breakRequirements;
|
||||||
|
this.max_points = max_points;
|
||||||
|
this.bottom_blocks = bottom_blocks;
|
||||||
|
this.stageMap = stageMap;
|
||||||
|
this.growConditions = growConditions;
|
||||||
|
this.boneMeals = boneMeals;
|
||||||
|
this.plantActions = plantActions;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getKey() {
|
||||||
|
return key;
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
public ItemMode getCropMode() {
|
||||||
|
return itemMode;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getMaxPoints() {
|
||||||
|
return max_points;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public StageConfig getStageConfig(int stage) {
|
||||||
|
return stageMap.get(stage);
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
public String[] getBottom_blocks() {
|
||||||
|
return bottom_blocks;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getMax_points() {
|
||||||
|
return max_points;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public Requirement[] getPlantRequirements() {
|
||||||
|
return plantRequirements;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public Requirement[] getBreakRequirements() {
|
||||||
|
return breakRequirements;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public DeathCondition[] getDeathConditions() {
|
||||||
|
return deathConditions;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public Condition[] getGrowConditions() {
|
||||||
|
return growConditions;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public BoneMeal[] getBoneMeals() {
|
||||||
|
return boneMeals;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public Action[] getPlantActions() {
|
||||||
|
return plantActions;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,182 @@
|
|||||||
|
package net.momirealms.customcrops.api.object.crop;
|
||||||
|
|
||||||
|
import net.momirealms.customcrops.CustomCrops;
|
||||||
|
import net.momirealms.customcrops.api.object.Function;
|
||||||
|
import net.momirealms.customcrops.api.object.ItemMode;
|
||||||
|
import net.momirealms.customcrops.api.object.condition.Condition;
|
||||||
|
import net.momirealms.customcrops.api.object.condition.DeathCondition;
|
||||||
|
import net.momirealms.customcrops.api.object.requirement.Requirement;
|
||||||
|
import net.momirealms.customcrops.api.util.AdventureUtils;
|
||||||
|
import net.momirealms.customcrops.api.util.ConfigUtils;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
|
import org.bukkit.entity.Item;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.HandlerList;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
import org.bukkit.event.entity.ItemSpawnEvent;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.HashSet;
|
||||||
|
|
||||||
|
public class CropManager extends Function implements Listener {
|
||||||
|
|
||||||
|
private final CustomCrops plugin;
|
||||||
|
private final HashMap<String, String> stageToCrop;
|
||||||
|
private final HashMap<String, CropConfig> seedToCropConfig;
|
||||||
|
private final HashMap<String, CropConfig> cropConfigMap;
|
||||||
|
private final HashMap<String, StageConfig> stageConfigMap;
|
||||||
|
private final HashSet<String> deadCrops;
|
||||||
|
|
||||||
|
public CropManager(CustomCrops plugin) {
|
||||||
|
this.plugin = plugin;
|
||||||
|
this.stageToCrop = new HashMap<>();
|
||||||
|
this.cropConfigMap = new HashMap<>();
|
||||||
|
this.stageConfigMap = new HashMap<>();
|
||||||
|
this.seedToCropConfig = new HashMap<>();
|
||||||
|
this.deadCrops = new HashSet<>();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void load() {
|
||||||
|
this.loadConfig();
|
||||||
|
Bukkit.getPluginManager().registerEvents(this, plugin);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void unload() {
|
||||||
|
this.stageToCrop.clear();
|
||||||
|
this.cropConfigMap.clear();
|
||||||
|
this.stageConfigMap.clear();
|
||||||
|
this.deadCrops.clear();
|
||||||
|
this.seedToCropConfig.clear();
|
||||||
|
HandlerList.unregisterAll(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void loadConfig() {
|
||||||
|
File crop_folder = new File(plugin.getDataFolder(), "contents" + File.separator + "crops");
|
||||||
|
if (!crop_folder.exists()) {
|
||||||
|
if (!crop_folder.mkdirs()) return;
|
||||||
|
plugin.saveResource("contents" + File.separator + "crops" + File.separator + "tomato.yml", false);
|
||||||
|
}
|
||||||
|
File[] files = crop_folder.listFiles();
|
||||||
|
if (files == null) return;
|
||||||
|
for (File file : files) {
|
||||||
|
YamlConfiguration config = YamlConfiguration.loadConfiguration(file);
|
||||||
|
for (String key : config.getKeys(false)) {
|
||||||
|
ConfigurationSection cropSec = config.getConfigurationSection(key);
|
||||||
|
if (cropSec == null) continue;
|
||||||
|
ItemMode itemMode = ItemMode.valueOf(cropSec.getString("crop-mode", "TripWire").toUpperCase());
|
||||||
|
String[] bottomBlocks = cropSec.getStringList("pot-whitelist").toArray(new String[0]);
|
||||||
|
if (bottomBlocks.length == 0) {
|
||||||
|
AdventureUtils.consoleMessage("<red>[CustomCrops] pot-whitelist is not set for crop: " + key);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
String seed = cropSec.getString("seed");
|
||||||
|
Requirement[] breakReq = ConfigUtils.getRequirementsWithMsg(cropSec.getConfigurationSection("requirements.break"));
|
||||||
|
Requirement[] plantReq = ConfigUtils.getRequirementsWithMsg(cropSec.getConfigurationSection("requirements.plant"));
|
||||||
|
|
||||||
|
int max = cropSec.getInt("max-points", 0);
|
||||||
|
ConfigurationSection pointSec = cropSec.getConfigurationSection("points");
|
||||||
|
if (pointSec == null || max == 0) {
|
||||||
|
AdventureUtils.consoleMessage("<red>[CustomCrops] Points are not set for crop: " + key);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
HashMap<Integer, StageConfig> stageMap = new HashMap<>();
|
||||||
|
for (String point : pointSec.getKeys(false)) {
|
||||||
|
try {
|
||||||
|
int parsed = Integer.parseInt(point);
|
||||||
|
String stageModel = pointSec.getString(point + ".model");
|
||||||
|
StageConfig stageConfig = new StageConfig(
|
||||||
|
stageModel,
|
||||||
|
ConfigUtils.getActions(pointSec.getConfigurationSection(point + ".events.break"), stageModel),
|
||||||
|
ConfigUtils.getActions(pointSec.getConfigurationSection(point + ".events.grow"), stageModel),
|
||||||
|
ConfigUtils.getInteractActions(pointSec.getConfigurationSection(point + ".events.interact-with-item"), stageModel),
|
||||||
|
ConfigUtils.getActions(pointSec.getConfigurationSection(point + ".events.interact-by-hand"), stageModel)
|
||||||
|
);
|
||||||
|
stageMap.put(parsed, stageConfig);
|
||||||
|
if (stageModel != null) {
|
||||||
|
stageToCrop.put(stageModel, key);
|
||||||
|
stageConfigMap.put(stageModel, stageConfig);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (NumberFormatException e) {
|
||||||
|
AdventureUtils.consoleMessage("<red>[CustomCrops] Unexpected point value: " + point);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
DeathCondition[] deathConditions = ConfigUtils.getDeathConditions(cropSec.getConfigurationSection("death-conditions"));
|
||||||
|
Condition[] growConditions = ConfigUtils.getConditions(cropSec.getConfigurationSection("grow-conditions"));
|
||||||
|
CropConfig cropConfig = new CropConfig(
|
||||||
|
key,
|
||||||
|
itemMode,
|
||||||
|
max,
|
||||||
|
bottomBlocks,
|
||||||
|
plantReq,
|
||||||
|
breakReq,
|
||||||
|
deathConditions,
|
||||||
|
growConditions,
|
||||||
|
stageMap,
|
||||||
|
ConfigUtils.getBoneMeals(cropSec.getConfigurationSection("custom-bone-meal")),
|
||||||
|
ConfigUtils.getActions(cropSec.getConfigurationSection("plant-actions"), null)
|
||||||
|
);
|
||||||
|
cropConfigMap.put(key, cropConfig);
|
||||||
|
if (seed != null) seedToCropConfig.put(seed, cropConfig);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
AdventureUtils.consoleMessage("[CustomCrops] Loaded <green>" + cropConfigMap.size() + " <gray>crop(s)");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public StageConfig getStageConfig(String stage_id) {
|
||||||
|
return stageConfigMap.get(stage_id);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public CropConfig getCropConfigByID(String id) {
|
||||||
|
return this.cropConfigMap.get(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public CropConfig getCropConfigByStage(String stage_id) {
|
||||||
|
String key = getCropConfigID(stage_id);
|
||||||
|
if (key == null) return null;
|
||||||
|
return this.cropConfigMap.get(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public String getCropConfigID(String stage_id) {
|
||||||
|
return this.stageToCrop.get(stage_id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isDeadCrop(String id) {
|
||||||
|
return deadCrops.contains(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean containsStage(String stage_id) {
|
||||||
|
return stageToCrop.containsKey(stage_id);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Prevent players from getting stage model
|
||||||
|
@EventHandler
|
||||||
|
public void onItemSpawn(ItemSpawnEvent event) {
|
||||||
|
if (event.isCancelled()) return;
|
||||||
|
Item item = event.getEntity();
|
||||||
|
String id = plugin.getPlatformInterface().getItemID(item.getItemStack());
|
||||||
|
if (containsStage(id)) {
|
||||||
|
event.setCancelled(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void registerDeadCrops(String id) {
|
||||||
|
this.deadCrops.add(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public CropConfig getCropConfigBySeed(String seed) {
|
||||||
|
return seedToCropConfig.get(seed);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
package net.momirealms.customcrops.api.object.crop;
|
||||||
|
|
||||||
|
import net.momirealms.customcrops.CustomCrops;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
public class GrowingCrop implements Serializable {
|
||||||
|
|
||||||
|
private int points;
|
||||||
|
private final String crop;
|
||||||
|
|
||||||
|
public GrowingCrop(String crop, int points) {
|
||||||
|
this.points = points;
|
||||||
|
this.crop = crop;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getPoints() {
|
||||||
|
return points;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPoints(int points) {
|
||||||
|
this.points = points;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getCropKey() {
|
||||||
|
return crop;
|
||||||
|
}
|
||||||
|
|
||||||
|
public CropConfig getConfig() {
|
||||||
|
return CustomCrops.getInstance().getCropManager().getCropConfigByID(crop);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,47 @@
|
|||||||
|
package net.momirealms.customcrops.api.object.crop;
|
||||||
|
|
||||||
|
import net.momirealms.customcrops.api.object.InteractWithItem;
|
||||||
|
import net.momirealms.customcrops.api.object.action.Action;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
public class StageConfig {
|
||||||
|
|
||||||
|
private final String model;
|
||||||
|
private final Action[] breakActions;
|
||||||
|
private final InteractWithItem[] interactActions;
|
||||||
|
private final Action[] growActions;
|
||||||
|
private final Action[] interactByHandActions;
|
||||||
|
|
||||||
|
public StageConfig(@Nullable String model, @Nullable Action[] breakActions, @Nullable Action[] growActions, @Nullable InteractWithItem[] interactActions, @Nullable Action[] interactByHandActions) {
|
||||||
|
this.breakActions = breakActions;
|
||||||
|
this.interactActions = interactActions;
|
||||||
|
this.growActions = growActions;
|
||||||
|
this.interactByHandActions = interactByHandActions;
|
||||||
|
this.model = model;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public Action[] getBreakActions() {
|
||||||
|
return breakActions;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public InteractWithItem[] getInteractActions() {
|
||||||
|
return interactActions;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public Action[] getGrowActions() {
|
||||||
|
return growActions;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public Action[] getInteractByHandActions() {
|
||||||
|
return interactByHandActions;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public String getModel() {
|
||||||
|
return model;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
package net.momirealms.customcrops.api.object.crop;
|
||||||
|
|
||||||
|
import net.momirealms.customcrops.api.object.ItemMode;
|
||||||
|
|
||||||
|
public class VariationCrop {
|
||||||
|
|
||||||
|
private final String id;
|
||||||
|
private final ItemMode itemMode;
|
||||||
|
private final double chance;
|
||||||
|
|
||||||
|
public VariationCrop(String id, ItemMode itemMode, double chance) {
|
||||||
|
this.id = id;
|
||||||
|
this.itemMode = itemMode;
|
||||||
|
this.chance = chance;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ItemMode getCropMode() {
|
||||||
|
return itemMode;
|
||||||
|
}
|
||||||
|
|
||||||
|
public double getChance() {
|
||||||
|
return chance;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,39 @@
|
|||||||
|
package net.momirealms.customcrops.api.object.fertilizer;
|
||||||
|
|
||||||
|
import net.momirealms.customcrops.CustomCrops;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
public class Fertilizer implements Serializable {
|
||||||
|
|
||||||
|
private final String key;
|
||||||
|
private int times;
|
||||||
|
|
||||||
|
public Fertilizer(String key, int times) {
|
||||||
|
this.key = key;
|
||||||
|
this.times = times;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Fertilizer(FertilizerConfig fertilizerConfig) {
|
||||||
|
this.key = fertilizerConfig.getKey();
|
||||||
|
this.times = fertilizerConfig.getTimes();
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
If fertilizer is used up
|
||||||
|
*/
|
||||||
|
public boolean reduceTimes() {
|
||||||
|
times--;
|
||||||
|
return times <= 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getKey() {
|
||||||
|
return key;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public FertilizerConfig getConfig() {
|
||||||
|
return CustomCrops.getInstance().getFertilizerManager().getConfigByFertilizer(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,84 @@
|
|||||||
|
/*
|
||||||
|
* 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.object.fertilizer;
|
||||||
|
|
||||||
|
import net.kyori.adventure.sound.Sound;
|
||||||
|
import org.bukkit.Particle;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
public abstract class FertilizerConfig {
|
||||||
|
|
||||||
|
protected int times;
|
||||||
|
protected double chance;
|
||||||
|
protected String key;
|
||||||
|
protected FertilizerType fertilizerType;
|
||||||
|
protected String[] pot_whitelist;
|
||||||
|
protected boolean beforePlant;
|
||||||
|
protected Particle particle;
|
||||||
|
protected Sound sound;
|
||||||
|
|
||||||
|
public FertilizerConfig(String key, FertilizerType fertilizerType, int times, double chance, @Nullable String[] pot_whitelist, boolean beforePlant, @Nullable Particle particle, @Nullable Sound sound) {
|
||||||
|
this.times = times;
|
||||||
|
this.chance = chance;
|
||||||
|
this.key = key;
|
||||||
|
this.fertilizerType = fertilizerType;
|
||||||
|
this.pot_whitelist = pot_whitelist;
|
||||||
|
this.beforePlant = beforePlant;
|
||||||
|
this.particle = particle;
|
||||||
|
this.sound = sound;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getTimes() {
|
||||||
|
return times;
|
||||||
|
}
|
||||||
|
|
||||||
|
public double getChance() {
|
||||||
|
return chance;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean canTakeEffect() {
|
||||||
|
return Math.random() < chance;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getKey() {
|
||||||
|
return key;
|
||||||
|
}
|
||||||
|
|
||||||
|
public FertilizerType getFertilizerType() {
|
||||||
|
return fertilizerType;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public String[] getPotWhitelist() {
|
||||||
|
return pot_whitelist;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isBeforePlant() {
|
||||||
|
return beforePlant;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public Particle getParticle() {
|
||||||
|
return particle;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public Sound getSound() {
|
||||||
|
return sound;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,113 @@
|
|||||||
|
package net.momirealms.customcrops.api.object.fertilizer;
|
||||||
|
|
||||||
|
import net.kyori.adventure.key.Key;
|
||||||
|
import net.kyori.adventure.sound.Sound;
|
||||||
|
import net.momirealms.customcrops.CustomCrops;
|
||||||
|
import net.momirealms.customcrops.api.object.Function;
|
||||||
|
import net.momirealms.customcrops.api.object.Pair;
|
||||||
|
import net.momirealms.customcrops.api.util.AdventureUtils;
|
||||||
|
import net.momirealms.customcrops.api.util.ConfigUtils;
|
||||||
|
import org.bukkit.Particle;
|
||||||
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
|
import org.intellij.lang.annotations.Subst;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
|
||||||
|
public class FertilizerManager extends Function {
|
||||||
|
|
||||||
|
private final CustomCrops plugin;
|
||||||
|
private final HashMap<String, FertilizerConfig> fertilizerConfigMap;
|
||||||
|
private final HashMap<String, String> itemToKey;
|
||||||
|
|
||||||
|
public FertilizerManager(CustomCrops plugin) {
|
||||||
|
this.plugin = plugin;
|
||||||
|
this.fertilizerConfigMap = new HashMap<>();
|
||||||
|
this.itemToKey = new HashMap<>();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void load() {
|
||||||
|
this.loadConfig();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void unload() {
|
||||||
|
this.fertilizerConfigMap.clear();
|
||||||
|
this.itemToKey.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public FertilizerConfig getConfigByFertilizer(@Nullable Fertilizer fertilizer) {
|
||||||
|
if (fertilizer == null) return null;
|
||||||
|
return fertilizerConfigMap.get(fertilizer.getKey());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public FertilizerConfig getConfigByKey(String key) {
|
||||||
|
return fertilizerConfigMap.get(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public FertilizerConfig getConfigByItemID(String id) {
|
||||||
|
String key = itemToKey.get(id);
|
||||||
|
if (key == null) return null;
|
||||||
|
return fertilizerConfigMap.get(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void loadConfig() {
|
||||||
|
File can_folder = new File(plugin.getDataFolder(), "contents" + File.separator + "fertilizers");
|
||||||
|
if (!can_folder.exists()) {
|
||||||
|
if (!can_folder.mkdirs()) return;
|
||||||
|
plugin.saveResource("contents" + File.separator + "fertilizers" + File.separator + "speed-grow.yml", false);
|
||||||
|
plugin.saveResource("contents" + File.separator + "fertilizers" + File.separator + "quality.yml", false);
|
||||||
|
plugin.saveResource("contents" + File.separator + "fertilizers" + File.separator + "soil-retain.yml", false);
|
||||||
|
plugin.saveResource("contents" + File.separator + "fertilizers" + File.separator + "yield-increase.yml", false);
|
||||||
|
plugin.saveResource("contents" + File.separator + "fertilizers" + File.separator + "variation.yml", false);
|
||||||
|
}
|
||||||
|
File[] files = can_folder.listFiles();
|
||||||
|
if (files == null) return;
|
||||||
|
for (File file : files) {
|
||||||
|
YamlConfiguration config = YamlConfiguration.loadConfiguration(file);
|
||||||
|
for (String key : config.getKeys(false)) {
|
||||||
|
ConfigurationSection fertilizerSec = config.getConfigurationSection(key);
|
||||||
|
if (fertilizerSec == null) continue;
|
||||||
|
FertilizerConfig fertilizerConfig;
|
||||||
|
FertilizerType fertilizerType = FertilizerType.valueOf(fertilizerSec.getString("type", "SPEED_GROW").toUpperCase());
|
||||||
|
String[] pot_whitelist = fertilizerSec.contains("pot-whitelist") ? fertilizerSec.getStringList("pot-whitelist").toArray(new String[0]) : null;
|
||||||
|
boolean beforePlant = fertilizerSec.getBoolean("before-plant", false);
|
||||||
|
int times = fertilizerSec.getInt("times", 14);
|
||||||
|
Particle particle = fertilizerSec.contains("particle") ? Particle.valueOf(fertilizerSec.getString("particle")) : null;
|
||||||
|
@Subst("namespace:key") String soundKey = fertilizerSec.getString("sound", "minecraft:item.hoe.till");
|
||||||
|
Sound sound = fertilizerSec.contains("sound") ? Sound.sound(Key.key(soundKey), Sound.Source.PLAYER, 1, 1) : null;
|
||||||
|
switch (fertilizerType) {
|
||||||
|
case SPEED_GROW -> fertilizerConfig = new SpeedGrow(key, fertilizerType, times, getChancePair(fertilizerSec), pot_whitelist, beforePlant, particle, sound);
|
||||||
|
case YIELD_INCREASE -> fertilizerConfig = new YieldIncrease(key, fertilizerType, times, fertilizerSec.getDouble("chance"), getChancePair(fertilizerSec), pot_whitelist, beforePlant, particle, sound);
|
||||||
|
case VARIATION -> fertilizerConfig = new Variation(key, fertilizerType, times, fertilizerSec.getDouble("chance"), pot_whitelist, beforePlant, particle, sound);
|
||||||
|
case QUALITY -> fertilizerConfig = new Quality(key, fertilizerType, times, fertilizerSec.getDouble("chance"), ConfigUtils.getQualityRatio(fertilizerSec.getString("ratio", "2/2/1")), pot_whitelist, beforePlant, particle, sound);
|
||||||
|
case SOIL_RETAIN -> fertilizerConfig = new SoilRetain(key, fertilizerType, times, fertilizerSec.getDouble("chance"), pot_whitelist, beforePlant, particle, sound);
|
||||||
|
default -> fertilizerConfig = null;
|
||||||
|
}
|
||||||
|
if (fertilizerConfig != null)
|
||||||
|
fertilizerConfigMap.put(key, fertilizerConfig);
|
||||||
|
else
|
||||||
|
AdventureUtils.consoleMessage("<red>[CustomCrops] Invalid fertilizer: " + key);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
AdventureUtils.consoleMessage("[CustomCrops] Loaded <green>" + fertilizerConfigMap.size() + " <gray>fertilizer(s)");
|
||||||
|
}
|
||||||
|
|
||||||
|
public ArrayList<Pair<Double, Integer>> getChancePair(ConfigurationSection fertilizerSec) {
|
||||||
|
ArrayList<Pair<Double, Integer>> pairs = new ArrayList<>();
|
||||||
|
ConfigurationSection effectSec = fertilizerSec.getConfigurationSection("effects");
|
||||||
|
if (effectSec == null) return new ArrayList<>();
|
||||||
|
for (String point : effectSec.getKeys(false)) {
|
||||||
|
Pair<Double, Integer> pair = new Pair<>(effectSec.getDouble(point), Integer.parseInt(point));
|
||||||
|
pairs.add(pair);
|
||||||
|
}
|
||||||
|
return pairs;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
package net.momirealms.customcrops.api.object.fertilizer;
|
||||||
|
|
||||||
|
public enum FertilizerType {
|
||||||
|
SPEED_GROW,
|
||||||
|
QUALITY,
|
||||||
|
SOIL_RETAIN,
|
||||||
|
VARIATION,
|
||||||
|
YIELD_INCREASE
|
||||||
|
}
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
package net.momirealms.customcrops.api.object.fertilizer;
|
||||||
|
|
||||||
|
import net.kyori.adventure.sound.Sound;
|
||||||
|
import org.bukkit.Particle;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
public class Quality extends FertilizerConfig {
|
||||||
|
|
||||||
|
private final double[] ratio;
|
||||||
|
|
||||||
|
public Quality(String key, FertilizerType fertilizerType, int times, double chance, double[] ratio, @Nullable String[] pot_whitelist, boolean beforePlant, @Nullable Particle particle, @Nullable Sound sound) {
|
||||||
|
super(key, fertilizerType, times, chance, pot_whitelist, beforePlant, particle, sound);
|
||||||
|
this.ratio = ratio;
|
||||||
|
}
|
||||||
|
|
||||||
|
public double[] getRatio() {
|
||||||
|
return ratio;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
package net.momirealms.customcrops.api.object.fertilizer;
|
||||||
|
|
||||||
|
import net.kyori.adventure.sound.Sound;
|
||||||
|
import org.bukkit.Particle;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
public class SoilRetain extends FertilizerConfig {
|
||||||
|
|
||||||
|
public SoilRetain(String key, FertilizerType fertilizerType, int times, double chance, @Nullable String[] pot_whitelist, boolean beforePlant, @Nullable Particle particle, @Nullable Sound sound) {
|
||||||
|
super(key, fertilizerType, times, chance, pot_whitelist, beforePlant, particle, sound);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
package net.momirealms.customcrops.api.object.fertilizer;
|
||||||
|
|
||||||
|
import net.kyori.adventure.sound.Sound;
|
||||||
|
import net.momirealms.customcrops.api.object.Pair;
|
||||||
|
import org.bukkit.Particle;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class SpeedGrow extends FertilizerConfig {
|
||||||
|
|
||||||
|
private final List<Pair<Double, Integer>> pairs;
|
||||||
|
|
||||||
|
public SpeedGrow(String key, FertilizerType fertilizerType, int times, List<Pair<Double, Integer>> pairs, @Nullable String[] pot_whitelist, boolean beforePlant, @Nullable Particle particle, @Nullable Sound sound) {
|
||||||
|
super(key, fertilizerType, times, 1, pot_whitelist, beforePlant, particle, sound);
|
||||||
|
this.pairs = pairs;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Pair<Double, Integer>> getPairs() {
|
||||||
|
return pairs;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getPointBonus() {
|
||||||
|
for (Pair<Double, Integer> pair : pairs) {
|
||||||
|
if (Math.random() < pair.left()) {
|
||||||
|
return pair.right();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
package net.momirealms.customcrops.api.object.fertilizer;
|
||||||
|
|
||||||
|
import net.kyori.adventure.sound.Sound;
|
||||||
|
import org.bukkit.Particle;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
public class Variation extends FertilizerConfig {
|
||||||
|
|
||||||
|
public Variation(String key, FertilizerType fertilizerType, int times, double chance, @Nullable String[] pot_whitelist, boolean beforePlant, @Nullable Particle particle, @Nullable Sound sound) {
|
||||||
|
super(key, fertilizerType, times, chance, pot_whitelist, beforePlant, particle, sound);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
package net.momirealms.customcrops.api.object.fertilizer;
|
||||||
|
|
||||||
|
import net.kyori.adventure.sound.Sound;
|
||||||
|
import net.momirealms.customcrops.api.object.Pair;
|
||||||
|
import org.bukkit.Particle;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class YieldIncrease extends FertilizerConfig {
|
||||||
|
|
||||||
|
private final List<Pair<Double, Integer>> pairs;
|
||||||
|
|
||||||
|
public YieldIncrease(String key, FertilizerType fertilizerType, int times, double chance, List<Pair<Double, Integer>> pairs, @Nullable String[] pot_whitelist, boolean beforePlant, @Nullable Particle particle, @Nullable Sound sound) {
|
||||||
|
super(key, fertilizerType, times, chance, pot_whitelist, beforePlant, particle, sound);
|
||||||
|
this.pairs = pairs;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Pair<Double, Integer>> getPairs() {
|
||||||
|
return pairs;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getAmountBonus() {
|
||||||
|
for (Pair<Double, Integer> pair : pairs) {
|
||||||
|
if (Math.random() < pair.left()) {
|
||||||
|
return pair.right();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
package net.momirealms.customcrops.api.object.fill;
|
||||||
|
|
||||||
|
import net.kyori.adventure.sound.Sound;
|
||||||
|
import org.bukkit.Particle;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
public abstract class AbstractFillMethod {
|
||||||
|
|
||||||
|
protected int amount;
|
||||||
|
protected Particle particle;
|
||||||
|
protected Sound sound;
|
||||||
|
|
||||||
|
protected AbstractFillMethod(int amount, Particle particle, Sound sound) {
|
||||||
|
this.amount = amount;
|
||||||
|
this.particle = particle;
|
||||||
|
this.sound = sound;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getAmount() {
|
||||||
|
return amount;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public Particle getParticle() {
|
||||||
|
return particle;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public Sound getSound() {
|
||||||
|
return sound;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
package net.momirealms.customcrops.api.object.fill;
|
||||||
|
|
||||||
|
import net.kyori.adventure.sound.Sound;
|
||||||
|
import net.momirealms.customcrops.CustomCrops;
|
||||||
|
import org.bukkit.Particle;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
public class PassiveFillMethod extends AbstractFillMethod {
|
||||||
|
|
||||||
|
private final String used;
|
||||||
|
private final String returned;
|
||||||
|
|
||||||
|
public PassiveFillMethod(String used, @Nullable String returned, int amount, @Nullable Particle particle, @Nullable Sound sound) {
|
||||||
|
super(amount, particle, sound);
|
||||||
|
this.used = used;
|
||||||
|
this.returned = returned;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isRightItem(String item_id) {
|
||||||
|
return used.equals(item_id);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public ItemStack getReturnedItemStack() {
|
||||||
|
if (returned == null) return null;
|
||||||
|
return CustomCrops.getInstance().getIntegrationManager().build(returned);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
package net.momirealms.customcrops.api.object.fill;
|
||||||
|
|
||||||
|
import net.kyori.adventure.sound.Sound;
|
||||||
|
import org.bukkit.Particle;
|
||||||
|
|
||||||
|
public class PositiveFillMethod extends AbstractFillMethod {
|
||||||
|
|
||||||
|
private final InteractType type;
|
||||||
|
private final String id;
|
||||||
|
|
||||||
|
public PositiveFillMethod(InteractType type, String id, int amount, Particle particle, Sound sound) {
|
||||||
|
super(amount, particle, sound);
|
||||||
|
this.type = type;
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public InteractType getType() {
|
||||||
|
return type;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public enum InteractType {
|
||||||
|
BLOCK,
|
||||||
|
ENTITY,
|
||||||
|
MM
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,54 @@
|
|||||||
|
package net.momirealms.customcrops.api.object.loot;
|
||||||
|
|
||||||
|
import net.momirealms.customcrops.CustomCrops;
|
||||||
|
import net.momirealms.customcrops.api.object.basic.ConfigManager;
|
||||||
|
import net.momirealms.customcrops.api.object.pot.Pot;
|
||||||
|
import net.momirealms.customcrops.api.object.fertilizer.YieldIncrease;
|
||||||
|
import net.momirealms.customcrops.api.object.world.SimpleLocation;
|
||||||
|
import net.momirealms.customcrops.integration.SkillInterface;
|
||||||
|
import net.objecthunter.exp4j.Expression;
|
||||||
|
import net.objecthunter.exp4j.ExpressionBuilder;
|
||||||
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
import java.util.concurrent.ThreadLocalRandom;
|
||||||
|
|
||||||
|
public abstract class Loot {
|
||||||
|
|
||||||
|
public int min;
|
||||||
|
public int max;
|
||||||
|
|
||||||
|
public Loot(int min, int max) {
|
||||||
|
this.min = min;
|
||||||
|
this.max = max;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void drop(Player player, Location location) {
|
||||||
|
//empty
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getMin() {
|
||||||
|
return min;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getMax() {
|
||||||
|
return max;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getAmount(Player player) {
|
||||||
|
int random = ThreadLocalRandom.current().nextInt(getMin(), getMax() + 1);
|
||||||
|
if (ConfigManager.enableSkillBonus && player != null) {
|
||||||
|
SkillInterface skillInterface = CustomCrops.getInstance().getIntegrationManager().getSkillInterface();
|
||||||
|
if (skillInterface != null) {
|
||||||
|
int level = skillInterface.getLevel(player);
|
||||||
|
Expression expression = new ExpressionBuilder(ConfigManager.bonusFormula)
|
||||||
|
.variables("base", "level")
|
||||||
|
.build()
|
||||||
|
.setVariable("base", random)
|
||||||
|
.setVariable("level", level);
|
||||||
|
random = (int) expression.evaluate();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return random;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,61 @@
|
|||||||
|
/*
|
||||||
|
* 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.object.loot;
|
||||||
|
|
||||||
|
import net.momirealms.customcrops.CustomCrops;
|
||||||
|
import net.momirealms.customcrops.api.object.fertilizer.YieldIncrease;
|
||||||
|
import net.momirealms.customcrops.api.object.pot.Pot;
|
||||||
|
import net.momirealms.customcrops.api.object.world.SimpleLocation;
|
||||||
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
|
public class OtherLoot extends Loot {
|
||||||
|
|
||||||
|
private final String itemID;
|
||||||
|
private final double chance;
|
||||||
|
|
||||||
|
public OtherLoot(int min, int max, String itemID, double chance) {
|
||||||
|
super(min, max);
|
||||||
|
this.itemID = itemID;
|
||||||
|
this.chance = chance;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getItemID() {
|
||||||
|
return itemID;
|
||||||
|
}
|
||||||
|
|
||||||
|
public double getChance() {
|
||||||
|
return chance;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void drop(Player player, Location location) {
|
||||||
|
if (Math.random() < getChance()) {
|
||||||
|
int random = getAmount(player);
|
||||||
|
Pot pot = CustomCrops.getInstance().getWorldDataManager().getPotData(SimpleLocation.getByBukkitLocation(location).add(0,-1,0));
|
||||||
|
if (pot != null && pot.getFertilizer() != null && pot.getFertilizer().getConfig() instanceof YieldIncrease increase) {
|
||||||
|
random += increase.getAmountBonus();
|
||||||
|
}
|
||||||
|
ItemStack drop = CustomCrops.getInstance().getIntegrationManager().build(getItemID());
|
||||||
|
if (drop.getType() == Material.AIR) return;
|
||||||
|
drop.setAmount(random);
|
||||||
|
location.getWorld().dropItemNaturally(location, drop);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,55 @@
|
|||||||
|
package net.momirealms.customcrops.api.object.loot;
|
||||||
|
|
||||||
|
import net.momirealms.customcrops.CustomCrops;
|
||||||
|
import net.momirealms.customcrops.api.object.basic.ConfigManager;
|
||||||
|
import net.momirealms.customcrops.api.object.fertilizer.FertilizerConfig;
|
||||||
|
import net.momirealms.customcrops.api.object.fertilizer.YieldIncrease;
|
||||||
|
import net.momirealms.customcrops.api.object.pot.Pot;
|
||||||
|
import net.momirealms.customcrops.api.object.fertilizer.Quality;
|
||||||
|
import net.momirealms.customcrops.api.object.world.SimpleLocation;
|
||||||
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
|
public class QualityLoot extends Loot {
|
||||||
|
|
||||||
|
private final String quality_1;
|
||||||
|
private final String quality_2;
|
||||||
|
private final String quality_3;
|
||||||
|
|
||||||
|
public QualityLoot(int min, int max, String quality_1, String quality_2, String quality_3) {
|
||||||
|
super(min, max);
|
||||||
|
this.quality_1 = quality_1;
|
||||||
|
this.quality_2 = quality_2;
|
||||||
|
this.quality_3 = quality_3;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void drop(Player player, Location location) {
|
||||||
|
SimpleLocation simpleLocation = SimpleLocation.getByBukkitLocation(location);
|
||||||
|
Pot pot = CustomCrops.getInstance().getWorldDataManager().getPotData(simpleLocation);
|
||||||
|
int amount = getAmount(player);
|
||||||
|
double[] qualityRatio = ConfigManager.defaultRatio;
|
||||||
|
if (pot != null) {
|
||||||
|
FertilizerConfig fertilizerConfig = CustomCrops.getInstance().getFertilizerManager().getConfigByFertilizer(pot.getFertilizer());
|
||||||
|
if (fertilizerConfig instanceof Quality quality && quality.canTakeEffect()) {
|
||||||
|
qualityRatio = quality.getRatio();
|
||||||
|
} else if (fertilizerConfig instanceof YieldIncrease increase) {
|
||||||
|
amount += increase.getAmountBonus();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (int i = 0; i < amount; i++) {
|
||||||
|
double random = Math.random();
|
||||||
|
if (random < qualityRatio[0]) dropItem(location, quality_1);
|
||||||
|
else if (random > qualityRatio[1]) dropItem(location, quality_2);
|
||||||
|
else dropItem(location, quality_3);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void dropItem(Location location, String id) {
|
||||||
|
ItemStack drop = CustomCrops.getInstance().getIntegrationManager().build(id);
|
||||||
|
if (drop.getType() == Material.AIR) return;
|
||||||
|
location.getWorld().dropItemNaturally(location, drop);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,82 @@
|
|||||||
|
package net.momirealms.customcrops.api.object.pot;
|
||||||
|
|
||||||
|
import net.momirealms.customcrops.CustomCrops;
|
||||||
|
import net.momirealms.customcrops.api.object.fertilizer.Fertilizer;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
public class Pot implements Serializable {
|
||||||
|
|
||||||
|
private Fertilizer fertilizer;
|
||||||
|
private int water;
|
||||||
|
private final String key;
|
||||||
|
|
||||||
|
public Pot(String key, Fertilizer fertilizer, int water) {
|
||||||
|
this.key = key;
|
||||||
|
this.fertilizer = fertilizer;
|
||||||
|
this.water = water;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Fertilizer getFertilizer() {
|
||||||
|
return fertilizer;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setFertilizer(Fertilizer fertilizer) {
|
||||||
|
this.fertilizer = fertilizer;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getWater() {
|
||||||
|
return water;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
whether to change block model
|
||||||
|
*/
|
||||||
|
public boolean addWater(int amount) {
|
||||||
|
if (water == 0) {
|
||||||
|
this.water = Math.min(getConfig().getMax_storage(), amount);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
this.water = Math.min(getConfig().getMax_storage(), water + amount);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setWater(int amount) {
|
||||||
|
this.water = amount;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
whether to change block model
|
||||||
|
*/
|
||||||
|
public boolean reduceWater() {
|
||||||
|
water--;
|
||||||
|
return water <= 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
whether to change block model
|
||||||
|
*/
|
||||||
|
public boolean reduceFertilizer() {
|
||||||
|
if (this.fertilizer != null && fertilizer.reduceTimes()) {
|
||||||
|
this.fertilizer = null;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isWet() {
|
||||||
|
return water != 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
public String getPotKey() {
|
||||||
|
return key;
|
||||||
|
}
|
||||||
|
|
||||||
|
public PotConfig getConfig() {
|
||||||
|
return CustomCrops.getInstance().getPotManager().getPotConfig(key);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,61 @@
|
|||||||
|
package net.momirealms.customcrops.api.object.pot;
|
||||||
|
|
||||||
|
import net.momirealms.customcrops.api.object.Pair;
|
||||||
|
import net.momirealms.customcrops.api.object.fill.PassiveFillMethod;
|
||||||
|
import net.momirealms.customcrops.api.object.fertilizer.Fertilizer;
|
||||||
|
import net.momirealms.customcrops.api.object.fertilizer.FertilizerConfig;
|
||||||
|
import net.momirealms.customcrops.api.object.fertilizer.FertilizerType;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
|
||||||
|
public class PotConfig {
|
||||||
|
|
||||||
|
private final HashMap<FertilizerType, Pair<String, String>> fertilizerConvertMap;
|
||||||
|
private final int max_storage;
|
||||||
|
private final Pair<String, String> pot;
|
||||||
|
private final boolean enableFertilized;
|
||||||
|
private final PassiveFillMethod[] passiveFillMethods;
|
||||||
|
|
||||||
|
public PotConfig(int max_storage, String dry_pot, String wet_pot, boolean enableFertilized, @NotNull PassiveFillMethod[] passiveFillMethods) {
|
||||||
|
this.max_storage = max_storage;
|
||||||
|
this.pot = Pair.of(dry_pot, wet_pot);
|
||||||
|
this.enableFertilized = enableFertilized;
|
||||||
|
this.fertilizerConvertMap = new HashMap<>();
|
||||||
|
this.passiveFillMethods = passiveFillMethods;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void registerFertilizedPot(FertilizerType fertilizerType, String dry_pot, String wet_pot) {
|
||||||
|
fertilizerConvertMap.put(fertilizerType, Pair.of(dry_pot, wet_pot));
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getWetPot(@Nullable Fertilizer fertilizer) {
|
||||||
|
if (fertilizer == null || !enableFertilized) return pot.right();
|
||||||
|
FertilizerConfig fertilizerConfig = fertilizer.getConfig();
|
||||||
|
if (fertilizerConfig == null) return pot.right();
|
||||||
|
FertilizerType fertilizerType = fertilizerConfig.getFertilizerType();
|
||||||
|
Pair<String, String> pair = fertilizerConvertMap.get(fertilizerType);
|
||||||
|
if (pair == null) return pot.right();
|
||||||
|
else return pair.right();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDryPot(@Nullable Fertilizer fertilizer) {
|
||||||
|
if (fertilizer == null || !enableFertilized) return pot.left();
|
||||||
|
FertilizerConfig fertilizerConfig = fertilizer.getConfig();
|
||||||
|
if (fertilizerConfig == null) return pot.left();
|
||||||
|
FertilizerType fertilizerType = fertilizerConfig.getFertilizerType();
|
||||||
|
Pair<String, String> pair = fertilizerConvertMap.get(fertilizerType);
|
||||||
|
if (pair == null) return pot.left();
|
||||||
|
else return pair.left();
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getMax_storage() {
|
||||||
|
return max_storage;
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
public PassiveFillMethod[] getPassiveFillMethods() {
|
||||||
|
return passiveFillMethods;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,117 @@
|
|||||||
|
package net.momirealms.customcrops.api.object.pot;
|
||||||
|
|
||||||
|
import net.momirealms.customcrops.CustomCrops;
|
||||||
|
import net.momirealms.customcrops.api.object.Function;
|
||||||
|
import net.momirealms.customcrops.api.object.fertilizer.FertilizerType;
|
||||||
|
import net.momirealms.customcrops.api.object.fill.PassiveFillMethod;
|
||||||
|
import net.momirealms.customcrops.api.util.AdventureUtils;
|
||||||
|
import net.momirealms.customcrops.api.util.ConfigUtils;
|
||||||
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.util.HashMap;
|
||||||
|
|
||||||
|
public class PotManager extends Function {
|
||||||
|
|
||||||
|
private final CustomCrops plugin;
|
||||||
|
private final HashMap<String, PotConfig> potConfigMap;
|
||||||
|
private final HashMap<String, String> blockToPotKey;
|
||||||
|
|
||||||
|
public PotManager(CustomCrops plugin) {
|
||||||
|
this.plugin = plugin;
|
||||||
|
this.potConfigMap = new HashMap<>();
|
||||||
|
this.blockToPotKey = new HashMap<>();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void load() {
|
||||||
|
loadConfig();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void unload() {
|
||||||
|
this.potConfigMap.clear();
|
||||||
|
this.blockToPotKey.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void loadConfig() {
|
||||||
|
File pot_folder = new File(plugin.getDataFolder(), "contents" + File.separator + "pots");
|
||||||
|
if (!pot_folder.exists()) {
|
||||||
|
if (!pot_folder.mkdirs()) return;
|
||||||
|
plugin.saveResource("contents" + File.separator + "pots" + File.separator + "default.yml", false);
|
||||||
|
}
|
||||||
|
File[] files = pot_folder.listFiles();
|
||||||
|
if (files == null) return;
|
||||||
|
for (File file : files) {
|
||||||
|
YamlConfiguration config = YamlConfiguration.loadConfiguration(file);
|
||||||
|
for (String key : config.getKeys(false)) {
|
||||||
|
ConfigurationSection section = config.getConfigurationSection(key);
|
||||||
|
if (section == null) continue;
|
||||||
|
boolean enableFertilized = section.getBoolean("fertilized-pots.enable", false);
|
||||||
|
String base_dry = section.getString("base.dry");
|
||||||
|
String base_wet = section.getString("base.wet");
|
||||||
|
if (base_wet == null || base_dry == null) {
|
||||||
|
AdventureUtils.consoleMessage("<red>[CustomCrops] base.dry/base.wet is not correctly set for pot: " + key);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
PassiveFillMethod[] methods = ConfigUtils.getPassiveFillMethods(section.getConfigurationSection("fill-method"));
|
||||||
|
if (methods == null) {
|
||||||
|
AdventureUtils.consoleMessage("<red>[CustomCrops] fill method is not set for pot: " + key);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
blockToPotKey.put(base_wet, key);
|
||||||
|
blockToPotKey.put(base_dry, key);
|
||||||
|
PotConfig potConfig = new PotConfig(
|
||||||
|
section.getInt("max-water-storage"),
|
||||||
|
base_dry,
|
||||||
|
base_wet,
|
||||||
|
enableFertilized,
|
||||||
|
methods
|
||||||
|
);
|
||||||
|
if (enableFertilized) {
|
||||||
|
ConfigurationSection fertilizedSec = section.getConfigurationSection("fertilized-pots");
|
||||||
|
if (fertilizedSec == null) continue;
|
||||||
|
for (String type : fertilizedSec.getKeys(false)) {
|
||||||
|
if (type.equals("enable")) continue;
|
||||||
|
String dry = fertilizedSec.getString(type + ".dry");
|
||||||
|
String wet = fertilizedSec.getString(type + ".wet");
|
||||||
|
blockToPotKey.put(dry, key);
|
||||||
|
blockToPotKey.put(wet, key);
|
||||||
|
switch (type) {
|
||||||
|
case "quality" -> potConfig.registerFertilizedPot(FertilizerType.QUALITY, dry, wet);
|
||||||
|
case "yield-increase" -> potConfig.registerFertilizedPot(FertilizerType.YIELD_INCREASE, dry, wet);
|
||||||
|
case "variation" -> potConfig.registerFertilizedPot(FertilizerType.VARIATION, dry, wet);
|
||||||
|
case "soil-retain" -> potConfig.registerFertilizedPot(FertilizerType.SOIL_RETAIN, dry, wet);
|
||||||
|
case "speed-grow" -> potConfig.registerFertilizedPot(FertilizerType.SPEED_GROW, dry, wet);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
potConfigMap.put(key, potConfig);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
AdventureUtils.consoleMessage("[CustomCrops] Loaded <green>" + potConfigMap.size() + " <gray>pot(s)");
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean containsPotBlock(String id) {
|
||||||
|
return blockToPotKey.containsKey(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public PotConfig getPotConfig(String key) {
|
||||||
|
return potConfigMap.get(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public String getPotKeyByBlockID(String id) {
|
||||||
|
return blockToPotKey.get(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public PotConfig getPotConfigByBlockID(String id) {
|
||||||
|
String key = blockToPotKey.get(id);
|
||||||
|
if (key == null) return null;
|
||||||
|
return potConfigMap.get(key);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -15,27 +15,25 @@
|
|||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package net.momirealms.customcrops.objects.requirements;
|
package net.momirealms.customcrops.api.object.requirement;
|
||||||
|
|
||||||
import net.momirealms.customcrops.utils.AdventureUtil;
|
import net.momirealms.customcrops.api.util.AdventureUtils;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
public abstract class Requirement {
|
public abstract class AbstractRequirement {
|
||||||
|
|
||||||
protected String[] values;
|
protected String[] msg;
|
||||||
protected boolean mode;
|
|
||||||
protected String msg;
|
|
||||||
|
|
||||||
protected Requirement(@NotNull String[] values, boolean mode, @Nullable String msg) {
|
protected AbstractRequirement(@Nullable String[] msg) {
|
||||||
this.values = values;
|
|
||||||
this.mode = mode;
|
|
||||||
this.msg = msg;
|
this.msg = msg;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void notMetMessage(Player player) {
|
public void notMetMessage(Player player) {
|
||||||
if (msg == null) return;
|
if (msg != null && player != null) {
|
||||||
AdventureUtil.playerMessage(player, this.msg);
|
for (String str : msg) {
|
||||||
|
AdventureUtils.playerMessage(player, str);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -15,30 +15,29 @@
|
|||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package net.momirealms.customcrops.objects.actions;
|
package net.momirealms.customcrops.api.object.requirement;
|
||||||
|
|
||||||
import net.momirealms.customcrops.config.MainConfig;
|
import net.momirealms.biomeapi.BiomeAPI;
|
||||||
import org.bukkit.entity.Player;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
public class ActionSkillXP implements ActionInterface {
|
import java.util.HashSet;
|
||||||
|
|
||||||
private final double xp;
|
public class BiomeImpl extends AbstractRequirement implements Requirement {
|
||||||
private final double chance;
|
|
||||||
|
|
||||||
public ActionSkillXP(double xp, double chance) {
|
private final HashSet<String> biomes;
|
||||||
this.xp = xp;
|
|
||||||
this.chance = chance;
|
public BiomeImpl(@Nullable String[] msg, HashSet<String> biomes) {
|
||||||
|
super(msg);
|
||||||
|
this.biomes = biomes;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void performOn(Player player) {
|
public boolean isConditionMet(CurrentState currentState) {
|
||||||
if (MainConfig.skillInterface != null) {
|
String currentBiome = BiomeAPI.getBiome(currentState.getLocation());
|
||||||
MainConfig.skillInterface.addXp(player, xp);
|
if (biomes.contains(currentBiome)) {
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
}
|
notMetMessage(currentState.getPlayer());
|
||||||
|
return false;
|
||||||
@Override
|
|
||||||
public double getChance() {
|
|
||||||
return chance;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -15,27 +15,26 @@
|
|||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package net.momirealms.customcrops.objects.actions;
|
package net.momirealms.customcrops.api.object.requirement;
|
||||||
|
|
||||||
|
import org.bukkit.Location;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
public class ActionXP implements ActionInterface {
|
public class CurrentState {
|
||||||
|
|
||||||
private final int amount;
|
private final Location location;
|
||||||
private final double chance;
|
private final Player player;
|
||||||
|
|
||||||
public ActionXP(int amount, double chance) {
|
public CurrentState(Location crop_loc, Player player) {
|
||||||
this.amount = amount;
|
this.location = crop_loc;
|
||||||
this.chance = chance;
|
this.player = player;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
public Location getLocation() {
|
||||||
public void performOn(Player player) {
|
return location;
|
||||||
player.giveExp(amount);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
public Player getPlayer() {
|
||||||
public double getChance() {
|
return player;
|
||||||
return chance;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,80 @@
|
|||||||
|
/*
|
||||||
|
* 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.object.requirement;
|
||||||
|
|
||||||
|
import net.momirealms.customcrops.api.object.requirement.papi.*;
|
||||||
|
import org.bukkit.configuration.MemorySection;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public class CustomPapi extends AbstractRequirement implements Requirement {
|
||||||
|
|
||||||
|
private final List<PapiRequirement> papiRequirement;
|
||||||
|
|
||||||
|
public CustomPapi(String[] msg, Map<String, Object> expressions){
|
||||||
|
super(msg);
|
||||||
|
papiRequirement = getRequirements(expressions);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isConditionMet(CurrentState currentState) {
|
||||||
|
Player player = currentState.getPlayer();
|
||||||
|
if (currentState.getPlayer() == null) return true;
|
||||||
|
for (PapiRequirement requirement : papiRequirement) {
|
||||||
|
if (!requirement.isMet(player)) {
|
||||||
|
notMetMessage(player);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<PapiRequirement> getRequirements(Map<String, Object> map) {
|
||||||
|
List<PapiRequirement> papiRequirements = new ArrayList<>();
|
||||||
|
map.keySet().forEach(key -> {
|
||||||
|
if (key.startsWith("&&")) {
|
||||||
|
if (map.get(key) instanceof MemorySection map2) {
|
||||||
|
papiRequirements.add(new ExpressionAnd(getRequirements(map2.getValues(false))));
|
||||||
|
}
|
||||||
|
} else if (key.startsWith("||")) {
|
||||||
|
if (map.get(key) instanceof MemorySection map2) {
|
||||||
|
papiRequirements.add(new ExpressionOr(getRequirements(map2.getValues(false))));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (map.get(key) instanceof MemorySection map2) {
|
||||||
|
String type = map2.getString("type");
|
||||||
|
String papi = map2.getString("papi");
|
||||||
|
String value = map2.getString("value");
|
||||||
|
if (value == null || papi == null || type == null) return;
|
||||||
|
switch (type){
|
||||||
|
case "==" -> papiRequirements.add(new PapiEquals(papi, value));
|
||||||
|
case "!=" -> papiRequirements.add(new PapiNotEquals(papi, value));
|
||||||
|
case ">=" -> papiRequirements.add(new PapiNoLess(papi, value));
|
||||||
|
case "<=" -> papiRequirements.add(new PapiNoLarger(papi, value));
|
||||||
|
case "<" -> papiRequirements.add(new PapiSmaller(papi, value));
|
||||||
|
case ">" -> papiRequirements.add(new PapiGreater(papi, value));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return papiRequirements;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
package net.momirealms.customcrops.api.object.requirement;
|
||||||
|
|
||||||
|
import java.util.Calendar;
|
||||||
|
import java.util.HashSet;
|
||||||
|
|
||||||
|
public class DateImpl extends AbstractRequirement implements Requirement {
|
||||||
|
|
||||||
|
private final HashSet<String> dates;
|
||||||
|
|
||||||
|
public DateImpl(String[] msg, HashSet<String> dates) {
|
||||||
|
super(msg);
|
||||||
|
this.dates = dates;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isConditionMet(CurrentState currentState) {
|
||||||
|
Calendar calendar = Calendar.getInstance();
|
||||||
|
String current = (calendar.get(Calendar.MONTH) + 1) + "/" + calendar.get(Calendar.DATE);
|
||||||
|
if (dates.contains(current)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
notMetMessage(currentState.getPlayer());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
package net.momirealms.customcrops.api.object.requirement;
|
||||||
|
|
||||||
|
import net.momirealms.customcrops.CustomCrops;
|
||||||
|
import net.momirealms.customcrops.integration.JobInterface;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
public class JobLevelImpl extends AbstractRequirement implements Requirement {
|
||||||
|
|
||||||
|
private final int level;
|
||||||
|
|
||||||
|
public JobLevelImpl(@Nullable String[] msg, int level) {
|
||||||
|
super(msg);
|
||||||
|
this.level = level;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isConditionMet(CurrentState currentState) {
|
||||||
|
JobInterface jobInterface = CustomCrops.getInstance().getIntegrationManager().getJobInterface();
|
||||||
|
if (jobInterface == null || currentState.getPlayer() == null) return true;
|
||||||
|
if (jobInterface.getLevel(currentState.getPlayer()) >= level) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
notMetMessage(currentState.getPlayer());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -15,30 +15,29 @@
|
|||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package net.momirealms.customcrops.objects.actions;
|
package net.momirealms.customcrops.api.object.requirement;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
public class ActionCommand implements ActionInterface {
|
public class PermissionImpl extends AbstractRequirement implements Requirement {
|
||||||
|
|
||||||
private final String[] commands;
|
private final String permission;
|
||||||
private final double chance;
|
|
||||||
|
|
||||||
public ActionCommand(String[] commands, double chance) {
|
public PermissionImpl(@Nullable String[] msg, String permission) {
|
||||||
this.commands = commands;
|
super(msg);
|
||||||
this.chance = chance;
|
this.permission = permission;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getPermission() {
|
||||||
|
return this.permission;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void performOn(Player player) {
|
public boolean isConditionMet(CurrentState currentState) {
|
||||||
for (String command : commands) {
|
if (currentState.getPlayer() == null || currentState.getPlayer().hasPermission(permission)) {
|
||||||
Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), command.replace("{player}", player.getName()));
|
return true;
|
||||||
}
|
}
|
||||||
|
notMetMessage(currentState.getPlayer());
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
@Override
|
|
||||||
public double getChance() {
|
|
||||||
return chance;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -15,13 +15,9 @@
|
|||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package net.momirealms.customcrops.objects;
|
package net.momirealms.customcrops.api.object.requirement;
|
||||||
|
|
||||||
public class Function {
|
public interface Requirement {
|
||||||
|
|
||||||
public void load() {
|
boolean isConditionMet(CurrentState currentState);
|
||||||
}
|
|
||||||
|
|
||||||
public void unload() {
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,47 @@
|
|||||||
|
/*
|
||||||
|
* 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.object.requirement;
|
||||||
|
|
||||||
|
import net.momirealms.customcrops.CustomCrops;
|
||||||
|
import net.momirealms.customcrops.api.object.season.CCSeason;
|
||||||
|
import net.momirealms.customcrops.integration.SeasonInterface;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class SeasonImpl extends AbstractRequirement implements Requirement {
|
||||||
|
|
||||||
|
private final List<CCSeason> seasons;
|
||||||
|
|
||||||
|
public SeasonImpl(@Nullable String[] msg, List<CCSeason> seasons) {
|
||||||
|
super(msg);
|
||||||
|
this.seasons = seasons;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isConditionMet(CurrentState currentState) {
|
||||||
|
SeasonInterface seasonInterface = CustomCrops.getInstance().getIntegrationManager().getSeasonInterface();
|
||||||
|
if (seasonInterface == null) return true;
|
||||||
|
CCSeason currentSeason = seasonInterface.getSeason(currentState.getLocation().getWorld().getName());
|
||||||
|
if (seasons.contains(currentSeason)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
notMetMessage(currentState.getPlayer());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
package net.momirealms.customcrops.api.object.requirement;
|
||||||
|
|
||||||
|
import net.momirealms.customcrops.CustomCrops;
|
||||||
|
import net.momirealms.customcrops.integration.SkillInterface;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
public class SkillLevelImpl extends AbstractRequirement implements Requirement {
|
||||||
|
|
||||||
|
private final int level;
|
||||||
|
|
||||||
|
public SkillLevelImpl(@Nullable String[] msg, int level) {
|
||||||
|
super(msg);
|
||||||
|
this.level = level;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isConditionMet(CurrentState currentState) {
|
||||||
|
SkillInterface skillInterface = CustomCrops.getInstance().getIntegrationManager().getSkillInterface();
|
||||||
|
if (skillInterface == null || currentState.getPlayer() == null) return true;
|
||||||
|
if (skillInterface.getLevel(currentState.getPlayer()) >= level) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
notMetMessage(currentState.getPlayer());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,45 @@
|
|||||||
|
/*
|
||||||
|
* 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.object.requirement;
|
||||||
|
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class TimeImpl extends AbstractRequirement implements Requirement {
|
||||||
|
|
||||||
|
private final List<String> times;
|
||||||
|
|
||||||
|
public TimeImpl(@Nullable String[] msg, List<String> times) {
|
||||||
|
super(msg);
|
||||||
|
this.times = times;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isConditionMet(CurrentState currentState) {
|
||||||
|
long time = currentState.getLocation().getWorld().getTime();
|
||||||
|
for (String range : times) {
|
||||||
|
String[] timeMinMax = range.split("~");
|
||||||
|
if (time > Long.parseLong(timeMinMax[0]) && time < Long.parseLong(timeMinMax[1])) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
notMetMessage(currentState.getPlayer());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,49 @@
|
|||||||
|
/*
|
||||||
|
* 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.object.requirement;
|
||||||
|
|
||||||
|
import org.bukkit.World;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class WeatherImpl extends AbstractRequirement implements Requirement {
|
||||||
|
|
||||||
|
private final List<String> weathers;
|
||||||
|
|
||||||
|
public WeatherImpl(@Nullable String[] msg, List<String> weathers) {
|
||||||
|
super(msg);
|
||||||
|
this.weathers = weathers;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isConditionMet(CurrentState currentState) {
|
||||||
|
World world = currentState.getLocation().getWorld();
|
||||||
|
String currentWeather;
|
||||||
|
if (world.isThundering()) currentWeather = "thunder";
|
||||||
|
else if (world.isClearWeather()) currentWeather = "clear";
|
||||||
|
else currentWeather = "rain";
|
||||||
|
for (String weather : weathers) {
|
||||||
|
if (weather.equalsIgnoreCase(currentWeather)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
notMetMessage(currentState.getPlayer());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -15,28 +15,29 @@
|
|||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
package net.momirealms.customcrops.api.object.requirement;
|
||||||
|
|
||||||
package net.momirealms.customcrops.api.utils;
|
|
||||||
|
|
||||||
import net.momirealms.customcrops.CustomCrops;
|
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
public class WorldUtils {
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
public class WorldImpl extends AbstractRequirement implements Requirement {
|
||||||
* load a world's crop data
|
|
||||||
* @param world world
|
private final List<String> worlds;
|
||||||
*/
|
|
||||||
public static void loadCropWorld(World world) {
|
public WorldImpl(@Nullable String[] msg, List<String> worlds) {
|
||||||
CustomCrops.plugin.getCropManager().onWorldLoad(world);
|
super(msg);
|
||||||
|
this.worlds = worlds;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
@Override
|
||||||
* unload a world's crop data
|
public boolean isConditionMet(CurrentState currentState) {
|
||||||
* @param world world
|
World world = currentState.getLocation().getWorld();
|
||||||
* @param sync whether unload is sync or async
|
if (worlds.contains(world.getName())) {
|
||||||
*/
|
return true;
|
||||||
public static void unloadCropWorld(World world, boolean sync) {
|
}
|
||||||
CustomCrops.plugin.getCropManager().onWorldUnload(world, sync);
|
notMetMessage(currentState.getPlayer());
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -15,26 +15,31 @@
|
|||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package net.momirealms.customcrops.objects.requirements;
|
package net.momirealms.customcrops.api.object.requirement;
|
||||||
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
public class RequirementWorld extends Requirement implements RequirementInterface {
|
import java.util.List;
|
||||||
|
|
||||||
public RequirementWorld(@NotNull String[] values, boolean mode, @Nullable String msg) {
|
public class YPosImpl extends AbstractRequirement implements Requirement {
|
||||||
super(values, mode, msg);
|
|
||||||
|
private final List<String> yPos;
|
||||||
|
|
||||||
|
public YPosImpl(@Nullable String[] msg, List<String> yPos) {
|
||||||
|
super(msg);
|
||||||
|
this.yPos = yPos;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isConditionMet(PlayerCondition playerCondition) {
|
public boolean isConditionMet(CurrentState currentState) {
|
||||||
String worldName = playerCondition.getLocation().getWorld().getName();
|
int y = (int) currentState.getLocation().getY();
|
||||||
for (String value : values) {
|
for (String range : yPos) {
|
||||||
if (value.equals(worldName)) {
|
String[] yMinMax = range.split("~");
|
||||||
|
if (y > Integer.parseInt(yMinMax[0]) && y < Integer.parseInt(yMinMax[1])) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
notMetMessage(playerCondition.getPlayer());
|
notMetMessage(currentState.getPlayer());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -15,19 +15,18 @@
|
|||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package net.momirealms.customcrops.objects.requirements.papi;
|
package net.momirealms.customcrops.api.object.requirement.papi;
|
||||||
|
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public record ExpressionAnd(List<PapiRequirement> requirements) implements PapiRequirement{
|
public record ExpressionAnd(List<PapiRequirement> requirements) implements PapiRequirement{
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isMet(HashMap<String, String> papiMap, Player player) {
|
public boolean isMet(Player player) {
|
||||||
for (PapiRequirement requirement : requirements) {
|
for (PapiRequirement requirement : requirements) {
|
||||||
if (!requirement.isMet(papiMap, player)) return false;
|
if (!requirement.isMet(player)) return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -15,19 +15,18 @@
|
|||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package net.momirealms.customcrops.objects.requirements.papi;
|
package net.momirealms.customcrops.api.object.requirement.papi;
|
||||||
|
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public record ExpressionOr(List<PapiRequirement> requirements) implements PapiRequirement{
|
public record ExpressionOr(List<PapiRequirement> requirements) implements PapiRequirement{
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isMet(HashMap<String, String> papiMap, Player player) {
|
public boolean isMet(Player player) {
|
||||||
for (PapiRequirement requirement : requirements) {
|
for (PapiRequirement requirement : requirements) {
|
||||||
if (requirement.isMet(papiMap, player)) return true;
|
if (requirement.isMet(player)) return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -15,19 +15,18 @@
|
|||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package net.momirealms.customcrops.objects.requirements.papi;
|
package net.momirealms.customcrops.api.object.requirement.papi;
|
||||||
|
|
||||||
import me.clip.placeholderapi.PlaceholderAPI;
|
import me.clip.placeholderapi.PlaceholderAPI;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
public record PapiEquals(String papi, String requirement) implements PapiRequirement{
|
public record PapiEquals(String papi, String requirement) implements PapiRequirement{
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isMet(HashMap<String, String> papiMap, Player player) {
|
public boolean isMet(Player player) {
|
||||||
String value = papiMap.get(papi);
|
String value = PlaceholderAPI.setPlaceholders(player, papi);
|
||||||
return Objects.equals(value, PlaceholderAPI.setPlaceholders(player, requirement));
|
return Objects.equals(value, PlaceholderAPI.setPlaceholders(player, requirement));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -15,18 +15,16 @@
|
|||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package net.momirealms.customcrops.objects.requirements.papi;
|
package net.momirealms.customcrops.api.object.requirement.papi;
|
||||||
|
|
||||||
import me.clip.placeholderapi.PlaceholderAPI;
|
import me.clip.placeholderapi.PlaceholderAPI;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
|
|
||||||
public record PapiGreater(String papi, String requirement) implements PapiRequirement{
|
public record PapiGreater(String papi, String requirement) implements PapiRequirement{
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isMet(HashMap<String, String> papiMap, Player player) {
|
public boolean isMet(Player player) {
|
||||||
double value = Double.parseDouble(papiMap.get(papi));
|
double value = Double.parseDouble(PlaceholderAPI.setPlaceholders(player, papi));
|
||||||
return value > Double.parseDouble(PlaceholderAPI.setPlaceholders(player, requirement));
|
return value > Double.parseDouble(PlaceholderAPI.setPlaceholders(player, requirement));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -15,18 +15,16 @@
|
|||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package net.momirealms.customcrops.objects.requirements.papi;
|
package net.momirealms.customcrops.api.object.requirement.papi;
|
||||||
|
|
||||||
import me.clip.placeholderapi.PlaceholderAPI;
|
import me.clip.placeholderapi.PlaceholderAPI;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
|
|
||||||
public record PapiNoLarger(String papi, String requirement) implements PapiRequirement{
|
public record PapiNoLarger(String papi, String requirement) implements PapiRequirement{
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isMet(HashMap<String, String> papiMap, Player player) {
|
public boolean isMet(Player player) {
|
||||||
double value = Double.parseDouble(papiMap.get(papi));
|
double value = Double.parseDouble(PlaceholderAPI.setPlaceholders(player, papi));
|
||||||
return value <= Double.parseDouble(PlaceholderAPI.setPlaceholders(player, requirement));
|
return value <= Double.parseDouble(PlaceholderAPI.setPlaceholders(player, requirement));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -15,18 +15,16 @@
|
|||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package net.momirealms.customcrops.objects.requirements.papi;
|
package net.momirealms.customcrops.api.object.requirement.papi;
|
||||||
|
|
||||||
import me.clip.placeholderapi.PlaceholderAPI;
|
import me.clip.placeholderapi.PlaceholderAPI;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
|
|
||||||
public record PapiNoLess(String papi, String requirement) implements PapiRequirement{
|
public record PapiNoLess(String papi, String requirement) implements PapiRequirement{
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isMet(HashMap<String, String> papiMap, Player player) {
|
public boolean isMet(Player player) {
|
||||||
double value = Double.parseDouble(papiMap.get(papi));
|
double value = Double.parseDouble(PlaceholderAPI.setPlaceholders(player, papi));
|
||||||
return value >= Double.parseDouble(PlaceholderAPI.setPlaceholders(player, requirement));
|
return value >= Double.parseDouble(PlaceholderAPI.setPlaceholders(player, requirement));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -15,19 +15,18 @@
|
|||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package net.momirealms.customcrops.objects.requirements.papi;
|
package net.momirealms.customcrops.api.object.requirement.papi;
|
||||||
|
|
||||||
import me.clip.placeholderapi.PlaceholderAPI;
|
import me.clip.placeholderapi.PlaceholderAPI;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
public record PapiNotEquals(String papi, String requirement) implements PapiRequirement{
|
public record PapiNotEquals(String papi, String requirement) implements PapiRequirement{
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isMet(HashMap<String, String> papiMap, Player player) {
|
public boolean isMet(Player player) {
|
||||||
String value = papiMap.get(papi);
|
String value = PlaceholderAPI.setPlaceholders(player, papi);
|
||||||
return !Objects.equals(value, PlaceholderAPI.setPlaceholders(player, requirement));
|
return !Objects.equals(value, PlaceholderAPI.setPlaceholders(player, requirement));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user