SteamWar/MissileWars
Archiviert
13
0

Fix Missle Info

Dieser Commit ist enthalten in:
jojo 2020-09-18 22:16:07 +02:00
Ursprung 4a07281f12
Commit d5dfd56113
2 geänderte Dateien mit 57 neuen und 35 gelöschten Zeilen

Datei anzeigen

@ -22,17 +22,13 @@ 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.extent.clipboard.BlockArrayClipboard;
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.extent.transform.BlockTransformExtent;
import com.sk89q.worldedit.function.mask.BlockTypeMask; import com.sk89q.worldedit.function.mask.BlockTypeMask;
import com.sk89q.worldedit.function.operation.ForwardExtentCopy;
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.math.transform.Identity;
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.BlockType; import com.sk89q.worldedit.world.block.BlockType;
@ -41,8 +37,8 @@ import de.steamwar.misslewars.MissileWars;
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.enchantments.Enchantment;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.entity.TNTPrimed;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.inventory.meta.ItemMeta;
@ -52,17 +48,20 @@ import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Objects; import java.util.Objects;
import java.util.Random;
import java.util.logging.Level; import java.util.logging.Level;
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 BlockType TNT = BlockTypes.TNT; private static final BlockType TNT = BlockTypes.TNT;
private static final int GRAPH_SIZE = 7;
private static final Random r = new Random();
private final Clipboard clipboard; private final Clipboard clipboard;
private final ItemStack item; private final ItemStack item;
private Missile(File missileFile){ private Missile(File missileFile, boolean special) {
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];
@ -78,37 +77,27 @@ public class Missile extends SpecialItem {
} }
List<String> lore = new ArrayList<>(); List<String> lore = new ArrayList<>();
if (strings.length > 2) { lore(lore, strings, 2, " §7Speed");
try { lore(lore, strings, 3, " §7Size");
lore.add(graph(Integer.parseInt(strings[2]), 7) + " §7Speed");
} catch (NumberFormatException e) {
lore.add(graph(0, 7) + " §7Speed");
}
} else {
lore.add(graph(0, 7) + " §7Speed");
}
if (strings.length > 3) {
try {
lore.add(graph(Integer.parseInt(strings[3]), 7) + " §7Size");
} catch (NumberFormatException e) {
lore.add(graph(0, 7) + " §7Size");
}
} else {
lore.add(graph(0, 7) + " §7Size");
}
try { try {
lore.add("§7TNT §8: §e" + count()); lore.add("§7TNT §8: §e" + count());
} catch (Exception e) { } catch (Exception e) {
Bukkit.getLogger().log(Level.SEVERE, e.getMessage(), e.getCause());
lore.add("§7TNT §8: §e?"); lore.add("§7TNT §8: §e?");
} }
item = new ItemStack(itemType, 1); item = createItem(itemType, "§c" + name, 1, lore, special);
ItemMeta meta = item.getItemMeta(); }
assert meta != null;
meta.setDisplayName("§c" + name); private void lore(List<String> lore, String[] args, int index, String tag) {
meta.setLore(lore); if (args.length > index) {
item.setItemMeta(meta); try {
lore.add(graph(Integer.parseInt(args[index]), 7) + tag);
return;
} catch (NumberFormatException e) {
// Ignored
}
}
lore.add(graph(0, 7) + tag);
} }
private String graph(int index, int size) { private String graph(int index, int size) {
@ -175,12 +164,36 @@ public class Missile extends SpecialItem {
public static void init(){ public static void init(){
File missileFolder = new File(MissileWars.getPlugin().getDataFolder(), "default-missles"); File missileFolder = new File(MissileWars.getPlugin().getDataFolder(), "default-missles");
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()) continue; if (!missileFile.canRead() || !missileFile.isFile()) continue;
new Missile(missileFile); new Missile(missileFile, false);
}
}
public static void randomInit() {
File missileFolder = new File(MissileWars.getPlugin().getDataFolder(), "missles");
if (!missileFolder.exists() || !missileFolder.canRead() || !missileFolder.isDirectory()) {
return;
}
File[] files = missileFolder.listFiles();
if (files == null) {
return;
}
if (files.length < 4) {
return;
}
List<File> pool = new ArrayList<>(files.length);
for (File missileFile : files) {
pool.add(missileFile);
}
for (int i = 0; i < 4; i++) {
File missileFile = pool.remove(r.nextInt(pool.size()));
if (!missileFile.canRead() || !missileFile.isFile()) continue;
new Missile(missileFile, true);
} }
} }
} }

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,11 +42,18 @@ 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<>(), false);
}
public ItemStack createItem(Material material, String name, int amount, List<String> lore, boolean special) {
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);
if (special) item.addEnchantment(Enchantment.PROTECTION_FALL, 1);
return item; return item;
} }