YEAH its kinda working

This commit is contained in:
ruby
2024-08-17 01:05:21 +12:00
parent 9663c70d54
commit f08d2662d9
9 changed files with 303 additions and 93 deletions

View File

@ -2,9 +2,11 @@ package com.pobnellion.floorGame;
import com.pobnellion.floorGame.command.CommandFloorGame; import com.pobnellion.floorGame.command.CommandFloorGame;
import com.pobnellion.floorGame.command.TabCompleterFloorGame; import com.pobnellion.floorGame.command.TabCompleterFloorGame;
import com.pobnellion.floorGame.game.FallListener;
import com.pobnellion.floorGame.game.GameConfig; import com.pobnellion.floorGame.game.GameConfig;
import com.pobnellion.floorGame.game.GameInstance; import com.pobnellion.floorGame.game.GameInstance;
import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
import javax.annotation.Nullable; import javax.annotation.Nullable;
@ -25,6 +27,9 @@ public final class FloorGame extends JavaPlugin {
// Register commands // Register commands
this.getCommand("floorgame").setExecutor(new CommandFloorGame()); this.getCommand("floorgame").setExecutor(new CommandFloorGame());
this.getCommand("floorgame").setTabCompleter(new TabCompleterFloorGame()); this.getCommand("floorgame").setTabCompleter(new TabCompleterFloorGame());
// Register events
getServer().getPluginManager().registerEvents(new FallListener(), this);
} }
@Override @Override
@ -52,6 +57,24 @@ public final class FloorGame extends JavaPlugin {
return false; 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() { public static void SaveConfig() {
instance.saveConfig(); instance.saveConfig();
} }

View File

@ -2,7 +2,7 @@ package com.pobnellion.floorGame.command;
import com.pobnellion.floorGame.FloorGame; import com.pobnellion.floorGame.FloorGame;
import com.pobnellion.floorGame.game.GameConfig; import com.pobnellion.floorGame.game.GameConfig;
import com.pobnellion.floorGame.Util; import com.pobnellion.floorGame.util.Util;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.command.Command; import org.bukkit.command.Command;

View File

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

View File

@ -1,24 +1,24 @@
package com.pobnellion.floorGame.game; package com.pobnellion.floorGame.game;
import com.pobnellion.floorGame.Util; import com.pobnellion.floorGame.util.Area;
import org.bukkit.Bukkit;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.World; import org.bukkit.World;
import java.util.HashSet; import java.util.HashSet;
import java.util.Random; import java.util.Random;
import java.util.logging.Level;
public class Floor { public class Floor {
private final Location xzCorner; private final Location xzCorner;
public int tileSize; public int tileSize;
public int gridSize; public int gridSize;
public Material[] colours; public Material[] colours;
public Area fallArea;
private final Material[][] colourGrid; private final Material[][] colourGrid;
public boolean isDropped = false;
public Floor(Location center, int tileSize, int gridSize, Material[] availableColours) { 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.tileSize = tileSize;
this.gridSize = gridSize; this.gridSize = gridSize;
@ -36,6 +36,9 @@ public class Floor {
} }
colours = colourSet.toArray(new Material[0]); 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() { public void Init() {
@ -44,11 +47,10 @@ public class Floor {
} }
public void Reset() { public void Reset() {
isDropped = false;
for (int row = 0; row < gridSize; row++) { for (int row = 0; row < gridSize; row++) {
for (int col = 0; col < gridSize; col++) { for (int col = 0; col < gridSize; col++) {
FillTile(xzCorner.getBlockX() + row * tileSize, FillTile(row, col, colourGrid[row][col]);
xzCorner.getBlockZ() + col * tileSize,
colourGrid[row][col]);
} }
} }
FillWalls(xzCorner.getBlockY() + 2, xzCorner.getBlockY() + 4, Material.BARRIER); FillWalls(xzCorner.getBlockY() + 2, xzCorner.getBlockY() + 4, Material.BARRIER);
@ -70,24 +72,29 @@ public class Floor {
FillWalls(xzCorner.getBlockY() + 2, xzCorner.getBlockY() + 4, material); 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 row = 0; row < gridSize; row++) {
for (int col = 0; col < gridSize; col++) { for (int col = 0; col < gridSize; col++) {
if (colourGrid[row][col] != material) if (colourGrid[row][col] != material)
FillTile(xzCorner.getBlockX() + row * tileSize, FillTile(row , col, Material.AIR);
xzCorner.getBlockZ() + col * tileSize,
Material.AIR);
} }
} }
} }
private void FillTile(int xMin, int zMin, Material material) { private void FillTile(int gridRow, int gridCol, Material material) {
FillArea(xzCorner.getWorld(), xMin, xzCorner.getBlockY(), zMin, FillArea(xzCorner.getWorld(),
xMin + tileSize, xzCorner.getBlockY(), zMin + tileSize, material); 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) { private void FillWalls(int yMin, int yMax, Material material) {
var floorSize = tileSize * gridSize + 1; var floorSize = tileSize * gridSize;
FillArea(xzCorner.getWorld(), FillArea(xzCorner.getWorld(),
xzCorner.getBlockX() - 1, xzCorner.getBlockX() - 1,
yMin, yMin,
@ -112,23 +119,27 @@ public class Floor {
xzCorner.getBlockZ() - 1, xzCorner.getBlockZ() - 1,
xzCorner.getBlockX() + floorSize, xzCorner.getBlockX() + floorSize,
yMax, yMax,
xzCorner.getBlockX() + floorSize, xzCorner.getBlockZ() + floorSize,
material); material);
FillArea(xzCorner.getWorld(), FillArea(xzCorner.getWorld(),
xzCorner.getBlockX() + -1, xzCorner.getBlockX() -1,
yMin, yMin,
xzCorner.getBlockZ() + floorSize, xzCorner.getBlockZ() + floorSize,
xzCorner.getBlockX() + floorSize, xzCorner.getBlockX() + floorSize,
yMax, yMax,
xzCorner.getBlockX() + floorSize, xzCorner.getBlockZ() + floorSize + 1,
material); material);
} }
private void FillArea(World world, int xMin, int yMin, int zMin, int xMax, int yMax, int zMax, Material 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++) { if (xMin == xMax) xMax++;
for (int y = yMin; y <= yMax; y++) { if (yMin == yMax) yMax++;
for (int z = zMin; z <= zMax; z++) { 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); world.getBlockAt(x, y, z).setType(material);
} }
} }

View File

@ -1,6 +1,8 @@
package com.pobnellion.floorGame.game; package com.pobnellion.floorGame.game;
import com.pobnellion.floorGame.FloorGame; import com.pobnellion.floorGame.FloorGame;
import com.pobnellion.floorGame.util.Area;
import com.pobnellion.floorGame.util.Util;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Material; import org.bukkit.Material;
@ -19,8 +21,8 @@ public class GameConfig {
private static final Map<Material, String> availableColours = new HashMap<>(); private static final Map<Material, String> availableColours = new HashMap<>();
private Location postGameTpLocation; private Location postGameTpLocation;
private Location floorCenter; private Location floorCenter;
private final Location[] playerJoinArea = new Location[2]; private Area playerJoinArea;
private final Location[] spectatorJoinArea= new Location[2]; private Area spectatorJoinArea;
private World world; private World world;
public GameConfig() { public GameConfig() {
@ -37,10 +39,9 @@ public class GameConfig {
this.postGameTpLocation = ParseLocation(world, FloorGame.config.getString("postGameTpLocation")); this.postGameTpLocation = ParseLocation(world, FloorGame.config.getString("postGameTpLocation"));
this.floorCenter = ParseLocation(world, FloorGame.config.getString("floorCenter")); 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.playerJoinArea = new Area(ParseLocation(world, playerJoinArea.get(0)), ParseLocation(world, playerJoinArea.get(1)));
this.spectatorJoinArea[0] = ParseLocation(world, spectatorJoinArea.get(0)); this.spectatorJoinArea = new Area(ParseLocation(world, spectatorJoinArea.get(0)), ParseLocation(world, spectatorJoinArea.get(1)));
this.spectatorJoinArea[1] = ParseLocation(world, spectatorJoinArea.get(1));
var coloursSection = FloorGame.config.getConfigurationSection("availableColours"); var coloursSection = FloorGame.config.getConfigurationSection("availableColours");
@ -132,7 +133,7 @@ public class GameConfig {
} }
public Material[] getAvailableColours() { public Material[] getAvailableColours() {
return availableColours.values().toArray(new Material[0]); return availableColours.keySet().toArray(new Material[0]);
} }
public Location getFloorCenter() { public Location getFloorCenter() {
@ -143,7 +144,7 @@ public class GameConfig {
if (floorCenter.getWorld() == null) if (floorCenter.getWorld() == null)
floorCenter.setWorld(world); floorCenter.setWorld(world);
this.floorCenter = floorCenter; this.floorCenter = floorCenter;
FloorGame.config.set("floorCenter", FormatBlockLocation(floorCenter)); FloorGame.config.set("floorCenter", Util.PrintBlockLocation(floorCenter));
FloorGame.SaveConfig(); FloorGame.SaveConfig();
} }
@ -153,25 +154,23 @@ public class GameConfig {
FloorGame.SaveConfig(); FloorGame.SaveConfig();
} }
public Location[] getPlayerJoinArea() { public Area getPlayerJoinArea() {
return playerJoinArea; return playerJoinArea;
} }
public void setPlayerJoinArea(Location l1, Location l2) { public void setPlayerJoinArea(Location l1, Location l2) {
playerJoinArea[0] = l1; playerJoinArea = new Area(l1, l2);
playerJoinArea[1] = l2; FloorGame.config.set("playerJoinArea", List.of(Util.PrintBlockLocation(playerJoinArea.min), Util.PrintBlockLocation(playerJoinArea.max)));
FloorGame.config.set("playerJoinArea", playerJoinArea);
FloorGame.SaveConfig(); FloorGame.SaveConfig();
} }
public Location[] getSpectatorJoinArea() { public Area getSpectatorJoinArea() {
return spectatorJoinArea; return spectatorJoinArea;
} }
public void setSpectatorJoinArea(Location l1, Location l2) { public void setSpectatorJoinArea(Location l1, Location l2) {
spectatorJoinArea[0] = l1; spectatorJoinArea = new Area(l1, l2);
spectatorJoinArea[1] = l2; FloorGame.config.set("spectatorJoinArea", List.of(Util.PrintBlockLocation(spectatorJoinArea.min), Util.PrintBlockLocation(spectatorJoinArea.max)));
FloorGame.config.set("spectatorJoinArea", spectatorJoinArea);
FloorGame.SaveConfig(); FloorGame.SaveConfig();
} }
@ -181,11 +180,7 @@ public class GameConfig {
public void setPostGameTpLocation(Location postGameTpLocation) { public void setPostGameTpLocation(Location postGameTpLocation) {
this.postGameTpLocation = postGameTpLocation; this.postGameTpLocation = postGameTpLocation;
FloorGame.config.set("postGameTpLocation", FormatBlockLocation(postGameTpLocation)); FloorGame.config.set("postGameTpLocation", Util.PrintBlockLocation(postGameTpLocation));
FloorGame.SaveConfig(); FloorGame.SaveConfig();
} }
private String FormatBlockLocation(Location location) {
return location.getBlockX() + ", " + location.getBlockY() + ", " + location.getBlockZ();
}
} }

View File

@ -1,16 +1,25 @@
package com.pobnellion.floorGame.game; package com.pobnellion.floorGame.game;
import com.pobnellion.floorGame.FloorGame; import com.pobnellion.floorGame.FloorGame;
import com.pobnellion.floorGame.Util; import com.pobnellion.floorGame.util.Area;
import org.bukkit.Bukkit; import net.md_5.bungee.api.ChatMessageType;
import org.bukkit.Material; import net.md_5.bungee.api.chat.ComponentBuilder;
import org.bukkit.World; 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.entity.Player;
import org.bukkit.inventory.EquipmentSlotGroup;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
import org.bukkit.scheduler.BukkitRunnable; import org.bukkit.scheduler.BukkitRunnable;
import java.text.DecimalFormat;
import java.time.Duration;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.ArrayList; import java.util.*;
import java.util.Random;
import java.util.logging.Level; import java.util.logging.Level;
public class GameInstance { public class GameInstance {
@ -19,14 +28,18 @@ public class GameInstance {
private final ArrayList<Player> players = new ArrayList<>(); private final ArrayList<Player> players = new ArrayList<>();
private final ArrayList<Player> spectators = new ArrayList<>(); private final ArrayList<Player> spectators = new ArrayList<>();
private final GameConfig config; private final GameConfig config;
private int round; private int round = 0;
private boolean roundInProgress; private final int timeDecreaseRounds = 5;
private LocalDateTime nextRoundStartTime;
private Material roundColour; 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) { 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; this.config = config;
world = config.getFloorCenter().getWorld(); world = config.getFloorCenter().getWorld();
@ -35,76 +48,200 @@ public class GameInstance {
throw new NullPointerException("floorCenter world is not set"); 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() { public void Start() {
Bukkit.getLogger().log(Level.INFO, "Starting floor game"); Bukkit.getLogger().log(Level.INFO, "Starting floor game");
world.getPlayers().forEach(player -> { world.getPlayers().forEach(player -> {
if (Util.IsInBounds(player.getLocation(), config.getPlayerJoinArea()[0], config.getPlayerJoinArea()[1])) if (config.getPlayerJoinArea().IsInBounds(player.getLocation()))
players.add(player); 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); spectators.add(player);
}); });
countdownBossbar = Bukkit.createBossBar("", BarColor.WHITE, BarStyle.SOLID);
countdownBossbar.setVisible(false);
floor.Init(); floor.Init();
var playerTpLocation = config.getFloorCenter().clone().add(0, 2, 0); var playerTpLocation = config.getFloorCenter().clone().add(0, 2, 0);
var spectatorTpLocation = config.getFloorCenter().clone().add(0, 15, 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)); spectators.forEach(player -> player.teleport(spectatorTpLocation));
roundInit().runTaskLater(FloorGame.GetInstance(), 50);
hudBar.runTaskTimer(FloorGame.GetInstance(), 0, 10);
} }
private void GameLoopTask() { private final BukkitRunnable hudBar = new BukkitRunnable() {
var a =new BukkitRunnable() {
public void run() {
floor.Reset();
}
}.runTaskLater(FloorGame.GetInstance(), 1000);
a.
}
private BukkitRunnable round = new BukkitRunnable() {
@Override @Override
public void run() { public void run() {
var rand = new Random(); if (stopped)
roundColour = floor.colours[rand.nextInt(floor.colours.length)]; cancel();
floor.SoloTile(colour);
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 @Override
public void run() { 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); floor.WarnWalls(roundColour);
var colourName = config.getColourMap().get(roundColour).toUpperCase(); var colourName = config.getColourMap().get(roundColour).toUpperCase();
players.forEach(player -> player.sendTitle("", colourName, 0, 200, 0));
// TODO: stay based on round time countdownBossbar.setVisible(true);
players.forEach(player -> player.sendTitle(null, colourName, 0, 10, 0)); 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() { public void Stop() {
new BukkitRunnable() { new BukkitRunnable() {
public void run() { public void run() {
stopped = true;
floor.Clear(); 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 -> {
spectators.forEach(player -> player.teleport(config.getPostGameTpLocation())); player.teleport(config.getPostGameTpLocation());
player.setGameMode(GameMode.CREATIVE);
});
} }
}.runTask(FloorGame.GetInstance()); }.runTask(FloorGame.GetInstance());
} }
private double GetRoundTime() { 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;
} }
} }

View 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();
}
}

View File

@ -1,4 +1,4 @@
package com.pobnellion.floorGame; package com.pobnellion.floorGame.util;
import org.bukkit.Location; import org.bukkit.Location;
@ -16,8 +16,8 @@ public class Util {
return location.getBlockX() + ", " + location.getBlockY() + ", " + location.getBlockZ(); return location.getBlockX() + ", " + location.getBlockY() + ", " + location.getBlockZ();
} }
public static String PrintArea(Location[] location) { public static String PrintArea(Area area) {
return "[" + PrintBlockLocation(location[0]) + "] - [" + PrintBlockLocation(location[1]) + "]"; return "[" + PrintBlockLocation(area.min) + "] - [" + PrintBlockLocation(area.max) + "]";
} }
} }

View File

@ -8,3 +8,5 @@ commands:
description: "Floor game setup and play" description: "Floor game setup and play"
usage: /floorgame <start|stop|config> usage: /floorgame <start|stop|config>
permission: floorGame.admin permission: floorGame.admin
aliases:
- fg