YEAH its kinda working
This commit is contained in:
@ -2,9 +2,11 @@ package com.pobnellion.floorGame;
|
||||
|
||||
import com.pobnellion.floorGame.command.CommandFloorGame;
|
||||
import com.pobnellion.floorGame.command.TabCompleterFloorGame;
|
||||
import com.pobnellion.floorGame.game.FallListener;
|
||||
import com.pobnellion.floorGame.game.GameConfig;
|
||||
import com.pobnellion.floorGame.game.GameInstance;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
@ -25,6 +27,9 @@ public final class FloorGame extends JavaPlugin {
|
||||
// Register commands
|
||||
this.getCommand("floorgame").setExecutor(new CommandFloorGame());
|
||||
this.getCommand("floorgame").setTabCompleter(new TabCompleterFloorGame());
|
||||
|
||||
// Register events
|
||||
getServer().getPluginManager().registerEvents(new FallListener(), this);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -52,6 +57,24 @@ public final class FloorGame extends JavaPlugin {
|
||||
return false;
|
||||
}
|
||||
|
||||
public static boolean IsGameRunning() {
|
||||
return gameInstance != null;
|
||||
}
|
||||
|
||||
public static boolean IsPlayerInGame(Player player) {
|
||||
return gameInstance != null && gameInstance.IsPlayerInGame(player);
|
||||
}
|
||||
|
||||
public static boolean PlayerInFallArea(Player player) {
|
||||
return gameInstance != null &&
|
||||
gameInstance.GetFallArea().IsInBounds(player.getLocation());
|
||||
}
|
||||
|
||||
public static void PlayerFell(Player player) {
|
||||
if (gameInstance != null)
|
||||
gameInstance.PlayerFell(player);
|
||||
}
|
||||
|
||||
public static void SaveConfig() {
|
||||
instance.saveConfig();
|
||||
}
|
||||
|
||||
@ -2,7 +2,7 @@ package com.pobnellion.floorGame.command;
|
||||
|
||||
import com.pobnellion.floorGame.FloorGame;
|
||||
import com.pobnellion.floorGame.game.GameConfig;
|
||||
import com.pobnellion.floorGame.Util;
|
||||
import com.pobnellion.floorGame.util.Util;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.command.Command;
|
||||
|
||||
@ -0,0 +1,14 @@
|
||||
package com.pobnellion.floorGame.game;
|
||||
|
||||
import com.pobnellion.floorGame.FloorGame;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerMoveEvent;
|
||||
|
||||
public class FallListener implements Listener {
|
||||
@EventHandler
|
||||
public void onPlayerMove(PlayerMoveEvent event) {
|
||||
if (FloorGame.IsPlayerInGame(event.getPlayer()) && FloorGame.PlayerInFallArea(event.getPlayer()))
|
||||
FloorGame.PlayerFell(event.getPlayer());
|
||||
}
|
||||
}
|
||||
@ -1,24 +1,24 @@
|
||||
package com.pobnellion.floorGame.game;
|
||||
|
||||
import com.pobnellion.floorGame.Util;
|
||||
import org.bukkit.Bukkit;
|
||||
import com.pobnellion.floorGame.util.Area;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Random;
|
||||
import java.util.logging.Level;
|
||||
|
||||
public class Floor {
|
||||
private final Location xzCorner;
|
||||
public int tileSize;
|
||||
public int gridSize;
|
||||
public Material[] colours;
|
||||
public Area fallArea;
|
||||
private final Material[][] colourGrid;
|
||||
public boolean isDropped = false;
|
||||
|
||||
public Floor(Location center, int tileSize, int gridSize, Material[] availableColours) {
|
||||
this.xzCorner = center.subtract(tileSize * gridSize * 0.5, 0, tileSize * gridSize * 0.5);
|
||||
this.xzCorner = center.clone().subtract(tileSize * gridSize * 0.5, 0, tileSize * gridSize * 0.5);
|
||||
this.tileSize = tileSize;
|
||||
this.gridSize = gridSize;
|
||||
|
||||
@ -36,6 +36,9 @@ public class Floor {
|
||||
}
|
||||
|
||||
colours = colourSet.toArray(new Material[0]);
|
||||
fallArea = new Area(
|
||||
xzCorner.clone().add(-10, -20, -10),
|
||||
xzCorner.clone().add(gridSize * tileSize + 10, -15, gridSize * tileSize + 10));
|
||||
}
|
||||
|
||||
public void Init() {
|
||||
@ -44,11 +47,10 @@ public class Floor {
|
||||
}
|
||||
|
||||
public void Reset() {
|
||||
isDropped = false;
|
||||
for (int row = 0; row < gridSize; row++) {
|
||||
for (int col = 0; col < gridSize; col++) {
|
||||
FillTile(xzCorner.getBlockX() + row * tileSize,
|
||||
xzCorner.getBlockZ() + col * tileSize,
|
||||
colourGrid[row][col]);
|
||||
FillTile(row, col, colourGrid[row][col]);
|
||||
}
|
||||
}
|
||||
FillWalls(xzCorner.getBlockY() + 2, xzCorner.getBlockY() + 4, Material.BARRIER);
|
||||
@ -70,24 +72,29 @@ public class Floor {
|
||||
FillWalls(xzCorner.getBlockY() + 2, xzCorner.getBlockY() + 4, material);
|
||||
}
|
||||
|
||||
public void SoloTile(Material material) {
|
||||
public void Drop(Material material) {
|
||||
isDropped = true;
|
||||
for (int row = 0; row < gridSize; row++) {
|
||||
for (int col = 0; col < gridSize; col++) {
|
||||
if (colourGrid[row][col] != material)
|
||||
FillTile(xzCorner.getBlockX() + row * tileSize,
|
||||
xzCorner.getBlockZ() + col * tileSize,
|
||||
Material.AIR);
|
||||
FillTile(row , col, Material.AIR);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void FillTile(int xMin, int zMin, Material material) {
|
||||
FillArea(xzCorner.getWorld(), xMin, xzCorner.getBlockY(), zMin,
|
||||
xMin + tileSize, xzCorner.getBlockY(), zMin + tileSize, material);
|
||||
private void FillTile(int gridRow, int gridCol, Material material) {
|
||||
FillArea(xzCorner.getWorld(),
|
||||
xzCorner.getBlockX() + gridRow * tileSize,
|
||||
xzCorner.getBlockY(),
|
||||
xzCorner.getBlockZ() + gridCol * tileSize,
|
||||
xzCorner.getBlockX() + gridRow * tileSize + tileSize,
|
||||
xzCorner.getBlockY(),
|
||||
xzCorner.getBlockZ() + gridCol * tileSize + tileSize,
|
||||
material);
|
||||
}
|
||||
|
||||
private void FillWalls(int yMin, int yMax, Material material) {
|
||||
var floorSize = tileSize * gridSize + 1;
|
||||
var floorSize = tileSize * gridSize;
|
||||
FillArea(xzCorner.getWorld(),
|
||||
xzCorner.getBlockX() - 1,
|
||||
yMin,
|
||||
@ -112,23 +119,27 @@ public class Floor {
|
||||
xzCorner.getBlockZ() - 1,
|
||||
xzCorner.getBlockX() + floorSize,
|
||||
yMax,
|
||||
xzCorner.getBlockX() + floorSize,
|
||||
xzCorner.getBlockZ() + floorSize,
|
||||
material);
|
||||
|
||||
FillArea(xzCorner.getWorld(),
|
||||
xzCorner.getBlockX() + -1,
|
||||
xzCorner.getBlockX() -1,
|
||||
yMin,
|
||||
xzCorner.getBlockZ() + floorSize,
|
||||
xzCorner.getBlockX() + floorSize,
|
||||
yMax,
|
||||
xzCorner.getBlockX() + floorSize,
|
||||
xzCorner.getBlockZ() + floorSize + 1,
|
||||
material);
|
||||
}
|
||||
|
||||
private void FillArea(World world, int xMin, int yMin, int zMin, int xMax, int yMax, int zMax, Material material) {
|
||||
for (int x = xMin; x <= xMax; x++) {
|
||||
for (int y = yMin; y <= yMax; y++) {
|
||||
for (int z = zMin; z <= zMax; z++) {
|
||||
if (xMin == xMax) xMax++;
|
||||
if (yMin == yMax) yMax++;
|
||||
if (zMin == zMax) zMax++;
|
||||
|
||||
for (int x = xMin; x < xMax; x++) {
|
||||
for (int y = yMin; y < yMax; y++) {
|
||||
for (int z = zMin; z < zMax; z++) {
|
||||
world.getBlockAt(x, y, z).setType(material);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,6 +1,8 @@
|
||||
package com.pobnellion.floorGame.game;
|
||||
|
||||
import com.pobnellion.floorGame.FloorGame;
|
||||
import com.pobnellion.floorGame.util.Area;
|
||||
import com.pobnellion.floorGame.util.Util;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
@ -19,8 +21,8 @@ public class GameConfig {
|
||||
private static final Map<Material, String> availableColours = new HashMap<>();
|
||||
private Location postGameTpLocation;
|
||||
private Location floorCenter;
|
||||
private final Location[] playerJoinArea = new Location[2];
|
||||
private final Location[] spectatorJoinArea= new Location[2];
|
||||
private Area playerJoinArea;
|
||||
private Area spectatorJoinArea;
|
||||
private World world;
|
||||
|
||||
public GameConfig() {
|
||||
@ -37,10 +39,9 @@ public class GameConfig {
|
||||
|
||||
this.postGameTpLocation = ParseLocation(world, FloorGame.config.getString("postGameTpLocation"));
|
||||
this.floorCenter = ParseLocation(world, FloorGame.config.getString("floorCenter"));
|
||||
this.playerJoinArea[0] = ParseLocation(world, playerJoinArea.get(0));
|
||||
this.playerJoinArea[1] = ParseLocation(world, playerJoinArea.get(1));
|
||||
this.spectatorJoinArea[0] = ParseLocation(world, spectatorJoinArea.get(0));
|
||||
this.spectatorJoinArea[1] = ParseLocation(world, spectatorJoinArea.get(1));
|
||||
|
||||
this.playerJoinArea = new Area(ParseLocation(world, playerJoinArea.get(0)), ParseLocation(world, playerJoinArea.get(1)));
|
||||
this.spectatorJoinArea = new Area(ParseLocation(world, spectatorJoinArea.get(0)), ParseLocation(world, spectatorJoinArea.get(1)));
|
||||
|
||||
var coloursSection = FloorGame.config.getConfigurationSection("availableColours");
|
||||
|
||||
@ -132,7 +133,7 @@ public class GameConfig {
|
||||
}
|
||||
|
||||
public Material[] getAvailableColours() {
|
||||
return availableColours.values().toArray(new Material[0]);
|
||||
return availableColours.keySet().toArray(new Material[0]);
|
||||
}
|
||||
|
||||
public Location getFloorCenter() {
|
||||
@ -143,7 +144,7 @@ public class GameConfig {
|
||||
if (floorCenter.getWorld() == null)
|
||||
floorCenter.setWorld(world);
|
||||
this.floorCenter = floorCenter;
|
||||
FloorGame.config.set("floorCenter", FormatBlockLocation(floorCenter));
|
||||
FloorGame.config.set("floorCenter", Util.PrintBlockLocation(floorCenter));
|
||||
FloorGame.SaveConfig();
|
||||
}
|
||||
|
||||
@ -153,25 +154,23 @@ public class GameConfig {
|
||||
FloorGame.SaveConfig();
|
||||
}
|
||||
|
||||
public Location[] getPlayerJoinArea() {
|
||||
public Area getPlayerJoinArea() {
|
||||
return playerJoinArea;
|
||||
}
|
||||
|
||||
public void setPlayerJoinArea(Location l1, Location l2) {
|
||||
playerJoinArea[0] = l1;
|
||||
playerJoinArea[1] = l2;
|
||||
FloorGame.config.set("playerJoinArea", playerJoinArea);
|
||||
playerJoinArea = new Area(l1, l2);
|
||||
FloorGame.config.set("playerJoinArea", List.of(Util.PrintBlockLocation(playerJoinArea.min), Util.PrintBlockLocation(playerJoinArea.max)));
|
||||
FloorGame.SaveConfig();
|
||||
}
|
||||
|
||||
public Location[] getSpectatorJoinArea() {
|
||||
public Area getSpectatorJoinArea() {
|
||||
return spectatorJoinArea;
|
||||
}
|
||||
|
||||
public void setSpectatorJoinArea(Location l1, Location l2) {
|
||||
spectatorJoinArea[0] = l1;
|
||||
spectatorJoinArea[1] = l2;
|
||||
FloorGame.config.set("spectatorJoinArea", spectatorJoinArea);
|
||||
spectatorJoinArea = new Area(l1, l2);
|
||||
FloorGame.config.set("spectatorJoinArea", List.of(Util.PrintBlockLocation(spectatorJoinArea.min), Util.PrintBlockLocation(spectatorJoinArea.max)));
|
||||
FloorGame.SaveConfig();
|
||||
}
|
||||
|
||||
@ -181,11 +180,7 @@ public class GameConfig {
|
||||
|
||||
public void setPostGameTpLocation(Location postGameTpLocation) {
|
||||
this.postGameTpLocation = postGameTpLocation;
|
||||
FloorGame.config.set("postGameTpLocation", FormatBlockLocation(postGameTpLocation));
|
||||
FloorGame.config.set("postGameTpLocation", Util.PrintBlockLocation(postGameTpLocation));
|
||||
FloorGame.SaveConfig();
|
||||
}
|
||||
|
||||
private String FormatBlockLocation(Location location) {
|
||||
return location.getBlockX() + ", " + location.getBlockY() + ", " + location.getBlockZ();
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,16 +1,25 @@
|
||||
package com.pobnellion.floorGame.game;
|
||||
|
||||
import com.pobnellion.floorGame.FloorGame;
|
||||
import com.pobnellion.floorGame.Util;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
import com.pobnellion.floorGame.util.Area;
|
||||
import net.md_5.bungee.api.ChatMessageType;
|
||||
import net.md_5.bungee.api.chat.ComponentBuilder;
|
||||
import org.bukkit.*;
|
||||
import org.bukkit.attribute.Attribute;
|
||||
import org.bukkit.attribute.AttributeModifier;
|
||||
import org.bukkit.boss.BarColor;
|
||||
import org.bukkit.boss.BarStyle;
|
||||
import org.bukkit.boss.BossBar;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.EquipmentSlotGroup;
|
||||
import org.bukkit.potion.PotionEffect;
|
||||
import org.bukkit.potion.PotionEffectType;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
import java.text.DecimalFormat;
|
||||
import java.time.Duration;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Random;
|
||||
import java.util.*;
|
||||
import java.util.logging.Level;
|
||||
|
||||
public class GameInstance {
|
||||
@ -19,14 +28,18 @@ public class GameInstance {
|
||||
private final ArrayList<Player> players = new ArrayList<>();
|
||||
private final ArrayList<Player> spectators = new ArrayList<>();
|
||||
private final GameConfig config;
|
||||
private int round;
|
||||
private boolean roundInProgress;
|
||||
private LocalDateTime nextRoundStartTime;
|
||||
private int round = 0;
|
||||
private final int timeDecreaseRounds = 5;
|
||||
private Material roundColour;
|
||||
|
||||
private BossBar countdownBossbar;
|
||||
private LocalDateTime countdownStartTime;
|
||||
private boolean stopped = false;
|
||||
private final DecimalFormat timeFormat = new DecimalFormat("#.##");
|
||||
private final Map<UUID, Integer> playerLives = new HashMap<>();
|
||||
private final AttributeModifier setZeroModifier = new AttributeModifier(NamespacedKey.minecraft("set_zero"), -1, AttributeModifier.Operation.ADD_SCALAR, EquipmentSlotGroup.ANY);
|
||||
|
||||
public GameInstance(GameConfig config) {
|
||||
floor = new Floor(config.getFloorCenter(), config.getGridSize(), config.getTileSize(), config.getAvailableColours());
|
||||
floor = new Floor(config.getFloorCenter(), config.getTileSize(), config.getGridSize(), config.getAvailableColours());
|
||||
this.config = config;
|
||||
|
||||
world = config.getFloorCenter().getWorld();
|
||||
@ -35,76 +48,200 @@ public class GameInstance {
|
||||
throw new NullPointerException("floorCenter world is not set");
|
||||
}
|
||||
|
||||
public boolean IsPlayerInGame(Player player) {
|
||||
return players.contains(player);
|
||||
}
|
||||
|
||||
public void PlayerFell(Player player) {
|
||||
playerLives.put(player.getUniqueId(), playerLives.get(player.getUniqueId()) - 1);
|
||||
player.teleport(config.getFloorCenter().clone().add(0, 10, 0));
|
||||
|
||||
if (playerLives.get(player.getUniqueId()) == 0) {
|
||||
players.remove(player);
|
||||
spectators.add(player);
|
||||
player.setGameMode(GameMode.SPECTATOR);
|
||||
player.getAttribute(Attribute.GENERIC_GRAVITY).removeModifier(setZeroModifier);
|
||||
player.getAttribute(Attribute.GENERIC_FALL_DAMAGE_MULTIPLIER).removeModifier(setZeroModifier);
|
||||
player.sendTitle("", "You are now spectating", 0, 40, 20);
|
||||
}
|
||||
|
||||
if (floor.isDropped)
|
||||
player.getAttribute(Attribute.GENERIC_GRAVITY).addModifier(setZeroModifier);
|
||||
}
|
||||
|
||||
public Area GetFallArea() {
|
||||
return floor.fallArea;
|
||||
}
|
||||
|
||||
public void Start() {
|
||||
Bukkit.getLogger().log(Level.INFO, "Starting floor game");
|
||||
world.getPlayers().forEach(player -> {
|
||||
if (Util.IsInBounds(player.getLocation(), config.getPlayerJoinArea()[0], config.getPlayerJoinArea()[1]))
|
||||
if (config.getPlayerJoinArea().IsInBounds(player.getLocation()))
|
||||
players.add(player);
|
||||
else if (Util.IsInBounds(player.getLocation(), config.getSpectatorJoinArea()[0], config.getSpectatorJoinArea()[1]))
|
||||
else if (config.getSpectatorJoinArea().IsInBounds(player.getLocation()))
|
||||
spectators.add(player);
|
||||
});
|
||||
|
||||
countdownBossbar = Bukkit.createBossBar("", BarColor.WHITE, BarStyle.SOLID);
|
||||
countdownBossbar.setVisible(false);
|
||||
|
||||
floor.Init();
|
||||
|
||||
var playerTpLocation = config.getFloorCenter().clone().add(0, 2, 0);
|
||||
var spectatorTpLocation = config.getFloorCenter().clone().add(0, 15, 0);
|
||||
players.forEach(player -> player.teleport(playerTpLocation));
|
||||
players.forEach(player -> {
|
||||
player.teleport(playerTpLocation);
|
||||
player.setGameMode(GameMode.ADVENTURE);
|
||||
countdownBossbar.addPlayer(player);
|
||||
playerLives.put(player.getUniqueId(), config.getFailLimit());
|
||||
player.getAttribute(Attribute.GENERIC_FALL_DAMAGE_MULTIPLIER).addModifier(setZeroModifier);
|
||||
});
|
||||
spectators.forEach(player -> player.teleport(spectatorTpLocation));
|
||||
|
||||
|
||||
|
||||
roundInit().runTaskLater(FloorGame.GetInstance(), 50);
|
||||
hudBar.runTaskTimer(FloorGame.GetInstance(), 0, 10);
|
||||
}
|
||||
|
||||
private void GameLoopTask() {
|
||||
|
||||
|
||||
|
||||
var a =new BukkitRunnable() {
|
||||
public void run() {
|
||||
floor.Reset();
|
||||
}
|
||||
}.runTaskLater(FloorGame.GetInstance(), 1000);
|
||||
|
||||
a.
|
||||
}
|
||||
|
||||
private BukkitRunnable round = new BukkitRunnable() {
|
||||
private final BukkitRunnable hudBar = new BukkitRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
var rand = new Random();
|
||||
roundColour = floor.colours[rand.nextInt(floor.colours.length)];
|
||||
|
||||
|
||||
|
||||
floor.SoloTile(colour);
|
||||
if (stopped)
|
||||
cancel();
|
||||
|
||||
players.forEach(player -> {
|
||||
var actionBarComponent = new ComponentBuilder("Round " + round)
|
||||
.append(" | ")
|
||||
.append(playerLives.get(player.getUniqueId()) + " lives")
|
||||
.create();
|
||||
player.spigot().sendMessage(ChatMessageType.ACTION_BAR, actionBarComponent);
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
private BukkitRunnable warnColour = new BukkitRunnable() {
|
||||
private BukkitRunnable roundInit() {
|
||||
return new BukkitRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (stopped)
|
||||
return;
|
||||
|
||||
players.forEach(player -> player.getAttribute(Attribute.GENERIC_GRAVITY).removeModifier(setZeroModifier));
|
||||
|
||||
floor.Reset();
|
||||
round++;
|
||||
|
||||
if (round % timeDecreaseRounds == 0)
|
||||
players.forEach(player -> {
|
||||
player.sendTitle("", "FLOOR TIME DECREASED: " + timeFormat.format(GetRoundTime()) + " seconds", 3, 60, 3);
|
||||
player.getActivePotionEffects().forEach(effect -> player.removePotionEffect(effect.getType()));
|
||||
player.addPotionEffects(GetRoundEffects());
|
||||
});
|
||||
|
||||
var rand = new Random();
|
||||
roundColour = floor.colours[rand.nextInt(floor.colours.length)];
|
||||
|
||||
// 5 - 8 second chill time before warn
|
||||
var delay = rand.nextInt(100, 160);
|
||||
roundWarn().runTaskLater(FloorGame.GetInstance(), delay);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
private BukkitRunnable roundWarn() {
|
||||
return new BukkitRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (stopped)
|
||||
return;
|
||||
|
||||
floor.WarnWalls(roundColour);
|
||||
var colourName = config.getColourMap().get(roundColour).toUpperCase();
|
||||
players.forEach(player -> player.sendTitle("", colourName, 0, 200, 0));
|
||||
|
||||
// TODO: stay based on round time
|
||||
players.forEach(player -> player.sendTitle(null, colourName, 0, 10, 0));
|
||||
countdownBossbar.setVisible(true);
|
||||
countdownStartTime = LocalDateTime.now();
|
||||
countdownBar().runTaskTimer(FloorGame.GetInstance(), 0, 1);
|
||||
|
||||
roundRemoveFloor().runTaskLater(FloorGame.GetInstance(), (int) (GetRoundTime() * 20));
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private BukkitRunnable countdownBar() {
|
||||
return new BukkitRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (stopped)
|
||||
return;
|
||||
|
||||
var durationSeconds = Duration.between(countdownStartTime, LocalDateTime.now()).toMillis() / 1000d;
|
||||
var countdownProgress = durationSeconds / GetRoundTime();
|
||||
|
||||
if (durationSeconds >= GetRoundTime())
|
||||
return;
|
||||
|
||||
countdownBossbar.setTitle(timeFormat.format(GetRoundTime() - durationSeconds) + " seconds");
|
||||
countdownBossbar.setProgress(1 - countdownProgress);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private BukkitRunnable roundRemoveFloor() {
|
||||
return new BukkitRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (stopped)
|
||||
return;
|
||||
|
||||
countdownBossbar.setVisible(false);
|
||||
floor.Drop(roundColour);
|
||||
players.forEach(player -> player.sendTitle("", "", 0, 0, 0));
|
||||
roundInit().runTaskLater(FloorGame.GetInstance(), 60);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public void Stop() {
|
||||
new BukkitRunnable() {
|
||||
public void run() {
|
||||
stopped = true;
|
||||
floor.Clear();
|
||||
countdownBossbar.removeAll();
|
||||
countdownBossbar.setVisible(false);
|
||||
players.forEach(player -> {
|
||||
player.getActivePotionEffects().forEach(effect -> player.removePotionEffect(effect.getType()));
|
||||
player.getAttribute(Attribute.GENERIC_GRAVITY).removeModifier(setZeroModifier);
|
||||
player.getAttribute(Attribute.GENERIC_FALL_DAMAGE_MULTIPLIER).removeModifier(setZeroModifier);
|
||||
player.teleport(config.getPostGameTpLocation());
|
||||
player.setGameMode(GameMode.CREATIVE);
|
||||
});
|
||||
|
||||
players.forEach(player -> player.teleport(config.getPostGameTpLocation()));
|
||||
spectators.forEach(player -> player.teleport(config.getPostGameTpLocation()));
|
||||
spectators.forEach(player -> {
|
||||
player.teleport(config.getPostGameTpLocation());
|
||||
player.setGameMode(GameMode.CREATIVE);
|
||||
});
|
||||
}
|
||||
}.runTask(FloorGame.GetInstance());
|
||||
}
|
||||
|
||||
private double GetRoundTime() {
|
||||
return 1 + 0.5 * floor.tileSize + Math.pow(0.85, Math.floor(round * 0.1));
|
||||
return 0.5 * floor.tileSize + Math.pow(0.5, Math.floor((double) round / timeDecreaseRounds));
|
||||
}
|
||||
|
||||
private Collection<PotionEffect> GetRoundEffects() {
|
||||
var effects = new ArrayList<PotionEffect>();
|
||||
effects.add(new PotionEffect(PotionEffectType.SATURATION, PotionEffect.INFINITE_DURATION, 1, false, false, false));
|
||||
|
||||
if (round >= 10 && round < 20)
|
||||
effects.add(new PotionEffect(PotionEffectType.SPEED, PotionEffect.INFINITE_DURATION, 0, false, false, false));
|
||||
if (round >= 20 && round < 30)
|
||||
effects.add(new PotionEffect(PotionEffectType.SPEED, PotionEffect.INFINITE_DURATION, 1, false, false, false));
|
||||
if (round >= 30 && round < 40)
|
||||
effects.add(new PotionEffect(PotionEffectType.SPEED, PotionEffect.INFINITE_DURATION, 2, false, false, false));
|
||||
if (round >= 40)
|
||||
effects.add(new PotionEffect(PotionEffectType.SPEED, PotionEffect.INFINITE_DURATION, 3, false, false, false));
|
||||
|
||||
return effects;
|
||||
}
|
||||
}
|
||||
|
||||
28
src/main/java/com/pobnellion/floorGame/util/Area.java
Normal file
28
src/main/java/com/pobnellion/floorGame/util/Area.java
Normal file
@ -0,0 +1,28 @@
|
||||
package com.pobnellion.floorGame.util;
|
||||
|
||||
import org.bukkit.Location;
|
||||
|
||||
public class Area {
|
||||
public Location min;
|
||||
public Location max;
|
||||
|
||||
public Area(Location l1, Location l2) {
|
||||
min = new Location(l1.getWorld(),
|
||||
Math.min(l1.getX(), l2.getX()),
|
||||
Math.min(l1.getY(), l2.getY()),
|
||||
Math.min(l1.getZ(), l2.getZ())
|
||||
);
|
||||
|
||||
max = new Location(l1.getWorld(),
|
||||
Math.max(l1.getX(), l2.getX()),
|
||||
Math.max(l1.getY(), l2.getY()),
|
||||
Math.max(l1.getZ(), l2.getZ())
|
||||
);
|
||||
}
|
||||
|
||||
public boolean IsInBounds(Location location) {
|
||||
return min.getBlockX() <= location.getBlockX() && location.getBlockX() <= max.getBlockX() &&
|
||||
min.getBlockY() <= location.getBlockY() && location.getBlockY() <= max.getBlockY() &&
|
||||
min.getBlockZ() <= location.getBlockZ() && location.getBlockZ() <= max.getBlockZ();
|
||||
}
|
||||
}
|
||||
@ -1,4 +1,4 @@
|
||||
package com.pobnellion.floorGame;
|
||||
package com.pobnellion.floorGame.util;
|
||||
|
||||
import org.bukkit.Location;
|
||||
|
||||
@ -16,8 +16,8 @@ public class Util {
|
||||
return location.getBlockX() + ", " + location.getBlockY() + ", " + location.getBlockZ();
|
||||
}
|
||||
|
||||
public static String PrintArea(Location[] location) {
|
||||
return "[" + PrintBlockLocation(location[0]) + "] - [" + PrintBlockLocation(location[1]) + "]";
|
||||
public static String PrintArea(Area area) {
|
||||
return "[" + PrintBlockLocation(area.min) + "] - [" + PrintBlockLocation(area.max) + "]";
|
||||
}
|
||||
}
|
||||
|
||||
@ -8,3 +8,5 @@ commands:
|
||||
description: "Floor game setup and play"
|
||||
usage: /floorgame <start|stop|config>
|
||||
permission: floorGame.admin
|
||||
aliases:
|
||||
- fg
|
||||
Reference in New Issue
Block a user