9
0
mirror of https://github.com/Xiao-MoMi/Custom-Crops.git synced 2025-12-22 16:39:36 +00:00
This commit is contained in:
Xiao-MoMi
2022-08-16 15:00:37 +08:00
parent 0d53a14487
commit c6eea41bca
21 changed files with 136 additions and 102 deletions

View File

@@ -5,7 +5,7 @@ plugins {
group = 'net.momirealms'
version = '1.5.26.2'
version = '1.5.26.3'
repositories {
mavenCentral()

View File

View File

@@ -17,18 +17,11 @@
package net.momirealms.customcrops;
import dev.dejvokep.boostedyaml.YamlDocument;
import dev.dejvokep.boostedyaml.dvs.versioning.BasicVersioning;
import dev.dejvokep.boostedyaml.settings.dumper.DumperSettings;
import dev.dejvokep.boostedyaml.settings.general.GeneralSettings;
import dev.dejvokep.boostedyaml.settings.loader.LoaderSettings;
import dev.dejvokep.boostedyaml.settings.updater.UpdaterSettings;
import net.kyori.adventure.key.Key;
import net.momirealms.customcrops.fertilizer.Fertilizer;
import net.momirealms.customcrops.fertilizer.QualityCrop;
import net.momirealms.customcrops.fertilizer.RetainingSoil;
import net.momirealms.customcrops.fertilizer.SpeedGrow;
import net.momirealms.customcrops.helper.Log;
import net.momirealms.customcrops.integrations.protection.*;
import net.momirealms.customcrops.integrations.skill.*;
import net.momirealms.customcrops.requirements.Biome;
@@ -44,7 +37,6 @@ import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import java.io.File;
import java.io.IOException;
import java.util.*;
public class ConfigReader {
@@ -55,9 +47,9 @@ public class ConfigReader {
public static HashMap<String, Sprinkler> SPRINKLERS = new HashMap<>();
public static YamlConfiguration getConfig(String configName) {
File file = new File(CustomCrops.instance.getDataFolder(), configName);
File file = new File(CustomCrops.plugin.getDataFolder(), configName);
if (!file.exists()) {
CustomCrops.instance.saveResource(configName, false);
CustomCrops.plugin.saveResource(configName, false);
}
return YamlConfiguration.loadConfiguration(file);
}
@@ -111,26 +103,19 @@ public class ConfigReader {
public static void loadConfig(){
//存读基本配置文件
CustomCrops.instance.saveDefaultConfig();
CustomCrops.instance.reloadConfig();
FileConfiguration config = CustomCrops.instance.getConfig();
CustomCrops.plugin.saveDefaultConfig();
CustomCrops.plugin.reloadConfig();
FileConfiguration config = CustomCrops.plugin.getConfig();
lang = config.getString("config.lang","chinese");
//农作物生长时间点
cropGrowTimeList = config.getLongList("config.grow-time");
cropGrowTimeList.forEach(time -> {
if(time < 0 || time > 23999){
AdventureManager.consoleMessage("<red>[CustomCrops] Grow time should be between 0 and 23999");
}
});
cropGrowTimeList.forEach(time -> {if(time < 0 || time > 23999){AdventureManager.consoleMessage("<red>[CustomCrops] Grow time should be between 0 and 23999");}});
timeToGrow = config.getInt("config.time-to-grow",60)*20;
timeToWork = config.getInt("config.time-to-work",30)*20;
asyncCheck = config.getBoolean("config.async-time-check",false);
logTime = config.getBoolean("config.log-time-consume",false);
growMode = config.getInt("config.grow-mode",3);
if (growMode > 4 || growMode < 1) growMode = 3;
growMode = config.getInt("config.grow-mode",3); if (growMode > 4 || growMode < 1) growMode = 3;
allWorld = config.getBoolean("config.all-world-grow",false);
hasParticle = config.getBoolean("config.water-particles", true);
rightClickHarvest = config.getBoolean("config.right-click-harvest", true);
@@ -201,7 +186,7 @@ public class ConfigReader {
integration = new ArrayList<>();
if(config.getBoolean("config.integration.Residence",false)){
if(Bukkit.getPluginManager().getPlugin("Residence") == null){
CustomCrops.instance.getLogger().warning("Failed to initialize Residence!");
CustomCrops.plugin.getLogger().warning("Failed to initialize Residence!");
}else {
integration.add(new Residence());
AdventureManager.consoleMessage("<gradient:#ff206c:#fdee55>[CustomCrops] </gradient><gold>Residence <color:#FFEBCD>Hooked!");
@@ -209,7 +194,7 @@ public class ConfigReader {
}
if(config.getBoolean("config.integration.Kingdoms",false)){
if(Bukkit.getPluginManager().getPlugin("Kingdoms") == null){
CustomCrops.instance.getLogger().warning("Failed to initialize Kingdoms!");
CustomCrops.plugin.getLogger().warning("Failed to initialize Kingdoms!");
}else {
integration.add(new KingdomsX());
AdventureManager.consoleMessage("<gradient:#ff206c:#fdee55>[CustomCrops] </gradient><gold>KingdomsX <color:#FFEBCD>Hooked!");
@@ -217,7 +202,7 @@ public class ConfigReader {
}
if(config.getBoolean("config.integration.WorldGuard",false)){
if(Bukkit.getPluginManager().getPlugin("WorldGuard") == null){
CustomCrops.instance.getLogger().warning("Failed to initialize WorldGuard!");
CustomCrops.plugin.getLogger().warning("Failed to initialize WorldGuard!");
}else {
integration.add(new WorldGuard());
AdventureManager.consoleMessage("<gradient:#ff206c:#fdee55>[CustomCrops] </gradient><gold>WorldGuard <color:#FFEBCD>Hooked!");
@@ -225,7 +210,7 @@ public class ConfigReader {
}
if(config.getBoolean("config.integration.GriefDefender",false)){
if(Bukkit.getPluginManager().getPlugin("GriefDefender") == null){
CustomCrops.instance.getLogger().warning("Failed to initialize GriefDefender!");
CustomCrops.plugin.getLogger().warning("Failed to initialize GriefDefender!");
}else {
integration.add(new GriefDefender());
AdventureManager.consoleMessage("<gradient:#ff206c:#fdee55>[CustomCrops] </gradient><gold>GriefDefender <color:#FFEBCD>Hooked!");
@@ -233,7 +218,7 @@ public class ConfigReader {
}
if(config.getBoolean("config.integration.PlotSquared",false)){
if(Bukkit.getPluginManager().getPlugin("PlotSquared") == null){
CustomCrops.instance.getLogger().warning("Failed to initialize PlotSquared!");
CustomCrops.plugin.getLogger().warning("Failed to initialize PlotSquared!");
}else {
integration.add(new PlotSquared());
AdventureManager.consoleMessage("<gradient:#ff206c:#fdee55>[CustomCrops] </gradient><gold>PlotSquared <color:#FFEBCD>Hooked!");
@@ -241,7 +226,7 @@ public class ConfigReader {
}
if(config.getBoolean("config.integration.Towny",false)){
if(Bukkit.getPluginManager().getPlugin("Towny") == null){
CustomCrops.instance.getLogger().warning("Failed to initialize Towny!");
CustomCrops.plugin.getLogger().warning("Failed to initialize Towny!");
}else {
integration.add(new Towny());
AdventureManager.consoleMessage("<gradient:#ff206c:#fdee55>[CustomCrops] </gradient><gold>Towny <color:#FFEBCD>Hooked!");
@@ -249,7 +234,7 @@ public class ConfigReader {
}
if(config.getBoolean("config.integration.Lands",false)){
if(Bukkit.getPluginManager().getPlugin("Lands") == null){
CustomCrops.instance.getLogger().warning("Failed to initialize Lands!");
CustomCrops.plugin.getLogger().warning("Failed to initialize Lands!");
}else {
integration.add(new Lands());
AdventureManager.consoleMessage("<gradient:#ff206c:#fdee55>[CustomCrops] </gradient><gold>Lands <color:#FFEBCD>Hooked!");
@@ -257,18 +242,26 @@ public class ConfigReader {
}
if(config.getBoolean("config.integration.GriefPrevention",false)){
if(Bukkit.getPluginManager().getPlugin("GriefPrevention") == null){
CustomCrops.instance.getLogger().warning("Failed to initialize GriefPrevention!");
CustomCrops.plugin.getLogger().warning("Failed to initialize GriefPrevention!");
}else {
integration.add(new GriefPrevention());
AdventureManager.consoleMessage("<gradient:#ff206c:#fdee55>[CustomCrops] </gradient><gold>GriefPrevention <color:#FFEBCD>Hooked!");
}
}
if(config.getBoolean("config.integration.CrashClaim",false)){
if(Bukkit.getPluginManager().getPlugin("CrashClaim") == null){
CustomCrops.plugin.getLogger().warning("Failed to initialize CrashClaim!");
}else {
integration.add(new CrashClaim());
AdventureManager.consoleMessage("<gradient:#ff206c:#fdee55>[CustomCrops] </gradient><gold>CrashClaim <color:#FFEBCD>Hooked!");
}
}
skillXP = null;
if(config.getBoolean("config.integration.mcMMO",false)){
if(Bukkit.getPluginManager().getPlugin("mcMMO") == null){
CustomCrops.instance.getLogger().warning("Failed to initialize mcMMO!");
CustomCrops.plugin.getLogger().warning("Failed to initialize mcMMO!");
}else {
skillXP = new mcMMO();
AdventureManager.consoleMessage("<gradient:#ff206c:#fdee55>[CustomCrops] </gradient><gold>mcMMO <color:#FFEBCD>Hooked!");
@@ -276,7 +269,7 @@ public class ConfigReader {
}
if(config.getBoolean("config.integration.AureliumSkills",false)){
if(Bukkit.getPluginManager().getPlugin("AureliumSkills") == null){
CustomCrops.instance.getLogger().warning("Failed to initialize AureliumSkills!");
CustomCrops.plugin.getLogger().warning("Failed to initialize AureliumSkills!");
}else {
skillXP = new Aurelium();
AdventureManager.consoleMessage("<gradient:#ff206c:#fdee55>[CustomCrops] </gradient><gold>AureliumSkills <color:#FFEBCD>Hooked!");
@@ -284,7 +277,7 @@ public class ConfigReader {
}
if(config.getBoolean("config.integration.MMOCore",false)){
if(Bukkit.getPluginManager().getPlugin("MMOCore") == null){
CustomCrops.instance.getLogger().warning("Failed to initialize MMOCore!");
CustomCrops.plugin.getLogger().warning("Failed to initialize MMOCore!");
}else {
skillXP = new MMOCore();
AdventureManager.consoleMessage("<gradient:#ff206c:#fdee55>[CustomCrops] </gradient><gold>MMOCore <color:#FFEBCD>Hooked!");
@@ -292,7 +285,7 @@ public class ConfigReader {
}
if(config.getBoolean("config.integration.EcoSkills",false)){
if(Bukkit.getPluginManager().getPlugin("EcoSkills") == null){
CustomCrops.instance.getLogger().warning("Failed to initialize EcoSkills!");
CustomCrops.plugin.getLogger().warning("Failed to initialize EcoSkills!");
}else {
skillXP = new EcoSkill();
AdventureManager.consoleMessage("<gradient:#ff206c:#fdee55>[CustomCrops] </gradient><gold>EcoSkills <color:#FFEBCD>Hooked!");

View File

@@ -35,7 +35,6 @@ import java.util.Objects;
public final class CustomCrops extends JavaPlugin {
public static JavaPlugin instance;
public static BukkitAudiences adventure;
public static CustomCrops plugin;
@@ -53,7 +52,7 @@ public final class CustomCrops extends JavaPlugin {
@Override
public void onLoad(){
instance = this;
plugin = this;
LibraryLoader.load("redis.clients","jedis","4.2.3","https://repo.maven.apache.org/maven2/");
LibraryLoader.load("org.apache.commons","commons-pool2","2.11.1","https://repo.maven.apache.org/maven2/");
LibraryLoader.load("dev.dejvokep","boosted-yaml","1.3","https://repo.maven.apache.org/maven2/");
@@ -62,8 +61,7 @@ public final class CustomCrops extends JavaPlugin {
@Override
public void onEnable() {
plugin = this;
instance = this;
adventure = BukkitAudiences.create(instance);
adventure = BukkitAudiences.create(plugin);
AdventureManager.consoleMessage("<gradient:#ff206c:#fdee55>[CustomCrops] </gradient><color:#FFEBCD>Running on " + Bukkit.getVersion());
ConfigReader.ReloadConfig();
if(Bukkit.getPluginManager().getPlugin("PlaceHolderAPI") != null){
@@ -97,7 +95,7 @@ public final class CustomCrops extends JavaPlugin {
this.potManager.loadData();
this.cropTimer = new CropTimer(this);
checkIAConfig();
if (ConfigReader.Config.version != 1){
if (ConfigReader.Config.version != 2){
UpdateConfig.update();
}
AdventureManager.consoleMessage("<gradient:#ff206c:#fdee55>[CustomCrops] </gradient><color:#F5DEB3>Plugin Enabled!");
@@ -125,7 +123,7 @@ public final class CustomCrops extends JavaPlugin {
this.seasonManager.saveData();
this.seasonManager = null;
}
if (this.placeholders != null){
if (placeholders != null){
placeholders.unregister();
placeholders = null;
}
@@ -140,8 +138,8 @@ public final class CustomCrops extends JavaPlugin {
if (adventure != null) {
adventure.close();
}
if (instance != null) {
instance = null;
if (plugin != null) {
plugin = null;
}
}

View File

@@ -66,7 +66,7 @@ public class Executor implements CommandExecutor {
lackArgs(sender);
return true;
}
Bukkit.getScheduler().runTaskAsynchronously(CustomCrops.instance, ()-> {
Bukkit.getScheduler().runTaskAsynchronously(CustomCrops.plugin, ()-> {
switch (ConfigReader.Config.growMode){
case 1 -> plugin.getCropManager().growModeOne(args[1]);
case 2 -> plugin.getCropManager().growModeTwo(args[1]);
@@ -86,7 +86,7 @@ public class Executor implements CommandExecutor {
lackArgs(sender);
return true;
}
Bukkit.getScheduler().runTaskAsynchronously(CustomCrops.instance, ()-> {
Bukkit.getScheduler().runTaskAsynchronously(CustomCrops.plugin, ()-> {
switch (ConfigReader.Config.growMode){
case 1 -> plugin.getSprinklerManager().workModeOne(args[1]);
case 2 -> plugin.getSprinklerManager().workModeTwo(args[1]);

View File

@@ -55,7 +55,7 @@ public class CropManager {
* 载入数据
*/
public void loadData() {
File file = new File(CustomCrops.instance.getDataFolder(), "data" + File.separator + "crop.yml");
File file = new File(CustomCrops.plugin.getDataFolder(), "data" + File.separator + "crop.yml");
if(!file.exists()){
try {
file.getParentFile().mkdirs();
@@ -72,7 +72,7 @@ public class CropManager {
* 保存数据
*/
public void saveData() {
File file = new File(CustomCrops.instance.getDataFolder(), "data" + File.separator + "crop.yml");
File file = new File(CustomCrops.plugin.getDataFolder(), "data" + File.separator + "crop.yml");
try{
data.save(file);
}catch (IOException e){
@@ -271,7 +271,7 @@ public class CropManager {
List<World> worlds = Bukkit.getWorlds();
for (int i = 0; i < worlds.size(); i++){
String worldName = worlds.get(i).getName();
bukkitScheduler.runTaskLaterAsynchronously(CustomCrops.instance, () -> {
bukkitScheduler.runTaskLaterAsynchronously(CustomCrops.plugin, () -> {
switch (ConfigReader.Config.growMode){
case 1 -> growModeOne(worldName);
case 2 -> growModeTwo(worldName);
@@ -321,7 +321,7 @@ public class CropManager {
if (ConfigReader.Season.enable && cropInstance.getSeasons() != null){
if (isWrongSeason(seedLocation, cropInstance.getSeasons(), worldName)){
bukkitScheduler.runTaskLater(CustomCrops.instance, () -> {
bukkitScheduler.runTaskLater(CustomCrops.plugin, () -> {
CustomBlock.remove(seedLocation);
CustomBlock.place(ConfigReader.Basic.dead, seedLocation);
}, random);
@@ -415,7 +415,7 @@ public class CropManager {
//巨大化判定
if (cropInstance.getGiantChance() > Math.random()){
//成功巨大化,移除数据
bukkitScheduler.runTaskLater(CustomCrops.instance, () ->{
bukkitScheduler.runTaskLater(CustomCrops.plugin, () ->{
CustomBlock.remove(seedLocation);
CustomBlock.place(cropInstance.getGiant(), seedLocation);
CustomBlock.remove(potLocation);
@@ -424,7 +424,7 @@ public class CropManager {
return true;
}else {
//失败,转湿为干
bukkitScheduler.runTaskLater(CustomCrops.instance, () ->{
bukkitScheduler.runTaskLater(CustomCrops.plugin, () ->{
CustomBlock.remove(potLocation);
CustomBlock.place(ConfigReader.Basic.pot, potLocation);
}, random);
@@ -433,7 +433,7 @@ public class CropManager {
}else {
//若无下一阶段,无巨大化,未启用季节,则移除无用数据
if (!ConfigReader.Season.enable) return true;
bukkitScheduler.runTaskLater(CustomCrops.instance, () -> {
bukkitScheduler.runTaskLater(CustomCrops.plugin, () -> {
CustomBlock.remove(potLocation);
CustomBlock.place(ConfigReader.Basic.pot, potLocation);
}, random);
@@ -448,7 +448,7 @@ public class CropManager {
if(seasons == null) return false;
//错误季节
if(isWrongSeason(seedLocation, seasons, worldName)){
bukkitScheduler.runTaskLater(CustomCrops.instance, () -> {
bukkitScheduler.runTaskLater(CustomCrops.plugin, () -> {
CustomBlock.remove(seedLocation);
CustomBlock.place(ConfigReader.Basic.dead, seedLocation);
}, new Random().nextInt(ConfigReader.Config.timeToGrow));
@@ -505,7 +505,7 @@ public class CropManager {
*/
private void addStage(Location potLocation, Location seedLocation, String namespacedID, int nextStage, int random){
String stage = StringUtils.chop(namespacedID) + nextStage;
bukkitScheduler.runTaskLater(CustomCrops.instance, () ->{
bukkitScheduler.runTaskLater(CustomCrops.plugin, () ->{
CustomBlock.remove(potLocation);
CustomBlock.place(ConfigReader.Basic.pot, potLocation);
CustomBlock.remove(seedLocation);
@@ -522,7 +522,7 @@ public class CropManager {
*/
private void addStage(Location seedLocation, String namespacedID, int nextStage, int random){
String stage = StringUtils.chop(namespacedID) + nextStage;
bukkitScheduler.runTaskLater(CustomCrops.instance, () ->{
bukkitScheduler.runTaskLater(CustomCrops.plugin, () ->{
CustomBlock.remove(seedLocation);
CustomBlock.place(stage, seedLocation);
}, random);
@@ -534,7 +534,7 @@ public class CropManager {
* @param random 随机生长时间
*/
private void notAddStage(Location potLocation, int random){
bukkitScheduler.runTaskLater(CustomCrops.instance, () ->{
bukkitScheduler.runTaskLater(CustomCrops.plugin, () ->{
CustomBlock.remove(potLocation);
CustomBlock.place(ConfigReader.Basic.pot, potLocation);
}, random);

View File

@@ -43,7 +43,7 @@ public class PotManager {
* 载入数据
*/
public void loadData(){
File file = new File(CustomCrops.instance.getDataFolder(), "data" + File.separator + "pot.yml");
File file = new File(CustomCrops.plugin.getDataFolder(), "data" + File.separator + "pot.yml");
if(!file.exists()){
try {
file.getParentFile().mkdirs();
@@ -79,7 +79,7 @@ public class PotManager {
* 保存数据
*/
public void saveData(){
File file = new File(CustomCrops.instance.getDataFolder(), "data" + File.separator + "pot.yml");
File file = new File(CustomCrops.plugin.getDataFolder(), "data" + File.separator + "pot.yml");
YamlConfiguration data = new YamlConfiguration();
Cache.forEach(((location, fertilizer) -> {
String world = location.getWorldName();

View File

@@ -56,7 +56,7 @@ public class SeasonManager{
*/
public void loadData() {
SEASON.clear();
YamlConfiguration data = readData(new File(CustomCrops.instance.getDataFolder(), "data" + File.separator + "season.yml"));
YamlConfiguration data = readData(new File(CustomCrops.plugin.getDataFolder(), "data" + File.separator + "season.yml"));
if (ConfigReader.Season.seasonChange) {
autoSeason();
} else {
@@ -95,7 +95,7 @@ public class SeasonManager{
*/
public void saveData() {
SEASON.forEach((key, value) -> {
File file = new File(CustomCrops.instance.getDataFolder(), "data" + File.separator + "season.yml");
File file = new File(CustomCrops.plugin.getDataFolder(), "data" + File.separator + "season.yml");
YamlConfiguration data = readData(file);
data.set(key, value);
try {

View File

@@ -50,7 +50,7 @@ public class SprinklerManager {
* 载入数据
*/
public void loadData() {
File file = new File(CustomCrops.instance.getDataFolder(), "data" + File.separator + "sprinkler.yml");
File file = new File(CustomCrops.plugin.getDataFolder(), "data" + File.separator + "sprinkler.yml");
if(!file.exists()){
try {
file.getParentFile().mkdirs();
@@ -67,7 +67,7 @@ public class SprinklerManager {
* 保存数据
*/
public void saveData(){
File file = new File(CustomCrops.instance.getDataFolder(), "data" + File.separator + "sprinkler.yml");
File file = new File(CustomCrops.plugin.getDataFolder(), "data" + File.separator + "sprinkler.yml");
try{
data.save(file);
}catch (IOException e){
@@ -133,7 +133,7 @@ public class SprinklerManager {
if (value instanceof MemorySection map){
String[] coordinate = StringUtils.split(key, ",");
Location location = new Location(world,Double.parseDouble(coordinate[0])+0.5,Double.parseDouble(coordinate[1])+0.5,Double.parseDouble(coordinate[2])+0.5);
bukkitScheduler.runTask(CustomCrops.instance, ()->{
bukkitScheduler.runTask(CustomCrops.plugin, ()->{
int water = (int) map.get("water");
int range = (int) Optional.ofNullable(map.get("range")).orElse(0);
if(!IAFurniture.getFromLocation(location, world)){
@@ -142,7 +142,7 @@ public class SprinklerManager {
}
if (water > 0){
data.set(worldName + "." + chunk + "." + key + ".water", water - 1);
bukkitScheduler.runTaskLater(CustomCrops.instance, ()-> {
bukkitScheduler.runTaskLater(CustomCrops.plugin, ()-> {
for(int i = -range; i <= range; i++){
for (int j = -range; j <= range; j++){
waterPot(location.clone().add(i,-1,j));
@@ -192,12 +192,12 @@ public class SprinklerManager {
if (!players.contains(player)) return;
String[] coordinate = StringUtils.split(key, ",");
Location location = new Location(world,Double.parseDouble(coordinate[0])+0.5,Double.parseDouble(coordinate[1])+0.5,Double.parseDouble(coordinate[2])+0.5);
bukkitScheduler.callSyncMethod(CustomCrops.instance, ()->{
bukkitScheduler.callSyncMethod(CustomCrops.plugin, ()->{
int water = (int) map.get("water");
int range = (int) Optional.ofNullable(map.get("range")).orElse(0);
if (water > 0){
data.set(worldName + "." + chunk + "." + key + ".water", water - 1);
bukkitScheduler.runTaskLater(CustomCrops.instance, ()-> {
bukkitScheduler.runTaskLater(CustomCrops.plugin, ()-> {
for(int i = -range; i <= range; i++){
for (int j = -range; j <= range; j++){
waterPot(location.clone().add(i,-1,j));
@@ -245,14 +245,14 @@ public class SprinklerManager {
int range = (int) Optional.ofNullable(map.get("range")).orElse(0);
String[] coordinate = StringUtils.split(key, ",");
Location location = new Location(world,Double.parseDouble(coordinate[0])+0.5,Double.parseDouble(coordinate[1])+0.5,Double.parseDouble(coordinate[2])+0.5);
bukkitScheduler.runTask(CustomCrops.instance, ()->{
bukkitScheduler.runTask(CustomCrops.plugin, ()->{
if(!IAFurniture.getFromLocation(location, world)){
data.set(worldName + "." + chunk + "." + key, null);
return;
}
if (water > 0){
data.set(worldName + "." + chunk + "." + key + ".water", water - 1);
bukkitScheduler.runTaskLater(CustomCrops.instance, ()-> {
bukkitScheduler.runTaskLater(CustomCrops.plugin, ()-> {
for(int i = -range; i <= range; i++){
for (int j = -range; j <= range; j++){
waterPot(location.clone().add(i,-1,j));
@@ -280,7 +280,7 @@ public class SprinklerManager {
String[] coordinate = StringUtils.split(key, ",");
Location location = new Location(world,Double.parseDouble(coordinate[0])+0.5,Double.parseDouble(coordinate[1])+0.5,Double.parseDouble(coordinate[2])+0.5);
data.set(worldName + "." + chunk + "." + key + ".water", water - 1);
bukkitScheduler.runTaskLater(CustomCrops.instance, ()-> {
bukkitScheduler.runTaskLater(CustomCrops.plugin, ()-> {
for(int i = -range; i <= range; i++){
for (int j = -range; j <= range; j++){
waterPot(location.clone().add(i,-1,j));
@@ -325,7 +325,7 @@ public class SprinklerManager {
String[] coordinate = StringUtils.split(key, ",");
Location location = new Location(world,Double.parseDouble(coordinate[0])+0.5,Double.parseDouble(coordinate[1])+0.5,Double.parseDouble(coordinate[2])+0.5);
data.set(worldName + "." + chunk + "." + key + ".water", water - 1);
bukkitScheduler.runTaskLater(CustomCrops.instance, ()-> {
bukkitScheduler.runTaskLater(CustomCrops.plugin, ()-> {
for(int i = -range; i <= range; i++){
for (int j = -range; j <= range; j++){
waterPot(location.clone().add(i,-1,j));
@@ -356,7 +356,7 @@ public class SprinklerManager {
List<World> worlds = Bukkit.getWorlds();
for (int i = 0; i < worlds.size(); i++){
String worldName = worlds.get(i).getName();
bukkitScheduler.runTaskLaterAsynchronously(CustomCrops.instance, () -> {
bukkitScheduler.runTaskLaterAsynchronously(CustomCrops.plugin, () -> {
switch (ConfigReader.Config.growMode){
case 1 -> workModeOne(worldName);
case 2 -> workModeTwo(worldName);

View File

@@ -47,7 +47,7 @@ import java.util.Objects;
public final class LibraryLoader {
@SuppressWarnings("Guava")
private static final Supplier<URLClassLoaderAccess> URL_INJECTOR = Suppliers.memoize(() -> URLClassLoaderAccess.create((URLClassLoader) CustomCrops.instance.getClass().getClassLoader()));
private static final Supplier<URLClassLoaderAccess> URL_INJECTOR = Suppliers.memoize(() -> URLClassLoaderAccess.create((URLClassLoader) CustomCrops.plugin.getClass().getClassLoader()));
/**
* Resolves all {@link MavenLibrary} annotations on the given object.
@@ -111,7 +111,7 @@ public final class LibraryLoader {
}
private static File getLibFolder(Dependency dependency) {
File pluginDataFolder = CustomCrops.instance.getDataFolder();
File pluginDataFolder = CustomCrops.plugin.getDataFolder();
File serverDir = pluginDataFolder.getParentFile().getParentFile();
File helperDir = new File(serverDir, "libraries");

View File

@@ -38,23 +38,23 @@ import javax.annotation.Nonnull;
public final class Log {
public static void info(@Nonnull String s) {
CustomCrops.instance.getLogger().info(s);
CustomCrops.plugin.getLogger().info(s);
}
public static void warn(@Nonnull String s) {
CustomCrops.instance.getLogger().warning(s);
CustomCrops.plugin.getLogger().warning(s);
}
public static void severe(@Nonnull String s) {
CustomCrops.instance.getLogger().severe(s);
CustomCrops.plugin.getLogger().severe(s);
}
public static void warn(@Nonnull String s, Throwable t) {
CustomCrops.instance.getLogger().log(Level.WARNING, s, t);
CustomCrops.plugin.getLogger().log(Level.WARNING, s, t);
}
public static void severe(@Nonnull String s, Throwable t) {
CustomCrops.instance.getLogger().log(Level.SEVERE, s, t);
CustomCrops.plugin.getLogger().log(Level.SEVERE, s, t);
}
private Log() {

View File

@@ -0,0 +1,38 @@
/*
* 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 net.crashcraft.crashclaim.api.CrashClaimAPI;
import net.crashcraft.crashclaim.permissions.PermissionRoute;
import org.bukkit.Location;
import org.bukkit.entity.Player;
public class CrashClaim implements Integration{
@Override
public boolean canBreak(Location location, Player player) {
CrashClaimAPI crashClaimAPI = net.crashcraft.crashclaim.CrashClaim.getPlugin().getApi();
return crashClaimAPI.getPermissionHelper().hasPermission(player.getUniqueId(), location, PermissionRoute.BUILD);
}
@Override
public boolean canPlace(Location location, Player player) {
CrashClaimAPI crashClaimAPI = net.crashcraft.crashclaim.CrashClaim.getPlugin().getApi();
return crashClaimAPI.getPermissionHelper().hasPermission(player.getUniqueId(), location, PermissionRoute.BUILD);
}
}

View File

@@ -28,7 +28,7 @@ public class Lands implements Integration{
@Override
public boolean canBreak(Location location, Player player) {
Area area = new LandsIntegration(CustomCrops.instance).getAreaByLoc(location);
Area area = new LandsIntegration(CustomCrops.plugin).getAreaByLoc(location);
if (area != null){
return area.hasFlag(player, Flags.BLOCK_BREAK, false);
}else {
@@ -38,7 +38,7 @@ public class Lands implements Integration{
@Override
public boolean canPlace(Location location, Player player) {
Area area = new LandsIntegration(CustomCrops.instance).getAreaByLoc(location);
Area area = new LandsIntegration(CustomCrops.plugin).getAreaByLoc(location);
if (area != null){
return area.hasFlag(player, Flags.BLOCK_PLACE, false);
}else {

View File

@@ -67,7 +67,7 @@ public class BreakBlock implements Listener {
String[] cropNameList = StringUtils.split(StringUtils.split(namespacedId, ":")[1], "_");
int nextStage = Integer.parseInt(cropNameList[2]) + 1;
if (CustomBlock.getInstance(StringUtils.chop(namespacedId) + nextStage) == null) {
Bukkit.getScheduler().runTaskAsynchronously(CustomCrops.instance, ()-> {
Bukkit.getScheduler().runTaskAsynchronously(CustomCrops.plugin, ()-> {
if (location.getBlock().getType() != Material.AIR) return;
CropInstance cropInstance = ConfigReader.CROPS.get(cropNameList[0]);
ThreadLocalRandom current = ThreadLocalRandom.current();
@@ -77,7 +77,7 @@ public class BreakBlock implements Listener {
Fertilizer fertilizer = PotManager.Cache.get(SimpleLocation.fromLocation(location.clone().subtract(0,1,0)));
List<String> commands = cropInstance.getCommands();
if (commands != null){
Bukkit.getScheduler().callSyncMethod(CustomCrops.instance, ()-> {
Bukkit.getScheduler().callSyncMethod(CustomCrops.plugin, ()-> {
for (String command : commands){
Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), command.replace("{player}", player.getName()));
}
@@ -85,7 +85,7 @@ public class BreakBlock implements Listener {
});
}
if (ConfigReader.Config.skillXP != null && cropInstance.getSkillXP() != 0){
Bukkit.getScheduler().callSyncMethod(CustomCrops.instance, ()-> {
Bukkit.getScheduler().callSyncMethod(CustomCrops.plugin, ()-> {
ConfigReader.Config.skillXP.addXp(player, cropInstance.getSkillXP());
return null;
});
@@ -96,7 +96,7 @@ public class BreakBlock implements Listener {
double weightTotal = weights[0] + weights[1] + weights[2];
double rank_1 = weights[0]/(weightTotal);
double rank_2 = 1 - weights[1]/(weightTotal);
Bukkit.getScheduler().callSyncMethod(CustomCrops.instance, ()-> {
Bukkit.getScheduler().callSyncMethod(CustomCrops.plugin, ()-> {
for (int i = 0; i < random; i++){
double ran = Math.random();
if (ran < rank_1){
@@ -111,13 +111,13 @@ public class BreakBlock implements Listener {
});
}else {
Bukkit.getScheduler().callSyncMethod(CustomCrops.instance, ()-> {
Bukkit.getScheduler().callSyncMethod(CustomCrops.plugin, ()-> {
normalDrop(cropInstance, random, itemLoc, world);
return null;
});
}
} else {
Bukkit.getScheduler().callSyncMethod(CustomCrops.instance, ()-> {
Bukkit.getScheduler().callSyncMethod(CustomCrops.plugin, ()-> {
normalDrop(cropInstance, random, itemLoc, world);
return null;
});

View File

@@ -30,9 +30,9 @@ public class CropTimer {
TimeCheck tc = new TimeCheck(plugin);
BukkitTask task;
if (ConfigReader.Config.asyncCheck){
task = tc.runTaskTimerAsynchronously(CustomCrops.instance, 1,1);
task = tc.runTaskTimerAsynchronously(CustomCrops.plugin, 1,1);
}else {
task = tc.runTaskTimer(CustomCrops.instance, 1,1);
task = tc.runTaskTimer(CustomCrops.plugin, 1,1);
}
this.taskID = task.getTaskId();
}

View File

@@ -41,14 +41,14 @@ public class TimeCheck extends BukkitRunnable {
}
if(time == cropGrowTime){
if (ConfigReader.Config.allWorld){
Bukkit.getScheduler().runTaskAsynchronously(CustomCrops.instance, () -> {
Bukkit.getScheduler().runTaskAsynchronously(CustomCrops.plugin, () -> {
plugin.getCropManager().cropGrowAll();
});
Bukkit.getScheduler().runTaskLaterAsynchronously(CustomCrops.instance, ()->{
Bukkit.getScheduler().runTaskLaterAsynchronously(CustomCrops.plugin, ()->{
plugin.getSprinklerManager().sprinklerWorkAll();
}, ConfigReader.Config.timeToGrow);
}else {
Bukkit.getScheduler().runTaskAsynchronously(CustomCrops.instance, () -> {
Bukkit.getScheduler().runTaskAsynchronously(CustomCrops.plugin, () -> {
switch (ConfigReader.Config.growMode){
case 1 -> plugin.getCropManager().growModeOne(world.getName());
case 2 -> plugin.getCropManager().growModeTwo(world.getName());
@@ -56,7 +56,7 @@ public class TimeCheck extends BukkitRunnable {
case 4 -> plugin.getCropManager().growModeFour(world.getName());
}
});
Bukkit.getScheduler().runTaskLaterAsynchronously(CustomCrops.instance, ()->{
Bukkit.getScheduler().runTaskLaterAsynchronously(CustomCrops.plugin, ()->{
switch (ConfigReader.Config.growMode){
case 1 -> plugin.getSprinklerManager().workModeOne(world.getName());
case 2 -> plugin.getSprinklerManager().workModeTwo(world.getName());

View File

@@ -41,13 +41,13 @@ public class BackUp {
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss");
files.forEach(fileName -> {
File data = new File(CustomCrops.instance.getDataFolder(), "data"+ File.separatorChar + fileName + ".yml");
File backUp = new File(CustomCrops.instance.getDataFolder(), "backups"+ File.separatorChar + format.format(date) + File.separatorChar + fileName + ".yml");
File data = new File(CustomCrops.plugin.getDataFolder(), "data"+ File.separatorChar + fileName + ".yml");
File backUp = new File(CustomCrops.plugin.getDataFolder(), "backups"+ File.separatorChar + format.format(date) + File.separatorChar + fileName + ".yml");
try {
BackUp.backUp(data, backUp);
} catch (IOException e) {
e.printStackTrace();
CustomCrops.instance.getLogger().warning(fileName + ".yml备份出错!");
CustomCrops.plugin.getLogger().warning(fileName + ".yml备份出错!");
}
});
}

View File

@@ -83,7 +83,7 @@ public class HoloUtil {
e.printStackTrace();
}
Bukkit.getScheduler().runTaskLater(CustomCrops.instance, ()->{
Bukkit.getScheduler().runTaskLater(CustomCrops.plugin, ()->{
removeHolo(player, id);
cache.remove(location);
}, duration * 20L);

View File

@@ -61,7 +61,7 @@ public class JedisUtil {
}
public static void addPlayer(String player){
Bukkit.getScheduler().runTaskLaterAsynchronously(CustomCrops.instance, ()->{
Bukkit.getScheduler().runTaskLaterAsynchronously(CustomCrops.plugin, ()->{
Jedis jedis = getJedis();
jedis.sadd("cc_players", player);
jedis.close();
@@ -69,7 +69,7 @@ public class JedisUtil {
}
public static void remPlayer(String player){
Bukkit.getScheduler().runTaskAsynchronously(CustomCrops.instance, ()->{
Bukkit.getScheduler().runTaskAsynchronously(CustomCrops.plugin, ()->{
Jedis jedis = getJedis();
jedis.srem("cc_players", player);
jedis.close();

View File

@@ -1,5 +1,5 @@
#Don't change
config-version: 1
config-version: 2
config:
#=============================================================#
#english spanish chinese
@@ -15,6 +15,7 @@ config:
Towny: false
Lands: false
GriefPrevention: false
CrashClaim: false
#integration to add players' farming skill xp
AureliumSkills: false
mcMMO: false
@@ -26,10 +27,11 @@ config:
#Mode 2:
# Online players' crops will grow
#Mode 3:
# Recommended
# Mode 1 + Mode 2
#Mode 4:
# No support in this mode! Please disable season in this mode!
# All the crops will grow (May cause lag)
# Please disable season in this mode!
# All the crops will grow
grow-mode: 3
#The time to start growing(ticks)
#1000ticks is 7am in game. (0-23999)

View File

@@ -20,7 +20,10 @@ softdepend:
- AureliumSkills
- MMOCore
- EcoSkills
- CrashClaim
commands:
customcrops:
usage: /customcrops <args>
permission: customcrops.admin
aliases:
- ccrops