From 5eb22c4ddd1d5b9f206f673fd0a171eaf2d70783 Mon Sep 17 00:00:00 2001 From: lanzhi6 Date: Tue, 10 May 2022 08:34:36 +0800 Subject: [PATCH] =?UTF-8?q?[3.2.0]=E5=A4=A7=E6=9B=B4=E6=94=B9,=E4=B8=BB?= =?UTF-8?q?=E8=A6=81=E5=A2=9E=E5=8A=A0=E6=95=88=E6=9E=9C=E5=92=8C=E4=BA=8B?= =?UTF-8?q?=E4=BB=B6=E6=95=88=E6=9E=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 8 +- .../bluestargame/BluestarGamePlugin.java | 11 + .../commands/BluestarItemCommand.java | 504 ++++++++++++++---- .../listener/ChatColorListener.java | 33 ++ .../bluestargame/listener/arrowListener.java | 6 +- .../bluestargame/listener/effectListener.java | 192 +++++++ .../listener/opSwordListener.java | 7 +- .../randoms/randChatColorListener.java | 8 +- .../managers/BluestarGameManager.java | 49 ++ .../managers/RandomEventsChange.java | 7 +- .../register/ListenersRegister.java | 6 +- src/main/resources/plugin.yml | 3 + 12 files changed, 701 insertions(+), 133 deletions(-) create mode 100644 src/main/java/me/lanzhi/bluestargame/listener/ChatColorListener.java create mode 100644 src/main/java/me/lanzhi/bluestargame/listener/effectListener.java diff --git a/pom.xml b/pom.xml index 6ae5494..7d2ee4e 100644 --- a/pom.xml +++ b/pom.xml @@ -6,13 +6,13 @@ me.lanzhi BluestarGame - 3.1.0 + 3.2.0 jar BluestarGame - 1.8 + 17 UTF-8 @@ -92,7 +92,7 @@ com.github.lanzhi6 BluestarAPI - 2.0.1 + 2.1.2 provided @@ -104,7 +104,7 @@ com.github.lanzhi6 BluestarGameAPI - 3.1 + 3.2 provided diff --git a/src/main/java/me/lanzhi/bluestargame/BluestarGamePlugin.java b/src/main/java/me/lanzhi/bluestargame/BluestarGamePlugin.java index 91be635..3d1238b 100644 --- a/src/main/java/me/lanzhi/bluestargame/BluestarGamePlugin.java +++ b/src/main/java/me/lanzhi/bluestargame/BluestarGamePlugin.java @@ -31,6 +31,7 @@ public final class BluestarGamePlugin extends JavaPlugin implements BluestarGame private final File PlayerData; private final YamlFile PlayerMap; private final YamlFile Data; + private final YamlFile Lang; private final String messageHead=ChatColor.GOLD+"["+ChatColor.DARK_AQUA+"BluestarGame"+ChatColor.GOLD+"]"; private final String errorMessageHead=messageHead+ChatColor.RED; private final SimpleDateFormat BluestarDateFormat; @@ -52,6 +53,7 @@ public BluestarGamePlugin() config=new YamlFile(new File(this.getDataFolder(),"config.yml")); PlayerMap=new YamlFile(new File(this.getDataFolder(),"playerMap.yml")); Data=new YamlFile(new File(this.getDataFolder(),"data.yml")); + Lang=new YamlFile(new File(this.getDataFolder(),"lang.yml")); PlayerData=new File(this.getDataFolder(),"PlayerData"); PlayerData.mkdirs(); BluestarDateFormat=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); @@ -65,6 +67,7 @@ public void onEnable() config.reload(); PlayerMap.reload(); Data.reload(); + Lang.reload(); bluestarGameManager=new BluestarGameManager(this); commandRegister=new CommandRegister(this); listenersRegister=new ListenersRegister(this); @@ -104,6 +107,7 @@ public void onDisable() Data.save(); PlayerMap.save(); config.save(); + Lang.save(); Bukkit.getServicesManager().unregisterAll(this); isEnable=false; System.out.println("BluestarGame已卸载"); @@ -175,6 +179,12 @@ public YamlFile getPlayerMap() return PlayerMap; } + @Override + public YamlFile getLang() + { + return Lang; + } + @Override public BluestarGameManager getBluestarGameManager() { @@ -199,6 +209,7 @@ public BluestarGamePlugin getPlugin() return this; } + @Override public boolean isEnable() { return this.isEnable; diff --git a/src/main/java/me/lanzhi/bluestargame/commands/BluestarItemCommand.java b/src/main/java/me/lanzhi/bluestargame/commands/BluestarItemCommand.java index 97f5881..34d26b9 100644 --- a/src/main/java/me/lanzhi/bluestargame/commands/BluestarItemCommand.java +++ b/src/main/java/me/lanzhi/bluestargame/commands/BluestarItemCommand.java @@ -2,6 +2,7 @@ import de.tr7zw.nbtapi.NBTCompound; import de.tr7zw.nbtapi.NBTItem; +import me.lanzhi.bluestarapi.Api.RGBChat; import me.lanzhi.bluestargame.BluestarGamePlugin; import org.bukkit.ChatColor; import org.bukkit.Material; @@ -9,35 +10,67 @@ import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; import org.bukkit.command.TabExecutor; +import org.bukkit.configuration.ConfigurationSection; import org.bukkit.entity.EntityType; import org.bukkit.entity.Player; +import org.bukkit.entity.Sheep; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; +import org.bukkit.potion.PotionEffectType; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.List; +import static me.lanzhi.bluestargame.listener.effectListener.effectEventType; + +import java.util.*; public final class BluestarItemCommand implements CommandExecutor, TabExecutor { private final List entityType=new ArrayList<>(); - + private final List potionEffectType=new ArrayList<>(); + private final Map effectEvents=new HashMap<>(); private final BluestarGamePlugin plugin; + private ConfigurationSection effectLang; + private ConfigurationSection entityLang; public BluestarItemCommand(BluestarGamePlugin plugin) { this.plugin=plugin; + effectLang=plugin.getLang().getConfigurationSection("effect"); + entityLang=plugin.getLang().getConfigurationSection("entity"); + if (effectLang==null) + { + effectLang=plugin.getLang().createSection("effect"); + } + if (entityLang==null) + { + entityLang=plugin.getLang().createSection("entity"); + } for (EntityType i: EntityType.values()) { if (i.getName()==null) { continue; } - entityType.add(i.getName()); + if (entityLang.getString(i.getName(),"").isEmpty()) + { + entityLang.set(i.getName(),i.getName()); + } + entityType.add(entityLang.getString(i.getName(),i.getName())); + } + for (PotionEffectType i: PotionEffectType.values()) + { + if (effectLang.getString(i.getName().toLowerCase(),"").isEmpty()) + { + effectLang.set(i.getName().toLowerCase(),i.getName().toLowerCase()); + } + potionEffectType.add(effectLang.getString(i.getName().toLowerCase(),i.getName().toLowerCase())); } + effectEvents.put("非生物导致受伤给予自己",effectEventType.DamageToUs); + effectEvents.put("被击中给予自己",effectEventType.DamageByEntityToUs); + effectEvents.put("击中生物时给予自己",effectEventType.DamageEntityToUs); + effectEvents.put("击中生物时给予对方",effectEventType.DamageEntityToIt); + effectEvents.put("被生物击中给予对方",effectEventType.DamageByEntityToIt); } @Override @@ -54,150 +87,313 @@ public boolean onCommand(@NotNull CommandSender sender,@NotNull Command command, return false; } Player player=(Player) sender; - if ("watersponge".equals(args[0])) + switch (args[0]) { - int cnt=1; - if (args.length>1) + case "watersponge": { - try - { - cnt=Integer.parseInt(args[1]); - } - catch (NumberFormatException e) + int cnt=1; + if (args.length>1) { + try + { + cnt=Integer.parseInt(args[1]); + } + catch (NumberFormatException e) + { + } } + ItemStack itemStack=plugin.getBluestarGameManager().getSuperSpongeManager().getWaterSponge().getItem().clone(); + itemStack.setAmount(cnt); + player.getInventory().addItem(itemStack); + player.sendMessage(plugin.getMessageHead()+ChatColor.GREEN+"已为给予您 \"超级海绵\" ×"+cnt); + return true; } - ItemStack itemStack=plugin.getBluestarGameManager().getSuperSpongeManager().getWaterSponge().getItem().clone(); - itemStack.setAmount(cnt); - player.getInventory().addItem(itemStack); - player.sendMessage(plugin.getMessageHead()+ChatColor.GREEN+"已为给予您 \"超级海绵\" ×"+cnt); - return true; - } - if ("lavasponge".equals(args[0])) - { - int cnt=1; - if (args.length>1) + case "lavasponge": { - try - { - cnt=Integer.parseInt(args[1]); - } - catch (NumberFormatException e) + int cnt=1; + if (args.length>1) { + try + { + cnt=Integer.parseInt(args[1]); + } + catch (NumberFormatException e) + { + } } + ItemStack itemStack=plugin.getBluestarGameManager().getSuperSpongeManager().getlavaSponge().getItem().clone(); + itemStack.setAmount(cnt); + player.getInventory().addItem(itemStack); + player.sendMessage(plugin.getMessageHead()+ChatColor.GREEN+"已为给予您 \"岩浆海绵\" ×"+cnt); + return true; } - ItemStack itemStack=plugin.getBluestarGameManager().getSuperSpongeManager().getlavaSponge().getItem().clone(); - itemStack.setAmount(cnt); - player.getInventory().addItem(itemStack); - player.sendMessage(plugin.getMessageHead()+ChatColor.GREEN+"已为给予您 \"岩浆海绵\" ×"+cnt); - return true; - } - if ("usedwatersponge".equals(args[0])) - { - int cnt=1; - if (args.length>1) + case "usedwatersponge": { - try - { - cnt=Integer.parseInt(args[1]); - } - catch (NumberFormatException e) + int cnt=1; + if (args.length>1) { + try + { + cnt=Integer.parseInt(args[1]); + } + catch (NumberFormatException e) + { + } } + ItemStack itemStack=plugin.getBluestarGameManager().getSuperSpongeManager().getUsedWaterSponge().getItem().clone(); + itemStack.setAmount(cnt); + player.getInventory().addItem(setLore(itemStack)); + player.sendMessage(plugin.getMessageHead()+ChatColor.GREEN+"已为给予您 \"湿超级海绵\" ×"+cnt); + return true; } - ItemStack itemStack=plugin.getBluestarGameManager().getSuperSpongeManager().getUsedWaterSponge().getItem().clone(); - itemStack.setAmount(cnt); - player.getInventory().addItem(itemStack); - player.sendMessage(plugin.getMessageHead()+ChatColor.GREEN+"已为给予您 \"湿超级海绵\" ×"+cnt); - return true; - } - if ("usedlavasponge".equals(args[0])) - { - int cnt=1; - if (args.length>1) + case "usedlavasponge": { - try - { - cnt=Integer.parseInt(args[1]); - } - catch (NumberFormatException e) + int cnt=1; + if (args.length>1) { + try + { + cnt=Integer.parseInt(args[1]); + } + catch (NumberFormatException e) + { + } } + ItemStack itemStack=plugin.getBluestarGameManager().getSuperSpongeManager().getUsedLavaSponge().getItem().clone(); + itemStack.setAmount(cnt); + player.getInventory().addItem(itemStack); + player.sendMessage(plugin.getMessageHead()+ChatColor.GREEN+"已为给予您 \"湿岩浆海绵\" ×"+cnt); + return true; } - ItemStack itemStack=plugin.getBluestarGameManager().getSuperSpongeManager().getUsedLavaSponge().getItem().clone(); - itemStack.setAmount(cnt); - player.getInventory().addItem(itemStack); - player.sendMessage(plugin.getMessageHead()+ChatColor.GREEN+"已为给予您 \"湿岩浆海绵\" ×"+cnt); - return true; - } - if ("sword".equals(args[0])) - { - if (player.getInventory().getItemInMainHand().getType().isAir()) - { - player.sendMessage(plugin.getMessageHead()+ChatColor.RED+"请手持任意物品"); - return false; - } - NBTItem item=new NBTItem(player.getInventory().getItemInMainHand()); - item.addCompound("BluestarGame").setBoolean("sword",true); - player.getInventory().setItemInMainHand(item.getItem()); - player.sendMessage(plugin.getMessageHead()+ChatColor.GREEN+"已为您手持的物品添加\"op剑\"属性"); - return true; - } - if ("bow".equals(args[0])) - { - if (args.length<2) + case "sword": { - sender.sendMessage(plugin.getMessageHead()+ChatColor.RED+"请输入生物类型"); + if (player.getInventory().getItemInMainHand().getType().isAir()) + { + player.sendMessage(plugin.getMessageHead()+ChatColor.RED+"请手持任意物品"); + return false; + } + NBTItem item=new NBTItem(player.getInventory().getItemInMainHand()); + item.addCompound("BluestarGame").setBoolean("sword",true); + player.getInventory().setItemInMainHand(setLore(item.getItem())); + return true; } - int cnt=1; - double v=1; - if (args.length>=3) + case "bow": { - try + if (args.length<2) { - v=Double.parseDouble(args[2]); + sender.sendMessage(plugin.getMessageHead()+ChatColor.RED+"请输入生物类型"); } - catch (NumberFormatException e) + EntityType entityType=null; + for (String i: entityLang.getKeys(false)) { - sender.sendMessage(plugin.getErrorMessageHead()+"错误,力量不合法"); - return true; + if (args[1].equals(entityLang.getString(i))) + { + entityType=EntityType.fromName(i); + break; + } } - if (v<=0D) + if (entityType==null) { - sender.sendMessage(plugin.getErrorMessageHead()+"错误,力量不合法"); + sender.sendMessage(plugin.getErrorMessageHead()+"未知生物类型"); return true; } - if (args.length>=4) + int cnt=1; + double v=1; + if (args.length>=3) { try { - cnt=Integer.parseInt(args[3]); + v=Double.parseDouble(args[2]); } catch (NumberFormatException e) { - sender.sendMessage(plugin.getErrorMessageHead()+"错误,数量不合法"); + sender.sendMessage(plugin.getErrorMessageHead()+"错误,力量不合法"); return true; } - if (cnt<=0) + if (v<=0D) { - sender.sendMessage(plugin.getErrorMessageHead()+"错误,数量不合法"); + sender.sendMessage(plugin.getErrorMessageHead()+"错误,力量不合法"); return true; } + if (args.length>=4) + { + try + { + cnt=Integer.parseInt(args[3]); + } + catch (NumberFormatException e) + { + sender.sendMessage(plugin.getErrorMessageHead()+"错误,数量不合法"); + return true; + } + if (cnt<=0) + { + sender.sendMessage(plugin.getErrorMessageHead()+"错误,数量不合法"); + return true; + } + } + } + NBTItem bow=new NBTItem(new ItemStack(Material.BOW,cnt)); + NBTCompound bluestarGame=bow.addCompound("BluestarGame"); + bluestarGame.setString("arrow",entityType.getName()); + bluestarGame.setDouble("arrowSpeed",v); + player.getInventory().addItem(setLore(bow.getItem())); + return true; + } + case "effect": + { + if (args.length<2) + { + sender.sendMessage(plugin.getErrorMessageHead()+"错误,请输入效果"); + return true; + } + if (player.getInventory().getItemInMainHand().getType().isAir()) + { + sender.sendMessage(plugin.getErrorMessageHead()+"请先手持任意物品"); + return true; + } + PotionEffectType type=null; + for (String i: effectLang.getKeys(false)) + { + if (args[1].equals(effectLang.getString(i))) + { + type=PotionEffectType.getByName(i); + break; + } + } + if (type==null) + { + sender.sendMessage(plugin.getErrorMessageHead()+"错误,未知效果"); + return true; + } + int l; + try + { + l=Integer.parseInt(args[2]); + } + catch (Throwable e) + { + l=1; + } + NBTItem item=new NBTItem(player.getInventory().getItemInMainHand()); + if (l==0) + { + item.addCompound("BluestarGame").addCompound("effect").removeKey(type.getName()); + } + else + { + item.addCompound("BluestarGame").addCompound("effect").setInteger(type.getName(),l); + } + player.getInventory().setItemInMainHand(setLore(item.getItem())); + return true; + } + case "effectEvent": + { + if (args.length<2) + { + sender.sendMessage(plugin.getErrorMessageHead()+"错误,请输入效果"); + return true; + } + if (player.getInventory().getItemInMainHand().getType().isAir()) + { + sender.sendMessage(plugin.getErrorMessageHead()+"请先手持任意物品"); + return true; + } + PotionEffectType type=null; + for (String i: effectLang.getKeys(false)) + { + if (args[1].equals(effectLang.getString(i))) + { + type=PotionEffectType.getByName(i); + break; + } + } + if (type==null) + { + sender.sendMessage(plugin.getErrorMessageHead()+"错误,未知效果"); + return true; + } + int l; + try + { + l=Integer.parseInt(args[2]); + } + catch (Throwable e) + { + l=1; + } + effectEventType mod; + try + { + mod=effectEvents.get(args[3]); + } + catch (Throwable e) + { + mod=null; + } + if (mod==null) + { + sender.sendMessage(plugin.getErrorMessageHead()+"触发条件错误!"); + return true; + } + int time; + try + { + time=Integer.parseInt(args[4]); + if (time==0) + { + throw new NullPointerException(); + } + } + catch (Throwable e) + { + time=5; + } + NBTItem item=new NBTItem(player.getInventory().getItemInMainHand()); + if (l==0) + { + item.addCompound("BluestarGame").addCompound(mod.name()).removeKey(type.getName()); + } + else + { + NBTCompound nbtCompound=item.addCompound("BluestarGame").addCompound(mod.name()).addCompound(type.getName()); + nbtCompound.setInteger("s",l); + nbtCompound.setInteger("time",time*20); + } + player.getInventory().setItemInMainHand(setLore(item.getItem())); + return true; + } + case "setname": + { + ItemStack itemStack=player.getInventory().getItemInMainHand(); + if (itemStack==null||itemStack.getType().isAir()) + { + player.sendMessage(plugin.getErrorMessageHead()+"请手持任意物品"); + return true; + } + if (args.length<2) + { + player.sendMessage(plugin.getErrorMessageHead()+"请输入名字"); + return true; + } + StringBuilder builder=new StringBuilder(args[1]); + for (int i=2;i onTabComplete(@NotNull CommandSender sender,@NotNull Command { if (args.length==1) { - return Arrays.asList("watersponge","lavasponge","usedwatersponge","usedlavasponge","sword","bow"); + return Arrays.asList("watersponge","lavasponge","usedwatersponge","usedlavasponge","effect","effectEvent","sword","bow","setname"); } if ("bow".equals(args[0])) { @@ -224,10 +420,98 @@ public List onTabComplete(@NotNull CommandSender sender,@NotNull Command } return Collections.emptyList(); } + if (args[0].startsWith("effect")) + { + if (args.length==2) + { + return potionEffectType; + } + if (args.length==3) + { + return Collections.singletonList("等级"); + } + if (args.length==4&&"effectEvent".equals(args[0])) + { + return new ArrayList<>(effectEvents.keySet()); + } + if (args.length==5&&"effectEvent".equals(args[0])) + { + return Collections.singletonList("时间"); + } + return Collections.emptyList(); + } + if ("setname".equals(args[0])) + { + return Collections.singletonList("名字"); + } if (args.length==2) { return Collections.singletonList("数量"); } return Collections.emptyList(); } + + private ItemStack setLore(ItemStack itemStack) + { + NBTCompound bluestarGame=new NBTItem(itemStack).addCompound("BluestarGame"); + ItemMeta meta=itemStack.getItemMeta(); + List lore=new ArrayList<>(); + if (bluestarGame==null) + { + return itemStack; + } + String c=RGBChat.toColorCode("888888"); + if (bluestarGame.getCompound("effect")!=null) + { + lore.add(c+"<===--- "+RGBChat.toColorCode("abcdef")+"手持或佩戴时效果"+c+" ---===>"); + NBTCompound compound=bluestarGame.getCompound("effect"); + for (String i: compound.getKeys()) + { + lore.add(ChatColor.GRAY+effectLang.getString(i.toLowerCase(),i.toLowerCase())+" "+compound.getInteger(i)); + } + } + for (effectEventType i:effectEventType.values()) + { + if (bluestarGame.getCompound(i.name())!=null) + { + lore.add(c+"<===--- "+i.getName()+c+" ---===>"); + NBTCompound compound=bluestarGame.getCompound(i.name()); + for (String j: compound.getKeys()) + { + lore.add(ChatColor.GRAY+effectLang.getString(j.toLowerCase(),j.toLowerCase())+" "+compound.addCompound(j).getInteger("s")+" 时间: "+(compound.addCompound(j).getInteger("time")/20)); + } + } + } + if (bluestarGame.getString("arrow")!=null&&!bluestarGame.getString("arrow").isEmpty()) + { + lore.add(ChatColor.AQUA+"箭: "+entityLang.getString(bluestarGame.getString("arrow"))); + } + if (bluestarGame.getDouble("arrowSpeed")!=null&&bluestarGame.getInteger("arrowSpeed")!=0) + { + lore.add(ChatColor.LIGHT_PURPLE+"力量: "+bluestarGame.getDouble("arrowSpeed")); + } + if (bluestarGame.getInteger("waterSponge")==1) + { + lore.add(ChatColor.GOLD+"超级海绵"); + } + if (bluestarGame.getInteger("waterSponge")==-1) + { + lore.add(ChatColor.GOLD+"湿超级海绵"); + } + if (bluestarGame.getInteger("lavaSponge")==1) + { + lore.add(ChatColor.GOLD+"岩浆海绵"); + } + if (bluestarGame.getInteger("lavaSponge")==-1) + { + lore.add(ChatColor.GOLD+"湿岩浆海绵"); + } + if (bluestarGame.getBoolean("sword")) + { + lore.add(ChatColor.GOLD+"无敌OP剑"); + } + meta.setLore(lore); + itemStack.setItemMeta(meta); + return itemStack; + } } diff --git a/src/main/java/me/lanzhi/bluestargame/listener/ChatColorListener.java b/src/main/java/me/lanzhi/bluestargame/listener/ChatColorListener.java new file mode 100644 index 0000000..523c13f --- /dev/null +++ b/src/main/java/me/lanzhi/bluestargame/listener/ChatColorListener.java @@ -0,0 +1,33 @@ +package me.lanzhi.bluestargame.listener; + +import me.lanzhi.bluestarapi.Api.*; +import org.bukkit.ChatColor; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.Listener; +import org.bukkit.event.player.AsyncPlayerChatEvent; + +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +public final class ChatColorListener implements Listener +{ + private Pattern hex=Pattern.compile("#([0-9A-Fa-fK-Ok-oRr]{6})"); + @EventHandler(priority=EventPriority.LOWEST) + public void onPlyaerChat(AsyncPlayerChatEvent event) + { + if (event.isCancelled()) + { + return; + } + boolean canUseColor=event.getPlayer().hasPermission("bluestargame.color"); + if (canUseColor) + { + event.setMessage(RGBChat.setColor(event.getMessage())); + } + else + { + event.setMessage(ChatColor.stripColor(RGBChat.setColor(event.getMessage()))); + } + } +} diff --git a/src/main/java/me/lanzhi/bluestargame/listener/arrowListener.java b/src/main/java/me/lanzhi/bluestargame/listener/arrowListener.java index e8e6f97..c022d32 100644 --- a/src/main/java/me/lanzhi/bluestargame/listener/arrowListener.java +++ b/src/main/java/me/lanzhi/bluestargame/listener/arrowListener.java @@ -16,7 +16,7 @@ public static double decide(double x,double y,double z) x=Math.abs(x); y=Math.abs(y); z=Math.abs(z); - return Math.min(10D/x,Math.min(10D/y,10D/z)); + return Math.min(10D/x,Math.min(10D/y,10D/z))-0.01D; } @EventHandler @@ -34,7 +34,7 @@ public void entityArrow(EntityShootBowEvent event) } String arrow=bluestarGame.getString("arrow"); double v=bluestarGame.getDouble("arrowSpeed"); - v=(v!=0)?v:1; + v=(v>0)?v:1; if (arrow==null) { return; @@ -44,12 +44,12 @@ public void entityArrow(EntityShootBowEvent event) { return; } + Vector vector=event.getProjectile().getVelocity().clone(); if (EntityType.ARROW!=type) { Entity entity=event.getEntity().getWorld().spawnEntity(event.getProjectile().getLocation(),type,true); event.setProjectile(entity); } - Vector vector=event.getProjectile().getVelocity().clone(); double vv=Math.min(v,decide(vector.getX(),vector.getY(),vector.getZ())); vector.setX(vector.getX()*vv).setY(vector.getY()*vv).setZ(vector.getZ()*vv); event.getProjectile().setVelocity(vector); diff --git a/src/main/java/me/lanzhi/bluestargame/listener/effectListener.java b/src/main/java/me/lanzhi/bluestargame/listener/effectListener.java new file mode 100644 index 0000000..5dcf3c6 --- /dev/null +++ b/src/main/java/me/lanzhi/bluestargame/listener/effectListener.java @@ -0,0 +1,192 @@ +package me.lanzhi.bluestargame.listener; + +import de.tr7zw.nbtapi.NBTCompound; +import de.tr7zw.nbtapi.NBTEntity; +import de.tr7zw.nbtapi.NBTItem; +import me.lanzhi.bluestarapi.Api.RGBChat; +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.entity.Entity; +import org.bukkit.entity.LivingEntity; +import org.bukkit.entity.Player; +import org.bukkit.entity.Projectile; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.Listener; +import org.bukkit.event.entity.EntityDamageByEntityEvent; +import org.bukkit.event.entity.EntityDamageEvent; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.PlayerInventory; +import org.bukkit.potion.PotionEffect; +import org.bukkit.potion.PotionEffectType; + +import java.util.HashMap; +import java.util.Map; + +public final class effectListener implements Listener +{ + @EventHandler(priority=EventPriority.MONITOR) + public void onEntityDamagePlayer(EntityDamageByEntityEvent event) + { + if (event.isCancelled()||!(event.getEntity() instanceof Player)) + { + return; + } + PlayerInventory inventory=((Player) event.getEntity()).getInventory(); + setEffect(event.getEntity(),inventory.getItemInOffHand(),effectEventType.DamageByEntityToUs); + setEffect(event.getEntity(),inventory.getItemInMainHand(),effectEventType.DamageByEntityToUs); + setEffect(event.getEntity(),inventory.getBoots(),effectEventType.DamageByEntityToUs); + setEffect(event.getEntity(),inventory.getChestplate(),effectEventType.DamageByEntityToUs); + setEffect(event.getEntity(),inventory.getLeggings(),effectEventType.DamageByEntityToUs); + setEffect(event.getEntity(),inventory.getHelmet(),effectEventType.DamageByEntityToUs); + setEffect(event.getDamager(),inventory.getItemInOffHand(),effectEventType.DamageByEntityToIt); + setEffect(event.getDamager(),inventory.getItemInMainHand(),effectEventType.DamageByEntityToIt); + setEffect(event.getDamager(),inventory.getBoots(),effectEventType.DamageByEntityToIt); + setEffect(event.getDamager(),inventory.getChestplate(),effectEventType.DamageByEntityToIt); + setEffect(event.getDamager(),inventory.getLeggings(),effectEventType.DamageByEntityToIt); + setEffect(event.getDamager(),inventory.getHelmet(),effectEventType.DamageByEntityToIt); + } + + @EventHandler(priority=EventPriority.MONITOR) + public void onPlayerDamageEntity(EntityDamageByEntityEvent event) + { + if (event.isCancelled()||!(event.getDamager() instanceof Player)) + { + return; + } + PlayerInventory inventory=((Player) event.getDamager()).getInventory(); + + setEffect(event.getEntity(),inventory.getItemInOffHand(),effectEventType.DamageEntityToIt); + setEffect(event.getEntity(),inventory.getItemInMainHand(),effectEventType.DamageEntityToIt); + setEffect(event.getEntity(),inventory.getBoots(),effectEventType.DamageEntityToIt); + setEffect(event.getEntity(),inventory.getChestplate(),effectEventType.DamageEntityToIt); + setEffect(event.getEntity(),inventory.getLeggings(),effectEventType.DamageEntityToIt); + setEffect(event.getEntity(),inventory.getHelmet(),effectEventType.DamageEntityToIt); + setEffect(event.getDamager(),inventory.getItemInOffHand(),effectEventType.DamageEntityToUs); + setEffect(event.getDamager(),inventory.getItemInMainHand(),effectEventType.DamageEntityToUs); + setEffect(event.getDamager(),inventory.getBoots(),effectEventType.DamageEntityToUs); + setEffect(event.getDamager(),inventory.getChestplate(),effectEventType.DamageEntityToUs); + setEffect(event.getDamager(),inventory.getLeggings(),effectEventType.DamageEntityToUs); + setEffect(event.getDamager(),inventory.getHelmet(),effectEventType.DamageEntityToUs); + } + @EventHandler(priority=EventPriority.MONITOR) + public void onPlayerDamage(EntityDamageEvent event) + { + if (event.isCancelled()||!(event.getEntity() instanceof Player)||event instanceof EntityDamageByEntityEvent) + { + return; + } + + PlayerInventory inventory=((Player) event.getEntity()).getInventory(); + + setEffect(event.getEntity(),inventory.getItemInOffHand(),effectEventType.DamageToUs); + setEffect(event.getEntity(),inventory.getItemInMainHand(),effectEventType.DamageToUs); + setEffect(event.getEntity(),inventory.getBoots(),effectEventType.DamageToUs); + setEffect(event.getEntity(),inventory.getChestplate(),effectEventType.DamageToUs); + setEffect(event.getEntity(),inventory.getLeggings(),effectEventType.DamageToUs); + setEffect(event.getEntity(),inventory.getHelmet(),effectEventType.DamageToUs); + } + + private void setEffect(Entity entity,ItemStack itemStack,effectEventType type) + { + if (itemStack==null||itemStack.getType().isAir()) + { + return; + } + if (entity instanceof Projectile) + { + entity=Bukkit.getEntity(new NBTEntity(entity).getUUID("Owner")); + } + NBTCompound effect=new NBTItem(itemStack).addCompound("BluestarGame").addCompound(type.name()); + for (String i:effect.getKeys()) + { + ((LivingEntity)entity).addPotionEffect(new PotionEffect(PotionEffectType.getByName(i),effect.addCompound(i).getInteger("time"),effect.addCompound(i).getInteger("s"))); + } + } + + public enum effectEventType + { + /** + * 非生物导致受伤给予自己 + */ + DamageToUs(1), + /** + * 被击中给予自己 + */ + DamageByEntityToUs(2), + /** + * 击中生物时给予自己 + */ + DamageEntityToUs(3), + /** + * 击中生物时给予对方 + */ + DamageEntityToIt(4), + /** + * 被生物击中给予对方 + */ + DamageByEntityToIt(5); + private final int id; + + effectEventType(int id) + { + this.id=id; + } + + public int getId() + { + return id; + } + + public String getName() + { + switch (id) + { + case 1: + { + return RGBChat.toColorCode("123456")+"非生物导致受伤时"; + } + case 2: + { + return RGBChat.toColorCode("523456")+"被生物击中受伤时"; + } + case 3: + { + return RGBChat.toColorCode("12f456")+"使生物受到伤害时"; + } + case 4: + { + return RGBChat.toColorCode("12f4c6")+"击中生物时给予它"; + } + case 5: + { + return RGBChat.toColorCode("c234f6")+"被击中时给予生物"; + } + default: + { + return ""; + } + } + } + + public static effectEventType getById(int id) + { + return byId.get(id); + } + public static effectEventType getByName(String name) + { + return byName.get(name.toLowerCase()); + } + + private final static MapbyId=new HashMap<>(); + private final static MapbyName=new HashMap<>(); + static + { + for (effectEventType i:values()) + { + byId.put(i.id,i); + byName.put(i.name().toLowerCase(),i); + } + } + } +} diff --git a/src/main/java/me/lanzhi/bluestargame/listener/opSwordListener.java b/src/main/java/me/lanzhi/bluestargame/listener/opSwordListener.java index 86b6377..95c1e22 100644 --- a/src/main/java/me/lanzhi/bluestargame/listener/opSwordListener.java +++ b/src/main/java/me/lanzhi/bluestargame/listener/opSwordListener.java @@ -7,10 +7,7 @@ import org.bukkit.Bukkit; import org.bukkit.Material; import org.bukkit.attribute.Attribute; -import org.bukkit.entity.Arrow; -import org.bukkit.entity.Damageable; -import org.bukkit.entity.LivingEntity; -import org.bukkit.entity.Player; +import org.bukkit.entity.*; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; @@ -80,7 +77,7 @@ public void onPlayerDamage(EntityDamageEvent event) ((Damageable) event1.getDamager()).damage(Integer.MAX_VALUE,entity); return; } - if (event1.getDamager() instanceof Arrow) + if (event1.getDamager() instanceof Projectile) { ((Damageable) Bukkit.getEntity(new NBTEntity(event1.getDamager()).getUUID("Owner"))).damage(Integer.MAX_VALUE,entity); return; diff --git a/src/main/java/me/lanzhi/bluestargame/listener/randoms/randChatColorListener.java b/src/main/java/me/lanzhi/bluestargame/listener/randoms/randChatColorListener.java index 9176bf9..1061135 100644 --- a/src/main/java/me/lanzhi/bluestargame/listener/randoms/randChatColorListener.java +++ b/src/main/java/me/lanzhi/bluestargame/listener/randoms/randChatColorListener.java @@ -1,6 +1,8 @@ package me.lanzhi.bluestargame.listener.randoms; +import me.lanzhi.bluestarapi.Api.RGBChat; import me.lanzhi.bluestargame.BluestarGamePlugin; +import me.lanzhi.bluestargame.listener.ChatColorListener; import me.lanzhi.bluestargame.managers.RandomEventManger; import org.bukkit.ChatColor; import org.bukkit.event.EventHandler; @@ -8,6 +10,8 @@ import org.bukkit.event.Listener; import org.bukkit.event.player.AsyncPlayerChatEvent; +import java.util.concurrent.ThreadLocalRandom; + public final class randChatColorListener implements Listener { private RandomEventManger randomEventManger; @@ -26,8 +30,6 @@ public void onChatForRand(AsyncPlayerChatEvent event) { return; } - String[] chatColor={ChatColor.GREEN.toString(),ChatColor.YELLOW.toString(),ChatColor.RED.toString(),ChatColor.GOLD.toString(),ChatColor.AQUA.toString(),ChatColor.BLACK.toString(),ChatColor.BLUE.toString(),ChatColor.DARK_GRAY.toString(),ChatColor.DARK_PURPLE.toString(),ChatColor.DARK_AQUA.toString(),ChatColor.DARK_BLUE.toString(),ChatColor.DARK_GREEN.toString(),ChatColor.DARK_RED.toString(),ChatColor.GRAY.toString(),ChatColor.LIGHT_PURPLE.toString(),ChatColor.WHITE.toString()}; - int i=(int) (Math.random()*17.0D); - event.setMessage(chatColor[i]+message); + event.setMessage(new RGBChat(Math.abs(ThreadLocalRandom.current().nextInt()%0xffffff))+message); } } diff --git a/src/main/java/me/lanzhi/bluestargame/managers/BluestarGameManager.java b/src/main/java/me/lanzhi/bluestargame/managers/BluestarGameManager.java index 81127a8..0aed894 100644 --- a/src/main/java/me/lanzhi/bluestargame/managers/BluestarGameManager.java +++ b/src/main/java/me/lanzhi/bluestargame/managers/BluestarGameManager.java @@ -1,11 +1,21 @@ package me.lanzhi.bluestargame.managers; +import de.tr7zw.nbtapi.NBTCompound; +import de.tr7zw.nbtapi.NBTItem; import me.lanzhi.bluestargame.BluestarGamePlugin; import me.lanzhi.bluestargame.Type.Elevator; import me.lanzhi.bluestargame.api.BluestarGameApi; import me.lanzhi.bluestargameapi.managers.BluestarGameManagerInterface; +import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.configuration.ConfigurationSection; +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.PlayerInventory; +import org.bukkit.potion.PotionEffect; +import org.bukkit.potion.PotionEffectType; +import org.bukkit.scheduler.BukkitRunnable; +import org.bukkit.scheduler.BukkitTask; import org.jetbrains.annotations.Nullable; import java.util.Set; @@ -18,6 +28,7 @@ public final class BluestarGameManager implements BluestarGameManagerInterface private final BluestarGameApi api; private final RandomEventManger randomEventManger; private final SuperSpongeManager superSpongeManager; + private final BukkitTask effectTask; public BluestarGameManager(BluestarGamePlugin plugin) { @@ -29,6 +40,7 @@ public BluestarGameManager(BluestarGamePlugin plugin) this.api=new BluestarGameApi(plugin); this.randomEventManger=new RandomEventManger(plugin); this.superSpongeManager=new SuperSpongeManager(plugin); + this.effectTask=new Effect().runTaskTimer(plugin,0,95); } @Override @@ -85,4 +97,41 @@ public BluestarGamePlugin getPlugin() { return plugin; } + + public static class Effect extends BukkitRunnable + { + private static void set(Player player,ItemStack itemStack) + { + if (itemStack==null||itemStack.getType().isAir()) + { + return; + } + NBTItem item=new NBTItem(itemStack); + NBTCompound compound=item.addCompound("BluestarGame").addCompound("effect"); + for (String i:compound.getKeys()) + { + PotionEffectType type=PotionEffectType.getByName(i); + if (type==null) + { + continue; + } + player.addPotionEffect(new PotionEffect(type,type.getId()==16?300:100,compound.getInteger(i)-1)); + } + } + + @Override + public void run() + { + for (Player player: Bukkit.getOnlinePlayers()) + { + PlayerInventory inventory=player.getInventory(); + set(player,inventory.getItemInMainHand()); + set(player,inventory.getItemInOffHand()); + for (ItemStack itemStack:inventory.getArmorContents()) + { + set(player,itemStack); + } + } + } + } } diff --git a/src/main/java/me/lanzhi/bluestargame/managers/RandomEventsChange.java b/src/main/java/me/lanzhi/bluestargame/managers/RandomEventsChange.java index b7a2352..838509a 100644 --- a/src/main/java/me/lanzhi/bluestargame/managers/RandomEventsChange.java +++ b/src/main/java/me/lanzhi/bluestargame/managers/RandomEventsChange.java @@ -31,7 +31,7 @@ public void run() } if (on==0) { - on=((int) (Math.random()*13)+1); + on=((int) (Math.random()*12)+1); if (Bukkit.getServer().getOnlinePlayers().size()<=0&&on!=4) { randomEventManger.randomEvents=new RandomEventsChange(plugin,on); @@ -123,11 +123,6 @@ public synchronized void change(boolean b) randomEventManger.respawn(b); return; } - case 13: - { - randomEventManger.oneHealth(b); - return; - } default:{ } diff --git a/src/main/java/me/lanzhi/bluestargame/register/ListenersRegister.java b/src/main/java/me/lanzhi/bluestargame/register/ListenersRegister.java index 9121e91..a8eb487 100644 --- a/src/main/java/me/lanzhi/bluestargame/register/ListenersRegister.java +++ b/src/main/java/me/lanzhi/bluestargame/register/ListenersRegister.java @@ -26,7 +26,9 @@ public void registerListeners() registerlistener(new opSwordListener(plugin)); registerlistener(new arrowListener()); registerlistener(new breakBedrockListener()); - registerlistener(new oneHealthListener(plugin)); + registerlistener(new elevatorListener(plugin)); + registerlistener(new effectListener()); + registerlistener(new ChatColorListener()); registerlistener(new moreMineralListener(plugin)); registerlistener(new randChatColorListener(plugin)); @@ -34,7 +36,7 @@ public void registerListeners() registerlistener(new randSheepColorListener(plugin)); registerlistener(new respawnListener(plugin)); registerlistener(new the24PointListener(plugin)); - registerlistener(new elevatorListener(plugin)); + registerlistener(new oneHealthListener(plugin)); } private void registerlistener(Listener listener) diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index a5a1ab4..0c6794e 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -55,6 +55,9 @@ permissions: bluestargame.lanzhi: description: 腐竹专属,用于腐竹自己调试插件,默认false default: false + bluestargame.color: + description: 使用颜色代码 + default: op depend: - BluestarAPI - NBTAPI