use of com.gmail.stefvanschiedev.buildinggame.utils.arena.Arena in project buildinggame by stefvanschie.
the class CommandManager method onReload.
/**
* Called whenever a command sender wants to reload the plugin
*
* @param sender the command sender
* @since 5.8.0
*/
@Subcommand("reload")
@Description("Reload the plugin")
@CommandPermission("bg.reload")
public void onReload(CommandSender sender) {
ArenaManager.getInstance().getArenas().stream().filter(arena -> arena.getPlayers() > 0).forEach(Arena::stop);
StatManager instance = StatManager.getInstance();
if (instance.getMySQLDatabase() == null)
instance.saveToFile();
else
instance.saveToDatabase();
FileCheckerTimer runnable = SettingsManager.getInstance().getRunnable();
if (!runnable.isCancelled())
runnable.cancel();
Main.getInstance().loadPlugin(true);
MessageManager.getInstance().send(sender, ChatColor.GREEN + "Reloaded the plugin!");
}
use of com.gmail.stefvanschiedev.buildinggame.utils.arena.Arena in project buildinggame by stefvanschie.
the class CommandManager method onSpectate.
/**
* Called whenever a player wants to spectate
*
* @param player the player
* @param toSpectate the player to spectate
* @since 5.8.0
*/
@Subcommand("spectate")
@Description("Spectate a player")
@CommandPermission("bg.spectate")
public void onSpectate(Player player, Player toSpectate) {
var arena = ArenaManager.getInstance().getArena(toSpectate);
if (arena == null) {
MessageManager.getInstance().send(player, ChatColor.RED + "Arena not found");
return;
}
if (arena.getState() != GameState.BUILDING) {
MessageManager.getInstance().send(player, ChatColor.RED + "You can't spectate right now");
return;
}
GamePlayer toSpectateGamePlayer = arena.getUsedPlots().stream().flatMap(plot -> plot.getAllGamePlayers().stream()).filter(gamePlayer -> gamePlayer.getPlayer().equals(toSpectate)).findAny().orElse(null);
if (toSpectateGamePlayer == null) {
MessageManager.getInstance().send(player, ChatColor.RED + "Couldn't find the player to spectate");
return;
}
if (toSpectateGamePlayer.getGamePlayerType() == GamePlayerType.SPECTATOR) {
MessageManager.getInstance().send(player, ChatColor.RED + "You can't spectate a spectator");
return;
}
// check if the player is playing the game
if (ArenaManager.getInstance().getArena(player) != null && ArenaManager.getInstance().getArena(player).getPlot(player).getGamePlayer(player).getGamePlayerType() == GamePlayerType.PLAYER) {
MessageManager.getInstance().send(player, ChatColor.RED + "You can't spectate while you're in game");
return;
}
// check if we are already spectating
Plot spectating = null;
for (Arena a : ArenaManager.getInstance().getArenas()) {
for (Plot plot : a.getUsedPlots()) {
for (GamePlayer gamePlayer : plot.getSpectators()) {
if (gamePlayer.getPlayer().equals(player)) {
spectating = plot;
break;
}
}
}
}
if (spectating != null)
spectating.removeSpectator(spectating.getGamePlayer(player));
arena.getPlot(toSpectateGamePlayer.getPlayer()).addSpectator(player, toSpectateGamePlayer);
MessageManager.getInstance().send(player, ChatColor.GREEN + "Now spectating " + toSpectateGamePlayer.getPlayer().getName() + '!');
}
use of com.gmail.stefvanschiedev.buildinggame.utils.arena.Arena in project buildinggame by stefvanschie.
the class LobbyTimer method run.
/**
* Called whenever a second has passed
*
* @since 2.1.0
*/
@Override
public void run() {
YamlConfiguration config = SettingsManager.getInstance().getConfig();
YamlConfiguration messages = SettingsManager.getInstance().getMessages();
if (seconds <= 0) {
arena.preStart();
running = false;
this.cancel();
return;
} else if (seconds % 15 == 0 || (seconds <= 10 && seconds >= 1)) {
arena.getUsedPlots().stream().flatMap(plot -> plot.getGamePlayers().stream()).forEach(gamePlayer -> {
var player = gamePlayer.getPlayer();
messages.getStringList("lobbyCountdown.message").forEach(message -> MessageManager.getInstance().send(player, message.replace("%seconds%", seconds + "").replace("%minutes%", getMinutes() + "").replace("%time%", getMinutes() + ":" + getSecondsFromMinute()).replace("%seconds_from_minute%", getSecondsFromMinute() + "")));
});
}
arena.getUsedPlots().forEach(plot -> plot.getGamePlayers().forEach(gamePlayer -> gamePlayer.getPlayer().setLevel(seconds)));
// timings
try {
config.getConfigurationSection("timings.lobby-timer.at").getKeys(false).forEach(key -> {
if (seconds == Integer.parseInt(key)) {
config.getStringList("timings.lobby-timer.at." + Integer.parseInt(key)).forEach(command -> CommandUtil.dispatch(command.replace("%arena%", arena.getName())));
}
});
config.getConfigurationSection("timings.lobby-timer.every").getKeys(false).forEach(key -> {
if (seconds % Integer.parseInt(key) == 0) {
config.getStringList("timings.lobby-timer.every." + Integer.parseInt(key)).forEach(command -> CommandUtil.dispatch(command.replace("%arena%", arena.getName())));
}
});
} catch (NullPointerException | NumberFormatException ignore) {
}
seconds--;
}
use of com.gmail.stefvanschiedev.buildinggame.utils.arena.Arena in project buildinggame by stefvanschie.
the class ClickJoinSign method onPlayerInteract.
/**
* Handles players clicking on join signs
*
* @param e an event representing a player interacting
* @see PlayerInteractEvent
* @since 2.1.0
*/
@EventHandler
public void onPlayerInteract(PlayerInteractEvent e) {
if (e.getHand() != EquipmentSlot.HAND) {
return;
}
var player = e.getPlayer();
var clickedBlock = e.getClickedBlock();
if (clickedBlock == null)
return;
BlockState state = clickedBlock.getState();
if (e.getAction() != Action.RIGHT_CLICK_BLOCK || !(state instanceof Sign))
return;
Arena arena = null;
for (Arena a : ArenaManager.getInstance().getArenas()) {
for (PotentialBlockPosition blockPos : a.getSigns()) {
Block block = blockPos.getBlock();
if (block != null && block.equals(clickedBlock)) {
arena = a;
break;
}
}
}
var playerArena = ArenaManager.getInstance().getArena(player);
if (arena == null) {
for (PotentialBlockPosition blockPos : SignManager.getInstance().getRandomJoinSigns()) {
Block block = blockPos.getBlock();
if (block == null || !block.equals(clickedBlock)) {
continue;
}
arena = getRandomArena();
if (arena == null)
MessageManager.getInstance().send(player, ChatColor.RED + "Unable to join an arena right now");
else if (playerArena != null)
MessageManager.getInstance().send(player, ChatColor.RED + "You're already in an arena");
else
arena.join(player);
}
} else {
if (playerArena != null)
MessageManager.getInstance().send(player, ChatColor.RED + "You're already in an arena");
else
arena.join(player);
}
e.setCancelled(true);
}
use of com.gmail.stefvanschiedev.buildinggame.utils.arena.Arena in project buildinggame by stefvanschie.
the class ArenaManager method setup.
/**
* Loads/Reloads all arena instances from the arenas.yml file
*
* @since 2.1.0
*/
public void setup() {
arenas.clear();
YamlConfiguration arenasYaml = SettingsManager.getInstance().getArenas();
Set<String> arenas = arenasYaml.getKeys(false);
for (String arena : arenas) {
if (!arena.equals("main-spawn")) {
Arena a = new Arena(arena);
a.setMoneyEnabled(arenasYaml.getBoolean(arena + ".enable-money", true));
this.arenas.add(a);
if (SettingsManager.getInstance().getConfig().getBoolean("debug"))
Main.getInstance().getLogger().info("Loaded arena " + arena);
}
}
}
Aggregations