mirror of
https://github.com/Xiao-MoMi/Custom-Crops.git
synced 2026-01-06 15:51:52 +00:00
2.2.1
This commit is contained in:
@@ -4,7 +4,7 @@ plugins {
|
|||||||
}
|
}
|
||||||
|
|
||||||
group = 'net.momirealms'
|
group = 'net.momirealms'
|
||||||
version = '2.2.0'
|
version = '2.2.1'
|
||||||
|
|
||||||
repositories {
|
repositories {
|
||||||
mavenCentral()
|
mavenCentral()
|
||||||
@@ -58,7 +58,7 @@ 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.6'
|
||||||
compileOnly 'commons-io:commons-io:2.11.0'
|
compileOnly 'commons-io:commons-io:2.11.0'
|
||||||
compileOnly 'com.github.angeschossen:LandsAPI:6.5.1'
|
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.17.1-R0.1-SNAPSHOT'
|
||||||
compileOnly 'me.clip:placeholderapi:2.11.2'
|
compileOnly 'me.clip:placeholderapi:2.11.2'
|
||||||
|
|||||||
@@ -17,26 +17,29 @@
|
|||||||
|
|
||||||
package net.momirealms.customcrops.api.event;
|
package net.momirealms.customcrops.api.event;
|
||||||
|
|
||||||
import de.tr7zw.changeme.nbtapi.NBTItem;
|
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.Cancellable;
|
import org.bukkit.event.Cancellable;
|
||||||
import org.bukkit.event.HandlerList;
|
import org.bukkit.event.HandlerList;
|
||||||
import org.bukkit.event.player.PlayerEvent;
|
import org.bukkit.event.player.PlayerEvent;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
public class WaterPotEvent extends PlayerEvent implements Cancellable {
|
public class WaterPotEvent extends PlayerEvent implements Cancellable {
|
||||||
|
|
||||||
private static final HandlerList handlers = new HandlerList();
|
private static final HandlerList handlers = new HandlerList();
|
||||||
private boolean cancelled;
|
private boolean cancelled;
|
||||||
private final NBTItem nbtItem;
|
private final ItemStack itemStack;
|
||||||
private int currentWater;
|
private int currentWater;
|
||||||
private final Location location;
|
private final Location location;
|
||||||
|
|
||||||
public WaterPotEvent(@NotNull Player who, Location location, NBTItem nbtItem, int currentWater) {
|
/**
|
||||||
|
* ItemStack can be a water-bucket or a watering-can
|
||||||
|
*/
|
||||||
|
public WaterPotEvent(@NotNull Player who, Location location, ItemStack itemStack, int currentWater) {
|
||||||
super(who);
|
super(who);
|
||||||
this.cancelled = false;
|
this.cancelled = false;
|
||||||
this.nbtItem = nbtItem;
|
this.itemStack = itemStack;
|
||||||
this.currentWater = currentWater;
|
this.currentWater = currentWater;
|
||||||
this.location = location;
|
this.location = location;
|
||||||
}
|
}
|
||||||
@@ -62,8 +65,8 @@ public class WaterPotEvent extends PlayerEvent implements Cancellable {
|
|||||||
return getHandlerList();
|
return getHandlerList();
|
||||||
}
|
}
|
||||||
|
|
||||||
public NBTItem getNbtItem() {
|
public ItemStack getItemStack() {
|
||||||
return nbtItem;
|
return itemStack;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getCurrentWater() {
|
public int getCurrentWater() {
|
||||||
|
|||||||
@@ -17,6 +17,7 @@
|
|||||||
|
|
||||||
package net.momirealms.customcrops.integrations.customplugin;
|
package net.momirealms.customcrops.integrations.customplugin;
|
||||||
|
|
||||||
|
import com.willfp.eco.core.items.Items;
|
||||||
import de.tr7zw.changeme.nbtapi.NBTCompound;
|
import de.tr7zw.changeme.nbtapi.NBTCompound;
|
||||||
import de.tr7zw.changeme.nbtapi.NBTItem;
|
import de.tr7zw.changeme.nbtapi.NBTItem;
|
||||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||||
@@ -314,7 +315,6 @@ public abstract class HandlerP extends Function {
|
|||||||
if (player.getGameMode() != GameMode.CREATIVE) item.setAmount(item.getAmount() - 1);
|
if (player.getGameMode() != GameMode.CREATIVE) item.setAmount(item.getAmount() - 1);
|
||||||
customWorld.addSprinklerCache(sprinklerLoc, sprinkler);
|
customWorld.addSprinklerCache(sprinklerLoc, sprinkler);
|
||||||
customInterface.placeFurniture(sprinklerLoc, config.getThreeD());
|
customInterface.placeFurniture(sprinklerLoc, config.getThreeD());
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
@@ -639,6 +639,20 @@ public abstract class HandlerP extends Function {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected boolean useBucket(Location potLoc, Player player, ItemStack itemInHand) {
|
||||||
|
if (itemInHand.getType() == Material.WATER_BUCKET) {
|
||||||
|
WaterPotEvent waterPotEvent = new WaterPotEvent(player, potLoc, itemInHand, 0);
|
||||||
|
Bukkit.getPluginManager().callEvent(waterPotEvent);
|
||||||
|
if (waterPotEvent.isCancelled()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
itemInHand.setType(Material.BUCKET);
|
||||||
|
waterPot(1,1, potLoc, 0);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
protected boolean isInCoolDown(Player player, int delay) {
|
protected boolean isInCoolDown(Player player, int delay) {
|
||||||
long time = System.currentTimeMillis();
|
long time = System.currentTimeMillis();
|
||||||
if (time - (coolDown.getOrDefault(player, time - delay)) < delay) return true;
|
if (time - (coolDown.getOrDefault(player, time - delay)) < delay) return true;
|
||||||
|
|||||||
@@ -125,8 +125,12 @@ public abstract class ItemsAdderHandler extends HandlerP {
|
|||||||
public boolean tryMisc(Player player, ItemStack itemInHand, Location potLoc) {
|
public boolean tryMisc(Player player, ItemStack itemInHand, Location potLoc) {
|
||||||
if (!AntiGrief.testPlace(player, potLoc)) return true;
|
if (!AntiGrief.testPlace(player, potLoc)) return true;
|
||||||
if (itemInHand == null || itemInHand.getType() == Material.AIR) return true;
|
if (itemInHand == null || itemInHand.getType() == Material.AIR) return true;
|
||||||
CustomStack customStack = CustomStack.byItemStack(itemInHand);
|
|
||||||
|
|
||||||
|
if (useBucket(potLoc, player, itemInHand)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
CustomStack customStack = CustomStack.byItemStack(itemInHand);
|
||||||
if (customStack == null) return false;
|
if (customStack == null) return false;
|
||||||
String itemID = customStack.getNamespacedID();
|
String itemID = customStack.getNamespacedID();
|
||||||
|
|
||||||
@@ -153,17 +157,17 @@ public abstract class ItemsAdderHandler extends HandlerP {
|
|||||||
int water = nbtItem.getInteger("WaterAmount");
|
int water = nbtItem.getInteger("WaterAmount");
|
||||||
if (water > 0) {
|
if (water > 0) {
|
||||||
|
|
||||||
WaterPotEvent waterPotEvent = new WaterPotEvent(player, potLoc, nbtItem, --water);
|
WaterPotEvent waterPotEvent = new WaterPotEvent(player, potLoc, itemStack, --water);
|
||||||
Bukkit.getPluginManager().callEvent(waterPotEvent);
|
Bukkit.getPluginManager().callEvent(waterPotEvent);
|
||||||
if (waterPotEvent.isCancelled()) {
|
if (waterPotEvent.isCancelled()) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
nbtItem = new NBTItem(waterPotEvent.getItemStack());
|
||||||
NBTCompound nbtCompound = nbtItem.getCompound("itemsadder");
|
NBTCompound nbtCompound = nbtItem.getCompound("itemsadder");
|
||||||
if (nbtCompound.hasKey("custom_durability")){
|
if (nbtCompound.hasTag("custom_durability")){
|
||||||
int dur = nbtCompound.getInteger("custom_durability");
|
int dur = nbtCompound.getInteger("custom_durability");
|
||||||
int max_dur = nbtCompound.getInteger("max_custom_durability");
|
int max_dur = nbtCompound.getInteger("max_custom_durability");
|
||||||
if (dur > 0){
|
if (dur > 0) {
|
||||||
nbtCompound.setInteger("custom_durability", dur - 1);
|
nbtCompound.setInteger("custom_durability", dur - 1);
|
||||||
nbtCompound.setDouble("fake_durability", (int) itemStack.getType().getMaxDurability() * (double) (dur/max_dur));
|
nbtCompound.setDouble("fake_durability", (int) itemStack.getType().getMaxDurability() * (double) (dur/max_dur));
|
||||||
nbtItem.setInteger("Damage", (int) (itemStack.getType().getMaxDurability() * (1 - (double) dur/max_dur)));
|
nbtItem.setInteger("Damage", (int) (itemStack.getType().getMaxDurability() * (1 - (double) dur/max_dur)));
|
||||||
|
|||||||
@@ -88,6 +88,11 @@ public abstract class OraxenHandler extends HandlerP {
|
|||||||
public boolean tryMisc(Player player, ItemStack itemInHand, Location potLoc) {
|
public boolean tryMisc(Player player, ItemStack itemInHand, Location potLoc) {
|
||||||
if (!AntiGrief.testPlace(player, potLoc)) return true;
|
if (!AntiGrief.testPlace(player, potLoc)) return true;
|
||||||
if (itemInHand == null || itemInHand.getType() == Material.AIR) return true;
|
if (itemInHand == null || itemInHand.getType() == Material.AIR) return true;
|
||||||
|
|
||||||
|
if (useBucket(potLoc, player, itemInHand)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
String id = OraxenItems.getIdByItem(itemInHand);
|
String id = OraxenItems.getIdByItem(itemInHand);
|
||||||
if (id == null) return false;
|
if (id == null) return false;
|
||||||
|
|
||||||
@@ -100,6 +105,7 @@ public abstract class OraxenHandler extends HandlerP {
|
|||||||
if (useWateringCan(potLoc, id, player, itemInHand)) {
|
if (useWateringCan(potLoc, id, player, itemInHand)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
//for future misc
|
//for future misc
|
||||||
}
|
}
|
||||||
@@ -146,12 +152,13 @@ public abstract class OraxenHandler extends HandlerP {
|
|||||||
int water = nbtItem.getInteger("WaterAmount");
|
int water = nbtItem.getInteger("WaterAmount");
|
||||||
if (water > 0) {
|
if (water > 0) {
|
||||||
|
|
||||||
WaterPotEvent waterPotEvent = new WaterPotEvent(player, potLoc, nbtItem, --water);
|
WaterPotEvent waterPotEvent = new WaterPotEvent(player, potLoc, can, --water);
|
||||||
Bukkit.getPluginManager().callEvent(waterPotEvent);
|
Bukkit.getPluginManager().callEvent(waterPotEvent);
|
||||||
if (waterPotEvent.isCancelled()) {
|
if (waterPotEvent.isCancelled()) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
nbtItem = new NBTItem(waterPotEvent.getItemStack());
|
||||||
nbtItem.setInteger("WaterAmount", waterPotEvent.getCurrentWater());
|
nbtItem.setInteger("WaterAmount", waterPotEvent.getCurrentWater());
|
||||||
|
|
||||||
if (SoundConfig.waterPot.isEnable()) {
|
if (SoundConfig.waterPot.isEnable()) {
|
||||||
|
|||||||
@@ -17,26 +17,42 @@
|
|||||||
|
|
||||||
package net.momirealms.customcrops.integrations.protection;
|
package net.momirealms.customcrops.integrations.protection;
|
||||||
|
|
||||||
|
import me.angeschossen.lands.api.LandsIntegration;
|
||||||
import me.angeschossen.lands.api.flags.Flags;
|
import me.angeschossen.lands.api.flags.Flags;
|
||||||
|
import me.angeschossen.lands.api.flags.enums.FlagTarget;
|
||||||
|
import me.angeschossen.lands.api.flags.enums.RoleFlagCategory;
|
||||||
|
import me.angeschossen.lands.api.flags.types.RoleFlag;
|
||||||
import me.angeschossen.lands.api.land.Area;
|
import me.angeschossen.lands.api.land.Area;
|
||||||
|
import me.angeschossen.lands.api.land.LandWorld;
|
||||||
import net.momirealms.customcrops.CustomCrops;
|
import net.momirealms.customcrops.CustomCrops;
|
||||||
import net.momirealms.customcrops.integrations.AntiGrief;
|
import net.momirealms.customcrops.integrations.AntiGrief;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.Material;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
public class LandsHook implements AntiGrief {
|
public class LandsHook implements AntiGrief {
|
||||||
|
|
||||||
|
private final LandsIntegration api;
|
||||||
|
|
||||||
|
public LandsHook() {
|
||||||
|
api = LandsIntegration.of(CustomCrops.plugin);;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean canBreak(Location location, Player player) {
|
public boolean canBreak(Location location, Player player) {
|
||||||
Area area = new me.angeschossen.lands.api.integration.LandsIntegration(CustomCrops.plugin).getAreaByLoc(location);
|
LandWorld world = api.getWorld(location.getWorld());
|
||||||
if (area != null) return area.hasFlag(player, Flags.BLOCK_BREAK, false);
|
if (world != null) {
|
||||||
else return true;
|
return world.hasRoleFlag(player.getUniqueId(), location, RoleFlag.of("BLOCK_BREAK"));
|
||||||
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean canPlace(Location location, Player player) {
|
public boolean canPlace(Location location, Player player) {
|
||||||
Area area = new me.angeschossen.lands.api.integration.LandsIntegration(CustomCrops.plugin).getAreaByLoc(location);
|
LandWorld world = api.getWorld(location.getWorld());
|
||||||
if (area != null) return area.hasFlag(player, Flags.BLOCK_PLACE, false);
|
if (world != null) {
|
||||||
else return true;
|
return world.hasRoleFlag(player.getUniqueId(), location, RoleFlag.of("BLOCK_PLACE"));
|
||||||
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -64,7 +64,6 @@ public class CustomWorld {
|
|||||||
private int timer;
|
private int timer;
|
||||||
|
|
||||||
public CustomWorld(World world, CropManager cropManager) {
|
public CustomWorld(World world, CropManager cropManager) {
|
||||||
|
|
||||||
this.world = world;
|
this.world = world;
|
||||||
this.fertilizerCache = new ConcurrentHashMap<>(2048);
|
this.fertilizerCache = new ConcurrentHashMap<>(2048);
|
||||||
this.sprinklerCache = new ConcurrentHashMap<>(512);
|
this.sprinklerCache = new ConcurrentHashMap<>(512);
|
||||||
@@ -370,10 +369,14 @@ public class CustomWorld {
|
|||||||
}
|
}
|
||||||
else if (!compensation) {
|
else if (!compensation) {
|
||||||
route(sprinklerTime);
|
route(sprinklerTime);
|
||||||
potDryJudge(sprinklerTime + randomGenerator.nextInt(dryTime));
|
|
||||||
for (Map.Entry<SimpleLocation, GrowingCrop> entry : cropData.entrySet()) {
|
for (Map.Entry<SimpleLocation, GrowingCrop> entry : cropData.entrySet()) {
|
||||||
growSingleWire(entry.getKey(), entry.getValue(), sprinklerTime + dryTime + randomGenerator.nextInt(cropTime));
|
growSingleWire(entry.getKey(), entry.getValue(), sprinklerTime + dryTime + randomGenerator.nextInt(cropTime));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Bukkit.getScheduler().runTaskLaterAsynchronously(CustomCrops.plugin, () -> {
|
||||||
|
potDryJudge(dryTime);
|
||||||
|
}, sprinklerTime);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
int delay = (int) (24000 - world.getTime());
|
int delay = (int) (24000 - world.getTime());
|
||||||
@@ -405,10 +408,14 @@ public class CustomWorld {
|
|||||||
}
|
}
|
||||||
else if (!compensation) {
|
else if (!compensation) {
|
||||||
route(sprinklerTime);
|
route(sprinklerTime);
|
||||||
potDryJudge(sprinklerTime + randomGenerator.nextInt(dryTime));
|
|
||||||
for (Map.Entry<SimpleLocation, GrowingCrop> entry : cropData.entrySet()) {
|
for (Map.Entry<SimpleLocation, GrowingCrop> entry : cropData.entrySet()) {
|
||||||
growSingleFrame(entry.getKey(), entry.getValue(), sprinklerTime + dryTime + randomGenerator.nextInt(cropTime));
|
growSingleFrame(entry.getKey(), entry.getValue(), sprinklerTime + dryTime + randomGenerator.nextInt(cropTime));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Bukkit.getScheduler().runTaskLaterAsynchronously(CustomCrops.plugin, () -> {
|
||||||
|
potDryJudge(dryTime);
|
||||||
|
}, sprinklerTime);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
int delay = (int) (24000 - world.getTime());
|
int delay = (int) (24000 - world.getTime());
|
||||||
@@ -438,13 +445,18 @@ public class CustomWorld {
|
|||||||
|
|
||||||
|
|
||||||
private void route(int sprinklerTime) {
|
private void route(int sprinklerTime) {
|
||||||
|
//先将湿润的种植盆放入等待判断的种植盆列表中
|
||||||
tempWatered = new HashSet<>(watered);
|
tempWatered = new HashSet<>(watered);
|
||||||
|
//清空湿润的
|
||||||
watered.clear();
|
watered.clear();
|
||||||
|
//玩家浇水
|
||||||
watered.addAll(playerWatered);
|
watered.addAll(playerWatered);
|
||||||
|
//清除昨日玩家浇水
|
||||||
playerWatered.clear();
|
playerWatered.clear();
|
||||||
|
//清除玩家昨日种植
|
||||||
plantedToday.clear();;
|
plantedToday.clear();;
|
||||||
|
|
||||||
|
//洒水器工作会把种植盆放入watered中
|
||||||
Random randomGenerator = new Random();
|
Random randomGenerator = new Random();
|
||||||
for (Map.Entry<SimpleLocation, Sprinkler> sprinklerEntry : sprinklerCache.entrySet()) {
|
for (Map.Entry<SimpleLocation, Sprinkler> sprinklerEntry : sprinklerCache.entrySet()) {
|
||||||
bukkitScheduler.runTaskLaterAsynchronously(CustomCrops.plugin, () -> sprinklerWork(sprinklerEntry.getKey(), sprinklerEntry.getValue()), randomGenerator.nextInt(sprinklerTime));
|
bukkitScheduler.runTaskLaterAsynchronously(CustomCrops.plugin, () -> sprinklerWork(sprinklerEntry.getKey(), sprinklerEntry.getValue()), randomGenerator.nextInt(sprinklerTime));
|
||||||
@@ -489,25 +501,25 @@ public class CustomWorld {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void potDryJudge(int time) {
|
private void potDryJudge(int dry_time) {
|
||||||
new BukkitRunnable() {
|
//将待干的种植盆中今日被浇水的种植盆移除
|
||||||
@Override
|
//剩余的种植盆即为需要变干的
|
||||||
public void run() {
|
tempWatered.removeAll(watered);
|
||||||
tempWatered.removeAll(watered);
|
for (SimpleLocation simpleLocation : tempWatered) {
|
||||||
for (SimpleLocation simpleLocation : tempWatered) {
|
new BukkitRunnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
Location potLoc = MiscUtils.getLocation(simpleLocation);
|
Location potLoc = MiscUtils.getLocation(simpleLocation);
|
||||||
if (potLoc == null) return;
|
if (potLoc == null) return;
|
||||||
if (!isPotWet(potLoc)) {
|
|
||||||
cropManager.makePotDry(potLoc);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
Fertilizer fertilizer = getFertilizerCache(potLoc);
|
Fertilizer fertilizer = getFertilizerCache(potLoc);
|
||||||
if (!(fertilizer instanceof RetainingSoil retainingSoil && Math.random() < retainingSoil.getChance())) {
|
if (!(fertilizer instanceof RetainingSoil retainingSoil && Math.random() < retainingSoil.getChance())) {
|
||||||
cropManager.makePotDry(potLoc);
|
cropManager.makePotDry(potLoc);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}.runTaskLaterAsynchronously(CustomCrops.plugin, new Random().nextInt(dry_time));
|
||||||
}.runTaskLaterAsynchronously(CustomCrops.plugin, time);
|
}
|
||||||
|
//用完就抛弃
|
||||||
|
tempWatered.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user