SteamWar/MissileWars
Archiviert
13
0
Dieser Commit ist enthalten in:
Jan9103 2020-05-22 16:36:52 +02:00
Commit 4947ede7dd
18 geänderte Dateien mit 645 neuen und 0 gelöschten Zeilen

4
src/Doku.txt Normale Datei
Datei anzeigen

@ -0,0 +1,4 @@
Rot ist im süden
SpawnEgg name == MissleName (Config)
incl Color-Tags, ect
Missle-Configs sind für Team Rot

19
src/ToDo.txt Normale Datei
Datei anzeigen

@ -0,0 +1,19 @@
Commands:
join
leave
forcestop
Config:
Timeout-Time
Runden max length
shield / platform / ect item on/off
give-speed (default: 11)
Features
Items:
shield
platform
fireball
pfeile
bridge
Item-giver
am anfang bogen geben
listener + commadns registrieren

3
src/config.yml Normale Datei
Datei anzeigen

@ -0,0 +1,3 @@
portal:
red: -60
blue: 60

Datei anzeigen

@ -0,0 +1,28 @@
package de.steamwar.misslewars;
import java.util.TimerTask;
import org.bukkit.Bukkit;
public class EndTimer extends TimerTask{
private boolean endPrep; //if true it counts to end of preparing (after end server if not ingame); if false it counts to end of game -> win
public EndTimer(boolean endPrep) {
this.endPrep = endPrep;
}
@Override
public void run() {
if (endPrep) {
if (MissleWars.getFightState() != FightState.WAITING) return;
Bukkit.getServer().broadcastMessage("Da kein Gegner gefunden wurde schaltet der Server sich jetzt ab.");
Bukkit.getServer().shutdown();
}else {
if (MissleWars.getFightState() == FightState.END) return;
//TODO end match - unentschieden
}
this.cancel();
}
}

Datei anzeigen

@ -0,0 +1,78 @@
package de.steamwar.misslewars;
import de.steamwar.misslewars.MWTeam;
import org.bukkit.Bukkit;
import org.bukkit.scoreboard.DisplaySlot;
import org.bukkit.scoreboard.Objective;
import org.bukkit.scoreboard.Scoreboard;
import java.util.Objects;
/**
* Modified Version of the Fight-System Scoreboard
*/
public class FightScoreboard {
private FightScoreboard(){}
private static final Scoreboard scoreboard = Objects.requireNonNull(Bukkit.getScoreboardManager()).getMainScoreboard();
private static final Objective objective;
private static int index = 0;
static{
if(scoreboard.getObjective("AAA") == null)
//noinspection deprecation
objective = scoreboard.registerNewObjective("AAA", "BBB", "MissleWars");
else
objective = scoreboard.getObjective("AAA");
}
public static void init(){
Bukkit.getScheduler().scheduleSyncRepeatingTask(MissleWars.getPlugin(), () -> {
objective.unregister();
//noinspection deprecation
scoreboard.registerNewObjective("AAA", "BBB", "MissleWars");
objective.setDisplaySlot(DisplaySlot.SIDEBAR);
MWTeam fightTeam = getIndexDisplay();
if(fightTeam != null)
teamScoreboard(fightTeam);
else
generalScoreboard();
Bukkit.getOnlinePlayers().forEach(player -> player.setScoreboard(scoreboard));
}, 0, 200);
}
public static Scoreboard getScoreboard() {
return scoreboard;
}
private static void teamScoreboard(MWTeam fightTeam){
objective.setDisplayName(fightTeam.getColoredName());
fightTeam.getPlayers().forEach(fp -> {
objective.getScore(fightTeam.getPrefix() + fp.getPlayer().getName()).setScore((int) fp.getKills());
});
}
private static void generalScoreboard(){
objective.setDisplayName("§6Kampf");
int fightTime = MissleWars.getFightTime();
if (fightTime >= 60)
objective.getScore("§7Zeit: §a" + fightTime / 60 + "m " + fightTime % 60 + "s").setScore(3);
else
objective.getScore("§7Zeit: §a" + fightTime + "s").setScore(3);
}
private static MWTeam getIndexDisplay() {
index++;
if(index == 1)
return MissleWars.redTeam;
if(index == 2)
return MissleWars.blueTeam;
index = 0;
return null;
}
}

