This commit is contained in:
Xanadu13
2022-08-17 10:06:25 +08:00
committed by GitHub
parent d1f362e504
commit 37486e05c1
11 changed files with 87 additions and 32 deletions
@@ -6,6 +6,7 @@ import org.bukkit.Server;
import org.bukkit.configuration.InvalidConfigurationException;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Entity;
import org.bukkit.inventory.ItemStack;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.PluginManager;
@@ -33,12 +34,15 @@ public final class EnderDragon extends JavaPlugin {
public static File langF;
public static FileConfiguration data;
public static FileConfiguration lang;
public static int mcMainVersion;
public static int mcPatchVersion;
@Override
public void onEnable() {
plugin = this;
server = plugin.getServer();
pm = Bukkit.getPluginManager();
mcMainVersion = getMinecraftVersion();
boolean configNotFound = false;
boolean dataNotFound = false;
if (!new File(getDataFolder(), "config.yml").exists()) {
@@ -66,7 +70,7 @@ public final class EnderDragon extends JavaPlugin {
if(!getConfig().getString("version").equals("1.8.3") ){
sendMessage(Message.configWrongVersion);
}
if(!data.getString("version").equals("1.8.1") ){
if(!data.getString("version").equals("1.8.4") ){
sendMessage(Message.dataWrongVersion);
}
if(!lang.getString("version").equals("1.8.3") ){
@@ -135,6 +139,23 @@ public final class EnderDragon extends JavaPlugin {
}
return item;
}
private int getMinecraftVersion() {
String[] version = getServer().getBukkitVersion().replace('-', '.').split("\\.");
try {
mcPatchVersion = Integer.parseInt(version[2]);
} catch (NumberFormatException ignored) {
}
return Integer.parseInt(version[1]);
}
public static boolean isSpecial(Entity e){
if(mcMainVersion >= 11){
return e.getScoreboardTags().contains("special");
}
else{
String uuid = e.getUniqueId().toString();
return data.getStringList("special").contains(uuid);
}
}
}
@@ -77,7 +77,7 @@ public class MainCommand implements CommandExecutor {
List<String> datum = data.getStringList("items");
ItemStack item = p.getItemInHand();
datum.add(itemStackToString(item));
datum.add(String.valueOf(chance));
datum.add(ChanceStr);
data.set("items", datum);
try {
data.save(dataF);
@@ -85,7 +85,7 @@ public class MainCommand implements CommandExecutor {
throw new RuntimeException(e);
}
data = YamlConfiguration.loadConfiguration(dataF);
p.sendMessage(prefix + Message.DropItemAddSucceed.replace("{chance}",""+chance));
p.sendMessage(prefix + Message.DropItemAddSucceed.replace("{chance}",ChanceStr));
}
}
@@ -119,18 +119,17 @@ public class MainCommand implements CommandExecutor {
int max = datum.size() / 2 ;
for(int i=0 ; i<max ; ){
i = i + 1;
double chance = Double.parseDouble(datum.get(i*2-1));
String str = datum.get(i*2-2);
ItemStack item = StringToItemStack(str);
ItemMeta meta = item.getItemMeta();
if(meta != null) {
List<String> lore = meta.getLore();
if(lore != null) {
lore.add("§6("+Message.DropChance+": " + chance + "%)§r");
lore.add("§6("+Message.DropChance+": " + datum.get(i*2-1) + "%)§r");
meta.setLore(lore);
}
else{
meta.setLore(Collections.singletonList("§6("+Message.DropChance+": " + chance + "%)§r"));
meta.setLore(Collections.singletonList("§6("+Message.DropChance+": " + datum.get(i*2-1) + "%)§r"));
}
item.setItemMeta(meta);
}
@@ -8,6 +8,7 @@ import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import xanadu.enderdragon.lang.Message;
import xanadu.enderdragon.tools.MyMath;
import static xanadu.enderdragon.EnderDragon.*;
@@ -20,10 +21,17 @@ public class CreatureHurt implements Listener {
if(e.getDamager().getType() != EntityType.PLAYER){return;}
if(e.getEntity().getType() != EntityType.ENDER_DRAGON){return;}
Player p = (Player) e.getDamager();
double damage = e.getDamage();
double damage = MyMath.div(e.getFinalDamage(),1,2);
MSG = MSG.replaceAll("%damage%", String.valueOf(damage));
if(DamageVisual == 1){p.sendTitle("",MSG,5,40,5);}
if(DamageVisual == 1){
if(mcMainVersion >= 11){p.sendTitle("",MSG,5,40,5);}
else if(mcMainVersion >= 9){p.sendTitle("",MSG);}
}
if(DamageVisual == 2){p.sendMessage(MSG);}
if(DamageVisual == 3){p.spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(MSG));}
if(DamageVisual == 3){
if(mcMainVersion >= 10){
p.spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(MSG));
}
}
}
}
@@ -18,7 +18,7 @@ public class DragonAttack implements Listener {
@EventHandler
public void OnDragonAttack(EntityDamageByEntityEvent e){
if(e.getDamager().getType() != EntityType.ENDER_DRAGON){return;}
if(!e.getDamager().getScoreboardTags().contains("special")){return;}
if(!isSpecial(e.getDamager())){return;}
double multiple = plugin.getConfig().getDouble("special-dragon.damage-multiply");
double rate = plugin.getConfig().getDouble("special-dragon.suck-blood.rate") / 100;
double BasicSuck = plugin.getConfig().getDouble("special-dragon.suck-blood.base-suck-blood");
@@ -43,7 +43,7 @@ public class DragonDeath implements Listener {
String InvIsFull = Message.PlayerInvFull;
if(KillMsg != null) {
if(p != null) {
if ((e.getEntity().getScoreboardTags().contains("special")) || (AllBroadcast)) {
if (isSpecial(e.getEntity()) || AllBroadcast) {
Bukkit.broadcastMessage(prefix + KillMsg.replaceAll("%times%", String.valueOf(times)).replaceAll("%player%", p.getDisplayName()));
}
}
@@ -57,13 +57,13 @@ public class DragonDeath implements Listener {
String name = names.toString();
if(name.equals("")){name = nobody;}
if(name.endsWith(",")){name = name.substring(0,name.length()-1);}
if ((e.getEntity().getScoreboardTags().contains("special")) || (AllBroadcast)) {
if (isSpecial(e.getEntity()) || AllBroadcast) {
Bukkit.broadcastMessage(prefix + KillMsg.replaceAll("%times%", String.valueOf(times)).replaceAll("%player%", name));
}
}
}
if(UseCMD) {
if (e.getEntity().getScoreboardTags().contains("special")) {
if (isSpecial(e.getEntity())) {
List<String> CMDList = plugin.getConfig().getStringList("command.special-dragon");
for (String command : CMDList) {
if (!(p == null && command.contains("%player%"))) {
@@ -80,7 +80,7 @@ public class DragonDeath implements Listener {
}
}
}
if(e.getEntity().getScoreboardTags().contains("special")){
if(isSpecial(e.getEntity())){
e.setDroppedExp(exp);
if (EggChance) {
BukkitRunnable runnable = new BukkitRunnable() {
@@ -117,6 +117,12 @@ public class DragonDeath implements Listener {
}
}
if(warning){p.sendMessage(prefix + InvIsFull);}
if(mcMainVersion < 11) {
List<String> special = data.getStringList("special");
special.remove(e.getEntity().getUniqueId().toString());
data.set("special", special);
data.save(dataF);
}
}
}
}
@@ -5,6 +5,7 @@ import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityRegainHealthEvent;
import static xanadu.enderdragon.EnderDragon.isSpecial;
import static xanadu.enderdragon.EnderDragon.plugin;
public class DragonHeal implements Listener {
@@ -14,7 +15,7 @@ public class DragonHeal implements Listener {
if(!e.getRegainReason().equals(EntityRegainHealthEvent.RegainReason.ENDER_CRYSTAL)){return;}
double NormalHeal = plugin.getConfig().getDouble("normal-dragon.crystal-heal");
double SpecialHeal = plugin.getConfig().getDouble("special-dragon.crystal-heal");
if(e.getEntity().getScoreboardTags().contains("special")){
if(isSpecial(e.getEntity())){
e.setAmount(SpecialHeal / 2);
}
else{
@@ -2,9 +2,6 @@ package xanadu.enderdragon.events;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.attribute.Attribute;
import org.bukkit.attribute.AttributeInstance;
import org.bukkit.attribute.AttributeModifier;
import org.bukkit.entity.EntityType;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
@@ -12,6 +9,8 @@ import org.bukkit.event.entity.CreatureSpawnEvent;
import org.bukkit.scoreboard.Team;
import xanadu.enderdragon.lang.Message;
import java.io.IOException;
import java.util.List;
import java.util.concurrent.ThreadLocalRandom;
import static xanadu.enderdragon.EnderDragon.*;
@@ -19,7 +18,7 @@ import static xanadu.enderdragon.EnderDragon.*;
public class DragonSpawn implements Listener {
@EventHandler
public void OnDragonSpawn(CreatureSpawnEvent e){
public void OnDragonSpawn(CreatureSpawnEvent e) throws IOException {
if(e.getEntity().getType() != EntityType.ENDER_DRAGON){return;}
int times = data.getInt("times");
double health = plugin.getConfig().getDouble("special-dragon.max-health");
@@ -38,21 +37,30 @@ public class DragonSpawn implements Listener {
Bukkit.broadcastMessage(prefix + SpawnMsg.replaceAll("%times%", String.valueOf(times)));
}
if(times % circle == 0 && chance) {
e.getEntity().addScoreboardTag("special");
if(mcMainVersion >= 11){e.getEntity().addScoreboardTag("special");}
else{
List<String> special = data.getStringList("special");
special.add(e.getEntity().getUniqueId().toString());
data.set("special",special);
data.save(dataF);
}
if(health > 0) {
AttributeInstance MaxHealth = e.getEntity().getAttribute(Attribute.GENERIC_MAX_HEALTH);
assert MaxHealth != null;
MaxHealth.addModifier(new AttributeModifier("最大生命值", health - 200, AttributeModifier.Operation.ADD_NUMBER));
e.getEntity().setMaxHealth(health);
}
e.getEntity().setHealth(SpawnHealth);
if (color != null) {
if (color != null && mcMainVersion >= 9) {
if(!color.equalsIgnoreCase("disable")) {
color = color.toUpperCase();
if(server.getScoreboardManager().getMainScoreboard().getTeam("enderdragon-glow") == null) {
server.getScoreboardManager().getMainScoreboard().registerNewTeam("enderdragon-glow");
}
Team team = server.getScoreboardManager().getMainScoreboard().getTeam("enderdragon-glow");
if(mcMainVersion >= 12) {
team.setColor(ChatColor.valueOf(color));
}
else{
team.setPrefix(ChatColor.valueOf(color).toString());
}
team.addEntry(e.getEntity().getUniqueId().toString());
e.getEntity().setGlowing(true);
}
@@ -0,0 +1,12 @@
package xanadu.enderdragon.tools;
import java.math.BigDecimal;
import java.math.RoundingMode;
public class MyMath {
public static double div(double d1,double d2,int len){
BigDecimal b1 = new BigDecimal(d1);
BigDecimal b2 = new BigDecimal(d2);
return b1.divide(b2,len, RoundingMode.HALF_UP).doubleValue();
}
}
+4 -4
View File
@@ -2,6 +2,7 @@
version: 1.8.3
#可选: 'Chinese','English'
#Spigot1.8等远古服务端不支持中文
lang: 'Chinese'
#普通末影龙
@@ -80,17 +81,16 @@ special-dragon:
y: 70
z: 0
#特殊龙发光的颜色
#特殊龙发光的颜色(mc1.8及以下版本不可用)
#若要关闭发光功能,设置该项为“disable”
#所有可用颜色如下(不区分大小写)
#AQUA-青色,BLACK-黑色,BLUE-蓝色,DARK_AQUA-深青,DARK_BLUE-深蓝,DARK_GRAY-深灰,DARK_GREEN-深绿,DARK_PURPLE-深紫,DARK_RED-深红,GOLD-金色,GRAY-灰色,GREEN-绿色,LIGHT_PURPLE-紫色,RED-红色,WHITE-白色,YELLOW-黄色
glow-color: GOLD
#玩家攻击末影龙时伤害显示
#填入0代表不显示
#填入1代表显示在副标题栏(会有略微视野遮挡)
#填入1代表显示在副标题栏(会有略微视野遮挡)(mc1.8及以下版本不可用)
#输入2代表显示在聊天栏(可能会刷屏)
#输入3代表显示在ActionBar(推荐)
#输入3代表显示在ActionBar(推荐)(mc1.9及以下版本不可用)
damage-visible: 3
#指令/ed drop gui 打开的页面的标题
+2 -2
View File
@@ -1,10 +1,10 @@
#配置文件版本,请勿修改
version: 1.8.1
version: 1.8.4
# 已生成过的末影龙数量
# 如果你安装本插件时,末影龙已被杀死过,请自行修改这个值(请填入整数)
# 指令召唤和指令杀死的末影龙不会被计入次数
# 注意:插件开始使用后不需再修改这个值
times: 1
special: []
items: []
+1 -1
View File
@@ -1,5 +1,5 @@
name: EnderDragon
version: 1.8.3
version: 1.8.4
main: xanadu.enderdragon.EnderDragon
author: Xanadu13
api-version: 1.13