SteamWar/MissileWars
Archiviert
13
0

Revert YoyoNow-Changes

Dieser Commit ist enthalten in:
Lixfel 2020-09-19 12:41:48 +02:00
Ursprung 3ca0ee519a
Commit 81a0e3a412
5 geänderte Dateien mit 58 neuen und 125 gelöschten Zeilen

Datei anzeigen

@ -48,9 +48,6 @@ public class Config {
public static final int ShieldFlyTime; public static final int ShieldFlyTime;
public static final int EndTime; public static final int EndTime;
public static final int MissileCount;
public static final double MissileChance;
static{ static{
File configfile = new File(Bukkit.getWorlds().get(0).getWorldFolder(), "config.yml"); File configfile = new File(Bukkit.getWorlds().get(0).getWorldFolder(), "config.yml");
if(!configfile.exists()){ if(!configfile.exists()){
@ -64,8 +61,6 @@ public class Config {
ItemTime = config.getInt("ItemTime"); ItemTime = config.getInt("ItemTime");
ShieldFlyTime = config.getInt("ShieldFlyTime"); ShieldFlyTime = config.getInt("ShieldFlyTime");
EndTime = config.getInt("EndTime"); EndTime = config.getInt("EndTime");
MissileCount = config.getInt("MissileCount");
MissileChance = config.getDouble("MissileChance");
ConfigurationSection arena = config.getConfigurationSection("Arena"); ConfigurationSection arena = config.getConfigurationSection("Arena");
assert arena != null; assert arena != null;

Datei anzeigen

@ -19,14 +19,11 @@
package de.steamwar.misslewars; package de.steamwar.misslewars;
import de.steamwar.misslewars.items.Missile;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.scoreboard.DisplaySlot; import org.bukkit.scoreboard.DisplaySlot;
import org.bukkit.scoreboard.Objective; import org.bukkit.scoreboard.Objective;
import org.bukkit.scoreboard.Scoreboard; import org.bukkit.scoreboard.Scoreboard;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects; import java.util.Objects;
/** /**
@ -55,10 +52,10 @@ class FightScoreboard {
teamScoreboard(MissileWars.getBlueTeam()); teamScoreboard(MissileWars.getBlueTeam());
teamScoreboard(MissileWars.getRedTeam()); teamScoreboard(MissileWars.getRedTeam());
specialMissiles();
Bukkit.getOnlinePlayers().forEach(player -> player.setScoreboard(scoreboard)); Bukkit.getOnlinePlayers().forEach(player -> player.setScoreboard(scoreboard));
}, 0, 50); }, 0, 200);
} }
static Scoreboard getScoreboard() { static Scoreboard getScoreboard() {
@ -68,11 +65,4 @@ class FightScoreboard {
private static void teamScoreboard(MWTeam fightTeam){ private static void teamScoreboard(MWTeam fightTeam){
fightTeam.getPlayers().forEach(p -> objective.getScore(fightTeam.getPrefix() + p.getName()).setScore(1)); fightTeam.getPlayers().forEach(p -> objective.getScore(fightTeam.getPrefix() + p.getName()).setScore(1));
} }
private static void specialMissiles() {
objective.getScore("§3").setScore(0);
for (String missile : Missile.specialMissiles) {
objective.getScore("§e" + missile).setScore(0);
}
}
} }

Datei anzeigen

@ -70,7 +70,6 @@ public class MissileWars extends JavaPlugin {
FightScoreboard.init(); FightScoreboard.init();
Missile.init(); Missile.init();
Missile.randomInit();
new Arrows(); new Arrows();
new Fireball(); new Fireball();
new Shield(); new Shield();

Datei anzeigen

@ -22,49 +22,68 @@ 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.BlockType; import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.world.block.BlockTypes;
import de.steamwar.misslewars.Config;
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.*;
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 int GRAPH_SIZE = 7; private static Set<BaseBlock> tnt = new HashSet<>();
private static final Random r = new Random();
public static final List<String> specialMissiles = new ArrayList<>(); 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 final int tntCount;
private Missile(File missileFile, boolean special) { 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")) material += "_SPAWN_EGG"; if (!material.endsWith("_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;
@ -73,41 +92,19 @@ public class Missile extends SpecialItem {
throw new SecurityException("Corrupt missile"); throw new SecurityException("Corrupt missile");
} }
List<String> lore = new ArrayList<>(); item = new ItemStack(itemType, 1);
lore(lore, strings, 2, " §7Speed"); ItemMeta meta = item.getItemMeta();
lore(lore, strings, 3, " §7Size"); assert meta != null;
int count; meta.setDisplayName("§c" + name);
try { meta.setLore(lore);
count = count(); item.setItemMeta(meta);
} catch (Exception e) {
count = 0;
}
tntCount = count;
lore.add("§7TNT §8: §e" + tntCount);
item = createItem(itemType, "§c" + name + " §7(§c" + tntCount + "§7)", 1, lore, special);
if (special) specialMissiles.add(name);
}
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");
if (index > 0) { st.append(repeat(index));
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]");
@ -124,9 +121,10 @@ public class Missile extends SpecialItem {
} }
private int count() { private int count() {
EditSession e = WorldEdit.getInstance().getEditSessionFactory().getEditSession(world, -1); if (tnt.isEmpty()) {
BlockTypeMask blockTypeMask = new BlockTypeMask(clipboard, TNT); return 0;
return e.countBlocks(clipboard.getRegion(), blockTypeMask); }
return WorldEdit.getInstance().getEditSessionFactory().getEditSession(world, -1).countBlocks(clipboard.getRegion(), tnt);
} }
@Override @Override
@ -163,38 +161,16 @@ public class Missile extends SpecialItem {
return true; return true;
} }
@Override
public boolean isMissile() {
return true;
}
public static void init(){ public static void init(){
File missileFolder = new File(MissileWars.getPlugin().getDataFolder(), "default-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()) continue; if(!missileFile.canRead() || !missileFile.isFile())
new Missile(missileFile, false); continue;
new Missile(missileFile);
} }
} }
public static void randomInit() {
File missileFolder = new File(MissileWars.getPlugin().getDataFolder(), "missiles");
if (!missileFolder.exists() || !missileFolder.canRead() || !missileFolder.isDirectory()) {
return;
}
File[] files = missileFolder.listFiles();
if (files == null) return;
if (files.length < Config.MissileCount) return;
List<File> pool = new ArrayList<>(files.length);
pool.addAll(Arrays.asList(files));
for (int i = 0; i < Config.MissileCount; i++) {
File missileFile = pool.remove(r.nextInt(pool.size()));
if (!missileFile.canRead() || !missileFile.isFile()) continue;
new Missile(missileFile, true);
}
}
} }

Datei anzeigen

@ -19,11 +19,8 @@
package de.steamwar.misslewars.items; package de.steamwar.misslewars.items;
import de.steamwar.misslewars.Config;
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;
@ -33,58 +30,34 @@ public abstract class SpecialItem {
private static final Random random = new Random(); private static final Random random = new Random();
private static List<SpecialItem> supportItems = new ArrayList<>(); private static List<SpecialItem> items = new ArrayList<>();
private static List<SpecialItem> missileItems = new ArrayList<>();
SpecialItem() { SpecialItem(){
if (this.isMissile()) { items.add(this);
missileItems.add(this);
return;
}
supportItems.add(this);
} }
public abstract ItemStack getItem(); public abstract ItemStack getItem();
public abstract boolean handleUse(Player p); public abstract boolean handleUse(Player p);
public boolean isMissile() {
return false;
}
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.addUnsafeEnchantment(Enchantment.PROTECTION_FALL, 1);
return item; return item;
} }
public static boolean handleUse(ItemStack item, Player player) { public static boolean handleUse(ItemStack item, Player player){
for (SpecialItem missileItem : missileItems) { for(SpecialItem specialItem : items){
if (item.isSimilar(missileItem.getItem())) { if(item.isSimilar(specialItem.getItem())){
return missileItem.handleUse(player);
}
}
for (SpecialItem specialItem : supportItems) {
if (item.isSimilar(specialItem.getItem())) {
return specialItem.handleUse(player); return specialItem.handleUse(player);
} }
} }
return false; return false;
} }
public static ItemStack getRandomItem() { public static ItemStack getRandomItem(){
if (random.nextDouble() > Config.MissileChance) { return items.get(random.nextInt(items.size())).getItem();
return supportItems.get(random.nextInt(supportItems.size())).getItem();
} else {
return missileItems.get(random.nextInt(missileItems.size())).getItem();
}
} }
} }