diff --git a/pom.xml b/pom.xml index 983d101..6ae5494 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ me.lanzhi BluestarGame - 3.0.1 + 3.1.0 jar BluestarGame @@ -92,7 +92,7 @@ com.github.lanzhi6 BluestarAPI - 2.0.0 + 2.0.1 provided @@ -104,7 +104,7 @@ com.github.lanzhi6 BluestarGameAPI - 1.1.0 + 3.1 provided diff --git a/src/main/java/me/lanzhi/bluestargame/BluestarGamePlugin.java b/src/main/java/me/lanzhi/bluestargame/BluestarGamePlugin.java index 87298ca..91be635 100644 --- a/src/main/java/me/lanzhi/bluestargame/BluestarGamePlugin.java +++ b/src/main/java/me/lanzhi/bluestargame/BluestarGamePlugin.java @@ -5,8 +5,8 @@ import me.lanzhi.bluestargame.Type.CompressedCoal; import me.lanzhi.bluestargame.Type.Elevator; import me.lanzhi.bluestargame.Type.SuperSponge; -import me.lanzhi.bluestargame.managers.BluestarGameManager; import me.lanzhi.bluestargame.listener.breakBedrockListener; +import me.lanzhi.bluestargame.managers.BluestarGameManager; import me.lanzhi.bluestargame.register.CommandRegister; import me.lanzhi.bluestargame.register.ListenersRegister; import me.lanzhi.bluestargame.register.RecipeRegister; @@ -31,11 +31,11 @@ public final class BluestarGamePlugin extends JavaPlugin implements BluestarGame private final File PlayerData; private final YamlFile PlayerMap; private final YamlFile Data; - private Economy econ; private final String messageHead=ChatColor.GOLD+"["+ChatColor.DARK_AQUA+"BluestarGame"+ChatColor.GOLD+"]"; private final String errorMessageHead=messageHead+ChatColor.RED; private final SimpleDateFormat BluestarDateFormat; private final NumberFormat BluestarNF; + private Economy econ; private BluestarGameManager bluestarGameManager; private CommandRegister commandRegister; private ListenersRegister listenersRegister; @@ -150,11 +150,13 @@ public YamlFile getConfig() { return config; } + @Override public void reloadConfig() { config.reload(); } + @Override public void saveConfig() { diff --git a/src/main/java/me/lanzhi/bluestargame/commands/BluestarGameCommand.java b/src/main/java/me/lanzhi/bluestargame/commands/BluestarGameCommand.java index c880237..a4636bd 100644 --- a/src/main/java/me/lanzhi/bluestargame/commands/BluestarGameCommand.java +++ b/src/main/java/me/lanzhi/bluestargame/commands/BluestarGameCommand.java @@ -98,6 +98,20 @@ else if (args.length==2&&sender instanceof Player) sender.sendMessage(plugin.getMessageHead()+ChatColor.RED+"格式错误!"); return false; } + if (args[0].equals("onehealth")) + { + if (args[1].equals("true")) + { + randomEventManger.oneHealth(true); + sender.sendMessage(plugin.getMessageHead()+ChatColor.GREEN+"已设置为true"); + } + else + { + randomEventManger.oneHealth(false); + sender.sendMessage(plugin.getMessageHead()+ChatColor.GREEN+"已设置为false"); + } + return true; + } if (args[0].equals("randdamage")) { if (args[1].equals("true")) @@ -402,6 +416,7 @@ public List onTabComplete(CommandSender sender,Command command,String al tablist.add("auto"); tablist.add("spongeR"); tablist.add("boom"); + tablist.add("onehealth"); if (sender.hasPermission("bluestargame.lanzhi")) { tablist.add("newsponge"); diff --git a/src/main/java/me/lanzhi/bluestargame/commands/BluestarItemCommand.java b/src/main/java/me/lanzhi/bluestargame/commands/BluestarItemCommand.java index abcf9d0..97f5881 100644 --- a/src/main/java/me/lanzhi/bluestargame/commands/BluestarItemCommand.java +++ b/src/main/java/me/lanzhi/bluestargame/commands/BluestarItemCommand.java @@ -23,32 +23,21 @@ public final class BluestarItemCommand implements CommandExecutor, TabExecutor { - private static List entityType=new ArrayList<>(); - - static - { - try - { - for (EntityType i: EntityType.values()) - { - if (i.getName()==null) - { - continue; - } - entityType.add(i.getName()); - } - } - catch (Throwable e) - { - System.out.println("错误在初始化"); - } - } + private final List entityType=new ArrayList<>(); private final BluestarGamePlugin plugin; public BluestarItemCommand(BluestarGamePlugin plugin) { this.plugin=plugin; + for (EntityType i: EntityType.values()) + { + if (i.getName()==null) + { + continue; + } + entityType.add(i.getName()); + } } @Override diff --git a/src/main/java/me/lanzhi/bluestargame/listener/HealthFixListener.java b/src/main/java/me/lanzhi/bluestargame/listener/HealthFixListener.java index edbbddd..a1e2f41 100644 --- a/src/main/java/me/lanzhi/bluestargame/listener/HealthFixListener.java +++ b/src/main/java/me/lanzhi/bluestargame/listener/HealthFixListener.java @@ -8,6 +8,7 @@ import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; +import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.event.player.PlayerLoginEvent; import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.scheduler.BukkitRunnable; @@ -17,43 +18,37 @@ public final class HealthFixListener implements Listener { private final BluestarGamePlugin plugin; - private final RandomEventManger randomEventManger; public HealthFixListener(BluestarGamePlugin plugin) { this.plugin=plugin; - randomEventManger=plugin.getBluestarGameManager().getRandomEventManger(); } - @EventHandler(priority=EventPriority.HIGHEST) - public void onPlayerJoin(PlayerLoginEvent event) + @EventHandler(priority=EventPriority.MONITOR) + public void onPlayerJoin(PlayerJoinEvent event) { Player player=event.getPlayer(); player.setHealthScaled(false); - YamlFile playerdata=new YamlFile(new File(plugin.getPlayerData(),player.getUniqueId()+".yml")); - if (playerdata.getDouble("maxhealth")!=0) + YamlFile playerData=YamlFile.loadYamlFile(new File(plugin.getPlayerData(),event.getPlayer().getUniqueId()+".yml")); + double health=playerData.getDouble("health"); + double maxHealth=playerData.getDouble("maxhealth"); + if (maxHealth!=0) { - player.getAttribute(Attribute.GENERIC_MAX_HEALTH).setBaseValue(playerdata.getDouble("maxhealth")); + player.getAttribute(Attribute.GENERIC_MAX_HEALTH).setBaseValue(maxHealth); } - if (playerdata.getDouble("health")!=0) + if (health!=0) { - player.setHealth(playerdata.getDouble("health")); + player.setHealth(health); } new BukkitRunnable() { @Override public void run() { - Player player=event.getPlayer(); player.setHealthScaled(false); - YamlFile playerdata=new YamlFile(new File(plugin.getPlayerData(),player.getUniqueId()+".yml")); - if (playerdata.getDouble("maxhealth")!=0) - { - player.getAttribute(Attribute.GENERIC_MAX_HEALTH).setBaseValue(playerdata.getDouble("maxhealth")); - } - if (playerdata.getDouble("health")!=0) + if (maxHealth!=0) { - player.setHealth(playerdata.getDouble("health")); + player.getAttribute(Attribute.GENERIC_MAX_HEALTH).setBaseValue(maxHealth); } } }.runTaskLater(plugin,70); @@ -62,8 +57,12 @@ public void run() @EventHandler(priority=EventPriority.HIGHEST) public void onPlayerQuit(PlayerQuitEvent event) { - YamlFile playerData=new YamlFile(new File(plugin.getPlayerData(),event.getPlayer().getUniqueId()+".yml")); + YamlFile playerData=YamlFile.loadYamlFile(new File(plugin.getPlayerData(),event.getPlayer().getUniqueId()+".yml")); double maxhealth=event.getPlayer().getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue(); + if (plugin.getBluestarGameManager().getRandomEventManger().oneHealth()) + { + maxhealth=plugin.getBluestarGameManager().getRandomEventManger().oneHealth_playerHealth.get(event.getPlayer()); + } playerData.set("health",Math.min(event.getPlayer().getHealth(),maxhealth)); playerData.set("maxhealth",maxhealth); playerData.save(); diff --git a/src/main/java/me/lanzhi/bluestargame/listener/elevatorListener.java b/src/main/java/me/lanzhi/bluestargame/listener/elevatorListener.java index 85f76ac..296f247 100644 --- a/src/main/java/me/lanzhi/bluestargame/listener/elevatorListener.java +++ b/src/main/java/me/lanzhi/bluestargame/listener/elevatorListener.java @@ -7,11 +7,14 @@ import org.bukkit.ChatColor; import org.bukkit.Location; import org.bukkit.Sound; +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.PlayerMoveEvent; +import org.bukkit.event.player.PlayerTeleportEvent; import org.bukkit.event.player.PlayerToggleSneakEvent; +import org.bukkit.scheduler.BukkitRunnable; public final class elevatorListener implements Listener { @@ -30,24 +33,28 @@ public void onPlayerMove(PlayerMoveEvent event) return; } Location loc=event.getPlayer().getLocation(); - Elevator ele=plugin.getBluestarGameManager().getElevator(loc); - if (ele!=null) + Player player=event.getPlayer(); + new BukkitRunnable() { - for (long y=loc.getBlockY()+1;y<=ele.getMaxY();y++) + @Override + public void run() { - Location locc=loc.clone(); - locc.setY(y); - Location loccc=loc.clone(); - loccc.setY(y-1); - if ((!locc.getBlock().getType().isSolid()||locc.getBlock().getType().name().endsWith("SIGN"))&&(loccc.getBlock().getType().isSolid()&&!loccc.getBlock().getType().name().endsWith("SIGN"))) + Location to=getTeleportLocation(loc,1); + if (to!=null) { - event.getPlayer().teleport(locc); - event.getPlayer().spigot().sendMessage(ChatMessageType.ACTION_BAR,new TextComponent(ChatColor.GREEN+"UP UPP UPPP!")); - event.getPlayer().playSound(event.getPlayer().getLocation(),Sound.ENTITY_PLAYER_LEVELUP,1,1); - return; + new BukkitRunnable() + { + @Override + public void run() + { + player.teleport(to,PlayerTeleportEvent.TeleportCause.CHORUS_FRUIT); + event.getPlayer().spigot().sendMessage(ChatMessageType.ACTION_BAR,new TextComponent(ChatColor.GREEN+"UP UPP UPPP!")); + event.getPlayer().playSound(event.getPlayer().getLocation(),Sound.ENTITY_PLAYER_LEVELUP,1,1); + } + }.runTask(plugin); } } - } + }.runTaskAsynchronously(plugin); } @EventHandler(priority=EventPriority.MONITOR) @@ -58,10 +65,36 @@ public void onPlayerSneak(PlayerToggleSneakEvent event) return; } Location loc=event.getPlayer().getLocation(); + Player player=event.getPlayer(); + new BukkitRunnable() + { + @Override + public void run() + { + Location to=getTeleportLocation(loc,-1); + if (to!=null) + { + new BukkitRunnable() + { + @Override + public void run() + { + player.teleport(to,PlayerTeleportEvent.TeleportCause.CHORUS_FRUIT); + event.getPlayer().spigot().sendMessage(ChatMessageType.ACTION_BAR,new TextComponent(ChatColor.GREEN+"DOWN DOWWN DOWWWN!")); + event.getPlayer().playSound(event.getPlayer().getLocation(),Sound.ENTITY_PLAYER_LEVELUP,1,1); + } + }.runTask(plugin); + } + } + }.runTaskAsynchronously(plugin); + } + + private Location getTeleportLocation(Location loc,long cnt) + { Elevator ele=plugin.getBluestarGameManager().getElevator(loc); if (ele!=null) { - for (long y=loc.getBlockY()-1;y>=ele.getMinY();y--) + for (long y=loc.getBlockY()+cnt;y<=ele.getMaxY()&&y>=ele.getMinY();y+=cnt) { Location locc=loc.clone(); locc.setY(y); @@ -69,13 +102,10 @@ public void onPlayerSneak(PlayerToggleSneakEvent event) loccc.setY(y-1); if ((!locc.getBlock().getType().isSolid()||locc.getBlock().getType().name().endsWith("SIGN"))&&(loccc.getBlock().getType().isSolid()&&!loccc.getBlock().getType().name().endsWith("SIGN"))) { - event.getPlayer().teleport(locc); - event.getPlayer().spigot().sendMessage(ChatMessageType.ACTION_BAR,new TextComponent(ChatColor.GREEN+"DOWN DOWWN DOWWWN!")); - event.getPlayer().playSound(event.getPlayer().getLocation(),Sound.ENTITY_PLAYER_LEVELUP,1,1); - return; + return locc; } } } + return null; } - } diff --git a/src/main/java/me/lanzhi/bluestargame/listener/randoms/oneHealthListener.java b/src/main/java/me/lanzhi/bluestargame/listener/randoms/oneHealthListener.java new file mode 100644 index 0000000..531bf57 --- /dev/null +++ b/src/main/java/me/lanzhi/bluestargame/listener/randoms/oneHealthListener.java @@ -0,0 +1,41 @@ +package me.lanzhi.bluestargame.listener.randoms; + +import me.lanzhi.bluestarapi.Api.config.YamlFile; +import me.lanzhi.bluestargame.BluestarGamePlugin; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.player.PlayerJoinEvent; +import org.bukkit.event.player.PlayerQuitEvent; + +import java.io.File; + +public final class oneHealthListener implements Listener +{ + private final BluestarGamePlugin plugin; + + public oneHealthListener(BluestarGamePlugin plugin) + { + this.plugin=plugin; + } + + @EventHandler + public void onPlayerJoin(PlayerJoinEvent event) + { + if (!plugin.getBluestarGameManager().getRandomEventManger().oneHealth()) + { + return; + } + double maxHealth=YamlFile.loadYamlFile(new File(plugin.getPlayerData(),event.getPlayer().getUniqueId()+".yml")).getDouble("maxhealth"); + plugin.getBluestarGameManager().getRandomEventManger().oneHealth_playerHealth.put(event.getPlayer(),maxHealth!=0?maxHealth:20); + } + + @EventHandler + public void onPlayerQuit(PlayerQuitEvent event) + { + if (!plugin.getBluestarGameManager().getRandomEventManger().oneHealth()) + { + return; + } + plugin.getBluestarGameManager().getRandomEventManger().oneHealth_playerHealth.remove(event.getPlayer()); + } +} diff --git a/src/main/java/me/lanzhi/bluestargame/managers/RandomEventManger.java b/src/main/java/me/lanzhi/bluestargame/managers/RandomEventManger.java index b2cc54e..bd4851b 100644 --- a/src/main/java/me/lanzhi/bluestargame/managers/RandomEventManger.java +++ b/src/main/java/me/lanzhi/bluestargame/managers/RandomEventManger.java @@ -4,15 +4,22 @@ import me.lanzhi.bluestargameapi.managers.RandomEventMangerInterface; import org.bukkit.Bukkit; import org.bukkit.ChatColor; +import org.bukkit.attribute.Attribute; +import org.bukkit.entity.Player; +import org.bukkit.scheduler.BukkitRunnable; import org.bukkit.scheduler.BukkitTask; import java.util.Arrays; +import java.util.HashMap; +import java.util.Map; public final class RandomEventManger implements RandomEventMangerInterface { private final BluestarGamePlugin plugin; public int[] fourNum=new int[4]; - public BukkitTask task=null; + public BukkitTask randomEventChangeTask=null; + public BukkitTask oneHealthTask=null; + public HashMap oneHealth_playerHealth=new HashMap<>(); public RandomEventsChange randomEvents; public RandomEventManger(BluestarGamePlugin plugin) @@ -35,25 +42,25 @@ public synchronized void runAuto(boolean b) Bukkit.getServer().broadcastMessage(plugin.getMessageHead()+"随机事件自动切换已启用!"); } } - if ((b)&&(task==null)) + if ((b)&&(randomEventChangeTask==null)) { randomEvents=new RandomEventsChange(plugin,0); - task=randomEvents.runTaskAsynchronously(plugin); + randomEventChangeTask=randomEvents.runTaskAsynchronously(plugin); } - else if ((!b)&&(task!=null)) + else if ((!b)&&(randomEventChangeTask!=null)) { - task.cancel(); + randomEventChangeTask.cancel(); randomEvents.stop(); - task=null; + randomEventChangeTask=null; } } @Override public void end() { - if (task!=null) + if (randomEventChangeTask!=null) { - task.cancel(); + randomEventChangeTask.cancel(); } } @@ -73,6 +80,7 @@ public void all(boolean b) moreemerald(b); moreredstone(b); respawn(b); + oneHealth(b); } @Override @@ -414,6 +422,53 @@ public void respawn(boolean b) } } + @Override + public boolean oneHealth() + { + return plugin.getData().getBoolean("oneHealth"); + } + + @Override + public void oneHealth(boolean b) + { + if (b==oneHealth()) + { + return; + } + plugin.getData().set("oneHealth",b); + if (b) + { + for (Player player:Bukkit.getOnlinePlayers()) + { + oneHealth_playerHealth.put(player,player.getAttribute(Attribute.GENERIC_MAX_HEALTH).getBaseValue()); + player.getAttribute(Attribute.GENERIC_MAX_HEALTH).setBaseValue(1); + player.setHealth(Math.min(player.getHealth(),1D)); + oneHealthTask=new BukkitRunnable() + { + @Override + public void run() + { + for (Player player:oneHealth_playerHealth.keySet()) + { + player.getAttribute(Attribute.GENERIC_MAX_HEALTH).setBaseValue(1); + } + } + }.runTaskTimer(plugin,0,1); + } + Bukkit.broadcastMessage(plugin.getMessageHead()+"一滴血生存已启用!"); + } + else + { + oneHealthTask.cancel(); + for (Map.Entry i:oneHealth_playerHealth.entrySet()) + { + i.getKey().getAttribute(Attribute.GENERIC_MAX_HEALTH).setBaseValue(i.getValue()); + } + oneHealth_playerHealth=new HashMap<>(); + Bukkit.broadcastMessage(plugin.getMessageHead()+"一滴血生存已禁用!"); + } + } + public static class mathFor24Points { diff --git a/src/main/java/me/lanzhi/bluestargame/managers/RandomEventsChange.java b/src/main/java/me/lanzhi/bluestargame/managers/RandomEventsChange.java index 0700ce7..b7a2352 100644 --- a/src/main/java/me/lanzhi/bluestargame/managers/RandomEventsChange.java +++ b/src/main/java/me/lanzhi/bluestargame/managers/RandomEventsChange.java @@ -31,23 +31,23 @@ public void run() } if (on==0) { - on=((int) (Math.random()*12)+1); + on=((int) (Math.random()*13)+1); if (Bukkit.getServer().getOnlinePlayers().size()<=0&&on!=4) { randomEventManger.randomEvents=new RandomEventsChange(plugin,on); - randomEventManger.task=randomEventManger.randomEvents.runTaskLaterAsynchronously(plugin,12000); + randomEventManger.randomEventChangeTask=randomEventManger.randomEvents.runTaskLaterAsynchronously(plugin,12000); return; } this.change(true); randomEventManger.randomEvents=new RandomEventsChange(plugin,on); - randomEventManger.task=randomEventManger.randomEvents.runTaskLaterAsynchronously(plugin,12000); + randomEventManger.randomEventChangeTask=randomEventManger.randomEvents.runTaskLaterAsynchronously(plugin,12000); } else { this.change(false); on=0; randomEventManger.randomEvents=new RandomEventsChange(plugin,on); - randomEventManger.task=randomEventManger.randomEvents.runTaskLaterAsynchronously(plugin,24000); + randomEventManger.randomEventChangeTask=randomEventManger.randomEvents.runTaskLaterAsynchronously(plugin,24000); } } @@ -61,53 +61,76 @@ public void stop() public synchronized void change(boolean b) { - if (on==1) + switch (on) { - randomEventManger.randdamage(b); - } - else if (on==2) - { - randomEventManger.randchat(b); - } - else if (on==3) - { - randomEventManger.randsheep(b); - } - else if (on==4) - { - randomEventManger.the24(b); - } - else if (on==5) - { - randomEventManger.morediamond(b); - } - else if (on==6) - { - randomEventManger.morecoal(b); - } - else if (on==7) - { - randomEventManger.morecopper(b); - } - else if (on==8) - { - randomEventManger.moregold(b); - } - else if (on==9) - { - randomEventManger.moreemerald(b); - } - else if (on==10) - { - randomEventManger.morelapis(b); - } - else if (on==11) - { - randomEventManger.moreiron(b); - } - else if (on==12) - { - randomEventManger.respawn(b); + case 1: + { + randomEventManger.randdamage(b); + return; + } + case 2: + { + randomEventManger.randchat(b); + return; + } + case 3: + { + randomEventManger.randsheep(b); + return; + } + case 4: + { + randomEventManger.the24(b); + return; + } + case 5: + { + randomEventManger.morediamond(b); + return; + } + case 6: + { + randomEventManger.morecoal(b); + return; + } + case 7: + { + randomEventManger.morecopper(b); + return; + } + case 8: + { + randomEventManger.moregold(b); + return; + } + case 9: + { + randomEventManger.moreemerald(b); + return; + } + case 10: + { + randomEventManger.morelapis(b); + return; + } + case 11: + { + randomEventManger.moreiron(b); + return; + } + case 12: + { + 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 4a9a07b..9121e91 100644 --- a/src/main/java/me/lanzhi/bluestargame/register/ListenersRegister.java +++ b/src/main/java/me/lanzhi/bluestargame/register/ListenersRegister.java @@ -26,6 +26,7 @@ public void registerListeners() registerlistener(new opSwordListener(plugin)); registerlistener(new arrowListener()); registerlistener(new breakBedrockListener()); + registerlistener(new oneHealthListener(plugin)); registerlistener(new moreMineralListener(plugin)); registerlistener(new randChatColorListener(plugin)); diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 1fa6152..a5a1ab4 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -37,6 +37,8 @@ commands: xiaomobank: aliases: - xmbank + shape: + permission: bluestargame.use cmdbag: aliases: - commandbag