SteamWar/MissileWars
Archiviert
13
0

Update1.0 #11

Geschlossen
YoyoNow möchte 11 Commits von Update1.0 nach master mergen
29 geänderte Dateien mit 322 neuen und 191 gelöschten Zeilen

Datei anzeigen

@ -4,6 +4,9 @@ ShieldFlyTime: 100
PlatformTime: 30 PlatformTime: 30
EndTime: 600 EndTime: 600
MissileCount: 4
MissileChance: 0.6
Arena: Arena:
MinX: 0 MinX: 0
MaxX: 0 MaxX: 0

Datei anzeigen

@ -29,7 +29,10 @@ import java.io.File;
import java.util.logging.Level; import java.util.logging.Level;
public class Config { public class Config {
private Config(){}
private Config() {
}
public static final int ArenaMinX; public static final int ArenaMinX;
public static final int ArenaMaxX; public static final int ArenaMaxX;
@ -48,9 +51,12 @@ public class Config {
public static final int ShieldFlyTime; public static final int ShieldFlyTime;
public static final int EndTime; public static final int EndTime;
static{ public static final int MissileCount;
public static final double MissileChance;
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()) {
Bukkit.getLogger().log(Level.SEVERE, "Config fehlt!"); Bukkit.getLogger().log(Level.SEVERE, "Config fehlt!");
Bukkit.shutdown(); Bukkit.shutdown();
} }
@ -61,6 +67,8 @@ 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,6 +19,7 @@
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;
@ -31,19 +32,21 @@ import java.util.Objects;
*/ */
class FightScoreboard { class FightScoreboard {
private FightScoreboard(){} private FightScoreboard() {
}
private static final Scoreboard scoreboard = Objects.requireNonNull(Bukkit.getScoreboardManager()).getMainScoreboard(); private static final Scoreboard scoreboard = Objects.requireNonNull(Bukkit.getScoreboardManager()).getMainScoreboard();
private static final Objective objective; private static final Objective objective;
static{ static {
if(scoreboard.getObjective("AAA") == null) if (scoreboard.getObjective("AAA") == null)
objective = scoreboard.registerNewObjective("AAA", "BBB", "MissleWars"); objective = scoreboard.registerNewObjective("AAA", "BBB", "MissleWars");
else else
objective = scoreboard.getObjective("AAA"); objective = scoreboard.getObjective("AAA");
} }
static void init(){ static void init() {
Bukkit.getScheduler().scheduleSyncRepeatingTask(MissileWars.getPlugin(), () -> { Bukkit.getScheduler().scheduleSyncRepeatingTask(MissileWars.getPlugin(), () -> {
objective.unregister(); objective.unregister();
scoreboard.registerNewObjective("AAA", "BBB", "MissleWars"); scoreboard.registerNewObjective("AAA", "BBB", "MissleWars");
@ -52,17 +55,24 @@ 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, 200); }, 0, 50);
} }
static Scoreboard getScoreboard() { static Scoreboard getScoreboard() {
return scoreboard; return scoreboard;
} }
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

@ -19,7 +19,10 @@
package de.steamwar.misslewars; package de.steamwar.misslewars;
import org.bukkit.*; import org.bukkit.ChatColor;
import org.bukkit.GameMode;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.enchantments.Enchantment; import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
@ -51,7 +54,7 @@ public class MWTeam {
private Set<Player> players = new HashSet<>(); private Set<Player> players = new HashSet<>();
public Set<Player> getPlayers(){ public Set<Player> getPlayers() {
return players; return players;
} }
@ -73,11 +76,12 @@ public class MWTeam {
return portalZ; return portalZ;
} }
public Location getSpawn(){ public Location getSpawn() {
return spawn; return spawn;
} }
public void join (Player p) { @SuppressWarnings("java:S1874")
public void join(Player p) {
players.add(p); players.add(p);
p.teleport(spawn); p.teleport(spawn);
p.setGameMode(GameMode.SURVIVAL); p.setGameMode(GameMode.SURVIVAL);
@ -88,10 +92,9 @@ public class MWTeam {
MissileWars.startRound(); MissileWars.startRound();
} }
public void leave (Player p) { @SuppressWarnings("java:S1874")
if(!players.contains(p)) public void leave(Player p) {
return; if(!players.contains(p)) return;
players.remove(p); players.remove(p);
sbteam.removePlayer(p); sbteam.removePlayer(p);
if (players.isEmpty() && MissileWars.getFightState() == FightState.FIGHTING) if (players.isEmpty() && MissileWars.getFightState() == FightState.FIGHTING)
@ -105,7 +108,7 @@ public class MWTeam {
return MissileWars.getRedTeam(); return MissileWars.getRedTeam();
} }
public String getPrefix(){ public String getPrefix() {
return "§" + color.getChar(); return "§" + color.getChar();
} }

Datei anzeigen

@ -19,6 +19,7 @@
package de.steamwar.misslewars; package de.steamwar.misslewars;
import de.steamwar.misslewars.commands.CommandSpectate;
import de.steamwar.misslewars.countdowns.EndCountdown; import de.steamwar.misslewars.countdowns.EndCountdown;
import de.steamwar.misslewars.countdowns.ItemCountdown; import de.steamwar.misslewars.countdowns.ItemCountdown;
import de.steamwar.misslewars.countdowns.WaitingCountdown; import de.steamwar.misslewars.countdowns.WaitingCountdown;
@ -36,7 +37,6 @@ public class MissileWars extends JavaPlugin {
private static MWTeam redTeam; //red has South side -> spawns missles towards north private static MWTeam redTeam; //red has South side -> spawns missles towards north
private static MWTeam blueTeam; private static MWTeam blueTeam;
private static FightState fightState; private static FightState fightState;
private static long startTime; //timestamp when the fight starts
/** /**
* create teams, ect * create teams, ect
@ -45,7 +45,6 @@ public class MissileWars extends JavaPlugin {
public void onLoad() { public void onLoad() {
plugin = this; plugin = this;
fightState = FightState.WAITING; fightState = FightState.WAITING;
startTime = System.currentTimeMillis();
} }
@Override @Override
@ -62,6 +61,7 @@ public class MissileWars extends JavaPlugin {
new WaitingListener(); new WaitingListener();
new FightListener(); new FightListener();
new ChatListener(); new ChatListener();
getCommand("spectate").setExecutor(new CommandSpectate());
new WaitingCountdown(); new WaitingCountdown();
new ItemCountdown(); new ItemCountdown();
@ -70,6 +70,7 @@ 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();
@ -87,8 +88,6 @@ public class MissileWars extends JavaPlugin {
return; return;
fightState = FightState.FIGHTING; fightState = FightState.FIGHTING;
StateDependent.setupState(fightState); StateDependent.setupState(fightState);
startTime = System.currentTimeMillis();
} }
/** /**
@ -102,7 +101,7 @@ public class MissileWars extends JavaPlugin {
fightState = FightState.END; fightState = FightState.END;
StateDependent.setupState(fightState); StateDependent.setupState(fightState);
for(Player player : Bukkit.getOnlinePlayers()){ for(Player player : Bukkit.getOnlinePlayers()) {
player.playSound(player.getLocation(), Sound.ENTITY_ENDER_DRAGON_DEATH, 100f, 1f); player.playSound(player.getLocation(), Sound.ENTITY_ENDER_DRAGON_DEATH, 100f, 1f);
player.setGameMode(GameMode.SPECTATOR); player.setGameMode(GameMode.SPECTATOR);
} }
@ -126,15 +125,15 @@ public class MissileWars extends JavaPlugin {
return fightState; return fightState;
} }
public static MWTeam getRedTeam(){ public static MWTeam getRedTeam() {
return redTeam; return redTeam;
} }
public static MWTeam getBlueTeam(){ public static MWTeam getBlueTeam() {
return blueTeam; return blueTeam;
} }
public static MWTeam getTeam(Player p){ public static MWTeam getTeam(Player p) {
if(blueTeam.hasPlayer(p)) if(blueTeam.hasPlayer(p))
return blueTeam; return blueTeam;
if(redTeam.hasPlayer(p)) if(redTeam.hasPlayer(p))
@ -142,10 +141,18 @@ public class MissileWars extends JavaPlugin {
return null; return null;
} }
/** public static void join(Player p) {
* @return seconds since start if (MissileWars.getTeam(p) != null) return;
*/ if (MissileWars.getRedTeam().getPlayers().size() < MissileWars.getBlueTeam().getPlayers().size()) {
public static int getFightTime() { MissileWars.getRedTeam().join(p);
return Math.floorDiv((int) (System.currentTimeMillis() - startTime), 60); } else {
MissileWars.getBlueTeam().join(p);
}
} }
public static void leave(Player p) {
MissileWars.getBlueTeam().leave(p);
MissileWars.getRedTeam().leave(p);
}
} }

Datei anzeigen

@ -37,7 +37,7 @@ public class SpawnPlatformCreator {
private Block currentBlock; private Block currentBlock;
private int ticks; private int ticks;
public SpawnPlatformCreator(Player player){ public SpawnPlatformCreator(Player player) {
this.player = player; this.player = player;
MWTeam team = MissileWars.getTeam(player); MWTeam team = MissileWars.getTeam(player);
if(team == null) if(team == null)
@ -49,31 +49,31 @@ public class SpawnPlatformCreator {
task = Bukkit.getScheduler().runTaskTimer(MissileWars.getPlugin(), this::createPlatform, 0, 1); task = Bukkit.getScheduler().runTaskTimer(MissileWars.getPlugin(), this::createPlatform, 0, 1);
} }
private void createPlatform(){ private void createPlatform() {
Location playerLoc = player.getLocation(); Location playerLoc = player.getLocation();
playerLoc.setY(spawn.getY() - 1); playerLoc.setY(spawn.getY() - 1);
if(currentBlock == null || !currentBlock.getLocation().equals(playerLoc)){ if (currentBlock == null || !currentBlock.getLocation().equals(playerLoc)) {
if(currentBlock != null){ if (currentBlock != null) {
if(currentBlock.getType() == Material.OBSIDIAN) if (currentBlock.getType() == Material.OBSIDIAN)
currentBlock.setType(Material.AIR); currentBlock.setType(Material.AIR);
currentBlock = null; currentBlock = null;
} }
Block newBlock = playerLoc.getBlock(); Block newBlock = playerLoc.getBlock();
if(newBlock.getType() == Material.AIR){ if (newBlock.getType() == Material.AIR) {
newBlock.setType(Material.OBSIDIAN); newBlock.setType(Material.OBSIDIAN);
currentBlock = newBlock; currentBlock = newBlock;
} }
} }
if(currentBlock != null && player.getLocation().getY() - 1 < currentBlock.getY()) if (currentBlock != null && player.getLocation().getY() - 1 < currentBlock.getY())
player.teleport(playerLoc.add(0, 1, 0)); player.teleport(playerLoc.add(0, 1, 0));
player.spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText("Spawnplattform§8: §c§l" + String.format("%.2f", ticks / 20f) + "§8s")); player.spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText("Spawnplattform§8: §c§l" + String.format("%.2f", ticks / 20f) + "§8s"));
if(ticks == 0){ if (ticks == 0) {
if(currentBlock != null && currentBlock.getType() == Material.OBSIDIAN) if (currentBlock != null && currentBlock.getType() == Material.OBSIDIAN)
currentBlock.setType(Material.AIR); currentBlock.setType(Material.AIR);
task.cancel(); task.cancel();

Datei anzeigen

@ -28,7 +28,7 @@ public abstract class StateDependent {
private final Set<FightState> active; private final Set<FightState> active;
private boolean running; private boolean running;
public StateDependent(final Set<FightState> active){ public StateDependent(final Set<FightState> active) {
this.active = active; this.active = active;
running = false; running = false;
listeners.add(this); listeners.add(this);
@ -37,12 +37,12 @@ public abstract class StateDependent {
public abstract void enable(); public abstract void enable();
public abstract void disable(); public abstract void disable();
static void setupState(FightState state){ static void setupState(FightState state) {
for(StateDependent listener : listeners){ for (StateDependent listener : listeners) {
if(listener.running && !listener.active.contains(state)){ if (listener.running && !listener.active.contains(state)) {
listener.disable(); listener.disable();
listener.running = false; listener.running = false;
}else if(!listener.running && listener.active.contains(state)){ } else if (!listener.running && listener.active.contains(state)) {
listener.enable(); listener.enable();
listener.running = true; listener.running = true;
} }

Datei anzeigen

@ -0,0 +1,56 @@
/*
This file is a part of the SteamWar software.
Copyright (C) 2020 SteamWar.de-Serverteam
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.steamwar.misslewars.commands;
import de.steamwar.misslewars.MWTeam;
import de.steamwar.misslewars.MissileWars;
import org.bukkit.GameMode;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
public class CommandSpectate implements CommandExecutor {
public boolean hasPermissions(Player p) {
if (p.hasPermission("bungeecore.group.admin")) return true;
if (p.hasPermission("bungeecore.group.developer")) return true;
if (p.hasPermission("bungeecore.group.moderator")) return true;
if (p.hasPermission("bungeecore.group.supporter")) return true;
if (p.hasPermission("bungeecore.group.builder")) return true;
if (p.hasPermission("bungeecore.group.youtuber")) return true;
return false;
}
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if(!(sender instanceof Player)) return false;
Player player = (Player) sender;
if (!hasPermissions(player)) return false;
MWTeam mwTeam = MissileWars.getTeam(player);
if (mwTeam == null) return false;
if (mwTeam.getPlayers().size() == 1) return false;
MissileWars.leave(player);
player.setGameMode(GameMode.SPECTATOR);
return true;
}
}

Datei anzeigen

@ -42,9 +42,9 @@ public class EndCountdown extends StateDependent {
} }
private void kickPlayer(){ private void kickPlayer(){
if(Bukkit.getOnlinePlayers().isEmpty()){ if (Bukkit.getOnlinePlayers().isEmpty()) {
Bukkit.shutdown(); Bukkit.shutdown();
}else{ } else {
Bukkit.getOnlinePlayers().iterator().next().kickPlayer(null); Bukkit.getOnlinePlayers().iterator().next().kickPlayer(null);
task = Bukkit.getScheduler().runTaskLater(MissileWars.getPlugin(), this::kickPlayer, 10); task = Bukkit.getScheduler().runTaskLater(MissileWars.getPlugin(), this::kickPlayer, 10);
} }
@ -52,7 +52,6 @@ public class EndCountdown extends StateDependent {
@Override @Override
public void disable() { public void disable() {
if(task != null && !task.isCancelled()) if (task != null && !task.isCancelled()) task.cancel();
task.cancel();
} }
} }

Datei anzeigen

@ -20,7 +20,6 @@
package de.steamwar.misslewars.countdowns; package de.steamwar.misslewars.countdowns;
import de.steamwar.misslewars.*; import de.steamwar.misslewars.*;
import de.steamwar.misslewars.items.Missile;
import de.steamwar.misslewars.items.SpecialItem; import de.steamwar.misslewars.items.SpecialItem;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Material; import org.bukkit.Material;
@ -29,7 +28,10 @@ import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.scheduler.BukkitTask; import org.bukkit.scheduler.BukkitTask;
import java.util.*; import java.util.ArrayList;
import java.util.EnumSet;
import java.util.List;
import java.util.Random;
public class ItemCountdown extends StateDependent { public class ItemCountdown extends StateDependent {
@ -40,22 +42,19 @@ public class ItemCountdown extends StateDependent {
super(EnumSet.of(FightState.FIGHTING)); super(EnumSet.of(FightState.FIGHTING));
} }
private void run(){ private void run() {
int items = Math.max(MissileWars.getBlueTeam().getPlayers().size(), MissileWars.getRedTeam().getPlayers().size()); List<Player> blue = new ArrayList<>(MissileWars.getBlueTeam().getPlayers());
List<ItemStack> itemList = new ArrayList<>(); List<Player> red = new ArrayList<>(MissileWars.getBlueTeam().getPlayers());
int items = Math.max(blue.size(), red.size());
int randomOffsetBlue = random.nextInt(blue.size());
int randomOffsetRed = random.nextInt(red.size());
for (int i = 0; i < items; i++) { for (int i = 0; i < items; i++) {
itemList.add(SpecialItem.getRandomItem()); ItemStack itemStack = SpecialItem.getRandomItem();
}
giveTeamItem(MissileWars.getBlueTeam(), itemList); givePlayerItem(blue.get((i + randomOffsetBlue) % blue.size()), itemStack);
giveTeamItem(MissileWars.getRedTeam(), itemList); givePlayerItem(red.get((i + randomOffsetRed) % red.size()), itemStack);
}
private void giveTeamItem(MWTeam team, List<ItemStack> itemList) {
List<ItemStack> itemStackList = new ArrayList<>(itemList);
for (Player p : team.getPlayers()) {
ItemStack itemStack = itemStackList.remove(random.nextInt(itemStackList.size()));
givePlayerItem(p, itemStack);
} }
} }
@ -88,7 +87,7 @@ public class ItemCountdown extends StateDependent {
@Override @Override
public void disable() { public void disable() {
if(task != null && !task.isCancelled()) if (task != null && !task.isCancelled()) task.cancel();
task.cancel();
} }
} }

Datei anzeigen

@ -36,4 +36,5 @@ public class Arrows extends SpecialItem {
public boolean handleUse(Player p) { public boolean handleUse(Player p) {
return false; return false;
} }
} }

Datei anzeigen

@ -44,4 +44,5 @@ public class Fireball extends SpecialItem {
fb.setYield(3f); fb.setYield(3f);
return true; return true;
} }
} }

Datei anzeigen

@ -76,4 +76,5 @@ public class LandingPad extends SpecialItem {
editSession.flushSession(); editSession.flushSession();
return true; return true;
} }
} }

Datei anzeigen

@ -36,4 +36,5 @@ public class Mine extends SpecialItem {
public boolean handleUse(Player p) { public boolean handleUse(Player p) {
return false; return false;
} }
} }

Datei anzeigen

@ -22,68 +22,49 @@ 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.BlockType;
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 Set<BaseBlock> tnt = new HashSet<>(); private static final int GRAPH_SIZE = 7;
private static final Random r = new Random();
static { public static final List<String> specialMissiles = new ArrayList<>();
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){ 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];
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,21 +73,43 @@ 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); int count;
meta.setLore(lore); try {
item.setItemMeta(meta); count = count();
} catch (Exception e) {
count = 0;
}
tntCount = count;
lore.add("§7TNT §8: §e" + tntCount);
item = createItem(itemType, "§c" + name, 1, lore, special);
if (special) specialMissiles.add(name);
} }
private String graph(int index, int size) { private void lore(List<String> lore, String[] args, int index, String tag) {
if (index > size) index = size; if (args.length > index) {
try {
lore.add(graph(Integer.parseInt(args[index])) + tag);
return;
} catch (NumberFormatException e) {
// Ignored
}
}
lore.add(graph(0) + tag);
}
private String graph(int index) {
if (index > Missile.GRAPH_SIZE) index = Missile.GRAPH_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(Missile.GRAPH_SIZE - index));
st.append("§8]"); st.append("§8]");
return st.toString(); return st.toString();
} }
@ -121,19 +124,18 @@ public class Missile extends SpecialItem {
} }
private int count() { private int count() {
if (tnt.isEmpty()) { EditSession e = WorldEdit.getInstance().getEditSessionFactory().getEditSession(world, -1);
return 0; BlockTypeMask blockTypeMask = new BlockTypeMask(clipboard, TNT);
} return e.countBlocks(clipboard.getRegion(), blockTypeMask);
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;
@ -161,16 +163,37 @@ public class Missile extends SpecialItem {
return true; return true;
} }
public static void init(){ @Override
File missileFolder = new File(MissileWars.getPlugin().getDataFolder(), "missiles"); public boolean isMissile() {
if(!missileFolder.exists() || !missileFolder.canRead() || !missileFolder.isDirectory()){ return true;
}
public static void init() {
File missileFolder = new File(MissileWars.getPlugin().getDataFolder(), "default-missiles");
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, false);
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<>(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

@ -36,4 +36,5 @@ public class Shield extends SpecialItem {
public boolean handleUse(Player p) { public boolean handleUse(Player p) {
return false; return false;
} }
} }

Datei anzeigen

@ -19,8 +19,11 @@
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;
@ -30,34 +33,58 @@ public abstract class SpecialItem {
private static final Random random = new Random(); private static final Random random = new Random();
private static List<SpecialItem> items = new ArrayList<>(); private static List<SpecialItem> supportItems = new ArrayList<>();
private static List<SpecialItem> missileItems = new ArrayList<>();
SpecialItem(){ SpecialItem() {
items.add(this); if (this.isMissile()) {
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 specialItem : items){ for (SpecialItem missileItem : missileItems) {
if(item.isSimilar(specialItem.getItem())){ if (item.isSimilar(missileItem.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() {
return items.get(random.nextInt(items.size())).getItem(); if (random.nextDouble() > Config.MissileChance) {
return supportItems.get(random.nextInt(supportItems.size())).getItem();
} else {
return missileItems.get(random.nextInt(missileItems.size())).getItem();
}
} }
} }

Datei anzeigen

@ -48,42 +48,37 @@ public class ArenaListener extends BasicListener {
Player p = e.getPlayer(); Player p = e.getPlayer();
assert location != null; assert location != null;
if(location.getY() < Config.ArenaMinY){ if (location.getY() < Config.ArenaMinY) {
if(p.getGameMode() == GameMode.SPECTATOR) if (p.getGameMode() == GameMode.SPECTATOR)
p.teleport(e.getFrom()); p.teleport(e.getFrom());
else if(MissileWars.getFightState() == FightState.WAITING) else if (MissileWars.getFightState() == FightState.WAITING)
p.teleport(Objects.requireNonNull(MissileWars.getTeam(p)).getSpawn()); p.teleport(Objects.requireNonNull(MissileWars.getTeam(p)).getSpawn());
else else
p.damage(20.0f); p.damage(20.0f);
}else if( } else if (location.getX() < Config.ArenaMinX || location.getX() > Config.ArenaMaxX || location.getZ() < Config.ArenaMinZ || location.getZ() > Config.ArenaMaxZ) {
location.getX() < Config.ArenaMinX ||
location.getX() > Config.ArenaMaxX ||
location.getZ() < Config.ArenaMinZ ||
location.getZ() > Config.ArenaMaxZ){
p.teleport(e.getFrom()); p.teleport(e.getFrom());
} }
} }
@EventHandler @EventHandler
public void onArrowPickup(PlayerPickupArrowEvent e){ public void onArrowPickup(PlayerPickupArrowEvent e) {
e.setCancelled(true); e.setCancelled(true);
} }
@EventHandler @EventHandler
public void onItemDrop(PlayerDropItemEvent e){ public void onItemDrop(PlayerDropItemEvent e) {
e.setCancelled(true); e.setCancelled(true);
} }
@EventHandler @EventHandler
public void onHunger(FoodLevelChangeEvent e){ public void onHunger(FoodLevelChangeEvent e) {
e.setCancelled(true); e.setCancelled(true);
} }
@EventHandler(ignoreCancelled = true) @EventHandler(ignoreCancelled = true)
public void onInventoryOpen(InventoryOpenEvent event) { public void onInventoryOpen(InventoryOpenEvent event) {
if(event.getView().getType() != InventoryType.PLAYER && if(event.getView().getType() != InventoryType.PLAYER && event.getView().getType() != InventoryType.CRAFTING && event.getView().getType() != InventoryType.CREATIVE) {
event.getView().getType() != InventoryType.CRAFTING && event.setCancelled(true);
event.getView().getType() != InventoryType.CREATIVE) }
event.setCancelled(true);
} }
} }

Datei anzeigen

@ -31,17 +31,18 @@ import java.util.Set;
public abstract class BasicListener extends StateDependent implements Listener { public abstract class BasicListener extends StateDependent implements Listener {
BasicListener(final Set<FightState> active){ BasicListener(final Set<FightState> active) {
super(active); super(active);
} }
@Override @Override
public void enable(){ public void enable() {
Bukkit.getPluginManager().registerEvents(this, MissileWars.getPlugin()); Bukkit.getPluginManager().registerEvents(this, MissileWars.getPlugin());
} }
@Override @Override
public void disable(){ public void disable() {
HandlerList.unregisterAll(this); HandlerList.unregisterAll(this);
} }
} }

Datei anzeigen

@ -33,8 +33,9 @@ public class ChatListener extends BasicListener {
} }
@EventHandler @EventHandler
public void onChat(AsyncPlayerChatEvent e){ public void onChat(AsyncPlayerChatEvent e) {
Bukkit.broadcastMessage(e.getPlayer().getDisplayName() + "§8» §7" + e.getMessage()); Bukkit.broadcastMessage(e.getPlayer().getDisplayName() + "§8» §7" + e.getMessage());
e.setCancelled(true); e.setCancelled(true);
} }
} }

Datei anzeigen

@ -22,7 +22,6 @@ package de.steamwar.misslewars.listener;
import de.steamwar.misslewars.FightState; import de.steamwar.misslewars.FightState;
import de.steamwar.misslewars.MissileWars; import de.steamwar.misslewars.MissileWars;
import org.bukkit.GameMode; import org.bukkit.GameMode;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority; import org.bukkit.event.EventPriority;
import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.event.player.PlayerJoinEvent;
@ -32,7 +31,7 @@ import java.util.EnumSet;
public class ConnectionListener extends BasicListener{ public class ConnectionListener extends BasicListener{
public ConnectionListener(){ public ConnectionListener() {
super(EnumSet.allOf(FightState.class)); super(EnumSet.allOf(FightState.class));
} }
@ -43,9 +42,7 @@ public class ConnectionListener extends BasicListener{
@EventHandler @EventHandler
public void onLeave(PlayerQuitEvent e) { public void onLeave(PlayerQuitEvent e) {
Player p = e.getPlayer(); MissileWars.leave(e.getPlayer());
MissileWars.getBlueTeam().leave(p);
MissileWars.getRedTeam().leave(p);
} }
} }

Datei anzeigen

@ -46,11 +46,12 @@ public class DeathListener extends BasicListener {
@EventHandler @EventHandler
public void onRespawn(PlayerRespawnEvent e){ public void onRespawn(PlayerRespawnEvent e){
Player p = e.getPlayer(); Player p = e.getPlayer();
p.setFireTicks(0);
MWTeam team = MissileWars.getTeam(p); MWTeam team = MissileWars.getTeam(p);
if(team == null) if(team == null) return;
return;
e.setRespawnLocation(team.getSpawn()); e.setRespawnLocation(team.getSpawn());
new SpawnPlatformCreator(p); new SpawnPlatformCreator(p);
} }
} }

Datei anzeigen

@ -28,7 +28,7 @@ import java.util.EnumSet;
public class EndListener extends BasicListener { public class EndListener extends BasicListener {
public EndListener(){ public EndListener() {
super(EnumSet.of(FightState.END)); super(EnumSet.of(FightState.END));
} }
@ -37,4 +37,5 @@ public class EndListener extends BasicListener {
e.setJoinMessage(null); e.setJoinMessage(null);
e.getPlayer().setGameMode(GameMode.SPECTATOR); e.getPlayer().setGameMode(GameMode.SPECTATOR);
} }
} }

Datei anzeigen

@ -34,14 +34,13 @@ public class FightListener extends BasicListener {
} }
@EventHandler @EventHandler
public void onDamage(EntityDamageByEntityEvent e){ public void onDamage(EntityDamageByEntityEvent e) {
if(!(e.getDamager() instanceof Player && e.getEntity() instanceof Player)) if (!(e.getDamager() instanceof Player && e.getEntity() instanceof Player)) return;
return;
Player damager = (Player)e.getDamager(); Player damager = (Player)e.getDamager();
Player reciever = (Player)e.getEntity(); Player reciever = (Player)e.getEntity();
if(MissileWars.getTeam(damager) == MissileWars.getTeam(reciever)) if (MissileWars.getTeam(damager) == MissileWars.getTeam(reciever)) e.setCancelled(true);
e.setCancelled(true);
} }
} }

Datei anzeigen

@ -84,13 +84,10 @@ public class ItemListener extends BasicListener {
@EventHandler @EventHandler
public void onItemClick(PlayerInteractEvent e) { public void onItemClick(PlayerInteractEvent e) {
ItemStack item = e.getItem(); ItemStack item = e.getItem();
if (item == null) if (item == null) return;
return; if (e.getAction() != Action.RIGHT_CLICK_BLOCK && e.getAction() != Action.RIGHT_CLICK_AIR) return;
if(e.getAction() != Action.RIGHT_CLICK_BLOCK && e.getAction() != Action.RIGHT_CLICK_AIR) if (SpecialItem.handleUse(item, e.getPlayer())) {
return;
if(SpecialItem.handleUse(item, e.getPlayer())){
item.setAmount(item.getAmount()-1); item.setAmount(item.getAmount()-1);
e.getPlayer().updateInventory(); e.getPlayer().updateInventory();
e.setCancelled(true); e.setCancelled(true);

Datei anzeigen

@ -29,16 +29,14 @@ import java.util.EnumSet;
public class JoinListener extends BasicListener { public class JoinListener extends BasicListener {
public JoinListener(){ public JoinListener() {
super(EnumSet.of(FightState.WAITING, FightState.FIGHTING)); super(EnumSet.of(FightState.WAITING, FightState.FIGHTING));
} }
@EventHandler(priority = EventPriority.HIGHEST) @EventHandler(priority = EventPriority.HIGHEST)
public void onJoin(PlayerJoinEvent e){ public void onJoin(PlayerJoinEvent e) {
if(MissileWars.getRedTeam().getPlayers().size() < MissileWars.getBlueTeam().getPlayers().size()) MissileWars.join(e.getPlayer());
MissileWars.getRedTeam().join(e.getPlayer());
else
MissileWars.getBlueTeam().join(e.getPlayer());
e.setJoinMessage("§a» " + e.getPlayer().getDisplayName()); e.setJoinMessage("§a» " + e.getPlayer().getDisplayName());
} }
} }

Datei anzeigen

@ -33,14 +33,14 @@ import java.util.EnumSet;
public class PortalDestructListener extends BasicListener { public class PortalDestructListener extends BasicListener {
public PortalDestructListener(){ public PortalDestructListener() {
super(EnumSet.of(FightState.FIGHTING)); super(EnumSet.of(FightState.FIGHTING));
} }
@EventHandler @EventHandler
public void onBlockupdate(BlockPhysicsEvent e) { public void onBlockupdate(BlockPhysicsEvent e) {
if (e.getBlock().getType() != Material.NETHER_PORTAL) if (e.getBlock().getType() != Material.NETHER_PORTAL) return;
return;
int z = e.getBlock().getZ(); int z = e.getBlock().getZ();
if (z == MissileWars.getRedTeam().getPortalZ()) if (z == MissileWars.getRedTeam().getPortalZ())
MissileWars.end(WinReasons.PORTAL_DESTROYED, MissileWars.getBlueTeam()); MissileWars.end(WinReasons.PORTAL_DESTROYED, MissileWars.getBlueTeam());
@ -49,14 +49,13 @@ public class PortalDestructListener extends BasicListener {
} }
@EventHandler @EventHandler
public void onExplosion(EntityExplodeEvent e){ public void onExplosion(EntityExplodeEvent e) {
if(e.getEntityType() != EntityType.FIREBALL) if(e.getEntityType() != EntityType.FIREBALL) return;
return;
double z = e.getLocation().getZ(); double z = e.getLocation().getZ();
double distRed = Math.abs(Config.RedPortalZ + 0.5 - z); double distRed = Math.abs(Config.RedPortalZ + 0.5 - z);
double distBlue = Math.abs(Config.BluePortalZ + 0.5 - z); double distBlue = Math.abs(Config.BluePortalZ + 0.5 - z);
if(distRed < 2 || distBlue < 2) if(distRed < 2 || distBlue < 2) e.setCancelled(true);
e.setCancelled(true);
} }
} }

Datei anzeigen

@ -28,19 +28,18 @@ import org.bukkit.event.player.PlayerQuitEvent;
import java.util.EnumSet; import java.util.EnumSet;
public class WaitingListener extends BasicListener { public class WaitingListener extends BasicListener {
public WaitingListener() { public WaitingListener() {
super(EnumSet.of(FightState.WAITING)); super(EnumSet.of(FightState.WAITING));
} }
@EventHandler @EventHandler
public void onDisconnect(PlayerQuitEvent e){ public void onDisconnect(PlayerQuitEvent e) {
if(Bukkit.getOnlinePlayers().isEmpty()) if(Bukkit.getOnlinePlayers().isEmpty()) Bukkit.shutdown();
Bukkit.shutdown();
} }
@EventHandler @EventHandler
public void onDamage(EntityDamageEvent e){ public void onDamage(EntityDamageEvent e) {
if(e.getCause() != EntityDamageEvent.DamageCause.VOID) if(e.getCause() != EntityDamageEvent.DamageCause.VOID) e.setCancelled(true);
e.setCancelled(true);
} }
} }

Datei anzeigen

@ -4,8 +4,11 @@ main: de.steamwar.misslewars.MissileWars
authors: authors:
- Jan9103 - Jan9103
- Lixfel - Lixfel
- YoyoNow
version: "1.0" version: "1.0"
api-version: "1.13" api-version: "1.13"
depend: depend:
- WorldEdit - WorldEdit
- SpigotCore - SpigotCore
commands:
spectate: