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-09-13 15:34:45 +08:00
parent b306dd3121
commit ed80c56d9b
18 changed files with 64 additions and 8 deletions

View File

@@ -3,9 +3,8 @@ plugins {
id 'com.github.johnrengelman.shadow' version '7.1.2'
}
group = 'net.momirealms'
version = '1.6.3.2'
version = '1.6.3.4'
repositories {
mavenCentral()

View File

@@ -47,6 +47,7 @@ public class ConfigReader {
public static HashMap<String, Fertilizer> FERTILIZERS = new HashMap<>();
public static HashMap<String, WateringCan> CANS = new HashMap<>();
public static HashMap<String, Sprinkler> SPRINKLERS = new HashMap<>();
public static HashSet<String> REALTIME = new HashSet<>();
public static boolean useRedis;
public static YamlConfiguration getConfig(String configName) {
@@ -128,6 +129,11 @@ public class ConfigReader {
rotation = config.getBoolean("config.rotation.enable", false);
oneTry = config.getBoolean("config.gigantic-only-one-try", false);
variant4 = config.getInt("config.rotation.variant", 4) == 4;
if (config.contains("config.real-time")){
REALTIME.clear();
REALTIME.addAll(config.getStringList("config.real-time"));
}
boneMeal = config.getBoolean("config.bone-meal.enable", true);
if (boneMeal){
@@ -359,6 +365,7 @@ public class ConfigReader {
public static String badSeason;
public static String forceGrow;
public static String forceWater;
public static String forceAll;
public static String backUp;
public static String setSeason;
public static String wrongArgs;
@@ -403,6 +410,7 @@ public class ConfigReader {
badSeason = config.getString("messages.bad-season");
forceGrow = config.getString("messages.force-grow");
forceWater = config.getString("messages.force-water");
forceAll = config.getString("messages.force-all","messages.force-all is missing");
backUp = config.getString("messages.back-up");
setSeason = config.getString("messages.set-season");
wrongArgs = config.getString("messages.wrong-args");

View File

@@ -37,7 +37,7 @@ public class Completer implements TabCompleter {
}
if (args.length == 1) {
List<String> arrayList = new ArrayList<>();
for (String cmd : Arrays.asList("backup", "forcegrow", "forcesave", "forcewater", "reload", "setseason")) {
for (String cmd : Arrays.asList("backup", "forcegrow", "forcesave", "forceall","forcewater", "reload", "setseason")) {
if (cmd.startsWith(args[0]))
arrayList.add(cmd);
}
@@ -81,7 +81,7 @@ public class Completer implements TabCompleter {
}
return arrayList;
}
if(args[0].equalsIgnoreCase("forcegrow") || args[0].equalsIgnoreCase("forcewater")){
if(args[0].equalsIgnoreCase("forcegrow") || args[0].equalsIgnoreCase("forcewater") || args[0].equalsIgnoreCase("forceall")){
List<String> arrayList = new ArrayList<>();
for (String cmd : ConfigReader.Config.worldNames) {
if (cmd.startsWith(args[1]))

View File

@@ -100,6 +100,34 @@ public class Executor implements CommandExecutor {
}
return true;
}
case "forceall" -> {
if (args.length < 2) {
lackArgs(sender);
return true;
}
Bukkit.getScheduler().runTaskAsynchronously(CustomCrops.plugin, ()-> {
switch (ConfigReader.Config.growMode){
case 1 -> plugin.getCropManager().growModeOne(args[1]);
case 2 -> plugin.getCropManager().growModeTwo(args[1]);
case 3 -> plugin.getCropManager().growModeThree(args[1]);
case 4 -> plugin.getCropManager().growModeFour(args[1]);
}
});
Bukkit.getScheduler().runTaskLaterAsynchronously(CustomCrops.plugin, ()-> {
switch (ConfigReader.Config.growMode){
case 1 -> plugin.getSprinklerManager().workModeOne(args[1]);
case 2 -> plugin.getSprinklerManager().workModeTwo(args[1]);
case 3 -> plugin.getSprinklerManager().workModeThree(args[1]);
case 4 -> plugin.getSprinklerManager().workModeFour(args[1]);
}
}, ConfigReader.Config.timeToGrow);
if (sender instanceof Player player){
AdventureManager.playerMessage(player,ConfigReader.Message.prefix + ConfigReader.Message.forceAll.replace("{world}",args[1]));
}else {
AdventureManager.consoleMessage(ConfigReader.Message.prefix + ConfigReader.Message.forceAll.replace("{world}",args[1]));
}
return true;
}
case "forcesave" -> {
if (args.length < 2) {
lackArgs(sender);

View File

@@ -43,6 +43,7 @@ public class BreakBlockI implements Listener {
@EventHandler
public void onBreak(CustomBlockBreakEvent event){
if (event.isCancelled()) return;
String namespacedId = event.getNamespacedID();
if(namespacedId.equalsIgnoreCase(ConfigReader.Basic.watered_pot) || namespacedId.equalsIgnoreCase(ConfigReader.Basic.pot)){
Location location = event.getBlock().getLocation();

View File

@@ -48,6 +48,7 @@ public class BreakFurnitureI implements Listener {
@EventHandler
public void onBreakFurniture(FurnitureBreakEvent event){
if (event.isCancelled()) return;
String namespacedID = event.getNamespacedID();
Sprinkler config = ConfigReader.SPRINKLERS.get(namespacedID);
if (config != null){

View File

@@ -58,6 +58,7 @@ public class InteractFurnitureI implements Listener {
@EventHandler
public void onEntityInteract(FurnitureInteractEvent event){
if (event.isCancelled()) return;
long time = System.currentTimeMillis();
Player player = event.getPlayer();
if (time - (JoinAndQuit.coolDown.getOrDefault(player, time - 200)) < 200) return;

View File

@@ -59,6 +59,7 @@ public class RightClickI implements Listener {
@EventHandler
public void onInteract(PlayerInteractEvent event){
if (event.isCancelled()) return;
long time = System.currentTimeMillis();
Player player = event.getPlayer();
if (time - (JoinAndQuit.coolDown.getOrDefault(player, time - 200)) < 200) return;

View File

@@ -45,17 +45,21 @@ import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.inventory.ItemStack;
import java.util.HashMap;
import java.util.List;
import java.util.concurrent.ThreadLocalRandom;
public class BreakBlockT implements Listener {
private HashMap<Player, Long> coolDown = new HashMap<>();
@EventHandler
public void onBreak(CustomBlockBreakEvent event){
if (event.isCancelled()) return;
long time = System.currentTimeMillis();
Player player = event.getPlayer();
if (time - (JoinAndQuit.coolDown.getOrDefault(player, time - 150)) < 150) return;
JoinAndQuit.coolDown.put(player, time);
if (time - (coolDown.getOrDefault(player, time - 100)) < 80) return;
coolDown.put(player, time);
String namespacedId = event.getNamespacedID();
if(namespacedId.contains("_stage_")){
Location location = event.getBlock().getLocation();

View File

@@ -30,6 +30,7 @@ public class BreakFurnitureT implements Listener {
@EventHandler
public void onBreakFurniture(FurnitureBreakEvent event){
if (event.isCancelled()) return;
Sprinkler config = ConfigReader.SPRINKLERS.get(event.getNamespacedID());
if (config != null){
SimpleLocation simpleLocation = LocUtil.fromLocation(event.getBukkitEntity().getLocation());

View File

@@ -47,6 +47,7 @@ public class InteractFurnitureT implements Listener {
@EventHandler
public void onEntityInteract(FurnitureInteractEvent event){
if (event.isCancelled()) return;
Sprinkler config = ConfigReader.SPRINKLERS.get(event.getNamespacedID());
if(config != null){
long time = System.currentTimeMillis();

View File

@@ -64,6 +64,7 @@ public class RightClickT implements Listener {
@EventHandler
public void onInteract(PlayerInteractEvent event){
if (event.isCancelled()) return;
long time = System.currentTimeMillis();
Player player = event.getPlayer();
if (time - (JoinAndQuit.coolDown.getOrDefault(player, time - 200)) < 200) return;

View File

@@ -27,5 +27,4 @@ public class DropUtil {
}
}
}
}

View File

@@ -1,5 +1,5 @@
#Don't change
config-version: '6'
config-version: '7'
#Want to sell the crops?
#Try this plugin: https://www.spigotmc.org/resources/shipping-bin.104591/
@@ -91,6 +91,11 @@ config:
# Sprinklers will work after all crops finish growing
grow-time:
- 1000
# Time in real life
#real-time:
# - 06:30
# Time in random a single crop need to growseconds
# This prevents a large amount of crops grow at the same time
# Large amount of block replacement would cause lag.

View File

@@ -21,6 +21,7 @@ messages:
force-grow: '<white>成功强制 {world} 的农作物生长!'
force-water: '<white>成功强制 {world} 的洒水器洒水!'
force-save: '<white>成功强制保存缓存信息!'
force-all: '<white>成功强制 {world} 的农作物生长和洒水器工作!'
back-up: '<white>已完成数据备份!'
set-season: '<white>成功切换世界 {world} 的季节为 {season}!'
before-plant: '<white>这种肥料必须在种植前使用!'

View File

@@ -21,6 +21,7 @@ messages:
force-grow: '<white>Forced {world}''s crops to start growing!'
force-water: '<white>Forced {world}''s sprinklers to start working!'
force-save: '<white>Successfully saved cache to file!'
force-all: '<white>Forced {world}''s crops to start growing and sprinklers to start working!'
back-up: '<white>Backed up!'
set-season: '<white>Changed {world}''s season to {season}!'
before-plant: '<white>This fertilizer must be used befored planting!'

View File

@@ -21,6 +21,7 @@ messages:
force-grow: '<white>¡Forzó a los cultivos de {world} a empezar a crecer!'
force-water: '<white>¡Forzó a los aspersores del {world} a empezar a crecer!'
force-save: '<white>¡Guardado con éxito la caché en un archivo!'
force-all: '<white>Forced {world}''s crops to start growing and sprinklers to start working!'
back-up: '<white>Backed up!'
set-season: '<white>¡Cambió la estación de {world} a {season}!'
before-plant: '<white>Este abono debe utilizarse antes de la siembra.'

View File

@@ -81,6 +81,9 @@ config:
# 洒水器将在所有农作物完成生长后开始工作
grow-time:
- 1000
# 现实时间
#real-time:
# - 06:30
# 农作物将在开始生长的时间点后多少秒内完成生长seconds
# 这是为了避免大量农作物在同一时间点进行判断和方块替换,否则会造成卡顿
# 假如你有100个农作物默认配置代表在游戏时间7点后的现实时间60秒内100个农作物会在这60秒内随机时间点完成生长