mirror of
https://github.com/Xiao-MoMi/Custom-Crops.git
synced 2025-12-25 09:59:20 +00:00
3.1.2
This commit is contained in:
@@ -21,12 +21,9 @@ import net.momirealms.customcrops.CustomCrops;
|
||||
import net.momirealms.customcrops.api.object.Function;
|
||||
import net.momirealms.customcrops.api.object.basic.ConfigManager;
|
||||
import net.momirealms.customcrops.api.object.pot.PotManager;
|
||||
import net.momirealms.customcrops.api.object.world.SimpleLocation;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.data.type.Farmland;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Cancellable;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
||||
@@ -124,7 +124,7 @@ public interface PlatformInterface {
|
||||
|
||||
@Nullable
|
||||
default ItemFrame getItemFrameAt(Location location) {
|
||||
Collection<ItemFrame> itemFrames = location.clone().add(0.5,0.5,0.5).getNearbyEntitiesByType(ItemFrame.class, 0.5, 0.5, 0.5);
|
||||
Collection<ItemFrame> itemFrames = location.clone().add(0.5,0.5,0.5).getNearbyEntitiesByType(ItemFrame.class, 0.4, 0.5, 0.4);
|
||||
int i = itemFrames.size();
|
||||
int j = 1;
|
||||
for (ItemFrame itemFrame : itemFrames) {
|
||||
@@ -139,7 +139,7 @@ public interface PlatformInterface {
|
||||
|
||||
@Nullable
|
||||
default ItemDisplay getItemDisplayAt(Location location) {
|
||||
Collection<ItemDisplay> itemDisplays = location.clone().add(0.5,0.25,0.5).getNearbyEntitiesByType(ItemDisplay.class, 0.5, 0.5, 0.5);
|
||||
Collection<ItemDisplay> itemDisplays = location.clone().add(0.5,0.25,0.5).getNearbyEntitiesByType(ItemDisplay.class, 0.4, 0.5, 0.4);
|
||||
int i = itemDisplays.size();
|
||||
int j = 1;
|
||||
for (ItemDisplay itemDisplay : itemDisplays) {
|
||||
@@ -163,7 +163,7 @@ public interface PlatformInterface {
|
||||
}
|
||||
|
||||
default void removeInteractions(Location location) {
|
||||
location.clone().add(0.5,0.5,0.5).getNearbyEntitiesByType(Interaction.class, 0.5, 0.5, 0.5).forEach(Entity::remove);
|
||||
location.clone().add(0.5,0.5,0.5).getNearbyEntitiesByType(Interaction.class, 0.4, 0.5, 0.4).forEach(Entity::remove);
|
||||
}
|
||||
|
||||
default boolean removeItemDisplay(Location location) {
|
||||
@@ -179,12 +179,12 @@ public interface PlatformInterface {
|
||||
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);
|
||||
Collection<Entity> entities = location.clone().add(0.5,0.5,0.5).getNearbyEntitiesByType(ItemFrame.class, 0.4, 0.5, 0.4);
|
||||
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,0.5).getNearbyEntitiesByType(ItemDisplay.class, 0.5, 0.5, 0.5);
|
||||
Collection<Entity> entities = location.clone().add(0.5,0,0.5).getNearbyEntitiesByType(ItemDisplay.class, 0.4, 0.5, 0.4);
|
||||
return entities.size() != 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -61,7 +61,6 @@ import org.bukkit.inventory.EquipmentSlot;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import javax.xml.transform.sax.SAXResult;
|
||||
import java.util.*;
|
||||
|
||||
public class PlatformManager extends Function {
|
||||
|
||||
@@ -18,6 +18,9 @@
|
||||
package net.momirealms.customcrops.api.customplugin.oraxen;
|
||||
|
||||
import io.th0rgal.oraxen.api.events.*;
|
||||
import io.th0rgal.oraxen.mechanics.provided.gameplay.furniture.FurnitureMechanic;
|
||||
import io.th0rgal.oraxen.mechanics.provided.gameplay.noteblock.NoteBlockMechanic;
|
||||
import io.th0rgal.oraxen.mechanics.provided.gameplay.stringblock.StringBlockMechanic;
|
||||
import net.momirealms.customcrops.api.customplugin.Handler;
|
||||
import net.momirealms.customcrops.api.customplugin.PlatformManager;
|
||||
import org.bukkit.entity.Entity;
|
||||
@@ -50,17 +53,23 @@ public class OraxenHandler extends Handler {
|
||||
|
||||
@EventHandler
|
||||
public void onPlaceFurniture(OraxenFurniturePlaceEvent event) {
|
||||
platformManager.onPlaceFurniture(event.getPlayer(), event.getBaseEntity().getLocation().getBlock().getLocation(), event.getMechanic().getItemID(), event);
|
||||
FurnitureMechanic mechanic = event.getMechanic();
|
||||
if (mechanic == null) return;
|
||||
platformManager.onPlaceFurniture(event.getPlayer(), event.getBaseEntity().getLocation().getBlock().getLocation(), mechanic.getItemID(), event);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlaceStringBlock(OraxenStringBlockPlaceEvent event) {
|
||||
platformManager.onPlaceBlock(event.getPlayer(), event.getBlock().getLocation(), event.getMechanic().getItemID(), event);
|
||||
StringBlockMechanic mechanic = event.getMechanic();
|
||||
if (mechanic == null) return;
|
||||
platformManager.onPlaceBlock(event.getPlayer(), event.getBlock().getLocation(), mechanic.getItemID(), event);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlaceNoteBlock(OraxenNoteBlockPlaceEvent event) {
|
||||
platformManager.onPlaceBlock(event.getPlayer(), event.getBlock().getLocation(), event.getMechanic().getItemID(), event);
|
||||
NoteBlockMechanic mechanic = event.getMechanic();
|
||||
if (mechanic == null) return;
|
||||
platformManager.onPlaceBlock(event.getPlayer(), event.getBlock().getLocation(), mechanic.getItemID(), event);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
|
||||
@@ -23,7 +23,6 @@ import org.bukkit.entity.Entity;
|
||||
import org.bukkit.event.Cancellable;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.bukkit.event.entity.EntityEvent;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@@ -36,6 +35,9 @@ public class CropBreakEvent extends Event implements Cancellable {
|
||||
private final Location location;
|
||||
private final Entity entity;
|
||||
|
||||
/**
|
||||
* This event might be called when entity breaks the crop or player triggers the break action
|
||||
*/
|
||||
public CropBreakEvent(@Nullable Entity entity, CropConfig cropConfig, String cropItemID, Location location) {
|
||||
this.entity = entity;
|
||||
this.cropConfig = cropConfig;
|
||||
|
||||
@@ -35,6 +35,9 @@ public class CropPlantEvent extends PlayerEvent implements Cancellable {
|
||||
private int point;
|
||||
private String crop_model;
|
||||
|
||||
/**
|
||||
* This event might be called when player plants the crop with a seed or triggers the replant action
|
||||
*/
|
||||
public CropPlantEvent(@NotNull Player who, ItemStack hand, Location location, String crop, int point, String crop_model) {
|
||||
super(who);
|
||||
this.hand = hand;
|
||||
|
||||
@@ -20,12 +20,9 @@ package net.momirealms.customcrops.api.event;
|
||||
import net.momirealms.customcrops.api.object.pot.PotConfig;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Cancellable;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.bukkit.event.entity.EntityEvent;
|
||||
import org.bukkit.event.player.PlayerEvent;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
|
||||
@@ -42,7 +42,6 @@ public class CrowTask extends BukkitRunnable {
|
||||
this.cropLoc = crop_location.clone();
|
||||
this.timer = 0;
|
||||
this.fly = CustomCrops.getInstance().getIntegrationManager().build(fly_model);
|
||||
ItemStack stand = CustomCrops.getInstance().getIntegrationManager().build(stand_model);
|
||||
this.player = player;
|
||||
this.entityID = ThreadLocalRandom.current().nextInt(Integer.MAX_VALUE);
|
||||
this.yaw = ThreadLocalRandom.current().nextInt(361) - 180;
|
||||
@@ -50,7 +49,7 @@ public class CrowTask extends BukkitRunnable {
|
||||
this.vectorUp = new Vector(relative.getX() / 75, 0.1, relative.getZ() / 75);
|
||||
CustomCrops.getProtocolManager().sendServerPacket(player, FakeEntityUtils.getSpawnPacket(entityID, crop_location, EntityType.ARMOR_STAND));
|
||||
CustomCrops.getProtocolManager().sendServerPacket(player, FakeEntityUtils.getVanishArmorStandMetaPacket(entityID));
|
||||
CustomCrops.getProtocolManager().sendServerPacket(player, FakeEntityUtils.getEquipPacket(entityID, stand));
|
||||
CustomCrops.getProtocolManager().sendServerPacket(player, FakeEntityUtils.getEquipPacket(entityID, CustomCrops.getInstance().getIntegrationManager().build(stand_model)));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -21,7 +21,6 @@ import net.momirealms.customcrops.CustomCrops;
|
||||
import net.momirealms.customcrops.api.object.action.Action;
|
||||
import net.momirealms.customcrops.api.object.requirement.Requirement;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class InteractCrop {
|
||||
|
||||
@@ -18,9 +18,12 @@
|
||||
package net.momirealms.customcrops.api.object.action;
|
||||
|
||||
import net.momirealms.customcrops.CustomCrops;
|
||||
import net.momirealms.customcrops.api.event.CropBreakEvent;
|
||||
import net.momirealms.customcrops.api.object.ItemMode;
|
||||
import net.momirealms.customcrops.api.object.crop.CropConfig;
|
||||
import net.momirealms.customcrops.api.object.crop.StageConfig;
|
||||
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.Nullable;
|
||||
@@ -37,24 +40,29 @@ public class BreakImpl implements Action {
|
||||
|
||||
@Override
|
||||
public void doOn(@Nullable Player player, @Nullable SimpleLocation crop_loc, ItemMode itemMode) {
|
||||
if (crop_loc == null) return;
|
||||
CustomCrops.getInstance().getScheduler().callSyncMethod(() -> {
|
||||
if (crop_loc == null || stage_id == null || player == null) return;
|
||||
CropConfig cropConfig = CustomCrops.getInstance().getCropManager().getCropConfigByStage(stage_id);
|
||||
CustomCrops.getInstance().getScheduler().runTask(() -> {
|
||||
Location bLoc = crop_loc.getBukkitLocation();
|
||||
if (bLoc == null) return null;
|
||||
if (bLoc == null) return;
|
||||
CropBreakEvent cropBreakEvent = new CropBreakEvent(player, cropConfig, stage_id, bLoc);
|
||||
Bukkit.getPluginManager().callEvent(cropBreakEvent);
|
||||
if (cropBreakEvent.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
CustomCrops.getInstance().getPlatformInterface().removeAnyThingAt(bLoc);
|
||||
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);
|
||||
if (triggerAction) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
package net.momirealms.customcrops.api.object.action;
|
||||
|
||||
import net.momirealms.customcrops.CustomCrops;
|
||||
import net.momirealms.customcrops.api.event.CropPlantEvent;
|
||||
import net.momirealms.customcrops.api.object.ItemMode;
|
||||
import net.momirealms.customcrops.api.object.basic.ConfigManager;
|
||||
import net.momirealms.customcrops.api.object.basic.MessageManager;
|
||||
@@ -25,6 +26,7 @@ import net.momirealms.customcrops.api.object.crop.CropConfig;
|
||||
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;
|
||||
@@ -43,21 +45,28 @@ public class ReplantImpl implements Action {
|
||||
|
||||
@Override
|
||||
public void doOn(@Nullable Player player, @Nullable SimpleLocation crop_loc, ItemMode itemMode) {
|
||||
if (player == null || crop_loc == null) return;
|
||||
CropConfig cropConfig = CustomCrops.getInstance().getCropManager().getCropConfigByID(crop);
|
||||
if (crop_loc != null && cropConfig != null) {
|
||||
if (cropConfig != null) {
|
||||
ItemMode newCMode = cropConfig.getCropMode();
|
||||
CustomCrops.getInstance().getScheduler().callSyncMethod(() -> {
|
||||
CustomCrops.getInstance().getScheduler().runTask(() -> {
|
||||
Location location = crop_loc.getBukkitLocation();
|
||||
if (location == null) return null;
|
||||
if (location == null) return;
|
||||
if (ConfigManager.enableLimitation && CustomCrops.getInstance().getWorldDataManager().getChunkCropAmount(crop_loc) >= ConfigManager.maxCropPerChunk) {
|
||||
if (player != null)AdventureUtils.playerMessage(player, MessageManager.prefix + MessageManager.reachChunkLimit);
|
||||
return null;
|
||||
AdventureUtils.playerMessage(player, MessageManager.prefix + MessageManager.reachChunkLimit);
|
||||
return;
|
||||
}
|
||||
|
||||
CropPlantEvent cropPlantEvent = new CropPlantEvent(player, player.getInventory().getItemInMainHand(), location, crop, point, model);
|
||||
Bukkit.getPluginManager().callEvent(cropPlantEvent);
|
||||
if (cropPlantEvent.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!CustomCrops.getInstance().getPlatformInterface().detectAnyThing(location)) {
|
||||
CustomCrops.getInstance().getPlatformInterface().placeCustomItem(location, model, newCMode);
|
||||
CustomCrops.getInstance().getWorldDataManager().addCropData(crop_loc, new GrowingCrop(crop, point), true);
|
||||
}
|
||||
return null;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,11 +19,9 @@ 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;
|
||||
|
||||
|
||||
@@ -45,10 +45,7 @@ public class CrowAttack implements Condition {
|
||||
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||
SimpleLocation playerLoc = SimpleLocation.getByBukkitLocation(player.getLocation());
|
||||
if (playerLoc.isNear(simpleLocation, 48)) {
|
||||
CustomCrops.getInstance().getScheduler().callSyncMethod(() -> {
|
||||
new CrowTask(player, location, fly_model, stand_model).runTaskTimerAsynchronously(CustomCrops.getInstance(), 1, 1);
|
||||
return null;
|
||||
});
|
||||
new CrowTask(player, location, fly_model, stand_model).runTaskTimerAsynchronously(CustomCrops.getInstance(), 1, 1);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
|
||||
@@ -21,7 +21,6 @@ import net.momirealms.customcrops.CustomCrops;
|
||||
import net.momirealms.customcrops.api.object.Function;
|
||||
import net.momirealms.customcrops.api.object.basic.ConfigManager;
|
||||
import net.momirealms.customcrops.api.object.fertilizer.FertilizerType;
|
||||
import net.momirealms.customcrops.api.object.fill.PassiveFillMethod;
|
||||
import net.momirealms.customcrops.api.object.hologram.FertilizerHologram;
|
||||
import net.momirealms.customcrops.api.object.hologram.HologramManager;
|
||||
import net.momirealms.customcrops.api.object.hologram.TextDisplayMeta;
|
||||
|
||||
@@ -20,8 +20,6 @@ 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 String[] weathers;
|
||||
|
||||
@@ -19,6 +19,7 @@ package net.momirealms.customcrops.api.object.scheduler;
|
||||
|
||||
import net.momirealms.customcrops.CustomCrops;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.concurrent.Callable;
|
||||
@@ -41,4 +42,9 @@ public class BukkitSchedulerImpl implements SchedulerPlatform {
|
||||
public void runTask(Runnable runnable) {
|
||||
Bukkit.getScheduler().runTask(plugin, runnable);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void runTask(Runnable runnable, Location location) {
|
||||
runTask(runnable);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
package net.momirealms.customcrops.api.object.scheduler;
|
||||
|
||||
import net.momirealms.customcrops.CustomCrops;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.Future;
|
||||
|
||||
public class FoliaSchedulerImpl implements SchedulerPlatform {
|
||||
|
||||
private final CustomCrops plugin;
|
||||
|
||||
public FoliaSchedulerImpl(CustomCrops plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> Future<T> callSyncMethod(@NotNull Callable<T> task) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void runTask(Runnable runnable) {
|
||||
Bukkit.getGlobalRegionScheduler().execute(plugin, runnable);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void runTask(Runnable runnable, Location location) {
|
||||
Bukkit.getRegionScheduler().execute(plugin, location, runnable);
|
||||
}
|
||||
}
|
||||
@@ -17,6 +17,7 @@
|
||||
|
||||
package net.momirealms.customcrops.api.object.scheduler;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.concurrent.Callable;
|
||||
@@ -27,4 +28,6 @@ public interface SchedulerPlatform {
|
||||
<T> Future<T> callSyncMethod(@NotNull Callable<T> task);
|
||||
|
||||
void runTask(Runnable runnable);
|
||||
|
||||
void runTask(Runnable runnable, Location location);
|
||||
}
|
||||
|
||||
@@ -21,6 +21,7 @@ import io.github.battlepass.BattlePlugin;
|
||||
import io.github.battlepass.quests.quests.external.executor.ExternalQuestExecutor;
|
||||
import io.github.battlepass.registry.quest.QuestRegistry;
|
||||
import net.momirealms.customcrops.api.event.CropBreakEvent;
|
||||
import net.momirealms.customcrops.api.event.CropPlantEvent;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
@@ -40,7 +41,16 @@ public class BattlePassCCQuest extends ExternalQuestExecutor implements Listener
|
||||
public void onHarvest(CropBreakEvent event) {
|
||||
if (event.isCancelled()) return;
|
||||
if (event.getEntity() instanceof Player player) {
|
||||
this.execute("harvest", player, (var1x) -> var1x.root(event.getCropItemID()));
|
||||
String id = event.getCropItemID();
|
||||
String[] split = id.split(":");
|
||||
this.execute("harvest", player, (result) -> result.root(split[split.length - 1]));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlant(CropPlantEvent event) {
|
||||
if (event.isCancelled()) return;
|
||||
String id = event.getCrop();
|
||||
this.execute("plant", event.getPlayer(), (result) -> result.root(id));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user