Update1.0 #11
@ -4,6 +4,9 @@ ShieldFlyTime: 100
|
||||
PlatformTime: 30
|
||||
EndTime: 600
|
||||
|
||||
MissileCount: 4
|
||||
MissileChance: 0.6
|
||||
|
||||
Arena:
|
||||
MinX: 0
|
||||
MaxX: 0
|
||||
|
@ -29,7 +29,10 @@ import java.io.File;
|
||||
import java.util.logging.Level;
|
||||
|
||||
public class Config {
|
||||
private Config(){}
|
||||
|
||||
private Config() {
|
||||
|
||||
}
|
||||
|
||||
public static final int ArenaMinX;
|
||||
public static final int ArenaMaxX;
|
||||
@ -48,9 +51,12 @@ public class Config {
|
||||
public static final int ShieldFlyTime;
|
||||
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");
|
||||
if(!configfile.exists()){
|
||||
if (!configfile.exists()) {
|
||||
Bukkit.getLogger().log(Level.SEVERE, "Config fehlt!");
|
||||
Bukkit.shutdown();
|
||||
}
|
||||
@ -61,6 +67,8 @@ public class Config {
|
||||
ItemTime = config.getInt("ItemTime");
|
||||
ShieldFlyTime = config.getInt("ShieldFlyTime");
|
||||
EndTime = config.getInt("EndTime");
|
||||
MissileCount = config.getInt("MissileCount");
|
||||
MissileChance = config.getDouble("MissileChance");
|
||||
|
||||
ConfigurationSection arena = config.getConfigurationSection("Arena");
|
||||
assert arena != null;
|
||||
|
@ -19,6 +19,7 @@
|
||||
|
||||
package de.steamwar.misslewars;
|
||||
|
||||
import de.steamwar.misslewars.items.Missile;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.scoreboard.DisplaySlot;
|
||||
import org.bukkit.scoreboard.Objective;
|
||||
@ -31,19 +32,21 @@ import java.util.Objects;
|
||||
*/
|
||||
class FightScoreboard {
|
||||
|
||||
private FightScoreboard(){}
|
||||
private FightScoreboard() {
|
||||
|
||||
}
|
||||
|
||||
private static final Scoreboard scoreboard = Objects.requireNonNull(Bukkit.getScoreboardManager()).getMainScoreboard();
|
||||
private static final Objective objective;
|
||||
|
||||
static{
|
||||
if(scoreboard.getObjective("AAA") == null)
|
||||
static {
|
||||
if (scoreboard.getObjective("AAA") == null)
|
||||
objective = scoreboard.registerNewObjective("AAA", "BBB", "MissleWars");
|
||||
else
|
||||
objective = scoreboard.getObjective("AAA");
|
||||
}
|
||||
|
||||
static void init(){
|
||||
static void init() {
|
||||
Bukkit.getScheduler().scheduleSyncRepeatingTask(MissileWars.getPlugin(), () -> {
|
||||
objective.unregister();
|
||||
scoreboard.registerNewObjective("AAA", "BBB", "MissleWars");
|
||||
@ -52,17 +55,24 @@ class FightScoreboard {
|
||||
|
||||
teamScoreboard(MissileWars.getBlueTeam());
|
||||
teamScoreboard(MissileWars.getRedTeam());
|
||||
|
||||
specialMissiles();
|
||||
|
||||
Bukkit.getOnlinePlayers().forEach(player -> player.setScoreboard(scoreboard));
|
||||
}, 0, 200);
|
||||
}, 0, 50);
|
||||
}
|
||||
|
||||
static Scoreboard getScoreboard() {
|
||||
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));
|
||||
}
|
||||
|
||||
private static void specialMissiles() {
|
||||
objective.getScore("§3").setScore(0);
|
||||
for (String missile : Missile.specialMissiles) {
|
||||
objective.getScore("§e" + missile).setScore(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -19,7 +19,10 @@
|
||||
|
||||
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.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
@ -51,7 +54,7 @@ public class MWTeam {
|
||||
|
||||
private Set<Player> players = new HashSet<>();
|
||||
|
||||
public Set<Player> getPlayers(){
|
||||
public Set<Player> getPlayers() {
|
||||
return players;
|
||||
}
|
||||
|
||||
@ -73,11 +76,12 @@ public class MWTeam {
|
||||
return portalZ;
|
||||
}
|
||||
|
||||
public Location getSpawn(){
|
||||
public Location getSpawn() {
|
||||
return spawn;
|
||||
}
|
||||
|
||||
public void join (Player p) {
|
||||
@SuppressWarnings("java:S1874")
|
||||
public void join(Player p) {
|
||||
players.add(p);
|
||||
p.teleport(spawn);
|
||||
p.setGameMode(GameMode.SURVIVAL);
|
||||
@ -88,10 +92,9 @@ public class MWTeam {
|
||||
MissileWars.startRound();
|
||||
}
|
||||
|
||||
public void leave (Player p) {
|
||||
if(!players.contains(p))
|
||||
return;
|
||||
|
||||
@SuppressWarnings("java:S1874")
|
||||
public void leave(Player p) {
|
||||
if(!players.contains(p)) return;
|
||||
players.remove(p);
|
||||
sbteam.removePlayer(p);
|
||||
if (players.isEmpty() && MissileWars.getFightState() == FightState.FIGHTING)
|
||||
@ -105,7 +108,7 @@ public class MWTeam {
|
||||
return MissileWars.getRedTeam();
|
||||
}
|
||||
|
||||
public String getPrefix(){
|
||||
public String getPrefix() {
|
||||
return "§" + color.getChar();
|
||||
}
|
||||
|
||||
|
@ -19,6 +19,7 @@
|
||||
|
||||
package de.steamwar.misslewars;
|
||||
|
||||
import de.steamwar.misslewars.commands.CommandSpectate;
|
||||
import de.steamwar.misslewars.countdowns.EndCountdown;
|
||||
import de.steamwar.misslewars.countdowns.ItemCountdown;
|
||||
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 blueTeam;
|
||||
private static FightState fightState;
|
||||
private static long startTime; //timestamp when the fight starts
|
||||
|
||||
/**
|
||||
* create teams, ect
|
||||
@ -45,7 +45,6 @@ public class MissileWars extends JavaPlugin {
|
||||
public void onLoad() {
|
||||
plugin = this;
|
||||
fightState = FightState.WAITING;
|
||||
startTime = System.currentTimeMillis();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -62,6 +61,7 @@ public class MissileWars extends JavaPlugin {
|
||||
new WaitingListener();
|
||||
new FightListener();
|
||||
new ChatListener();
|
||||
getCommand("spectate").setExecutor(new CommandSpectate());
|
||||
|
||||
new WaitingCountdown();
|
||||
new ItemCountdown();
|
||||
@ -70,6 +70,7 @@ public class MissileWars extends JavaPlugin {
|
||||
FightScoreboard.init();
|
||||
|
||||
Missile.init();
|
||||
Missile.randomInit();
|
||||
new Arrows();
|
||||
new Fireball();
|
||||
new Shield();
|
||||
@ -87,8 +88,6 @@ public class MissileWars extends JavaPlugin {
|
||||
return;
|
||||
fightState = FightState.FIGHTING;
|
||||
StateDependent.setupState(fightState);
|
||||
|
||||
startTime = System.currentTimeMillis();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -102,7 +101,7 @@ public class MissileWars extends JavaPlugin {
|
||||
fightState = FightState.END;
|
||||
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.setGameMode(GameMode.SPECTATOR);
|
||||
}
|
||||
@ -126,15 +125,15 @@ public class MissileWars extends JavaPlugin {
|
||||
return fightState;
|
||||
}
|
||||
|
||||
public static MWTeam getRedTeam(){
|
||||
public static MWTeam getRedTeam() {
|
||||
return redTeam;
|
||||
}
|
||||
|
||||
public static MWTeam getBlueTeam(){
|
||||
public static MWTeam getBlueTeam() {
|
||||
return blueTeam;
|
||||
}
|
||||
|
||||
public static MWTeam getTeam(Player p){
|
||||
public static MWTeam getTeam(Player p) {
|
||||
if(blueTeam.hasPlayer(p))
|
||||
return blueTeam;
|
||||
if(redTeam.hasPlayer(p))
|
||||
@ -142,10 +141,18 @@ public class MissileWars extends JavaPlugin {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return seconds since start
|
||||
*/
|
||||
public static int getFightTime() {
|
||||
return Math.floorDiv((int) (System.currentTimeMillis() - startTime), 60);
|
||||
public static void join(Player p) {
|
||||
if (MissileWars.getTeam(p) != null) return;
|
||||
if (MissileWars.getRedTeam().getPlayers().size() < MissileWars.getBlueTeam().getPlayers().size()) {
|
||||
MissileWars.getRedTeam().join(p);
|
||||
} else {
|
||||
MissileWars.getBlueTeam().join(p);
|
||||
}
|
||||
}
|
||||
|
||||
public static void leave(Player p) {
|
||||
MissileWars.getBlueTeam().leave(p);
|
||||
MissileWars.getRedTeam().leave(p);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -37,7 +37,7 @@ public class SpawnPlatformCreator {
|
||||
private Block currentBlock;
|
||||
private int ticks;
|
||||
|
||||
public SpawnPlatformCreator(Player player){
|
||||
public SpawnPlatformCreator(Player player) {
|
||||
this.player = player;
|
||||
MWTeam team = MissileWars.getTeam(player);
|
||||
if(team == null)
|
||||
@ -49,31 +49,31 @@ public class SpawnPlatformCreator {
|
||||
task = Bukkit.getScheduler().runTaskTimer(MissileWars.getPlugin(), this::createPlatform, 0, 1);
|
||||
}
|
||||
|
||||
private void createPlatform(){
|
||||
private void createPlatform() {
|
||||
Location playerLoc = player.getLocation();
|
||||
playerLoc.setY(spawn.getY() - 1);
|
||||
|
||||
if(currentBlock == null || !currentBlock.getLocation().equals(playerLoc)){
|
||||
if(currentBlock != null){
|
||||
if(currentBlock.getType() == Material.OBSIDIAN)
|
||||
if (currentBlock == null || !currentBlock.getLocation().equals(playerLoc)) {
|
||||
if (currentBlock != null) {
|
||||
if (currentBlock.getType() == Material.OBSIDIAN)
|
||||
currentBlock.setType(Material.AIR);
|
||||
currentBlock = null;
|
||||
}
|
||||
|
||||
Block newBlock = playerLoc.getBlock();
|
||||
if(newBlock.getType() == Material.AIR){
|
||||
if (newBlock.getType() == Material.AIR) {
|
||||
newBlock.setType(Material.OBSIDIAN);
|
||||
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.spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText("Spawnplattform§8: §c§l" + String.format("%.2f", ticks / 20f) + "§8s"));
|
||||
|
||||
if(ticks == 0){
|
||||
if(currentBlock != null && currentBlock.getType() == Material.OBSIDIAN)
|
||||
if (ticks == 0) {
|
||||
if (currentBlock != null && currentBlock.getType() == Material.OBSIDIAN)
|
||||
currentBlock.setType(Material.AIR);
|
||||
|
||||
task.cancel();
|
||||
|
@ -28,7 +28,7 @@ public abstract class StateDependent {
|
||||
private final Set<FightState> active;
|
||||
private boolean running;
|
||||
|
||||
public StateDependent(final Set<FightState> active){
|
||||
public StateDependent(final Set<FightState> active) {
|
||||
this.active = active;
|
||||
running = false;
|
||||
listeners.add(this);
|
||||
@ -37,12 +37,12 @@ public abstract class StateDependent {
|
||||
public abstract void enable();
|
||||
public abstract void disable();
|
||||
|
||||
static void setupState(FightState state){
|
||||
for(StateDependent listener : listeners){
|
||||
if(listener.running && !listener.active.contains(state)){
|
||||
static void setupState(FightState state) {
|
||||
for (StateDependent listener : listeners) {
|
||||
if (listener.running && !listener.active.contains(state)) {
|
||||
listener.disable();
|
||||
listener.running = false;
|
||||
}else if(!listener.running && listener.active.contains(state)){
|
||||
} else if (!listener.running && listener.active.contains(state)) {
|
||||
listener.enable();
|
||||
listener.running = true;
|
||||
}
|
||||
|
56
src/de/steamwar/misslewars/commands/CommandSpectate.java
Normale Datei
56
src/de/steamwar/misslewars/commands/CommandSpectate.java
Normale Datei
@ -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;
|
||||
}
|
||||
|
||||
}
|
@ -42,9 +42,9 @@ public class EndCountdown extends StateDependent {
|
||||
}
|
||||
|
||||
private void kickPlayer(){
|
||||
if(Bukkit.getOnlinePlayers().isEmpty()){
|
||||
if (Bukkit.getOnlinePlayers().isEmpty()) {
|
||||
Bukkit.shutdown();
|
||||
}else{
|
||||
} else {
|
||||
Bukkit.getOnlinePlayers().iterator().next().kickPlayer(null);
|
||||
task = Bukkit.getScheduler().runTaskLater(MissileWars.getPlugin(), this::kickPlayer, 10);
|
||||
}
|
||||
@ -52,7 +52,6 @@ public class EndCountdown extends StateDependent {
|
||||
|
||||
@Override
|
||||
public void disable() {
|
||||
if(task != null && !task.isCancelled())
|
||||
task.cancel();
|
||||
if (task != null && !task.isCancelled()) task.cancel();
|
||||
}
|
||||
}
|
||||
|
@ -20,7 +20,6 @@
|
||||
package de.steamwar.misslewars.countdowns;
|
||||
|
||||
import de.steamwar.misslewars.*;
|
||||
import de.steamwar.misslewars.items.Missile;
|
||||
import de.steamwar.misslewars.items.SpecialItem;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
@ -29,7 +28,10 @@ import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
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 {
|
||||
|
||||
@ -40,22 +42,19 @@ public class ItemCountdown extends StateDependent {
|
||||
super(EnumSet.of(FightState.FIGHTING));
|
||||
}
|
||||
|
||||
private void run(){
|
||||
int items = Math.max(MissileWars.getBlueTeam().getPlayers().size(), MissileWars.getRedTeam().getPlayers().size());
|
||||
List<ItemStack> itemList = new ArrayList<>();
|
||||
private void run() {
|
||||
List<Player> blue = new ArrayList<>(MissileWars.getBlueTeam().getPlayers());
|
||||
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++) {
|
||||
itemList.add(SpecialItem.getRandomItem());
|
||||
}
|
||||
ItemStack itemStack = SpecialItem.getRandomItem();
|
||||
|
||||
giveTeamItem(MissileWars.getBlueTeam(), itemList);
|
||||
giveTeamItem(MissileWars.getRedTeam(), itemList);
|
||||
}
|
||||
|
||||
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);
|
||||
givePlayerItem(blue.get((i + randomOffsetBlue) % blue.size()), itemStack);
|
||||
givePlayerItem(red.get((i + randomOffsetRed) % red.size()), itemStack);
|
||||
}
|
||||
}
|
||||
|
||||
@ -88,7 +87,7 @@ public class ItemCountdown extends StateDependent {
|
||||
|
||||
@Override
|
||||
public void disable() {
|
||||
if(task != null && !task.isCancelled())
|
||||
task.cancel();
|
||||
if (task != null && !task.isCancelled()) task.cancel();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -36,4 +36,5 @@ public class Arrows extends SpecialItem {
|
||||
public boolean handleUse(Player p) {
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -44,4 +44,5 @@ public class Fireball extends SpecialItem {
|
||||
fb.setYield(3f);
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -76,4 +76,5 @@ public class LandingPad extends SpecialItem {
|
||||
editSession.flushSession();
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -36,4 +36,5 @@ public class Mine extends SpecialItem {
|
||||
public boolean handleUse(Player p) {
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -22,68 +22,49 @@ 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.extension.input.ParserContext;
|
||||
import com.sk89q.worldedit.extent.clipboard.Clipboard;
|
||||
import com.sk89q.worldedit.extent.clipboard.io.ClipboardFormat;
|
||||
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.math.BlockVector3;
|
||||
import com.sk89q.worldedit.math.transform.AffineTransform;
|
||||
import com.sk89q.worldedit.session.ClipboardHolder;
|
||||
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 io.netty.handler.logging.LogLevel;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.*;
|
||||
import java.util.logging.Level;
|
||||
|
||||
public class Missile extends SpecialItem {
|
||||
|
||||
private static final World world = new BukkitWorld(Bukkit.getWorlds().get(0));
|
||||
|
||||
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 static final BlockType TNT = BlockTypes.TNT;
|
||||
private static final int GRAPH_SIZE = 7;
|
||||
private static final Random r = new Random();
|
||||
public static final List<String> specialMissiles = new ArrayList<>();
|
||||
|
||||
private final Clipboard clipboard;
|
||||
private final ItemStack item;
|
||||
private final int tntCount;
|
||||
|
||||
private Missile(File missileFile){
|
||||
private Missile(File missileFile, boolean special) {
|
||||
String[] strings = missileFile.getName().split("\\.");
|
||||
String name = strings[0];
|
||||
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);
|
||||
|
||||
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);
|
||||
try {
|
||||
assert format != null;
|
||||
@ -92,21 +73,43 @@ public class Missile extends SpecialItem {
|
||||
throw new SecurityException("Corrupt missile");
|
||||
}
|
||||
|
||||
item = new ItemStack(itemType, 1);
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
assert meta != null;
|
||||
meta.setDisplayName("§c" + name);
|
||||
meta.setLore(lore);
|
||||
item.setItemMeta(meta);
|
||||
List<String> lore = new ArrayList<>();
|
||||
lore(lore, strings, 2, " §7Speed");
|
||||
lore(lore, strings, 3, " §7Size");
|
||||
int count;
|
||||
try {
|
||||
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) {
|
||||
if (index > size) index = size;
|
||||
private void lore(List<String> lore, String[] args, int index, String tag) {
|
||||
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();
|
||||
st.append("§8[§e");
|
||||
st.append(repeat(index));
|
||||
if (index > 0) {
|
||||
st.append(repeat(index));
|
||||
}
|
||||
st.append("§7");
|
||||
st.append(repeat(size - index));
|
||||
st.append(repeat(Missile.GRAPH_SIZE - index));
|
||||
st.append("§8]");
|
||||
return st.toString();
|
||||
}
|
||||
@ -121,19 +124,18 @@ public class Missile extends SpecialItem {
|
||||
}
|
||||
|
||||
private int count() {
|
||||
if (tnt.isEmpty()) {
|
||||
return 0;
|
||||
}
|
||||
return WorldEdit.getInstance().getEditSessionFactory().getEditSession(world, -1).countBlocks(clipboard.getRegion(), tnt);
|
||||
EditSession e = WorldEdit.getInstance().getEditSessionFactory().getEditSession(world, -1);
|
||||
BlockTypeMask blockTypeMask = new BlockTypeMask(clipboard, TNT);
|
||||
return e.countBlocks(clipboard.getRegion(), blockTypeMask);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getItem(){
|
||||
public ItemStack getItem() {
|
||||
return item;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handleUse(Player p){
|
||||
public boolean handleUse(Player p) {
|
||||
BlockVector3 dimensions = clipboard.getDimensions();
|
||||
Location location = p.getLocation();
|
||||
BlockVector3 v = BlockVector3.ZERO;
|
||||
@ -161,16 +163,37 @@ public class Missile extends SpecialItem {
|
||||
return true;
|
||||
}
|
||||
|
||||
public static void init(){
|
||||
File missileFolder = new File(MissileWars.getPlugin().getDataFolder(), "missiles");
|
||||
if(!missileFolder.exists() || !missileFolder.canRead() || !missileFolder.isDirectory()){
|
||||
@Override
|
||||
public boolean isMissile() {
|
||||
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");
|
||||
}
|
||||
for(File missileFile : Objects.requireNonNull(missileFolder.listFiles())){
|
||||
if(!missileFile.canRead() || !missileFile.isFile())
|
||||
continue;
|
||||
|
||||
new Missile(missileFile);
|
||||
for (File missileFile : Objects.requireNonNull(missileFolder.listFiles())) {
|
||||
if (!missileFile.canRead() || !missileFile.isFile()) continue;
|
||||
new Missile(missileFile, false);
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -36,4 +36,5 @@ public class Shield extends SpecialItem {
|
||||
public boolean handleUse(Player p) {
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -19,8 +19,11 @@
|
||||
|
||||
package de.steamwar.misslewars.items;
|
||||
|
||||
import de.steamwar.misslewars.Config;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemFlag;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
@ -30,34 +33,58 @@ public abstract class SpecialItem {
|
||||
|
||||
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(){
|
||||
items.add(this);
|
||||
SpecialItem() {
|
||||
if (this.isMissile()) {
|
||||
missileItems.add(this);
|
||||
return;
|
||||
}
|
||||
supportItems.add(this);
|
||||
}
|
||||
|
||||
public abstract ItemStack getItem();
|
||||
public abstract boolean handleUse(Player p);
|
||||
public boolean isMissile() {
|
||||
return false;
|
||||
}
|
||||
|
||||
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);
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
assert meta != null;
|
||||
meta.addItemFlags(ItemFlag.HIDE_ENCHANTS);
|
||||
meta.setLore(lore);
|
||||
meta.setDisplayName(name);
|
||||
item.setItemMeta(meta);
|
||||
if (special) item.addUnsafeEnchantment(Enchantment.PROTECTION_FALL, 1);
|
||||
return item;
|
||||
}
|
||||
|
||||
public static boolean handleUse(ItemStack item, Player player){
|
||||
for(SpecialItem specialItem : items){
|
||||
if(item.isSimilar(specialItem.getItem())){
|
||||
public static boolean handleUse(ItemStack item, Player player) {
|
||||
for (SpecialItem missileItem : missileItems) {
|
||||
if (item.isSimilar(missileItem.getItem())) {
|
||||
return missileItem.handleUse(player);
|
||||
}
|
||||
}
|
||||
for (SpecialItem specialItem : supportItems) {
|
||||
if (item.isSimilar(specialItem.getItem())) {
|
||||
return specialItem.handleUse(player);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static ItemStack getRandomItem(){
|
||||
return items.get(random.nextInt(items.size())).getItem();
|
||||
public static ItemStack getRandomItem() {
|
||||
if (random.nextDouble() > Config.MissileChance) {
|
||||
return supportItems.get(random.nextInt(supportItems.size())).getItem();
|
||||
} else {
|
||||
return missileItems.get(random.nextInt(missileItems.size())).getItem();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -48,42 +48,37 @@ public class ArenaListener extends BasicListener {
|
||||
Player p = e.getPlayer();
|
||||
|
||||
assert location != null;
|
||||
if(location.getY() < Config.ArenaMinY){
|
||||
if(p.getGameMode() == GameMode.SPECTATOR)
|
||||
if (location.getY() < Config.ArenaMinY) {
|
||||
if (p.getGameMode() == GameMode.SPECTATOR)
|
||||
p.teleport(e.getFrom());
|
||||
else if(MissileWars.getFightState() == FightState.WAITING)
|
||||
else if (MissileWars.getFightState() == FightState.WAITING)
|
||||
p.teleport(Objects.requireNonNull(MissileWars.getTeam(p)).getSpawn());
|
||||
else
|
||||
p.damage(20.0f);
|
||||
}else if(
|
||||
location.getX() < Config.ArenaMinX ||
|
||||
location.getX() > Config.ArenaMaxX ||
|
||||
location.getZ() < Config.ArenaMinZ ||
|
||||
location.getZ() > Config.ArenaMaxZ){
|
||||
} else if (location.getX() < Config.ArenaMinX || location.getX() > Config.ArenaMaxX || location.getZ() < Config.ArenaMinZ || location.getZ() > Config.ArenaMaxZ) {
|
||||
p.teleport(e.getFrom());
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onArrowPickup(PlayerPickupArrowEvent e){
|
||||
public void onArrowPickup(PlayerPickupArrowEvent e) {
|
||||
e.setCancelled(true);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onItemDrop(PlayerDropItemEvent e){
|
||||
public void onItemDrop(PlayerDropItemEvent e) {
|
||||
e.setCancelled(true);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onHunger(FoodLevelChangeEvent e){
|
||||
public void onHunger(FoodLevelChangeEvent e) {
|
||||
e.setCancelled(true);
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void onInventoryOpen(InventoryOpenEvent event) {
|
||||
if(event.getView().getType() != InventoryType.PLAYER &&
|
||||
event.getView().getType() != InventoryType.CRAFTING &&
|
||||
event.getView().getType() != InventoryType.CREATIVE)
|
||||
event.setCancelled(true);
|
||||
if(event.getView().getType() != InventoryType.PLAYER && event.getView().getType() != InventoryType.CRAFTING && event.getView().getType() != InventoryType.CREATIVE) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -31,17 +31,18 @@ import java.util.Set;
|
||||
public abstract class BasicListener extends StateDependent implements Listener {
|
||||
|
||||
|
||||
BasicListener(final Set<FightState> active){
|
||||
BasicListener(final Set<FightState> active) {
|
||||
super(active);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void enable(){
|
||||
public void enable() {
|
||||
Bukkit.getPluginManager().registerEvents(this, MissileWars.getPlugin());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void disable(){
|
||||
public void disable() {
|
||||
HandlerList.unregisterAll(this);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -33,8 +33,9 @@ public class ChatListener extends BasicListener {
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onChat(AsyncPlayerChatEvent e){
|
||||
public void onChat(AsyncPlayerChatEvent e) {
|
||||
Bukkit.broadcastMessage(e.getPlayer().getDisplayName() + "§8» §7" + e.getMessage());
|
||||
e.setCancelled(true);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -22,7 +22,6 @@ package de.steamwar.misslewars.listener;
|
||||
import de.steamwar.misslewars.FightState;
|
||||
import de.steamwar.misslewars.MissileWars;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
@ -32,7 +31,7 @@ import java.util.EnumSet;
|
||||
|
||||
public class ConnectionListener extends BasicListener{
|
||||
|
||||
public ConnectionListener(){
|
||||
public ConnectionListener() {
|
||||
super(EnumSet.allOf(FightState.class));
|
||||
}
|
||||
|
||||
@ -43,9 +42,7 @@ public class ConnectionListener extends BasicListener{
|
||||
|
||||
@EventHandler
|
||||
public void onLeave(PlayerQuitEvent e) {
|
||||
Player p = e.getPlayer();
|
||||
|
||||
MissileWars.getBlueTeam().leave(p);
|
||||
MissileWars.getRedTeam().leave(p);
|
||||
MissileWars.leave(e.getPlayer());
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -46,11 +46,12 @@ public class DeathListener extends BasicListener {
|
||||
@EventHandler
|
||||
public void onRespawn(PlayerRespawnEvent e){
|
||||
Player p = e.getPlayer();
|
||||
p.setFireTicks(0);
|
||||
MWTeam team = MissileWars.getTeam(p);
|
||||
if(team == null)
|
||||
return;
|
||||
if(team == null) return;
|
||||
|
||||
e.setRespawnLocation(team.getSpawn());
|
||||
new SpawnPlatformCreator(p);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -28,7 +28,7 @@ import java.util.EnumSet;
|
||||
|
||||
public class EndListener extends BasicListener {
|
||||
|
||||
public EndListener(){
|
||||
public EndListener() {
|
||||
super(EnumSet.of(FightState.END));
|
||||
}
|
||||
|
||||
@ -37,4 +37,5 @@ public class EndListener extends BasicListener {
|
||||
e.setJoinMessage(null);
|
||||
e.getPlayer().setGameMode(GameMode.SPECTATOR);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -34,14 +34,13 @@ public class FightListener extends BasicListener {
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onDamage(EntityDamageByEntityEvent e){
|
||||
if(!(e.getDamager() instanceof Player && e.getEntity() instanceof Player))
|
||||
return;
|
||||
public void onDamage(EntityDamageByEntityEvent e) {
|
||||
if (!(e.getDamager() instanceof Player && e.getEntity() instanceof Player)) return;
|
||||
|
||||
Player damager = (Player)e.getDamager();
|
||||
Player reciever = (Player)e.getEntity();
|
||||
|
||||
if(MissileWars.getTeam(damager) == MissileWars.getTeam(reciever))
|
||||
e.setCancelled(true);
|
||||
if (MissileWars.getTeam(damager) == MissileWars.getTeam(reciever)) e.setCancelled(true);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -84,13 +84,10 @@ public class ItemListener extends BasicListener {
|
||||
@EventHandler
|
||||
public void onItemClick(PlayerInteractEvent e) {
|
||||
ItemStack item = e.getItem();
|
||||
if (item == null)
|
||||
return;
|
||||
if (item == null) 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)
|
||||
return;
|
||||
|
||||
if(SpecialItem.handleUse(item, e.getPlayer())){
|
||||
if (SpecialItem.handleUse(item, e.getPlayer())) {
|
||||
item.setAmount(item.getAmount()-1);
|
||||
e.getPlayer().updateInventory();
|
||||
e.setCancelled(true);
|
||||
|
@ -29,16 +29,14 @@ import java.util.EnumSet;
|
||||
|
||||
public class JoinListener extends BasicListener {
|
||||
|
||||
public JoinListener(){
|
||||
public JoinListener() {
|
||||
super(EnumSet.of(FightState.WAITING, FightState.FIGHTING));
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
public void onJoin(PlayerJoinEvent e){
|
||||
if(MissileWars.getRedTeam().getPlayers().size() < MissileWars.getBlueTeam().getPlayers().size())
|
||||
MissileWars.getRedTeam().join(e.getPlayer());
|
||||
else
|
||||
MissileWars.getBlueTeam().join(e.getPlayer());
|
||||
public void onJoin(PlayerJoinEvent e) {
|
||||
MissileWars.join(e.getPlayer());
|
||||
e.setJoinMessage("§a» " + e.getPlayer().getDisplayName());
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -33,14 +33,14 @@ import java.util.EnumSet;
|
||||
|
||||
public class PortalDestructListener extends BasicListener {
|
||||
|
||||
public PortalDestructListener(){
|
||||
public PortalDestructListener() {
|
||||
super(EnumSet.of(FightState.FIGHTING));
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onBlockupdate(BlockPhysicsEvent e) {
|
||||
if (e.getBlock().getType() != Material.NETHER_PORTAL)
|
||||
return;
|
||||
if (e.getBlock().getType() != Material.NETHER_PORTAL) return;
|
||||
|
||||
int z = e.getBlock().getZ();
|
||||
if (z == MissileWars.getRedTeam().getPortalZ())
|
||||
MissileWars.end(WinReasons.PORTAL_DESTROYED, MissileWars.getBlueTeam());
|
||||
@ -49,14 +49,13 @@ public class PortalDestructListener extends BasicListener {
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onExplosion(EntityExplodeEvent e){
|
||||
if(e.getEntityType() != EntityType.FIREBALL)
|
||||
return;
|
||||
public void onExplosion(EntityExplodeEvent e) {
|
||||
if(e.getEntityType() != EntityType.FIREBALL) return;
|
||||
|
||||
double z = e.getLocation().getZ();
|
||||
double distRed = Math.abs(Config.RedPortalZ + 0.5 - z);
|
||||
double distBlue = Math.abs(Config.BluePortalZ + 0.5 - z);
|
||||
if(distRed < 2 || distBlue < 2)
|
||||
e.setCancelled(true);
|
||||
if(distRed < 2 || distBlue < 2) e.setCancelled(true);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -28,19 +28,18 @@ import org.bukkit.event.player.PlayerQuitEvent;
|
||||
import java.util.EnumSet;
|
||||
|
||||
public class WaitingListener extends BasicListener {
|
||||
|
||||
public WaitingListener() {
|
||||
super(EnumSet.of(FightState.WAITING));
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onDisconnect(PlayerQuitEvent e){
|
||||
if(Bukkit.getOnlinePlayers().isEmpty())
|
||||
Bukkit.shutdown();
|
||||
public void onDisconnect(PlayerQuitEvent e) {
|
||||
if(Bukkit.getOnlinePlayers().isEmpty()) Bukkit.shutdown();
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onDamage(EntityDamageEvent e){
|
||||
if(e.getCause() != EntityDamageEvent.DamageCause.VOID)
|
||||
e.setCancelled(true);
|
||||
public void onDamage(EntityDamageEvent e) {
|
||||
if(e.getCause() != EntityDamageEvent.DamageCause.VOID) e.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
@ -4,8 +4,11 @@ main: de.steamwar.misslewars.MissileWars
|
||||
authors:
|
||||
- Jan9103
|
||||
- Lixfel
|
||||
- YoyoNow
|
||||
version: "1.0"
|
||||
api-version: "1.13"
|
||||
depend:
|
||||
- WorldEdit
|
||||
- SpigotCore
|
||||
commands:
|
||||
spectate:
|
In neuem Issue referenzieren
Einen Benutzer sperren