9
0
mirror of https://github.com/Xiao-MoMi/Custom-Crops.git synced 2025-12-22 08:29:35 +00:00
This commit is contained in:
Xiao-MoMi
2022-09-06 22:28:03 +08:00
parent d4e8c1ce85
commit b306dd3121
40 changed files with 416 additions and 63 deletions

View File

@@ -182,39 +182,43 @@ public class ConfigReader {
integration = new ArrayList<>();
if (config.getBoolean("config.integration.Residence",false)){
if (Bukkit.getPluginManager().getPlugin("Residence") == null) Log.warn("Failed to initialize Residence!");
else {integration.add(new Residence());hookMessage("Residence");}
else {integration.add(new ResidenceIntegration());hookMessage("Residence");}
}
if (config.getBoolean("config.integration.Kingdoms",false)){
if (Bukkit.getPluginManager().getPlugin("Kingdoms") == null) Log.warn("Failed to initialize Kingdoms!");
else {integration.add(new KingdomsX());hookMessage("Kingdoms");}
else {integration.add(new KingdomsXIntegration());hookMessage("Kingdoms");}
}
if (config.getBoolean("config.integration.WorldGuard",false)){
if (Bukkit.getPluginManager().getPlugin("WorldGuard") == null) Log.warn("Failed to initialize WorldGuard!");
else {integration.add(new WorldGuard());hookMessage("WorldGuard");}
else {integration.add(new WorldGuardIntegration());hookMessage("WorldGuard");}
}
if (config.getBoolean("config.integration.GriefDefender",false)){
if(Bukkit.getPluginManager().getPlugin("GriefDefender") == null) Log.warn("Failed to initialize GriefDefender!");
else {integration.add(new GriefDefender());hookMessage("GriefDefender");}
else {integration.add(new GriefDefenderIntegration());hookMessage("GriefDefender");}
}
if (config.getBoolean("config.integration.PlotSquared",false)){
if(Bukkit.getPluginManager().getPlugin("PlotSquared") == null) Log.warn("Failed to initialize PlotSquared!");
else {integration.add(new PlotSquared());hookMessage("PlotSquared");}
else {integration.add(new PlotSquaredIntegration());hookMessage("PlotSquared");}
}
if (config.getBoolean("config.integration.Towny",false)){
if (Bukkit.getPluginManager().getPlugin("Towny") == null) Log.warn("Failed to initialize Towny!");
else {integration.add(new Towny());hookMessage("Towny");}
else {integration.add(new TownyIntegration());hookMessage("Towny");}
}
if (config.getBoolean("config.integration.Lands",false)){
if (Bukkit.getPluginManager().getPlugin("Lands") == null) Log.warn("Failed to initialize Lands!");
else {integration.add(new Lands());hookMessage("Lands");}
else {integration.add(new LandsIntegration());hookMessage("Lands");}
}
if (config.getBoolean("config.integration.GriefPrevention",false)){
if (Bukkit.getPluginManager().getPlugin("GriefPrevention") == null) Log.warn("Failed to initialize GriefPrevention!");
else {integration.add(new GriefPrevention());hookMessage("GriefPrevention");}
else {integration.add(new GriefPreventionIntegration());hookMessage("GriefPrevention");}
}
if (config.getBoolean("config.integration.CrashClaim",false)){
if (Bukkit.getPluginManager().getPlugin("CrashClaim") == null) Log.warn("Failed to initialize CrashClaim!");
else {integration.add(new CrashClaim());hookMessage("CrashClaim");}
else {integration.add(new CrashClaimIntegration());hookMessage("CrashClaim");}
}
if (config.getBoolean("config.integration.BentoBox",false)){
if (Bukkit.getPluginManager().getPlugin("BentoBox") == null) Log.warn("Failed to initialize BentoBox!");
else {integration.add(new BentoBoxIntegration());hookMessage("BentoBox");}
}
realisticSeason = false;
@@ -226,23 +230,23 @@ public class ConfigReader {
skillXP = null;
if (config.getBoolean("config.integration.mcMMO",false)){
if (Bukkit.getPluginManager().getPlugin("mcMMO") == null) Log.warn("Failed to initialize mcMMO!");
else {skillXP = new mcMMO();hookMessage("mcMMO");}
else {skillXP = new mcMMOIntegration();hookMessage("mcMMO");}
}
if (config.getBoolean("config.integration.AureliumSkills",false)){
if (Bukkit.getPluginManager().getPlugin("AureliumSkills") == null) Log.warn("Failed to initialize AureliumSkills!");
else {skillXP = new Aurelium();hookMessage("AureliumSkills");}
else {skillXP = new AureliumIntegration();hookMessage("AureliumSkills");}
}
if(config.getBoolean("config.integration.MMOCore",false)){
if(Bukkit.getPluginManager().getPlugin("MMOCore") == null) Log.warn("Failed to initialize MMOCore!");
else {skillXP = new MMOCore();hookMessage("MMOCore");}
else {skillXP = new MMOCoreIntegration();hookMessage("MMOCore");}
}
if(config.getBoolean("config.integration.EcoSkills",false)){
if(Bukkit.getPluginManager().getPlugin("EcoSkills") == null) Log.warn("Failed to initialize EcoSkills!");
else {skillXP = new EcoSkill();hookMessage("EcoSkills");}
else {skillXP = new EcoSkillsIntegration();hookMessage("EcoSkills");}
}
if(config.getBoolean("config.integration.JobsReborn",false)){
if(Bukkit.getPluginManager().getPlugin("Jobs") == null) Log.warn("Failed to initialize Jobs!");
else {skillXP = new JobsReborn();hookMessage("JobsReborn");}
else {skillXP = new JobsRebornIntegration();hookMessage("JobsReborn");}
}
}
}

