From 7b0fc3647e06dd5f80f045de0fef12bf3cffb7f1 Mon Sep 17 00:00:00 2001 From: tianyu <32282861@qq.com> Date: Thu, 25 Jul 2024 05:58:44 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B5=8B=E8=AF=95=E7=89=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 39 ++++++++ pom.xml | 32 +++++++ .../java/me/Demon/DemonDeathEvent/Main.java | 94 +++++++++++++++++++ src/main/resources/config.yml | 63 +++++++++++++ src/main/resources/plugin.yml | 5 + 5 files changed, 233 insertions(+) create mode 100644 .gitignore create mode 100644 pom.xml create mode 100644 src/main/java/me/Demon/DemonDeathEvent/Main.java create mode 100644 src/main/resources/config.yml create mode 100644 src/main/resources/plugin.yml diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..a91c35d --- /dev/null +++ b/.gitignore @@ -0,0 +1,39 @@ +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/ diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..37a328d --- /dev/null +++ b/pom.xml @@ -0,0 +1,32 @@ + + + 4.0.0 + + org.example + DemonDeathEvent + 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/DemonDeathEvent/Main.java b/src/main/java/me/Demon/DemonDeathEvent/Main.java new file mode 100644 index 0000000..8993dc8 --- /dev/null +++ b/src/main/java/me/Demon/DemonDeathEvent/Main.java @@ -0,0 +1,94 @@ +package me.Demon.DemonDeathEvent; + +import org.bukkit.Bukkit; +import org.bukkit.Location; +import org.bukkit.command.Command; +import org.bukkit.command.CommandSender; +import org.bukkit.configuration.file.FileConfiguration; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.entity.PlayerDeathEvent; +import org.bukkit.plugin.java.JavaPlugin; +import org.bukkit.scheduler.BukkitRunnable; + +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Calendar; +import java.util.Date; +import java.util.List; + +public class Main extends JavaPlugin implements Listener { + + public static Main plugin; + public static List listWorld = new ArrayList<>(); + public static List BlockWorld = new ArrayList<>(); + + public void onEnable() { + plugin = this; + saveDefaultConfig(); + Bukkit.getPluginManager().registerEvents( this, this ); + listWorld.addAll(getConfig().getConfigurationSection("WorldSpawn").getKeys(false)); + BlockWorld.addAll(getConfig().getStringList("BlockWorld")); + Bukkit.getConsoleSender().sendMessage("§b[DemonDeathEvent] §a插件成功载入Sever!"); + Bukkit.getConsoleSender().sendMessage("§b[DemonDeathEvent] §a妖魂QQ:1763917516"); + } + public void onDisable(){ + Bukkit.getConsoleSender().sendMessage("§b[DemonDeathEvent] §c插件已正常关闭!"); + } + + public boolean onCommand(CommandSender sender, Command cmd, String Command, String[] args) { + if (Command.equalsIgnoreCase( "setrespawn" ) && sender.isOp() && (sender instanceof Player)) { + Player p = (Player)sender; + String worldName = p.getWorld().getName(); + String str = "WorldSpawn." + worldName + "."; + getConfig().set(str + "world", p.getLocation().getWorld().getName()); + getConfig().set(str + "x", p.getLocation().getX()); + getConfig().set(str + "y", p.getLocation().getY()); + getConfig().set(str + "z", p.getLocation().getZ()); + getConfig().set(str + "yaw", p.getLocation().getYaw()); + getConfig().set(str + "pitch", p.getLocation().getPitch()); + p.getWorld().setSpawnLocation(p.getLocation().getBlockX(), p.getLocation().getBlockZ(), p.getLocation().getBlockY()); + saveConfig(); + sender.sendMessage("§f[§c消息§f] §a成功设置§e"+worldName+"§a的复活点."); + } + return false; + } + + public static Location TpSpawn(String worlName) { + Location loc = null; + FileConfiguration yml = Main.plugin.getConfig(); + String str = "WorldSpawn." + worlName + "."; + if (yml.getString(str) != null) { + String w = yml.getString(str + "world"); + double x = yml.getDouble(str + "x"); + double y = yml.getDouble(str + "y"); + double z = yml.getDouble(str + "z"); + float pi = (float) yml.getDouble(str + "pitch"); + float ya = (float) yml.getDouble(str + "yaw"); + loc = new Location(Bukkit.getWorld(w), x, y, z, ya, pi); + } + return loc; + } + + + public static String getTime(String Format){ + Date date = Calendar.getInstance().getTime(); + SimpleDateFormat datatime = new SimpleDateFormat(Format); + return datatime.format(date); + } + + // 若玩家在禁止back的世界则直接复活 + @EventHandler + public void onAutoRespawn(PlayerDeathEvent e){ + if(e.getEntity() == null){ return; } + Player p = e.getEntity(); + Location loc = TpSpawn("hub"); + new BukkitRunnable() { + public void run() { + p.spigot().respawn(); + p.teleport(loc); + } + }.runTaskLater(this, 5L); + } +} \ No newline at end of file diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml new file mode 100644 index 0000000..08cdf88 --- /dev/null +++ b/src/main/resources/config.yml @@ -0,0 +1,63 @@ +BlockWorld: +- hub +- PlotSquared +Todaytime: 2021/03/31 +BackAmount: + 虎牙妖魂: 10 +WorldSpawn: + world: + world: world + x: 0.4529860503396992 + y: 93.0 + z: 2.4946512089232633 + yaw: 89.999275 + pitch: 0.15037563 + lrzs: + world: lrzs + x: 112.51658683192733 + y: 39.0 + z: -62.30000001192093 + yaw: -180.14899 + pitch: 0.45002207 + xdsl: + world: xdsl + x: -146.57872435534708 + y: 77.0 + z: -190.66123050974164 + yaw: 357.60358 + pitch: 5.100116 + jhby: + world: jhby + x: 0.634781297747613 + y: 50.0 + z: 0.4355539632605311 + yaw: -88.79977 + pitch: -0.45014793 + bhlyy: + world: bhlyy + x: 179.37079143213032 + y: 82.0 + z: 114.03616108316832 + yaw: 141.38824 + pitch: -0.8989827 + slds: + world: slds + x: -234.5158956025492 + y: 27.0 + z: -141.60707933744933 + yaw: 180.11926 + pitch: 0.8999367 + whd: + world: whd + x: 22.484167799538906 + y: 52.0 + z: -14.496803957077004 + yaw: -270.29922 + pitch: -0.4500123 + cjq: + world: cjq + x: 0.46134267863077005 + y: 53.0 + z: 0.8488541554841655 + yaw: 0.3026275 + pitch: -0.30001152 diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml new file mode 100644 index 0000000..52f67dc --- /dev/null +++ b/src/main/resources/plugin.yml @@ -0,0 +1,5 @@ +name: DemonDeathEvent +main: me.Demon.DemonDeathEvent.Main +version: 1.3.4 +commands: + setrespawn: \ No newline at end of file