Datei anzeigen

@ -0,0 +1,7 @@
package de.steamwar.misslewars;
public enum FightState {
WAITING, //waiting for at least 2Players
FIGHTING, //no one has Won
END // fight ended for some reason
}

Datei anzeigen

@ -0,0 +1,24 @@
package de.steamwar.misslewars;
import org.bukkit.entity.Player;
public class MWPlayer {
private Player p;
private int kills = 0;
public int getKills() {
return kills;
}
public void addKill() {
kills++;
}
public MWPlayer (Player p) {
this.p = p;
}
public Player getPlayer() {
return p;
}
}

Datei anzeigen

@ -0,0 +1,89 @@
package de.steamwar.misslewars;
import java.util.ArrayList;
import java.util.List;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.bukkit.scoreboard.Team;
import org.bukkit.scoreboard.Team.Option;
import org.bukkit.scoreboard.Team.OptionStatus;
public class MWTeam {
private ChatColor color;
private String teamName;
private String prefix;
private Team sbteam; //scoreboard-Team
private ArrayList<MWPlayer> spieler = new ArrayList<MWPlayer>();
private Location spawn;
public List<MWPlayer> getPlayers(){
return spieler;
}
public MWTeam(ChatColor color, String teamName, String prefix) {
this.teamName = teamName;
this.prefix = prefix;
this.color = color;
if(FightScoreboard.getScoreboard().getTeam(teamName) == null)
sbteam = FightScoreboard.getScoreboard().registerNewTeam(teamName);
else
sbteam = FightScoreboard.getScoreboard().getTeam(teamName);
assert sbteam != null;
sbteam.setOption(Option.NAME_TAG_VISIBILITY, OptionStatus.FOR_OWN_TEAM);
sbteam.setAllowFriendlyFire(false);
}
public void tpToSpawn(Player p) {
p.teleport(spawn);
}
public void join (Player p) {
spieler.add(new MWPlayer(p));
p.setDisplayName(color + "[" + teamName + "]" + p.getName());
if (MissleWars.getFightState() == FightState.WAITING) {
if (!enemy().getPlayers().isEmpty())
MissleWars.startRound();
}
}
public void leave (Player p) {
for (MWPlayer pl : spieler) {
if (p == pl.getPlayer()) {
spieler.remove(pl);
break;
}
p.setDisplayName(p.getName());
}
if (spieler.isEmpty())
MissleWars.end(WinReasons.NOENEMY, enemy());
}
public MWTeam enemy() {
if (this == MissleWars.redTeam) return MissleWars.blueTeam;
return MissleWars.redTeam;
}
public String getPrefix(){
return prefix;
}
public boolean hasPlayer (Player p) {
for (MWPlayer pl : spieler)
if (p == pl.getPlayer())
return true;
return false;
}
public MWPlayer getPlayer (Player p) {
for (MWPlayer pl : spieler)
if (p == pl.getPlayer())
return pl;
return null;
}
public String getColoredName() {
return color.toString() + teamName;
}
}

Datei anzeigen

