mirror of
https://github.com/Xiao-MoMi/Custom-Crops.git
synced 2025-12-22 16:39:36 +00:00
1.5.25
This commit is contained in:
@@ -5,7 +5,7 @@ plugins {
|
|||||||
|
|
||||||
|
|
||||||
group = 'net.momirealms'
|
group = 'net.momirealms'
|
||||||
version = '1.5.20'
|
version = '1.5.25'
|
||||||
|
|
||||||
repositories {
|
repositories {
|
||||||
mavenCentral()
|
mavenCentral()
|
||||||
@@ -52,6 +52,8 @@ repositories {
|
|||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
|
compileOnly 'dev.dejvokep:boosted-yaml:1.3'
|
||||||
|
compileOnly 'redis.clients:jedis:4.2.3'
|
||||||
compileOnly 'com.github.Archy-X:AureliumSkills:Beta1.3.6'
|
compileOnly 'com.github.Archy-X:AureliumSkills:Beta1.3.6'
|
||||||
compileOnly 'com.github.angeschossen:LandsAPI:6.5.1'
|
compileOnly 'com.github.angeschossen:LandsAPI:6.5.1'
|
||||||
compileOnly 'com.github.TechFortress:GriefPrevention:16.18'
|
compileOnly 'com.github.TechFortress:GriefPrevention:16.18'
|
||||||
@@ -59,7 +61,7 @@ dependencies {
|
|||||||
compileOnly 'com.comphenix.protocol:ProtocolLib:4.8.0'
|
compileOnly 'com.comphenix.protocol:ProtocolLib:4.8.0'
|
||||||
compileOnly 'me.clip:placeholderapi:2.11.2'
|
compileOnly 'me.clip:placeholderapi:2.11.2'
|
||||||
compileOnly 'com.sk89q.worldguard:worldguard-bukkit:7.0.7'
|
compileOnly 'com.sk89q.worldguard:worldguard-bukkit:7.0.7'
|
||||||
compileOnly 'com.github.LoneDev6:api-itemsadder:3.2.0c-beta6'
|
compileOnly 'com.github.LoneDev6:api-itemsadder:3.2.3c'
|
||||||
compileOnly 'com.palmergames.bukkit.towny:towny:0.98.2.0'
|
compileOnly 'com.palmergames.bukkit.towny:towny:0.98.2.0'
|
||||||
compileOnly fileTree(dir:'libs',includes:['*.jar'])
|
compileOnly fileTree(dir:'libs',includes:['*.jar'])
|
||||||
implementation("net.kyori:adventure-api:4.11.0")
|
implementation("net.kyori:adventure-api:4.11.0")
|
||||||
|
|||||||
@@ -654,4 +654,14 @@ public class ConfigReader {
|
|||||||
boneMealSource = net.kyori.adventure.sound.Sound.Source.valueOf(config.getString("bonemeal.type","player").toUpperCase());
|
boneMealSource = net.kyori.adventure.sound.Sound.Source.valueOf(config.getString("bonemeal.type","player").toUpperCase());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void tryEnableJedis(){
|
||||||
|
YamlConfiguration configuration = ConfigReader.getConfig("redis.yml");
|
||||||
|
if (configuration.getBoolean("redis.enable")){
|
||||||
|
JedisUtil.initializeRedis(configuration);
|
||||||
|
JedisUtil.useRedis = true;
|
||||||
|
}else {
|
||||||
|
JedisUtil.useRedis = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -56,6 +56,8 @@ public final class CustomCrops extends JavaPlugin {
|
|||||||
@Override
|
@Override
|
||||||
public void onLoad(){
|
public void onLoad(){
|
||||||
instance = this;
|
instance = 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/");
|
LibraryLoader.load("dev.dejvokep","boosted-yaml","1.3","https://repo.maven.apache.org/maven2/");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -85,10 +87,13 @@ public final class CustomCrops extends JavaPlugin {
|
|||||||
Bukkit.getPluginManager().registerEvents(new BreakFurniture(), this);
|
Bukkit.getPluginManager().registerEvents(new BreakFurniture(), this);
|
||||||
Bukkit.getPluginManager().registerEvents(new InteractEntity(this), this);
|
Bukkit.getPluginManager().registerEvents(new InteractEntity(this), this);
|
||||||
|
|
||||||
|
ConfigReader.tryEnableJedis();
|
||||||
|
|
||||||
if (ConfigReader.Season.enable){
|
if (ConfigReader.Season.enable){
|
||||||
this.seasonManager = new SeasonManager();
|
this.seasonManager = new SeasonManager();
|
||||||
this.seasonManager.loadData();
|
this.seasonManager.loadData();
|
||||||
}
|
}
|
||||||
|
|
||||||
this.cropManager = new CropManager();
|
this.cropManager = new CropManager();
|
||||||
this.cropManager.loadData();
|
this.cropManager.loadData();
|
||||||
this.sprinklerManager = new SprinklerManager();
|
this.sprinklerManager = new SprinklerManager();
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ import net.momirealms.customcrops.fertilizer.Fertilizer;
|
|||||||
import net.momirealms.customcrops.fertilizer.RetainingSoil;
|
import net.momirealms.customcrops.fertilizer.RetainingSoil;
|
||||||
import net.momirealms.customcrops.fertilizer.SpeedGrow;
|
import net.momirealms.customcrops.fertilizer.SpeedGrow;
|
||||||
import net.momirealms.customcrops.utils.CropInstance;
|
import net.momirealms.customcrops.utils.CropInstance;
|
||||||
|
import net.momirealms.customcrops.utils.JedisUtil;
|
||||||
import net.momirealms.customcrops.utils.SimpleLocation;
|
import net.momirealms.customcrops.utils.SimpleLocation;
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang.StringUtils;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
@@ -37,9 +38,7 @@ import org.bukkit.scheduler.BukkitScheduler;
|
|||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.HashSet;
|
import java.util.*;
|
||||||
import java.util.List;
|
|
||||||
import java.util.Random;
|
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
public class CropManager {
|
public class CropManager {
|
||||||
@@ -155,7 +154,8 @@ public class CropManager {
|
|||||||
}
|
}
|
||||||
Long time2 = System.currentTimeMillis();
|
Long time2 = System.currentTimeMillis();
|
||||||
if(ConfigReader.Config.logTime) AdventureManager.consoleMessage("性能监测: 农作物数据更新" + (time2-time1) + "ms");
|
if(ConfigReader.Config.logTime) AdventureManager.consoleMessage("性能监测: 农作物数据更新" + (time2-time1) + "ms");
|
||||||
HashSet<String> players = new HashSet<>(JoinAndQuit.onlinePlayers);
|
//HashSet<String> players = new HashSet<>(JoinAndQuit.onlinePlayers);
|
||||||
|
HashSet<String> players = getPlayers();
|
||||||
if (data.contains(worldName)){
|
if (data.contains(worldName)){
|
||||||
World world = Bukkit.getWorld(worldName);
|
World world = Bukkit.getWorld(worldName);
|
||||||
data.getConfigurationSection(worldName).getKeys(false).forEach(chunk ->{
|
data.getConfigurationSection(worldName).getKeys(false).forEach(chunk ->{
|
||||||
@@ -190,7 +190,8 @@ public class CropManager {
|
|||||||
}
|
}
|
||||||
Long time2 = System.currentTimeMillis();
|
Long time2 = System.currentTimeMillis();
|
||||||
if(ConfigReader.Config.logTime) AdventureManager.consoleMessage("性能监测: 农作物数据更新" + (time2-time1) + "ms");
|
if(ConfigReader.Config.logTime) AdventureManager.consoleMessage("性能监测: 农作物数据更新" + (time2-time1) + "ms");
|
||||||
HashSet<String> players = new HashSet<>(JoinAndQuit.onlinePlayers);
|
//HashSet<String> players = new HashSet<>(JoinAndQuit.onlinePlayers);
|
||||||
|
HashSet<String> players = getPlayers();
|
||||||
if (data.contains(worldName)){
|
if (data.contains(worldName)){
|
||||||
World world = Bukkit.getWorld(worldName);
|
World world = Bukkit.getWorld(worldName);
|
||||||
data.getConfigurationSection(worldName).getKeys(false).forEach(chunk ->{
|
data.getConfigurationSection(worldName).getKeys(false).forEach(chunk ->{
|
||||||
@@ -538,4 +539,12 @@ public class CropManager {
|
|||||||
CustomBlock.place(ConfigReader.Basic.pot, potLocation);
|
CustomBlock.place(ConfigReader.Basic.pot, potLocation);
|
||||||
}, random);
|
}, random);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private HashSet<String> getPlayers(){
|
||||||
|
if (JedisUtil.useRedis){
|
||||||
|
return JedisUtil.getPlayers();
|
||||||
|
}else {
|
||||||
|
return new HashSet<>(JoinAndQuit.onlinePlayers);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -19,12 +19,9 @@ package net.momirealms.customcrops.datamanager;
|
|||||||
|
|
||||||
import dev.lone.itemsadder.api.CustomBlock;
|
import dev.lone.itemsadder.api.CustomBlock;
|
||||||
import net.momirealms.customcrops.listener.JoinAndQuit;
|
import net.momirealms.customcrops.listener.JoinAndQuit;
|
||||||
import net.momirealms.customcrops.utils.AdventureManager;
|
import net.momirealms.customcrops.utils.*;
|
||||||
import net.momirealms.customcrops.ConfigReader;
|
import net.momirealms.customcrops.ConfigReader;
|
||||||
import net.momirealms.customcrops.CustomCrops;
|
import net.momirealms.customcrops.CustomCrops;
|
||||||
import net.momirealms.customcrops.utils.IAFurniture;
|
|
||||||
import net.momirealms.customcrops.utils.SimpleLocation;
|
|
||||||
import net.momirealms.customcrops.utils.Sprinkler;
|
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang.StringUtils;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
@@ -180,7 +177,8 @@ public class SprinklerManager {
|
|||||||
}
|
}
|
||||||
Long time2 = System.currentTimeMillis();
|
Long time2 = System.currentTimeMillis();
|
||||||
if (ConfigReader.Config.logTime) AdventureManager.consoleMessage("性能监测: 洒水器数据更新" + (time2-time1) + "ms");
|
if (ConfigReader.Config.logTime) AdventureManager.consoleMessage("性能监测: 洒水器数据更新" + (time2-time1) + "ms");
|
||||||
HashSet<String> players = new HashSet<>(JoinAndQuit.onlinePlayers);
|
//HashSet<String> players = new HashSet<>(JoinAndQuit.onlinePlayers);
|
||||||
|
HashSet<String> players = getPlayers();
|
||||||
if (data.contains(worldName)){
|
if (data.contains(worldName)){
|
||||||
World world = Bukkit.getWorld(worldName);
|
World world = Bukkit.getWorld(worldName);
|
||||||
data.getConfigurationSection(worldName).getKeys(false).forEach(chunk ->{
|
data.getConfigurationSection(worldName).getKeys(false).forEach(chunk ->{
|
||||||
@@ -234,7 +232,8 @@ public class SprinklerManager {
|
|||||||
}
|
}
|
||||||
Long time2 = System.currentTimeMillis();
|
Long time2 = System.currentTimeMillis();
|
||||||
if (ConfigReader.Config.logTime) AdventureManager.consoleMessage("性能监测: 洒水器数据更新" + (time2-time1) + "ms");
|
if (ConfigReader.Config.logTime) AdventureManager.consoleMessage("性能监测: 洒水器数据更新" + (time2-time1) + "ms");
|
||||||
HashSet<String> players = new HashSet<>(JoinAndQuit.onlinePlayers);
|
//HashSet<String> players = new HashSet<>(JoinAndQuit.onlinePlayers);
|
||||||
|
HashSet<String> players = getPlayers();
|
||||||
if (data.contains(worldName)){
|
if (data.contains(worldName)){
|
||||||
World world = Bukkit.getWorld(worldName);
|
World world = Bukkit.getWorld(worldName);
|
||||||
data.getConfigurationSection(worldName).getKeys(false).forEach(chunk ->{
|
data.getConfigurationSection(worldName).getKeys(false).forEach(chunk ->{
|
||||||
@@ -382,4 +381,12 @@ public class SprinklerManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private HashSet<String> getPlayers(){
|
||||||
|
if (JedisUtil.useRedis){
|
||||||
|
return JedisUtil.getPlayers();
|
||||||
|
}else {
|
||||||
|
return new HashSet<>(JoinAndQuit.onlinePlayers);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package net.momirealms.customcrops.listener;
|
package net.momirealms.customcrops.listener;
|
||||||
|
|
||||||
|
import net.momirealms.customcrops.utils.JedisUtil;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
import org.bukkit.event.player.PlayerJoinEvent;
|
import org.bukkit.event.player.PlayerJoinEvent;
|
||||||
@@ -13,11 +14,19 @@ public class JoinAndQuit implements Listener {
|
|||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onJoin(PlayerJoinEvent event){
|
public void onJoin(PlayerJoinEvent event){
|
||||||
onlinePlayers.add(event.getPlayer().getName());
|
if (JedisUtil.useRedis){
|
||||||
|
JedisUtil.addPlayer(event.getPlayer().getName());
|
||||||
|
}else {
|
||||||
|
onlinePlayers.add(event.getPlayer().getName());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onQuit(PlayerQuitEvent event){
|
public void onQuit(PlayerQuitEvent event){
|
||||||
onlinePlayers.remove(event.getPlayer().getName());
|
if (JedisUtil.useRedis){
|
||||||
|
JedisUtil.remPlayer(event.getPlayer().getName());
|
||||||
|
}else {
|
||||||
|
onlinePlayers.remove(event.getPlayer().getName());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,85 @@
|
|||||||
|
package net.momirealms.customcrops.utils;
|
||||||
|
|
||||||
|
import net.momirealms.customcrops.CustomCrops;
|
||||||
|
import net.momirealms.customcrops.helper.Log;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
|
import redis.clients.jedis.Jedis;
|
||||||
|
import redis.clients.jedis.JedisPool;
|
||||||
|
import redis.clients.jedis.JedisPoolConfig;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class JedisUtil {
|
||||||
|
|
||||||
|
private static JedisPool jedisPool;
|
||||||
|
public static boolean useRedis;
|
||||||
|
|
||||||
|
public static Jedis getJedis(){
|
||||||
|
return jedisPool.getResource();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void initializeRedis(YamlConfiguration configuration){
|
||||||
|
|
||||||
|
JedisPoolConfig jedisPoolConfig = new JedisPoolConfig();
|
||||||
|
jedisPoolConfig.setTestWhileIdle(true);
|
||||||
|
jedisPoolConfig.setTimeBetweenEvictionRunsMillis(30000);
|
||||||
|
jedisPoolConfig.setNumTestsPerEvictionRun(-1);
|
||||||
|
jedisPoolConfig.setMinEvictableIdleTimeMillis(configuration.getInt("redis.MinEvictableIdleTimeMillis",1800000));
|
||||||
|
jedisPoolConfig.setMaxTotal(configuration.getInt("redis.MaxTotal",8));
|
||||||
|
jedisPoolConfig.setMaxIdle(configuration.getInt("redis.MaxIdle",8));
|
||||||
|
jedisPoolConfig.setMinIdle(configuration.getInt("redis.MinIdle",1));
|
||||||
|
jedisPoolConfig.setMaxWaitMillis(configuration.getInt("redis.MaxWaitMillis",30000));
|
||||||
|
|
||||||
|
jedisPool = new JedisPool(jedisPoolConfig, configuration.getString("redis.host","localhost"), configuration.getInt("redis.port",6379));
|
||||||
|
|
||||||
|
AdventureManager.consoleMessage("<gradient:#ff206c:#fdee55>[CustomCrops] <color:#FFEBCD>Redis Enabled!");
|
||||||
|
|
||||||
|
List<Jedis> minIdleJedisList = new ArrayList<>(jedisPoolConfig.getMinIdle());
|
||||||
|
for (int i = 0; i < jedisPoolConfig.getMinIdle(); i++) {
|
||||||
|
Jedis jedis;
|
||||||
|
try {
|
||||||
|
jedis = jedisPool.getResource();
|
||||||
|
minIdleJedisList.add(jedis);
|
||||||
|
jedis.ping();
|
||||||
|
} catch (Exception e) {
|
||||||
|
Log.warn(e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < jedisPoolConfig.getMinIdle(); i++) {
|
||||||
|
Jedis jedis;
|
||||||
|
try {
|
||||||
|
jedis = minIdleJedisList.get(i);
|
||||||
|
jedis.close();
|
||||||
|
} catch (Exception e) {
|
||||||
|
Log.warn(e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void addPlayer(String player){
|
||||||
|
Bukkit.getScheduler().runTaskLaterAsynchronously(CustomCrops.instance, ()->{
|
||||||
|
Jedis jedis = getJedis();
|
||||||
|
jedis.sadd("cc_players", player);
|
||||||
|
jedis.close();
|
||||||
|
}, 20);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void remPlayer(String player){
|
||||||
|
Bukkit.getScheduler().runTaskAsynchronously(CustomCrops.instance, ()->{
|
||||||
|
Jedis jedis = getJedis();
|
||||||
|
jedis.srem("cc_players", player);
|
||||||
|
jedis.close();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public static HashSet<String> getPlayers(){
|
||||||
|
Jedis jedis = getJedis();
|
||||||
|
HashSet<String> players = (HashSet<String>) jedis.smembers("cc_players");
|
||||||
|
jedis.close();
|
||||||
|
return players;
|
||||||
|
}
|
||||||
|
}
|
||||||
11
src/main/resources/redis.yml
Normal file
11
src/main/resources/redis.yml
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
# Sync online players list between servers
|
||||||
|
# Designed for grow-mode 2 & 3
|
||||||
|
redis:
|
||||||
|
enable: false
|
||||||
|
host: localhost
|
||||||
|
port: 6379
|
||||||
|
MaxTotal: 8
|
||||||
|
MaxIdle: 8
|
||||||
|
MinIdle: 1
|
||||||
|
MaxWaitMillis: 30000
|
||||||
|
MinEvictableIdleTimeMillis: 1800000
|
||||||
Reference in New Issue
Block a user