mirror of
https://github.com/Xiao-MoMi/Custom-Crops.git
synced 2025-12-25 09:59:20 +00:00
2.2.5
This commit is contained in:
@@ -19,9 +19,18 @@ package net.momirealms.customcrops.api.utils;
|
||||
|
||||
import net.momirealms.customcrops.CustomCrops;
|
||||
import net.momirealms.customcrops.api.crop.Crop;
|
||||
import net.momirealms.customcrops.config.BasicItemConfig;
|
||||
import net.momirealms.customcrops.config.CropConfig;
|
||||
import net.momirealms.customcrops.config.MainConfig;
|
||||
import net.momirealms.customcrops.managers.CropManager;
|
||||
import net.momirealms.customcrops.managers.CustomWorld;
|
||||
import net.momirealms.customcrops.objects.GrowingCrop;
|
||||
import net.momirealms.customcrops.objects.Sprinkler;
|
||||
import net.momirealms.customcrops.objects.fertilizer.Fertilizer;
|
||||
import net.momirealms.customcrops.utils.FurnitureUtil;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class CropUtils {
|
||||
@@ -32,7 +41,7 @@ public class CropUtils {
|
||||
* @return crop config
|
||||
*/
|
||||
@Nullable
|
||||
public static Crop getCrop(String crop) {
|
||||
public static Crop getCropConfig(String crop) {
|
||||
return CropConfig.CROPS.get(crop);
|
||||
}
|
||||
|
||||
@@ -46,6 +55,61 @@ public class CropUtils {
|
||||
return CustomCrops.plugin.getCropManager().getHandler().plantSeed(location, crop, null, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Oraxen & ItemsAdder handle item frame hitbox in different ways
|
||||
* If you want to remove a crop at a certain location, use location.getBlock() method as the param
|
||||
* @param block block
|
||||
* @return success or not
|
||||
*/
|
||||
public static boolean removeCrop(Block block) {
|
||||
Location location = block.getLocation();
|
||||
CustomCrops.plugin.getCropManager().getHandler().onBreakUnripeCrop(location);
|
||||
if (MainConfig.cropMode) {
|
||||
CustomCrops.plugin.getCropManager().getCustomInterface().removeBlock(location);
|
||||
}
|
||||
else {
|
||||
if (MainConfig.OraxenHook) {CustomCrops.plugin.getCropManager().getCustomInterface().removeFurniture(FurnitureUtil.getItemFrame(location.clone().add(0.5,0.03125,0.5)));}
|
||||
else {CustomCrops.plugin.getCropManager().getCustomInterface().removeFurniture(FurnitureUtil.getItemFrame(location.clone().add(0.5,0.5,0.5)));}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* get the growing crop
|
||||
* @param location crop location
|
||||
* @return growing crop
|
||||
*/
|
||||
@Nullable
|
||||
public static GrowingCrop getGrowingCrop(Location location) {
|
||||
CustomWorld customWorld = CustomCrops.plugin.getCropManager().getCustomWorld(location.getWorld());
|
||||
if (customWorld != null) {
|
||||
return customWorld.getCropCache(location);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* [Only works in tripwire mode]
|
||||
* @param block block
|
||||
* @return the block is crop or not
|
||||
*/
|
||||
public static boolean isCropBlock(Block block) {
|
||||
String block_id = CustomCrops.plugin.getCropManager().getCustomInterface().getBlockID(block.getLocation());
|
||||
if (block_id == null) return false;
|
||||
return block_id.contains("_stage_") || block_id.equals(BasicItemConfig.deadCrop);
|
||||
}
|
||||
|
||||
/**
|
||||
* [Only works in item_frame mode]
|
||||
* @param entity entity
|
||||
* @return the entity is crop or not
|
||||
*/
|
||||
public static boolean isCropEntity(Entity entity) {
|
||||
String entity_id = CustomCrops.plugin.getCropManager().getCustomInterface().getEntityID(entity);
|
||||
if (entity_id == null) return false;
|
||||
return entity_id.contains("_stage_") || entity_id.equals(BasicItemConfig.deadCrop);
|
||||
}
|
||||
|
||||
/**
|
||||
* get the cropManager
|
||||
* @return cropManager
|
||||
@@ -53,4 +117,62 @@ public class CropUtils {
|
||||
public static CropManager getCropManager() {
|
||||
return CustomCrops.plugin.getCropManager();
|
||||
}
|
||||
|
||||
/**
|
||||
* get the fertilizer
|
||||
* @param location pot location
|
||||
* @return fertilizer
|
||||
*/
|
||||
@Nullable
|
||||
public static Fertilizer getFertilizer(Location location) {
|
||||
CustomWorld customWorld = CustomCrops.plugin.getCropManager().getCustomWorld(location.getWorld());
|
||||
if (customWorld != null) {
|
||||
return customWorld.getFertilizerCache(location);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* get the wet state
|
||||
* @param location pot location
|
||||
* @return wet or not
|
||||
*/
|
||||
public static boolean isPotWet(Location location) {
|
||||
String block_id = CustomCrops.plugin.getCropManager().getCustomInterface().getBlockID(location);
|
||||
if (block_id == null) return false;
|
||||
return block_id.equals(BasicItemConfig.wetPot);
|
||||
}
|
||||
|
||||
/**
|
||||
* Make a pot dry
|
||||
* @param location pot location
|
||||
*/
|
||||
public static void makePotDry(Location location) {
|
||||
CustomCrops.plugin.getCropManager().makePotDry(location);
|
||||
}
|
||||
|
||||
/**
|
||||
* If the block is a pot
|
||||
* @param location pot location
|
||||
* @return the block is a pot or not
|
||||
*/
|
||||
public static boolean isPotBlock(Location location) {
|
||||
String block_id = CustomCrops.plugin.getCropManager().getCustomInterface().getBlockID(location);
|
||||
if (block_id == null) return false;
|
||||
return block_id.equals(BasicItemConfig.wetPot) || block_id.equals(BasicItemConfig.dryPot);
|
||||
}
|
||||
|
||||
/**
|
||||
* get the sprinkler data
|
||||
* @param location sprinkler location
|
||||
* @return sprinkler data
|
||||
*/
|
||||
@Nullable
|
||||
public static Sprinkler getSprinkler(Location location) {
|
||||
CustomWorld customWorld = CustomCrops.plugin.getCropManager().getCustomWorld(location.getWorld());
|
||||
if (customWorld != null) {
|
||||
return customWorld.getSprinklerCache(location);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -51,12 +51,18 @@ public class SeasonUtils {
|
||||
CustomCrops.plugin.getCropManager().getSeasonAPI().unloadWorld(world);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a season's localization
|
||||
* @param season season
|
||||
* @return localization
|
||||
*/
|
||||
public static String getSeasonText(CCSeason season) {
|
||||
return switch (season) {
|
||||
case SPRING -> MessageConfig.spring;
|
||||
case SUMMER -> MessageConfig.summer;
|
||||
case AUTUMN -> MessageConfig.autumn;
|
||||
case WINTER -> MessageConfig.winter;
|
||||
case UNKNOWN -> "Error";
|
||||
default -> throw new IllegalStateException("Unexpected value: " + season);
|
||||
};
|
||||
}
|
||||
|
||||
@@ -19,8 +19,11 @@
|
||||
package net.momirealms.customcrops.api.utils;
|
||||
|
||||
import net.momirealms.customcrops.CustomCrops;
|
||||
import net.momirealms.customcrops.config.MainConfig;
|
||||
import org.bukkit.World;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class WorldUtils {
|
||||
|
||||
/**
|
||||
@@ -39,4 +42,34 @@ public class WorldUtils {
|
||||
public static void unloadCropWorld(World world, boolean sync) {
|
||||
CustomCrops.plugin.getCropManager().onWorldUnload(world, sync);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a world to the world list
|
||||
* @param world world
|
||||
*/
|
||||
public static void addWorldToWorldList(World world) {
|
||||
MainConfig.worldList.add(world);
|
||||
MainConfig.worlds = MainConfig.worldList.toArray(new World[0]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a world from world list
|
||||
* @param world world
|
||||
* @return success or not
|
||||
*/
|
||||
public static boolean removeWorldFromWorldList(World world) {
|
||||
boolean success = MainConfig.worldList.remove(world);
|
||||
if (success) {
|
||||
MainConfig.worlds = MainConfig.worldList.toArray(new World[0]);
|
||||
}
|
||||
return success;
|
||||
}
|
||||
|
||||
/**
|
||||
* get the world list
|
||||
* @return world list
|
||||
*/
|
||||
public static List<World> getWorldList() {
|
||||
return MainConfig.worldList;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -61,7 +61,6 @@ public class ConfigUtil {
|
||||
}
|
||||
|
||||
public static void reloadConfigs() {
|
||||
|
||||
MainConfig.load();
|
||||
BasicItemConfig.load();
|
||||
CropConfig.load();
|
||||
@@ -71,7 +70,6 @@ public class ConfigUtil {
|
||||
SprinklerConfig.load();
|
||||
WaterCanConfig.load();
|
||||
SoundConfig.load();
|
||||
// would not be activated when enabling
|
||||
if (CustomCrops.plugin.getPlaceholderManager() != null) {
|
||||
CustomCrops.plugin.getPlaceholderManager().unload();
|
||||
CustomCrops.plugin.getPlaceholderManager().load();
|
||||
|
||||
@@ -369,6 +369,13 @@ public class MainConfig {
|
||||
hookMessage("IridiumSkyblock");
|
||||
}
|
||||
}
|
||||
if (config.getBoolean("integration.SuperiorSkyBlock",false)){
|
||||
if (Bukkit.getPluginManager().getPlugin("SuperiorSkyBlock2") == null) Log.warn("Failed to initialize SuperiorSkyBlock!");
|
||||
else {
|
||||
internalAntiGriefs.add(new SuperiorSkyBlockHook());
|
||||
hookMessage("SuperiorSkyBlock");
|
||||
}
|
||||
}
|
||||
|
||||
if (config.getBoolean("integration.AureliumSkills")) {
|
||||
if (Bukkit.getPluginManager().getPlugin("AureliumSkills") == null) Log.warn("Failed to initialize AureliumSkills!");
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package net.momirealms.customcrops.helper;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
|
||||
public class VersionHelper {
|
||||
|
||||
|
||||
@@ -60,4 +60,7 @@ public interface CustomInterface {
|
||||
void addFrameStage(ItemFrame itemFrame, String stage, boolean rotate);
|
||||
|
||||
void addWireStage(Location seedLoc, String stage);
|
||||
|
||||
@Nullable
|
||||
String getEntityID(Entity entity);
|
||||
}
|
||||
|
||||
@@ -143,4 +143,12 @@ public class ItemsAdderHook implements CustomInterface {
|
||||
placeWire(seedLoc, stage);
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public String getEntityID(Entity entity) {
|
||||
CustomFurniture customFurniture = CustomFurniture.byAlreadySpawned(entity);
|
||||
if (customFurniture == null) return null;
|
||||
return customFurniture.getNamespacedID();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,14 +17,11 @@
|
||||
|
||||
package net.momirealms.customcrops.integrations.customplugin.oraxen;
|
||||
|
||||
import dev.lone.itemsadder.api.CustomBlock;
|
||||
import dev.lone.itemsadder.api.CustomStack;
|
||||
import io.th0rgal.oraxen.api.OraxenBlocks;
|
||||
import io.th0rgal.oraxen.api.OraxenItems;
|
||||
import io.th0rgal.oraxen.api.events.OraxenFurnitureBreakEvent;
|
||||
import io.th0rgal.oraxen.api.events.OraxenFurnitureInteractEvent;
|
||||
import io.th0rgal.oraxen.api.events.OraxenNoteBlockBreakEvent;
|
||||
import io.th0rgal.oraxen.api.events.OraxenNoteBlockInteractEvent;
|
||||
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.NoteBlockMechanic;
|
||||
@@ -40,6 +37,7 @@ import net.momirealms.customcrops.objects.Sprinkler;
|
||||
import net.momirealms.customcrops.utils.AdventureUtil;
|
||||
import net.momirealms.customcrops.utils.FurnitureUtil;
|
||||
import net.momirealms.customcrops.utils.MiscUtils;
|
||||
import org.bukkit.BanList;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
|
||||
@@ -136,6 +136,8 @@ public abstract class OraxenHandler extends HandlerP {
|
||||
|
||||
if (block == null) return;
|
||||
|
||||
if (!CCAntiGrief.testPlace(player, block.getLocation())) return;
|
||||
|
||||
if (event.getBlockFace() == BlockFace.UP && placeSprinkler(id, block.getLocation(), player, item)) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -37,6 +37,7 @@ import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.ItemFrame;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.persistence.PersistentDataContainer;
|
||||
import org.bukkit.persistence.PersistentDataType;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@@ -139,4 +140,11 @@ public class OraxenHook implements CustomInterface {
|
||||
public void addWireStage(Location seedLoc, String stage) {
|
||||
Bukkit.getScheduler().runTask(CustomCrops.plugin, () -> placeWire(seedLoc, stage));
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public String getEntityID(Entity entity) {
|
||||
PersistentDataContainer pdc = entity.getPersistentDataContainer();
|
||||
return pdc.get(FURNITURE, PersistentDataType.STRING);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,9 +17,11 @@
|
||||
|
||||
package net.momirealms.customcrops.integrations.customplugin.oraxen;
|
||||
|
||||
import io.th0rgal.oraxen.api.OraxenBlocks;
|
||||
import io.th0rgal.oraxen.api.OraxenItems;
|
||||
import io.th0rgal.oraxen.api.events.*;
|
||||
import io.th0rgal.oraxen.api.events.OraxenFurnitureBreakEvent;
|
||||
import io.th0rgal.oraxen.api.events.OraxenFurnitureInteractEvent;
|
||||
import io.th0rgal.oraxen.api.events.OraxenNoteBlockBreakEvent;
|
||||
import io.th0rgal.oraxen.api.events.OraxenStringBlockBreakEvent;
|
||||
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.stringblock.StringBlockMechanic;
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
package net.momirealms.customcrops.integrations.item;
|
||||
|
||||
import net.Indyuce.mmoitems.MMOItems;
|
||||
import net.Indyuce.mmoitems.api.Type;
|
||||
import net.Indyuce.mmoitems.api.item.mmoitem.MMOItem;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public class MMOItemsHook {
|
||||
|
||||
public static ItemStack get(String id) {
|
||||
id = id.substring(9);
|
||||
String[] split = StringUtils.split(id, ":");
|
||||
MMOItem mmoItem = MMOItems.plugin.getMMOItem(Type.get(split[0]), split[1]);
|
||||
return mmoItem == null ? null : mmoItem.newBuilder().build();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package net.momirealms.customcrops.integrations.item;
|
||||
|
||||
import io.lumine.mythic.bukkit.MythicBukkit;
|
||||
import io.lumine.mythic.core.items.ItemExecutor;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class MythicMobsHook {
|
||||
|
||||
private static ItemExecutor itemManager;
|
||||
|
||||
@Nullable
|
||||
public static ItemStack get(String id) {
|
||||
id = id.substring(11);
|
||||
if (itemManager == null) {
|
||||
itemManager = MythicBukkit.inst().getItemManager();
|
||||
}
|
||||
return itemManager.getItemStack(id);
|
||||
}
|
||||
}
|
||||
@@ -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.integrations.protection;
|
||||
|
||||
import com.bgsoftware.superiorskyblock.api.SuperiorSkyblockAPI;
|
||||
import com.bgsoftware.superiorskyblock.api.island.Island;
|
||||
import com.bgsoftware.superiorskyblock.api.island.IslandPrivilege;
|
||||
import net.momirealms.customcrops.integrations.CCAntiGrief;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class SuperiorSkyBlockHook implements CCAntiGrief {
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "SuperiorSkyBlock";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canBreak(Location location, Player player) {
|
||||
Island island = SuperiorSkyblockAPI.getIslandAt(location);
|
||||
if (island == null) return true;
|
||||
return island.hasPermission(SuperiorSkyblockAPI.getPlayer(player), IslandPrivilege.getByName("BREAK"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canPlace(Location location, Player player) {
|
||||
Island island = SuperiorSkyblockAPI.getIslandAt(location);
|
||||
if (island == null) return true;
|
||||
return island.hasPermission(SuperiorSkyblockAPI.getPlayer(player), IslandPrivilege.getByName("BUILD"));
|
||||
}
|
||||
}
|
||||
@@ -31,6 +31,8 @@ import net.momirealms.customcrops.integrations.customplugin.itemsadder.ItemsAdde
|
||||
import net.momirealms.customcrops.integrations.customplugin.oraxen.OraxenFrameHandler;
|
||||
import net.momirealms.customcrops.integrations.customplugin.oraxen.OraxenHook;
|
||||
import net.momirealms.customcrops.integrations.customplugin.oraxen.OraxenWireHandler;
|
||||
import net.momirealms.customcrops.integrations.item.MMOItemsHook;
|
||||
import net.momirealms.customcrops.integrations.item.MythicMobsHook;
|
||||
import net.momirealms.customcrops.integrations.season.InternalSeason;
|
||||
import net.momirealms.customcrops.integrations.season.RealisticSeasonsHook;
|
||||
import net.momirealms.customcrops.integrations.season.SeasonInterface;
|
||||
@@ -400,6 +402,8 @@ public class CropManager extends Function {
|
||||
private ItemStack getLoot(String id) {
|
||||
if (id == null) return null;
|
||||
if (MiscUtils.isVanillaItem(id)) return new ItemStack(Material.valueOf(id));
|
||||
else if (id.startsWith("MMOItems:")) return MMOItemsHook.get(id);
|
||||
else if (id.startsWith("MythicMobs:")) return MythicMobsHook.get(id);
|
||||
else return customInterface.getItemStack(id);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user