From 5d879beaa4842e9330bc8f63a0ab90e71180ba0d Mon Sep 17 00:00:00 2001 From: jojo Date: Sat, 19 Sep 2020 13:16:18 +0200 Subject: [PATCH 01/11] Add Missile Lore Info Add 2 new Config Keys Add SpecialMissiles to Scoreboard Add SpecialMissiles Pool System Add Special Missile/Support item picking in SpecialItem --- src/de/steamwar/misslewars/Config.java | 5 + .../steamwar/misslewars/FightScoreboard.java | 14 +- src/de/steamwar/misslewars/MissileWars.java | 3 +- src/de/steamwar/misslewars/items/Missile.java | 120 +++++++++++------- .../misslewars/items/SpecialItem.java | 43 +++++-- 5 files changed, 125 insertions(+), 60 deletions(-) diff --git a/src/de/steamwar/misslewars/Config.java b/src/de/steamwar/misslewars/Config.java index 7807c6e..1e8a80c 100644 --- a/src/de/steamwar/misslewars/Config.java +++ b/src/de/steamwar/misslewars/Config.java @@ -48,6 +48,9 @@ public class Config { public static final int ShieldFlyTime; public static final int EndTime; + public static final int MissileCount; + public static final double MissileChance; + static{ File configfile = new File(Bukkit.getWorlds().get(0).getWorldFolder(), "config.yml"); if(!configfile.exists()){ @@ -61,6 +64,8 @@ public class Config { ItemTime = config.getInt("ItemTime"); ShieldFlyTime = config.getInt("ShieldFlyTime"); EndTime = config.getInt("EndTime"); + MissileCount = config.getInt("MissileCount"); + MissileChance = config.getDouble("MissileChance"); ConfigurationSection arena = config.getConfigurationSection("Arena"); assert arena != null; diff --git a/src/de/steamwar/misslewars/FightScoreboard.java b/src/de/steamwar/misslewars/FightScoreboard.java index a9e5f93..fcb3ef9 100644 --- a/src/de/steamwar/misslewars/FightScoreboard.java +++ b/src/de/steamwar/misslewars/FightScoreboard.java @@ -19,6 +19,7 @@ package de.steamwar.misslewars; +import de.steamwar.misslewars.items.Missile; import org.bukkit.Bukkit; import org.bukkit.scoreboard.DisplaySlot; import org.bukkit.scoreboard.Objective; @@ -37,7 +38,7 @@ class FightScoreboard { private static final Objective objective; static{ - if(scoreboard.getObjective("AAA") == null) + if(scoreboard.getObjective("AAA") == null) objective = scoreboard.registerNewObjective("AAA", "BBB", "MissleWars"); else objective = scoreboard.getObjective("AAA"); @@ -52,10 +53,10 @@ class FightScoreboard { teamScoreboard(MissileWars.getBlueTeam()); teamScoreboard(MissileWars.getRedTeam()); - + specialMissiles(); Bukkit.getOnlinePlayers().forEach(player -> player.setScoreboard(scoreboard)); - }, 0, 200); + }, 0, 50); } static Scoreboard getScoreboard() { @@ -65,4 +66,11 @@ class FightScoreboard { private static void teamScoreboard(MWTeam fightTeam){ fightTeam.getPlayers().forEach(p -> objective.getScore(fightTeam.getPrefix() + p.getName()).setScore(1)); } + + private static void specialMissiles() { + objective.getScore("§3").setScore(0); + for (String missile : Missile.specialMissiles) { + objective.getScore("§e" + missile).setScore(0); + } + } } diff --git a/src/de/steamwar/misslewars/MissileWars.java b/src/de/steamwar/misslewars/MissileWars.java index ac2bbf8..be712bc 100644 --- a/src/de/steamwar/misslewars/MissileWars.java +++ b/src/de/steamwar/misslewars/MissileWars.java @@ -37,7 +37,7 @@ public class MissileWars extends JavaPlugin { private static MWTeam blueTeam; private static FightState fightState; private static long startTime; //timestamp when the fight starts - + /** * create teams, ect */ @@ -70,6 +70,7 @@ public class MissileWars extends JavaPlugin { FightScoreboard.init(); Missile.init(); + Missile.randomInit(); new Arrows(); new Fireball(); new Shield(); diff --git a/src/de/steamwar/misslewars/items/Missile.java b/src/de/steamwar/misslewars/items/Missile.java index a1434d5..4537487 100644 --- a/src/de/steamwar/misslewars/items/Missile.java +++ b/src/de/steamwar/misslewars/items/Missile.java @@ -22,68 +22,49 @@ package de.steamwar.misslewars.items; import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.WorldEdit; import com.sk89q.worldedit.bukkit.BukkitWorld; -import com.sk89q.worldedit.extension.input.ParserContext; import com.sk89q.worldedit.extent.clipboard.Clipboard; import com.sk89q.worldedit.extent.clipboard.io.ClipboardFormat; import com.sk89q.worldedit.extent.clipboard.io.ClipboardFormats; +import com.sk89q.worldedit.function.mask.BlockTypeMask; import com.sk89q.worldedit.function.operation.Operations; import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.math.transform.AffineTransform; import com.sk89q.worldedit.session.ClipboardHolder; import com.sk89q.worldedit.world.World; -import com.sk89q.worldedit.world.block.BaseBlock; +import com.sk89q.worldedit.world.block.BlockType; +import com.sk89q.worldedit.world.block.BlockTypes; +import de.steamwar.misslewars.Config; import de.steamwar.misslewars.MissileWars; -import io.netty.handler.logging.LogLevel; import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; -import org.bukkit.inventory.meta.ItemMeta; import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.util.*; -import java.util.logging.Level; public class Missile extends SpecialItem { private static final World world = new BukkitWorld(Bukkit.getWorlds().get(0)); - - private static Set tnt = new HashSet<>(); - - static { - try { - tnt = WorldEdit.getInstance().getBlockFactory().parseFromListInput("tnt", new ParserContext()); - } catch (Exception e) { - //Bukkit.getLogger().log(Level.SEVERE, e.getMessage(), e.getCause()); - } - } + private static final BlockType TNT = BlockTypes.TNT; + private static final int GRAPH_SIZE = 7; + private static final Random r = new Random(); + public static final List specialMissiles = new ArrayList<>(); private final Clipboard clipboard; private final ItemStack item; + private final int tntCount; - private Missile(File missileFile){ + private Missile(File missileFile, boolean special) { String[] strings = missileFile.getName().split("\\."); String name = strings[0]; String material = strings[1]; - if (!material.endsWith("_SPAWN_EGG")) { - material += "_SPAWN_EGG"; - } + if (!material.endsWith("_SPAWN_EGG")) material += "_SPAWN_EGG"; Material itemType = Material.valueOf(material); - List lore = new ArrayList<>(); - if (strings.length > 3) { - try { - lore.add(graph(Integer.parseInt(strings[2]), 7) + " §7Speed"); - lore.add(graph(Integer.parseInt(strings[3]), 7) + " §7Size"); - // lore.add("§7TNT §8: " + count()); - } catch (NumberFormatException e) { - - } - } - ClipboardFormat format = ClipboardFormats.findByFile(missileFile); try { assert format != null; @@ -92,19 +73,41 @@ public class Missile extends SpecialItem { throw new SecurityException("Corrupt missile"); } - item = new ItemStack(itemType, 1); - ItemMeta meta = item.getItemMeta(); - assert meta != null; - meta.setDisplayName("§c" + name); - meta.setLore(lore); - item.setItemMeta(meta); + List lore = new ArrayList<>(); + lore(lore, strings, 2, " §7Speed"); + lore(lore, strings, 3, " §7Size"); + int count; + try { + count = count(); + } catch (Exception e) { + count = 0; + } + tntCount = count; + lore.add("§7TNT §8: §e" + tntCount); + + item = createItem(itemType, "§c" + name, 1, lore, special); + if (special) specialMissiles.add(name); + } + + private void lore(List lore, String[] args, int index, String tag) { + if (args.length > index) { + try { + lore.add(graph(Integer.parseInt(args[index]), GRAPH_SIZE) + tag); + return; + } catch (NumberFormatException e) { + // Ignored + } + } + lore.add(graph(0, GRAPH_SIZE) + tag); } private String graph(int index, int size) { if (index > size) index = size; StringBuilder st = new StringBuilder(); st.append("§8[§e"); - st.append(repeat(index)); + if (index > 0) { + st.append(repeat(index)); + } st.append("§7"); st.append(repeat(size - index)); st.append("§8]"); @@ -121,10 +124,9 @@ public class Missile extends SpecialItem { } private int count() { - if (tnt.isEmpty()) { - return 0; - } - return WorldEdit.getInstance().getEditSessionFactory().getEditSession(world, -1).countBlocks(clipboard.getRegion(), tnt); + EditSession e = WorldEdit.getInstance().getEditSessionFactory().getEditSession(world, -1); + BlockTypeMask blockTypeMask = new BlockTypeMask(clipboard, TNT); + return e.countBlocks(clipboard.getRegion(), blockTypeMask); } @Override @@ -161,16 +163,38 @@ public class Missile extends SpecialItem { return true; } + @Override + public boolean isMissile() { + return true; + } + public static void init(){ - File missileFolder = new File(MissileWars.getPlugin().getDataFolder(), "missiles"); - if(!missileFolder.exists() || !missileFolder.canRead() || !missileFolder.isDirectory()){ + File missileFolder = new File(MissileWars.getPlugin().getDataFolder(), "default-missiles"); + if (!missileFolder.exists() || !missileFolder.canRead() || !missileFolder.isDirectory()) { throw new SecurityException("Missiles could not be loaded"); } - for(File missileFile : Objects.requireNonNull(missileFolder.listFiles())){ - if(!missileFile.canRead() || !missileFile.isFile()) - continue; - - new Missile(missileFile); + for (File missileFile : Objects.requireNonNull(missileFolder.listFiles())) { + if (!missileFile.canRead() || !missileFile.isFile()) continue; + new Missile(missileFile, false); } } + + public static void randomInit() { + File missileFolder = new File(MissileWars.getPlugin().getDataFolder(), "missiles"); + if (!missileFolder.exists() || !missileFolder.canRead() || !missileFolder.isDirectory()) { + return; + } + File[] files = missileFolder.listFiles(); + if (files == null) return; + if (files.length < Config.MissileCount) return; + List pool = new ArrayList<>(files.length); + pool.addAll(Arrays.asList(files)); + + for (int i = 0; i < Config.MissileCount; i++) { + File missileFile = pool.remove(r.nextInt(pool.size())); + if (!missileFile.canRead() || !missileFile.isFile()) continue; + new Missile(missileFile, true); + } + } + } diff --git a/src/de/steamwar/misslewars/items/SpecialItem.java b/src/de/steamwar/misslewars/items/SpecialItem.java index bf131e6..3b22372 100644 --- a/src/de/steamwar/misslewars/items/SpecialItem.java +++ b/src/de/steamwar/misslewars/items/SpecialItem.java @@ -19,8 +19,11 @@ package de.steamwar.misslewars.items; +import de.steamwar.misslewars.Config; import org.bukkit.Material; +import org.bukkit.enchantments.Enchantment; import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemFlag; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; @@ -30,34 +33,58 @@ public abstract class SpecialItem { private static final Random random = new Random(); - private static List items = new ArrayList<>(); + private static List supportItems = new ArrayList<>(); + private static List missileItems = new ArrayList<>(); - SpecialItem(){ - items.add(this); + SpecialItem() { + if (this.isMissile()) { + missileItems.add(this); + return; + } + supportItems.add(this); } public abstract ItemStack getItem(); public abstract boolean handleUse(Player p); + public boolean isMissile() { + return false; + } public ItemStack createItem(Material material, String name, int amount) { + return createItem(material, name, amount, new ArrayList<>(), false); + } + + public ItemStack createItem(Material material, String name, int amount, List lore, boolean special) { ItemStack item = new ItemStack(material, amount); ItemMeta meta = item.getItemMeta(); assert meta != null; + meta.addItemFlags(ItemFlag.HIDE_ENCHANTS); + meta.setLore(lore); meta.setDisplayName(name); item.setItemMeta(meta); + if (special) item.addUnsafeEnchantment(Enchantment.PROTECTION_FALL, 1); return item; } - public static boolean handleUse(ItemStack item, Player player){ - for(SpecialItem specialItem : items){ - if(item.isSimilar(specialItem.getItem())){ + public static boolean handleUse(ItemStack item, Player player) { + for (SpecialItem missileItem : missileItems) { + if (item.isSimilar(missileItem.getItem())) { + return missileItem.handleUse(player); + } + } + for (SpecialItem specialItem : supportItems) { + if (item.isSimilar(specialItem.getItem())) { return specialItem.handleUse(player); } } return false; } - public static ItemStack getRandomItem(){ - return items.get(random.nextInt(items.size())).getItem(); + public static ItemStack getRandomItem() { + if (random.nextDouble() > Config.MissileChance) { + return supportItems.get(random.nextInt(supportItems.size())).getItem(); + } else { + return missileItems.get(random.nextInt(missileItems.size())).getItem(); + } } } -- 2.39.5 From 388323e6b0135959272df1501523e54bf4557252 Mon Sep 17 00:00:00 2001 From: jojo Date: Sat, 19 Sep 2020 14:36:03 +0200 Subject: [PATCH 02/11] Simplify ItemCountdown --- src/de/steamwar/misslewars/MWTeam.java | 10 +++++----- .../steamwar/misslewars/countdowns/ItemCountdown.java | 6 ++++-- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/de/steamwar/misslewars/MWTeam.java b/src/de/steamwar/misslewars/MWTeam.java index 4cd09ee..201d9e8 100644 --- a/src/de/steamwar/misslewars/MWTeam.java +++ b/src/de/steamwar/misslewars/MWTeam.java @@ -77,7 +77,8 @@ public class MWTeam { return spawn; } - public void join (Player p) { + @SuppressWarnings("java:S1874") + public void join(Player p) { players.add(p); p.teleport(spawn); p.setGameMode(GameMode.SURVIVAL); @@ -87,11 +88,10 @@ public class MWTeam { if (MissileWars.getFightState() == FightState.WAITING && !enemy().getPlayers().isEmpty()) MissileWars.startRound(); } - - public void leave (Player p) { - if(!players.contains(p)) - return; + @SuppressWarnings("java:S1874") + public void leave(Player p) { + if(!players.contains(p)) return; players.remove(p); sbteam.removePlayer(p); if (players.isEmpty() && MissileWars.getFightState() == FightState.FIGHTING) diff --git a/src/de/steamwar/misslewars/countdowns/ItemCountdown.java b/src/de/steamwar/misslewars/countdowns/ItemCountdown.java index 35ca32f..3c6f9a3 100644 --- a/src/de/steamwar/misslewars/countdowns/ItemCountdown.java +++ b/src/de/steamwar/misslewars/countdowns/ItemCountdown.java @@ -20,7 +20,6 @@ package de.steamwar.misslewars.countdowns; import de.steamwar.misslewars.*; -import de.steamwar.misslewars.items.Missile; import de.steamwar.misslewars.items.SpecialItem; import org.bukkit.Bukkit; import org.bukkit.Material; @@ -29,7 +28,10 @@ import org.bukkit.inventory.Inventory; import org.bukkit.inventory.ItemStack; import org.bukkit.scheduler.BukkitTask; -import java.util.*; +import java.util.ArrayList; +import java.util.EnumSet; +import java.util.List; +import java.util.Random; public class ItemCountdown extends StateDependent { -- 2.39.5 From 25ae5ce352009459da62a9edb08a40e51462dc57 Mon Sep 17 00:00:00 2001 From: jojo Date: Sun, 20 Sep 2020 13:13:24 +0200 Subject: [PATCH 03/11] Simplify ItemCountdown Balance ItemCountdown --- src/de/steamwar/misslewars/MWTeam.java | 5 +++- .../misslewars/countdowns/ItemCountdown.java | 23 ++++++++----------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/de/steamwar/misslewars/MWTeam.java b/src/de/steamwar/misslewars/MWTeam.java index 201d9e8..e21ad57 100644 --- a/src/de/steamwar/misslewars/MWTeam.java +++ b/src/de/steamwar/misslewars/MWTeam.java @@ -19,7 +19,10 @@ package de.steamwar.misslewars; -import org.bukkit.*; +import org.bukkit.ChatColor; +import org.bukkit.GameMode; +import org.bukkit.Location; +import org.bukkit.Material; import org.bukkit.enchantments.Enchantment; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; diff --git a/src/de/steamwar/misslewars/countdowns/ItemCountdown.java b/src/de/steamwar/misslewars/countdowns/ItemCountdown.java index 3c6f9a3..71f1d98 100644 --- a/src/de/steamwar/misslewars/countdowns/ItemCountdown.java +++ b/src/de/steamwar/misslewars/countdowns/ItemCountdown.java @@ -43,21 +43,18 @@ public class ItemCountdown extends StateDependent { } private void run(){ - int items = Math.max(MissileWars.getBlueTeam().getPlayers().size(), MissileWars.getRedTeam().getPlayers().size()); - List itemList = new ArrayList<>(); + List blue = new ArrayList<>(MissileWars.getBlueTeam().getPlayers()); + List red = new ArrayList<>(MissileWars.getBlueTeam().getPlayers()); + + int items = Math.max(blue.size(), red.size()); + int randomOffsetBlue = random.nextInt(blue.size()); + int randomOffsetRed = random.nextInt(red.size()); + for (int i = 0; i < items; i++) { - itemList.add(SpecialItem.getRandomItem()); - } + ItemStack itemStack = SpecialItem.getRandomItem(); - giveTeamItem(MissileWars.getBlueTeam(), itemList); - giveTeamItem(MissileWars.getRedTeam(), itemList); - } - - private void giveTeamItem(MWTeam team, List itemList) { - List itemStackList = new ArrayList<>(itemList); - for (Player p : team.getPlayers()) { - ItemStack itemStack = itemStackList.remove(random.nextInt(itemStackList.size())); - givePlayerItem(p, itemStack); + givePlayerItem(blue.get((i + randomOffsetBlue) % blue.size()), itemStack); + givePlayerItem(red.get((i + randomOffsetRed) % red.size()), itemStack); } } -- 2.39.5 From f09c856b32f955288b6d67854188656c9ebc8470 Mon Sep 17 00:00:00 2001 From: jojo Date: Sun, 20 Sep 2020 13:18:20 +0200 Subject: [PATCH 04/11] Fix MissileWars.getFightTime --- src/de/steamwar/misslewars/MissileWars.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/de/steamwar/misslewars/MissileWars.java b/src/de/steamwar/misslewars/MissileWars.java index be712bc..a312214 100644 --- a/src/de/steamwar/misslewars/MissileWars.java +++ b/src/de/steamwar/misslewars/MissileWars.java @@ -45,7 +45,7 @@ public class MissileWars extends JavaPlugin { public void onLoad() { plugin = this; fightState = FightState.WAITING; - startTime = System.currentTimeMillis(); + startTime = -1; } @Override @@ -87,6 +87,7 @@ public class MissileWars extends JavaPlugin { if (fightState != FightState.WAITING) // anti dual-call return; fightState = FightState.FIGHTING; + startTime = System.currentTimeMillis(); StateDependent.setupState(fightState); startTime = System.currentTimeMillis(); @@ -147,6 +148,7 @@ public class MissileWars extends JavaPlugin { * @return seconds since start */ public static int getFightTime() { - return Math.floorDiv((int) (System.currentTimeMillis() - startTime), 60); + if (startTime == -1) return -1; + return (int)((System.currentTimeMillis() - startTime) / 1000); } } -- 2.39.5 From 411d602a99220efc20c1cd221e1449b1426ee529 Mon Sep 17 00:00:00 2001 From: jojo Date: Sun, 20 Sep 2020 13:19:33 +0200 Subject: [PATCH 05/11] Remove MissileWars.getFightTime --- src/de/steamwar/misslewars/MissileWars.java | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/src/de/steamwar/misslewars/MissileWars.java b/src/de/steamwar/misslewars/MissileWars.java index a312214..e6ed243 100644 --- a/src/de/steamwar/misslewars/MissileWars.java +++ b/src/de/steamwar/misslewars/MissileWars.java @@ -36,7 +36,6 @@ public class MissileWars extends JavaPlugin { private static MWTeam redTeam; //red has South side -> spawns missles towards north private static MWTeam blueTeam; private static FightState fightState; - private static long startTime; //timestamp when the fight starts /** * create teams, ect @@ -45,7 +44,6 @@ public class MissileWars extends JavaPlugin { public void onLoad() { plugin = this; fightState = FightState.WAITING; - startTime = -1; } @Override @@ -87,10 +85,7 @@ public class MissileWars extends JavaPlugin { if (fightState != FightState.WAITING) // anti dual-call return; fightState = FightState.FIGHTING; - startTime = System.currentTimeMillis(); StateDependent.setupState(fightState); - - startTime = System.currentTimeMillis(); } /** @@ -144,11 +139,4 @@ public class MissileWars extends JavaPlugin { return null; } - /** - * @return seconds since start - */ - public static int getFightTime() { - if (startTime == -1) return -1; - return (int)((System.currentTimeMillis() - startTime) / 1000); - } } -- 2.39.5 From 842b5ead20c28b62c892804d8a167f5cbe7ba858 Mon Sep 17 00:00:00 2001 From: jojo Date: Sun, 20 Sep 2020 13:31:46 +0200 Subject: [PATCH 06/11] Simplify MissileWars --- src/de/steamwar/misslewars/MissileWars.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/de/steamwar/misslewars/MissileWars.java b/src/de/steamwar/misslewars/MissileWars.java index e6ed243..9e72528 100644 --- a/src/de/steamwar/misslewars/MissileWars.java +++ b/src/de/steamwar/misslewars/MissileWars.java @@ -99,7 +99,7 @@ public class MissileWars extends JavaPlugin { fightState = FightState.END; StateDependent.setupState(fightState); - for(Player player : Bukkit.getOnlinePlayers()){ + for(Player player : Bukkit.getOnlinePlayers()) { player.playSound(player.getLocation(), Sound.ENTITY_ENDER_DRAGON_DEATH, 100f, 1f); player.setGameMode(GameMode.SPECTATOR); } @@ -123,15 +123,15 @@ public class MissileWars extends JavaPlugin { return fightState; } - public static MWTeam getRedTeam(){ + public static MWTeam getRedTeam() { return redTeam; } - public static MWTeam getBlueTeam(){ + public static MWTeam getBlueTeam() { return blueTeam; } - public static MWTeam getTeam(Player p){ + public static MWTeam getTeam(Player p) { if(blueTeam.hasPlayer(p)) return blueTeam; if(redTeam.hasPlayer(p)) -- 2.39.5 From 2a0b316608f934dc73e5dff87bf045c5a48958af Mon Sep 17 00:00:00 2001 From: jojo Date: Sun, 20 Sep 2020 13:37:37 +0200 Subject: [PATCH 07/11] Fix Missile.randomInit --- src/de/steamwar/misslewars/items/Missile.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/de/steamwar/misslewars/items/Missile.java b/src/de/steamwar/misslewars/items/Missile.java index 4537487..82cca6c 100644 --- a/src/de/steamwar/misslewars/items/Missile.java +++ b/src/de/steamwar/misslewars/items/Missile.java @@ -187,8 +187,7 @@ public class Missile extends SpecialItem { File[] files = missileFolder.listFiles(); if (files == null) return; if (files.length < Config.MissileCount) return; - List pool = new ArrayList<>(files.length); - pool.addAll(Arrays.asList(files)); + List pool = new ArrayList<>(Arrays.asList(files)); for (int i = 0; i < Config.MissileCount; i++) { File missileFile = pool.remove(r.nextInt(pool.size())); -- 2.39.5 From a2296dac4bb5cb547e406513d6b31492740b9ecd Mon Sep 17 00:00:00 2001 From: jojo Date: Sun, 20 Sep 2020 16:20:15 +0200 Subject: [PATCH 08/11] Add CommandSpectate --- src/config.yml | 3 ++ src/de/steamwar/misslewars/MissileWars.java | 17 ++++++++ .../misslewars/commands/CommandSpectate.java | 39 +++++++++++++++++++ .../listener/ConnectionListener.java | 7 +--- .../misslewars/listener/JoinListener.java | 6 +-- src/plugin.yml | 5 ++- 6 files changed, 67 insertions(+), 10 deletions(-) create mode 100644 src/de/steamwar/misslewars/commands/CommandSpectate.java diff --git a/src/config.yml b/src/config.yml index 49abd82..df837d4 100644 --- a/src/config.yml +++ b/src/config.yml @@ -4,6 +4,9 @@ ShieldFlyTime: 100 PlatformTime: 30 EndTime: 600 +MissileCount: 4 +MissileChance: 0.6 + Arena: MinX: 0 MaxX: 0 diff --git a/src/de/steamwar/misslewars/MissileWars.java b/src/de/steamwar/misslewars/MissileWars.java index 9e72528..08cc17e 100644 --- a/src/de/steamwar/misslewars/MissileWars.java +++ b/src/de/steamwar/misslewars/MissileWars.java @@ -19,6 +19,7 @@ package de.steamwar.misslewars; +import de.steamwar.misslewars.commands.CommandSpectate; import de.steamwar.misslewars.countdowns.EndCountdown; import de.steamwar.misslewars.countdowns.ItemCountdown; import de.steamwar.misslewars.countdowns.WaitingCountdown; @@ -60,6 +61,8 @@ public class MissileWars extends JavaPlugin { new WaitingListener(); new FightListener(); new ChatListener(); + new GamemodeListener(); + getCommand("spectate").setExecutor(new CommandSpectate()); new WaitingCountdown(); new ItemCountdown(); @@ -139,4 +142,18 @@ public class MissileWars extends JavaPlugin { return null; } + public static void join(Player p) { + if (MissileWars.getTeam(p) != null) return; + if (MissileWars.getRedTeam().getPlayers().size() < MissileWars.getBlueTeam().getPlayers().size()) { + MissileWars.getRedTeam().join(p); + } else { + MissileWars.getBlueTeam().join(p); + } + } + + public static void leave(Player p) { + MissileWars.getBlueTeam().leave(p); + MissileWars.getRedTeam().leave(p); + } + } diff --git a/src/de/steamwar/misslewars/commands/CommandSpectate.java b/src/de/steamwar/misslewars/commands/CommandSpectate.java new file mode 100644 index 0000000..a58233f --- /dev/null +++ b/src/de/steamwar/misslewars/commands/CommandSpectate.java @@ -0,0 +1,39 @@ +package de.steamwar.misslewars.commands; + +import de.steamwar.misslewars.MWTeam; +import de.steamwar.misslewars.MissileWars; +import org.bukkit.GameMode; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +public class CommandSpectate implements CommandExecutor { + + public boolean hasPermissions(Player p) { + if (p.hasPermission("bungeecore.group.admin")) return true; + if (p.hasPermission("bungeecore.group.developer")) return true; + if (p.hasPermission("bungeecore.group.moderator")) return true; + if (p.hasPermission("bungeecore.group.supporter")) return true; + if (p.hasPermission("bungeecore.group.builder")) return true; + if (p.hasPermission("bungeecore.group.youtuber")) return true; + return false; + } + + @Override + public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + if(!(sender instanceof Player)) + return false; + Player player = (Player) sender; + + if (!hasPermissions(player)) return false; + + MWTeam mwTeam = MissileWars.getTeam(player); + if (mwTeam == null) return false; + if (mwTeam.getPlayers().size() == 1) return false; + MissileWars.leave(player); + player.setGameMode(GameMode.SPECTATOR); + return true; + } + +} diff --git a/src/de/steamwar/misslewars/listener/ConnectionListener.java b/src/de/steamwar/misslewars/listener/ConnectionListener.java index 3d7f273..7c556ed 100644 --- a/src/de/steamwar/misslewars/listener/ConnectionListener.java +++ b/src/de/steamwar/misslewars/listener/ConnectionListener.java @@ -22,7 +22,6 @@ package de.steamwar.misslewars.listener; import de.steamwar.misslewars.FightState; 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; @@ -43,9 +42,7 @@ public class ConnectionListener extends BasicListener{ @EventHandler public void onLeave(PlayerQuitEvent e) { - Player p = e.getPlayer(); - - MissileWars.getBlueTeam().leave(p); - MissileWars.getRedTeam().leave(p); + MissileWars.leave(e.getPlayer()); } + } diff --git a/src/de/steamwar/misslewars/listener/JoinListener.java b/src/de/steamwar/misslewars/listener/JoinListener.java index 8aaeb7f..83a9bd7 100644 --- a/src/de/steamwar/misslewars/listener/JoinListener.java +++ b/src/de/steamwar/misslewars/listener/JoinListener.java @@ -35,10 +35,8 @@ public class JoinListener extends BasicListener { @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()); + MissileWars.join(e.getPlayer()); e.setJoinMessage("§a» " + e.getPlayer().getDisplayName()); } + } diff --git a/src/plugin.yml b/src/plugin.yml index e046845..452b135 100644 --- a/src/plugin.yml +++ b/src/plugin.yml @@ -4,8 +4,11 @@ main: de.steamwar.misslewars.MissileWars authors: - Jan9103 - Lixfel + - YoyoNow version: "1.0" api-version: "1.13" depend: - WorldEdit - - SpigotCore \ No newline at end of file + - SpigotCore +commands: + spectate: \ No newline at end of file -- 2.39.5 From 60ab66de86c85c31f981c29475e31a33199c0108 Mon Sep 17 00:00:00 2001 From: jojo Date: Sun, 20 Sep 2020 16:20:59 +0200 Subject: [PATCH 09/11] Simplify CommandSpectate --- .../misslewars/commands/CommandSpectate.java | 23 ++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/src/de/steamwar/misslewars/commands/CommandSpectate.java b/src/de/steamwar/misslewars/commands/CommandSpectate.java index a58233f..3ebae21 100644 --- a/src/de/steamwar/misslewars/commands/CommandSpectate.java +++ b/src/de/steamwar/misslewars/commands/CommandSpectate.java @@ -1,3 +1,22 @@ +/* + This file is a part of the SteamWar software. + + Copyright (C) 2020 SteamWar.de-Serverteam + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . +*/ + package de.steamwar.misslewars.commands; import de.steamwar.misslewars.MWTeam; @@ -22,10 +41,8 @@ public class CommandSpectate implements CommandExecutor { @Override public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { - if(!(sender instanceof Player)) - return false; + if(!(sender instanceof Player)) return false; Player player = (Player) sender; - if (!hasPermissions(player)) return false; MWTeam mwTeam = MissileWars.getTeam(player); -- 2.39.5 From 7e0be0a412d70dbd64a105e5d565be47be45a778 Mon Sep 17 00:00:00 2001 From: jojo Date: Fri, 25 Sep 2020 22:14:04 +0200 Subject: [PATCH 10/11] Fix FireTick after Death --- src/de/steamwar/misslewars/listener/DeathListener.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/de/steamwar/misslewars/listener/DeathListener.java b/src/de/steamwar/misslewars/listener/DeathListener.java index 8e7b872..4c12226 100644 --- a/src/de/steamwar/misslewars/listener/DeathListener.java +++ b/src/de/steamwar/misslewars/listener/DeathListener.java @@ -46,6 +46,7 @@ public class DeathListener extends BasicListener { @EventHandler public void onRespawn(PlayerRespawnEvent e){ Player p = e.getPlayer(); + p.setFireTicks(0); MWTeam team = MissileWars.getTeam(p); if(team == null) return; -- 2.39.5 From 8b2c67d8f34272b5d8cb3d164a63e5225a8a469c Mon Sep 17 00:00:00 2001 From: jojo Date: Fri, 25 Sep 2020 22:35:46 +0200 Subject: [PATCH 11/11] Update CodeStyle --- src/de/steamwar/misslewars/Config.java | 9 ++++--- .../steamwar/misslewars/FightScoreboard.java | 12 +++++---- src/de/steamwar/misslewars/MWTeam.java | 6 ++--- src/de/steamwar/misslewars/MissileWars.java | 1 - .../misslewars/SpawnPlatformCreator.java | 18 ++++++------- .../steamwar/misslewars/StateDependent.java | 10 ++++---- .../misslewars/countdowns/EndCountdown.java | 7 +++--- .../misslewars/countdowns/ItemCountdown.java | 6 ++--- src/de/steamwar/misslewars/items/Arrows.java | 1 + .../steamwar/misslewars/items/Fireball.java | 1 + .../steamwar/misslewars/items/LandingPad.java | 1 + src/de/steamwar/misslewars/items/Mine.java | 1 + src/de/steamwar/misslewars/items/Missile.java | 16 ++++++------ src/de/steamwar/misslewars/items/Shield.java | 1 + .../misslewars/listener/ArenaListener.java | 25 ++++++++----------- .../misslewars/listener/BasicListener.java | 7 +++--- .../misslewars/listener/ChatListener.java | 3 ++- .../listener/ConnectionListener.java | 2 +- .../misslewars/listener/DeathListener.java | 4 +-- .../misslewars/listener/EndListener.java | 3 ++- .../misslewars/listener/FightListener.java | 9 +++---- .../misslewars/listener/ItemListener.java | 9 +++---- .../misslewars/listener/JoinListener.java | 4 +-- .../listener/PortalDestructListener.java | 15 ++++++----- .../misslewars/listener/WaitingListener.java | 11 ++++---- 25 files changed, 91 insertions(+), 91 deletions(-) diff --git a/src/de/steamwar/misslewars/Config.java b/src/de/steamwar/misslewars/Config.java index 1e8a80c..913f710 100644 --- a/src/de/steamwar/misslewars/Config.java +++ b/src/de/steamwar/misslewars/Config.java @@ -29,7 +29,10 @@ import java.io.File; import java.util.logging.Level; public class Config { - private Config(){} + + private Config() { + + } public static final int ArenaMinX; public static final int ArenaMaxX; @@ -51,9 +54,9 @@ public class Config { public static final int MissileCount; public static final double MissileChance; - static{ + static { File configfile = new File(Bukkit.getWorlds().get(0).getWorldFolder(), "config.yml"); - if(!configfile.exists()){ + if (!configfile.exists()) { Bukkit.getLogger().log(Level.SEVERE, "Config fehlt!"); Bukkit.shutdown(); } diff --git a/src/de/steamwar/misslewars/FightScoreboard.java b/src/de/steamwar/misslewars/FightScoreboard.java index fcb3ef9..9251734 100644 --- a/src/de/steamwar/misslewars/FightScoreboard.java +++ b/src/de/steamwar/misslewars/FightScoreboard.java @@ -32,19 +32,21 @@ import java.util.Objects; */ class FightScoreboard { - private FightScoreboard(){} + private FightScoreboard() { + + } private static final Scoreboard scoreboard = Objects.requireNonNull(Bukkit.getScoreboardManager()).getMainScoreboard(); private static final Objective objective; - static{ - if(scoreboard.getObjective("AAA") == null) + static { + if (scoreboard.getObjective("AAA") == null) objective = scoreboard.registerNewObjective("AAA", "BBB", "MissleWars"); else objective = scoreboard.getObjective("AAA"); } - static void init(){ + static void init() { Bukkit.getScheduler().scheduleSyncRepeatingTask(MissileWars.getPlugin(), () -> { objective.unregister(); scoreboard.registerNewObjective("AAA", "BBB", "MissleWars"); @@ -63,7 +65,7 @@ class FightScoreboard { return scoreboard; } - private static void teamScoreboard(MWTeam fightTeam){ + private static void teamScoreboard(MWTeam fightTeam) { fightTeam.getPlayers().forEach(p -> objective.getScore(fightTeam.getPrefix() + p.getName()).setScore(1)); } diff --git a/src/de/steamwar/misslewars/MWTeam.java b/src/de/steamwar/misslewars/MWTeam.java index e21ad57..cabaf9d 100644 --- a/src/de/steamwar/misslewars/MWTeam.java +++ b/src/de/steamwar/misslewars/MWTeam.java @@ -54,7 +54,7 @@ public class MWTeam { private Set players = new HashSet<>(); - public Set getPlayers(){ + public Set getPlayers() { return players; } @@ -76,7 +76,7 @@ public class MWTeam { return portalZ; } - public Location getSpawn(){ + public Location getSpawn() { return spawn; } @@ -108,7 +108,7 @@ public class MWTeam { return MissileWars.getRedTeam(); } - public String getPrefix(){ + public String getPrefix() { return "§" + color.getChar(); } diff --git a/src/de/steamwar/misslewars/MissileWars.java b/src/de/steamwar/misslewars/MissileWars.java index 08cc17e..7ddd0cb 100644 --- a/src/de/steamwar/misslewars/MissileWars.java +++ b/src/de/steamwar/misslewars/MissileWars.java @@ -61,7 +61,6 @@ public class MissileWars extends JavaPlugin { new WaitingListener(); new FightListener(); new ChatListener(); - new GamemodeListener(); getCommand("spectate").setExecutor(new CommandSpectate()); new WaitingCountdown(); diff --git a/src/de/steamwar/misslewars/SpawnPlatformCreator.java b/src/de/steamwar/misslewars/SpawnPlatformCreator.java index b9c222a..947cae3 100644 --- a/src/de/steamwar/misslewars/SpawnPlatformCreator.java +++ b/src/de/steamwar/misslewars/SpawnPlatformCreator.java @@ -37,7 +37,7 @@ public class SpawnPlatformCreator { private Block currentBlock; private int ticks; - public SpawnPlatformCreator(Player player){ + public SpawnPlatformCreator(Player player) { this.player = player; MWTeam team = MissileWars.getTeam(player); if(team == null) @@ -49,31 +49,31 @@ public class SpawnPlatformCreator { task = Bukkit.getScheduler().runTaskTimer(MissileWars.getPlugin(), this::createPlatform, 0, 1); } - private void createPlatform(){ + private void createPlatform() { Location playerLoc = player.getLocation(); playerLoc.setY(spawn.getY() - 1); - if(currentBlock == null || !currentBlock.getLocation().equals(playerLoc)){ - if(currentBlock != null){ - if(currentBlock.getType() == Material.OBSIDIAN) + if (currentBlock == null || !currentBlock.getLocation().equals(playerLoc)) { + if (currentBlock != null) { + if (currentBlock.getType() == Material.OBSIDIAN) currentBlock.setType(Material.AIR); currentBlock = null; } Block newBlock = playerLoc.getBlock(); - if(newBlock.getType() == Material.AIR){ + if (newBlock.getType() == Material.AIR) { newBlock.setType(Material.OBSIDIAN); currentBlock = newBlock; } } - if(currentBlock != null && player.getLocation().getY() - 1 < currentBlock.getY()) + if (currentBlock != null && player.getLocation().getY() - 1 < currentBlock.getY()) player.teleport(playerLoc.add(0, 1, 0)); player.spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText("Spawnplattform§8: §c§l" + String.format("%.2f", ticks / 20f) + "§8s")); - if(ticks == 0){ - if(currentBlock != null && currentBlock.getType() == Material.OBSIDIAN) + if (ticks == 0) { + if (currentBlock != null && currentBlock.getType() == Material.OBSIDIAN) currentBlock.setType(Material.AIR); task.cancel(); diff --git a/src/de/steamwar/misslewars/StateDependent.java b/src/de/steamwar/misslewars/StateDependent.java index be9a5e7..f2d6b67 100644 --- a/src/de/steamwar/misslewars/StateDependent.java +++ b/src/de/steamwar/misslewars/StateDependent.java @@ -28,7 +28,7 @@ public abstract class StateDependent { private final Set active; private boolean running; - public StateDependent(final Set active){ + public StateDependent(final Set active) { this.active = active; running = false; listeners.add(this); @@ -37,12 +37,12 @@ public abstract class StateDependent { public abstract void enable(); public abstract void disable(); - static void setupState(FightState state){ - for(StateDependent listener : listeners){ - if(listener.running && !listener.active.contains(state)){ + static void setupState(FightState state) { + for (StateDependent listener : listeners) { + if (listener.running && !listener.active.contains(state)) { listener.disable(); listener.running = false; - }else if(!listener.running && listener.active.contains(state)){ + } else if (!listener.running && listener.active.contains(state)) { listener.enable(); listener.running = true; } diff --git a/src/de/steamwar/misslewars/countdowns/EndCountdown.java b/src/de/steamwar/misslewars/countdowns/EndCountdown.java index 155cceb..482b629 100644 --- a/src/de/steamwar/misslewars/countdowns/EndCountdown.java +++ b/src/de/steamwar/misslewars/countdowns/EndCountdown.java @@ -42,9 +42,9 @@ public class EndCountdown extends StateDependent { } private void kickPlayer(){ - if(Bukkit.getOnlinePlayers().isEmpty()){ + if (Bukkit.getOnlinePlayers().isEmpty()) { Bukkit.shutdown(); - }else{ + } else { Bukkit.getOnlinePlayers().iterator().next().kickPlayer(null); task = Bukkit.getScheduler().runTaskLater(MissileWars.getPlugin(), this::kickPlayer, 10); } @@ -52,7 +52,6 @@ public class EndCountdown extends StateDependent { @Override public void disable() { - if(task != null && !task.isCancelled()) - task.cancel(); + 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 71f1d98..ac90ca0 100644 --- a/src/de/steamwar/misslewars/countdowns/ItemCountdown.java +++ b/src/de/steamwar/misslewars/countdowns/ItemCountdown.java @@ -42,7 +42,7 @@ public class ItemCountdown extends StateDependent { super(EnumSet.of(FightState.FIGHTING)); } - private void run(){ + private void run() { List blue = new ArrayList<>(MissileWars.getBlueTeam().getPlayers()); List red = new ArrayList<>(MissileWars.getBlueTeam().getPlayers()); @@ -87,7 +87,7 @@ public class ItemCountdown extends StateDependent { @Override public void disable() { - if(task != null && !task.isCancelled()) - task.cancel(); + if (task != null && !task.isCancelled()) task.cancel(); } + } diff --git a/src/de/steamwar/misslewars/items/Arrows.java b/src/de/steamwar/misslewars/items/Arrows.java index 38668f3..5c94b6e 100644 --- a/src/de/steamwar/misslewars/items/Arrows.java +++ b/src/de/steamwar/misslewars/items/Arrows.java @@ -36,4 +36,5 @@ public class Arrows extends SpecialItem { public boolean handleUse(Player p) { return false; } + } diff --git a/src/de/steamwar/misslewars/items/Fireball.java b/src/de/steamwar/misslewars/items/Fireball.java index 2fb7d75..e235642 100644 --- a/src/de/steamwar/misslewars/items/Fireball.java +++ b/src/de/steamwar/misslewars/items/Fireball.java @@ -44,4 +44,5 @@ public class Fireball extends SpecialItem { fb.setYield(3f); return true; } + } diff --git a/src/de/steamwar/misslewars/items/LandingPad.java b/src/de/steamwar/misslewars/items/LandingPad.java index db7e781..9e1d26b 100644 --- a/src/de/steamwar/misslewars/items/LandingPad.java +++ b/src/de/steamwar/misslewars/items/LandingPad.java @@ -76,4 +76,5 @@ public class LandingPad extends SpecialItem { editSession.flushSession(); return true; } + } diff --git a/src/de/steamwar/misslewars/items/Mine.java b/src/de/steamwar/misslewars/items/Mine.java index f87d9a1..27fc476 100644 --- a/src/de/steamwar/misslewars/items/Mine.java +++ b/src/de/steamwar/misslewars/items/Mine.java @@ -36,4 +36,5 @@ public class Mine extends SpecialItem { public boolean handleUse(Player p) { return false; } + } diff --git a/src/de/steamwar/misslewars/items/Missile.java b/src/de/steamwar/misslewars/items/Missile.java index 82cca6c..c30e389 100644 --- a/src/de/steamwar/misslewars/items/Missile.java +++ b/src/de/steamwar/misslewars/items/Missile.java @@ -92,24 +92,24 @@ public class Missile extends SpecialItem { private void lore(List lore, String[] args, int index, String tag) { if (args.length > index) { try { - lore.add(graph(Integer.parseInt(args[index]), GRAPH_SIZE) + tag); + lore.add(graph(Integer.parseInt(args[index])) + tag); return; } catch (NumberFormatException e) { // Ignored } } - lore.add(graph(0, GRAPH_SIZE) + tag); + lore.add(graph(0) + tag); } - private String graph(int index, int size) { - if (index > size) index = size; + private String graph(int index) { + if (index > Missile.GRAPH_SIZE) index = Missile.GRAPH_SIZE; StringBuilder st = new StringBuilder(); st.append("§8[§e"); if (index > 0) { st.append(repeat(index)); } st.append("§7"); - st.append(repeat(size - index)); + st.append(repeat(Missile.GRAPH_SIZE - index)); st.append("§8]"); return st.toString(); } @@ -130,12 +130,12 @@ public class Missile extends SpecialItem { } @Override - public ItemStack getItem(){ + public ItemStack getItem() { return item; } @Override - public boolean handleUse(Player p){ + public boolean handleUse(Player p) { BlockVector3 dimensions = clipboard.getDimensions(); Location location = p.getLocation(); BlockVector3 v = BlockVector3.ZERO; @@ -168,7 +168,7 @@ public class Missile extends SpecialItem { return true; } - public static void init(){ + public static void init() { File missileFolder = new File(MissileWars.getPlugin().getDataFolder(), "default-missiles"); if (!missileFolder.exists() || !missileFolder.canRead() || !missileFolder.isDirectory()) { throw new SecurityException("Missiles could not be loaded"); diff --git a/src/de/steamwar/misslewars/items/Shield.java b/src/de/steamwar/misslewars/items/Shield.java index b954660..31e5c51 100644 --- a/src/de/steamwar/misslewars/items/Shield.java +++ b/src/de/steamwar/misslewars/items/Shield.java @@ -36,4 +36,5 @@ public class Shield extends SpecialItem { public boolean handleUse(Player p) { return false; } + } diff --git a/src/de/steamwar/misslewars/listener/ArenaListener.java b/src/de/steamwar/misslewars/listener/ArenaListener.java index 57e2c7a..e89963e 100644 --- a/src/de/steamwar/misslewars/listener/ArenaListener.java +++ b/src/de/steamwar/misslewars/listener/ArenaListener.java @@ -48,42 +48,37 @@ public class ArenaListener extends BasicListener { Player p = e.getPlayer(); assert location != null; - if(location.getY() < Config.ArenaMinY){ - if(p.getGameMode() == GameMode.SPECTATOR) + if (location.getY() < Config.ArenaMinY) { + if (p.getGameMode() == GameMode.SPECTATOR) p.teleport(e.getFrom()); - else if(MissileWars.getFightState() == FightState.WAITING) + else if (MissileWars.getFightState() == FightState.WAITING) p.teleport(Objects.requireNonNull(MissileWars.getTeam(p)).getSpawn()); else p.damage(20.0f); - }else if( - location.getX() < Config.ArenaMinX || - location.getX() > Config.ArenaMaxX || - location.getZ() < Config.ArenaMinZ || - location.getZ() > Config.ArenaMaxZ){ + } else if (location.getX() < Config.ArenaMinX || location.getX() > Config.ArenaMaxX || location.getZ() < Config.ArenaMinZ || location.getZ() > Config.ArenaMaxZ) { p.teleport(e.getFrom()); } } @EventHandler - public void onArrowPickup(PlayerPickupArrowEvent e){ + public void onArrowPickup(PlayerPickupArrowEvent e) { e.setCancelled(true); } @EventHandler - public void onItemDrop(PlayerDropItemEvent e){ + public void onItemDrop(PlayerDropItemEvent e) { e.setCancelled(true); } @EventHandler - public void onHunger(FoodLevelChangeEvent e){ + public void onHunger(FoodLevelChangeEvent e) { e.setCancelled(true); } @EventHandler(ignoreCancelled = true) public void onInventoryOpen(InventoryOpenEvent event) { - if(event.getView().getType() != InventoryType.PLAYER && - event.getView().getType() != InventoryType.CRAFTING && - event.getView().getType() != InventoryType.CREATIVE) - event.setCancelled(true); + if(event.getView().getType() != InventoryType.PLAYER && event.getView().getType() != InventoryType.CRAFTING && event.getView().getType() != InventoryType.CREATIVE) { + event.setCancelled(true); + } } } diff --git a/src/de/steamwar/misslewars/listener/BasicListener.java b/src/de/steamwar/misslewars/listener/BasicListener.java index 58f84c1..1fa2b8f 100644 --- a/src/de/steamwar/misslewars/listener/BasicListener.java +++ b/src/de/steamwar/misslewars/listener/BasicListener.java @@ -31,17 +31,18 @@ import java.util.Set; public abstract class BasicListener extends StateDependent implements Listener { - BasicListener(final Set active){ + BasicListener(final Set active) { super(active); } @Override - public void enable(){ + public void enable() { Bukkit.getPluginManager().registerEvents(this, MissileWars.getPlugin()); } @Override - public void disable(){ + public void disable() { HandlerList.unregisterAll(this); } + } diff --git a/src/de/steamwar/misslewars/listener/ChatListener.java b/src/de/steamwar/misslewars/listener/ChatListener.java index 86f8d81..be748c4 100644 --- a/src/de/steamwar/misslewars/listener/ChatListener.java +++ b/src/de/steamwar/misslewars/listener/ChatListener.java @@ -33,8 +33,9 @@ public class ChatListener extends BasicListener { } @EventHandler - public void onChat(AsyncPlayerChatEvent e){ + 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 7c556ed..f6b24f2 100644 --- a/src/de/steamwar/misslewars/listener/ConnectionListener.java +++ b/src/de/steamwar/misslewars/listener/ConnectionListener.java @@ -31,7 +31,7 @@ import java.util.EnumSet; public class ConnectionListener extends BasicListener{ - public ConnectionListener(){ + public ConnectionListener() { super(EnumSet.allOf(FightState.class)); } diff --git a/src/de/steamwar/misslewars/listener/DeathListener.java b/src/de/steamwar/misslewars/listener/DeathListener.java index 4c12226..bd694e0 100644 --- a/src/de/steamwar/misslewars/listener/DeathListener.java +++ b/src/de/steamwar/misslewars/listener/DeathListener.java @@ -48,10 +48,10 @@ public class DeathListener extends BasicListener { Player p = e.getPlayer(); p.setFireTicks(0); MWTeam team = MissileWars.getTeam(p); - if(team == null) - return; + if(team == null) return; e.setRespawnLocation(team.getSpawn()); new SpawnPlatformCreator(p); } + } diff --git a/src/de/steamwar/misslewars/listener/EndListener.java b/src/de/steamwar/misslewars/listener/EndListener.java index 1483354..15f1d55 100644 --- a/src/de/steamwar/misslewars/listener/EndListener.java +++ b/src/de/steamwar/misslewars/listener/EndListener.java @@ -28,7 +28,7 @@ import java.util.EnumSet; public class EndListener extends BasicListener { - public EndListener(){ + public EndListener() { super(EnumSet.of(FightState.END)); } @@ -37,4 +37,5 @@ public class EndListener extends BasicListener { e.setJoinMessage(null); e.getPlayer().setGameMode(GameMode.SPECTATOR); } + } diff --git a/src/de/steamwar/misslewars/listener/FightListener.java b/src/de/steamwar/misslewars/listener/FightListener.java index 7ed369f..4082579 100644 --- a/src/de/steamwar/misslewars/listener/FightListener.java +++ b/src/de/steamwar/misslewars/listener/FightListener.java @@ -34,14 +34,13 @@ public class FightListener extends BasicListener { } @EventHandler - public void onDamage(EntityDamageByEntityEvent e){ - if(!(e.getDamager() instanceof Player && e.getEntity() instanceof Player)) - return; + public void onDamage(EntityDamageByEntityEvent e) { + if (!(e.getDamager() instanceof Player && e.getEntity() instanceof Player)) return; Player damager = (Player)e.getDamager(); Player reciever = (Player)e.getEntity(); - if(MissileWars.getTeam(damager) == MissileWars.getTeam(reciever)) - e.setCancelled(true); + if (MissileWars.getTeam(damager) == MissileWars.getTeam(reciever)) e.setCancelled(true); } + } diff --git a/src/de/steamwar/misslewars/listener/ItemListener.java b/src/de/steamwar/misslewars/listener/ItemListener.java index 14e6ec6..1037206 100644 --- a/src/de/steamwar/misslewars/listener/ItemListener.java +++ b/src/de/steamwar/misslewars/listener/ItemListener.java @@ -84,13 +84,10 @@ public class ItemListener extends BasicListener { @EventHandler public void onItemClick(PlayerInteractEvent e) { ItemStack item = e.getItem(); - if (item == null) - return; + if (item == null) return; + if (e.getAction() != Action.RIGHT_CLICK_BLOCK && e.getAction() != Action.RIGHT_CLICK_AIR) return; - if(e.getAction() != Action.RIGHT_CLICK_BLOCK && e.getAction() != Action.RIGHT_CLICK_AIR) - return; - - if(SpecialItem.handleUse(item, e.getPlayer())){ + if (SpecialItem.handleUse(item, e.getPlayer())) { item.setAmount(item.getAmount()-1); e.getPlayer().updateInventory(); e.setCancelled(true); diff --git a/src/de/steamwar/misslewars/listener/JoinListener.java b/src/de/steamwar/misslewars/listener/JoinListener.java index 83a9bd7..4dae7b9 100644 --- a/src/de/steamwar/misslewars/listener/JoinListener.java +++ b/src/de/steamwar/misslewars/listener/JoinListener.java @@ -29,12 +29,12 @@ import java.util.EnumSet; public class JoinListener extends BasicListener { - public JoinListener(){ + public JoinListener() { super(EnumSet.of(FightState.WAITING, FightState.FIGHTING)); } @EventHandler(priority = EventPriority.HIGHEST) - public void onJoin(PlayerJoinEvent e){ + public void onJoin(PlayerJoinEvent e) { MissileWars.join(e.getPlayer()); e.setJoinMessage("§a» " + e.getPlayer().getDisplayName()); } diff --git a/src/de/steamwar/misslewars/listener/PortalDestructListener.java b/src/de/steamwar/misslewars/listener/PortalDestructListener.java index c235ff3..50c5826 100644 --- a/src/de/steamwar/misslewars/listener/PortalDestructListener.java +++ b/src/de/steamwar/misslewars/listener/PortalDestructListener.java @@ -33,14 +33,14 @@ import java.util.EnumSet; public class PortalDestructListener extends BasicListener { - public PortalDestructListener(){ + public PortalDestructListener() { super(EnumSet.of(FightState.FIGHTING)); } @EventHandler public void onBlockupdate(BlockPhysicsEvent e) { - if (e.getBlock().getType() != Material.NETHER_PORTAL) - return; + if (e.getBlock().getType() != Material.NETHER_PORTAL) return; + int z = e.getBlock().getZ(); if (z == MissileWars.getRedTeam().getPortalZ()) MissileWars.end(WinReasons.PORTAL_DESTROYED, MissileWars.getBlueTeam()); @@ -49,14 +49,13 @@ public class PortalDestructListener extends BasicListener { } @EventHandler - public void onExplosion(EntityExplodeEvent e){ - if(e.getEntityType() != EntityType.FIREBALL) - return; + public void onExplosion(EntityExplodeEvent e) { + if(e.getEntityType() != EntityType.FIREBALL) return; double z = e.getLocation().getZ(); double distRed = Math.abs(Config.RedPortalZ + 0.5 - z); double distBlue = Math.abs(Config.BluePortalZ + 0.5 - z); - if(distRed < 2 || distBlue < 2) - e.setCancelled(true); + if(distRed < 2 || distBlue < 2) e.setCancelled(true); } + } diff --git a/src/de/steamwar/misslewars/listener/WaitingListener.java b/src/de/steamwar/misslewars/listener/WaitingListener.java index 744c9d2..d5336ab 100644 --- a/src/de/steamwar/misslewars/listener/WaitingListener.java +++ b/src/de/steamwar/misslewars/listener/WaitingListener.java @@ -28,19 +28,18 @@ import org.bukkit.event.player.PlayerQuitEvent; import java.util.EnumSet; public class WaitingListener extends BasicListener { + public WaitingListener() { super(EnumSet.of(FightState.WAITING)); } @EventHandler - public void onDisconnect(PlayerQuitEvent e){ - if(Bukkit.getOnlinePlayers().isEmpty()) - Bukkit.shutdown(); + public void onDisconnect(PlayerQuitEvent e) { + if(Bukkit.getOnlinePlayers().isEmpty()) Bukkit.shutdown(); } @EventHandler - public void onDamage(EntityDamageEvent e){ - if(e.getCause() != EntityDamageEvent.DamageCause.VOID) - e.setCancelled(true); + public void onDamage(EntityDamageEvent e) { + if(e.getCause() != EntityDamageEvent.DamageCause.VOID) e.setCancelled(true); } } -- 2.39.5