mirror of
https://github.com/Xiao-MoMi/Custom-Crops.git
synced 2025-12-22 08:29:35 +00:00
KingdomsX 兼容
This commit is contained in:
@@ -3,6 +3,7 @@ package net.momirealms.customcrops;
|
|||||||
import net.momirealms.customcrops.DataManager.BackUp;
|
import net.momirealms.customcrops.DataManager.BackUp;
|
||||||
import net.momirealms.customcrops.DataManager.CropManager;
|
import net.momirealms.customcrops.DataManager.CropManager;
|
||||||
import net.momirealms.customcrops.DataManager.SprinklerManager;
|
import net.momirealms.customcrops.DataManager.SprinklerManager;
|
||||||
|
import net.momirealms.customcrops.Integrations.KingdomsXIntegrations;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.CommandExecutor;
|
import org.bukkit.command.CommandExecutor;
|
||||||
@@ -26,6 +27,7 @@ public class CommandHandler implements CommandExecutor {
|
|||||||
|
|
||||||
FileConfiguration config = CustomCrops.instance.getConfig();
|
FileConfiguration config = CustomCrops.instance.getConfig();
|
||||||
|
|
||||||
|
//重载插件
|
||||||
if(args[0].equalsIgnoreCase("reload")){
|
if(args[0].equalsIgnoreCase("reload")){
|
||||||
CustomCrops.loadConfig();
|
CustomCrops.loadConfig();
|
||||||
if(sender instanceof Player){
|
if(sender instanceof Player){
|
||||||
@@ -34,7 +36,7 @@ public class CommandHandler implements CommandExecutor {
|
|||||||
MessageManager.consoleMessage(config.getString("messages.prefix") + config.getString("messages.reload"), Bukkit.getConsoleSender());
|
MessageManager.consoleMessage(config.getString("messages.prefix") + config.getString("messages.reload"), Bukkit.getConsoleSender());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
//设置季节
|
||||||
if(args[0].equalsIgnoreCase("setseason")){
|
if(args[0].equalsIgnoreCase("setseason")){
|
||||||
if(config.getBoolean("enable-season")){
|
if(config.getBoolean("enable-season")){
|
||||||
config.set("current-season", args[1]);
|
config.set("current-season", args[1]);
|
||||||
@@ -60,7 +62,7 @@ public class CommandHandler implements CommandExecutor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
//强制保存
|
||||||
if(args[0].equalsIgnoreCase("forcesave")){
|
if(args[0].equalsIgnoreCase("forcesave")){
|
||||||
CropManager.saveData();
|
CropManager.saveData();
|
||||||
SprinklerManager.saveData();
|
SprinklerManager.saveData();
|
||||||
@@ -70,7 +72,7 @@ public class CommandHandler implements CommandExecutor {
|
|||||||
MessageManager.consoleMessage(config.getString("messages.prefix") + config.getString("messages.force-save"), Bukkit.getConsoleSender());
|
MessageManager.consoleMessage(config.getString("messages.prefix") + config.getString("messages.force-save"), Bukkit.getConsoleSender());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
//清除缓存
|
||||||
if(args[0].equalsIgnoreCase("cleancache")){
|
if(args[0].equalsIgnoreCase("cleancache")){
|
||||||
Bukkit.getScheduler().runTaskAsynchronously(CustomCrops.instance,()->{
|
Bukkit.getScheduler().runTaskAsynchronously(CustomCrops.instance,()->{
|
||||||
CropManager.cleanLoadedCache();
|
CropManager.cleanLoadedCache();
|
||||||
@@ -82,7 +84,6 @@ public class CommandHandler implements CommandExecutor {
|
|||||||
MessageManager.consoleMessage(config.getString("messages.prefix") + config.getString("messages.clean-cache"), Bukkit.getConsoleSender());
|
MessageManager.consoleMessage(config.getString("messages.prefix") + config.getString("messages.clean-cache"), Bukkit.getConsoleSender());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(args[0].equalsIgnoreCase("backup")){
|
if(args[0].equalsIgnoreCase("backup")){
|
||||||
BackUp.backUpData();
|
BackUp.backUpData();
|
||||||
if(sender instanceof Player){
|
if(sender instanceof Player){
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ import java.util.Objects;
|
|||||||
|
|
||||||
public class TimeCheck extends BukkitRunnable {
|
public class TimeCheck extends BukkitRunnable {
|
||||||
|
|
||||||
FileConfiguration config = CustomCrops.instance.getConfig();
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
@@ -30,6 +30,7 @@ public class TimeCheck extends BukkitRunnable {
|
|||||||
CropManager.saveData();
|
CropManager.saveData();
|
||||||
}
|
}
|
||||||
if(time == 23900){
|
if(time == 23900){
|
||||||
|
FileConfiguration config = CustomCrops.instance.getConfig();
|
||||||
File file = new File(CustomCrops.instance.getDataFolder(), "crop-data.yml");
|
File file = new File(CustomCrops.instance.getDataFolder(), "crop-data.yml");
|
||||||
FileConfiguration data;
|
FileConfiguration data;
|
||||||
data = YamlConfiguration.loadConfiguration(file);
|
data = YamlConfiguration.loadConfiguration(file);
|
||||||
@@ -126,6 +127,7 @@ public class TimeCheck extends BukkitRunnable {
|
|||||||
SprinklerManager.saveData();
|
SprinklerManager.saveData();
|
||||||
}
|
}
|
||||||
if(time == 500){
|
if(time == 500){
|
||||||
|
FileConfiguration config = CustomCrops.instance.getConfig();
|
||||||
File file = new File(CustomCrops.instance.getDataFolder(), "sprinkler-data.yml");
|
File file = new File(CustomCrops.instance.getDataFolder(), "sprinkler-data.yml");
|
||||||
FileConfiguration data;
|
FileConfiguration data;
|
||||||
data = YamlConfiguration.loadConfiguration(file);
|
data = YamlConfiguration.loadConfiguration(file);
|
||||||
@@ -136,21 +138,21 @@ public class TimeCheck extends BukkitRunnable {
|
|||||||
for(int i = -1; i <= 1;i++){
|
for(int i = -1; i <= 1;i++){
|
||||||
for (int j = -1; j <= 1; j++){
|
for (int j = -1; j <= 1; j++){
|
||||||
Location tempLoc = location.clone().add(i,-1,j);
|
Location tempLoc = location.clone().add(i,-1,j);
|
||||||
waterPot(tempLoc, world);
|
waterPot(tempLoc, world, config);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}else if(type.equals("s2")){
|
}else if(type.equals("s2")){
|
||||||
for(int i = -2; i <= 2;i++){
|
for(int i = -2; i <= 2;i++){
|
||||||
for (int j = -2; j <= 2; j++){
|
for (int j = -2; j <= 2; j++){
|
||||||
Location tempLoc = location.clone().add(i,-1,j);
|
Location tempLoc = location.clone().add(i,-1,j);
|
||||||
waterPot(tempLoc, world);
|
waterPot(tempLoc, world, config);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
private void waterPot(Location tempLoc, World world) {
|
private void waterPot(Location tempLoc, World world, FileConfiguration config) {
|
||||||
if(CustomBlock.byAlreadyPlaced(world.getBlockAt(tempLoc)) != null){
|
if(CustomBlock.byAlreadyPlaced(world.getBlockAt(tempLoc)) != null){
|
||||||
if(CustomBlock.byAlreadyPlaced(world.getBlockAt(tempLoc)).getNamespacedID().equalsIgnoreCase(config.getString("config.pot"))){
|
if(CustomBlock.byAlreadyPlaced(world.getBlockAt(tempLoc)).getNamespacedID().equalsIgnoreCase(config.getString("config.pot"))){
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,12 @@
|
|||||||
package net.momirealms.customcrops;
|
package net.momirealms.customcrops;
|
||||||
|
|
||||||
|
import com.comphenix.protocol.PacketType;
|
||||||
|
import com.comphenix.protocol.ProtocolLibrary;
|
||||||
|
import com.comphenix.protocol.ProtocolManager;
|
||||||
|
import com.comphenix.protocol.events.PacketAdapter;
|
||||||
|
import com.comphenix.protocol.events.PacketContainer;
|
||||||
|
import com.comphenix.protocol.events.PacketEvent;
|
||||||
|
import com.comphenix.protocol.wrappers.WrappedChatComponent;
|
||||||
import net.kyori.adventure.platform.bukkit.BukkitAudiences;
|
import net.kyori.adventure.platform.bukkit.BukkitAudiences;
|
||||||
import net.momirealms.customcrops.Crops.CropTimer;
|
import net.momirealms.customcrops.Crops.CropTimer;
|
||||||
import net.momirealms.customcrops.DataManager.BackUp;
|
import net.momirealms.customcrops.DataManager.BackUp;
|
||||||
@@ -34,6 +41,7 @@ public final class CustomCrops extends JavaPlugin {
|
|||||||
instance = this;
|
instance = this;
|
||||||
saveDefaultConfig();
|
saveDefaultConfig();
|
||||||
|
|
||||||
|
//指令注册
|
||||||
Objects.requireNonNull(Bukkit.getPluginCommand("customcrops")).setExecutor(new CommandHandler());
|
Objects.requireNonNull(Bukkit.getPluginCommand("customcrops")).setExecutor(new CommandHandler());
|
||||||
Objects.requireNonNull(Bukkit.getPluginCommand("customcrops")).setTabCompleter(new CommandTabComplete());
|
Objects.requireNonNull(Bukkit.getPluginCommand("customcrops")).setTabCompleter(new CommandTabComplete());
|
||||||
Bukkit.getPluginManager().registerEvents(new RightClickCustomBlock(),this);
|
Bukkit.getPluginManager().registerEvents(new RightClickCustomBlock(),this);
|
||||||
@@ -41,8 +49,26 @@ public final class CustomCrops extends JavaPlugin {
|
|||||||
Bukkit.getPluginManager().registerEvents(new RightClickBlock(),this);
|
Bukkit.getPluginManager().registerEvents(new RightClickBlock(),this);
|
||||||
Bukkit.getPluginManager().registerEvents(new BreakFurniture(),this);
|
Bukkit.getPluginManager().registerEvents(new BreakFurniture(),this);
|
||||||
|
|
||||||
|
//修改末影箱标题
|
||||||
|
manager = ProtocolLibrary.getProtocolManager();
|
||||||
|
manager.addPacketListener(new PacketAdapter(this, PacketType.Play.Server.OPEN_WINDOW) {
|
||||||
|
public void onPacketSending(PacketEvent event) {
|
||||||
|
PacketContainer packet = event.getPacket();
|
||||||
|
List<WrappedChatComponent> components = packet.getChatComponents().getValues();
|
||||||
|
for (WrappedChatComponent component : components) {
|
||||||
|
if(component.toString().contains("Ender Chest")){
|
||||||
|
//component.setJson("{\"text\":\"收纳袋\"}");
|
||||||
|
component.setJson("{\"translate\":\"container.enderchest\"}");
|
||||||
|
packet.getChatComponents().write(components.indexOf(component), component);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
//开始计时任务
|
||||||
startTimer();
|
startTimer();
|
||||||
|
|
||||||
|
//新建data文件
|
||||||
File crop_file = new File(CustomCrops.instance.getDataFolder(), "crop-data.yml");
|
File crop_file = new File(CustomCrops.instance.getDataFolder(), "crop-data.yml");
|
||||||
File sprinkler_file = new File(CustomCrops.instance.getDataFolder(), "sprinkler-data.yml");
|
File sprinkler_file = new File(CustomCrops.instance.getDataFolder(), "sprinkler-data.yml");
|
||||||
if(!crop_file.exists()){
|
if(!crop_file.exists()){
|
||||||
@@ -60,6 +86,7 @@ public final class CustomCrops extends JavaPlugin {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//载入data数据
|
||||||
FileConfiguration crop_data;
|
FileConfiguration crop_data;
|
||||||
FileConfiguration sprinkler_data;
|
FileConfiguration sprinkler_data;
|
||||||
crop_data = YamlConfiguration.loadConfiguration(crop_file);
|
crop_data = YamlConfiguration.loadConfiguration(crop_file);
|
||||||
@@ -67,30 +94,35 @@ public final class CustomCrops extends JavaPlugin {
|
|||||||
CustomCrops.cropManager = new CropManager(crop_data);
|
CustomCrops.cropManager = new CropManager(crop_data);
|
||||||
CustomCrops.sprinklerManager = new SprinklerManager(sprinkler_data);
|
CustomCrops.sprinklerManager = new SprinklerManager(sprinkler_data);
|
||||||
|
|
||||||
|
//检测papi依赖
|
||||||
if(Bukkit.getPluginManager().getPlugin("PlaceholderAPI") != null){
|
if(Bukkit.getPluginManager().getPlugin("PlaceholderAPI") != null){
|
||||||
new Placeholders(this).register();
|
new Placeholders(this).register();
|
||||||
MessageManager.consoleMessage("<gradient:#ccfbff:#ef96c5>[CustomCorps] 检测到PlaceHolderAPI 已启用季节变量!</gradient>",Bukkit.getConsoleSender());
|
MessageManager.consoleMessage("<gradient:#ccfbff:#ef96c5>[CustomCorps] 检测到PlaceHolderAPI 已启用季节变量!</gradient>",Bukkit.getConsoleSender());
|
||||||
}
|
}
|
||||||
|
//启动成功
|
||||||
MessageManager.consoleMessage("<gradient:#ccfbff:#ef96c5>[CustomCorps] 自定义农作物插件已启用!作者:小默米</gradient>",Bukkit.getConsoleSender());
|
MessageManager.consoleMessage("<gradient:#ccfbff:#ef96c5>[CustomCorps] 自定义农作物插件已启用!作者:小默米 QQ:3266959688</gradient>",Bukkit.getConsoleSender());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDisable() {
|
public void onDisable() {
|
||||||
|
//关闭异步定时任务
|
||||||
if (CustomCrops.timer != null) {
|
if (CustomCrops.timer != null) {
|
||||||
CropTimer.stopTimer(CustomCrops.timer.getTaskID());
|
CropTimer.stopTimer(CustomCrops.timer.getTaskID());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//保存缓存中的数据
|
||||||
CropManager.saveData();
|
CropManager.saveData();
|
||||||
SprinklerManager.saveData();
|
SprinklerManager.saveData();
|
||||||
|
|
||||||
|
//关闭adventure
|
||||||
if(this.adventure != null) {
|
if(this.adventure != null) {
|
||||||
this.adventure.close();
|
this.adventure.close();
|
||||||
this.adventure = null;
|
this.adventure = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//备份
|
||||||
BackUp.backUpData();
|
BackUp.backUpData();
|
||||||
MessageManager.consoleMessage("<gradient:#ccfbff:#ef96c5>[CustomCorps] 自定义农作物插件已卸载!作者:小默米</gradient>",Bukkit.getConsoleSender());
|
MessageManager.consoleMessage("<gradient:#ccfbff:#ef96c5>[CustomCorps] 自定义农作物插件已卸载!作者:小默米 QQ:3266959688</gradient>",Bukkit.getConsoleSender());
|
||||||
}
|
}
|
||||||
|
|
||||||
public @NonNull BukkitAudiences adventure() {
|
public @NonNull BukkitAudiences adventure() {
|
||||||
@@ -100,10 +132,12 @@ public final class CustomCrops extends JavaPlugin {
|
|||||||
return this.adventure;
|
return this.adventure;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//定时任务
|
||||||
public static void startTimer() {
|
public static void startTimer() {
|
||||||
CustomCrops.timer = new CropTimer();
|
CustomCrops.timer = new CropTimer();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//重载插件
|
||||||
public static void loadConfig(){
|
public static void loadConfig(){
|
||||||
instance.reloadConfig();
|
instance.reloadConfig();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ import java.util.*;
|
|||||||
public class CropManager {
|
public class CropManager {
|
||||||
|
|
||||||
public static HashMap<Location, String> instances;
|
public static HashMap<Location, String> instances;
|
||||||
|
//开服的时候将文件的数据读入
|
||||||
public CropManager(FileConfiguration data) {
|
public CropManager(FileConfiguration data) {
|
||||||
FileConfiguration config = CustomCrops.instance.getConfig();
|
FileConfiguration config = CustomCrops.instance.getConfig();
|
||||||
File file = new File(CustomCrops.instance.getDataFolder(), "crop-data.yml");
|
File file = new File(CustomCrops.instance.getDataFolder(), "crop-data.yml");
|
||||||
@@ -38,7 +38,7 @@ public class CropManager {
|
|||||||
}
|
}
|
||||||
saveData();
|
saveData();
|
||||||
}
|
}
|
||||||
|
//根据世界名获取所有的农作物
|
||||||
public static List<Location> getCrops(World world){
|
public static List<Location> getCrops(World world){
|
||||||
FileConfiguration config = CustomCrops.instance.getConfig();
|
FileConfiguration config = CustomCrops.instance.getConfig();
|
||||||
File file = new File(CustomCrops.instance.getDataFolder(), "crop-data.yml");
|
File file = new File(CustomCrops.instance.getDataFolder(), "crop-data.yml");
|
||||||
@@ -61,12 +61,13 @@ public class CropManager {
|
|||||||
}
|
}
|
||||||
return locations;
|
return locations;
|
||||||
}
|
}
|
||||||
|
//保存数据
|
||||||
public static void saveData(){
|
public static void saveData(){
|
||||||
File file = new File(CustomCrops.instance.getDataFolder(), "crop-data.yml");
|
File file = new File(CustomCrops.instance.getDataFolder(), "crop-data.yml");
|
||||||
FileConfiguration data;
|
FileConfiguration data;
|
||||||
data = YamlConfiguration.loadConfiguration(file);
|
data = YamlConfiguration.loadConfiguration(file);
|
||||||
if (CropManager.instances != null) {
|
if (CropManager.instances != null) {
|
||||||
|
//性能更高
|
||||||
Set<Map.Entry<Location, String>> en = instances.entrySet();
|
Set<Map.Entry<Location, String>> en = instances.entrySet();
|
||||||
for(Map.Entry<Location, String> entry : en){
|
for(Map.Entry<Location, String> entry : en){
|
||||||
data.set(entry.getKey().getWorld().getName() + "." + entry.getKey().getBlockX() + "," + entry.getKey().getBlockY()+ ","+entry.getKey().getBlockZ(), entry.getValue());
|
data.set(entry.getKey().getWorld().getName() + "." + entry.getKey().getBlockX() + "," + entry.getKey().getBlockY()+ ","+entry.getKey().getBlockZ(), entry.getValue());
|
||||||
@@ -74,7 +75,7 @@ public class CropManager {
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
CropManager.instances = new HashMap<Location, String>();
|
CropManager.instances = new HashMap<Location, String>();
|
||||||
Bukkit.getConsoleSender().sendMessage("错误");
|
Bukkit.getConsoleSender().sendMessage("错误类型1:请联系开发者并提供报错信息");
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
data.save(file);
|
data.save(file);
|
||||||
@@ -84,12 +85,21 @@ public class CropManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
//test
|
//test
|
||||||
|
public static void testData(){
|
||||||
|
for(int i = 1; i < 100000;i++){
|
||||||
|
Location tempLoc = new Location(Bukkit.getWorld("world"),i,100,i);
|
||||||
|
String name = "1";
|
||||||
|
instances.put(tempLoc, name);
|
||||||
|
}
|
||||||
|
}
|
||||||
public static void putInstance(Location location, String season) {
|
public static void putInstance(Location location, String season) {
|
||||||
CropManager.instances.put(location, season);
|
CropManager.instances.put(location, season);
|
||||||
}
|
}
|
||||||
public HashMap<Location, String> getMap() {
|
public HashMap<Location, String> getMap() {
|
||||||
return CropManager.instances;
|
return CropManager.instances;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//清理无效的农作物
|
||||||
public static void cleanLoadedCache() {
|
public static void cleanLoadedCache() {
|
||||||
FileConfiguration config = CustomCrops.instance.getConfig();
|
FileConfiguration config = CustomCrops.instance.getConfig();
|
||||||
File file = new File(CustomCrops.instance.getDataFolder(), "crop-data.yml");
|
File file = new File(CustomCrops.instance.getDataFolder(), "crop-data.yml");
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ public class SprinklerManager {
|
|||||||
|
|
||||||
public static HashMap<Location, String> instances;
|
public static HashMap<Location, String> instances;
|
||||||
|
|
||||||
|
//开服的时候将文件的数据读入
|
||||||
public SprinklerManager(FileConfiguration data) {
|
public SprinklerManager(FileConfiguration data) {
|
||||||
FileConfiguration config = CustomCrops.instance.getConfig();
|
FileConfiguration config = CustomCrops.instance.getConfig();
|
||||||
File file = new File(CustomCrops.instance.getDataFolder(), "sprinkler-data.yml");
|
File file = new File(CustomCrops.instance.getDataFolder(), "sprinkler-data.yml");
|
||||||
@@ -38,7 +39,7 @@ public class SprinklerManager {
|
|||||||
}
|
}
|
||||||
saveData();
|
saveData();
|
||||||
}
|
}
|
||||||
|
//根据世界名获取所有的洒水器
|
||||||
public static List<Location> getSprinklers(World world){
|
public static List<Location> getSprinklers(World world){
|
||||||
FileConfiguration config = CustomCrops.instance.getConfig();
|
FileConfiguration config = CustomCrops.instance.getConfig();
|
||||||
File file = new File(CustomCrops.instance.getDataFolder(), "sprinkler-data.yml");
|
File file = new File(CustomCrops.instance.getDataFolder(), "sprinkler-data.yml");
|
||||||
@@ -49,6 +50,7 @@ public class SprinklerManager {
|
|||||||
if(data.contains(world.getName())){
|
if(data.contains(world.getName())){
|
||||||
data.getConfigurationSection(world.getName()).getKeys(false).forEach(key ->{
|
data.getConfigurationSection(world.getName()).getKeys(false).forEach(key ->{
|
||||||
String[] string_list = key.split(",");
|
String[] string_list = key.split(",");
|
||||||
|
//只返回被加载的区块中的洒水器坐标
|
||||||
if (config.getBoolean("config.only-grow-in-loaded-chunks")){
|
if (config.getBoolean("config.only-grow-in-loaded-chunks")){
|
||||||
if (world.isChunkLoaded(Integer.parseInt(string_list[0])/16, Integer.parseInt(string_list[2])/16)){
|
if (world.isChunkLoaded(Integer.parseInt(string_list[0])/16, Integer.parseInt(string_list[2])/16)){
|
||||||
locations.add(new Location(world, Double.parseDouble(string_list[0]),Double.parseDouble(string_list[1]),Double.parseDouble(string_list[2])));
|
locations.add(new Location(world, Double.parseDouble(string_list[0]),Double.parseDouble(string_list[1]),Double.parseDouble(string_list[2])));
|
||||||
@@ -61,12 +63,13 @@ public class SprinklerManager {
|
|||||||
}
|
}
|
||||||
return locations;
|
return locations;
|
||||||
}
|
}
|
||||||
|
//保存数据
|
||||||
public static void saveData(){
|
public static void saveData(){
|
||||||
File file = new File(CustomCrops.instance.getDataFolder(), "sprinkler-data.yml");
|
File file = new File(CustomCrops.instance.getDataFolder(), "sprinkler-data.yml");
|
||||||
FileConfiguration data;
|
FileConfiguration data;
|
||||||
data = YamlConfiguration.loadConfiguration(file);
|
data = YamlConfiguration.loadConfiguration(file);
|
||||||
if (SprinklerManager.instances != null) {
|
if (SprinklerManager.instances != null) {
|
||||||
|
//性能更高
|
||||||
Set<Map.Entry<Location, String>> en = instances.entrySet();
|
Set<Map.Entry<Location, String>> en = instances.entrySet();
|
||||||
for(Map.Entry<Location, String> entry : en){
|
for(Map.Entry<Location, String> entry : en){
|
||||||
data.set(entry.getKey().getWorld().getName() + "." + entry.getKey().getBlockX() + "," + entry.getKey().getBlockY()+ ","+entry.getKey().getBlockZ(), entry.getValue());
|
data.set(entry.getKey().getWorld().getName() + "." + entry.getKey().getBlockX() + "," + entry.getKey().getBlockY()+ ","+entry.getKey().getBlockZ(), entry.getValue());
|
||||||
@@ -74,7 +77,7 @@ public class SprinklerManager {
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
SprinklerManager.instances = new HashMap<Location, String>();
|
SprinklerManager.instances = new HashMap<Location, String>();
|
||||||
Bukkit.getConsoleSender().sendMessage("错误");
|
Bukkit.getConsoleSender().sendMessage("错误:请联系开发者并提供报错信息");
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
data.save(file);
|
data.save(file);
|
||||||
@@ -90,6 +93,8 @@ public class SprinklerManager {
|
|||||||
File file = new File(CustomCrops.instance.getDataFolder(), "sprinkler-data.yml");
|
File file = new File(CustomCrops.instance.getDataFolder(), "sprinkler-data.yml");
|
||||||
FileConfiguration data;
|
FileConfiguration data;
|
||||||
data = YamlConfiguration.loadConfiguration(file);
|
data = YamlConfiguration.loadConfiguration(file);
|
||||||
|
//map不能一边循环一边删除
|
||||||
|
//创建一个新的HashSet,用作循环
|
||||||
Bukkit.getScheduler().callSyncMethod(CustomCrops.instance,()->{
|
Bukkit.getScheduler().callSyncMethod(CustomCrops.instance,()->{
|
||||||
Set<Location> key = new HashSet(instances.keySet());
|
Set<Location> key = new HashSet(instances.keySet());
|
||||||
try{
|
try{
|
||||||
|
|||||||
@@ -11,10 +11,12 @@ public class IAFurniture {
|
|||||||
|
|
||||||
static FileConfiguration config = CustomCrops.instance.getConfig();
|
static FileConfiguration config = CustomCrops.instance.getConfig();
|
||||||
|
|
||||||
|
//放置IA自定义家具
|
||||||
public static void placeFurniture(String name, Location location){
|
public static void placeFurniture(String name, Location location){
|
||||||
CustomFurniture.spawn(name,location.getWorld().getBlockAt(location));
|
CustomFurniture.spawn(name,location.getWorld().getBlockAt(location));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//根据位置获取盔甲架,如果是洒水器返回true,否则返回false
|
||||||
public static boolean getFromLocation(Location location, World world){
|
public static boolean getFromLocation(Location location, World world){
|
||||||
for(Entity entity : world.getNearbyEntities(location,0,0,0)){
|
for(Entity entity : world.getNearbyEntities(location,0,0,0)){
|
||||||
if(entity instanceof ArmorStand){
|
if(entity instanceof ArmorStand){
|
||||||
|
|||||||
@@ -0,0 +1,25 @@
|
|||||||
|
package net.momirealms.customcrops.Integrations;
|
||||||
|
|
||||||
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.kingdoms.constants.group.Kingdom;
|
||||||
|
import org.kingdoms.constants.land.Land;
|
||||||
|
import org.kingdoms.constants.player.KingdomPlayer;
|
||||||
|
|
||||||
|
public class KingdomsXIntegrations {
|
||||||
|
public static boolean checkKDBuild(Location location, Player player){
|
||||||
|
KingdomPlayer kp = KingdomPlayer.getKingdomPlayer(player);
|
||||||
|
Land land = Land.getLand(location);
|
||||||
|
if (land == null) return false;
|
||||||
|
if (land.isClaimed()) {
|
||||||
|
Kingdom cropKingdom = land.getKingdom();
|
||||||
|
if (kp.getKingdom() != null) {
|
||||||
|
Kingdom kingdom = kp.getKingdom();
|
||||||
|
return kingdom != cropKingdom;
|
||||||
|
}else {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -3,35 +3,29 @@ package net.momirealms.customcrops.Integrations;
|
|||||||
import com.bekvon.bukkit.residence.protection.ClaimedResidence;
|
import com.bekvon.bukkit.residence.protection.ClaimedResidence;
|
||||||
import com.bekvon.bukkit.residence.protection.FlagPermissions;
|
import com.bekvon.bukkit.residence.protection.FlagPermissions;
|
||||||
import com.bekvon.bukkit.residence.protection.ResidencePermissions;
|
import com.bekvon.bukkit.residence.protection.ResidencePermissions;
|
||||||
import dev.lone.itemsadder.api.Events.CustomBlockInteractEvent;
|
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
public class ResidenceIntegrations {
|
public class ResidenceIntegrations {
|
||||||
public static boolean checkResBuild(Location location, CustomBlockInteractEvent event){
|
public static boolean checkResBuild(Location location, Player player){
|
||||||
FlagPermissions.addFlag("build");
|
FlagPermissions.addFlag("build");
|
||||||
ClaimedResidence res = com.bekvon.bukkit.residence.Residence.getInstance().getResidenceManager().getByLoc(location);
|
ClaimedResidence res = com.bekvon.bukkit.residence.Residence.getInstance().getResidenceManager().getByLoc(location);
|
||||||
if(res!=null){
|
if(res!=null){
|
||||||
ResidencePermissions perms = res.getPermissions();
|
ResidencePermissions perms = res.getPermissions();
|
||||||
String playerName = event.getPlayer().getName();
|
String playerName = player.getName();
|
||||||
boolean hasPermission = perms.playerHas(playerName, "build", true);
|
boolean hasPermission = perms.playerHas(playerName, "build", true);
|
||||||
if(!hasPermission){
|
return !hasPermission;
|
||||||
event.setCancelled(true);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
public static boolean checkResHarvest(Location location, CustomBlockInteractEvent event){
|
public static boolean checkResHarvest(Location location, Player player){
|
||||||
FlagPermissions.addFlag("harvest");
|
FlagPermissions.addFlag("harvest");
|
||||||
ClaimedResidence res = com.bekvon.bukkit.residence.Residence.getInstance().getResidenceManager().getByLoc(location);
|
ClaimedResidence res = com.bekvon.bukkit.residence.Residence.getInstance().getResidenceManager().getByLoc(location);
|
||||||
if(res!=null){
|
if(res!=null){
|
||||||
ResidencePermissions perms = res.getPermissions();
|
ResidencePermissions perms = res.getPermissions();
|
||||||
String playerName = event.getPlayer().getName();
|
String playerName = player.getName();
|
||||||
boolean hasPermission = perms.playerHas(playerName, "harvest", true);
|
boolean hasPermission = perms.playerHas(playerName, "harvest", true);
|
||||||
if(!hasPermission){
|
return !hasPermission;
|
||||||
event.setCancelled(true);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,31 +7,28 @@ import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
|
|||||||
import com.sk89q.worldguard.protection.flags.Flags;
|
import com.sk89q.worldguard.protection.flags.Flags;
|
||||||
import com.sk89q.worldguard.protection.regions.RegionContainer;
|
import com.sk89q.worldguard.protection.regions.RegionContainer;
|
||||||
import com.sk89q.worldguard.protection.regions.RegionQuery;
|
import com.sk89q.worldguard.protection.regions.RegionQuery;
|
||||||
import dev.lone.itemsadder.api.Events.CustomBlockInteractEvent;
|
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
public class WorldGuardIntegrations {
|
public class WorldGuardIntegrations {
|
||||||
public static boolean checkWGBuild(Player player, Location loc, CustomBlockInteractEvent event){
|
public static boolean checkWGBuild(Location loc,Player player){
|
||||||
|
|
||||||
LocalPlayer localPlayer = WorldGuardPlugin.inst().wrapPlayer(player);
|
LocalPlayer localPlayer = WorldGuardPlugin.inst().wrapPlayer(player);
|
||||||
RegionContainer container = WorldGuard.getInstance().getPlatform().getRegionContainer();
|
RegionContainer container = WorldGuard.getInstance().getPlatform().getRegionContainer();
|
||||||
RegionQuery query = container.createQuery();
|
RegionQuery query = container.createQuery();
|
||||||
|
|
||||||
if (!query.testState(BukkitAdapter.adapt(loc), localPlayer, Flags.BUILD)) {
|
if (!query.testState(BukkitAdapter.adapt(loc), localPlayer, Flags.BUILD)) {
|
||||||
event.setCancelled(true);
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
public static boolean checkWGHarvest(Player player, Location loc, CustomBlockInteractEvent event){
|
public static boolean checkWGHarvest(Location loc,Player player){
|
||||||
|
|
||||||
LocalPlayer localPlayer = WorldGuardPlugin.inst().wrapPlayer(player);
|
LocalPlayer localPlayer = WorldGuardPlugin.inst().wrapPlayer(player);
|
||||||
RegionContainer container = WorldGuard.getInstance().getPlatform().getRegionContainer();
|
RegionContainer container = WorldGuard.getInstance().getPlatform().getRegionContainer();
|
||||||
RegionQuery query = container.createQuery();
|
RegionQuery query = container.createQuery();
|
||||||
|
|
||||||
if (!query.testState(BukkitAdapter.adapt(loc), localPlayer, Flags.BLOCK_BREAK)) {
|
if (!query.testState(BukkitAdapter.adapt(loc), localPlayer, Flags.BLOCK_BREAK)) {
|
||||||
event.setCancelled(true);
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@@ -13,10 +13,9 @@ import org.bukkit.event.Listener;
|
|||||||
|
|
||||||
public class BreakCustomBlock implements Listener {
|
public class BreakCustomBlock implements Listener {
|
||||||
|
|
||||||
FileConfiguration config = CustomCrops.instance.getConfig();
|
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void breakCustomBlock(CustomBlockBreakEvent event){
|
public void breakCustomBlock(CustomBlockBreakEvent event){
|
||||||
|
FileConfiguration config = CustomCrops.instance.getConfig();
|
||||||
Player player =event.getPlayer();
|
Player player =event.getPlayer();
|
||||||
Location location = event.getBlock().getLocation();
|
Location location = event.getBlock().getLocation();
|
||||||
if(event.getNamespacedID().contains("stage")){
|
if(event.getNamespacedID().contains("stage")){
|
||||||
|
|||||||
@@ -11,10 +11,9 @@ import org.bukkit.event.entity.EntitySpawnEvent;
|
|||||||
|
|
||||||
public class BreakFurniture implements Listener {
|
public class BreakFurniture implements Listener {
|
||||||
|
|
||||||
FileConfiguration config = CustomCrops.instance.getConfig();
|
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void breakFurniture(EntitySpawnEvent event){
|
public void breakFurniture(EntitySpawnEvent event){
|
||||||
|
FileConfiguration config = CustomCrops.instance.getConfig();
|
||||||
Entity entity = event.getEntity();
|
Entity entity = event.getEntity();
|
||||||
if(!(entity instanceof Item)){
|
if(!(entity instanceof Item)){
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -9,6 +9,9 @@ import net.momirealms.customcrops.CustomCrops;
|
|||||||
import net.momirealms.customcrops.DataManager.MaxSprinklersPerChunk;
|
import net.momirealms.customcrops.DataManager.MaxSprinklersPerChunk;
|
||||||
import net.momirealms.customcrops.DataManager.SprinklerManager;
|
import net.momirealms.customcrops.DataManager.SprinklerManager;
|
||||||
import net.momirealms.customcrops.IAFurniture;
|
import net.momirealms.customcrops.IAFurniture;
|
||||||
|
import net.momirealms.customcrops.Integrations.KingdomsXIntegrations;
|
||||||
|
import net.momirealms.customcrops.Integrations.ResidenceIntegrations;
|
||||||
|
import net.momirealms.customcrops.Integrations.WorldGuardIntegrations;
|
||||||
import net.momirealms.customcrops.MessageManager;
|
import net.momirealms.customcrops.MessageManager;
|
||||||
import org.bukkit.GameMode;
|
import org.bukkit.GameMode;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
@@ -56,17 +59,22 @@ public class RightClickBlock implements Listener {
|
|||||||
if(CustomStack.byItemStack(event.getItem()) == null) return;
|
if(CustomStack.byItemStack(event.getItem()) == null) return;
|
||||||
|
|
||||||
Location location = event.getClickedBlock().getLocation();
|
Location location = event.getClickedBlock().getLocation();
|
||||||
|
//res兼容
|
||||||
if(config.getBoolean("config.integration.residence")){
|
if(config.getBoolean("config.integration.residence")){
|
||||||
FlagPermissions.addFlag("build");
|
if(ResidenceIntegrations.checkResBuild(location,player)){
|
||||||
ClaimedResidence res = Residence.getInstance().getResidenceManager().getByLoc(location);
|
return;
|
||||||
if(res!=null){
|
}
|
||||||
ResidencePermissions perms = res.getPermissions();
|
}
|
||||||
String playerName = event.getPlayer().getName();
|
//wg兼容
|
||||||
boolean hasPermission = perms.playerHas(playerName, "build", true);
|
if(config.getBoolean("config.integration.worldguard")){
|
||||||
if(!hasPermission){
|
if(WorldGuardIntegrations.checkWGBuild(location,player)){
|
||||||
event.setCancelled(true);
|
return;
|
||||||
return;
|
}
|
||||||
}
|
}
|
||||||
|
//kingdomsX兼容
|
||||||
|
if(config.getBoolean("config.integration.kingdomsX")){
|
||||||
|
if(KingdomsXIntegrations.checkKDBuild(location,player)){
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//是否过高过低
|
//是否过高过低
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import dev.lone.itemsadder.api.Events.CustomBlockInteractEvent;
|
|||||||
import net.momirealms.customcrops.CustomCrops;
|
import net.momirealms.customcrops.CustomCrops;
|
||||||
import net.momirealms.customcrops.DataManager.CropManager;
|
import net.momirealms.customcrops.DataManager.CropManager;
|
||||||
import net.momirealms.customcrops.DataManager.MaxCropsPerChunk;
|
import net.momirealms.customcrops.DataManager.MaxCropsPerChunk;
|
||||||
|
import net.momirealms.customcrops.Integrations.KingdomsXIntegrations;
|
||||||
import net.momirealms.customcrops.Integrations.ResidenceIntegrations;
|
import net.momirealms.customcrops.Integrations.ResidenceIntegrations;
|
||||||
import net.momirealms.customcrops.Integrations.WorldGuardIntegrations;
|
import net.momirealms.customcrops.Integrations.WorldGuardIntegrations;
|
||||||
import net.momirealms.customcrops.MessageManager;
|
import net.momirealms.customcrops.MessageManager;
|
||||||
@@ -33,14 +34,20 @@ public class RightClickCustomBlock implements Listener {
|
|||||||
CustomBlock clickedCustomBlock = CustomBlock.byAlreadyPlaced(clickedBlock);
|
CustomBlock clickedCustomBlock = CustomBlock.byAlreadyPlaced(clickedBlock);
|
||||||
FileConfiguration config = CustomCrops.instance.getConfig();
|
FileConfiguration config = CustomCrops.instance.getConfig();
|
||||||
Player player = event.getPlayer();
|
Player player = event.getPlayer();
|
||||||
|
//kingdomsX兼容
|
||||||
|
if(config.getBoolean("config.integration.kingdomsX")){
|
||||||
|
if(KingdomsXIntegrations.checkKDBuild(clickedBlockLocation,player)){
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
if (event.getItem() == null) {
|
if (event.getItem() == null) {
|
||||||
if(config.getBoolean("config.integration.residence")){
|
if(config.getBoolean("config.integration.residence")){
|
||||||
if(ResidenceIntegrations.checkResHarvest(clickedBlockLocation, event)){
|
if(ResidenceIntegrations.checkResHarvest(clickedBlockLocation,player)){
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(config.getBoolean("config.integration.worldguard")){
|
if(config.getBoolean("config.integration.worldguard")){
|
||||||
if(WorldGuardIntegrations.checkWGHarvest(player,clickedBlockLocation, event)){
|
if(WorldGuardIntegrations.checkWGHarvest(clickedBlockLocation,player)){
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -62,14 +69,14 @@ public class RightClickCustomBlock implements Listener {
|
|||||||
}
|
}
|
||||||
//res兼容
|
//res兼容
|
||||||
if(config.getBoolean("config.integration.residence")){
|
if(config.getBoolean("config.integration.residence")){
|
||||||
if(ResidenceIntegrations.checkResBuild(clickedBlockLocation, event)){
|
if(ResidenceIntegrations.checkResBuild(clickedBlockLocation,player)){
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//wg兼容
|
//wg兼容
|
||||||
if(config.getBoolean("config.integration.worldguard")){
|
if(config.getBoolean("config.integration.worldguard")){
|
||||||
if(WorldGuardIntegrations.checkWGBuild(player,clickedBlockLocation, event)){
|
if(WorldGuardIntegrations.checkWGBuild(clickedBlockLocation,player)){
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -71,6 +71,8 @@ config:
|
|||||||
residence: false
|
residence: false
|
||||||
#收获flag为BLOCK_BREAK 浇水种植flag为BUILD
|
#收获flag为BLOCK_BREAK 浇水种植flag为BUILD
|
||||||
worldguard: false
|
worldguard: false
|
||||||
|
#王国成员可以破坏和种植
|
||||||
|
kingdomsX: false
|
||||||
|
|
||||||
messages:
|
messages:
|
||||||
prefix: '<gradient:#ccfbff:#ef96c5>[CustomCrops] </gradient>'
|
prefix: '<gradient:#ccfbff:#ef96c5>[CustomCrops] </gradient>'
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
name: CustomCrops
|
name: CustomCrops
|
||||||
version: '${project.version}'
|
version: '1.1'
|
||||||
main: net.momirealms.customcrops.CustomCrops
|
main: net.momirealms.customcrops.CustomCrops
|
||||||
api-version: 1.18
|
api-version: 1.18
|
||||||
depend: [ ItemsAdder , ProtocolLib ]
|
depend: [ ItemsAdder , ProtocolLib ]
|
||||||
softdepend: [ PlaceholderAPI ]
|
softdepend: [ PlaceholderAPI , Kingdoms , Residence , WorldGuard ]
|
||||||
authors: [ XiaoMoMi ]
|
authors: [ XiaoMoMi ]
|
||||||
commands:
|
commands:
|
||||||
customcrops:
|
customcrops:
|
||||||
|
|||||||
Reference in New Issue
Block a user