@ -0,0 +1,142 @@
package de.steamwar.misslewars;
import java.io.File;
import java.util.List;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.block.data.type.Piston;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.block.data.type.Observer;
public class MissleSpawnSystem {
public static Missle[] missles;
/**
* load Config, ect
*/
@SuppressWarnings("unchecked")
public static void load() {
FileConfiguration c = YamlConfiguration.loadConfiguration(new File(MissleWars.path + "/missles.yml"));
missles = ((List<Missle>) c.get("missles")).toArray(new Missle[0]);
}
public static void paste(String missle, boolean red, Location l) {
for (Missle m : missles) {
if (m.name == missle)
m.paste(l, red, red);
}
}
/**
* Missle-Schematic
*/
@SuppressWarnings("unused")
private class Missle{
public String name;
private byte height;
private byte depth;
private byte width;
private MissleBlockTypes[] blocks;
/**
*
* @param l Location of the spawning player
* @param redTeam for Block-color blue / red
* @param north facing north or south?
*/
public void paste(Location l, boolean redTeam, boolean north) {
byte a = 1;
if (!north) a = -1;
for (int x=0; x < width; x++) {
for (int y=height; y > 0; y--) {
for (int z=0; z < width; z++) {
int i = x+y*width+z*height*width;
if (i > blocks.length || i < 0) continue;
setBlock(blocks[i], MissleWars.world.getBlockAt(l.getBlockX() + x, l.getBlockY() + y, l.getBlockZ() + z * a), north, redTeam);
}
}
}
}
//bewusst mit blockupdate, damit observer, ect beim pasten triggern
private void setBlock(MissleBlockTypes t, Block b, boolean n, boolean red) {
if (t == MissleBlockTypes.GLASS) {
if (red)
b.setType(Material.RED_STAINED_GLASS);
else
b.setType(Material.BLUE_STAINED_GLASS);
}else if (t == MissleBlockTypes.BLOCK) {
if (red)
b.setType(Material.RED_CONCRETE);
else
b.setType(Material.BLUE_CONCRETE);
}else if (t == MissleBlockTypes.HONEY_BLOCK) {
b.setType(Material.HONEY_BLOCK);
}else if (t == MissleBlockTypes.PANE) {
if (red)
b.setType(Material.RED_STAINED_GLASS_PANE);
else
b.setType(Material.BLUE_STAINED_GLASS_PANE);
}else if (t == MissleBlockTypes.TNT) {
b.setType(Material.TNT);
}else if (t == MissleBlockTypes.SLIME_BLOCK) {
b.setType(Material.SLIME_BLOCK);
}else if (t.toString().contains("STICKY_PISTON")) {
b.setType(Material.STICKY_PISTON);
((Piston) b).setFacing(getFacing(t, n));
}else if (t.toString().contains("PISTON")) {
b.setType(Material.PISTON);
((Piston) b).setFacing(getFacing(t, n));
}else if (t.toString().contains("OBSERVER")) {
b.setType(Material.OBSERVER);
((Observer) b).setFacing(getFacing(t, n));
}
}
}
public BlockFace getFacing(MissleBlockTypes t, boolean north) {
String s = t.toString();
if (s.contains("UP")) return BlockFace.UP;
if (s.contains("DOWN")) return BlockFace.DOWN;
if ((s.contains("NORTH") && north) || (s.contains("SOUTH") && !north)) return BlockFace.NORTH;
if ((s.contains("NORTH") && !north) || (s.contains("SOUTH") && north)) return BlockFace.SOUTH;
if ((s.contains("WEST") && north) || (s.contains("EAST") && !north)) return BlockFace.WEST;
return BlockFace.EAST;
}
/**
* For Config & lowRAM save of missles
*/
private enum MissleBlockTypes {
PISTON_UP,
PISTON_DOWN,
PISTON_NORTH,
PISTON_SOUTH,
PISTON_EAST,
PISTON_WEST,
STICKY_PISTON_UP,
STICKY_PISTON_DOWN,
STICKY_PISTON_NORTH,
STICKY_PISTON_SOUTH,
STICKY_PISTON_WEST,
STICKY_PISTON_EAST,
GLASS, //teamcolored
BLOCK, //normal block, teamcolored
PANE, //teamcolored (glass-pane)
REDSTONE_BLOCK,
OBSERVER_UP,
OBSERVER_DOWN,
OBSERVER_NORTH,
OBSERVER_SOUTH,
OBSERVER_EAST,
OBSERVER_WEST,
SLIME_BLOCK,
HONEY_BLOCK,
TNT
}
}

