SteamWar/MissileWars
Archiviert
13
0

Update1.0 #11

Geschlossen
YoyoNow möchte 11 Commits von Update1.0 nach master mergen
25 geänderte Dateien mit 91 neuen und 91 gelöschten Zeilen
Nur Änderungen aus Commit 8b2c67d8f3 werden angezeigt - Alle Commits anzeigen

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;
@ -51,9 +54,9 @@ public class Config {
public static final int MissileCount; public static final int MissileCount;
public static final double MissileChance; public static final double MissileChance;
static{ static {
File configfile = new File(Bukkit.getWorlds().get(0).getWorldFolder(), "config.yml"); File configfile = new File(Bukkit.getWorlds().get(0).getWorldFolder(), "config.yml");
if(!configfile.exists()){ if (!configfile.exists()) {
Bukkit.getLogger().log(Level.SEVERE, "Config fehlt!"); Bukkit.getLogger().log(Level.SEVERE, "Config fehlt!");
Bukkit.shutdown(); Bukkit.shutdown();
} }

Datei anzeigen

@ -32,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");
@ -63,7 +65,7 @@ class FightScoreboard {
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));
} }

Datei anzeigen

@ -54,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;
} }
@ -76,7 +76,7 @@ public class MWTeam {
return portalZ; return portalZ;
} }
public Location getSpawn(){ public Location getSpawn() {
return spawn; return spawn;
} }
@ -108,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

@ -61,7 +61,6 @@ public class MissileWars extends JavaPlugin {
new WaitingListener(); new WaitingListener();
new FightListener(); new FightListener();
new ChatListener(); new ChatListener();
new GamemodeListener();
getCommand("spectate").setExecutor(new CommandSpectate()); getCommand("spectate").setExecutor(new CommandSpectate());
new WaitingCountdown(); new WaitingCountdown();

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

@ -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

@ -42,7 +42,7 @@ public class ItemCountdown extends StateDependent {
super(EnumSet.of(FightState.FIGHTING)); super(EnumSet.of(FightState.FIGHTING));
} }
private void run(){ private void run() {
List<Player> blue = new ArrayList<>(MissileWars.getBlueTeam().getPlayers()); List<Player> blue = new ArrayList<>(MissileWars.getBlueTeam().getPlayers());
List<Player> red = new ArrayList<>(MissileWars.getBlueTeam().getPlayers()); List<Player> red = new ArrayList<>(MissileWars.getBlueTeam().getPlayers());
@ -87,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

@ -92,24 +92,24 @@ public class Missile extends SpecialItem {
private void lore(List<String> lore, String[] args, int index, String tag) { private void lore(List<String> lore, String[] args, int index, String tag) {
if (args.length > index) { if (args.length > index) {
try { try {
lore.add(graph(Integer.parseInt(args[index]), GRAPH_SIZE) + tag); lore.add(graph(Integer.parseInt(args[index])) + tag);
return; return;
} catch (NumberFormatException e) { } catch (NumberFormatException e) {
// Ignored // Ignored
} }
} }
lore.add(graph(0, GRAPH_SIZE) + tag); lore.add(graph(0) + tag);
} }
private String graph(int index, int size) { private String graph(int index) {
if (index > size) index = size; 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");
if (index > 0) { if (index > 0) {
st.append(repeat(index)); st.append(repeat(index));
} }
st.append("§7"); st.append("§7");
st.append(repeat(size - index)); st.append(repeat(Missile.GRAPH_SIZE - index));
st.append("§8]"); st.append("§8]");
return st.toString(); return st.toString();
} }
@ -130,12 +130,12 @@ public class Missile extends SpecialItem {
} }
@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;
@ -168,7 +168,7 @@ public class Missile extends SpecialItem {
return true; return true;
} }
public static void init(){ public static void init() {
File missileFolder = new File(MissileWars.getPlugin().getDataFolder(), "default-missiles"); File missileFolder = new File(MissileWars.getPlugin().getDataFolder(), "default-missiles");
if (!missileFolder.exists() || !missileFolder.canRead() || !missileFolder.isDirectory()) { if (!missileFolder.exists() || !missileFolder.canRead() || !missileFolder.isDirectory()) {
throw new SecurityException("Missiles could not be loaded"); throw new SecurityException("Missiles could not be loaded");

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

@ -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

@ -31,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));
} }

Datei anzeigen

@ -48,10 +48,10 @@ public class DeathListener extends BasicListener {
Player p = e.getPlayer(); Player p = e.getPlayer();
p.setFireTicks(0); 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,12 +29,12 @@ 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) {
MissileWars.join(e.getPlayer()); MissileWars.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);
} }
} }