commit c17e938b58a3f48a8e6decd0cdbb601e91ceeffe
Author: tianyu <32282861@qq.com>
Date: Wed Jul 24 06:17:46 2024 +0800
测试版
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..6c53d53
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,41 @@
+target/
+!.mvn/wrapper/maven-wrapper.jar
+!**/src/main/**/target/
+!**/src/test/**/target/
+
+### IntelliJ IDEA ###
+.idea/modules.xml
+.idea/jarRepositories.xml
+.idea/compiler.xml
+.idea/libraries/
+*.iws
+*.iml
+*.ipr
+
+### Eclipse ###
+.apt_generated
+.classpath
+.factorypath
+.project
+.settings
+.springBeans
+.sts4-cache
+
+### NetBeans ###
+/nbproject/private/
+/nbbuild/
+/dist/
+/nbdist/
+/.nb-gradle/
+build/
+!**/src/main/**/build/
+!**/src/test/**/build/
+
+### VS Code ###
+.vscode/
+
+### Mac OS ###
+.DS_Store
+/.idea/
+/libs/
+/out/
diff --git a/pom.xml b/pom.xml
new file mode 100644
index 0000000..f7ad0ac
--- /dev/null
+++ b/pom.xml
@@ -0,0 +1,32 @@
+
+
+ 4.0.0
+
+ org.example
+ DemonNeverLag
+ 1.0-SNAPSHOT
+
+
+ 8
+ 8
+ UTF-8
+
+
+
+
+ public-rpg
+ https://repo.aurora-pixels.com/repository/public-rpg/
+
+
+
+
+
+ org.spigotmc
+ spigot-api
+ 1.12.2
+
+
+
+
\ No newline at end of file
diff --git a/src/main/java/me/Demon/DemonNeverLag/ClearEntity/AntiChicken.java b/src/main/java/me/Demon/DemonNeverLag/ClearEntity/AntiChicken.java
new file mode 100644
index 0000000..79767ce
--- /dev/null
+++ b/src/main/java/me/Demon/DemonNeverLag/ClearEntity/AntiChicken.java
@@ -0,0 +1,54 @@
+package me.Demon.DemonNeverLag.ClearEntity;
+
+import org.bukkit.Bukkit;
+import org.bukkit.Location;
+import org.bukkit.Material;
+import org.bukkit.World;
+import org.bukkit.entity.Chicken;
+import org.bukkit.entity.Egg;
+import org.bukkit.entity.Entity;
+import org.bukkit.event.EventHandler;
+import org.bukkit.event.Listener;
+import org.bukkit.event.entity.ItemMergeEvent;
+import org.bukkit.event.entity.ItemSpawnEvent;
+import org.bukkit.inventory.ItemStack;
+
+public class AntiChicken implements Listener {
+
+ @EventHandler
+ public void onEntityDropItem(ItemSpawnEvent e) {
+ ItemStack items = e.getEntity().getItemStack();
+ if(items.getType() == Material.EGG) {
+ Location centerLocation = e.getEntity().getLocation();
+ World world = centerLocation.getWorld();
+ int radius = 3;
+ int maxChickenCount = 20;
+ // 统计在该区域内的鸡的数量
+ int chickenCount = 0;
+ for (Entity entity : world.getNearbyEntities(centerLocation, radius, radius, radius)) {
+ if (entity instanceof Chicken) {
+ chickenCount++;
+ }
+ }
+ // 如果鸡的数量超过10只,将多余的鸡清理掉
+ if (chickenCount > maxChickenCount) {
+ int amount = 0;
+ int chickensToRemove = chickenCount - maxChickenCount;
+ for (Entity entity : world.getEntities()) {
+ if (entity instanceof Chicken) {
+ entity.remove();
+ amount++;
+ chickensToRemove--;
+ if (chickensToRemove <= 0) {
+ break;
+ }
+ }
+ }
+ int x = (int) centerLocation.getX();
+ int y = (int) centerLocation.getY();
+ int z = (int) centerLocation.getZ();
+ Bukkit.getConsoleSender().sendMessage("[日志-刷蛋鸡] 检测到密集刷蛋鸡 "+x+","+y+","+z+" 已清理多余鸡["+amount+"只].");
+ }
+ }
+ }
+}
diff --git a/src/main/java/me/Demon/DemonNeverLag/ClearEntity/AntiCow.java b/src/main/java/me/Demon/DemonNeverLag/ClearEntity/AntiCow.java
new file mode 100644
index 0000000..8a7b164
--- /dev/null
+++ b/src/main/java/me/Demon/DemonNeverLag/ClearEntity/AntiCow.java
@@ -0,0 +1,64 @@
+package me.Demon.DemonNeverLag.ClearEntity;
+
+import me.Demon.DemonNeverLag.Main;
+import org.bukkit.Bukkit;
+import org.bukkit.Location;
+import org.bukkit.Material;
+import org.bukkit.World;
+import org.bukkit.entity.*;
+import org.bukkit.event.EventHandler;
+import org.bukkit.event.Listener;
+import org.bukkit.event.entity.ItemSpawnEvent;
+import org.bukkit.event.player.PlayerInteractEntityEvent;
+import org.bukkit.inventory.ItemStack;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class AntiCow implements Listener {
+
+ @EventHandler
+ public void onBucket_Cow(PlayerInteractEntityEvent e) {
+ Player p = e.getPlayer();
+ ItemStack item = p.getItemInHand();
+ if (!Main.itemIsNull(item) && item.getType() == Material.BUCKET) {
+ short item_data = item.getData().getData();
+ if (item_data == 0 && e.getRightClicked().getType() == EntityType.COW) {
+ if (e.getRightClicked().getType() == EntityType.COW) {
+ Location centerLocation = e.getRightClicked().getLocation();
+ World world = centerLocation.getWorld();
+ int radius = 10;
+ int maxChickenCount = 20;
+ // 统计在该区域内的鸡的数量
+ int chickenCount = 0;
+ for (Entity entity : world.getNearbyEntities(centerLocation, radius, radius, radius)) {
+ if (entity instanceof Cow) {
+ chickenCount++;
+ }
+ }
+ // 如果鸡的数量超过10只,将多余的鸡清理掉
+ if (chickenCount > maxChickenCount) {
+ int amount = 0;
+ int chickensToRemove = chickenCount - maxChickenCount;
+ for (Entity entity : world.getEntities()) {
+ if (entity instanceof Cow) {
+ //entity.remove();
+ ((Cow) entity).damage(10);
+ amount++;
+ chickensToRemove--;
+ if (chickensToRemove <= 0) {
+ break;
+ }
+ }
+ }
+ int x = (int) centerLocation.getX();
+ int y = (int) centerLocation.getY();
+ int z = (int) centerLocation.getZ();
+ Bukkit.getConsoleSender().sendMessage("[日志-刷奶牛] 检测到密集牛群 "+x+","+y+","+z+" 已清理多余牛["+amount+"只].");
+ p.sendMessage(Main.prefix+"区块检测到存在密集牛群,已清理§a"+amount+"只");
+ }
+ }
+ }
+ }
+ }
+}
diff --git a/src/main/java/me/Demon/DemonNeverLag/ClearEntity/AntiEntity_Nether.java b/src/main/java/me/Demon/DemonNeverLag/ClearEntity/AntiEntity_Nether.java
new file mode 100644
index 0000000..87c9a07
--- /dev/null
+++ b/src/main/java/me/Demon/DemonNeverLag/ClearEntity/AntiEntity_Nether.java
@@ -0,0 +1,48 @@
+package me.Demon.DemonNeverLag.ClearEntity;
+
+import me.Demon.DemonNeverLag.Main;
+import org.bukkit.Bukkit;
+import org.bukkit.Location;
+import org.bukkit.Material;
+import org.bukkit.World;
+import org.bukkit.entity.Cow;
+import org.bukkit.entity.Entity;
+import org.bukkit.entity.EntityType;
+import org.bukkit.entity.Player;
+import org.bukkit.event.EventHandler;
+import org.bukkit.event.Listener;
+import org.bukkit.event.entity.EntitySpawnEvent;
+import org.bukkit.event.player.PlayerInteractEntityEvent;
+import org.bukkit.inventory.ItemStack;
+
+public class AntiEntity_Nether implements Listener {
+
+ @EventHandler
+ public void onEntitySpawn(EntitySpawnEvent event) {
+ EntityType entityType = event.getEntityType();
+ if (entityType.isSpawnable() && entityType != EntityType.PLAYER) {
+ if (entityType == EntityType.PIG_ZOMBIE || entityType == EntityType.BLAZE || entityType == EntityType.MAGMA_CUBE) {
+ Location spawnLocation = event.getEntity().getLocation();
+ if (spawnLocation.getWorld().getName().equalsIgnoreCase("ASkyBlock_nether")) {
+ int nearbyMonsterCount = countNearbyMonsters(spawnLocation);
+ if (nearbyMonsterCount >= 40) {
+ event.setCancelled(true);
+ }
+ }
+ }
+ }
+ }
+
+ private int countNearbyMonsters(Location location) {
+ int monsterCount = 0;
+ for (Entity entity : location.getWorld().getEntities()) {
+ if (entity.getType().isSpawnable() && entity.getType() != EntityType.PLAYER) {
+ double distanceSquared = entity.getLocation().distanceSquared(location);
+ if (distanceSquared <= 150) {
+ monsterCount++;
+ }
+ }
+ }
+ return monsterCount;
+ }
+}
diff --git a/src/main/java/me/Demon/DemonNeverLag/ClearEntity/AntiSheep.java b/src/main/java/me/Demon/DemonNeverLag/ClearEntity/AntiSheep.java
new file mode 100644
index 0000000..0ec1a97
--- /dev/null
+++ b/src/main/java/me/Demon/DemonNeverLag/ClearEntity/AntiSheep.java
@@ -0,0 +1,57 @@
+package me.Demon.DemonNeverLag.ClearEntity;
+
+import me.Demon.DemonNeverLag.Main;
+import org.bukkit.Bukkit;
+import org.bukkit.Location;
+import org.bukkit.Material;
+import org.bukkit.World;
+import org.bukkit.entity.*;
+import org.bukkit.event.EventHandler;
+import org.bukkit.event.Listener;
+import org.bukkit.event.player.PlayerInteractEntityEvent;
+import org.bukkit.event.player.PlayerShearEntityEvent;
+import org.bukkit.inventory.ItemStack;
+
+public class AntiSheep implements Listener {
+
+ @EventHandler
+ public void onShear(PlayerShearEntityEvent e){
+ Player player = e.getPlayer();
+ if(e.getEntity().getType() == EntityType.SHEEP){
+ Sheep sheep = (Sheep) e.getEntity();
+ if(sheep.isSheared()){
+ return;
+ }
+ Location centerLocation = sheep.getLocation();
+ World world = centerLocation.getWorld();
+ int radius = 10;
+ int maxChickenCount = 20;
+ int chickenCount = 0;
+ for (Entity entity : world.getNearbyEntities(centerLocation, radius, radius, radius)) {
+ if (entity instanceof Sheep) {
+ chickenCount++;
+ }
+ }
+ if (chickenCount > maxChickenCount) {
+ int amount = 0;
+ int chickensToRemove = chickenCount - maxChickenCount;
+ for (Entity entity : world.getEntities()) {
+ if (entity instanceof Sheep) {
+ //entity.remove();
+ ((Sheep) entity).damage(8);
+ amount++;
+ chickensToRemove--;
+ if (chickensToRemove <= 0) {
+ break;
+ }
+ }
+ }
+ int x = (int) centerLocation.getX();
+ int y = (int) centerLocation.getY();
+ int z = (int) centerLocation.getZ();
+ Bukkit.getConsoleSender().sendMessage("[日志-刷喜羊羊] 检测到密集羊群 "+x+","+y+","+z+" 已清理多余羊["+amount+"只].");
+ player.sendMessage(Main.prefix+"区块检测到存在密集羊群,已清理§a"+amount+"只");
+ }
+ }
+ }
+}
diff --git a/src/main/java/me/Demon/DemonNeverLag/Main.java b/src/main/java/me/Demon/DemonNeverLag/Main.java
new file mode 100644
index 0000000..8999dbb
--- /dev/null
+++ b/src/main/java/me/Demon/DemonNeverLag/Main.java
@@ -0,0 +1,98 @@
+package me.Demon.DemonNeverLag;
+
+import me.Demon.DemonNeverLag.ClearEntity.AntiChicken;
+import me.Demon.DemonNeverLag.ClearEntity.AntiCow;
+import me.Demon.DemonNeverLag.ClearEntity.AntiEntity_Nether;
+import me.Demon.DemonNeverLag.ClearEntity.AntiSheep;
+import me.Demon.DemonNeverLag.listener.*;
+import me.Demon.DemonNeverLag.task.ClearItem;
+import me.Demon.DemonNeverLag.util.Config;
+import org.bukkit.Bukkit;
+import org.bukkit.Material;
+import org.bukkit.command.Command;
+import org.bukkit.command.CommandSender;
+import org.bukkit.configuration.InvalidConfigurationException;
+import org.bukkit.configuration.file.YamlConfiguration;
+import org.bukkit.inventory.ItemStack;
+import org.bukkit.plugin.java.JavaPlugin;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.nio.charset.StandardCharsets;
+
+public class Main extends JavaPlugin {
+
+ public static Main plugin;
+ public static String prefix = "§7[§6战争领域§7] §f";
+
+ @Override
+ public void onEnable() {
+ plugin = this;
+ Config.init(loadConfig());
+ Bukkit.getServer().getPluginManager().registerEvents(new AntiEntity_Nether(), plugin);
+ Bukkit.getServer().getPluginManager().registerEvents(new AntiSheep(), plugin);
+ Bukkit.getServer().getPluginManager().registerEvents(new AntiCow(), plugin);
+ Bukkit.getServer().getPluginManager().registerEvents(new AntiChicken(), plugin);
+ Bukkit.getServer().getPluginManager().registerEvents(new AntiShuaDongXi(), plugin);
+ Bukkit.getServer().getPluginManager().registerEvents(new FluidLimit(), plugin);
+ Bukkit.getServer().getPluginManager().registerEvents(new ArrowRemover(), plugin);
+ Bukkit.getServer().getPluginManager().registerEvents(new AntiEnderPearl(), plugin);
+ Bukkit.getServer().getPluginManager().registerEvents(new ProtectFarm(), plugin);
+ Bukkit.getServer().getPluginManager().registerEvents(new AntiExplode(), plugin);
+ Bukkit.getServer().getPluginManager().registerEvents(new AntiCrashSign(), plugin);
+ Bukkit.getServer().getPluginManager().registerEvents(new AntiChatLimit(), plugin);
+ Bukkit.getServer().getPluginManager().registerEvents(new AntiNoRain(), plugin);
+ Bukkit.getServer().getPluginManager().registerEvents(new NoSpawnChunk(), plugin);
+ // Bukkit.getServer().getPluginManager().registerEvents(new SpawnRate(), plugin);
+ Bukkit.getServer().getPluginManager().registerEvents(new VoidTp(), plugin);
+ Bukkit.getServer().getPluginManager().registerEvents(new AntiItemMerge(), plugin);
+ if(Config.ClearItem_butt) {
+ int clear_time = Config.ClearItem_Delay;
+ getServer().getScheduler().scheduleSyncRepeatingTask(this, new Runnable() {
+ public void run() {
+ ClearItem.clean_run();
+ }
+ }, clear_time * 20L, clear_time * 20L);
+ getServer().getScheduler().scheduleSyncRepeatingTask(this, new Runnable() {
+ public void run() {
+ ClearItem.domessage();
+ }
+ }, 20L, 20L);
+ }
+ }
+
+ @Override
+ public void onDisable() {
+
+ }
+
+ @Override
+ public boolean onCommand(CommandSender sender, Command cmd, String Command, String[] args) {
+ if (Command.equalsIgnoreCase("neverlag") && sender.isOp()) {
+ if(args.length == 1 && args[0].equalsIgnoreCase("clearitem")){
+ ClearItem.clean_run();
+ sender.sendMessage(prefix+"垃圾清理启动成功.");
+ }
+ }
+ return false;
+ }
+ public static boolean itemIsNull(ItemStack item){
+ return item == null || item.getType() == Material.AIR;
+ }
+ public static boolean itemIsLore(ItemStack item){
+ return item.getItemMeta().getLore() == null;
+ }
+
+ public YamlConfiguration loadConfig() {
+ saveDefaultConfig();
+ YamlConfiguration config = new YamlConfiguration();
+ try {
+ config.load(new InputStreamReader(new FileInputStream(new File(getDataFolder(), "config.yml")), StandardCharsets.UTF_8));
+ } catch (IOException | InvalidConfigurationException e) {
+ e.printStackTrace();
+ }
+ return config;
+ }
+}
diff --git a/src/main/java/me/Demon/DemonNeverLag/listener/AntiChatLimit.java b/src/main/java/me/Demon/DemonNeverLag/listener/AntiChatLimit.java
new file mode 100644
index 0000000..cdafc94
--- /dev/null
+++ b/src/main/java/me/Demon/DemonNeverLag/listener/AntiChatLimit.java
@@ -0,0 +1,22 @@
+package me.Demon.DemonNeverLag.listener;
+
+import me.Demon.DemonNeverLag.Main;
+import org.bukkit.ChatColor;
+import org.bukkit.entity.Player;
+import org.bukkit.event.EventHandler;
+import org.bukkit.event.EventPriority;
+import org.bukkit.event.Listener;
+import org.bukkit.event.player.AsyncPlayerChatEvent;
+
+public class AntiChatLimit implements Listener {
+
+ @EventHandler
+ public void chat(AsyncPlayerChatEvent e) {
+ Player p = e.getPlayer();
+ if(ChatColor.stripColor(e.getMessage()).length() > 95) {
+ e.setCancelled(true);
+ p.sendMessage(Main.prefix+"发送的聊天消息过长,请修改后重新发送。");
+ }
+ }
+
+}
diff --git a/src/main/java/me/Demon/DemonNeverLag/listener/AntiCrashSign.java b/src/main/java/me/Demon/DemonNeverLag/listener/AntiCrashSign.java
new file mode 100644
index 0000000..bad36cf
--- /dev/null
+++ b/src/main/java/me/Demon/DemonNeverLag/listener/AntiCrashSign.java
@@ -0,0 +1,27 @@
+package me.Demon.DemonNeverLag.listener;
+
+import me.Demon.DemonNeverLag.Main;
+import org.bukkit.entity.Player;
+import org.bukkit.event.EventHandler;
+import org.bukkit.event.EventPriority;
+import org.bukkit.event.Listener;
+import org.bukkit.event.block.SignChangeEvent;
+
+public class AntiCrashSign implements Listener {
+
+ @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
+ public void onSignChange(SignChangeEvent e) {
+ Player p = e.getPlayer();
+ for (int i = 0; i < 4; i++) {
+ if (e.getLine(i).matches("^[a-zA-Z0-9_]*$")) {
+ if (e.getLine(i).length() > 20) {
+ e.setCancelled(true);
+ p.sendMessage(Main.prefix+"木牌写不下这么长的字符.");
+ }
+ } else if (e.getLine(i).length() > 50) {
+ e.setCancelled(true);
+ p.sendMessage(Main.prefix+"木牌写不下这么长的字符.");
+ }
+ }
+ }
+}
diff --git a/src/main/java/me/Demon/DemonNeverLag/listener/AntiEnderPearl.java b/src/main/java/me/Demon/DemonNeverLag/listener/AntiEnderPearl.java
new file mode 100644
index 0000000..f048358
--- /dev/null
+++ b/src/main/java/me/Demon/DemonNeverLag/listener/AntiEnderPearl.java
@@ -0,0 +1,25 @@
+package me.Demon.DemonNeverLag.listener;
+
+import me.Demon.DemonNeverLag.Main;
+import me.Demon.DemonNeverLag.util.Config;
+import org.bukkit.Material;
+import org.bukkit.entity.Player;
+import org.bukkit.event.EventHandler;
+import org.bukkit.event.Listener;
+import org.bukkit.event.player.PlayerInteractEvent;
+import org.bukkit.inventory.ItemStack;
+
+public class AntiEnderPearl implements Listener {
+
+ @EventHandler
+ public void onEnderPa(PlayerInteractEvent e){
+ Player p = e.getPlayer();
+ if (Config.NoEnderPearl) {
+ ItemStack item = p.getItemInHand();
+ if (!Main.itemIsNull(item) && item.getType() == Material.ENDER_PEARL) {
+ e.setCancelled(true);
+ p.sendMessage(Main.prefix+"当前世界禁止了末影珍珠传送。");
+ }
+ }
+ }
+}
diff --git a/src/main/java/me/Demon/DemonNeverLag/listener/AntiExplode.java b/src/main/java/me/Demon/DemonNeverLag/listener/AntiExplode.java
new file mode 100644
index 0000000..635d228
--- /dev/null
+++ b/src/main/java/me/Demon/DemonNeverLag/listener/AntiExplode.java
@@ -0,0 +1,40 @@
+package me.Demon.DemonNeverLag.listener;
+
+import me.Demon.DemonNeverLag.Main;
+import org.bukkit.event.EventHandler;
+import org.bukkit.event.Listener;
+import org.bukkit.event.entity.EntityExplodeEvent;
+
+public class AntiExplode implements Listener {
+
+ @EventHandler
+ public void onHIGHESTExplosion(EntityExplodeEvent e){
+ if (e.isCancelled()){
+ return;
+ }
+ String worldName = e.getLocation().getWorld().getName();
+ if(AntiWorldName(worldName)) {
+ e.blockList().clear();
+ }
+ }
+
+ @EventHandler
+ public void onMONITORExplosion(EntityExplodeEvent e){
+ if (e.isCancelled()){
+ return;
+ }
+ String worldName = e.getLocation().getWorld().getName();
+ if(AntiWorldName(worldName)) {
+ e.blockList().clear();
+ }
+ }
+
+ public boolean AntiWorldName(String worldName){
+ /*if(worldName.equalsIgnoreCase("ASkyBlock_nether")){
+ return false;
+ }else if(worldName.equalsIgnoreCase("ASkyBlock")){
+ return false;
+ }*/
+ return true;
+ }
+}
diff --git a/src/main/java/me/Demon/DemonNeverLag/listener/AntiItemMerge.java b/src/main/java/me/Demon/DemonNeverLag/listener/AntiItemMerge.java
new file mode 100644
index 0000000..0ab83fb
--- /dev/null
+++ b/src/main/java/me/Demon/DemonNeverLag/listener/AntiItemMerge.java
@@ -0,0 +1,41 @@
+package me.Demon.DemonNeverLag.listener;
+
+import me.Demon.DemonNeverLag.Main;
+import org.bukkit.Bukkit;
+import org.bukkit.Material;
+import org.bukkit.entity.Item;
+import org.bukkit.event.EventHandler;
+import org.bukkit.event.Listener;
+import org.bukkit.event.entity.ItemMergeEvent;
+import org.bukkit.event.player.PlayerDropItemEvent;
+import org.bukkit.inventory.ItemStack;
+import org.bukkit.metadata.FixedMetadataValue;
+
+public class AntiItemMerge implements Listener {
+
+
+ @EventHandler
+ public void onpick(PlayerDropItemEvent e) {
+ Item item = e.getItemDrop();
+ item.setMetadata("drop",new FixedMetadataValue(Main.plugin,"true"));
+ }
+
+ @EventHandler
+ public void onItemMerge(ItemMergeEvent e) {
+ Item item_en = e.getEntity();
+ Item item = e.getTarget();
+ if(!item.hasMetadata("drop") && !item_en.hasMetadata("drop")) {
+ Bukkit.getScheduler().runTaskLater(Main.plugin, new Runnable() {
+ @Override
+ public void run() {
+ ItemStack item = e.getTarget().getItemStack();
+ if(item.getType() == Material.CACTUS) {
+ if (item.getAmount() >= 12) {
+ item.setAmount(12);
+ }
+ }
+ }
+ }, 2);
+ }
+ }
+}
diff --git a/src/main/java/me/Demon/DemonNeverLag/listener/AntiNoPlugin.java b/src/main/java/me/Demon/DemonNeverLag/listener/AntiNoPlugin.java
new file mode 100644
index 0000000..c2e3f9d
--- /dev/null
+++ b/src/main/java/me/Demon/DemonNeverLag/listener/AntiNoPlugin.java
@@ -0,0 +1,7 @@
+package me.Demon.DemonNeverLag.listener;
+
+import org.bukkit.event.Listener;
+
+public class AntiNoPlugin implements Listener {
+
+}
diff --git a/src/main/java/me/Demon/DemonNeverLag/listener/AntiNoRain.java b/src/main/java/me/Demon/DemonNeverLag/listener/AntiNoRain.java
new file mode 100644
index 0000000..1e9bdfe
--- /dev/null
+++ b/src/main/java/me/Demon/DemonNeverLag/listener/AntiNoRain.java
@@ -0,0 +1,16 @@
+package me.Demon.DemonNeverLag.listener;
+
+import me.Demon.DemonNeverLag.util.Config;
+import org.bukkit.event.EventHandler;
+import org.bukkit.event.Listener;
+import org.bukkit.event.weather.WeatherChangeEvent;
+
+public class AntiNoRain implements Listener {
+
+ @EventHandler
+ public void onwe(WeatherChangeEvent e) {
+ if (Config.NoRain) {
+ e.setCancelled(true);
+ }
+ }
+}
diff --git a/src/main/java/me/Demon/DemonNeverLag/listener/AntiShuaDongXi.java b/src/main/java/me/Demon/DemonNeverLag/listener/AntiShuaDongXi.java
new file mode 100644
index 0000000..b809ccf
--- /dev/null
+++ b/src/main/java/me/Demon/DemonNeverLag/listener/AntiShuaDongXi.java
@@ -0,0 +1,67 @@
+package me.Demon.DemonNeverLag.listener;
+
+import me.Demon.DemonNeverLag.Main;
+import org.bukkit.ChatColor;
+import org.bukkit.Location;
+import org.bukkit.Material;
+import org.bukkit.entity.Player;
+import org.bukkit.event.EventHandler;
+import org.bukkit.event.Listener;
+import org.bukkit.event.block.BlockPlaceEvent;
+import org.bukkit.event.inventory.InventoryClickEvent;
+import org.bukkit.event.inventory.InventoryType;
+import org.bukkit.event.player.AsyncPlayerChatEvent;
+import org.bukkit.event.player.PlayerDropItemEvent;
+import org.bukkit.event.player.PlayerInteractEvent;
+import org.bukkit.inventory.Inventory;
+import org.bukkit.inventory.ItemStack;
+
+public class AntiShuaDongXi implements Listener {
+
+ @EventHandler
+ public void chat(BlockPlaceEvent e) {
+ Player p = e.getPlayer();
+ Location loc = e.getBlock().getLocation();
+ if(loc.getBlockY() > 250){
+ e.setCancelled(true);
+ p.sendMessage(Main.prefix+"您没有在此高空进行建筑的权限.");
+ }else if(loc.getBlockY() < 2){
+ e.setCancelled(true);
+ p.sendMessage(Main.prefix+"您没有在此低空进行建筑的权限.");
+ }
+ }
+
+ @EventHandler
+ public void onAnitBook(InventoryClickEvent e){
+ Player p = (Player) e.getWhoClicked();
+ if(e.getInventory() != null) {
+ if(!e.getInventory().getType().name().equalsIgnoreCase("CRAFTING")) {
+ ItemStack item = e.getCurrentItem();
+ if (!Main.itemIsNull(item) && item.getType() == Material.BOOK_AND_QUILL) {
+ e.setCancelled(true);
+ p.sendMessage(Main.prefix+"此物品因版本限制,无法在背包外其他地方使用.");
+ return;
+ }
+ if (!Main.itemIsNull(item) && item.getType() == Material.WRITTEN_BOOK) {
+ e.setCancelled(true);
+ p.sendMessage(Main.prefix+"此物品因版本限制,无法在背包外其他地方使用.");
+ return;
+ }
+ }
+ }
+ }
+
+ @EventHandler
+ public void onAnitBookDrop(PlayerDropItemEvent e){
+ ItemStack item = e.getItemDrop().getItemStack();
+ if (!Main.itemIsNull(item) && item.getType() == Material.BOOK_AND_QUILL) {
+ e.setCancelled(true);
+ return;
+ }
+ if (!Main.itemIsNull(item) && item.getType() == Material.WRITTEN_BOOK) {
+ e.setCancelled(true);
+ return;
+ }
+ }
+
+}
diff --git a/src/main/java/me/Demon/DemonNeverLag/listener/ArrowRemover.java b/src/main/java/me/Demon/DemonNeverLag/listener/ArrowRemover.java
new file mode 100644
index 0000000..ad64fcf
--- /dev/null
+++ b/src/main/java/me/Demon/DemonNeverLag/listener/ArrowRemover.java
@@ -0,0 +1,32 @@
+package me.Demon.DemonNeverLag.listener;
+
+import me.Demon.DemonNeverLag.Main;
+import me.Demon.DemonNeverLag.util.Config;
+import org.bukkit.craftbukkit.v1_12_R1.entity.CraftPlayer;
+import org.bukkit.entity.Player;
+import org.bukkit.event.EventHandler;
+import org.bukkit.event.Listener;
+import org.bukkit.event.entity.EntityDamageByEntityEvent;
+import org.bukkit.scheduler.BukkitRunnable;
+
+public class ArrowRemover implements Listener {
+
+ @EventHandler
+ public void onDamage(EntityDamageByEntityEvent e) {
+ if (Config.RemoveArrow) {
+ if (e.getEntity() instanceof Player && e.getDamager() instanceof org.bukkit.entity.Arrow) {
+ (new BukkitRunnable() {
+ public void run() {
+ Player p = (Player) e.getEntity();
+ try {
+ ((CraftPlayer) p).getHandle().getDataWatcher().wait(9L, (byte) 0);
+ } catch (InterruptedException ex) {
+ throw new RuntimeException(ex);
+ }
+ }
+ }).runTaskLater(Main.plugin, 2L);
+ }
+ }
+ }
+
+}
diff --git a/src/main/java/me/Demon/DemonNeverLag/listener/FluidLimit.java b/src/main/java/me/Demon/DemonNeverLag/listener/FluidLimit.java
new file mode 100644
index 0000000..d125e9c
--- /dev/null
+++ b/src/main/java/me/Demon/DemonNeverLag/listener/FluidLimit.java
@@ -0,0 +1,40 @@
+package me.Demon.DemonNeverLag.listener;
+
+import me.Demon.DemonNeverLag.util.Config;
+import org.bukkit.Bukkit;
+import org.bukkit.Location;
+import org.bukkit.Material;
+import org.bukkit.event.EventHandler;
+import org.bukkit.event.EventPriority;
+import org.bukkit.event.Listener;
+import org.bukkit.event.block.BlockFromToEvent;
+
+public class FluidLimit implements Listener {
+
+ // 最多可流动多远
+ private final int water_flow = 8;
+ private final int lava_flow = 3;
+
+ @EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
+ public void onBlockFromToEvent(BlockFromToEvent e) {
+ if (Config.FluidLimit) {
+ Material material = e.getBlock().getType();
+ Location loc = e.getToBlock().getLocation();
+ // 检测流方块是否是水
+ if (material == Material.WATER || material == Material.STATIONARY_WATER) {
+ // 若水从135格以上的位置出现 并来到了Y135将拦截
+ if (loc.getY() >= 0 && loc.getY() <= 135) {
+ if (e.getBlock().getData() >= this.water_flow) {
+ e.setCancelled(true);
+ }
+ }
+ } else if (material == Material.LAVA || material == Material.STATIONARY_LAVA) {
+ if (loc.getY() >= 0 && loc.getY() <= 135) {
+ if (e.getBlock().getData() >= this.lava_flow) {
+ e.setCancelled(true);
+ }
+ }
+ }
+ }
+ }
+}
diff --git a/src/main/java/me/Demon/DemonNeverLag/listener/NoSpawnChunk.java b/src/main/java/me/Demon/DemonNeverLag/listener/NoSpawnChunk.java
new file mode 100644
index 0000000..b79fd5d
--- /dev/null
+++ b/src/main/java/me/Demon/DemonNeverLag/listener/NoSpawnChunk.java
@@ -0,0 +1,15 @@
+package me.Demon.DemonNeverLag.listener;
+
+import org.bukkit.event.EventHandler;
+import org.bukkit.event.EventPriority;
+import org.bukkit.event.Listener;
+import org.bukkit.event.world.WorldInitEvent;
+
+public class NoSpawnChunk implements Listener {
+
+ @EventHandler(priority = EventPriority.LOWEST)
+ public void onWorldLoad(WorldInitEvent e) {
+ e.getWorld().setKeepSpawnInMemory(false);
+ }
+
+}
diff --git a/src/main/java/me/Demon/DemonNeverLag/listener/ProtectFarm.java b/src/main/java/me/Demon/DemonNeverLag/listener/ProtectFarm.java
new file mode 100644
index 0000000..51dc422
--- /dev/null
+++ b/src/main/java/me/Demon/DemonNeverLag/listener/ProtectFarm.java
@@ -0,0 +1,40 @@
+package me.Demon.DemonNeverLag.listener;
+
+import org.bukkit.Bukkit;
+import org.bukkit.Material;
+import org.bukkit.entity.EntityType;
+import org.bukkit.entity.Player;
+import org.bukkit.event.EventHandler;
+import org.bukkit.event.Listener;
+import org.bukkit.event.block.Action;
+import org.bukkit.event.entity.EntityInteractEvent;
+import org.bukkit.event.player.PlayerInteractEvent;
+
+public class ProtectFarm implements Listener {
+
+ @EventHandler
+ public void onJump(PlayerInteractEvent e){
+ if(e.isCancelled()){
+ return;
+ }
+ if(e.getAction() == Action.PHYSICAL) {
+ if (e.getClickedBlock().getType() == Material.SOIL) {
+ e.setCancelled(true);
+ }
+ }
+ }
+
+ @EventHandler
+ public void onMobJump(EntityInteractEvent e) {
+ if (e.isCancelled()) {
+ return;
+ }
+ if (e.getEntityType() == EntityType.PLAYER) {
+ return;
+ }
+ if(e.getBlock().getType() == Material.SOIL){
+ e.setCancelled(true);
+ }
+ }
+
+}
diff --git a/src/main/java/me/Demon/DemonNeverLag/listener/SpawnRate.java b/src/main/java/me/Demon/DemonNeverLag/listener/SpawnRate.java
new file mode 100644
index 0000000..596e8ce
--- /dev/null
+++ b/src/main/java/me/Demon/DemonNeverLag/listener/SpawnRate.java
@@ -0,0 +1,65 @@
+package me.Demon.DemonNeverLag.listener;
+
+import me.Demon.DemonNeverLag.util.Config;
+import org.bukkit.event.EventHandler;
+import org.bukkit.event.Listener;
+import org.bukkit.event.entity.CreatureSpawnEvent;
+
+import java.util.Locale;
+import java.util.Random;
+
+public class SpawnRate implements Listener {
+
+ @EventHandler
+ public void AntiRate(CreatureSpawnEvent e){
+ if (e.isCancelled()) {
+ return;
+ }
+ String Reason = e.getSpawnReason().toString().toUpperCase();
+ Random r = new Random();
+ int rand = r.nextInt(100);
+ String str1;
+ switch ((str1 = Reason).hashCode()) {
+ case -1848073207:
+ if(!str1.equals("NATURAL")){
+ break;
+ }
+ if(Config.SpawnRate_CommonRate <= 0 || rand > Config.SpawnRate_CommonRate){
+ e.setCancelled(true);
+ return;
+ }
+ case -1293575864:
+ if (!str1.equals("SPAWNER")){
+ break;
+ }
+ if(Config.SpawnRate_SpawnerRate <= 0 || rand > Config.SpawnRate_SpawnerRate){
+ e.setCancelled(true);
+ return;
+ }
+ case -1182414285:
+ if (!str1.equals("NETHER_PORTAL")){
+ break;
+ }
+ if(Config.SpawnRate_PortalRate <= 0 || rand > Config.SpawnRate_PortalRate){
+ e.setCancelled(true);
+ return;
+ }
+ case 521567806:
+ if (!str1.equals("CHUNK_GEN")){
+ break;
+ }
+ if(Config.SpawnRate_ChunkRate <= 0 || rand > Config.SpawnRate_ChunkRate){
+ e.setCancelled(true);
+ return;
+ }
+ case 1206494573:
+ if (!str1.equals("VILLAGE_DEFENSE")){
+ break;
+ }
+ if(Config.SpawnRate_IronRate <= 0 || rand > Config.SpawnRate_IronRate){
+ e.setCancelled(true);
+ return;
+ }
+ }
+ }
+}
diff --git a/src/main/java/me/Demon/DemonNeverLag/listener/VoidTp.java b/src/main/java/me/Demon/DemonNeverLag/listener/VoidTp.java
new file mode 100644
index 0000000..ca78323
--- /dev/null
+++ b/src/main/java/me/Demon/DemonNeverLag/listener/VoidTp.java
@@ -0,0 +1,47 @@
+package me.Demon.DemonNeverLag.listener;
+
+import com.google.common.collect.Lists;
+import javafx.fxml.LoadException;
+import me.Demon.DemonNeverLag.util.Config;
+import org.bukkit.Bukkit;
+import org.bukkit.Location;
+import org.bukkit.entity.Player;
+import org.bukkit.event.EventHandler;
+import org.bukkit.event.Listener;
+import org.bukkit.event.entity.EntityDamageEvent;
+import org.bukkit.event.player.PlayerMoveEvent;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.UUID;
+
+public class VoidTp implements Listener {
+
+
+ private final List isVoidFalling = new ArrayList<>();
+
+ @EventHandler
+ public void onvoidTp(PlayerMoveEvent e){
+ if (Config.AntiVidTp) {
+ Player p = e.getPlayer();
+ if (e.getTo().getBlockY() <= -10) {
+ if (!isVoidFalling.contains(p.getName())) {
+ isVoidFalling.add(p.getName());
+ }
+ Location spawn = p.getWorld().getSpawnLocation();
+ p.teleport(spawn.add(0.5, 1, 0.5));
+ }
+ }
+ }
+
+ @EventHandler
+ public void onFall(EntityDamageEvent e){
+ if(String.valueOf(e.getCause()).equals("FALL") && e.getEntity() instanceof Player){
+ Player p = (Player) e.getEntity();
+ if(isVoidFalling.contains(p.getName())){
+ isVoidFalling.remove(p.getName());
+ e.setCancelled(true);
+ }
+ }
+ }
+}
diff --git a/src/main/java/me/Demon/DemonNeverLag/task/ClearItem.java b/src/main/java/me/Demon/DemonNeverLag/task/ClearItem.java
new file mode 100644
index 0000000..c7cb08e
--- /dev/null
+++ b/src/main/java/me/Demon/DemonNeverLag/task/ClearItem.java
@@ -0,0 +1,77 @@
+package me.Demon.DemonNeverLag.task;
+
+import me.Demon.DemonNeverLag.Main;
+import me.Demon.DemonNeverLag.util.Config;
+import me.Demon.DemonTrash.TrashAPI;
+import org.bukkit.Bukkit;
+import org.bukkit.World;
+import org.bukkit.entity.Arrow;
+import org.bukkit.entity.Entity;
+import org.bukkit.entity.Item;
+import org.bukkit.inventory.ItemStack;
+
+public class ClearItem {
+ public static int nowtime = 0;
+
+ public static void domessage(){
+ nowtime++;
+ // 每次清理的时间周期 建议900秒
+ int clear_time = Config.ClearItem_Delay;
+ int time = clear_time - nowtime;
+ String PreMessage = Main.prefix+"地面物品将在%TIME%秒后清除";
+ if(clear_time - nowtime == 60){
+ Bukkit.broadcastMessage(PreMessage.replace("%TIME%",String.valueOf(time)));
+ }else if(clear_time - nowtime == 30){
+ Bukkit.broadcastMessage(PreMessage.replace("%TIME%",String.valueOf(time)));
+ }else if(clear_time - nowtime == 10){
+ Bukkit.broadcastMessage(PreMessage.replace("%TIME%",String.valueOf(time)));
+ }else if(clear_time - nowtime == 5){
+ Bukkit.broadcastMessage(PreMessage.replace("%TIME%",String.valueOf(time)));
+ }else if(clear_time - nowtime == 4){
+ Bukkit.broadcastMessage(PreMessage.replace("%TIME%",String.valueOf(time)));
+ }else if(clear_time - nowtime == 3){
+ Bukkit.broadcastMessage(PreMessage.replace("%TIME%",String.valueOf(time)));
+ }else if(clear_time - nowtime == 2){
+ Bukkit.broadcastMessage(PreMessage.replace("%TIME%",String.valueOf(time)));
+ }else if(clear_time - nowtime == 1){
+ Bukkit.broadcastMessage(PreMessage.replace("%TIME%",String.valueOf(time)));
+ }else if(clear_time - nowtime <= 0){
+ nowtime = 0;
+ }
+ }
+ public static void clean_run() {
+ int count = 0;
+ String Message = Main.prefix+"清理了%COUNT%物品";
+ for (World world : Bukkit.getWorlds()) {
+ String world_Name = world.getName();
+ // 不清理该List中的世界
+ if(!Config.ClearItem_NoClearItemWorld.contains(world_Name)) {
+ for (Entity ent : world.getEntities()) {
+ if (ent instanceof Item) {
+ Item item = (Item) ent;
+ ItemStack items = item.getItemStack();
+ String name = items.getType().name();
+ // 不清理该List中的物品
+ if (!Config.ClearItem_NoClearItemIDList.contains(name)) {
+ if(!Main.itemIsNull(items)) {
+ if(!Main.itemIsLore(items)){
+ TrashAPI.addItemsTrash(ent.getWorld().getName(),items);
+ }
+ count++;
+ ent.remove();
+ continue;
+ }
+ }
+ }
+ if(ent instanceof Arrow){
+ count++;
+ ent.remove();
+ continue;
+ }
+ }
+ }
+ }
+ Bukkit.broadcastMessage(Message.replace("%COUNT%",String.valueOf(count)));
+ count = 0;
+ }
+}
diff --git a/src/main/java/me/Demon/DemonNeverLag/util/Config.java b/src/main/java/me/Demon/DemonNeverLag/util/Config.java
new file mode 100644
index 0000000..5ac9add
--- /dev/null
+++ b/src/main/java/me/Demon/DemonNeverLag/util/Config.java
@@ -0,0 +1,46 @@
+package me.Demon.DemonNeverLag.util;
+
+import org.bukkit.configuration.file.YamlConfiguration;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class Config {
+
+ private static YamlConfiguration config;
+ public static boolean NoRain = false;
+ public static boolean NoEnderPearl = false;
+ public static boolean RemoveArrow = false;
+ public static boolean AntiVidTp = false;
+ public static boolean FluidLimit = false;
+ public static int ClearItem_Delay = 300;
+ public static boolean ClearItem_butt = false;
+ public static List ClearItem_NoClearItemIDList = new ArrayList<>();
+ public static List ClearItem_NoClearItemWorld = new ArrayList<>();
+ public static List BlockCommand = new ArrayList<>();
+
+ public static int SpawnRate_ChunkRate = 50;
+ public static int SpawnRate_SpawnerRate = 100;
+ public static int SpawnRate_IronRate = 40;
+ public static int SpawnRate_CommonRate = 50;
+ public static int SpawnRate_PortalRate = 0;
+
+ public static void init(YamlConfiguration cfg) {
+ config = cfg;
+ AntiVidTp = config.getBoolean("NoVidTp");
+ FluidLimit = config.getBoolean("FluidLimit");
+ NoEnderPearl = config.getBoolean("NoEnderPearl");
+ NoRain = config.getBoolean("NoRain");
+ ClearItem_Delay = config.getInt("ClearItem.Delay");
+ ClearItem_butt = config.getBoolean("ClearItem.Butt");
+ RemoveArrow = config.getBoolean("RemoveArrow");
+ ClearItem_NoClearItemIDList = config.getStringList("ClearItem.NoClearItemIDList");
+ ClearItem_NoClearItemWorld = config.getStringList("ClearItem.NoClearItemWorld");
+ BlockCommand = config.getStringList("BlockCommand");
+ SpawnRate_ChunkRate = config.getInt("SpawnRate.ChunkRate");
+ SpawnRate_SpawnerRate = config.getInt("SpawnRate.SpawnerRate");
+ SpawnRate_IronRate = config.getInt("SpawnRate.IronRate");
+ SpawnRate_CommonRate = config.getInt("SpawnRate.CommonRate");
+ SpawnRate_PortalRate = config.getInt("SpawnRate.PortalRate");
+ }
+}
diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml
new file mode 100644
index 0000000..417e16d
--- /dev/null
+++ b/src/main/resources/config.yml
@@ -0,0 +1,52 @@
+# 是否锁定天气
+NoRain: true
+# 是否禁止高空流水
+FluidLimit: true
+# 是否清理地面弓箭
+RemoveArrow: true
+# 是否禁止末影珍珠传送
+NoEnderPearl: true
+# 是否开启虚空回传
+NoVidTp: false
+# 禁止的命令
+BlockCommand:
+ - pve
+# 垃圾清理系统
+ClearItem:
+ # 是否开启清理
+ Butt: true
+ # 清理周期 单位: 秒
+ Delay: 900
+ # 不清理的世界
+ NoClearItemWorld:
+ - hub
+ - wudeng
+ - kuangqu
+ # 不清理的物品ID
+ NoClearItemIDList:
+ - 276
+SpawnRate:
+ Enable: true
+ #设置特殊区块(女巫、史莱姆)的刷怪速度,单位为百分比
+ ChunkRate: 50
+ #刷怪笼生成怪物速度
+ SpawnerRate: 100
+ #村庄生成铁傀儡的速度,设置为0可以禁止刷铁塔等不平衡的自动化建筑
+ IronRate: 40
+ #普通、自然条件的生成速度
+ CommonRate: 50
+ #传送门的生成速度,设置为0可以禁止猪人通过传送门,防止建造刷金塔
+ PortalRate: 0
+# ###################
+# 功能介绍:
+# 聊天字符过多bug
+# 木牌字符过多bug
+# 玩家命令禁止
+# 自然天气锁定
+# NeverLag的Chunk 区块检测
+# NeverLag的刷怪控制
+# 防爆炸破坏建筑
+# 防止践踏农作物
+# 垃圾定时清理系统
+#
+######################
\ No newline at end of file
diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml
new file mode 100644
index 0000000..9ee6d4d
--- /dev/null
+++ b/src/main/resources/plugin.yml
@@ -0,0 +1,5 @@
+name: DemonNeverLag
+main: me.Demon.DemonNeverLag.Main
+version: 1.0.5
+commands:
+ neverlag:
\ No newline at end of file