View File

@@ -76,10 +76,9 @@ public final class CustomCrops extends JavaPlugin {
AdventureManager.consoleMessage("[CustomCrops] Running on <white>" + Bukkit.getVersion());
ConfigReader.reloadConfig();
if (!Objects.equals(ConfigReader.Config.version, "5")){
if (!Objects.equals(ConfigReader.Config.version, "6")){
ConfigUtil.update();
}
if(Bukkit.getPluginManager().getPlugin("PlaceHolderAPI") != null){
placeholders = new Placeholders();
placeholders.register();

View File

@@ -56,17 +56,22 @@ public class PotManager {
String key = map.getString("fertilizer");
Fertilizer fertilizer = ConfigReader.FERTILIZERS.get(key);
if (fertilizer == null) return;
if (fertilizer instanceof SpeedGrow){
if (fertilizer instanceof SpeedGrow speedGrowConfig){
SpeedGrow speedGrow = new SpeedGrow(key, map.getInt("times"));
speedGrow.setChance(speedGrowConfig.getChance());
Cache.put(new SimpleLocation(worldName, Integer.parseInt(split[0]), Integer.parseInt(split[1]), Integer.parseInt(split[2])), speedGrow);
}else if (fertilizer instanceof QualityCrop){
}else if (fertilizer instanceof QualityCrop qualityCropConfig){
QualityCrop qualityCrop = new QualityCrop(key, map.getInt("times"));
qualityCrop.setChance(qualityCropConfig.getChance());
Cache.put(new SimpleLocation(worldName, Integer.parseInt(split[0]), Integer.parseInt(split[1]), Integer.parseInt(split[2])), qualityCrop);
}else if (fertilizer instanceof RetainingSoil){
}else if (fertilizer instanceof RetainingSoil retainingSoilConfig){
RetainingSoil retainingSoil = new RetainingSoil(key, map.getInt("times"));
retainingSoil.setChance(retainingSoilConfig.getChance());
Cache.put(new SimpleLocation(worldName, Integer.parseInt(split[0]), Integer.parseInt(split[1]), Integer.parseInt(split[2])), retainingSoil);
}else if(fertilizer instanceof YieldIncreasing){
}else if(fertilizer instanceof YieldIncreasing yieldIncreasingConfig){
YieldIncreasing yieldIncreasing = new YieldIncreasing(key, map.getInt("times"));
yieldIncreasing.setChance(yieldIncreasingConfig.getChance());
yieldIncreasing.setBonus(yieldIncreasingConfig.getBonus());
Cache.put(new SimpleLocation(worldName, Integer.parseInt(split[0]), Integer.parseInt(split[1]), Integer.parseInt(split[2])), yieldIncreasing);
}else {
AdventureManager.consoleMessage("<red>[CustomCrops] 未知肥料类型错误!</red>");

View File

@@ -0,0 +1,44 @@
/*
* 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 org.bukkit.Location;
import org.bukkit.entity.Player;
import world.bentobox.bentobox.BentoBox;
import world.bentobox.bentobox.api.user.User;
import world.bentobox.bentobox.database.objects.Island;
import world.bentobox.bentobox.lists.Flags;
import java.util.Optional;
public class BentoBoxIntegration implements Integration{
@Override
public boolean canBreak(Location location, Player player) {
User user = User.getInstance(player);
Optional<Island> islandOptional = BentoBox.getInstance().getIslands().getIslandAt(location);
return islandOptional.map(island -> island.isAllowed(user, Flags.BREAK_BLOCKS)).orElse(true);
}
@Override
public boolean canPlace(Location location, Player player) {
User user = User.getInstance(player);
Optional<Island> islandOptional = BentoBox.getInstance().getIslands().getIslandAt(location);
return islandOptional.map(island -> island.isAllowed(user, Flags.PLACE_BLOCKS)).orElse(true);
}
}

View File

@@ -22,7 +22,7 @@ import net.crashcraft.crashclaim.permissions.PermissionRoute;
import org.bukkit.Location;
import org.bukkit.entity.Player;
public class CrashClaim implements Integration{
public class CrashClaimIntegration implements Integration{
@Override
public boolean canBreak(Location location, Player player) {

View File

@@ -20,7 +20,7 @@ package net.momirealms.customcrops.integrations.protection;
import org.bukkit.Location;
import org.bukkit.entity.Player;
public class GriefDefender implements Integration {
public class GriefDefenderIntegration implements Integration {
@Override
public boolean canBreak(Location location, Player player) {

View File

@@ -20,7 +20,7 @@ package net.momirealms.customcrops.integrations.protection;
import org.bukkit.Location;
import org.bukkit.entity.Player;
public class GriefPrevention implements Integration{
public class GriefPreventionIntegration implements Integration{
@Override
public boolean canBreak(Location location, Player player) {

View File

@@ -23,7 +23,7 @@ import org.kingdoms.constants.group.Kingdom;
import org.kingdoms.constants.land.Land;
import org.kingdoms.constants.player.KingdomPlayer;
public class KingdomsX implements Integration {
public class KingdomsXIntegration implements Integration {
@Override
public boolean canBreak(Location location, Player player) {

View File

@@ -18,24 +18,23 @@
package net.momirealms.customcrops.integrations.protection;
import me.angeschossen.lands.api.flags.Flags;
import me.angeschossen.lands.api.integration.LandsIntegration;
import me.angeschossen.lands.api.land.Area;
import net.momirealms.customcrops.CustomCrops;
import org.bukkit.Location;
import org.bukkit.entity.Player;
public class Lands implements Integration{
public class LandsIntegration implements Integration{
@Override
public boolean canBreak(Location location, Player player) {
Area area = new LandsIntegration(CustomCrops.plugin).getAreaByLoc(location);
Area area = new me.angeschossen.lands.api.integration.LandsIntegration(CustomCrops.plugin).getAreaByLoc(location);
if (area != null) return area.hasFlag(player, Flags.BLOCK_BREAK, false);
else return true;
}
@Override
public boolean canPlace(Location location, Player player) {
Area area = new LandsIntegration(CustomCrops.plugin).getAreaByLoc(location);
Area area = new me.angeschossen.lands.api.integration.LandsIntegration(CustomCrops.plugin).getAreaByLoc(location);
if (area != null) return area.hasFlag(player, Flags.BLOCK_PLACE, false);
else return true;
}

View File

@@ -20,7 +20,7 @@ package net.momirealms.customcrops.integrations.protection;
import com.plotsquared.core.location.Location;
import org.bukkit.entity.Player;
public class PlotSquared implements Integration {
public class PlotSquaredIntegration implements Integration {
@Override
public boolean canBreak(org.bukkit.Location location, Player player) {

View File

@@ -23,7 +23,7 @@ import com.bekvon.bukkit.residence.protection.ResidencePermissions;
import org.bukkit.Location;
import org.bukkit.entity.Player;
public class Residence implements Integration {
public class ResidenceIntegration implements Integration {
@Override
public boolean canBreak(Location location, Player player) {

View File

@@ -22,7 +22,7 @@ import com.palmergames.bukkit.towny.utils.PlayerCacheUtil;
import org.bukkit.Location;
import org.bukkit.entity.Player;
public class Towny implements Integration{
public class TownyIntegration implements Integration{
@Override
public boolean canBreak(Location location, Player player) {

View File

@@ -30,10 +30,11 @@ import com.sk89q.worldguard.protection.regions.RegionQuery;
import org.bukkit.Location;
import org.bukkit.entity.Player;
public class WorldGuard implements Integration {
public class WorldGuardIntegration implements Integration {
@Override
public boolean canPlace(Location location, Player player) {
if (player.isOp()) return true;
LocalPlayer localPlayer = WorldGuardPlugin.inst().wrapPlayer(player);
World world = BukkitAdapter.adapt(location.getWorld());
WorldGuardPlatform platform = com.sk89q.worldguard.WorldGuard.getInstance().getPlatform();
@@ -46,6 +47,7 @@ public class WorldGuard implements Integration {
@Override
public boolean canBreak(Location location, Player player) {
if (player.isOp()) return true;
LocalPlayer localPlayer = WorldGuardPlugin.inst().wrapPlayer(player);
World world = BukkitAdapter.adapt(location.getWorld());
WorldGuardPlatform platform = com.sk89q.worldguard.WorldGuard.getInstance().getPlatform();

View File

@@ -22,7 +22,7 @@ import com.archyx.aureliumskills.leveler.Leveler;
import com.archyx.aureliumskills.skills.Skill;
import org.bukkit.entity.Player;
public class Aurelium implements SkillXP {
public class AureliumIntegration implements SkillXP {
private static final Leveler leveler = AureliumAPI.getPlugin().getLeveler();
private static final Skill skill = AureliumAPI.getPlugin().getSkillRegistry().getSkill("farming");

View File

@@ -1,13 +0,0 @@
package net.momirealms.customcrops.integrations.skill;
import com.willfp.ecoskills.api.EcoSkillsAPI;
import com.willfp.ecoskills.skills.Skills;
import org.bukkit.entity.Player;
public class EcoSkill implements SkillXP{
@Override
public void addXp(Player player, double amount) {
EcoSkillsAPI.getInstance().giveSkillExperience(player, Skills.FARMING, amount);
}
}

View File

@@ -0,0 +1,30 @@
/*
* 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.skill;
import com.willfp.ecoskills.api.EcoSkillsAPI;
import com.willfp.ecoskills.skills.Skills;
import org.bukkit.entity.Player;
public class EcoSkillsIntegration implements SkillXP{
@Override
public void addXp(Player player, double amount) {
EcoSkillsAPI.getInstance().giveSkillExperience(player, Skills.FARMING, amount);
}
}

View File

@@ -1,3 +1,20 @@
/*
* 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.skill;
import com.gamingmesh.jobs.Jobs;
@@ -8,7 +25,7 @@ import org.bukkit.entity.Player;
import java.util.List;
public class JobsReborn implements SkillXP{
public class JobsRebornIntegration implements SkillXP{
@Override
public void addXp(Player player, double amount) {

View File

@@ -21,7 +21,7 @@ import net.Indyuce.mmocore.experience.EXPSource;
import net.Indyuce.mmocore.experience.Profession;
import org.bukkit.entity.Player;
public class MMOCore implements SkillXP{
public class MMOCoreIntegration implements SkillXP{
@Override
public void addXp(Player player, double amount) {
Profession profession = net.Indyuce.mmocore.MMOCore.plugin.professionManager.get("farming");

View File

@@ -20,7 +20,7 @@ package net.momirealms.customcrops.integrations.skill;
import com.gmail.nossr50.api.ExperienceAPI;
import org.bukkit.entity.Player;
public class mcMMO implements SkillXP {
public class mcMMOIntegration implements SkillXP {
@Override
public void addXp(Player player, double amount) {

View File

@@ -1,3 +1,20 @@
/*
* 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.listener;
import net.momirealms.customcrops.ConfigReader;

View File

@@ -1,3 +1,20 @@
/*
* 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.listener;
import net.momirealms.customcrops.CustomCrops;

View File

@@ -1,3 +1,20 @@
/*
* 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.listener.itemframe;
import dev.lone.itemsadder.api.CustomFurniture;

View File

@@ -1,3 +1,20 @@
/*
* 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.listener.itemframe;
import dev.lone.itemsadder.api.CustomFurniture;

View File

@@ -1,3 +1,20 @@
/*
* 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.listener.itemframe;
import de.tr7zw.changeme.nbtapi.NBTCompound;
@@ -5,6 +22,8 @@ import de.tr7zw.changeme.nbtapi.NBTItem;
import dev.lone.itemsadder.api.CustomFurniture;
import dev.lone.itemsadder.api.CustomStack;
import dev.lone.itemsadder.api.Events.FurnitureInteractEvent;
import net.kyori.adventure.key.Key;
import net.kyori.adventure.sound.Sound;
import net.kyori.adventure.text.minimessage.MiniMessage;
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
import net.momirealms.customcrops.ConfigReader;
@@ -23,11 +42,13 @@ import net.momirealms.customcrops.objects.fertilizer.YieldIncreasing;
import net.momirealms.customcrops.utils.*;
import org.apache.commons.lang.StringUtils;
import org.bukkit.*;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.Damageable;
import java.util.List;
import java.util.Objects;
@@ -83,6 +104,18 @@ public class InteractFurnitureI implements Listener {
if (water > 0){
nbtItem.setInteger("WaterAmount", --water);
AdventureManager.playerSound(player, ConfigReader.Sounds.addWaterToSprinklerSource, ConfigReader.Sounds.addWaterToSprinklerKey);
if (nbtCompound.hasKey("custom_durability")){
int dur = nbtCompound.getInteger("custom_durability");
int max_dur = nbtCompound.getInteger("max_custom_durability");
if (dur > 0){
nbtCompound.setInteger("custom_durability", dur - 1);
nbtCompound.setDouble("fake_durability", (int) itemStack.getType().getMaxDurability() * (double) (dur/max_dur));
nbtItem.setInteger("Damage", (int) (itemStack.getType().getMaxDurability() * (1 - (double) dur/max_dur)));
} else {
AdventureManager.playerSound(player, net.kyori.adventure.sound.Sound.Source.PLAYER, Key.key("minecraft:item.shield.break"));
itemStack.setAmount(itemStack.getAmount() - 1);
}
}
if (sprinkler != null){
currentWater = sprinkler.getWater();
currentWater++;
@@ -157,6 +190,18 @@ public class InteractFurnitureI implements Listener {
int water = nbtItem.getInteger("WaterAmount");
if (water > 0){
nbtItem.setInteger("WaterAmount", --water);
if (nbtCompound.hasKey("custom_durability")){
int dur = nbtCompound.getInteger("custom_durability");
int max_dur = nbtCompound.getInteger("max_custom_durability");
if (dur > 0){
nbtCompound.setInteger("custom_durability", dur - 1);
nbtCompound.setDouble("fake_durability", (int) itemStack.getType().getMaxDurability() * (double) (dur/max_dur));
nbtItem.setInteger("Damage", (int) (itemStack.getType().getMaxDurability() * (1 - (double) dur/max_dur)));
} else {
AdventureManager.playerSound(player, net.kyori.adventure.sound.Sound.Source.PLAYER, Key.key("minecraft:item.shield.break"));
itemStack.setAmount(itemStack.getAmount() - 1);
}
}
AdventureManager.playerSound(player, ConfigReader.Sounds.waterPotSource, ConfigReader.Sounds.waterPotKey);
PotUtil.waterPot(wateringCan.getWidth(), wateringCan.getLength(), location.subtract(0.5,1,0.5), player.getLocation().getYaw());
}
@@ -242,6 +287,8 @@ public class InteractFurnitureI implements Listener {
}
}
/**
* 右键收获判定
* @param crop 农作物实体

View File

@@ -1,8 +1,26 @@
/*
* 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.listener.itemframe;
import de.tr7zw.changeme.nbtapi.NBTCompound;
import de.tr7zw.changeme.nbtapi.NBTItem;
import dev.lone.itemsadder.api.CustomBlock;
import net.kyori.adventure.key.Key;
import net.kyori.adventure.text.minimessage.MiniMessage;
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
import net.momirealms.customcrops.ConfigReader;
@@ -26,12 +44,14 @@ import org.apache.commons.lang.StringUtils;
import org.bukkit.*;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.Action;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.Damageable;
import java.util.List;
@@ -156,6 +176,18 @@ public class RightClickI implements Listener {
nbtItem.setInteger("WaterAmount", --water);
AdventureManager.playerSound(player, ConfigReader.Sounds.waterPotSource, ConfigReader.Sounds.waterPotKey);
PotUtil.waterPot(wateringCan.getWidth(), wateringCan.getLength(), block.getLocation(), player.getLocation().getYaw());
if (nbtCompound.hasKey("custom_durability")){
int dur = nbtCompound.getInteger("custom_durability");
int max_dur = nbtCompound.getInteger("max_custom_durability");
if (dur > 0){
nbtCompound.setInteger("custom_durability", dur - 1);
nbtCompound.setDouble("fake_durability", (int) itemStack.getType().getMaxDurability() * (double) (dur/max_dur));
nbtItem.setInteger("Damage", (int) (itemStack.getType().getMaxDurability() * (1 - (double) dur/max_dur)));
} else {
AdventureManager.playerSound(player, net.kyori.adventure.sound.Sound.Source.PLAYER, Key.key("minecraft:item.shield.break"));
itemStack.setAmount(itemStack.getAmount() - 1);
}
}
}
if (ConfigReader.Message.hasWaterInfo)
AdventureManager.playerActionbar(player,

View File

@@ -24,6 +24,7 @@ import net.momirealms.customcrops.ConfigReader;
import net.momirealms.customcrops.CustomCrops;
import net.momirealms.customcrops.datamanager.CropManager;
import net.momirealms.customcrops.datamanager.PotManager;
import net.momirealms.customcrops.listener.JoinAndQuit;
import net.momirealms.customcrops.objects.fertilizer.Fertilizer;
import net.momirealms.customcrops.objects.fertilizer.QualityCrop;
import net.momirealms.customcrops.integrations.protection.Integration;
@@ -51,9 +52,12 @@ public class BreakBlockT implements Listener {
@EventHandler
public void onBreak(CustomBlockBreakEvent event){
long time = System.currentTimeMillis();
Player player = event.getPlayer();
if (time - (JoinAndQuit.coolDown.getOrDefault(player, time - 150)) < 150) return;
JoinAndQuit.coolDown.put(player, time);
String namespacedId = event.getNamespacedID();
if(namespacedId.contains("_stage_")){
Player player = event.getPlayer();
Location location = event.getBlock().getLocation();
for (Integration integration : ConfigReader.Config.integration)
if(!integration.canBreak(location, player)) return;

View File

@@ -1,3 +1,20 @@
/*
* 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.listener.tripwire;
import dev.lone.itemsadder.api.Events.FurnitureBreakEvent;

View File

@@ -20,6 +20,8 @@ package net.momirealms.customcrops.listener.tripwire;
import de.tr7zw.changeme.nbtapi.NBTCompound;
import de.tr7zw.changeme.nbtapi.NBTItem;
import dev.lone.itemsadder.api.Events.FurnitureInteractEvent;
import net.kyori.adventure.key.Key;
import net.kyori.adventure.sound.Sound;
import net.kyori.adventure.text.minimessage.MiniMessage;
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
import net.momirealms.customcrops.ConfigReader;
@@ -89,6 +91,18 @@ public class InteractFurnitureT implements Listener {
int water = nbtItem.getInteger("WaterAmount");
if (water > 0){
nbtItem.setInteger("WaterAmount", --water);
if (nbtCompound.hasKey("custom_durability")){
int dur = nbtCompound.getInteger("custom_durability");
int max_dur = nbtCompound.getInteger("max_custom_durability");
if (dur > 0){
nbtCompound.setInteger("custom_durability", dur - 1);
nbtCompound.setDouble("fake_durability", (int) itemStack.getType().getMaxDurability() * (double) (dur/max_dur));
nbtItem.setInteger("Damage", (int) (itemStack.getType().getMaxDurability() * (1 - (double) dur/max_dur)));
} else {
AdventureManager.playerSound(player, net.kyori.adventure.sound.Sound.Source.PLAYER, Key.key("minecraft:item.shield.break"));
itemStack.setAmount(itemStack.getAmount() - 1);
}
}
AdventureManager.playerSound(player, ConfigReader.Sounds.addWaterToSprinklerSource, ConfigReader.Sounds.addWaterToSprinklerKey);
if (sprinkler != null){
currentWater = sprinkler.getWater();

View File

@@ -21,6 +21,7 @@ import de.tr7zw.changeme.nbtapi.NBTCompound;
import de.tr7zw.changeme.nbtapi.NBTItem;
import dev.lone.itemsadder.api.CustomBlock;
import dev.lone.itemsadder.api.CustomStack;
import net.kyori.adventure.key.Key;
import net.kyori.adventure.text.minimessage.MiniMessage;
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
import net.momirealms.customcrops.ConfigReader;
@@ -28,6 +29,7 @@ import net.momirealms.customcrops.datamanager.CropManager;
import net.momirealms.customcrops.datamanager.PotManager;
import net.momirealms.customcrops.datamanager.SeasonManager;
import net.momirealms.customcrops.datamanager.SprinklerManager;
import net.momirealms.customcrops.listener.itemframe.InteractFurnitureI;
import net.momirealms.customcrops.objects.fertilizer.Fertilizer;
import net.momirealms.customcrops.objects.fertilizer.QualityCrop;
import net.momirealms.customcrops.integrations.protection.Integration;
@@ -46,12 +48,14 @@ import org.apache.commons.lang.StringUtils;
import org.bukkit.*;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.Action;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.Damageable;
import java.util.List;
import java.util.concurrent.ThreadLocalRandom;
@@ -177,6 +181,18 @@ public class RightClickT implements Listener {
nbtItem.setInteger("WaterAmount", --water);
AdventureManager.playerSound(player, ConfigReader.Sounds.waterPotSource, ConfigReader.Sounds.waterPotKey);
PotUtil.waterPot(wateringCan.getWidth(), wateringCan.getLength(), block.getLocation(), player.getLocation().getYaw());
if (nbtCompound.hasKey("custom_durability")){
int dur = nbtCompound.getInteger("custom_durability");
int max_dur = nbtCompound.getInteger("max_custom_durability");
if (dur > 0){
nbtCompound.setInteger("custom_durability", dur - 1);
nbtCompound.setDouble("fake_durability", (int) itemStack.getType().getMaxDurability() * (double) (dur/max_dur));
nbtItem.setInteger("Damage", (int) (itemStack.getType().getMaxDurability() * (1 - (double) dur/max_dur)));
} else {
AdventureManager.playerSound(player, net.kyori.adventure.sound.Sound.Source.PLAYER, Key.key("minecraft:item.shield.break"));
itemStack.setAmount(itemStack.getAmount() - 1);
}
}
}
if (ConfigReader.Message.hasWaterInfo)
AdventureManager.playerActionbar(player,
@@ -205,6 +221,18 @@ public class RightClickT implements Listener {
nbtItem.setInteger("WaterAmount", --water);
AdventureManager.playerSound(player, ConfigReader.Sounds.waterPotSource, ConfigReader.Sounds.waterPotKey);
PotUtil.waterPot(wateringCan.getWidth(), wateringCan.getLength(), block.getLocation().subtract(0, 1, 0), player.getLocation().getYaw());
if (nbtCompound.hasKey("custom_durability")){
int dur = nbtCompound.getInteger("custom_durability");
int max_dur = nbtCompound.getInteger("max_custom_durability");
if (dur > 0){
nbtCompound.setInteger("custom_durability", dur - 1);
nbtCompound.setDouble("fake_durability", (int) itemStack.getType().getMaxDurability() * (double) (dur/max_dur));
nbtItem.setInteger("Damage", (int) (itemStack.getType().getMaxDurability() * (1 - (double) dur/max_dur)));
} else {
AdventureManager.playerSound(player, net.kyori.adventure.sound.Sound.Source.PLAYER, Key.key("minecraft:item.shield.break"));
itemStack.setAmount(itemStack.getAmount() - 1);
}
}
}
if (ConfigReader.Message.hasWaterInfo)
AdventureManager.playerActionbar(player,

View File

@@ -19,8 +19,16 @@ package net.momirealms.customcrops.objects;
public record WateringCan(int max, int width, int length) {
public int getMax() { return max; }
public int getLength() { return length; }
public int getWidth() { return width; }
public int getMax() {
return max;
}
public int getLength() {
return length;
}
public int getWidth() {
return width;
}
}

View File

@@ -1,3 +1,20 @@
/*
* 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.objects.fertilizer;
import org.bukkit.Particle;

View File

@@ -1,3 +1,20 @@
/*
* 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.objects.fertilizer;
public class YieldIncreasing extends Fertilizer {

View File

@@ -78,6 +78,7 @@ public class HoloUtil {
packet2.getModifier().write(0,id);
packet2.getWatchableCollectionModifier().write(0, wrappedDataWatcher.getWatchableObjects());
cache.put(location, id);
try {
ProtocolLibrary.getProtocolManager().sendServerPacket(player, packet1);
ProtocolLibrary.getProtocolManager().sendServerPacket(player, packet2);

View File

@@ -94,15 +94,20 @@ public class PotUtil {
public static void addFertilizer(Fertilizer fertilizerConfig, Location location) {
if (fertilizerConfig instanceof QualityCrop config){
QualityCrop qualityCrop = new QualityCrop(config.getKey(), config.getTimes());
qualityCrop.setChance(config.getChance());
PotManager.Cache.put(LocUtil.fromLocation(location), qualityCrop);
}else if (fertilizerConfig instanceof SpeedGrow config){
SpeedGrow speedGrow = new SpeedGrow(config.getKey(), config.getTimes());
speedGrow.setChance(config.getChance());
PotManager.Cache.put(LocUtil.fromLocation(location), speedGrow);
}else if (fertilizerConfig instanceof RetainingSoil config){
RetainingSoil retainingSoil = new RetainingSoil(config.getKey(), config.getTimes());
retainingSoil.setChance(config.getChance());
PotManager.Cache.put(LocUtil.fromLocation(location), retainingSoil);
}else if (fertilizerConfig instanceof YieldIncreasing config){
YieldIncreasing yieldIncreasing = new YieldIncreasing(config.getKey(), config.getTimes());
yieldIncreasing.setBonus(config.getBonus());
yieldIncreasing.setChance(config.getChance());
PotManager.Cache.put(LocUtil.fromLocation(location), yieldIncreasing);
}
if (fertilizerConfig.getParticle() != null) location.getWorld().spawnParticle(fertilizerConfig.getParticle(), location.add(0.5,1.3,0.5), 5,0.2,0.2,0.2);