Datei anzeigen

@ -0,0 +1,135 @@
package de.steamwar.misslewars;
import java.io.File;
import java.util.Timer;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.World;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.scheduler.BukkitRunnable;
public class MissleWars extends JavaPlugin {
public static World world;
private static MissleWars plugin;
public static MWTeam redTeam; //red has South side -> spawns missles towards north
public static MWTeam blueTeam;
public static int redPortalZ;
public static int bluePortalZ;
private static FightState fightstate;
private static long fightend; //timestamp when the fight ends
private static int rundenLaenge = 108000; //millis (108000 = 30mins)
private static int timeOut = 36000; //millis (36000 = 10min)
private static EndTimer timerClass;
private static int inspectionTime = 3600; //gameticks (3600 = 3min)
public static File path;
/**
* create teams, ect
*/
public void onLoad() {
path = getDataFolder();
plugin = this;
redTeam = new MWTeam(ChatColor.RED, "Rot", "Rot");
redTeam = new MWTeam(ChatColor.BLUE, "Blau", "Blau");
fightstate = FightState.WAITING;
fightend = System.currentTimeMillis() + timeOut;
MissleSpawnSystem.load();
}
/**
* start waiting for players timeout-timer
*/
public void onEnable() {
world = Bukkit.getServer().getWorlds().get(0);
timerClass = new EndTimer(true);
(new Timer()).schedule(timerClass, timeOut);
fightend = System.currentTimeMillis() + timeOut;
}
/**
* call to change fightstate from WAITING to INGAME
*/
public static void startRound() {
if (fightstate != FightState.WAITING) // anti dual-call
return;
if (timerClass != null) timerClass.cancel();
timerClass = new EndTimer(false);
(new Timer()).schedule(timerClass, rundenLaenge);
fightend = System.currentTimeMillis() + rundenLaenge;
}
/**
* @return how long did this round last so far
*/
public static long getRoundLength() {
return rundenLaenge - (fightend - System.currentTimeMillis());
//pflicht-ende-zeit - zeit bis zum pflicht-ende (pflicht-ende-timestamp - current-timestamp)
}
public static MissleWars getPlugin() {
return plugin;
}
public static FightState getFightState() {
return fightstate;
}
/**
* @return seconds left
*/
public static int getFightTime() {
return Math.floorDiv((int) (fightend - System.currentTimeMillis()), 60);
}
/**
* get the corresponding MWPlayer Object for a Player (if Player is ingame, otherwise returns null)
*/
public static MWPlayer getPlayer(Player p) {
MWPlayer pe = redTeam.getPlayer(p);
if (pe != null) return pe;
return blueTeam.getPlayer(p);
}
/**
* checks if a Bukkit-Player Object is in a team
*/
public static boolean playerInGame(Player p) {
return redTeam.hasPlayer(p) || blueTeam.hasPlayer(p);
}
/**
* Fight beenden
* @param reason Grund fürs ende
* @param winner Gewinner (oder null)
*/
public static void end(WinReasons reason, MWTeam winner) {
if (fightstate == FightState.END) //verhindern dass es mehrfach gecallt wird
return;
fightstate = FightState.END;
timerClass.cancel();
String winnerName = "Null";
if (winner == redTeam) winnerName = redTeam.getColoredName();
if (winner == blueTeam) winnerName = blueTeam.getColoredName();
switch (reason) {
case NOENEMY:
Bukkit.getServer().broadcastMessage("Ohne Gegner kein Kampf - Team " + winnerName + ChatColor.RESET + " hat gewonnen.");
break;
case PORTALDESTROYED:
Bukkit.getServer().broadcastMessage(winnerName + ChatColor.RESET + " hat das gegnerische Portal zerstört.");
break;
case TIMEOUT:
Bukkit.getServer().broadcastMessage("Kampf beendet: Unentschieden (Zeit abgelaufen).");
break;
default:
Bukkit.getServer().broadcastMessage("Kampf beendet.");
break;
}
new BukkitRunnable() {
public void run() {
Bukkit.getServer().shutdown();
}
}.runTaskLater(plugin, inspectionTime);
}
}

