From 4cb0242974e8723c4f849c95397afa04ae2024a9 Mon Sep 17 00:00:00 2001 From: jojo Date: Sat, 26 Sep 2020 21:18:10 +0200 Subject: [PATCH 1/7] Add Missile Lore --- src/de/steamwar/misslewars/items/Missile.java | 112 ++++++++++-------- .../misslewars/items/SpecialItem.java | 9 ++ 2 files changed, 70 insertions(+), 51 deletions(-) diff --git a/src/de/steamwar/misslewars/items/Missile.java b/src/de/steamwar/misslewars/items/Missile.java index a1434d5..888d035 100644 --- a/src/de/steamwar/misslewars/items/Missile.java +++ b/src/de/steamwar/misslewars/items/Missile.java @@ -22,68 +22,48 @@ 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.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; +import java.util.ArrayList; +import java.util.List; +import java.util.Objects; 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 final Clipboard clipboard; private final ItemStack item; + private final int tntCount; - private Missile(File missileFile){ + private Missile(File missileFile) { 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 +72,35 @@ 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"); + + tntCount = count(); + lore.add("§7TNT §8: §e" + tntCount); + + item = createItem(itemType, "§c" + name, 1, lore, false); + } + + 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,19 +117,22 @@ public class Missile extends SpecialItem { } private int count() { - if (tnt.isEmpty()) { + try { + EditSession e = WorldEdit.getInstance().getEditSessionFactory().getEditSession(world, -1); + BlockTypeMask blockTypeMask = new BlockTypeMask(clipboard, TNT); + return e.countBlocks(clipboard.getRegion(), blockTypeMask); + } catch (Exception e) { return 0; } - return WorldEdit.getInstance().getEditSessionFactory().getEditSession(world, -1).countBlocks(clipboard.getRegion(), tnt); } @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; @@ -141,11 +140,11 @@ public class Missile extends SpecialItem { AffineTransform aT = new AffineTransform(); double yaw = (p.getLocation().getYaw() + 360f) % 360; - if(yaw > 45 && yaw <= 135) { + if (yaw > 45 && yaw <= 135) { aT = aT.rotateY(270); - }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(90); } @@ -161,16 +160,27 @@ public class Missile extends SpecialItem { return true; } - public static void init(){ - File missileFolder = new File(MissileWars.getPlugin().getDataFolder(), "missiles"); - if(!missileFolder.exists() || !missileFolder.canRead() || !missileFolder.isDirectory()){ + 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"); } - for(File missileFile : Objects.requireNonNull(missileFolder.listFiles())){ - if(!missileFile.canRead() || !missileFile.isFile()) - continue; + for (File missileFile : Objects.requireNonNull(missileFolder.listFiles())) { + if (!missileFile.canRead() || !missileFile.isFile()) continue; + new Missile(missileFile); + } + otherInit(); + } + public static void otherInit() { + File missileFolder = new File(MissileWars.getPlugin().getDataFolder(), "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); } } + } diff --git a/src/de/steamwar/misslewars/items/SpecialItem.java b/src/de/steamwar/misslewars/items/SpecialItem.java index bf131e6..1ed1f91 100644 --- a/src/de/steamwar/misslewars/items/SpecialItem.java +++ b/src/de/steamwar/misslewars/items/SpecialItem.java @@ -20,7 +20,9 @@ package de.steamwar.misslewars.items; 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; @@ -40,11 +42,18 @@ public abstract class SpecialItem { public abstract boolean handleUse(Player p); 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; } -- 2.39.5 From 360b47e490efff7ff5f45b3fc4d48e76bc01ef48 Mon Sep 17 00:00:00 2001 From: jojo Date: Sat, 26 Sep 2020 21:36:08 +0200 Subject: [PATCH 2/7] Remove Missile.count() --- src/de/steamwar/misslewars/items/Missile.java | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/src/de/steamwar/misslewars/items/Missile.java b/src/de/steamwar/misslewars/items/Missile.java index 888d035..3f02abf 100644 --- a/src/de/steamwar/misslewars/items/Missile.java +++ b/src/de/steamwar/misslewars/items/Missile.java @@ -50,7 +50,6 @@ import java.util.Objects; public class Missile extends SpecialItem { private static final World world = new BukkitWorld(Bukkit.getWorlds().get(0)); - private static final BlockType TNT = BlockTypes.TNT; private static final int GRAPH_SIZE = 7; private final Clipboard clipboard; @@ -76,7 +75,9 @@ public class Missile extends SpecialItem { lore(lore, strings, 2, " §7Speed"); lore(lore, strings, 3, " §7Size"); - tntCount = count(); + EditSession e = WorldEdit.getInstance().getEditSessionFactory().getEditSession(world, -1); + BlockTypeMask blockTypeMask = new BlockTypeMask(clipboard, BlockTypes.TNT); + tntCount = e.countBlocks(clipboard.getRegion(), blockTypeMask); lore.add("§7TNT §8: §e" + tntCount); item = createItem(itemType, "§c" + name, 1, lore, false); @@ -116,16 +117,6 @@ public class Missile extends SpecialItem { return st.toString(); } - private int count() { - try { - EditSession e = WorldEdit.getInstance().getEditSessionFactory().getEditSession(world, -1); - BlockTypeMask blockTypeMask = new BlockTypeMask(clipboard, TNT); - return e.countBlocks(clipboard.getRegion(), blockTypeMask); - } catch (Exception e) { - return 0; - } - } - @Override public ItemStack getItem() { return item; -- 2.39.5 From 4c82cb3cd4e849a5ff8388a2f2e03be8a7500597 Mon Sep 17 00:00:00 2001 From: jojo Date: Sat, 26 Sep 2020 21:45:08 +0200 Subject: [PATCH 3/7] Remove Missile tntCount saving --- src/de/steamwar/misslewars/items/Missile.java | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/de/steamwar/misslewars/items/Missile.java b/src/de/steamwar/misslewars/items/Missile.java index 3f02abf..cd6b00c 100644 --- a/src/de/steamwar/misslewars/items/Missile.java +++ b/src/de/steamwar/misslewars/items/Missile.java @@ -31,7 +31,6 @@ 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.BlockType; import com.sk89q.worldedit.world.block.BlockTypes; import de.steamwar.misslewars.MissileWars; import org.bukkit.Bukkit; @@ -54,7 +53,6 @@ public class Missile extends SpecialItem { private final Clipboard clipboard; private final ItemStack item; - private final int tntCount; private Missile(File missileFile) { String[] strings = missileFile.getName().split("\\."); @@ -77,8 +75,7 @@ public class Missile extends SpecialItem { EditSession e = WorldEdit.getInstance().getEditSessionFactory().getEditSession(world, -1); BlockTypeMask blockTypeMask = new BlockTypeMask(clipboard, BlockTypes.TNT); - tntCount = e.countBlocks(clipboard.getRegion(), blockTypeMask); - lore.add("§7TNT §8: §e" + tntCount); + lore.add("§7TNT §8: §e" + e.countBlocks(clipboard.getRegion(), blockTypeMask)); item = createItem(itemType, "§c" + name, 1, lore, false); } -- 2.39.5 From 9250e325f47bc7a98aa033d10a4bffa592535dbf Mon Sep 17 00:00:00 2001 From: jojo Date: Sat, 26 Sep 2020 21:45:48 +0200 Subject: [PATCH 4/7] Fix MissileWars --- src/de/steamwar/misslewars/MissileWars.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/de/steamwar/misslewars/MissileWars.java b/src/de/steamwar/misslewars/MissileWars.java index 24c576c..29e3ec8 100644 --- a/src/de/steamwar/misslewars/MissileWars.java +++ b/src/de/steamwar/misslewars/MissileWars.java @@ -141,7 +141,7 @@ public class MissileWars extends JavaPlugin { } public static void join(Player p) { - if (MissileWars.getRedTeam().getPlayers().size() < MissileWars.getBlueTeam().getPlayers().size()) { + if (MissileWars.getRedTeam().size() < MissileWars.getBlueTeam().size()) { MissileWars.getRedTeam().join(p); } else { MissileWars.getBlueTeam().join(p); -- 2.39.5 From 48dac847ee1fba14787e49381357ee07cab9a529 Mon Sep 17 00:00:00 2001 From: jojo Date: Sat, 26 Sep 2020 21:46:05 +0200 Subject: [PATCH 5/7] Fix CommandSpectate --- src/de/steamwar/misslewars/commands/CommandSpectate.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/de/steamwar/misslewars/commands/CommandSpectate.java b/src/de/steamwar/misslewars/commands/CommandSpectate.java index ded0a44..6efa06f 100644 --- a/src/de/steamwar/misslewars/commands/CommandSpectate.java +++ b/src/de/steamwar/misslewars/commands/CommandSpectate.java @@ -36,7 +36,7 @@ public class CommandSpectate implements CommandExecutor { MWTeam mwTeam = MissileWars.getTeam(player); if (mwTeam == null) return false; - if (mwTeam.getPlayers().size() == 1) { + if (mwTeam.size() == 1) { player.sendMessage("§cDu bist alleine im Team, zuschauen ist daher nicht möglich."); return false; } -- 2.39.5 From d15728aba8705a15868379dbaf6619e3155a5410 Mon Sep 17 00:00:00 2001 From: jojo Date: Sat, 26 Sep 2020 21:49:54 +0200 Subject: [PATCH 6/7] Fix missiles --- src/de/steamwar/misslewars/items/Missile.java | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/src/de/steamwar/misslewars/items/Missile.java b/src/de/steamwar/misslewars/items/Missile.java index cd6b00c..99e5e0d 100644 --- a/src/de/steamwar/misslewars/items/Missile.java +++ b/src/de/steamwar/misslewars/items/Missile.java @@ -149,18 +149,6 @@ public class Missile extends SpecialItem { } 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"); - } - for (File missileFile : Objects.requireNonNull(missileFolder.listFiles())) { - if (!missileFile.canRead() || !missileFile.isFile()) continue; - new Missile(missileFile); - } - otherInit(); - } - - public static void otherInit() { File missileFolder = new File(MissileWars.getPlugin().getDataFolder(), "missiles"); if (!missileFolder.exists() || !missileFolder.canRead() || !missileFolder.isDirectory()) { throw new SecurityException("Missiles could not be loaded"); -- 2.39.5 From b5f1219807cd2f4674c3a8387ad020ac088d073d Mon Sep 17 00:00:00 2001 From: jojo Date: Sat, 26 Sep 2020 21:51:10 +0200 Subject: [PATCH 7/7] Remove special Tag --- src/de/steamwar/misslewars/items/Missile.java | 2 +- src/de/steamwar/misslewars/items/SpecialItem.java | 5 ++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/de/steamwar/misslewars/items/Missile.java b/src/de/steamwar/misslewars/items/Missile.java index 99e5e0d..2392aea 100644 --- a/src/de/steamwar/misslewars/items/Missile.java +++ b/src/de/steamwar/misslewars/items/Missile.java @@ -77,7 +77,7 @@ public class Missile extends SpecialItem { BlockTypeMask blockTypeMask = new BlockTypeMask(clipboard, BlockTypes.TNT); lore.add("§7TNT §8: §e" + e.countBlocks(clipboard.getRegion(), blockTypeMask)); - item = createItem(itemType, "§c" + name, 1, lore, false); + item = createItem(itemType, "§c" + name, 1, lore); } private void lore(List lore, String[] args, int index, String tag) { diff --git a/src/de/steamwar/misslewars/items/SpecialItem.java b/src/de/steamwar/misslewars/items/SpecialItem.java index 1ed1f91..b66c04c 100644 --- a/src/de/steamwar/misslewars/items/SpecialItem.java +++ b/src/de/steamwar/misslewars/items/SpecialItem.java @@ -42,10 +42,10 @@ public abstract class SpecialItem { public abstract boolean handleUse(Player p); public ItemStack createItem(Material material, String name, int amount) { - return createItem(material, name, amount, new ArrayList<>(), false); + return createItem(material, name, amount, new ArrayList<>()); } - public ItemStack createItem(Material material, String name, int amount, List lore, boolean special) { + public ItemStack createItem(Material material, String name, int amount, List lore) { ItemStack item = new ItemStack(material, amount); ItemMeta meta = item.getItemMeta(); assert meta != null; @@ -53,7 +53,6 @@ public abstract class SpecialItem { meta.setLore(lore); meta.setDisplayName(name); item.setItemMeta(meta); - if (special) item.addUnsafeEnchantment(Enchantment.PROTECTION_FALL, 1); return item; } -- 2.39.5