diff --git a/src/config.yml b/src/config.yml index 89c30fd..2a0a4e4 100644 --- a/src/config.yml +++ b/src/config.yml @@ -1,7 +1,7 @@ WaitingTime: 600 ItemTime: 300 ShieldFlyTime: 100 -EndTime: 100 +EndTime: 600 Arena: MinX: 0 diff --git a/src/de/steamwar/misslewars/Config.java b/src/de/steamwar/misslewars/Config.java index 278b07a..160562a 100644 --- a/src/de/steamwar/misslewars/Config.java +++ b/src/de/steamwar/misslewars/Config.java @@ -51,11 +51,11 @@ public class Config { ConfigurationSection red = config.getConfigurationSection("Red"); assert red != null; RedPortalZ = red.getInt("PortalZ"); - RedSpawn = new Location(Bukkit.getWorlds().get(0), red.getDouble("SpawnX"), red.getDouble("SpawnY"), red.getDouble("SpawnZ")); + RedSpawn = new Location(Bukkit.getWorlds().get(0), red.getDouble("SpawnX"), red.getDouble("SpawnY"), red.getDouble("SpawnZ"), (float)red.getDouble("SpawnYaw"), (float)red.getDouble("SpawnPitch")); ConfigurationSection blue = config.getConfigurationSection("Blue"); assert blue != null; BluePortalZ = blue.getInt("PortalZ"); - BlueSpawn = new Location(Bukkit.getWorlds().get(0), blue.getDouble("SpawnX"), blue.getDouble("SpawnY"), blue.getDouble("SpawnZ")); + BlueSpawn = new Location(Bukkit.getWorlds().get(0), blue.getDouble("SpawnX"), blue.getDouble("SpawnY"), blue.getDouble("SpawnZ"), (float)blue.getDouble("SpawnYaw"), (float)blue.getDouble("SpawnPitch")); } } diff --git a/src/de/steamwar/misslewars/FightScoreboard.java b/src/de/steamwar/misslewars/FightScoreboard.java index dcd7fd6..6421de6 100644 --- a/src/de/steamwar/misslewars/FightScoreboard.java +++ b/src/de/steamwar/misslewars/FightScoreboard.java @@ -32,16 +32,14 @@ public class FightScoreboard { objective.setDisplaySlot(DisplaySlot.SIDEBAR); MWTeam fightTeam = getIndexDisplay(); - if(fightTeam != null) - teamScoreboard(fightTeam); - else - generalScoreboard(); + teamScoreboard(fightTeam); + Bukkit.getOnlinePlayers().forEach(player -> player.setScoreboard(scoreboard)); }, 0, 200); } - public static Scoreboard getScoreboard() { + static Scoreboard getScoreboard() { return scoreboard; } @@ -52,23 +50,14 @@ public class FightScoreboard { }); } - private static void generalScoreboard(){ - objective.setDisplayName("§6Kampf"); - int fightTime = MissileWars.getFightTime(); - if (fightTime >= 60) - objective.getScore("§7Zeit: §a" + fightTime / 60 + "m " + fightTime % 60 + "s").setScore(3); - else - objective.getScore("§7Zeit: §a" + fightTime + "s").setScore(3); - } - private static MWTeam getIndexDisplay() { - index++; - if(index == 1) + if(index == 0) { + index = 1; return MissileWars.getRedTeam(); - if(index == 2) + }else{ + index = 0; return MissileWars.getBlueTeam(); - index = 0; - return null; + } } } diff --git a/src/de/steamwar/misslewars/MWTeam.java b/src/de/steamwar/misslewars/MWTeam.java index 4cfb1d3..4782f25 100644 --- a/src/de/steamwar/misslewars/MWTeam.java +++ b/src/de/steamwar/misslewars/MWTeam.java @@ -1,8 +1,6 @@ package de.steamwar.misslewars; -import org.bukkit.ChatColor; -import org.bukkit.Location; -import org.bukkit.Material; +import org.bukkit.*; import org.bukkit.enchantments.Enchantment; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; @@ -60,9 +58,10 @@ public class MWTeam { public void join (Player p) { players.add(p); p.teleport(spawn); + Bukkit.getScheduler().runTaskLater(MissileWars.getPlugin(), () -> p.setGameMode(GameMode.SURVIVAL), 1); p.getInventory().setItem(0, bow); sbteam.addPlayer(p); - p.setDisplayName(color + teamName + " " + p.getName()); + p.setDisplayName(color + " " + p.getName()); if (MissileWars.getFightState() == FightState.WAITING && !enemy().getPlayers().isEmpty()) MissileWars.startRound(); } diff --git a/src/de/steamwar/misslewars/MissileWars.java b/src/de/steamwar/misslewars/MissileWars.java index 3b7e12f..5480185 100644 --- a/src/de/steamwar/misslewars/MissileWars.java +++ b/src/de/steamwar/misslewars/MissileWars.java @@ -10,6 +10,8 @@ import de.steamwar.misslewars.items.Snowball; import de.steamwar.misslewars.listener.*; import org.bukkit.Bukkit; import org.bukkit.ChatColor; +import org.bukkit.GameMode; +import org.bukkit.Sound; import org.bukkit.entity.Player; import org.bukkit.plugin.java.JavaPlugin; @@ -28,13 +30,12 @@ public class MissileWars extends JavaPlugin { plugin = this; fightState = FightState.WAITING; startTime = System.currentTimeMillis(); - - redTeam = new MWTeam(ChatColor.RED, Config.RedSpawn, "Rot", Config.RedPortalZ); - blueTeam = new MWTeam(ChatColor.BLUE, Config.BlueSpawn, "Blau", Config.BluePortalZ); } @Override public void onEnable() { + redTeam = new MWTeam(ChatColor.RED, Config.RedSpawn, "Rot", Config.RedPortalZ); + blueTeam = new MWTeam(ChatColor.BLUE, Config.BlueSpawn, "Blau", Config.BluePortalZ); new DeathListener(); new ItemListener(); new ArenaListener(); @@ -44,6 +45,7 @@ public class MissileWars extends JavaPlugin { new PortalDestructListener(); new WaitingListener(); new FightListener(); + new ChatListener(); new WaitingCountdown(); new ItemCountdown(); @@ -82,13 +84,18 @@ public class MissileWars extends JavaPlugin { fightState = FightState.END; StateDependent.setupState(fightState); + for(Player player : Bukkit.getOnlinePlayers()){ + player.playSound(player.getLocation(), Sound.ENTITY_ENDER_DRAGON_DEATH, 100f, 1f); + player.setGameMode(GameMode.SPECTATOR); + } + switch (reason) { case PORTAL_DESTROYED: - Bukkit.getServer().broadcastMessage(winner.getColoredName() + ChatColor.RESET + " hat das gegnerische Portal zerstört."); + Bukkit.getServer().broadcastMessage(winner.getColoredName() + ChatColor.RESET + " §7hat das gegnerische Portal zerstört"); break; case NO_ENEMY: default: - Bukkit.getServer().broadcastMessage("Ohne Gegner kein Kampf - Team " + winner.getColoredName() + ChatColor.RESET + " hat gewonnen."); + Bukkit.getServer().broadcastMessage("§7Team " + winner.getColoredName() + ChatColor.RESET + " §7hat aufgrund fehlenden Gegners gewonnen"); break; } } diff --git a/src/de/steamwar/misslewars/StateDependent.java b/src/de/steamwar/misslewars/StateDependent.java index 015fa2c..0fdba16 100644 --- a/src/de/steamwar/misslewars/StateDependent.java +++ b/src/de/steamwar/misslewars/StateDependent.java @@ -21,10 +21,10 @@ public abstract class StateDependent { static void setupState(FightState state){ for(StateDependent listener : listeners){ if(listener.running && !listener.active.contains(state)){ - listener.enable(); + listener.disable(); listener.running = false; }else if(!listener.running && listener.active.contains(state)){ - listener.disable(); + listener.enable(); listener.running = true; } } diff --git a/src/de/steamwar/misslewars/countdowns/EndCountdown.java b/src/de/steamwar/misslewars/countdowns/EndCountdown.java index 339e10f..de8d757 100644 --- a/src/de/steamwar/misslewars/countdowns/EndCountdown.java +++ b/src/de/steamwar/misslewars/countdowns/EndCountdown.java @@ -29,7 +29,7 @@ public class EndCountdown extends StateDependent { @Override public void disable() { - if(!task.isCancelled()) + if(task != null && !task.isCancelled()) task.cancel(); } } diff --git a/src/de/steamwar/misslewars/countdowns/ItemCountdown.java b/src/de/steamwar/misslewars/countdowns/ItemCountdown.java index da39314..bc4bd7c 100644 --- a/src/de/steamwar/misslewars/countdowns/ItemCountdown.java +++ b/src/de/steamwar/misslewars/countdowns/ItemCountdown.java @@ -55,12 +55,12 @@ public class ItemCountdown extends StateDependent { @Override public void enable() { - task = Bukkit.getScheduler().runTaskTimer(MissileWars.getPlugin(), this::run, Config.ItemTime, 0); + task = Bukkit.getScheduler().runTaskTimer(MissileWars.getPlugin(), this::run, 0, Config.ItemTime); } @Override public void disable() { - if(!task.isCancelled()) + if(task != null && !task.isCancelled()) task.cancel(); } } diff --git a/src/de/steamwar/misslewars/countdowns/WaitingCountdown.java b/src/de/steamwar/misslewars/countdowns/WaitingCountdown.java index 88ff1ce..cd94971 100644 --- a/src/de/steamwar/misslewars/countdowns/WaitingCountdown.java +++ b/src/de/steamwar/misslewars/countdowns/WaitingCountdown.java @@ -27,7 +27,7 @@ public class WaitingCountdown extends StateDependent { @Override public void disable() { - if(!task.isCancelled()) + if(task != null && !task.isCancelled()) task.cancel(); } } diff --git a/src/de/steamwar/misslewars/items/Fireball.java b/src/de/steamwar/misslewars/items/Fireball.java index 86b6d52..c1a0592 100644 --- a/src/de/steamwar/misslewars/items/Fireball.java +++ b/src/de/steamwar/misslewars/items/Fireball.java @@ -1,6 +1,7 @@ package de.steamwar.misslewars.items; import org.bukkit.Material; +import org.bukkit.Sound; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; @@ -16,6 +17,8 @@ public class Fireball extends SpecialItem { @Override public boolean handleUse(Player p) { org.bukkit.entity.Fireball fb = p.launchProjectile(org.bukkit.entity.Fireball.class); + fb.setVelocity(fb.getVelocity().multiply(2)); + p.playSound(p.getLocation(), Sound.ITEM_FIRECHARGE_USE, 100, 1); fb.setIsIncendiary(true); return true; } diff --git a/src/de/steamwar/misslewars/items/Missile.java b/src/de/steamwar/misslewars/items/Missile.java index 83bfa69..4ef3ca8 100644 --- a/src/de/steamwar/misslewars/items/Missile.java +++ b/src/de/steamwar/misslewars/items/Missile.java @@ -32,8 +32,8 @@ public class Missile extends SpecialItem { private final ItemStack item; private Missile(File missileFile){ - String name = missileFile.getName().split(".")[0]; - Material itemType = Material.valueOf(missileFile.getName().split(".")[1]); + String name = missileFile.getName().split("\\.")[0]; + Material itemType = Material.valueOf(missileFile.getName().split("\\.")[1]); ClipboardFormat format = ClipboardFormats.findByFile(missileFile); @@ -60,24 +60,27 @@ public class Missile extends SpecialItem { public boolean handleUse(Player p){ BlockVector3 dimensions = clipboard.getDimensions(); Location location = p.getLocation(); - BlockVector3 v = BlockVector3.at(location.getBlockX(), location.getBlockY(), location.getBlockZ()); + BlockVector3 v = BlockVector3.ZERO; BlockVector3 offset = clipboard.getRegion().getMinimumPoint().subtract(clipboard.getOrigin()); AffineTransform aT = new AffineTransform(); - double yaw = p.getLocation().getYaw(); - if(yaw > 45 && yaw <= 135) + double yaw = (p.getLocation().getYaw() + 360f) % 360; + if(yaw > 45 && yaw <= 135) { aT = aT.rotateY(90); - else if(yaw > 135 && yaw <= 225) + }else if(yaw > 135 && yaw <= 225) { aT = aT.rotateY(180); - else if(yaw > 225 && yaw <= 315) + }else if(yaw > 225 && yaw <= 315) { aT = aT.rotateY(270); + } - v = v.subtract(dimensions.getX()/2, dimensions.getY(), dimensions.getZ()/2 - dimensions.getZ()%2).subtract(offset); + v = v.subtract(dimensions.getX()/2, dimensions.getY() + 2, -2).subtract(offset); + v = aT.apply(v.toVector3()).toBlockPoint(); + v = v.add(location.getBlockX(), location.getBlockY(), location.getBlockZ()); EditSession e = WorldEdit.getInstance().getEditSessionFactory().getEditSession(world, -1); ClipboardHolder ch = new ClipboardHolder(clipboard); ch.setTransform(aT); - Operations.completeBlindly(ch.createPaste(e).to(v).build()); + Operations.completeBlindly(ch.createPaste(e).to(v).ignoreAirBlocks(true).build()); e.flushSession(); return true; } diff --git a/src/de/steamwar/misslewars/listener/ArenaListener.java b/src/de/steamwar/misslewars/listener/ArenaListener.java index bf0b6de..7bb3388 100644 --- a/src/de/steamwar/misslewars/listener/ArenaListener.java +++ b/src/de/steamwar/misslewars/listener/ArenaListener.java @@ -6,7 +6,9 @@ import org.bukkit.GameMode; import org.bukkit.Location; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; +import org.bukkit.event.player.PlayerDropItemEvent; import org.bukkit.event.player.PlayerMoveEvent; +import org.bukkit.event.player.PlayerPickupArrowEvent; import java.util.EnumSet; @@ -26,7 +28,7 @@ public class ArenaListener extends BasicListener { if(p.getGameMode() == GameMode.SPECTATOR) p.teleport(e.getFrom()); else - p.damage(Double.MAX_VALUE); + p.damage(20.0f); }else if( location.getX() < Config.ArenaMinX || location.getX() > Config.ArenaMaxX || @@ -35,4 +37,14 @@ public class ArenaListener extends BasicListener { p.teleport(e.getFrom()); } } + + @EventHandler + public void onArrowPickup(PlayerPickupArrowEvent e){ + e.setCancelled(true); + } + + @EventHandler + public void onItemDrop(PlayerDropItemEvent e){ + e.setCancelled(true); + } } diff --git a/src/de/steamwar/misslewars/listener/ChatListener.java b/src/de/steamwar/misslewars/listener/ChatListener.java new file mode 100644 index 0000000..d3232e4 --- /dev/null +++ b/src/de/steamwar/misslewars/listener/ChatListener.java @@ -0,0 +1,21 @@ +package de.steamwar.misslewars.listener; + +import de.steamwar.misslewars.FightState; +import org.bukkit.Bukkit; +import org.bukkit.event.EventHandler; +import org.bukkit.event.player.AsyncPlayerChatEvent; + +import java.util.EnumSet; + +public class ChatListener extends BasicListener { + + public ChatListener() { + super(EnumSet.allOf(FightState.class)); + } + + @EventHandler + public void onChat(AsyncPlayerChatEvent e){ + Bukkit.broadcastMessage(e.getPlayer().getDisplayName() + "§8» §7" + e.getMessage()); + e.setCancelled(true); + } +} diff --git a/src/de/steamwar/misslewars/listener/ConnectionListener.java b/src/de/steamwar/misslewars/listener/ConnectionListener.java index 5d7d91e..5d5a664 100644 --- a/src/de/steamwar/misslewars/listener/ConnectionListener.java +++ b/src/de/steamwar/misslewars/listener/ConnectionListener.java @@ -5,6 +5,7 @@ import de.steamwar.misslewars.MissileWars; import org.bukkit.GameMode; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.event.player.PlayerQuitEvent; @@ -16,14 +17,13 @@ public class ConnectionListener extends BasicListener{ super(EnumSet.allOf(FightState.class)); } - @EventHandler + @EventHandler(priority = EventPriority.HIGH) public void onJoin(PlayerJoinEvent e) { e.getPlayer().setGameMode(GameMode.SPECTATOR); } @EventHandler public void onLeave(PlayerQuitEvent e) { - e.setQuitMessage(null); Player p = e.getPlayer(); MissileWars.getBlueTeam().leave(p); diff --git a/src/de/steamwar/misslewars/listener/ItemListener.java b/src/de/steamwar/misslewars/listener/ItemListener.java index 30286c3..90da797 100644 --- a/src/de/steamwar/misslewars/listener/ItemListener.java +++ b/src/de/steamwar/misslewars/listener/ItemListener.java @@ -29,7 +29,7 @@ import java.util.Objects; public class ItemListener extends BasicListener { - private static final File shield = new File(de.steamwar.misslewars.MissileWars.getPlugin().getDataFolder(), "shield.schematic"); + private static final File shield = new File(MissileWars.getPlugin().getDataFolder(), "shield.schematic"); private static final World world = new BukkitWorld(Bukkit.getWorlds().get(0)); private static final Clipboard clipboard; private static final BlockVector3 offset; @@ -69,7 +69,7 @@ public class ItemListener extends BasicListener { BlockVector3 paste = BlockVector3.at(l.getX(), l.getY(), l.getZ()).subtract(offset); EditSession editSession = WorldEdit.getInstance().getEditSessionFactory().getEditSession(world, -1); - Operations.completeBlindly(new ClipboardHolder(clipboard).createPaste(editSession).to(paste).build()); + Operations.completeBlindly(new ClipboardHolder(clipboard).createPaste(editSession).ignoreAirBlocks(true).to(paste).build()); editSession.flushSession(); }, Config.ShieldFlyTime); } diff --git a/src/de/steamwar/misslewars/listener/JoinListener.java b/src/de/steamwar/misslewars/listener/JoinListener.java index 708f685..34d206d 100644 --- a/src/de/steamwar/misslewars/listener/JoinListener.java +++ b/src/de/steamwar/misslewars/listener/JoinListener.java @@ -3,6 +3,7 @@ package de.steamwar.misslewars.listener; import de.steamwar.misslewars.FightState; import de.steamwar.misslewars.MissileWars; import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; import org.bukkit.event.player.PlayerJoinEvent; import java.util.EnumSet; @@ -13,11 +14,12 @@ public class JoinListener extends BasicListener { super(EnumSet.of(FightState.WAITING, FightState.FIGHTING)); } - @EventHandler + @EventHandler(priority = EventPriority.HIGHEST) public void onJoin(PlayerJoinEvent e){ if(MissileWars.getRedTeam().getPlayers().size() < MissileWars.getBlueTeam().getPlayers().size()) MissileWars.getRedTeam().join(e.getPlayer()); else MissileWars.getBlueTeam().join(e.getPlayer()); + e.setJoinMessage("§a» " + e.getPlayer().getDisplayName()); } } diff --git a/src/plugin.yml b/src/plugin.yml index 124d00f..e046845 100644 --- a/src/plugin.yml +++ b/src/plugin.yml @@ -1,8 +1,11 @@ -name: MissleWars +name: MissileWars prefix: MW main: de.steamwar.misslewars.MissileWars authors: - Jan9103 - Lixfel version: "1.0" -api-version: "1.13" \ No newline at end of file +api-version: "1.13" +depend: + - WorldEdit + - SpigotCore \ No newline at end of file