9
0
mirror of https://github.com/Xiao-MoMi/Custom-Crops.git synced 2025-12-21 07:59:16 +00:00
This commit is contained in:
XiaoMoMi
2024-05-05 02:33:39 +08:00
parent 856efc01b7
commit 8716b3022e
23 changed files with 299 additions and 224 deletions

View File

@@ -18,7 +18,6 @@
package net.momirealms.customcrops.api;
import net.momirealms.customcrops.api.manager.*;
import net.momirealms.customcrops.api.mechanic.world.season.Season;
import net.momirealms.customcrops.api.scheduler.Scheduler;
import org.bukkit.plugin.java.JavaPlugin;

View File

@@ -18,6 +18,7 @@
package net.momirealms.customcrops.api.manager;
import net.momirealms.customcrops.api.common.Reloadable;
import net.momirealms.customcrops.api.mechanic.item.ItemCarrier;
import org.bukkit.World;
public abstract class ConfigManager implements Reloadable {
@@ -120,21 +121,33 @@ public abstract class ConfigManager implements Reloadable {
return instance.isConvertWorldOnLoad();
}
protected abstract boolean isConvertWorldOnLoad();
public static boolean scarecrowProtectChunk() {
return instance.doesScarecrowProtectChunk();
}
protected abstract double[] getDefaultQualityRatio();
public static ItemCarrier scarecrowItemCarrier() {
return instance.getScarecrowItemCarrier();
}
protected abstract String getLang();
public static ItemCarrier glassItemCarrier() {
return instance.getGlassItemCarrier();
}
protected abstract boolean getDebugMode();
public abstract boolean isConvertWorldOnLoad();
protected abstract boolean hasLegacyColorSupport();
public abstract double[] getDefaultQualityRatio();
protected abstract int getMaximumPoolSize();
public abstract String getLang();
protected abstract int getKeepAliveTime();
public abstract boolean getDebugMode();
protected abstract int getCorePoolSize();
public abstract boolean hasLegacyColorSupport();
public abstract int getMaximumPoolSize();
public abstract int getKeepAliveTime();
public abstract int getCorePoolSize();
public abstract boolean isProtectLore();
@@ -162,5 +175,11 @@ public abstract class ConfigManager implements Reloadable {
public abstract boolean isSyncSeasons();
public abstract boolean doesScarecrowProtectChunk();
public abstract ItemCarrier getScarecrowItemCarrier();
public abstract ItemCarrier getGlassItemCarrier();
public abstract World getReferenceWorld();
}

View File

@@ -25,8 +25,11 @@ import net.momirealms.customcrops.api.manager.VersionManager;
import net.momirealms.customcrops.api.manager.WorldManager;
import net.momirealms.customcrops.api.mechanic.item.*;
import net.momirealms.customcrops.api.mechanic.requirement.State;
import net.momirealms.customcrops.api.mechanic.world.CustomCropsBlock;
import net.momirealms.customcrops.api.mechanic.world.SimpleLocation;
import net.momirealms.customcrops.api.mechanic.world.level.WorldCrop;
import net.momirealms.customcrops.api.mechanic.world.level.WorldGlass;
import net.momirealms.customcrops.api.mechanic.world.level.WorldPot;
import net.momirealms.customcrops.api.util.EventUtils;
import org.bukkit.Location;
import org.bukkit.Material;
@@ -113,7 +116,7 @@ public abstract class AbstractCustomListener implements Listener {
);
}
@EventHandler (ignoreCancelled = false)
@EventHandler
public void onInteractAir(PlayerInteractEvent event) {
if (event.getHand() != EquipmentSlot.HAND)
return;
@@ -146,10 +149,15 @@ public abstract class AbstractCustomListener implements Listener {
@EventHandler (ignoreCancelled = true)
public void onPlaceBlock(BlockPlaceEvent event) {
final Block block = event.getBlock();
// prevent players from placing blocks on entities (crops/sprinklers)
if (CustomCropsPlugin.get().getWorldManager().getBlockAt(SimpleLocation.of(block.getLocation())).isPresent()) {
event.setCancelled(true);
return;
final Location location = block.getLocation();
Optional<CustomCropsBlock> customCropsBlock = CustomCropsPlugin.get().getWorldManager().getBlockAt(SimpleLocation.of(location));
if (customCropsBlock.isPresent()) {
if (customCropsBlock.get() instanceof WorldPot || customCropsBlock.get() instanceof WorldGlass) {
CustomCropsPlugin.get().getWorldManager().removeAnythingAt(SimpleLocation.of(location));
} else {
event.setCancelled(true);
return;
}
}
this.onPlaceBlock(
event.getPlayer(),

View File

@@ -98,7 +98,6 @@ public class SimpleLocation {
return hash;
}
@Nullable
public Location getBukkitLocation() {
World world = Bukkit.getWorld(worldName);
if (world == null) return null;

View File

@@ -308,6 +308,13 @@ public interface CustomCropsChunk {
*/
void addScarecrowAt(WorldScarecrow scarecrow, SimpleLocation location);
/**
* If this chunk has scarecrow
*
* @return has or not
*/
boolean hasScarecrow();
/**
* Get CustomCrops sections
*

View File

@@ -344,6 +344,8 @@ public interface CustomCropsWorld {
@Nullable
CustomCropsBlock removeAnythingAt(SimpleLocation location);
boolean doesChunkHaveScarecrow(SimpleLocation location);
/**
* If the amount of pot reaches the limitation
*

View File

@@ -18,7 +18,6 @@
package net.momirealms.customcrops.api.mechanic.world.level;
import com.google.gson.annotations.SerializedName;
import net.momirealms.customcrops.api.manager.ConfigManager;
import net.momirealms.customcrops.api.mechanic.world.season.Season;
public class WorldInfoData {

View File

@@ -8,7 +8,7 @@ plugins {
allprojects {
project.group = "net.momirealms"
project.version = "3.4.7-BETA"
project.version = "3.4.7"
apply<JavaPlugin>()
apply(plugin = "java")

View File

@@ -24,6 +24,7 @@ import net.momirealms.customcrops.api.CustomCropsPlugin;
import net.momirealms.customcrops.api.event.CustomCropsReloadEvent;
import net.momirealms.customcrops.api.manager.ConfigManager;
import net.momirealms.customcrops.api.manager.CoolDownManager;
import net.momirealms.customcrops.api.util.EventUtils;
import net.momirealms.customcrops.api.util.LogUtils;
import net.momirealms.customcrops.compatibility.IntegrationManagerImpl;
import net.momirealms.customcrops.libraries.classpath.ReflectionClassPathAppender;
@@ -38,7 +39,6 @@ import net.momirealms.customcrops.mechanic.misc.migrator.Migration;
import net.momirealms.customcrops.mechanic.requirement.RequirementManagerImpl;
import net.momirealms.customcrops.mechanic.world.WorldManagerImpl;
import net.momirealms.customcrops.scheduler.SchedulerImpl;
import net.momirealms.customcrops.api.util.EventUtils;
import org.bstats.bukkit.Metrics;
import org.bukkit.Bukkit;

View File

@@ -25,6 +25,7 @@ import dev.dejvokep.boostedyaml.settings.loader.LoaderSettings;
import dev.dejvokep.boostedyaml.settings.updater.UpdaterSettings;
import net.momirealms.customcrops.api.CustomCropsPlugin;
import net.momirealms.customcrops.api.manager.ConfigManager;
import net.momirealms.customcrops.api.mechanic.item.ItemCarrier;
import net.momirealms.customcrops.api.util.LogUtils;
import net.momirealms.customcrops.util.ConfigUtils;
import org.bukkit.Bukkit;
@@ -35,12 +36,13 @@ import org.bukkit.configuration.file.YamlConfiguration;
import java.io.File;
import java.io.IOException;
import java.lang.ref.WeakReference;
import java.util.Locale;
import java.util.Objects;
public class ConfigManagerImpl extends ConfigManager {
public static final String configVersion = "36";
private CustomCropsPlugin plugin;
public static final String configVersion = "37";
private final CustomCropsPlugin plugin;
private String lang;
private int maximumPoolSize;
private int corePoolSize;
@@ -63,6 +65,9 @@ public class ConfigManagerImpl extends ConfigManager {
private boolean syncSeasons;
private WeakReference<World> referenceWorld;
private boolean convertWorldOnLoad;
private boolean scarecrowProtectChunk;
private ItemCarrier scarecrowItemType;
private ItemCarrier glassItemType;
public ConfigManagerImpl(CustomCropsPlugin plugin) {
this.plugin = plugin;
@@ -126,10 +131,13 @@ public class ConfigManagerImpl extends ConfigManager {
greenhouse = mechanics.getBoolean("greenhouse.enable", true);
greenhouseID = mechanics.getString("greenhouse.id");
greenhouseRange = mechanics.getInt("greenhouse.range", 5);
glassItemType = ItemCarrier.valueOf(mechanics.getString("greenhouse.type", "CHORUS").toUpperCase(Locale.ENGLISH));
scarecrow = mechanics.getBoolean("scarecrow.enable", true);
scarecrowID = mechanics.getString("scarecrow.id");
scarecrowRange = mechanics.getInt("scarecrow.range", 7);
scarecrowProtectChunk = mechanics.getBoolean("scarecrow.protect-chunk", false);
scarecrowItemType = ItemCarrier.valueOf(mechanics.getString("scarecrow.type", "ITEM_FRAME").toUpperCase(Locale.ENGLISH));
syncSeasons = mechanics.getBoolean("sync-season.enable", true);
if (syncSeasons) {
@@ -163,17 +171,17 @@ public class ConfigManagerImpl extends ConfigManager {
}
@Override
protected boolean isConvertWorldOnLoad() {
public boolean isConvertWorldOnLoad() {
return convertWorldOnLoad;
}
@Override
protected double[] getDefaultQualityRatio() {
public double[] getDefaultQualityRatio() {
return defaultQualityRatio;
}
@Override
protected String getLang() {
public String getLang() {
return lang;
}
@@ -247,6 +255,21 @@ public class ConfigManagerImpl extends ConfigManager {
return syncSeasons;
}
@Override
public boolean doesScarecrowProtectChunk() {
return scarecrowProtectChunk;
}
@Override
public ItemCarrier getScarecrowItemCarrier() {
return scarecrowItemType;
}
@Override
public ItemCarrier getGlassItemCarrier() {
return glassItemType;
}
@Override
public World getReferenceWorld() {
return referenceWorld.get();

View File

@@ -48,6 +48,7 @@ import net.momirealms.customcrops.api.mechanic.world.level.WorldCrop;
import net.momirealms.customcrops.api.mechanic.world.level.WorldPot;
import net.momirealms.customcrops.api.mechanic.world.level.WorldSprinkler;
import net.momirealms.customcrops.api.scheduler.CancellableTask;
import net.momirealms.customcrops.api.util.EventUtils;
import net.momirealms.customcrops.api.util.LogUtils;
import net.momirealms.customcrops.compatibility.VaultHook;
import net.momirealms.customcrops.manager.AdventureManagerImpl;
@@ -58,7 +59,6 @@ import net.momirealms.customcrops.mechanic.misc.TempFakeItem;
import net.momirealms.customcrops.mechanic.world.block.MemoryCrop;
import net.momirealms.customcrops.util.ClassUtils;
import net.momirealms.customcrops.util.ConfigUtils;
import net.momirealms.customcrops.api.util.EventUtils;
import net.momirealms.customcrops.util.ItemUtils;
import org.bukkit.*;
import org.bukkit.block.BlockFace;

View File

@@ -168,18 +168,24 @@ public class ConditionManagerImpl implements ConditionManager {
if (Math.random() > chance) return false;
SimpleLocation location = block.getLocation();
if (ConfigManager.enableScarecrow()) {
int range = ConfigManager.scarecrowRange();
Optional<CustomCropsWorld> world = plugin.getWorldManager().getCustomCropsWorld(location.getWorldName());
if (world.isEmpty()) return false;
CustomCropsWorld customCropsWorld = world.get();
for (int i = -range; i <= range; i++) {
for (int j = -range; j <= range; j++) {
for (int k : new int[]{0,-1,1}) {
if (customCropsWorld.getScarecrowAt(location.copy().add(i, k, j)).isPresent()) {
return false;
if (!ConfigManager.scarecrowProtectChunk()) {
int range = ConfigManager.scarecrowRange();
for (int i = -range; i <= range; i++) {
for (int j = -range; j <= range; j++) {
for (int k : new int[]{0,-1,1}) {
if (customCropsWorld.getScarecrowAt(location.copy().add(i, k, j)).isPresent()) {
return false;
}
}
}
}
} else {
if (customCropsWorld.doesChunkHaveScarecrow(location)) {
return false;
}
}
}
if (!offline)

View File

@@ -29,6 +29,7 @@ import net.momirealms.customcrops.api.mechanic.action.ActionTrigger;
import net.momirealms.customcrops.api.mechanic.condition.Conditions;
import net.momirealms.customcrops.api.mechanic.condition.DeathConditions;
import net.momirealms.customcrops.api.mechanic.item.*;
import net.momirealms.customcrops.api.mechanic.item.custom.AbstractCustomListener;
import net.momirealms.customcrops.api.mechanic.item.custom.CustomProvider;
import net.momirealms.customcrops.api.mechanic.item.water.PassiveFillMethod;
import net.momirealms.customcrops.api.mechanic.item.water.PositiveFillMethod;
@@ -39,11 +40,9 @@ import net.momirealms.customcrops.api.mechanic.requirement.State;
import net.momirealms.customcrops.api.mechanic.world.CustomCropsBlock;
import net.momirealms.customcrops.api.mechanic.world.SimpleLocation;
import net.momirealms.customcrops.api.mechanic.world.level.*;
import net.momirealms.customcrops.api.util.EventUtils;
import net.momirealms.customcrops.api.util.LocationUtils;
import net.momirealms.customcrops.api.util.LogUtils;
import net.momirealms.customcrops.api.mechanic.item.custom.AbstractCustomListener;
import net.momirealms.customcrops.mechanic.item.custom.crucible.CrucibleListener;
import net.momirealms.customcrops.mechanic.item.custom.crucible.CrucibleProvider;
import net.momirealms.customcrops.mechanic.item.custom.itemsadder.ItemsAdderListener;
import net.momirealms.customcrops.mechanic.item.custom.itemsadder.ItemsAdderProvider;
import net.momirealms.customcrops.mechanic.item.custom.oraxen.OraxenListener;
@@ -61,7 +60,6 @@ import net.momirealms.customcrops.mechanic.item.impl.WateringCanConfig;
import net.momirealms.customcrops.mechanic.item.impl.fertilizer.*;
import net.momirealms.customcrops.mechanic.world.block.*;
import net.momirealms.customcrops.util.ConfigUtils;
import net.momirealms.customcrops.api.util.EventUtils;
import net.momirealms.customcrops.util.ItemUtils;
import net.momirealms.customcrops.util.RotationUtils;
import org.bukkit.*;
@@ -140,8 +138,8 @@ public class ItemManagerImpl implements ItemManager {
listener = new ItemsAdderListener(this);
customProvider = new ItemsAdderProvider();
} else if (Bukkit.getPluginManager().getPlugin("MythicCrucible") != null) {
listener = new CrucibleListener(this);
customProvider = new CrucibleProvider();
// listener = new CrucibleListener(this);
// customProvider = new CrucibleProvider();
} else {
LogUtils.severe("======================================================");
LogUtils.severe(" Please install ItemsAdder or Oraxen as dependency.");

View File

@@ -1,56 +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.mechanic.item.custom.crucible;
import io.lumine.mythiccrucible.events.MythicFurniturePlaceEvent;
import net.momirealms.customcrops.mechanic.item.ItemManagerImpl;
import net.momirealms.customcrops.api.mechanic.item.custom.AbstractCustomListener;
import org.bukkit.event.EventHandler;
public class CrucibleListener extends AbstractCustomListener {
public CrucibleListener(ItemManagerImpl itemManager) {
super(itemManager);
}
@EventHandler (ignoreCancelled = true)
public void onBreakCustomBlock() {
}
@EventHandler (ignoreCancelled = true)
public void onPlaceCustomBlock() {
}
@EventHandler (ignoreCancelled = true)
public void onPlaceFurniture(MythicFurniturePlaceEvent event) {
super.onPlaceFurniture(
event.getPlayer(),
event.getBlock().getLocation(),
event.getFurnitureItemContext().getItem().getInternalName(),
event
);
}
@EventHandler (ignoreCancelled = true)
public void onBreakFurniture() {
}
@EventHandler (ignoreCancelled = true)
public void onInteractFurniture() {
}
}
///*
// * 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.mechanic.item.custom.crucible;
//
//import net.momirealms.customcrops.mechanic.item.ItemManagerImpl;
//import net.momirealms.customcrops.api.mechanic.item.custom.AbstractCustomListener;
//import org.bukkit.event.EventHandler;
//
//public class CrucibleListener extends AbstractCustomListener {
//
// public CrucibleListener(ItemManagerImpl itemManager) {
// super(itemManager);
// }
//
// @EventHandler (ignoreCancelled = true)
// public void onBreakCustomBlock() {
// }
//
// @EventHandler (ignoreCancelled = true)
// public void onPlaceCustomBlock() {
// }
//
// @EventHandler (ignoreCancelled = true)
// public void onPlaceFurniture() {
// }
//
// @EventHandler (ignoreCancelled = true)
// public void onBreakFurniture() {
// }
//
// @EventHandler (ignoreCancelled = true)
// public void onInteractFurniture() {
// }
//}

View File

@@ -1,124 +1,124 @@
/*
* 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.mechanic.item.custom.crucible;
import io.lumine.mythic.bukkit.BukkitAdapter;
import io.lumine.mythic.bukkit.adapters.BukkitEntity;
import io.lumine.mythiccrucible.MythicCrucible;
import io.lumine.mythiccrucible.items.CrucibleItem;
import io.lumine.mythiccrucible.items.ItemManager;
import io.lumine.mythiccrucible.items.blocks.CustomBlockItemContext;
import io.lumine.mythiccrucible.items.blocks.CustomBlockManager;
import io.lumine.mythiccrucible.items.furniture.Furniture;
import io.lumine.mythiccrucible.items.furniture.FurnitureManager;
import net.momirealms.customcrops.api.util.LogUtils;
import net.momirealms.customcrops.api.mechanic.item.custom.CustomProvider;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.entity.Entity;
import org.bukkit.inventory.ItemStack;
import java.util.Optional;
public class CrucibleProvider implements CustomProvider {
private final ItemManager itemManager;
private final CustomBlockManager blockManager;
private final FurnitureManager furnitureManager;
public CrucibleProvider() {
this.itemManager = MythicCrucible.inst().getItemManager();
this.blockManager = itemManager.getCustomBlockManager();
this.furnitureManager = itemManager.getFurnitureManager();
}
@Override
public boolean removeBlock(Location location) {
Block block = location.getBlock();
if (block.getType() == Material.AIR) {
return false;
}
Optional<CustomBlockItemContext> optional = blockManager.getBlockFromBlock(block);
if (optional.isPresent()) {
optional.get().remove(block, null, false);
} else {
block.setType(Material.AIR);
}
return true;
}
@Override
public void placeCustomBlock(Location location, String id) {
Optional<CrucibleItem> optionalCI = itemManager.getItem(id);
if (optionalCI.isPresent()) {
location.getBlock().setBlockData(optionalCI.get().getBlockData().getBlockData());
} else {
LogUtils.warn("Custom block(" + id +") doesn't exist in Crucible configs. Please double check if that block exists.");
}
}
@Override
public Entity placeFurniture(Location location, String id) {
Optional<CrucibleItem> optionalCI = itemManager.getItem(id);
if (optionalCI.isPresent()) {
return optionalCI.get().getFurnitureData().placeFrame(location.getBlock(), BlockFace.UP, 0f, null);
} else {
LogUtils.warn("Furniture(" + id +") doesn't exist in Crucible configs. Please double check if that furniture exists.");
return null;
}
}
@Override
public void removeFurniture(Entity entity) {
Optional<Furniture> optional = furnitureManager.getFurniture(entity.getUniqueId());
optional.ifPresent(furniture -> furniture.getFurnitureData().remove(furniture, null, false, false));
}
@Override
public String getBlockID(Block block) {
Optional<CustomBlockItemContext> optionalCB = blockManager.getBlockFromBlock(block);
return optionalCB.map(customBlockItemContext -> customBlockItemContext.getCrucibleItem().getInternalName()).orElse(block.getType().name());
}
@Override
public String getItemID(ItemStack itemStack) {
return itemManager.getItem(itemStack).map(CrucibleItem::getInternalName).orElse(null);
}
@Override
public ItemStack getItemStack(String id) {
Optional<CrucibleItem> optionalCI = itemManager.getItem(id);
return optionalCI.map(crucibleItem -> BukkitAdapter.adapt(crucibleItem.getMythicItem().generateItemStack(1))).orElse(null);
}
@Override
public String getEntityID(Entity entity) {
Optional<CrucibleItem> optionalCI = furnitureManager.getItemFromEntity(entity);
if (optionalCI.isPresent()) {
return optionalCI.get().getInternalName();
}
return entity.getType().name();
}
@Override
public boolean isFurniture(Entity entity) {
return furnitureManager.isFurniture(new BukkitEntity(entity));
}
}
///*
// * 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.mechanic.item.custom.crucible;
//
//import io.lumine.mythic.bukkit.BukkitAdapter;
//import io.lumine.mythic.bukkit.adapters.BukkitEntity;
//import io.lumine.mythiccrucible.MythicCrucible;
//import io.lumine.mythiccrucible.items.CrucibleItem;
//import io.lumine.mythiccrucible.items.ItemManager;
//import io.lumine.mythiccrucible.items.blocks.CustomBlockItemContext;
//import io.lumine.mythiccrucible.items.blocks.CustomBlockManager;
//import io.lumine.mythiccrucible.items.furniture.Furniture;
//import io.lumine.mythiccrucible.items.furniture.FurnitureManager;
//import net.momirealms.customcrops.api.util.LogUtils;
//import net.momirealms.customcrops.api.mechanic.item.custom.CustomProvider;
//import org.bukkit.Location;
//import org.bukkit.Material;
//import org.bukkit.block.Block;
//import org.bukkit.block.BlockFace;
//import org.bukkit.entity.Entity;
//import org.bukkit.inventory.ItemStack;
//
//import java.util.Optional;
//
//public class CrucibleProvider implements CustomProvider {
//
// private final ItemManager itemManager;
// private final CustomBlockManager blockManager;
// private final FurnitureManager furnitureManager;
//
// public CrucibleProvider() {
// this.itemManager = MythicCrucible.inst().getItemManager();
// this.blockManager = itemManager.getCustomBlockManager();
// this.furnitureManager = itemManager.getFurnitureManager();
// }
//
// @Override
// public boolean removeBlock(Location location) {
// Block block = location.getBlock();
// if (block.getType() == Material.AIR) {
// return false;
// }
// Optional<CustomBlockItemContext> optional = blockManager.getBlockFromBlock(block);
// if (optional.isPresent()) {
// optional.get().remove(block, null, false);
// } else {
// block.setType(Material.AIR);
// }
// return true;
// }
//
// @Override
// public void placeCustomBlock(Location location, String id) {
// Optional<CrucibleItem> optionalCI = itemManager.getItem(id);
// if (optionalCI.isPresent()) {
// location.getBlock().setBlockData(optionalCI.get().getBlockData().getBlockData());
// } else {
// LogUtils.warn("Custom block(" + id +") doesn't exist in Crucible configs. Please double check if that block exists.");
// }
// }
//
// @Override
// public Entity placeFurniture(Location location, String id) {
// Optional<CrucibleItem> optionalCI = itemManager.getItem(id);
// if (optionalCI.isPresent()) {
// return optionalCI.get().getFurnitureData().placeFrame(location.getBlock(), BlockFace.UP, 0f, null);
// } else {
// LogUtils.warn("Furniture(" + id +") doesn't exist in Crucible configs. Please double check if that furniture exists.");
// return null;
// }
// }
//
// @Override
// public void removeFurniture(Entity entity) {
// Optional<Furniture> optional = furnitureManager.getFurniture(entity.getUniqueId());
// optional.ifPresent(furniture -> furniture.getFurnitureData().remove(furniture, null, false, false));
// }
//
// @Override
// public String getBlockID(Block block) {
// Optional<CustomBlockItemContext> optionalCB = blockManager.getBlockFromBlock(block);
// return optionalCB.map(customBlockItemContext -> customBlockItemContext.getCrucibleItem().getInternalName()).orElse(block.getType().name());
// }
//
// @Override
// public String getItemID(ItemStack itemStack) {
// return itemManager.getItem(itemStack).map(CrucibleItem::getInternalName).orElse(null);
// }
//
// @Override
// public ItemStack getItemStack(String id) {
// Optional<CrucibleItem> optionalCI = itemManager.getItem(id);
// return optionalCI.map(crucibleItem -> BukkitAdapter.adapt(crucibleItem.getMythicItem().generateItemStack(1))).orElse(null);
// }
//
// @Override
// public String getEntityID(Entity entity) {
// Optional<CrucibleItem> optionalCI = furnitureManager.getItemFromEntity(entity);
// if (optionalCI.isPresent()) {
// return optionalCI.get().getInternalName();
// }
// return entity.getType().name();
// }
//
// @Override
// public boolean isFurniture(Entity entity) {
// return furnitureManager.isFurniture(new BukkitEntity(entity));
// }
//}

View File

@@ -19,8 +19,8 @@ package net.momirealms.customcrops.mechanic.item.custom.itemsadder;
import dev.lone.itemsadder.api.CustomFurniture;
import dev.lone.itemsadder.api.Events.*;
import net.momirealms.customcrops.mechanic.item.ItemManagerImpl;
import net.momirealms.customcrops.api.mechanic.item.custom.AbstractCustomListener;
import net.momirealms.customcrops.mechanic.item.ItemManagerImpl;
import org.bukkit.entity.Entity;
import org.bukkit.event.EventHandler;

View File

@@ -20,8 +20,8 @@ package net.momirealms.customcrops.mechanic.item.custom.itemsadder;
import dev.lone.itemsadder.api.CustomBlock;
import dev.lone.itemsadder.api.CustomFurniture;
import dev.lone.itemsadder.api.CustomStack;
import net.momirealms.customcrops.api.util.LogUtils;
import net.momirealms.customcrops.api.mechanic.item.custom.CustomProvider;
import net.momirealms.customcrops.api.util.LogUtils;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;

View File

@@ -24,9 +24,9 @@ import io.th0rgal.oraxen.api.events.custom_block.stringblock.OraxenStringBlockPl
import io.th0rgal.oraxen.api.events.furniture.OraxenFurnitureBreakEvent;
import io.th0rgal.oraxen.api.events.furniture.OraxenFurnitureInteractEvent;
import io.th0rgal.oraxen.api.events.furniture.OraxenFurniturePlaceEvent;
import net.momirealms.customcrops.api.mechanic.item.custom.AbstractCustomListener;
import net.momirealms.customcrops.api.util.LocationUtils;
import net.momirealms.customcrops.mechanic.item.ItemManagerImpl;
import net.momirealms.customcrops.api.mechanic.item.custom.AbstractCustomListener;
import org.bukkit.event.EventHandler;
public class OraxenListener extends AbstractCustomListener {

View File

@@ -23,8 +23,8 @@ 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.furniture.FurnitureMechanic;
import net.momirealms.customcrops.api.util.LogUtils;
import net.momirealms.customcrops.api.mechanic.item.custom.CustomProvider;
import net.momirealms.customcrops.api.util.LogUtils;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.Rotation;

View File

@@ -553,6 +553,18 @@ public class CChunk implements CustomCropsChunk {
return amount;
}
@Override
public boolean hasScarecrow() {
for (CustomCropsSection section : getSections()) {
for (CustomCropsBlock block : section.getBlocks()) {
if (block instanceof WorldScarecrow) {
return true;
}
}
}
return false;
}
public CSection[] getSectionsForSerialization() {
ArrayList<CSection> sections = new ArrayList<>();
for (Map.Entry<Integer, CSection> entry : loadedSections.entrySet()) {

View File

@@ -35,8 +35,8 @@ import net.momirealms.customcrops.api.mechanic.world.level.*;
import net.momirealms.customcrops.api.mechanic.world.season.Season;
import net.momirealms.customcrops.api.scheduler.CancellableTask;
import net.momirealms.customcrops.api.scheduler.Scheduler;
import net.momirealms.customcrops.api.util.LogUtils;
import net.momirealms.customcrops.api.util.EventUtils;
import net.momirealms.customcrops.api.util.LogUtils;
import org.bukkit.Bukkit;
import org.bukkit.World;
import org.jetbrains.annotations.NotNull;
@@ -525,7 +525,7 @@ public class CWorld implements CustomCropsWorld {
if (chunk != null) {
return chunk;
}
// is a loaded chunk, but it doesn't have customcrops data
// is a loaded chunk, but it doesn't have CustomCrops data
if (bukkitWorld.isChunkLoaded(chunkPos.x(), chunkPos.z())) {
chunk = new CChunk(this, chunkPos);
loadChunk(chunk);
@@ -535,6 +535,12 @@ public class CWorld implements CustomCropsWorld {
}
}
@Override
public boolean doesChunkHaveScarecrow(SimpleLocation location) {
Optional<CustomCropsChunk> chunk = getLoadedChunkAt(location.getChunkPos());
return chunk.map(CustomCropsChunk::hasScarecrow).orElse(false);
}
@Override
public boolean isPotReachLimit(SimpleLocation location) {
Optional<CustomCropsChunk> chunk = getLoadedChunkAt(location.getChunkPos());

View File

@@ -27,7 +27,6 @@ import net.momirealms.customcrops.api.mechanic.item.ItemType;
import net.momirealms.customcrops.api.mechanic.item.Pot;
import net.momirealms.customcrops.api.mechanic.world.SimpleLocation;
import net.momirealms.customcrops.api.mechanic.world.level.AbstractCustomCropsBlock;
import net.momirealms.customcrops.api.mechanic.world.level.CustomCropsChunk;
import net.momirealms.customcrops.api.mechanic.world.level.WorldPot;
import net.momirealms.customcrops.api.util.LogUtils;
import org.bukkit.Location;

View File

@@ -1,5 +1,5 @@
# Don't change
config-version: '36'
config-version: '37'
# Debug
debug: false
@@ -102,12 +102,17 @@ mechanics:
scarecrow:
enable: true
id: '{0}scarecrow'
type: ITEM_FRAME
range: 7
# If this option is enabled, the range above would not longer take effect
# This option would make the scarecrow protect all the crops in a chunk instead of crops in certain range
protect-chunk: false
# Greenhouse glass prevents crops from withering from season changing
greenhouse:
enable: true
id: '{0}greenhouse_glass'
type: CHORUS
range: 5
# Sync seasons