Datei anzeigen

@ -0,0 +1,7 @@
package de.steamwar.misslewars;
public enum WinReasons {
NOENEMY,
PORTALDESTROYED,
TIMEOUT
}

Datei anzeigen

@ -0,0 +1,5 @@
package de.steamwar.misslewars.commands;
public class JoinCommand {
}

Datei anzeigen

@ -0,0 +1,25 @@
package de.steamwar.misslewars.listener;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import de.steamwar.misslewars.MWPlayer;
import de.steamwar.misslewars.MissleWars;
import org.bukkit.event.entity.PlayerDeathEvent;
public class DeathListener implements Listener {
@EventHandler
public void onDeath(PlayerDeathEvent e) {
Player p = e.getEntity();
if (!MissleWars.playerInGame(p)) {
e.setDeathMessage("");
return;
}
Player killer = p.getKiller();
if (killer == null) return;
MWPlayer mwKiller = MissleWars.getPlayer(killer);
if (mwKiller != null) mwKiller.addKill();
}
}

Datei anzeigen

@ -0,0 +1,21 @@
package de.steamwar.misslewars.listener;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerInteractEvent;
import de.steamwar.misslewars.FightState;
import de.steamwar.misslewars.MissleSpawnSystem;
import de.steamwar.misslewars.MissleWars;
public class EggClickListener implements Listener {
@EventHandler
public void onItemClick(PlayerInteractEvent e) {
if (MissleWars.getFightState() != FightState.FIGHTING) return;
if (!MissleWars.playerInGame(e.getPlayer())) return;
if (!e.getItem().getType().toString().contains("SPAWN_EGG")) return;
MissleSpawnSystem.paste(e.getItem().getItemMeta().getDisplayName() , MissleWars.redTeam.hasPlayer(e.getPlayer()), e.getPlayer().getLocation());
e.getItem().setAmount(e.getItem().getAmount()-1);
e.setCancelled(true);
}
}

Datei anzeigen

@ -0,0 +1,15 @@
package de.steamwar.misslewars.listener;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerMoveEvent;
import de.steamwar.misslewars.MissleWars;
public class FallOutOfWorldListener implements Listener {
@EventHandler
public void onMove(PlayerMoveEvent e) {
if (!MissleWars.playerInGame(e.getPlayer())) return;
if (e.getPlayer().getEyeHeight() < 0) e.getPlayer().damage(Double.MAX_VALUE);
}
}

Datei anzeigen

@ -0,0 +1,13 @@
package de.steamwar.misslewars.listener;
import org.bukkit.GameMode;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent;
public class JoinListener implements Listener{
@EventHandler
public void onJoin(PlayerJoinEvent e) {
e.getPlayer().setGameMode(GameMode.SPECTATOR);
}
}

Datei anzeigen

@ -0,0 +1,22 @@
package de.steamwar.misslewars.listener;
import org.bukkit.Material;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockPhysicsEvent;
import de.steamwar.misslewars.MissleWars;
import de.steamwar.misslewars.WinReasons;
public class PortalDestructListener implements Listener {
@EventHandler
public void onBlockupdate(BlockPhysicsEvent e) {
if (e.getBlock().getType() != Material.NETHER_PORTAL)
return;
int z = e.getBlock().getZ();
if (z == MissleWars.redPortalZ)
MissleWars.end(WinReasons.PORTALDESTROYED, MissleWars.blueTeam);
if (z == MissleWars.bluePortalZ)
MissleWars.end(WinReasons.PORTALDESTROYED, MissleWars.blueTeam);
}
}

8
src/plugin.yml Normale Datei
Datei anzeigen

@ -0,0 +1,8 @@
name: MissleWars
prefix: MW
main: de.steamwar.misslewars
authors: [Jan9103]
version: 1.0
commands:
join:
leave: