SteamWar/MissileWars
Archiviert
13
0

Merge pull request 'ItemManagement' (#5) from ItemManagement into master

Reviewed-by: Chaoscaot <chaoscaot444@gmail.com>
Dieser Commit ist enthalten in:
YoyoNow 2020-09-05 18:44:49 +02:00
Commit 89ab368381
9 geänderte Dateien mit 125 neuen und 16 gelöschten Zeilen

Datei anzeigen

@ -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;
@ -56,7 +53,9 @@ public class MissileWars extends JavaPlugin {
Missile.init();
new Arrows();
new Fireball();
new Snowball();
new Shield();
new Mine();
new LandingPad();
StateDependent.setupState(fightState);
}

Datei anzeigen

@ -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, "§ePfeile", 3);
@Override
public ItemStack getItem() {

Datei anzeigen

@ -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, "§eFeuerball", 1);
@Override
public ItemStack getItem() {

Datei anzeigen

@ -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, "§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;
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;
}
}

Datei anzeigen

@ -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, "§eMine", 1);
@Override
public ItemStack getItem() {
return item;
}
@Override
public boolean handleUse(Player p) {
return false;
}
}

Datei anzeigen

@ -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);
}

Datei anzeigen

@ -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 = new ItemStack(Material.SNOWBALL, 1);
private final ItemStack item = createItem(Material.SNOWBALL, "§aSchild", 1);
@Override
public ItemStack getItem() {

Datei anzeigen

@ -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())){

Datei anzeigen

@ -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);
}