DisableCreeperBoom
This commit is contained in:
@@ -0,0 +1,101 @@
|
||||
package top.gtb520.java.minecraft.plugins.disableCreeperBoom.Commands;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import top.gtb520.java.minecraft.plugins.disableCreeperBoom.main;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
public class creeperboom_Commands implements CommandExecutor {
|
||||
|
||||
@Override
|
||||
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
|
||||
// 检查权限
|
||||
if (!sender.hasPermission("disablecreeperboom.admin")) {
|
||||
sender.sendMessage(ChatColor.RED + "你没有权限使用此命令!");
|
||||
return true;
|
||||
}
|
||||
|
||||
// Debug部分
|
||||
boolean debug = main.instance.getConfig().getBoolean("config.debug", false);
|
||||
if (debug) {
|
||||
main.getInstance().getLogger().info("========DisableCreeperBoom Command Debug========\n" +
|
||||
"sender: " + sender.toString() + "\n" +
|
||||
"command: " + command.toString() + "\n" +
|
||||
"label: " + label + "\n" +
|
||||
"args: " + Arrays.toString(args) + "\n" +
|
||||
"========DisableCreeperBoom Command Debug========"
|
||||
);
|
||||
}
|
||||
|
||||
// 没有参数时显示帮助信息
|
||||
if (args.length == 0) {
|
||||
showHelp(sender);
|
||||
return true;
|
||||
}
|
||||
|
||||
// 处理命令参数
|
||||
String subCommand = args[0].toLowerCase();
|
||||
|
||||
switch (subCommand) {
|
||||
case "reload":
|
||||
handleReload(sender);
|
||||
break;
|
||||
case "status":
|
||||
handleStatus(sender);
|
||||
break;
|
||||
case "help":
|
||||
showHelp(sender);
|
||||
break;
|
||||
default:
|
||||
sender.sendMessage(ChatColor.RED + "未知命令!使用 /" + label + " help 查看帮助");
|
||||
break;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 显示帮助信息
|
||||
*/
|
||||
private void showHelp(CommandSender sender) {
|
||||
sender.sendMessage(ChatColor.GREEN + "======== DisableCreeperBoom 帮助 ========");
|
||||
sender.sendMessage(ChatColor.YELLOW + "/" + "creeperboom" + " reload" + ChatColor.WHITE + " - 重新加载配置文件");
|
||||
sender.sendMessage(ChatColor.YELLOW + "/" + "creeperboom" + " status" + ChatColor.WHITE + " - 查看当前配置状态");
|
||||
sender.sendMessage(ChatColor.YELLOW + "/" + "creeperboom" + " help" + ChatColor.WHITE + " - 显示此帮助信息");
|
||||
sender.sendMessage(ChatColor.GREEN + "====================================");
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理重载命令
|
||||
*/
|
||||
private void handleReload(CommandSender sender) {
|
||||
main.instance.reloadConfig();
|
||||
sender.sendMessage(ChatColor.GREEN + "配置文件已重新加载!");
|
||||
|
||||
// 如果开启debug模式,输出日志
|
||||
if (main.instance.getConfig().getBoolean("config.debug", false)) {
|
||||
main.getInstance().getLogger().info("配置文件已由 " + sender.getName() + " 重新加载");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理状态查询命令
|
||||
*/
|
||||
private void handleStatus(CommandSender sender) {
|
||||
boolean enabled = main.instance.getConfig().getBoolean("config.Enable", true);
|
||||
boolean preventExplode = main.instance.getConfig().getBoolean("config.CreeperExplode", false);
|
||||
boolean preventDamage = main.instance.getConfig().getBoolean("config.CreeperDamage", false);
|
||||
boolean debug = main.instance.getConfig().getBoolean("config.debug", false);
|
||||
|
||||
sender.sendMessage(ChatColor.GREEN + "======== DisableCreeperBoom 状态 ========");
|
||||
sender.sendMessage(ChatColor.WHITE + "插件启用: " + (enabled ? ChatColor.GREEN + "是" : ChatColor.RED + "否"));
|
||||
sender.sendMessage(ChatColor.WHITE + "阻止爆炸破坏: " + (preventExplode ? ChatColor.GREEN + "是" : ChatColor.RED + "否"));
|
||||
sender.sendMessage(ChatColor.WHITE + "阻止爆炸伤害: " + (preventDamage ? ChatColor.GREEN + "是" : ChatColor.RED + "否"));
|
||||
sender.sendMessage(ChatColor.WHITE + "调试模式: " + (debug ? ChatColor.GREEN + "开启" : ChatColor.RED + "关闭"));
|
||||
sender.sendMessage(ChatColor.GREEN + "====================================");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
package top.gtb520.java.minecraft.plugins.disableCreeperBoom.Event;
|
||||
|
||||
import org.bukkit.entity.Creeper;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||
import org.bukkit.event.entity.EntityExplodeEvent;
|
||||
import top.gtb520.java.minecraft.plugins.disableCreeperBoom.main;
|
||||
|
||||
public class CreeperBoom implements Listener {
|
||||
|
||||
/**
|
||||
* 处理苦力怕爆炸事件 - 阻止破坏方块
|
||||
*/
|
||||
@EventHandler
|
||||
public void onCreeperExplode(EntityExplodeEvent event) {
|
||||
// 检查插件是否启用
|
||||
if (!main.instance.getConfig().getBoolean("config.Enable", true)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// 检查是否是苦力怕爆炸
|
||||
if (!(event.getEntity() instanceof Creeper)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// 获取配置项:是否阻止苦力怕爆炸破坏方块
|
||||
boolean preventBlockDamage = main.instance.getConfig().getBoolean("config.CreeperExplode", false);
|
||||
|
||||
if (preventBlockDamage) {
|
||||
// 取消方块破坏
|
||||
event.setCancelled(true);
|
||||
|
||||
// 如果开启debug模式,输出日志
|
||||
if (main.instance.getConfig().getBoolean("config.debug", false)) {
|
||||
main.getInstance().getLogger().info("已阻止苦力怕爆炸破坏方块 at " + event.getLocation());
|
||||
}
|
||||
} else {
|
||||
// 如果不阻止破坏,但需要清除爆炸影响的方块列表
|
||||
// 这样可以让爆炸发生但不破坏任何方块
|
||||
event.blockList().clear();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理苦力怕伤害事件 - 阻止对玩家和实体造成伤害
|
||||
*/
|
||||
@EventHandler
|
||||
public void onCreeperDamage(EntityDamageByEntityEvent event) {
|
||||
// 检查插件是否启用
|
||||
if (!main.instance.getConfig().getBoolean("config.Enable", true)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// 检查攻击者是否是苦力怕
|
||||
if (!(event.getDamager() instanceof Creeper)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// 获取配置项:是否阻止苦力怕伤害
|
||||
boolean preventDamage = main.instance.getConfig().getBoolean("config.CreeperDamage", false);
|
||||
|
||||
if (preventDamage) {
|
||||
// 取消伤害
|
||||
event.setCancelled(true);
|
||||
|
||||
// 如果开启debug模式,输出日志
|
||||
if (main.instance.getConfig().getBoolean("config.debug", false)) {
|
||||
main.getInstance().getLogger().info("已阻止苦力怕对 " + event.getEntity().getType() + " 造成伤害");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
package top.gtb520.java.minecraft.plugins.disableCreeperBoom;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.plugin.PluginDescriptionFile;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import top.gtb520.java.minecraft.plugins.disableCreeperBoom.Commands.creeperboom_Commands;
|
||||
import top.gtb520.java.minecraft.plugins.disableCreeperBoom.Event.CreeperBoom;
|
||||
import top.gtb520.java.minecraft.plugins.disableCreeperBoom.utils.YamlFile_Utils;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
import static top.gtb520.java.minecraft.plugins.disableCreeperBoom.utils.unity.GetLoggerPlus;
|
||||
|
||||
public final class main extends JavaPlugin {
|
||||
|
||||
public static YamlFile_Utils Yaml;
|
||||
public static main instance;
|
||||
private static PluginDescriptionFile descriptionFile;
|
||||
public static PluginDescriptionFile getDescriptionFile() {
|
||||
return descriptionFile;
|
||||
}
|
||||
public static main getInstance() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
// Plugin startup logic
|
||||
instance = this;
|
||||
|
||||
GetLoggerPlus("\n" +
|
||||
" ___ ___ \n" +
|
||||
" / _ \\ _ __ ___ _ _ / __| ___ _ _ _ _ __ ___ \n" +
|
||||
" | (_) | '_ \\/ -_) ' \\\\__ \\/ _ \\ || | '_/ _/ -_)\n" +
|
||||
" \\___/| .__/\\___|_||_|___/\\___/\\_,_|_| \\__\\___|\n" +
|
||||
" |_| \n");
|
||||
GetLoggerPlus("&f========DisableCreeperBoom========" + "\n" +
|
||||
"禁用苦力怕爆炸破坏" + "\n" +
|
||||
"&f========DisableCreeperBoom========\""
|
||||
);
|
||||
|
||||
// 加载配置文件及初始化目录等
|
||||
File Folder = new File(String.valueOf(getDataFolder()));
|
||||
File Config_File = new File(getDataFolder(), "config.yml");
|
||||
Yaml = new YamlFile_Utils();
|
||||
if (!Folder.exists() || !Config_File.exists()) {
|
||||
Folder.mkdirs();
|
||||
Yaml.saveYamlFile(getDataFolder().getPath(), "config.yml", "config.yml",true);
|
||||
}
|
||||
List<File> Folders = new ArrayList<>();
|
||||
Folders.add(new File(getDataFolder().getPath()));
|
||||
Makedirs(Folders);
|
||||
|
||||
// 注册事件监听器
|
||||
Bukkit.getPluginManager().registerEvents(new CreeperBoom(), this);
|
||||
|
||||
// 注册命令
|
||||
Objects.requireNonNull(getCommand("creeperboom")).setExecutor(new creeperboom_Commands());
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
// Plugin shutdown logic
|
||||
}
|
||||
|
||||
private static void Makedirs(List<File> Folders) {
|
||||
for (File EachFolder : Folders) {
|
||||
if (!EachFolder.exists()) {
|
||||
EachFolder.mkdirs();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
package top.gtb520.java.minecraft.plugins.disableCreeperBoom.utils;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.io.*;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
|
||||
public class YamlFile_Utils {
|
||||
|
||||
private InputStream getResource(@NotNull String filename) {
|
||||
try {
|
||||
URL URL = getClass().getClassLoader().getResource(filename);
|
||||
if (URL == null)
|
||||
return null;
|
||||
URLConnection Connection = URL.openConnection();
|
||||
Connection.setUseCaches(false);
|
||||
return Connection.getInputStream();
|
||||
} catch (IOException ex) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public void saveYmlFile(String FilePath, String FileName, String ResourcePath) {
|
||||
File Folder = new File(FilePath);
|
||||
if (!Folder.exists())
|
||||
Folder.mkdirs();
|
||||
saveResource(FilePath, ResourcePath, FileName, false);
|
||||
}
|
||||
|
||||
public void saveYamlFile(String FilePath, String FileName, String ResourcePath,boolean Replace) {
|
||||
File Folder = new File(FilePath);
|
||||
if (!Folder.exists())
|
||||
Folder.mkdirs();
|
||||
saveResource(FilePath, ResourcePath, FileName, Replace);
|
||||
}
|
||||
|
||||
public void saveResource(String FilePath, @NotNull String ResourcePath, String OutFileName, boolean Replace) {
|
||||
if (ResourcePath.equals(""))
|
||||
throw new IllegalArgumentException("ResourcePath cannot be null or empty");
|
||||
ResourcePath = ResourcePath.replace('\\', '/');
|
||||
InputStream in = getResource(ResourcePath);
|
||||
if (in == null)
|
||||
throw new IllegalArgumentException("The embedded resource '" + ResourcePath + "' cannot be found in " + ResourcePath);
|
||||
File OutFile = new File(FilePath, OutFileName);
|
||||
try {
|
||||
if (!OutFile.exists() || Replace) {
|
||||
OutputStream out = new FileOutputStream(OutFile);
|
||||
byte[] buf = new byte[1024];
|
||||
int Len;
|
||||
while ((Len = in.read(buf)) > 0)
|
||||
out.write(buf, 0, Len);
|
||||
out.close();
|
||||
in.close();
|
||||
} else {
|
||||
System.out.println("Could not save " + OutFile.getName() + " to " + OutFile + " because " + OutFile.getName() + " already exists.");
|
||||
}
|
||||
} catch (IOException ex) {
|
||||
System.out.println("Could not save " + OutFile.getName() + " to " + OutFile);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,134 @@
|
||||
package top.gtb520.java.minecraft.plugins.disableCreeperBoom.utils;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.inventory.meta.SkullMeta;
|
||||
import top.gtb520.java.minecraft.plugins.disableCreeperBoom.main;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Objects;
|
||||
|
||||
public class unity {
|
||||
|
||||
public static void SaveAndReloadConfig() {
|
||||
main.instance.saveConfig();
|
||||
main.instance.reloadConfig();
|
||||
}
|
||||
public static String ColorMessage(String String1) {
|
||||
return ChatColor.translateAlternateColorCodes('&',String1);
|
||||
}
|
||||
|
||||
public static void GetLoggerPlus(String String1) {
|
||||
CommandSender Console = Bukkit.getConsoleSender();
|
||||
Console.sendMessage(ColorMessage(String1));
|
||||
}
|
||||
|
||||
static HashMap<String, Integer> IntTemp = new HashMap<>();
|
||||
|
||||
static HashMap<String, String> StringTemp = new HashMap<>();
|
||||
|
||||
static HashMap<String, Boolean> BooleanTemp = new HashMap<>();
|
||||
|
||||
static HashMap<String, Location> LocationTemp = new HashMap<>();
|
||||
|
||||
public static void SetLocationTempTemp(String String1, Location String2) {
|
||||
LocationTemp.put(String1,String2);
|
||||
}
|
||||
|
||||
public static Location getLocationTempTemp(String String1) {
|
||||
return LocationTemp.get(String1);
|
||||
}
|
||||
|
||||
public static void SetStringTemp(String String1,String String2) {
|
||||
StringTemp.put(String1,String2);
|
||||
}
|
||||
|
||||
public static String getStringTemp(String String1) {
|
||||
return StringTemp.get(String1);
|
||||
}
|
||||
|
||||
public static void SetIntTemp(String String1, Integer Int1) {
|
||||
IntTemp.put(String1,Int1);
|
||||
}
|
||||
|
||||
public static Integer GetIntTemp(String String1) {
|
||||
return IntTemp.get(String1);
|
||||
}
|
||||
|
||||
public static void SetBooleanTemp(String String1, boolean Boolean1) {
|
||||
BooleanTemp.put(String1, Boolean1);
|
||||
}
|
||||
|
||||
public static boolean getBooleanTemp(String String1) {
|
||||
return BooleanTemp.get(String1);
|
||||
}
|
||||
|
||||
public static void KickGui(Player player) {
|
||||
Inventory UI = Bukkit.createInventory(player,45, ColorMessage("&a选择你要踢出的玩家"));
|
||||
|
||||
ItemStack Bk = new ItemStack(Material.ORANGE_STAINED_GLASS_PANE);
|
||||
ItemMeta Bk_Meta = Bk.getItemMeta();
|
||||
Objects.requireNonNull(Bk_Meta).setDisplayName(ColorMessage("&e这只是一个边框"));
|
||||
ArrayList<String> Bk_Lore = new ArrayList<>();
|
||||
Bk_Lore.add(null);
|
||||
Bk_Lore.add(ColorMessage("&e这只是一个边框"));
|
||||
Bk_Meta.setLore(Bk_Lore);
|
||||
Bk.setItemMeta(Bk_Meta);
|
||||
|
||||
for (int i1 = 0 ; i1 <9 ; i1++) {
|
||||
UI.setItem(i1,Bk);
|
||||
}
|
||||
|
||||
for (int i2 = 36 ; i2 <40 ; i2++) {
|
||||
UI.setItem(i2,Bk);
|
||||
}
|
||||
|
||||
for (int i3 = 41 ; i3 <45 ; i3++) {
|
||||
UI.setItem(i3,Bk);
|
||||
}
|
||||
|
||||
UI.setItem(9,Bk);
|
||||
UI.setItem(17,Bk);
|
||||
|
||||
UI.setItem(18,Bk);
|
||||
UI.setItem(26,Bk);
|
||||
|
||||
UI.setItem(27,Bk);
|
||||
UI.setItem(35,Bk);
|
||||
|
||||
ItemStack Gb = new ItemStack(Material.REDSTONE_BLOCK);
|
||||
ItemMeta Gb_Meta = Gb.getItemMeta();
|
||||
Objects.requireNonNull(Gb_Meta).setDisplayName(ColorMessage("&d关闭菜单"));
|
||||
ArrayList<String> Gb_Lore = new ArrayList<>();
|
||||
Gb_Lore.add(null);
|
||||
Gb_Lore.add(ColorMessage("&e点击关闭菜单"));
|
||||
Gb_Meta.setLore(Gb_Lore);
|
||||
Gb.setItemMeta(Gb_Meta);
|
||||
|
||||
UI.setItem(40,Gb);
|
||||
|
||||
ArrayList<Player> players = new ArrayList<>(player.getServer().getOnlinePlayers());
|
||||
for (Player value : players) {
|
||||
ItemStack PlayerHead = new ItemStack(Material.PLAYER_HEAD);
|
||||
SkullMeta PlayerHead_meta = (SkullMeta) PlayerHead.getItemMeta();
|
||||
Objects.requireNonNull(PlayerHead_meta).setOwningPlayer(value);
|
||||
Objects.requireNonNull(PlayerHead_meta).setDisplayName(ChatColor.RESET + value.getDisplayName() + ChatColor.RESET);
|
||||
ArrayList<String> PlayerHead_Lore = new ArrayList<>();
|
||||
PlayerHead_Lore.add(null);
|
||||
PlayerHead_Lore.add(ColorMessage( "&e点击踢出玩家"));
|
||||
PlayerHead_meta.setLore(PlayerHead_Lore);
|
||||
PlayerHead.setItemMeta(PlayerHead_meta);
|
||||
|
||||
UI.addItem(PlayerHead);
|
||||
}
|
||||
player.openInventory(UI);
|
||||
}
|
||||
}
|
||||
27
src/main/resources/config.yml
Normal file
27
src/main/resources/config.yml
Normal file
@@ -0,0 +1,27 @@
|
||||
# ============================================
|
||||
# DisableCreeperBoom 插件配置文件
|
||||
# ============================================
|
||||
# Minecraft 版本: 1.21.8
|
||||
# Bukkit API 插件
|
||||
# ============================================
|
||||
|
||||
config:
|
||||
# 插件总开关 - 是否启用此插件功能
|
||||
# true = 启用插件功能
|
||||
# false = 禁用插件功能(苦力怕正常爆炸)
|
||||
Enable: true
|
||||
|
||||
# 苦力怕爆炸破坏方块控制
|
||||
# true = 阻止苦力怕爆炸破坏方块
|
||||
# false = 允许苦力怕爆炸破坏方块
|
||||
CreeperExplode: true
|
||||
|
||||
# 苦力怕爆炸伤害控制
|
||||
# true = 阻止苦力怕爆炸对玩家和实体造成伤害
|
||||
# false = 允许苦力怕爆炸对玩家和实体造成伤害
|
||||
CreeperDamage: true
|
||||
|
||||
# 调试模式
|
||||
# true = 在控制台输出详细的调试信息
|
||||
# false = 关闭调试信息输出
|
||||
debug: false
|
||||
20
src/main/resources/plugin.yml
Normal file
20
src/main/resources/plugin.yml
Normal file
@@ -0,0 +1,20 @@
|
||||
name: DisableCreeperBoom
|
||||
version: '${version}'
|
||||
main: top.gtb520.java.minecraft.plugins.disableCreeperBoom.main
|
||||
api-version: '1.21'
|
||||
authors: [gtb520]
|
||||
description: 禁用苦力怕爆炸破坏方块和伤害玩家
|
||||
website: https://github.com/gtb520
|
||||
|
||||
commands:
|
||||
creeperboom:
|
||||
description: 苦力怕爆炸控制插件主命令
|
||||
usage: /<command> [reload|status]
|
||||
aliases: [cb, creeper]
|
||||
permission: disablecreeperboom.admin
|
||||
permission-message: "你没有权限使用此命令"
|
||||
|
||||
permissions:
|
||||
disablecreeperboom.admin:
|
||||
description: 允许使用插件管理命令
|
||||
default: op
|
||||
Reference in New Issue
Block a user