12
0

Add Missile Lore #18

Manuell gemergt
Lixfel hat 7 Commits von Lore nach master 2020-09-26 21:51:38 +02:00 zusammengeführt
4 geänderte Dateien mit 52 neuen und 58 gelöschten Zeilen

Datei anzeigen

@ -141,7 +141,7 @@ public class MissileWars extends JavaPlugin {
} }
public static void join(Player p) { 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); MissileWars.getRedTeam().join(p);
} else { } else {
MissileWars.getBlueTeam().join(p); MissileWars.getBlueTeam().join(p);

Datei anzeigen

@ -36,7 +36,7 @@ public class CommandSpectate implements CommandExecutor {
MWTeam mwTeam = MissileWars.getTeam(player); MWTeam mwTeam = MissileWars.getTeam(player);
if (mwTeam == null) return false; 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."); player.sendMessage("§cDu bist alleine im Team, zuschauen ist daher nicht möglich.");
return false; return false;
} }

Datei anzeigen

@ -22,68 +22,45 @@ package de.steamwar.misslewars.items;
import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.WorldEdit; import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.bukkit.BukkitWorld; 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.Clipboard;
import com.sk89q.worldedit.extent.clipboard.io.ClipboardFormat; import com.sk89q.worldedit.extent.clipboard.io.ClipboardFormat;
import com.sk89q.worldedit.extent.clipboard.io.ClipboardFormats; 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.function.operation.Operations;
import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.math.transform.AffineTransform; import com.sk89q.worldedit.math.transform.AffineTransform;
import com.sk89q.worldedit.session.ClipboardHolder; import com.sk89q.worldedit.session.ClipboardHolder;
import com.sk89q.worldedit.world.World; import com.sk89q.worldedit.world.World;
import com.sk89q.worldedit.world.block.BaseBlock; import com.sk89q.worldedit.world.block.BlockTypes;
import de.steamwar.misslewars.MissileWars; import de.steamwar.misslewars.MissileWars;
import io.netty.handler.logging.LogLevel;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import java.io.File; import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.IOException; import java.io.IOException;
import java.util.*; import java.util.ArrayList;
import java.util.logging.Level; import java.util.List;
import java.util.Objects;
public class Missile extends SpecialItem { public class Missile extends SpecialItem {
private static final World world = new BukkitWorld(Bukkit.getWorlds().get(0)); private static final World world = new BukkitWorld(Bukkit.getWorlds().get(0));
private static final int GRAPH_SIZE = 7;
private static Set<BaseBlock> 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 final Clipboard clipboard; private final Clipboard clipboard;
private final ItemStack item; private final ItemStack item;
private Missile(File missileFile){ private Missile(File missileFile) {
String[] strings = missileFile.getName().split("\\."); String[] strings = missileFile.getName().split("\\.");
String name = strings[0]; String name = strings[0];
String material = strings[1]; String material = strings[1];
if (!material.endsWith("_SPAWN_EGG")) { if (!material.endsWith("_SPAWN_EGG")) material += "_SPAWN_EGG";
material += "_SPAWN_EGG";
}
Material itemType = Material.valueOf(material); Material itemType = Material.valueOf(material);
List<String> 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); ClipboardFormat format = ClipboardFormats.findByFile(missileFile);
try { try {
assert format != null; assert format != null;
@ -92,19 +69,36 @@ public class Missile extends SpecialItem {
throw new SecurityException("Corrupt missile"); throw new SecurityException("Corrupt missile");
} }
item = new ItemStack(itemType, 1); List<String> lore = new ArrayList<>();
ItemMeta meta = item.getItemMeta(); lore(lore, strings, 2, " §7Speed");
assert meta != null; lore(lore, strings, 3, " §7Size");
meta.setDisplayName("§c" + name);
meta.setLore(lore); EditSession e = WorldEdit.getInstance().getEditSessionFactory().getEditSession(world, -1);
item.setItemMeta(meta); BlockTypeMask blockTypeMask = new BlockTypeMask(clipboard, BlockTypes.TNT);
lore.add("§7TNT §8: §e" + e.countBlocks(clipboard.getRegion(), blockTypeMask));
item = createItem(itemType, "§c" + name, 1, lore);
}
private void lore(List<String> 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) { private String graph(int index, int size) {
if (index > size) index = size; if (index > size) index = size;
StringBuilder st = new StringBuilder(); StringBuilder st = new StringBuilder();
st.append("§8[§e"); st.append("§8[§e");
st.append(repeat(index)); if (index > 0) {
st.append(repeat(index));
}
st.append("§7"); st.append("§7");
st.append(repeat(size - index)); st.append(repeat(size - index));
st.append("§8]"); st.append("§8]");
@ -120,20 +114,13 @@ public class Missile extends SpecialItem {
return st.toString(); return st.toString();
} }
private int count() {
if (tnt.isEmpty()) {
return 0;
}
return WorldEdit.getInstance().getEditSessionFactory().getEditSession(world, -1).countBlocks(clipboard.getRegion(), tnt);
}
@Override @Override
public ItemStack getItem(){ public ItemStack getItem() {
return item; return item;
} }
@Override @Override
public boolean handleUse(Player p){ public boolean handleUse(Player p) {
BlockVector3 dimensions = clipboard.getDimensions(); BlockVector3 dimensions = clipboard.getDimensions();
Location location = p.getLocation(); Location location = p.getLocation();
BlockVector3 v = BlockVector3.ZERO; BlockVector3 v = BlockVector3.ZERO;
@ -141,11 +128,11 @@ public class Missile extends SpecialItem {
AffineTransform aT = new AffineTransform(); AffineTransform aT = new AffineTransform();
double yaw = (p.getLocation().getYaw() + 360f) % 360; double yaw = (p.getLocation().getYaw() + 360f) % 360;
if(yaw > 45 && yaw <= 135) { if (yaw > 45 && yaw <= 135) {
aT = aT.rotateY(270); aT = aT.rotateY(270);
}else if(yaw > 135 && yaw <= 225) { } else if (yaw > 135 && yaw <= 225) {
aT = aT.rotateY(180); aT = aT.rotateY(180);
}else if(yaw > 225 && yaw <= 315) { } else if (yaw > 225 && yaw <= 315) {
aT = aT.rotateY(90); aT = aT.rotateY(90);
} }
@ -161,16 +148,15 @@ public class Missile extends SpecialItem {
return true; return true;
} }
public static void init(){ public static void init() {
File missileFolder = new File(MissileWars.getPlugin().getDataFolder(), "missiles"); File missileFolder = new File(MissileWars.getPlugin().getDataFolder(), "missiles");
if(!missileFolder.exists() || !missileFolder.canRead() || !missileFolder.isDirectory()){ if (!missileFolder.exists() || !missileFolder.canRead() || !missileFolder.isDirectory()) {
throw new SecurityException("Missiles could not be loaded"); throw new SecurityException("Missiles could not be loaded");
} }
for(File missileFile : Objects.requireNonNull(missileFolder.listFiles())){ for (File missileFile : Objects.requireNonNull(missileFolder.listFiles())) {
if(!missileFile.canRead() || !missileFile.isFile()) if (!missileFile.canRead() || !missileFile.isFile()) continue;
continue;
new Missile(missileFile); new Missile(missileFile);
} }
} }
} }

Datei anzeigen

@ -20,7 +20,9 @@
package de.steamwar.misslewars.items; package de.steamwar.misslewars.items;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemFlag;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.inventory.meta.ItemMeta;
@ -40,9 +42,15 @@ public abstract class SpecialItem {
public abstract boolean handleUse(Player p); public abstract boolean handleUse(Player p);
public ItemStack createItem(Material material, String name, int amount) { public ItemStack createItem(Material material, String name, int amount) {
return createItem(material, name, amount, new ArrayList<>());
}
public ItemStack createItem(Material material, String name, int amount, List<String> lore) {
ItemStack item = new ItemStack(material, amount); ItemStack item = new ItemStack(material, amount);
ItemMeta meta = item.getItemMeta(); ItemMeta meta = item.getItemMeta();
assert meta != null; assert meta != null;
meta.addItemFlags(ItemFlag.HIDE_ENCHANTS);
meta.setLore(lore);
meta.setDisplayName(name); meta.setDisplayName(name);
item.setItemMeta(meta); item.setItemMeta(meta);
return item; return item;