From 3d36d41361fb7bfc1e01f06d4c7d3ac80de4f68d Mon Sep 17 00:00:00 2001 From: jojo Date: Sat, 5 Sep 2020 18:22:20 +0200 Subject: [PATCH 1/2] Add LandingPad Add Mine --- src/de/steamwar/misslewars/MissileWars.java | 7 +-- src/de/steamwar/misslewars/items/Arrows.java | 2 +- .../steamwar/misslewars/items/Fireball.java | 2 +- .../steamwar/misslewars/items/LandingPad.java | 57 +++++++++++++++++++ src/de/steamwar/misslewars/items/Mine.java | 20 +++++++ .../steamwar/misslewars/items/Snowball.java | 2 +- .../misslewars/items/SpecialItem.java | 11 ++++ .../misslewars/listener/ItemListener.java | 34 +++++++++-- 8 files changed, 122 insertions(+), 13 deletions(-) create mode 100644 src/de/steamwar/misslewars/items/LandingPad.java create mode 100644 src/de/steamwar/misslewars/items/Mine.java diff --git a/src/de/steamwar/misslewars/MissileWars.java b/src/de/steamwar/misslewars/MissileWars.java index 5480185..5cf028d 100644 --- a/src/de/steamwar/misslewars/MissileWars.java +++ b/src/de/steamwar/misslewars/MissileWars.java @@ -3,10 +3,7 @@ package de.steamwar.misslewars; import de.steamwar.misslewars.countdowns.EndCountdown; import de.steamwar.misslewars.countdowns.ItemCountdown; import de.steamwar.misslewars.countdowns.WaitingCountdown; -import de.steamwar.misslewars.items.Arrows; -import de.steamwar.misslewars.items.Fireball; -import de.steamwar.misslewars.items.Missile; -import de.steamwar.misslewars.items.Snowball; +import de.steamwar.misslewars.items.*; import de.steamwar.misslewars.listener.*; import org.bukkit.Bukkit; import org.bukkit.ChatColor; @@ -57,6 +54,8 @@ public class MissileWars extends JavaPlugin { new Arrows(); new Fireball(); new Snowball(); + new Mine(); + new LandingPad(); StateDependent.setupState(fightState); } diff --git a/src/de/steamwar/misslewars/items/Arrows.java b/src/de/steamwar/misslewars/items/Arrows.java index 37c0bea..43784b2 100644 --- a/src/de/steamwar/misslewars/items/Arrows.java +++ b/src/de/steamwar/misslewars/items/Arrows.java @@ -6,7 +6,7 @@ import org.bukkit.inventory.ItemStack; public class Arrows extends SpecialItem { - private final ItemStack item = new ItemStack(Material.ARROW, 3); + private final ItemStack item = createItem(Material.ARROW, "Pfeile", 3); @Override public ItemStack getItem() { diff --git a/src/de/steamwar/misslewars/items/Fireball.java b/src/de/steamwar/misslewars/items/Fireball.java index a015026..965a723 100644 --- a/src/de/steamwar/misslewars/items/Fireball.java +++ b/src/de/steamwar/misslewars/items/Fireball.java @@ -7,7 +7,7 @@ import org.bukkit.inventory.ItemStack; public class Fireball extends SpecialItem { - private final ItemStack item = new ItemStack(Material.FIRE_CHARGE, 1); + private final ItemStack item = createItem(Material.FIRE_CHARGE, "Feuerball", 1); @Override public ItemStack getItem() { diff --git a/src/de/steamwar/misslewars/items/LandingPad.java b/src/de/steamwar/misslewars/items/LandingPad.java new file mode 100644 index 0000000..beee821 --- /dev/null +++ b/src/de/steamwar/misslewars/items/LandingPad.java @@ -0,0 +1,57 @@ +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.extent.clipboard.Clipboard; +import com.sk89q.worldedit.extent.clipboard.io.ClipboardFormats; +import com.sk89q.worldedit.function.operation.Operations; +import com.sk89q.worldedit.math.BlockVector3; +import com.sk89q.worldedit.session.ClipboardHolder; +import com.sk89q.worldedit.world.World; +import de.steamwar.misslewars.MissileWars; +import org.bukkit.Bukkit; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; + +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.util.Objects; + +public class LandingPad extends SpecialItem { + + private final ItemStack item = createItem(Material.SLIME_BALL, "Landing Pad", 1); + private static final World world = new BukkitWorld(Bukkit.getWorlds().get(0)); + private static final File landingPad = new File(MissileWars.getPlugin().getDataFolder(), "landingPad.schem"); + private final Clipboard clipboard; + private final BlockVector3 offset; + + { + try { + clipboard = Objects.requireNonNull(ClipboardFormats.findByFile(landingPad)).getReader(new FileInputStream(landingPad)).read(); + } catch (IOException e) { + throw new SecurityException("Could not load landingPad", e); + } + + offset = clipboard.getRegion().getMinimumPoint().subtract(clipboard.getOrigin()).add(clipboard.getDimensions().divide(2)); + } + + @Override + public ItemStack getItem() { + return item; + } + + @Override + public boolean handleUse(Player p) { + Location l = p.getLocation(); + BlockVector3 paste = BlockVector3.at(l.getX(), l.getY() - 5, l.getZ()).subtract(offset); + + EditSession editSession = WorldEdit.getInstance().getEditSessionFactory().getEditSession(world, -1); + Operations.completeBlindly(new ClipboardHolder(clipboard).createPaste(editSession).ignoreAirBlocks(true).to(paste).build()); + editSession.flushSession(); + return true; + } +} diff --git a/src/de/steamwar/misslewars/items/Mine.java b/src/de/steamwar/misslewars/items/Mine.java new file mode 100644 index 0000000..0c0a8eb --- /dev/null +++ b/src/de/steamwar/misslewars/items/Mine.java @@ -0,0 +1,20 @@ +package de.steamwar.misslewars.items; + +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; + +public class Mine extends SpecialItem { + + private final ItemStack item = createItem(Material.EGG, "Mine", 1); + + @Override + public ItemStack getItem() { + return item; + } + + @Override + public boolean handleUse(Player p) { + return false; + } +} diff --git a/src/de/steamwar/misslewars/items/Snowball.java b/src/de/steamwar/misslewars/items/Snowball.java index 384b9fc..23067bd 100644 --- a/src/de/steamwar/misslewars/items/Snowball.java +++ b/src/de/steamwar/misslewars/items/Snowball.java @@ -6,7 +6,7 @@ import org.bukkit.inventory.ItemStack; public class Snowball extends SpecialItem { - private final ItemStack item = new ItemStack(Material.SNOWBALL, 1); + private final ItemStack item = createItem(Material.SNOWBALL, "Schild", 1); @Override public ItemStack getItem() { diff --git a/src/de/steamwar/misslewars/items/SpecialItem.java b/src/de/steamwar/misslewars/items/SpecialItem.java index bce73bf..d3e3b3a 100644 --- a/src/de/steamwar/misslewars/items/SpecialItem.java +++ b/src/de/steamwar/misslewars/items/SpecialItem.java @@ -1,7 +1,9 @@ package de.steamwar.misslewars.items; +import org.bukkit.Material; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.ItemMeta; import java.util.*; @@ -18,6 +20,15 @@ public abstract class SpecialItem { public abstract ItemStack getItem(); public abstract boolean handleUse(Player p); + public ItemStack createItem(Material material, String name, int amount) { + ItemStack item = new ItemStack(material, amount); + ItemMeta meta = item.getItemMeta(); + assert meta != null; + meta.setDisplayName(name); + item.setItemMeta(meta); + return item; + } + public static boolean handleUse(ItemStack item, Player player){ for(SpecialItem specialItem : items){ if(item.isSimilar(specialItem.getItem())){ diff --git a/src/de/steamwar/misslewars/listener/ItemListener.java b/src/de/steamwar/misslewars/listener/ItemListener.java index e893f63..a3b07ae 100644 --- a/src/de/steamwar/misslewars/listener/ItemListener.java +++ b/src/de/steamwar/misslewars/listener/ItemListener.java @@ -15,6 +15,7 @@ import de.steamwar.misslewars.MissileWars; import de.steamwar.misslewars.items.SpecialItem; import org.bukkit.Bukkit; import org.bukkit.Location; +import org.bukkit.entity.Egg; import org.bukkit.entity.Snowball; import org.bukkit.event.EventHandler; import org.bukkit.event.block.Action; @@ -31,18 +32,29 @@ import java.util.Objects; public class ItemListener extends BasicListener { private static final File shield = new File(MissileWars.getPlugin().getDataFolder(), "shield.schem"); + private static final File mine = new File(MissileWars.getPlugin().getDataFolder(), "mine.schem"); private static final World world = new BukkitWorld(Bukkit.getWorlds().get(0)); - private static final Clipboard clipboard; - private static final BlockVector3 offset; + private static final Clipboard clipboardShield; + private static final BlockVector3 offsetShield; + + private static final Clipboard clipboardMine; + private static final BlockVector3 offsetMine; static { try { - clipboard = Objects.requireNonNull(ClipboardFormats.findByFile(shield)).getReader(new FileInputStream(shield)).read(); + clipboardShield = Objects.requireNonNull(ClipboardFormats.findByFile(shield)).getReader(new FileInputStream(shield)).read(); } catch (IOException e) { throw new SecurityException("Could not load shield", e); } - offset = clipboard.getRegion().getMinimumPoint().subtract(clipboard.getOrigin()).add(clipboard.getDimensions().divide(2)); + try { + clipboardMine = Objects.requireNonNull(ClipboardFormats.findByFile(mine)).getReader(new FileInputStream(mine)).read(); + } catch (IOException e) { + throw new SecurityException("Could not load mine", e); + } + + offsetShield = clipboardShield.getRegion().getMinimumPoint().subtract(clipboardShield.getOrigin()).add(clipboardShield.getDimensions().divide(2)); + offsetMine = clipboardMine.getRegion().getMinimumPoint().subtract(clipboardMine.getOrigin()).add(clipboardMine.getDimensions().divide(2)); } public ItemListener() { @@ -70,10 +82,20 @@ public class ItemListener extends BasicListener { if (e.getEntity() instanceof Snowball) { Bukkit.getScheduler().runTaskLater(MissileWars.getPlugin(), () -> { Location l = e.getEntity().getLocation(); - BlockVector3 paste = BlockVector3.at(l.getX(), l.getY(), l.getZ()).subtract(offset); + BlockVector3 paste = BlockVector3.at(l.getX(), l.getY(), l.getZ()).subtract(offsetShield); EditSession editSession = WorldEdit.getInstance().getEditSessionFactory().getEditSession(world, -1); - Operations.completeBlindly(new ClipboardHolder(clipboard).createPaste(editSession).ignoreAirBlocks(true).to(paste).build()); + Operations.completeBlindly(new ClipboardHolder(clipboardShield).createPaste(editSession).ignoreAirBlocks(true).to(paste).build()); + editSession.flushSession(); + }, Config.ShieldFlyTime); + } + if (e.getEntity() instanceof Egg) { + Bukkit.getScheduler().runTaskLater(MissileWars.getPlugin(), () -> { + Location l = e.getEntity().getLocation(); + BlockVector3 paste = BlockVector3.at(l.getX(), l.getY(), l.getZ()).subtract(offsetMine); + + EditSession editSession = WorldEdit.getInstance().getEditSessionFactory().getEditSession(world, -1); + Operations.completeBlindly(new ClipboardHolder(clipboardMine).createPaste(editSession).ignoreAirBlocks(true).to(paste).build()); editSession.flushSession(); }, Config.ShieldFlyTime); } -- 2.39.5 From a121ea0755a1a86fe1033a56772595541ef6a0c2 Mon Sep 17 00:00:00 2001 From: jojo Date: Sat, 5 Sep 2020 18:35:15 +0200 Subject: [PATCH 2/2] Add ColorCoding for SpecialItems --- src/de/steamwar/misslewars/MissileWars.java | 2 +- src/de/steamwar/misslewars/items/Arrows.java | 2 +- src/de/steamwar/misslewars/items/Fireball.java | 2 +- src/de/steamwar/misslewars/items/LandingPad.java | 2 +- src/de/steamwar/misslewars/items/Mine.java | 2 +- src/de/steamwar/misslewars/items/Missile.java | 2 +- .../steamwar/misslewars/items/{Snowball.java => Shield.java} | 4 ++-- 7 files changed, 8 insertions(+), 8 deletions(-) rename src/de/steamwar/misslewars/items/{Snowball.java => Shield.java} (69%) diff --git a/src/de/steamwar/misslewars/MissileWars.java b/src/de/steamwar/misslewars/MissileWars.java index 5cf028d..a395ae4 100644 --- a/src/de/steamwar/misslewars/MissileWars.java +++ b/src/de/steamwar/misslewars/MissileWars.java @@ -53,7 +53,7 @@ public class MissileWars extends JavaPlugin { Missile.init(); new Arrows(); new Fireball(); - new Snowball(); + new Shield(); new Mine(); new LandingPad(); diff --git a/src/de/steamwar/misslewars/items/Arrows.java b/src/de/steamwar/misslewars/items/Arrows.java index 43784b2..253d0b0 100644 --- a/src/de/steamwar/misslewars/items/Arrows.java +++ b/src/de/steamwar/misslewars/items/Arrows.java @@ -6,7 +6,7 @@ import org.bukkit.inventory.ItemStack; public class Arrows extends SpecialItem { - private final ItemStack item = createItem(Material.ARROW, "Pfeile", 3); + private final ItemStack item = createItem(Material.ARROW, "§ePfeile", 3); @Override public ItemStack getItem() { diff --git a/src/de/steamwar/misslewars/items/Fireball.java b/src/de/steamwar/misslewars/items/Fireball.java index 965a723..1747c99 100644 --- a/src/de/steamwar/misslewars/items/Fireball.java +++ b/src/de/steamwar/misslewars/items/Fireball.java @@ -7,7 +7,7 @@ import org.bukkit.inventory.ItemStack; public class Fireball extends SpecialItem { - private final ItemStack item = createItem(Material.FIRE_CHARGE, "Feuerball", 1); + private final ItemStack item = createItem(Material.FIRE_CHARGE, "§eFeuerball", 1); @Override public ItemStack getItem() { diff --git a/src/de/steamwar/misslewars/items/LandingPad.java b/src/de/steamwar/misslewars/items/LandingPad.java index beee821..15455c0 100644 --- a/src/de/steamwar/misslewars/items/LandingPad.java +++ b/src/de/steamwar/misslewars/items/LandingPad.java @@ -23,7 +23,7 @@ import java.util.Objects; public class LandingPad extends SpecialItem { - private final ItemStack item = createItem(Material.SLIME_BALL, "Landing Pad", 1); + private final ItemStack item = createItem(Material.SLIME_BALL, "§aLanding Pad", 1); private static final World world = new BukkitWorld(Bukkit.getWorlds().get(0)); private static final File landingPad = new File(MissileWars.getPlugin().getDataFolder(), "landingPad.schem"); private final Clipboard clipboard; diff --git a/src/de/steamwar/misslewars/items/Mine.java b/src/de/steamwar/misslewars/items/Mine.java index 0c0a8eb..59a89c6 100644 --- a/src/de/steamwar/misslewars/items/Mine.java +++ b/src/de/steamwar/misslewars/items/Mine.java @@ -6,7 +6,7 @@ import org.bukkit.inventory.ItemStack; public class Mine extends SpecialItem { - private final ItemStack item = createItem(Material.EGG, "Mine", 1); + private final ItemStack item = createItem(Material.EGG, "§eMine", 1); @Override public ItemStack getItem() { diff --git a/src/de/steamwar/misslewars/items/Missile.java b/src/de/steamwar/misslewars/items/Missile.java index dd70503..8a75ab7 100644 --- a/src/de/steamwar/misslewars/items/Missile.java +++ b/src/de/steamwar/misslewars/items/Missile.java @@ -47,7 +47,7 @@ public class Missile extends SpecialItem { item = new ItemStack(itemType, 1); ItemMeta meta = item.getItemMeta(); assert meta != null; - meta.setDisplayName(name); + meta.setDisplayName("§c" + name); item.setItemMeta(meta); } diff --git a/src/de/steamwar/misslewars/items/Snowball.java b/src/de/steamwar/misslewars/items/Shield.java similarity index 69% rename from src/de/steamwar/misslewars/items/Snowball.java rename to src/de/steamwar/misslewars/items/Shield.java index 23067bd..d7178e1 100644 --- a/src/de/steamwar/misslewars/items/Snowball.java +++ b/src/de/steamwar/misslewars/items/Shield.java @@ -4,9 +4,9 @@ import org.bukkit.Material; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; -public class Snowball extends SpecialItem { +public class Shield extends SpecialItem { - private final ItemStack item = createItem(Material.SNOWBALL, "Schild", 1); + private final ItemStack item = createItem(Material.SNOWBALL, "§aSchild", 1); @Override public ItemStack getItem() { -- 2.39.5