Merge pull request #53 from bobby29831/1.4.3
Implement better coding practices
This commit is contained in:
commit
7d152668d7
46 changed files with 1087 additions and 1008 deletions
|
@ -2,13 +2,13 @@
|
||||||
## Contributing Guidelines
|
## Contributing Guidelines
|
||||||
- Do not send any pull requests to the master branch
|
- Do not send any pull requests to the master branch
|
||||||
- Any pull requests sent to master will be closed
|
- Any pull requests sent to master will be closed
|
||||||
- Send pull requets to the current beta branch (usually named as an unreleased version)
|
- Send pull requests to the current beta branch (usually named as an unreleased version)
|
||||||
- Please tell us why you think this change is nessessary
|
- Please tell us why you think this change is necessary
|
||||||
- We dont want to spend lots of time browsing through your code changes
|
- We don't want to spend lots of time browsing through your code changes
|
||||||
- Describe your changes
|
- Describe your changes
|
||||||
- Do not repoen a pull request if we closed it for not being a nessary feature
|
- Do not reopen a pull request if we closed it for not being a necessary feature
|
||||||
- Do not change credits in any of the files
|
- Do not change credits in any of the files
|
||||||
- If making a new language file, follow the local naming convencion
|
- If making a new language file, follow the local naming convention
|
||||||
- localization-[LANGUAGE](https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes#)_[TERROTORY](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2#Officially_assigned_code_elements).yml. You can find the 2 letter codes in the links.
|
- localization-[LANGUAGE](https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes#)_[TERRITORY](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2#Officially_assigned_code_elements).yml. You can find the 2-letter codes in the links.
|
||||||
- Common sense, please...
|
- Common sense, please...
|
||||||
- File subject to change in the future
|
- File subject to change in the future
|
||||||
|
|
|
@ -19,32 +19,27 @@
|
||||||
|
|
||||||
package net.tylermurphy.hideAndSeek;
|
package net.tylermurphy.hideAndSeek;
|
||||||
|
|
||||||
import java.io.File;
|
import net.tylermurphy.hideAndSeek.configuration.Config;
|
||||||
import java.util.List;
|
import net.tylermurphy.hideAndSeek.configuration.Items;
|
||||||
|
import net.tylermurphy.hideAndSeek.configuration.Localization;
|
||||||
import net.tylermurphy.hideAndSeek.database.Database;
|
import net.tylermurphy.hideAndSeek.database.Database;
|
||||||
|
import net.tylermurphy.hideAndSeek.game.Board;
|
||||||
|
import net.tylermurphy.hideAndSeek.game.CommandHandler;
|
||||||
|
import net.tylermurphy.hideAndSeek.game.Game;
|
||||||
|
import net.tylermurphy.hideAndSeek.game.listener.*;
|
||||||
import net.tylermurphy.hideAndSeek.util.PAPIExpansion;
|
import net.tylermurphy.hideAndSeek.util.PAPIExpansion;
|
||||||
|
import net.tylermurphy.hideAndSeek.util.TabCompleter;
|
||||||
import net.tylermurphy.hideAndSeek.util.UUIDFetcher;
|
import net.tylermurphy.hideAndSeek.util.UUIDFetcher;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
|
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
import org.bukkit.plugin.Plugin;
|
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
import org.bukkit.plugin.messaging.PluginMessageListener;
|
|
||||||
import org.bukkit.scheduler.BukkitTask;
|
|
||||||
|
|
||||||
import net.tylermurphy.hideAndSeek.game.CommandHandler;
|
|
||||||
import net.tylermurphy.hideAndSeek.game.EventListener;
|
|
||||||
import net.tylermurphy.hideAndSeek.util.TabCompleter;
|
|
||||||
import net.tylermurphy.hideAndSeek.game.Game;
|
|
||||||
import net.tylermurphy.hideAndSeek.configuration.Config;
|
|
||||||
import net.tylermurphy.hideAndSeek.configuration.Localization;
|
|
||||||
import net.tylermurphy.hideAndSeek.configuration.Items;
|
|
||||||
import net.tylermurphy.hideAndSeek.game.Board;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public class Main extends JavaPlugin implements Listener {
|
public class Main extends JavaPlugin implements Listener {
|
||||||
|
|
||||||
public static Main plugin;
|
public static Main plugin;
|
||||||
|
@ -55,7 +50,8 @@ public class Main extends JavaPlugin implements Listener {
|
||||||
plugin = this;
|
plugin = this;
|
||||||
root = this.getServer().getWorldContainer();
|
root = this.getServer().getWorldContainer();
|
||||||
data = this.getDataFolder();
|
data = this.getDataFolder();
|
||||||
getServer().getPluginManager().registerEvents(new EventListener(), this);
|
|
||||||
|
this.registerListeners();
|
||||||
|
|
||||||
Config.loadConfig();
|
Config.loadConfig();
|
||||||
Localization.loadLocalization();
|
Localization.loadLocalization();
|
||||||
|
@ -76,7 +72,7 @@ public class Main extends JavaPlugin implements Listener {
|
||||||
|
|
||||||
Bukkit.getServer().getMessenger().registerOutgoingPluginChannel(this, "BungeeCord");
|
Bukkit.getServer().getMessenger().registerOutgoingPluginChannel(this, "BungeeCord");
|
||||||
|
|
||||||
if(Bukkit.getPluginManager().getPlugin("PlaceholderAPI") != null) {
|
if (Bukkit.getPluginManager().getPlugin("PlaceholderAPI") != null) {
|
||||||
new PAPIExpansion().register();
|
new PAPIExpansion().register();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -87,6 +83,17 @@ public class Main extends JavaPlugin implements Listener {
|
||||||
UUIDFetcher.cleanup();
|
UUIDFetcher.cleanup();
|
||||||
Board.cleanup();
|
Board.cleanup();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void registerListeners() {
|
||||||
|
getServer().getPluginManager().registerEvents(new BlockedCommandHandler(), this);
|
||||||
|
getServer().getPluginManager().registerEvents(new ChatHandler(), this);
|
||||||
|
getServer().getPluginManager().registerEvents(new DamageHandler(), this);
|
||||||
|
getServer().getPluginManager().registerEvents(new InteractHandler(), this);
|
||||||
|
getServer().getPluginManager().registerEvents(new JoinLeaveHandler(), this);
|
||||||
|
getServer().getPluginManager().registerEvents(new MovementHandler(), this);
|
||||||
|
getServer().getPluginManager().registerEvents(new PlayerHandler(), this);
|
||||||
|
getServer().getPluginManager().registerEvents(new RespawnHandler(), this);
|
||||||
|
}
|
||||||
|
|
||||||
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command cmd, @NotNull String label, String[] args) {
|
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command cmd, @NotNull String label, String[] args) {
|
||||||
return CommandHandler.handleCommand(sender, args);
|
return CommandHandler.handleCommand(sender, args);
|
||||||
|
|
|
@ -19,10 +19,9 @@
|
||||||
|
|
||||||
package net.tylermurphy.hideAndSeek.command;
|
package net.tylermurphy.hideAndSeek.command;
|
||||||
|
|
||||||
import org.bukkit.command.CommandSender;
|
|
||||||
|
|
||||||
import net.md_5.bungee.api.ChatColor;
|
import net.md_5.bungee.api.ChatColor;
|
||||||
import net.tylermurphy.hideAndSeek.game.CommandHandler;
|
import net.tylermurphy.hideAndSeek.game.CommandHandler;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
|
||||||
public class Help implements ICommand {
|
public class Help implements ICommand {
|
||||||
|
|
||||||
|
|
|
@ -19,29 +19,28 @@
|
||||||
|
|
||||||
package net.tylermurphy.hideAndSeek.command;
|
package net.tylermurphy.hideAndSeek.command;
|
||||||
|
|
||||||
import static net.tylermurphy.hideAndSeek.configuration.Config.*;
|
|
||||||
|
|
||||||
import net.tylermurphy.hideAndSeek.game.Board;
|
import net.tylermurphy.hideAndSeek.game.Board;
|
||||||
import net.tylermurphy.hideAndSeek.game.Game;
|
import net.tylermurphy.hideAndSeek.game.Game;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import static net.tylermurphy.hideAndSeek.configuration.Localization.*;
|
import static net.tylermurphy.hideAndSeek.configuration.Config.errorPrefix;
|
||||||
|
import static net.tylermurphy.hideAndSeek.configuration.Localization.message;
|
||||||
|
|
||||||
public class Join implements ICommand {
|
public class Join implements ICommand {
|
||||||
|
|
||||||
public void execute(CommandSender sender, String[] args) {
|
public void execute(CommandSender sender, String[] args) {
|
||||||
if(Game.isNotSetup()) {
|
if (Game.isNotSetup()) {
|
||||||
sender.sendMessage(errorPrefix + message("GAME_SETUP"));
|
sender.sendMessage(errorPrefix + message("GAME_SETUP"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Player player = Bukkit.getServer().getPlayer(sender.getName());
|
Player player = Bukkit.getServer().getPlayer(sender.getName());
|
||||||
if(player == null) {
|
if (player == null) {
|
||||||
sender.sendMessage(errorPrefix + message("COMMAND_ERROR"));
|
sender.sendMessage(errorPrefix + message("COMMAND_ERROR"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if(Board.isPlayer(player)){
|
if (Board.contains(player)) {
|
||||||
sender.sendMessage(errorPrefix + message("GAME_INGAME"));
|
sender.sendMessage(errorPrefix + message("GAME_INGAME"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,31 +19,28 @@
|
||||||
|
|
||||||
package net.tylermurphy.hideAndSeek.command;
|
package net.tylermurphy.hideAndSeek.command;
|
||||||
|
|
||||||
import static net.tylermurphy.hideAndSeek.configuration.Config.*;
|
|
||||||
|
|
||||||
import net.tylermurphy.hideAndSeek.game.Board;
|
import net.tylermurphy.hideAndSeek.game.Board;
|
||||||
import net.tylermurphy.hideAndSeek.game.Game;
|
import net.tylermurphy.hideAndSeek.game.Game;
|
||||||
import net.tylermurphy.hideAndSeek.util.Status;
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Location;
|
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import static net.tylermurphy.hideAndSeek.configuration.Localization.*;
|
import static net.tylermurphy.hideAndSeek.configuration.Config.errorPrefix;
|
||||||
|
import static net.tylermurphy.hideAndSeek.configuration.Localization.message;
|
||||||
|
|
||||||
public class Leave implements ICommand {
|
public class Leave implements ICommand {
|
||||||
|
|
||||||
public void execute(CommandSender sender, String[] args) {
|
public void execute(CommandSender sender, String[] args) {
|
||||||
if(Game.isNotSetup()) {
|
if (Game.isNotSetup()) {
|
||||||
sender.sendMessage(errorPrefix + message("GAME_SETUP"));
|
sender.sendMessage(errorPrefix + message("GAME_SETUP"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Player player = Bukkit.getServer().getPlayer(sender.getName());
|
Player player = Bukkit.getServer().getPlayer(sender.getName());
|
||||||
if(player == null) {
|
if (player == null) {
|
||||||
sender.sendMessage(errorPrefix + message("COMMAND_ERROR"));
|
sender.sendMessage(errorPrefix + message("COMMAND_ERROR"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if(!Board.isPlayer(player)) {
|
if (!Board.contains(player)) {
|
||||||
sender.sendMessage(errorPrefix + message("GAME_NOT_INGAME"));
|
sender.sendMessage(errorPrefix + message("GAME_NOT_INGAME"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,23 +19,22 @@
|
||||||
|
|
||||||
package net.tylermurphy.hideAndSeek.command;
|
package net.tylermurphy.hideAndSeek.command;
|
||||||
|
|
||||||
import static net.tylermurphy.hideAndSeek.configuration.Config.*;
|
import net.tylermurphy.hideAndSeek.configuration.Config;
|
||||||
|
|
||||||
import net.tylermurphy.hideAndSeek.configuration.Items;
|
import net.tylermurphy.hideAndSeek.configuration.Items;
|
||||||
|
import net.tylermurphy.hideAndSeek.configuration.Localization;
|
||||||
import net.tylermurphy.hideAndSeek.game.Game;
|
import net.tylermurphy.hideAndSeek.game.Game;
|
||||||
import net.tylermurphy.hideAndSeek.util.Status;
|
import net.tylermurphy.hideAndSeek.util.Status;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
|
|
||||||
import net.tylermurphy.hideAndSeek.configuration.Config;
|
import static net.tylermurphy.hideAndSeek.configuration.Config.errorPrefix;
|
||||||
import net.tylermurphy.hideAndSeek.configuration.Localization;
|
import static net.tylermurphy.hideAndSeek.configuration.Config.messagePrefix;
|
||||||
|
import static net.tylermurphy.hideAndSeek.configuration.Localization.message;
|
||||||
import static net.tylermurphy.hideAndSeek.configuration.Localization.*;
|
|
||||||
|
|
||||||
public class Reload implements ICommand {
|
public class Reload implements ICommand {
|
||||||
|
|
||||||
public void execute(CommandSender sender, String[] args) {
|
public void execute(CommandSender sender, String[] args) {
|
||||||
|
|
||||||
if(Game.status != Status.STANDBY) {
|
if (Game.status != Status.STANDBY) {
|
||||||
sender.sendMessage(errorPrefix + message("GAME_INPROGRESS"));
|
sender.sendMessage(errorPrefix + message("GAME_INPROGRESS"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,8 +19,7 @@
|
||||||
|
|
||||||
package net.tylermurphy.hideAndSeek.command;
|
package net.tylermurphy.hideAndSeek.command;
|
||||||
|
|
||||||
import static net.tylermurphy.hideAndSeek.configuration.Config.*;
|
import net.tylermurphy.hideAndSeek.Main;
|
||||||
|
|
||||||
import net.tylermurphy.hideAndSeek.game.Game;
|
import net.tylermurphy.hideAndSeek.game.Game;
|
||||||
import net.tylermurphy.hideAndSeek.util.Status;
|
import net.tylermurphy.hideAndSeek.util.Status;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
|
@ -28,30 +27,30 @@ import org.bukkit.World;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.scheduler.BukkitRunnable;
|
import org.bukkit.scheduler.BukkitRunnable;
|
||||||
|
|
||||||
import net.tylermurphy.hideAndSeek.Main;
|
import static net.tylermurphy.hideAndSeek.configuration.Config.*;
|
||||||
import static net.tylermurphy.hideAndSeek.configuration.Localization.*;
|
import static net.tylermurphy.hideAndSeek.configuration.Localization.message;
|
||||||
|
|
||||||
public class SaveMap implements ICommand {
|
public class SaveMap implements ICommand {
|
||||||
|
|
||||||
public static boolean runningBackup = false;
|
public static boolean runningBackup = false;
|
||||||
|
|
||||||
public void execute(CommandSender sender, String[] args) {
|
public void execute(CommandSender sender, String[] args) {
|
||||||
if(!mapSaveEnabled){
|
if (!mapSaveEnabled) {
|
||||||
sender.sendMessage(errorPrefix + message("MAPSAVE_DISABLED"));
|
sender.sendMessage(errorPrefix + message("MAPSAVE_DISABLED"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if(Game.status != Status.STANDBY) {
|
if (Game.status != Status.STANDBY) {
|
||||||
sender.sendMessage(errorPrefix + message("GAME_INPROGRESS"));
|
sender.sendMessage(errorPrefix + message("GAME_INPROGRESS"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if(spawnPosition.getBlockX() == 0 && spawnPosition.getBlockY() == 0 && spawnPosition.getBlockZ() == 0) {
|
if (spawnPosition.getBlockX() == 0 && spawnPosition.getBlockY() == 0 && spawnPosition.getBlockZ() == 0) {
|
||||||
sender.sendMessage(errorPrefix + message("ERROR_GAME_SPAWN"));
|
sender.sendMessage(errorPrefix + message("ERROR_GAME_SPAWN"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
sender.sendMessage(messagePrefix + message("MAPSAVE_START"));
|
sender.sendMessage(messagePrefix + message("MAPSAVE_START"));
|
||||||
sender.sendMessage(warningPrefix + message("MAPSAVE_WARNING"));
|
sender.sendMessage(warningPrefix + message("MAPSAVE_WARNING"));
|
||||||
World world = Bukkit.getServer().getWorld(spawnWorld);
|
World world = Bukkit.getServer().getWorld(spawnWorld);
|
||||||
if(world == null){
|
if (world == null) {
|
||||||
throw new RuntimeException("Unable to get world: " + spawnWorld);
|
throw new RuntimeException("Unable to get world: " + spawnWorld);
|
||||||
}
|
}
|
||||||
world.save();
|
world.save();
|
||||||
|
|
|
@ -19,33 +19,32 @@
|
||||||
|
|
||||||
package net.tylermurphy.hideAndSeek.command;
|
package net.tylermurphy.hideAndSeek.command;
|
||||||
|
|
||||||
import static net.tylermurphy.hideAndSeek.configuration.Config.*;
|
|
||||||
|
|
||||||
import net.tylermurphy.hideAndSeek.game.Game;
|
import net.tylermurphy.hideAndSeek.game.Game;
|
||||||
import net.tylermurphy.hideAndSeek.util.Status;
|
import net.tylermurphy.hideAndSeek.util.Status;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.util.Vector;
|
import org.bukkit.util.Vector;
|
||||||
|
|
||||||
import static net.tylermurphy.hideAndSeek.configuration.Localization.*;
|
import static net.tylermurphy.hideAndSeek.configuration.Config.*;
|
||||||
|
import static net.tylermurphy.hideAndSeek.configuration.Localization.message;
|
||||||
|
|
||||||
public class SetBorder implements ICommand {
|
public class SetBorder implements ICommand {
|
||||||
|
|
||||||
public void execute(CommandSender sender, String[] args) {
|
public void execute(CommandSender sender, String[] args) {
|
||||||
if(Game.status != Status.STANDBY) {
|
if (Game.status != Status.STANDBY) {
|
||||||
sender.sendMessage(errorPrefix + message("GAME_INPROGRESS"));
|
sender.sendMessage(errorPrefix + message("GAME_INPROGRESS"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if(spawnPosition == null) {
|
if (spawnPosition == null) {
|
||||||
sender.sendMessage(errorPrefix + message("ERROR_GAME_SPAWN"));
|
sender.sendMessage(errorPrefix + message("ERROR_GAME_SPAWN"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if(args.length < 3) {
|
if (args.length < 3) {
|
||||||
worldborderEnabled = false;
|
worldborderEnabled = false;
|
||||||
addToConfig("worldBorder.enabled",false);
|
addToConfig("worldBorder.enabled",false);
|
||||||
saveConfig();
|
saveConfig();
|
||||||
sender.sendMessage(messagePrefix + message("WORLDBORDER_DISABLE"));
|
sender.sendMessage(messagePrefix + message("WORLDBORDER_DISABLE"));
|
||||||
Game.resetWorldborder(spawnWorld);
|
Game.resetWorldBorder(spawnWorld);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
int num,delay,change;
|
int num,delay,change;
|
||||||
|
@ -61,11 +60,11 @@ public class SetBorder implements ICommand {
|
||||||
sender.sendMessage(errorPrefix + message("WORLDBORDER_INVALID_INPUT").addAmount(args[2]));
|
sender.sendMessage(errorPrefix + message("WORLDBORDER_INVALID_INPUT").addAmount(args[2]));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if(num < 100) {
|
if (num < 100) {
|
||||||
sender.sendMessage(errorPrefix + message("WORLDBORDER_MIN_SIZE"));
|
sender.sendMessage(errorPrefix + message("WORLDBORDER_MIN_SIZE"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if(change < 1) {
|
if (change < 1) {
|
||||||
sender.sendMessage(errorPrefix + message("WORLDBORDER_CHANGE_SIZE"));
|
sender.sendMessage(errorPrefix + message("WORLDBORDER_CHANGE_SIZE"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -74,7 +73,7 @@ public class SetBorder implements ICommand {
|
||||||
newWorldborderPosition.setX(player.getLocation().getBlockX());
|
newWorldborderPosition.setX(player.getLocation().getBlockX());
|
||||||
newWorldborderPosition.setY(0);
|
newWorldborderPosition.setY(0);
|
||||||
newWorldborderPosition.setZ(player.getLocation().getBlockZ());
|
newWorldborderPosition.setZ(player.getLocation().getBlockZ());
|
||||||
if(spawnPosition.distance(newWorldborderPosition) > 100) {
|
if (spawnPosition.distance(newWorldborderPosition) > 100) {
|
||||||
sender.sendMessage(errorPrefix + message("WORLDBORDER_POSITION"));
|
sender.sendMessage(errorPrefix + message("WORLDBORDER_POSITION"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -91,7 +90,7 @@ public class SetBorder implements ICommand {
|
||||||
addToConfig("worldBorder.move", worldborderChange);
|
addToConfig("worldBorder.move", worldborderChange);
|
||||||
sender.sendMessage(messagePrefix + message("WORLDBORDER_ENABLE").addAmount(num).addAmount(delay));
|
sender.sendMessage(messagePrefix + message("WORLDBORDER_ENABLE").addAmount(num).addAmount(delay));
|
||||||
saveConfig();
|
saveConfig();
|
||||||
Game.resetWorldborder(spawnWorld);
|
Game.resetWorldBorder(spawnWorld);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getLabel() {
|
public String getLabel() {
|
||||||
|
|
|
@ -19,43 +19,42 @@
|
||||||
|
|
||||||
package net.tylermurphy.hideAndSeek.command;
|
package net.tylermurphy.hideAndSeek.command;
|
||||||
|
|
||||||
import static net.tylermurphy.hideAndSeek.configuration.Config.*;
|
|
||||||
|
|
||||||
import net.tylermurphy.hideAndSeek.game.Game;
|
import net.tylermurphy.hideAndSeek.game.Game;
|
||||||
import net.tylermurphy.hideAndSeek.util.Status;
|
import net.tylermurphy.hideAndSeek.util.Status;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import static net.tylermurphy.hideAndSeek.configuration.Localization.*;
|
import static net.tylermurphy.hideAndSeek.configuration.Config.*;
|
||||||
|
import static net.tylermurphy.hideAndSeek.configuration.Localization.message;
|
||||||
|
|
||||||
public class SetBounds implements ICommand {
|
public class SetBounds implements ICommand {
|
||||||
|
|
||||||
public void execute(CommandSender sender, String[] args) {
|
public void execute(CommandSender sender, String[] args) {
|
||||||
if(Game.status != Status.STANDBY) {
|
if (Game.status != Status.STANDBY) {
|
||||||
sender.sendMessage(errorPrefix + message("GAME_INPROGRESS"));
|
sender.sendMessage(errorPrefix + message("GAME_INPROGRESS"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if(spawnPosition == null) {
|
if (spawnPosition == null) {
|
||||||
sender.sendMessage(errorPrefix + message("ERROR_GAME_SPAWN"));
|
sender.sendMessage(errorPrefix + message("ERROR_GAME_SPAWN"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Player player = (Player) sender;
|
Player player = (Player) sender;
|
||||||
if(!player.getWorld().getName().equals(spawnWorld)){
|
if (!player.getWorld().getName().equals(spawnWorld)) {
|
||||||
sender.sendMessage(errorPrefix + message("BOUNDS_WRONG_WORLD"));
|
sender.sendMessage(errorPrefix + message("BOUNDS_WRONG_WORLD"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if(player.getLocation().getBlockX() == 0 || player.getLocation().getBlockZ() == 0){
|
if (player.getLocation().getBlockX() == 0 || player.getLocation().getBlockZ() == 0) {
|
||||||
sender.sendMessage(errorPrefix + message("NOT_AT_ZERO"));
|
sender.sendMessage(errorPrefix + message("NOT_AT_ZERO"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
boolean first = true;
|
boolean first = true;
|
||||||
if(saveMinX != 0 && saveMinZ != 0 && saveMaxX != 0 && saveMaxZ != 0) {
|
if (saveMinX != 0 && saveMinZ != 0 && saveMaxX != 0 && saveMaxZ != 0) {
|
||||||
saveMinX = 0; saveMinZ= 0; saveMaxX = 0; saveMaxZ = 0;
|
saveMinX = 0; saveMinZ= 0; saveMaxX = 0; saveMaxZ = 0;
|
||||||
}
|
}
|
||||||
if(saveMaxX == 0) {
|
if (saveMaxX == 0) {
|
||||||
addToConfig("bounds.max.x", player.getLocation().getBlockX());
|
addToConfig("bounds.max.x", player.getLocation().getBlockX());
|
||||||
saveMaxX = player.getLocation().getBlockX();
|
saveMaxX = player.getLocation().getBlockX();
|
||||||
} else if(saveMaxX < player.getLocation().getBlockX()) {
|
} else if (saveMaxX < player.getLocation().getBlockX()) {
|
||||||
first = false;
|
first = false;
|
||||||
addToConfig("bounds.max.x", player.getLocation().getBlockX());
|
addToConfig("bounds.max.x", player.getLocation().getBlockX());
|
||||||
addToConfig("bounds.min.x", saveMaxX);
|
addToConfig("bounds.min.x", saveMaxX);
|
||||||
|
@ -66,10 +65,10 @@ public class SetBounds implements ICommand {
|
||||||
addToConfig("bounds.min.x", player.getLocation().getBlockX());
|
addToConfig("bounds.min.x", player.getLocation().getBlockX());
|
||||||
saveMinX = player.getLocation().getBlockX();
|
saveMinX = player.getLocation().getBlockX();
|
||||||
}
|
}
|
||||||
if(saveMaxZ == 0) {
|
if (saveMaxZ == 0) {
|
||||||
addToConfig("bounds.max.z", player.getLocation().getBlockZ());
|
addToConfig("bounds.max.z", player.getLocation().getBlockZ());
|
||||||
saveMaxZ = player.getLocation().getBlockZ();
|
saveMaxZ = player.getLocation().getBlockZ();
|
||||||
} else if(saveMaxZ < player.getLocation().getBlockZ()) {
|
} else if (saveMaxZ < player.getLocation().getBlockZ()) {
|
||||||
first = false;
|
first = false;
|
||||||
addToConfig("bounds.max.z", player.getLocation().getBlockZ());
|
addToConfig("bounds.max.z", player.getLocation().getBlockZ());
|
||||||
addToConfig("bounds.min.z", saveMaxZ);
|
addToConfig("bounds.min.z", saveMaxZ);
|
||||||
|
|
|
@ -19,8 +19,6 @@
|
||||||
|
|
||||||
package net.tylermurphy.hideAndSeek.command;
|
package net.tylermurphy.hideAndSeek.command;
|
||||||
|
|
||||||
import static net.tylermurphy.hideAndSeek.configuration.Config.*;
|
|
||||||
|
|
||||||
import net.tylermurphy.hideAndSeek.game.Game;
|
import net.tylermurphy.hideAndSeek.game.Game;
|
||||||
import net.tylermurphy.hideAndSeek.util.Status;
|
import net.tylermurphy.hideAndSeek.util.Status;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
|
@ -28,18 +26,19 @@ import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.util.Vector;
|
import org.bukkit.util.Vector;
|
||||||
|
|
||||||
import static net.tylermurphy.hideAndSeek.configuration.Localization.*;
|
import static net.tylermurphy.hideAndSeek.configuration.Config.*;
|
||||||
|
import static net.tylermurphy.hideAndSeek.configuration.Localization.message;
|
||||||
|
|
||||||
public class SetExitLocation implements ICommand {
|
public class SetExitLocation implements ICommand {
|
||||||
|
|
||||||
public void execute(CommandSender sender, String[] args) {
|
public void execute(CommandSender sender, String[] args) {
|
||||||
if(Game.status != Status.STANDBY) {
|
if (Game.status != Status.STANDBY) {
|
||||||
sender.sendMessage(errorPrefix + message("GAME_INPROGRESS"));
|
sender.sendMessage(errorPrefix + message("GAME_INPROGRESS"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Vector newExitPosition = new Vector();
|
Vector newExitPosition = new Vector();
|
||||||
Player player = (Player) sender;
|
Player player = (Player) sender;
|
||||||
if(player.getLocation().getBlockX() == 0 || player.getLocation().getBlockZ() == 0 || player.getLocation().getBlockY() == 0){
|
if (player.getLocation().getBlockX() == 0 || player.getLocation().getBlockZ() == 0 || player.getLocation().getBlockY() == 0) {
|
||||||
sender.sendMessage(errorPrefix + message("NOT_AT_ZERO"));
|
sender.sendMessage(errorPrefix + message("NOT_AT_ZERO"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -47,7 +46,7 @@ public class SetExitLocation implements ICommand {
|
||||||
newExitPosition.setY(player.getLocation().getBlockY());
|
newExitPosition.setY(player.getLocation().getBlockY());
|
||||||
newExitPosition.setZ(player.getLocation().getBlockZ());
|
newExitPosition.setZ(player.getLocation().getBlockZ());
|
||||||
World world = player.getLocation().getWorld();
|
World world = player.getLocation().getWorld();
|
||||||
if(world == null){
|
if (world == null) {
|
||||||
throw new RuntimeException("Unable to get world: " + spawnWorld);
|
throw new RuntimeException("Unable to get world: " + spawnWorld);
|
||||||
}
|
}
|
||||||
exitWorld = world.getName();
|
exitWorld = world.getName();
|
||||||
|
|
|
@ -19,8 +19,6 @@
|
||||||
|
|
||||||
package net.tylermurphy.hideAndSeek.command;
|
package net.tylermurphy.hideAndSeek.command;
|
||||||
|
|
||||||
import static net.tylermurphy.hideAndSeek.configuration.Config.*;
|
|
||||||
|
|
||||||
import net.tylermurphy.hideAndSeek.game.Game;
|
import net.tylermurphy.hideAndSeek.game.Game;
|
||||||
import net.tylermurphy.hideAndSeek.util.Status;
|
import net.tylermurphy.hideAndSeek.util.Status;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
|
@ -28,18 +26,19 @@ import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.util.Vector;
|
import org.bukkit.util.Vector;
|
||||||
|
|
||||||
import static net.tylermurphy.hideAndSeek.configuration.Localization.*;
|
import static net.tylermurphy.hideAndSeek.configuration.Config.*;
|
||||||
|
import static net.tylermurphy.hideAndSeek.configuration.Localization.message;
|
||||||
|
|
||||||
public class SetLobbyLocation implements ICommand {
|
public class SetLobbyLocation implements ICommand {
|
||||||
|
|
||||||
public void execute(CommandSender sender, String[] args) {
|
public void execute(CommandSender sender, String[] args) {
|
||||||
if(Game.status != Status.STANDBY) {
|
if (Game.status != Status.STANDBY) {
|
||||||
sender.sendMessage(errorPrefix + message("GAME_INPROGRESS"));
|
sender.sendMessage(errorPrefix + message("GAME_INPROGRESS"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Vector newLobbyPosition = new Vector();
|
Vector newLobbyPosition = new Vector();
|
||||||
Player player = (Player) sender;
|
Player player = (Player) sender;
|
||||||
if(player.getLocation().getBlockX() == 0 || player.getLocation().getBlockZ() == 0 || player.getLocation().getBlockY() == 0){
|
if (player.getLocation().getBlockX() == 0 || player.getLocation().getBlockZ() == 0 || player.getLocation().getBlockY() == 0) {
|
||||||
sender.sendMessage(errorPrefix + message("NOT_AT_ZERO"));
|
sender.sendMessage(errorPrefix + message("NOT_AT_ZERO"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -47,7 +46,7 @@ public class SetLobbyLocation implements ICommand {
|
||||||
newLobbyPosition.setY(player.getLocation().getBlockY());
|
newLobbyPosition.setY(player.getLocation().getBlockY());
|
||||||
newLobbyPosition.setZ(player.getLocation().getBlockZ());
|
newLobbyPosition.setZ(player.getLocation().getBlockZ());
|
||||||
World world = player.getLocation().getWorld();
|
World world = player.getLocation().getWorld();
|
||||||
if(world == null){
|
if (world == null) {
|
||||||
throw new RuntimeException("Unable to get world: " + spawnWorld);
|
throw new RuntimeException("Unable to get world: " + spawnWorld);
|
||||||
}
|
}
|
||||||
lobbyWorld = world.getName();
|
lobbyWorld = world.getName();
|
||||||
|
|
|
@ -19,8 +19,6 @@
|
||||||
|
|
||||||
package net.tylermurphy.hideAndSeek.command;
|
package net.tylermurphy.hideAndSeek.command;
|
||||||
|
|
||||||
import static net.tylermurphy.hideAndSeek.configuration.Config.*;
|
|
||||||
|
|
||||||
import net.tylermurphy.hideAndSeek.game.Game;
|
import net.tylermurphy.hideAndSeek.game.Game;
|
||||||
import net.tylermurphy.hideAndSeek.util.Status;
|
import net.tylermurphy.hideAndSeek.util.Status;
|
||||||
import net.tylermurphy.hideAndSeek.world.WorldLoader;
|
import net.tylermurphy.hideAndSeek.world.WorldLoader;
|
||||||
|
@ -29,34 +27,34 @@ import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.util.Vector;
|
import org.bukkit.util.Vector;
|
||||||
|
|
||||||
import static net.tylermurphy.hideAndSeek.configuration.Config.addToConfig;
|
import static net.tylermurphy.hideAndSeek.configuration.Config.*;
|
||||||
import static net.tylermurphy.hideAndSeek.configuration.Localization.*;
|
import static net.tylermurphy.hideAndSeek.configuration.Localization.message;
|
||||||
|
|
||||||
public class SetSpawnLocation implements ICommand {
|
public class SetSpawnLocation implements ICommand {
|
||||||
|
|
||||||
public void execute(CommandSender sender, String[] args) {
|
public void execute(CommandSender sender, String[] args) {
|
||||||
if(Game.status != Status.STANDBY) {
|
if (Game.status != Status.STANDBY) {
|
||||||
sender.sendMessage(errorPrefix + message("GAME_INPROGRESS"));
|
sender.sendMessage(errorPrefix + message("GAME_INPROGRESS"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Vector newSpawnPosition = new Vector();
|
Vector newSpawnPosition = new Vector();
|
||||||
Player player = (Player) sender;
|
Player player = (Player) sender;
|
||||||
if(player.getLocation().getBlockX() == 0 || player.getLocation().getBlockZ() == 0 || player.getLocation().getBlockY() == 0){
|
if (player.getLocation().getBlockX() == 0 || player.getLocation().getBlockZ() == 0 || player.getLocation().getBlockY() == 0) {
|
||||||
sender.sendMessage(errorPrefix + message("NOT_AT_ZERO"));
|
sender.sendMessage(errorPrefix + message("NOT_AT_ZERO"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
newSpawnPosition.setX(player.getLocation().getBlockX());
|
newSpawnPosition.setX(player.getLocation().getBlockX());
|
||||||
newSpawnPosition.setY(player.getLocation().getBlockY());
|
newSpawnPosition.setY(player.getLocation().getBlockY());
|
||||||
newSpawnPosition.setZ(player.getLocation().getBlockZ());
|
newSpawnPosition.setZ(player.getLocation().getBlockZ());
|
||||||
if(worldborderEnabled && newSpawnPosition.distance(worldborderPosition) > 100) {
|
if (worldborderEnabled && newSpawnPosition.distance(worldborderPosition) > 100) {
|
||||||
sender.sendMessage(errorPrefix + message("WORLDBORDER_POSITION"));
|
sender.sendMessage(errorPrefix + message("WORLDBORDER_POSITION"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
World world = player.getLocation().getWorld();
|
World world = player.getLocation().getWorld();
|
||||||
if(world == null){
|
if (world == null) {
|
||||||
throw new RuntimeException("Unable to get world: " + spawnWorld);
|
throw new RuntimeException("Unable to get world: " + spawnWorld);
|
||||||
}
|
}
|
||||||
if(mapSaveEnabled && !world.getName().equals(spawnWorld)){
|
if (mapSaveEnabled && !world.getName().equals(spawnWorld)) {
|
||||||
Game.worldLoader.unloadMap();
|
Game.worldLoader.unloadMap();
|
||||||
Game.worldLoader = new WorldLoader(world.getName());
|
Game.worldLoader = new WorldLoader(world.getName());
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,15 +19,14 @@
|
||||||
|
|
||||||
package net.tylermurphy.hideAndSeek.command;
|
package net.tylermurphy.hideAndSeek.command;
|
||||||
|
|
||||||
|
import net.tylermurphy.hideAndSeek.Main;
|
||||||
import net.tylermurphy.hideAndSeek.game.Game;
|
import net.tylermurphy.hideAndSeek.game.Game;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
|
|
||||||
import net.tylermurphy.hideAndSeek.Main;
|
import java.io.File;
|
||||||
|
|
||||||
import static net.tylermurphy.hideAndSeek.configuration.Config.*;
|
import static net.tylermurphy.hideAndSeek.configuration.Config.*;
|
||||||
|
import static net.tylermurphy.hideAndSeek.configuration.Localization.message;
|
||||||
import java.io.File;
|
|
||||||
import static net.tylermurphy.hideAndSeek.configuration.Localization.*;
|
|
||||||
|
|
||||||
public class Setup implements ICommand {
|
public class Setup implements ICommand {
|
||||||
|
|
||||||
|
@ -36,30 +35,30 @@ public class Setup implements ICommand {
|
||||||
String msg = message("SETUP").toString();
|
String msg = message("SETUP").toString();
|
||||||
int count = 0;
|
int count = 0;
|
||||||
|
|
||||||
if(spawnPosition.getBlockX() == 0 && spawnPosition.getBlockY() == 0 && spawnPosition.getBlockZ() == 0) {
|
if (spawnPosition.getBlockX() == 0 && spawnPosition.getBlockY() == 0 && spawnPosition.getBlockZ() == 0) {
|
||||||
msg = msg + "\n" + message("SETUP_GAME");
|
msg = msg + "\n" + message("SETUP_GAME");
|
||||||
count++;
|
count++;
|
||||||
}
|
}
|
||||||
if(lobbyPosition.getBlockX() == 0 && lobbyPosition.getBlockY() == 0 && lobbyPosition.getBlockZ() == 0) {
|
if (lobbyPosition.getBlockX() == 0 && lobbyPosition.getBlockY() == 0 && lobbyPosition.getBlockZ() == 0) {
|
||||||
msg = msg + "\n" + message("SETUP_LOBBY");
|
msg = msg + "\n" + message("SETUP_LOBBY");
|
||||||
count++;
|
count++;
|
||||||
}
|
}
|
||||||
if(exitPosition.getBlockX() == 0 && exitPosition.getBlockY() == 0 && exitPosition.getBlockZ() == 0) {
|
if (exitPosition.getBlockX() == 0 && exitPosition.getBlockY() == 0 && exitPosition.getBlockZ() == 0) {
|
||||||
msg = msg + "\n" + message("SETUP_EXIT");
|
msg = msg + "\n" + message("SETUP_EXIT");
|
||||||
count++;
|
count++;
|
||||||
}
|
}
|
||||||
if(saveMinX == 0 || saveMinZ == 0 || saveMaxX == 0 || saveMaxZ == 0) {
|
if (saveMinX == 0 || saveMinZ == 0 || saveMaxX == 0 || saveMaxZ == 0) {
|
||||||
msg = msg + "\n" + message("SETUP_BOUNDS");
|
msg = msg + "\n" + message("SETUP_BOUNDS");
|
||||||
count++;
|
count++;
|
||||||
}
|
}
|
||||||
if(mapSaveEnabled) {
|
if (mapSaveEnabled) {
|
||||||
File destenation = new File(Main.root + File.separator + Game.getGameWorld());
|
File destenation = new File(Main.root + File.separator + Game.getGameWorld());
|
||||||
if (!destenation.exists()) {
|
if (!destenation.exists()) {
|
||||||
msg = msg + "\n" + message("SETUP_SAVEMAP");
|
msg = msg + "\n" + message("SETUP_SAVEMAP");
|
||||||
count++;
|
count++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(count < 1) {
|
if (count < 1) {
|
||||||
sender.sendMessage(messagePrefix + message("SETUP_COMPLETE"));
|
sender.sendMessage(messagePrefix + message("SETUP_COMPLETE"));
|
||||||
} else {
|
} else {
|
||||||
sender.sendMessage(msg);
|
sender.sendMessage(msg);
|
||||||
|
|
|
@ -19,8 +19,7 @@
|
||||||
|
|
||||||
package net.tylermurphy.hideAndSeek.command;
|
package net.tylermurphy.hideAndSeek.command;
|
||||||
|
|
||||||
import static net.tylermurphy.hideAndSeek.configuration.Localization.*;
|
import net.tylermurphy.hideAndSeek.Main;
|
||||||
|
|
||||||
import net.tylermurphy.hideAndSeek.game.Board;
|
import net.tylermurphy.hideAndSeek.game.Board;
|
||||||
import net.tylermurphy.hideAndSeek.game.Game;
|
import net.tylermurphy.hideAndSeek.game.Game;
|
||||||
import net.tylermurphy.hideAndSeek.util.Status;
|
import net.tylermurphy.hideAndSeek.util.Status;
|
||||||
|
@ -28,36 +27,36 @@ import org.bukkit.Bukkit;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import net.tylermurphy.hideAndSeek.Main;
|
|
||||||
|
|
||||||
import static net.tylermurphy.hideAndSeek.configuration.Config.*;
|
|
||||||
|
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
|
||||||
|
import static net.tylermurphy.hideAndSeek.configuration.Config.errorPrefix;
|
||||||
|
import static net.tylermurphy.hideAndSeek.configuration.Config.minPlayers;
|
||||||
|
import static net.tylermurphy.hideAndSeek.configuration.Localization.message;
|
||||||
|
|
||||||
public class Start implements ICommand {
|
public class Start implements ICommand {
|
||||||
|
|
||||||
public void execute(CommandSender sender, String[] args) {
|
public void execute(CommandSender sender, String[] args) {
|
||||||
if(Game.isNotSetup()) {
|
if (Game.isNotSetup()) {
|
||||||
sender.sendMessage(errorPrefix + message("GAME_SETUP"));
|
sender.sendMessage(errorPrefix + message("GAME_SETUP"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if(Game.status != Status.STANDBY) {
|
if (Game.status != Status.STANDBY) {
|
||||||
sender.sendMessage(errorPrefix + message("GAME_INPROGRESS"));
|
sender.sendMessage(errorPrefix + message("GAME_INPROGRESS"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if(!Board.isPlayer(sender)) {
|
if (!Board.contains(sender)) {
|
||||||
sender.sendMessage(errorPrefix + message("GAME_NOT_INGAME"));
|
sender.sendMessage(errorPrefix + message("GAME_NOT_INGAME"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if(Board.size() < minPlayers) {
|
if (Board.size() < minPlayers) {
|
||||||
sender.sendMessage(errorPrefix + message("START_MIN_PLAYERS").addAmount(minPlayers));
|
sender.sendMessage(errorPrefix + message("START_MIN_PLAYERS").addAmount(minPlayers));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
String seekerName;
|
String seekerName;
|
||||||
if(args.length < 1) {
|
if (args.length < 1) {
|
||||||
Optional<Player> rand = Board.getPlayers().stream().skip(new Random().nextInt(Board.size())).findFirst();
|
Optional<Player> rand = Board.getPlayers().stream().skip(new Random().nextInt(Board.size())).findFirst();
|
||||||
if(!rand.isPresent()){
|
if (!rand.isPresent()) {
|
||||||
Main.plugin.getLogger().warning("Failed to select random seeker.");
|
Main.plugin.getLogger().warning("Failed to select random seeker.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -66,12 +65,12 @@ public class Start implements ICommand {
|
||||||
seekerName = args[0];
|
seekerName = args[0];
|
||||||
}
|
}
|
||||||
Player temp = Bukkit.getPlayer(seekerName);
|
Player temp = Bukkit.getPlayer(seekerName);
|
||||||
if(temp == null) {
|
if (temp == null) {
|
||||||
sender.sendMessage(errorPrefix + message("START_INVALID_NAME").addPlayer(seekerName));
|
sender.sendMessage(errorPrefix + message("START_INVALID_NAME").addPlayer(seekerName));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Player seeker = Board.getPlayer(temp.getUniqueId());
|
Player seeker = Board.getPlayer(temp.getUniqueId());
|
||||||
if(seeker == null) {
|
if (seeker == null) {
|
||||||
sender.sendMessage(errorPrefix + message("START_INVALID_NAME").addPlayer(seekerName));
|
sender.sendMessage(errorPrefix + message("START_INVALID_NAME").addPlayer(seekerName));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,22 +19,22 @@
|
||||||
|
|
||||||
package net.tylermurphy.hideAndSeek.command;
|
package net.tylermurphy.hideAndSeek.command;
|
||||||
|
|
||||||
import static net.tylermurphy.hideAndSeek.configuration.Config.*;
|
|
||||||
|
|
||||||
import net.tylermurphy.hideAndSeek.game.Game;
|
import net.tylermurphy.hideAndSeek.game.Game;
|
||||||
import net.tylermurphy.hideAndSeek.util.Status;
|
import net.tylermurphy.hideAndSeek.util.Status;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
|
|
||||||
import static net.tylermurphy.hideAndSeek.configuration.Localization.*;
|
import static net.tylermurphy.hideAndSeek.configuration.Config.abortPrefix;
|
||||||
|
import static net.tylermurphy.hideAndSeek.configuration.Config.errorPrefix;
|
||||||
|
import static net.tylermurphy.hideAndSeek.configuration.Localization.message;
|
||||||
|
|
||||||
public class Stop implements ICommand {
|
public class Stop implements ICommand {
|
||||||
|
|
||||||
public void execute(CommandSender sender, String[] args) {
|
public void execute(CommandSender sender, String[] args) {
|
||||||
if(Game.isNotSetup()) {
|
if (Game.isNotSetup()) {
|
||||||
sender.sendMessage(errorPrefix + "Game is not setup. Run /hs setup to see what you needed to do");
|
sender.sendMessage(errorPrefix + "Game is not setup. Run /hs setup to see what you needed to do");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if(Game.status == Status.STARTING || Game.status == Status.PLAYING) {
|
if (Game.status == Status.STARTING || Game.status == Status.PLAYING) {
|
||||||
Game.broadcastMessage(abortPrefix + message("STOP"));
|
Game.broadcastMessage(abortPrefix + message("STOP"));
|
||||||
Game.end();
|
Game.end();
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -27,21 +27,21 @@ import org.bukkit.command.CommandSender;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import static net.tylermurphy.hideAndSeek.configuration.Config.*;
|
import static net.tylermurphy.hideAndSeek.configuration.Config.errorPrefix;
|
||||||
import static net.tylermurphy.hideAndSeek.configuration.Localization.*;
|
import static net.tylermurphy.hideAndSeek.configuration.Localization.message;
|
||||||
|
|
||||||
public class Top implements ICommand {
|
public class Top implements ICommand {
|
||||||
|
|
||||||
public void execute(CommandSender sender, String[] args) {
|
public void execute(CommandSender sender, String[] args) {
|
||||||
int page;
|
int page;
|
||||||
if(args.length == 0) page = 1;
|
if (args.length == 0) page = 1;
|
||||||
else try{
|
else try{
|
||||||
page = Integer.parseInt(args[0]);
|
page = Integer.parseInt(args[0]);
|
||||||
} catch(Exception e){
|
} catch(Exception e) {
|
||||||
sender.sendMessage(errorPrefix + message("WORLDBORDER_INVALID_INPUT").addAmount(args[0]));
|
sender.sendMessage(errorPrefix + message("WORLDBORDER_INVALID_INPUT").addAmount(args[0]));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if(page < 1){
|
if (page < 1) {
|
||||||
sender.sendMessage(errorPrefix + message("WORLDBORDER_INVALID_INPUT").addAmount(page));
|
sender.sendMessage(errorPrefix + message("WORLDBORDER_INVALID_INPUT").addAmount(page));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -50,14 +50,14 @@ public class Top implements ICommand {
|
||||||
ChatColor.WHITE, ChatColor.BOLD, ChatColor.GRAY, page, ChatColor.WHITE));
|
ChatColor.WHITE, ChatColor.BOLD, ChatColor.GRAY, page, ChatColor.WHITE));
|
||||||
List<PlayerInfo> infos = Database.playerInfo.getInfoPage(page);
|
List<PlayerInfo> infos = Database.playerInfo.getInfoPage(page);
|
||||||
int i = 1 + (page-1)*10;
|
int i = 1 + (page-1)*10;
|
||||||
if(infos == null){
|
if (infos == null) {
|
||||||
sender.sendMessage(errorPrefix + message("NO_GAME_INFO"));
|
sender.sendMessage(errorPrefix + message("NO_GAME_INFO"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
for(PlayerInfo info : infos){
|
for(PlayerInfo info : infos) {
|
||||||
String name = Main.plugin.getServer().getOfflinePlayer(info.uuid).getName();
|
String name = Main.plugin.getServer().getOfflinePlayer(info.uuid).getName();
|
||||||
ChatColor color;
|
ChatColor color;
|
||||||
switch (i){
|
switch (i) {
|
||||||
case 1: color = ChatColor.YELLOW; break;
|
case 1: color = ChatColor.YELLOW; break;
|
||||||
case 2: color = ChatColor.GRAY; break;
|
case 2: color = ChatColor.GRAY; break;
|
||||||
case 3: color = ChatColor.GOLD; break;
|
case 3: color = ChatColor.GOLD; break;
|
||||||
|
|
|
@ -29,8 +29,8 @@ import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import static net.tylermurphy.hideAndSeek.configuration.Config.*;
|
import static net.tylermurphy.hideAndSeek.configuration.Config.errorPrefix;
|
||||||
import static net.tylermurphy.hideAndSeek.configuration.Localization.*;
|
import static net.tylermurphy.hideAndSeek.configuration.Localization.message;
|
||||||
|
|
||||||
public class Wins implements ICommand {
|
public class Wins implements ICommand {
|
||||||
|
|
||||||
|
@ -39,9 +39,9 @@ public class Wins implements ICommand {
|
||||||
|
|
||||||
UUID uuid;
|
UUID uuid;
|
||||||
String name;
|
String name;
|
||||||
if(args.length == 0) {
|
if (args.length == 0) {
|
||||||
Player player = Main.plugin.getServer().getPlayer(sender.getName());
|
Player player = Main.plugin.getServer().getPlayer(sender.getName());
|
||||||
if(player == null){
|
if (player == null) {
|
||||||
sender.sendMessage(errorPrefix + message("START_INVALID_NAME").addPlayer(sender.getName()));
|
sender.sendMessage(errorPrefix + message("START_INVALID_NAME").addPlayer(sender.getName()));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -52,13 +52,13 @@ public class Wins implements ICommand {
|
||||||
try {
|
try {
|
||||||
name = args[0];
|
name = args[0];
|
||||||
uuid = UUIDFetcher.getUUID(args[0]);
|
uuid = UUIDFetcher.getUUID(args[0]);
|
||||||
} catch (Exception e){
|
} catch (Exception e) {
|
||||||
sender.sendMessage(errorPrefix + message("START_INVALID_NAME").addPlayer(args[0]));
|
sender.sendMessage(errorPrefix + message("START_INVALID_NAME").addPlayer(args[0]));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
PlayerInfo info = Database.playerInfo.getInfo(uuid);
|
PlayerInfo info = Database.playerInfo.getInfo(uuid);
|
||||||
if(info == null){
|
if (info == null) {
|
||||||
sender.sendMessage(errorPrefix + message("NO_GAME_INFO"));
|
sender.sendMessage(errorPrefix + message("NO_GAME_INFO"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,8 +39,8 @@ import java.util.Optional;
|
||||||
|
|
||||||
public class Config {
|
public class Config {
|
||||||
|
|
||||||
private static ConfigManager config, leaderboard;
|
private static ConfigManager config;
|
||||||
|
|
||||||
public static String
|
public static String
|
||||||
messagePrefix,
|
messagePrefix,
|
||||||
errorPrefix,
|
errorPrefix,
|
||||||
|
@ -150,7 +150,7 @@ public class Config {
|
||||||
|
|
||||||
config = ConfigManager.create("config.yml");
|
config = ConfigManager.create("config.yml");
|
||||||
config.saveConfig();
|
config.saveConfig();
|
||||||
leaderboard = ConfigManager.create("leaderboard.yml");
|
ConfigManager leaderboard = ConfigManager.create("leaderboard.yml");
|
||||||
|
|
||||||
//Spawn
|
//Spawn
|
||||||
spawnPosition = new Vector(
|
spawnPosition = new Vector(
|
||||||
|
@ -217,14 +217,14 @@ public class Config {
|
||||||
glowLength = Math.max(1, config.getInt("glow.time"));
|
glowLength = Math.max(1, config.getInt("glow.time"));
|
||||||
glowStackable = config.getBoolean("glow.stackable");
|
glowStackable = config.getBoolean("glow.stackable");
|
||||||
glowEnabled = config.getBoolean("glow.enabled") && Version.atLeast("1.9");
|
glowEnabled = config.getBoolean("glow.enabled") && Version.atLeast("1.9");
|
||||||
if(glowEnabled) {
|
if (glowEnabled) {
|
||||||
ConfigurationSection item = new YamlConfiguration().createSection("temp");
|
ConfigurationSection item = new YamlConfiguration().createSection("temp");
|
||||||
item.set("name", ChatColor.translateAlternateColorCodes('&',config.getString("glow.name")));
|
item.set("name", ChatColor.translateAlternateColorCodes('&',config.getString("glow.name")));
|
||||||
item.set("material", config.getString("glow.material"));
|
item.set("material", config.getString("glow.material"));
|
||||||
List<String> lore = config.getStringList("glow.lore");
|
List<String> lore = config.getStringList("glow.lore");
|
||||||
if (lore != null && !lore.isEmpty()) item.set("lore", lore);
|
if (lore != null && !lore.isEmpty()) item.set("lore", lore);
|
||||||
ItemStack temp = null;
|
ItemStack temp = null;
|
||||||
try{ temp = XItemStack.deserialize(item); } catch(Exception ignored){}
|
try{ temp = XItemStack.deserialize(item); } catch(Exception ignored) {}
|
||||||
glowPowerupItem = temp;
|
glowPowerupItem = temp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -264,17 +264,17 @@ public class Config {
|
||||||
placeholderNoData = config.getString("placeholder.noData");
|
placeholderNoData = config.getString("placeholder.noData");
|
||||||
try {
|
try {
|
||||||
countdownDisplay = CountdownDisplay.valueOf(config.getString("hideCountdownDisplay"));
|
countdownDisplay = CountdownDisplay.valueOf(config.getString("hideCountdownDisplay"));
|
||||||
} catch (IllegalArgumentException e){
|
} catch (IllegalArgumentException e) {
|
||||||
countdownDisplay = CountdownDisplay.CHAT;
|
countdownDisplay = CountdownDisplay.CHAT;
|
||||||
Main.plugin.getLogger().warning("hideCountdownDisplay: "+config.getString("hideCountdownDisplay")+" is not a valid configuration option!");
|
Main.plugin.getLogger().warning("hideCountdownDisplay: "+config.getString("hideCountdownDisplay")+" is not a valid configuration option!");
|
||||||
}
|
}
|
||||||
blockedInteracts = new ArrayList<>();
|
blockedInteracts = new ArrayList<>();
|
||||||
List<String> tempInteracts = config.getStringList("blockedInteracts");
|
List<String> tempInteracts = config.getStringList("blockedInteracts");
|
||||||
for(String id : tempInteracts){
|
for(String id : tempInteracts) {
|
||||||
Optional<XMaterial> optional_mat = XMaterial.matchXMaterial(id);
|
Optional<XMaterial> optional_mat = XMaterial.matchXMaterial(id);
|
||||||
if(optional_mat.isPresent()){
|
if (optional_mat.isPresent()) {
|
||||||
Material mat = optional_mat.get().parseMaterial();
|
Material mat = optional_mat.get().parseMaterial();
|
||||||
if(mat != null){
|
if (mat != null) {
|
||||||
blockedInteracts.add(mat.name());
|
blockedInteracts.add(mat.name());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -301,35 +301,35 @@ public class Config {
|
||||||
BORDER_DECREASING = leaderboard.getString("border.decreasing");
|
BORDER_DECREASING = leaderboard.getString("border.decreasing");
|
||||||
|
|
||||||
//Lobby Items
|
//Lobby Items
|
||||||
if(config.getBoolean("lobbyItems.leave.enabled")) {
|
if (config.getBoolean("lobbyItems.leave.enabled")) {
|
||||||
ConfigurationSection item = new YamlConfiguration().createSection("temp");
|
ConfigurationSection item = new YamlConfiguration().createSection("temp");
|
||||||
item.set("name", ChatColor.translateAlternateColorCodes('&',config.getString("lobbyItems.leave.name")));
|
item.set("name", ChatColor.translateAlternateColorCodes('&',config.getString("lobbyItems.leave.name")));
|
||||||
item.set("material", config.getString("lobbyItems.leave.material"));
|
item.set("material", config.getString("lobbyItems.leave.material"));
|
||||||
if(Version.atLeast("1.14")){
|
if (Version.atLeast("1.14")) {
|
||||||
if(config.contains("lobbyItems.leave.model-data") && config.getInt("lobbyItems.leave.model-data") != 0){
|
if (config.contains("lobbyItems.leave.model-data") && config.getInt("lobbyItems.leave.model-data") != 0) {
|
||||||
item.set("model-data", config.getInt("lobbyItems.leave.model-data"));
|
item.set("model-data", config.getInt("lobbyItems.leave.model-data"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
List<String> lore = config.getStringList("lobbyItems.leave.lore");
|
List<String> lore = config.getStringList("lobbyItems.leave.lore");
|
||||||
if (lore != null && !lore.isEmpty()) item.set("lore", lore);
|
if (lore != null && !lore.isEmpty()) item.set("lore", lore);
|
||||||
ItemStack temp = null;
|
ItemStack temp = null;
|
||||||
try{ temp = XItemStack.deserialize(item); } catch(Exception ignored){}
|
try{ temp = XItemStack.deserialize(item); } catch(Exception ignored) {}
|
||||||
lobbyLeaveItem = temp;
|
lobbyLeaveItem = temp;
|
||||||
lobbyItemLeavePosition = config.getInt("lobbyItems.leave.position");
|
lobbyItemLeavePosition = config.getInt("lobbyItems.leave.position");
|
||||||
}
|
}
|
||||||
if(config.getBoolean("lobbyItems.start.enabled")) {
|
if (config.getBoolean("lobbyItems.start.enabled")) {
|
||||||
ConfigurationSection item = new YamlConfiguration().createSection("temp");
|
ConfigurationSection item = new YamlConfiguration().createSection("temp");
|
||||||
item.set("name", ChatColor.translateAlternateColorCodes('&',config.getString("lobbyItems.start.name")));
|
item.set("name", ChatColor.translateAlternateColorCodes('&',config.getString("lobbyItems.start.name")));
|
||||||
item.set("material", config.getString("lobbyItems.start.material"));
|
item.set("material", config.getString("lobbyItems.start.material"));
|
||||||
List<String> lore = config.getStringList("lobbyItems.start.lore");
|
List<String> lore = config.getStringList("lobbyItems.start.lore");
|
||||||
if (lore != null && !lore.isEmpty()) item.set("lore", lore);
|
if (lore != null && !lore.isEmpty()) item.set("lore", lore);
|
||||||
ItemStack temp = null;
|
ItemStack temp = null;
|
||||||
try{ temp = XItemStack.deserialize(item); } catch(Exception ignored){}
|
try{ temp = XItemStack.deserialize(item); } catch(Exception ignored) {}
|
||||||
lobbyStartItem = temp;
|
lobbyStartItem = temp;
|
||||||
lobbyItemStartAdmin = config.getBoolean("lobbyItems.start.adminOnly");
|
lobbyItemStartAdmin = config.getBoolean("lobbyItems.start.adminOnly");
|
||||||
lobbyItemStartPosition = config.getInt("lobbyItems.start.position");
|
lobbyItemStartPosition = config.getInt("lobbyItems.start.position");
|
||||||
if(Version.atLeast("1.14")){
|
if (Version.atLeast("1.14")) {
|
||||||
if(config.contains("lobbyItems.start.model-data") && config.getInt("lobbyItems.start.model-data") != 0){
|
if (config.contains("lobbyItems.start.model-data") && config.getInt("lobbyItems.start.model-data") != 0) {
|
||||||
item.set("model-data", config.getInt("lobbyItems.start.model-data"));
|
item.set("model-data", config.getInt("lobbyItems.start.model-data"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,35 +36,35 @@ public class ConfigManager {
|
||||||
private YamlConfiguration config,defaultConfig;
|
private YamlConfiguration config,defaultConfig;
|
||||||
private String defaultFilename;
|
private String defaultFilename;
|
||||||
|
|
||||||
public static ConfigManager create(String filename){
|
public static ConfigManager create(String filename) {
|
||||||
return new ConfigManager(filename, filename);
|
return new ConfigManager(filename, filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ConfigManager create(String filename, String defaultFilename){
|
public static ConfigManager create(String filename, String defaultFilename) {
|
||||||
return new ConfigManager(filename, defaultFilename);
|
return new ConfigManager(filename, defaultFilename);
|
||||||
}
|
}
|
||||||
|
|
||||||
private ConfigManager(String filename, String defaultFilename){
|
private ConfigManager(String filename, String defaultFilename) {
|
||||||
|
|
||||||
this.defaultFilename = defaultFilename;
|
this.defaultFilename = defaultFilename;
|
||||||
this.file = new File(Main.data, filename);
|
this.file = new File(Main.data, filename);
|
||||||
|
|
||||||
File folder = Main.data;
|
File folder = Main.data;
|
||||||
if(!folder.exists()){
|
if (!folder.exists()) {
|
||||||
if(!folder.mkdirs()){
|
if (!folder.mkdirs()) {
|
||||||
throw new RuntimeException("Failed to make directory: " + file.getPath());
|
throw new RuntimeException("Failed to make directory: " + file.getPath());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!file.exists()){
|
if (!file.exists()) {
|
||||||
try{
|
try{
|
||||||
InputStream input = Main.plugin.getResource(defaultFilename);
|
InputStream input = Main.plugin.getResource(defaultFilename);
|
||||||
if(input == null){
|
if (input == null) {
|
||||||
throw new RuntimeException("Could not create input stream for "+defaultFilename);
|
throw new RuntimeException("Could not create input stream for "+defaultFilename);
|
||||||
}
|
}
|
||||||
java.nio.file.Files.copy(input, file.toPath());
|
java.nio.file.Files.copy(input, file.toPath());
|
||||||
input.close();
|
input.close();
|
||||||
} catch(IOException e){
|
} catch(IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -72,90 +72,90 @@ public class ConfigManager {
|
||||||
FileInputStream fileInputStream;
|
FileInputStream fileInputStream;
|
||||||
try {
|
try {
|
||||||
fileInputStream = new FileInputStream(file);
|
fileInputStream = new FileInputStream(file);
|
||||||
} catch (FileNotFoundException e){
|
} catch (FileNotFoundException e) {
|
||||||
throw new RuntimeException("Could not create input stream for "+file.getPath());
|
throw new RuntimeException("Could not create input stream for "+file.getPath());
|
||||||
}
|
}
|
||||||
InputStreamReader reader = new InputStreamReader(fileInputStream, StandardCharsets.UTF_8);
|
InputStreamReader reader = new InputStreamReader(fileInputStream, StandardCharsets.UTF_8);
|
||||||
this.config = new YamlConfiguration();
|
this.config = new YamlConfiguration();
|
||||||
try {
|
try {
|
||||||
this.config.load(reader);
|
this.config.load(reader);
|
||||||
} catch(InvalidConfigurationException e){
|
} catch(InvalidConfigurationException e) {
|
||||||
throw new RuntimeException("Invalid configuration in config file: "+file.getPath());
|
throw new RuntimeException("Invalid configuration in config file: "+file.getPath());
|
||||||
} catch(IOException e){
|
} catch(IOException e) {
|
||||||
throw new RuntimeException("Could not access file: "+file.getPath());
|
throw new RuntimeException("Could not access file: "+file.getPath());
|
||||||
}
|
}
|
||||||
|
|
||||||
InputStream input = this.getClass().getClassLoader().getResourceAsStream(defaultFilename);
|
InputStream input = this.getClass().getClassLoader().getResourceAsStream(defaultFilename);
|
||||||
if(input == null){
|
if (input == null) {
|
||||||
throw new RuntimeException("Could not create input stream for "+defaultFilename);
|
throw new RuntimeException("Could not create input stream for "+defaultFilename);
|
||||||
}
|
}
|
||||||
InputStreamReader default_reader = new InputStreamReader(input, StandardCharsets.UTF_8);
|
InputStreamReader default_reader = new InputStreamReader(input, StandardCharsets.UTF_8);
|
||||||
this.defaultConfig = new YamlConfiguration();
|
this.defaultConfig = new YamlConfiguration();
|
||||||
try {
|
try {
|
||||||
this.defaultConfig.load(default_reader);
|
this.defaultConfig.load(default_reader);
|
||||||
} catch(InvalidConfigurationException e){
|
} catch(InvalidConfigurationException e) {
|
||||||
throw new RuntimeException("Invalid configuration in config file: "+file.getPath());
|
throw new RuntimeException("Invalid configuration in config file: "+file.getPath());
|
||||||
} catch(IOException e){
|
} catch(IOException e) {
|
||||||
throw new RuntimeException("Could not access file: "+file.getPath());
|
throw new RuntimeException("Could not access file: "+file.getPath());
|
||||||
}
|
}
|
||||||
|
|
||||||
try{
|
try{
|
||||||
fileInputStream.close();
|
fileInputStream.close();
|
||||||
default_reader.close();
|
default_reader.close();
|
||||||
} catch (IOException e){
|
} catch (IOException e) {
|
||||||
throw new RuntimeException("Unable to finalize loading of config files.");
|
throw new RuntimeException("Unable to finalize loading of config files.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean contains(String path){
|
public boolean contains(String path) {
|
||||||
return config.contains(path);
|
return config.contains(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
public double getDouble(String path){
|
public double getDouble(String path) {
|
||||||
double value = config.getDouble(path);
|
double value = config.getDouble(path);
|
||||||
if(value == 0.0D){
|
if (value == 0.0D) {
|
||||||
return defaultConfig.getDouble(path);
|
return defaultConfig.getDouble(path);
|
||||||
} else {
|
} else {
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getInt(String path){
|
public int getInt(String path) {
|
||||||
int value = config.getInt(path);
|
int value = config.getInt(path);
|
||||||
if(value == 0){
|
if (value == 0) {
|
||||||
return defaultConfig.getInt(path);
|
return defaultConfig.getInt(path);
|
||||||
} else {
|
} else {
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getDefaultInt(String path){
|
public int getDefaultInt(String path) {
|
||||||
return defaultConfig.getInt(path);
|
return defaultConfig.getInt(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
public float getFloat(String path){
|
public float getFloat(String path) {
|
||||||
float value = (float) config.getDouble(path);
|
float value = (float) config.getDouble(path);
|
||||||
if(value == 0.0F){
|
if (value == 0.0F) {
|
||||||
return (float) defaultConfig.getDouble(path);
|
return (float) defaultConfig.getDouble(path);
|
||||||
} else {
|
} else {
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getString(String path){
|
public String getString(String path) {
|
||||||
String value = config.getString(path);
|
String value = config.getString(path);
|
||||||
if(value == null){
|
if (value == null) {
|
||||||
return defaultConfig.getString(path);
|
return defaultConfig.getString(path);
|
||||||
} else {
|
} else {
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getString(String path, String oldPath){
|
public String getString(String path, String oldPath) {
|
||||||
String value = config.getString(path);
|
String value = config.getString(path);
|
||||||
if(value == null){
|
if (value == null) {
|
||||||
String oldValue = config.getString(oldPath);
|
String oldValue = config.getString(oldPath);
|
||||||
if(oldValue == null){
|
if (oldValue == null) {
|
||||||
return defaultConfig.getString(path);
|
return defaultConfig.getString(path);
|
||||||
} else {
|
} else {
|
||||||
return oldValue;
|
return oldValue;
|
||||||
|
@ -165,24 +165,24 @@ public class ConfigManager {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<String> getStringList(String path){
|
public List<String> getStringList(String path) {
|
||||||
List<String> value = config.getStringList(path);
|
List<String> value = config.getStringList(path);
|
||||||
if(value == null){
|
if (value == null) {
|
||||||
return defaultConfig.getStringList(path);
|
return defaultConfig.getStringList(path);
|
||||||
} else {
|
} else {
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void reset(String path){
|
public void reset(String path) {
|
||||||
config.set(path, defaultConfig.get(path));
|
config.set(path, defaultConfig.get(path));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void resetFile(String newDefaultFilename){
|
public void resetFile(String newDefaultFilename) {
|
||||||
this.defaultFilename = newDefaultFilename;
|
this.defaultFilename = newDefaultFilename;
|
||||||
|
|
||||||
InputStream input = Main.plugin.getResource(defaultFilename);
|
InputStream input = Main.plugin.getResource(defaultFilename);
|
||||||
if(input == null){
|
if (input == null) {
|
||||||
throw new RuntimeException("Could not create input stream for "+defaultFilename);
|
throw new RuntimeException("Could not create input stream for "+defaultFilename);
|
||||||
}
|
}
|
||||||
InputStreamReader reader = new InputStreamReader(input);
|
InputStreamReader reader = new InputStreamReader(input);
|
||||||
|
@ -191,63 +191,63 @@ public class ConfigManager {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean getBoolean(String path){
|
public boolean getBoolean(String path) {
|
||||||
if(!config.contains(path)){
|
if (!config.contains(path)) {
|
||||||
return defaultConfig.getBoolean(path);
|
return defaultConfig.getBoolean(path);
|
||||||
} else {
|
} else {
|
||||||
return config.getBoolean(path);
|
return config.getBoolean(path);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public ConfigurationSection getConfigurationSection(String path){
|
public ConfigurationSection getConfigurationSection(String path) {
|
||||||
ConfigurationSection section = config.getConfigurationSection(path);
|
ConfigurationSection section = config.getConfigurationSection(path);
|
||||||
if(section == null){
|
if (section == null) {
|
||||||
return defaultConfig.getConfigurationSection(path);
|
return defaultConfig.getConfigurationSection(path);
|
||||||
} else {
|
} else {
|
||||||
return section;
|
return section;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void set(String path, Object value){
|
public void set(String path, Object value) {
|
||||||
config.set(path, value);
|
config.set(path, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void saveConfig(){
|
public void saveConfig() {
|
||||||
try {
|
try {
|
||||||
InputStream is = Main.plugin.getResource(defaultFilename);
|
InputStream is = Main.plugin.getResource(defaultFilename);
|
||||||
if(is == null){
|
if (is == null) {
|
||||||
throw new RuntimeException("Could not create input stream for "+defaultFilename);
|
throw new RuntimeException("Could not create input stream for "+defaultFilename);
|
||||||
}
|
}
|
||||||
StringBuilder textBuilder = new StringBuilder(new String("".getBytes(), StandardCharsets.UTF_8));
|
StringBuilder textBuilder = new StringBuilder(new String("".getBytes(), StandardCharsets.UTF_8));
|
||||||
Reader reader = new BufferedReader(new InputStreamReader(is, Charset.forName(StandardCharsets.UTF_8.name())));
|
Reader reader = new BufferedReader(new InputStreamReader(is, Charset.forName(StandardCharsets.UTF_8.name())));
|
||||||
int c;
|
int c;
|
||||||
while((c = reader.read()) != -1){
|
while((c = reader.read()) != -1) {
|
||||||
textBuilder.append((char) c);
|
textBuilder.append((char) c);
|
||||||
}
|
}
|
||||||
String yamlString = new String(textBuilder.toString().getBytes(), StandardCharsets.UTF_8);
|
String yamlString = new String(textBuilder.toString().getBytes(), StandardCharsets.UTF_8);
|
||||||
Map<String, Object> temp = config.getValues(true);
|
Map<String, Object> temp = config.getValues(true);
|
||||||
for(Map.Entry<String, Object> entry: temp.entrySet()){
|
for(Map.Entry<String, Object> entry: temp.entrySet()) {
|
||||||
if(entry.getValue() instanceof Integer || entry.getValue() instanceof Double || entry.getValue() instanceof String || entry.getValue() instanceof Boolean || entry.getValue() instanceof List){
|
if (entry.getValue() instanceof Integer || entry.getValue() instanceof Double || entry.getValue() instanceof String || entry.getValue() instanceof Boolean || entry.getValue() instanceof List) {
|
||||||
String[] parts = entry.getKey().split("\\.");
|
String[] parts = entry.getKey().split("\\.");
|
||||||
int index = 0;
|
int index = 0;
|
||||||
int i = 0;
|
int i = 0;
|
||||||
for(String part : parts) {
|
for(String part : parts) {
|
||||||
if(i == 0) {
|
if (i == 0) {
|
||||||
index = yamlString.indexOf(part+":", index);
|
index = yamlString.indexOf(part+":", index);
|
||||||
} else {
|
} else {
|
||||||
index = yamlString.indexOf(" " + part+":", index);
|
index = yamlString.indexOf(" " + part+":", index);
|
||||||
index++;
|
index++;
|
||||||
}
|
}
|
||||||
i++;
|
i++;
|
||||||
if(index == -1) break;
|
if (index == -1) break;
|
||||||
}
|
}
|
||||||
if(index < 10) continue;
|
if (index < 10) continue;
|
||||||
int start = yamlString.indexOf(' ', index);
|
int start = yamlString.indexOf(' ', index);
|
||||||
int end = yamlString.indexOf('\n', index);
|
int end = yamlString.indexOf('\n', index);
|
||||||
if(end == -1) end = yamlString.length();
|
if (end == -1) end = yamlString.length();
|
||||||
StringBuilder replace = new StringBuilder(new String("".getBytes(), StandardCharsets.UTF_8));
|
StringBuilder replace = new StringBuilder(new String("".getBytes(), StandardCharsets.UTF_8));
|
||||||
if(entry.getValue() instanceof List){
|
if (entry.getValue() instanceof List) {
|
||||||
if(((List<?>) entry.getValue()).isEmpty()){
|
if (((List<?>) entry.getValue()).isEmpty()) {
|
||||||
replace.append("[]");
|
replace.append("[]");
|
||||||
} else {
|
} else {
|
||||||
replace.append("[");
|
replace.append("[");
|
||||||
|
@ -260,7 +260,7 @@ public class ConfigManager {
|
||||||
} else {
|
} else {
|
||||||
replace.append(entry.getValue());
|
replace.append(entry.getValue());
|
||||||
}
|
}
|
||||||
if(entry.getValue() instanceof String){
|
if (entry.getValue() instanceof String) {
|
||||||
replace.append("\"");
|
replace.append("\"");
|
||||||
replace.reverse();
|
replace.reverse();
|
||||||
replace.append("\"");
|
replace.append("\"");
|
||||||
|
@ -274,7 +274,7 @@ public class ConfigManager {
|
||||||
Writer fileWriter = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file), StandardCharsets.UTF_8));
|
Writer fileWriter = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file), StandardCharsets.UTF_8));
|
||||||
fileWriter.write(yamlString);
|
fileWriter.write(yamlString);
|
||||||
fileWriter.close();
|
fileWriter.close();
|
||||||
} catch (IOException e){
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,7 +25,8 @@ import org.bukkit.Material;
|
||||||
import org.bukkit.configuration.ConfigurationSection;
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
import org.bukkit.configuration.file.YamlConfiguration;
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.bukkit.potion.*;
|
import org.bukkit.potion.PotionEffect;
|
||||||
|
import org.bukkit.potion.PotionEffectType;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -45,9 +46,9 @@ public class Items {
|
||||||
int i = 1;
|
int i = 1;
|
||||||
while (true) {
|
while (true) {
|
||||||
ConfigurationSection section = SeekerItems.getConfigurationSection(String.valueOf(i));
|
ConfigurationSection section = SeekerItems.getConfigurationSection(String.valueOf(i));
|
||||||
if(section == null) break;
|
if (section == null) break;
|
||||||
ItemStack item = createItem(section);
|
ItemStack item = createItem(section);
|
||||||
if(item != null) SEEKER_ITEMS.add(item);
|
if (item != null) SEEKER_ITEMS.add(item);
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -56,9 +57,9 @@ public class Items {
|
||||||
i = 1;
|
i = 1;
|
||||||
while (true) {
|
while (true) {
|
||||||
ConfigurationSection section = HiderItems.getConfigurationSection(String.valueOf(i));
|
ConfigurationSection section = HiderItems.getConfigurationSection(String.valueOf(i));
|
||||||
if(section == null) break;
|
if (section == null) break;
|
||||||
ItemStack item = createItem(section);
|
ItemStack item = createItem(section);
|
||||||
if(item != null) HIDER_ITEMS.add(item);
|
if (item != null) HIDER_ITEMS.add(item);
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
SEEKER_EFFECTS = new ArrayList<>();
|
SEEKER_EFFECTS = new ArrayList<>();
|
||||||
|
@ -66,9 +67,9 @@ public class Items {
|
||||||
i = 1;
|
i = 1;
|
||||||
while (true) {
|
while (true) {
|
||||||
ConfigurationSection section = SeekerEffects.getConfigurationSection(String.valueOf(i));
|
ConfigurationSection section = SeekerEffects.getConfigurationSection(String.valueOf(i));
|
||||||
if(section == null) break;
|
if (section == null) break;
|
||||||
PotionEffect effect = getPotionEffect(section);
|
PotionEffect effect = getPotionEffect(section);
|
||||||
if(effect != null) SEEKER_EFFECTS.add(effect);
|
if (effect != null) SEEKER_EFFECTS.add(effect);
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -77,9 +78,9 @@ public class Items {
|
||||||
i = 1;
|
i = 1;
|
||||||
while (true) {
|
while (true) {
|
||||||
ConfigurationSection section = HiderEffects.getConfigurationSection(String.valueOf(i));
|
ConfigurationSection section = HiderEffects.getConfigurationSection(String.valueOf(i));
|
||||||
if(section == null) break;
|
if (section == null) break;
|
||||||
PotionEffect effect = getPotionEffect(section);
|
PotionEffect effect = getPotionEffect(section);
|
||||||
if(effect != null) HIDER_EFFECTS.add(effect);
|
if (effect != null) HIDER_EFFECTS.add(effect);
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -89,11 +90,11 @@ public class Items {
|
||||||
ConfigurationSection config = new YamlConfiguration().createSection("temp");
|
ConfigurationSection config = new YamlConfiguration().createSection("temp");
|
||||||
String material = item.getString("material").toUpperCase();
|
String material = item.getString("material").toUpperCase();
|
||||||
boolean splash = false;
|
boolean splash = false;
|
||||||
if(!Version.atLeast("1.9")){
|
if (!Version.atLeast("1.9")) {
|
||||||
if(material.contains("POTION")){
|
if (material.contains("POTION")) {
|
||||||
config.set("level", 1);
|
config.set("level", 1);
|
||||||
}
|
}
|
||||||
if(material.equalsIgnoreCase("SPLASH_POTION") || material.equalsIgnoreCase("LINGERING_POTION")){
|
if (material.equalsIgnoreCase("SPLASH_POTION") || material.equalsIgnoreCase("LINGERING_POTION")) {
|
||||||
material = "POTION";
|
material = "POTION";
|
||||||
splash = true;
|
splash = true;
|
||||||
}
|
}
|
||||||
|
@ -102,25 +103,25 @@ public class Items {
|
||||||
config.set("material", material);
|
config.set("material", material);
|
||||||
config.set("enchants", item.getConfigurationSection("enchantments"));
|
config.set("enchants", item.getConfigurationSection("enchantments"));
|
||||||
config.set("unbreakable", item.getBoolean("unbreakable"));
|
config.set("unbreakable", item.getBoolean("unbreakable"));
|
||||||
if(Version.atLeast("1.14")){
|
if (Version.atLeast("1.14")) {
|
||||||
if(item.contains("model-data")){
|
if (item.contains("model-data")) {
|
||||||
config.set("model-data", item.getInt("model-data"));
|
config.set("model-data", item.getInt("model-data"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(item.isSet("lore"))
|
if (item.isSet("lore"))
|
||||||
config.set("lore", item.getStringList("lore"));
|
config.set("lore", item.getStringList("lore"));
|
||||||
if (material.equalsIgnoreCase("POTION") || material.equalsIgnoreCase("SPLASH_POTION") || material.equalsIgnoreCase("LINGERING_POTION"))
|
if (material.equalsIgnoreCase("POTION") || material.equalsIgnoreCase("SPLASH_POTION") || material.equalsIgnoreCase("LINGERING_POTION"))
|
||||||
config.set("base-effect", String.format("%s,%s,%s", item.getString("type"), false, splash));
|
config.set("base-effect", String.format("%s,%s,%s", item.getString("type"), false, splash));
|
||||||
ItemStack stack = XItemStack.deserialize(config);
|
ItemStack stack = XItemStack.deserialize(config);
|
||||||
stack.setAmount(item.getInt("amount"));
|
stack.setAmount(item.getInt("amount"));
|
||||||
if(stack.getData().getItemType() == Material.AIR) return null;
|
if (stack.getData().getItemType() == Material.AIR) return null;
|
||||||
return stack;
|
return stack;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static PotionEffect getPotionEffect(ConfigurationSection item){
|
private static PotionEffect getPotionEffect(ConfigurationSection item) {
|
||||||
String type = item.getString("type");
|
String type = item.getString("type");
|
||||||
if(type == null) return null;
|
if (type == null) return null;
|
||||||
if(PotionEffectType.getByName(type.toUpperCase()) == null) return null;
|
if (PotionEffectType.getByName(type.toUpperCase()) == null) return null;
|
||||||
return new PotionEffect(
|
return new PotionEffect(
|
||||||
Objects.requireNonNull(PotionEffectType.getByName(type.toUpperCase())),
|
Objects.requireNonNull(PotionEffectType.getByName(type.toUpperCase())),
|
||||||
item.getInt("duration"),
|
item.getInt("duration"),
|
||||||
|
|
|
@ -19,12 +19,12 @@
|
||||||
|
|
||||||
package net.tylermurphy.hideAndSeek.configuration;
|
package net.tylermurphy.hideAndSeek.configuration;
|
||||||
|
|
||||||
|
import net.md_5.bungee.api.ChatColor;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import net.md_5.bungee.api.ChatColor;
|
|
||||||
|
|
||||||
public class Localization {
|
public class Localization {
|
||||||
|
|
||||||
public static final Map<String,LocalizationString> LOCAL = new HashMap<>();
|
public static final Map<String,LocalizationString> LOCAL = new HashMap<>();
|
||||||
|
@ -40,9 +40,9 @@ public class Localization {
|
||||||
|
|
||||||
int PLUGIN_VERSION = manager.getDefaultInt("version");
|
int PLUGIN_VERSION = manager.getDefaultInt("version");
|
||||||
int VERSION = manager.getInt("version");
|
int VERSION = manager.getInt("version");
|
||||||
if(VERSION < PLUGIN_VERSION){
|
if (VERSION < PLUGIN_VERSION) {
|
||||||
for(int i = VERSION; i < PLUGIN_VERSION; i++){
|
for(int i = VERSION; i < PLUGIN_VERSION; i++) {
|
||||||
if(i < 1) continue;
|
if (i < 1) continue;
|
||||||
String[] changeList = CHANGES.get(Config.locale)[i-1];
|
String[] changeList = CHANGES.get(Config.locale)[i-1];
|
||||||
for(String change : changeList)
|
for(String change : changeList)
|
||||||
manager.reset("Localization." + change);
|
manager.reset("Localization." + change);
|
||||||
|
@ -51,9 +51,9 @@ public class Localization {
|
||||||
}
|
}
|
||||||
|
|
||||||
String SELECTED_LOCAL = manager.getString("type");
|
String SELECTED_LOCAL = manager.getString("type");
|
||||||
if(SELECTED_LOCAL == null){
|
if (SELECTED_LOCAL == null) {
|
||||||
manager.reset("type");
|
manager.reset("type");
|
||||||
} else if(!SELECTED_LOCAL.equals(Config.locale)){
|
} else if (!SELECTED_LOCAL.equals(Config.locale)) {
|
||||||
manager.resetFile("lang"+File.separator+"localization_"+Config.locale +".yml");
|
manager.resetFile("lang"+File.separator+"localization_"+Config.locale +".yml");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -69,7 +69,7 @@ public class Localization {
|
||||||
|
|
||||||
public static LocalizationString message(String key) {
|
public static LocalizationString message(String key) {
|
||||||
LocalizationString temp = LOCAL.get(key);
|
LocalizationString temp = LOCAL.get(key);
|
||||||
if(temp == null) {
|
if (temp == null) {
|
||||||
return new LocalizationString(ChatColor.RED + "" + ChatColor.ITALIC + key + " is not found in localization.yml. This is a plugin issue, please report it.");
|
return new LocalizationString(ChatColor.RED + "" + ChatColor.ITALIC + key + " is not found in localization.yml. This is a plugin issue, please report it.");
|
||||||
}
|
}
|
||||||
return new LocalizationString(temp.toString());
|
return new LocalizationString(temp.toString());
|
||||||
|
|
|
@ -22,9 +22,7 @@ package net.tylermurphy.hideAndSeek.database;
|
||||||
import com.google.common.io.ByteStreams;
|
import com.google.common.io.ByteStreams;
|
||||||
import net.tylermurphy.hideAndSeek.Main;
|
import net.tylermurphy.hideAndSeek.Main;
|
||||||
import org.sqlite.SQLiteConfig;
|
import org.sqlite.SQLiteConfig;
|
||||||
import sun.font.ScriptRun;
|
|
||||||
|
|
||||||
import java.io.ByteArrayInputStream;
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
@ -32,8 +30,6 @@ import java.nio.ByteBuffer;
|
||||||
import java.sql.Connection;
|
import java.sql.Connection;
|
||||||
import java.sql.DriverManager;
|
import java.sql.DriverManager;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
|
|
||||||
import java.sql.Statement;
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
public class Database {
|
public class Database {
|
||||||
|
@ -65,7 +61,7 @@ public class Database {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void init(){
|
public static void init() {
|
||||||
try {
|
try {
|
||||||
Class.forName("org.sqlite.JDBC");
|
Class.forName("org.sqlite.JDBC");
|
||||||
} catch (ClassNotFoundException e) {
|
} catch (ClassNotFoundException e) {
|
||||||
|
|
|
@ -23,8 +23,15 @@ import java.util.UUID;
|
||||||
|
|
||||||
public class PlayerInfo {
|
public class PlayerInfo {
|
||||||
|
|
||||||
public UUID uuid;
|
public final UUID uuid;
|
||||||
public int hider_wins, seeker_wins, hider_games, seeker_games, hider_kills, seeker_kills, hider_deaths, seeker_deaths;
|
public final int hider_wins;
|
||||||
|
public final int seeker_wins;
|
||||||
|
public final int hider_games;
|
||||||
|
public final int seeker_games;
|
||||||
|
public final int hider_kills;
|
||||||
|
public final int seeker_kills;
|
||||||
|
public final int hider_deaths;
|
||||||
|
public final int seeker_deaths;
|
||||||
|
|
||||||
public PlayerInfo(UUID uuid, int hider_wins, int seeker_wins, int hider_games, int seeker_games, int hider_kills, int seeker_kills, int hider_deaths, int seeker_deaths) {
|
public PlayerInfo(UUID uuid, int hider_wins, int seeker_wins, int hider_games, int seeker_games, int hider_kills, int seeker_kills, int hider_deaths, int seeker_deaths) {
|
||||||
this.uuid = uuid;
|
this.uuid = uuid;
|
||||||
|
|
|
@ -21,7 +21,6 @@ package net.tylermurphy.hideAndSeek.database;
|
||||||
|
|
||||||
import com.google.common.io.ByteStreams;
|
import com.google.common.io.ByteStreams;
|
||||||
import net.tylermurphy.hideAndSeek.Main;
|
import net.tylermurphy.hideAndSeek.Main;
|
||||||
import net.tylermurphy.hideAndSeek.configuration.Config;
|
|
||||||
import net.tylermurphy.hideAndSeek.game.Board;
|
import net.tylermurphy.hideAndSeek.game.Board;
|
||||||
import net.tylermurphy.hideAndSeek.util.WinType;
|
import net.tylermurphy.hideAndSeek.util.WinType;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
@ -38,7 +37,7 @@ public class PlayerInfoTable {
|
||||||
|
|
||||||
private static final Map<UUID, PlayerInfo> CACHE = new HashMap<>();
|
private static final Map<UUID, PlayerInfo> CACHE = new HashMap<>();
|
||||||
|
|
||||||
protected PlayerInfoTable(){
|
protected PlayerInfoTable() {
|
||||||
|
|
||||||
String sql = "CREATE TABLE IF NOT EXISTS hs_data (\n"
|
String sql = "CREATE TABLE IF NOT EXISTS hs_data (\n"
|
||||||
+ " uuid BINARY(16) PRIMARY KEY,\n"
|
+ " uuid BINARY(16) PRIMARY KEY,\n"
|
||||||
|
@ -52,15 +51,15 @@ public class PlayerInfoTable {
|
||||||
+ " seeker_deaths int NOT NULL\n"
|
+ " seeker_deaths int NOT NULL\n"
|
||||||
+ ");";
|
+ ");";
|
||||||
|
|
||||||
try(Connection connection = Database.connect(); Statement statement = connection.createStatement()){
|
try(Connection connection = Database.connect(); Statement statement = connection.createStatement()) {
|
||||||
statement.executeUpdate(sql);
|
statement.executeUpdate(sql);
|
||||||
} catch (SQLException e){
|
} catch (SQLException e) {
|
||||||
Main.plugin.getLogger().severe("SQL Error: " + e.getMessage());
|
Main.plugin.getLogger().severe("SQL Error: " + e.getMessage());
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private byte[] encodeUUID(UUID uuid){
|
private byte[] encodeUUID(UUID uuid) {
|
||||||
try {
|
try {
|
||||||
byte[] bytes = new byte[16];
|
byte[] bytes = new byte[16];
|
||||||
ByteBuffer.wrap(bytes)
|
ByteBuffer.wrap(bytes)
|
||||||
|
@ -73,13 +72,13 @@ public class PlayerInfoTable {
|
||||||
return new byte[0];
|
return new byte[0];
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
} catch (IOException e){
|
} catch (IOException e) {
|
||||||
Main.plugin.getLogger().severe("IO Error: " + e.getMessage());
|
Main.plugin.getLogger().severe("IO Error: " + e.getMessage());
|
||||||
return new byte[0];
|
return new byte[0];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private UUID decodeUUID(byte[] bytes){
|
private UUID decodeUUID(byte[] bytes) {
|
||||||
InputStream is = new ByteArrayInputStream(bytes);
|
InputStream is = new ByteArrayInputStream(bytes);
|
||||||
ByteBuffer buffer = ByteBuffer.allocate(16);
|
ByteBuffer buffer = ByteBuffer.allocate(16);
|
||||||
try {
|
try {
|
||||||
|
@ -93,12 +92,12 @@ public class PlayerInfoTable {
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public PlayerInfo getInfo(UUID uuid){
|
public PlayerInfo getInfo(UUID uuid) {
|
||||||
String sql = "SELECT * FROM hs_data WHERE uuid = ?;";
|
String sql = "SELECT * FROM hs_data WHERE uuid = ?;";
|
||||||
try(Connection connection = Database.connect(); PreparedStatement statement = connection.prepareStatement(sql)){
|
try(Connection connection = Database.connect(); PreparedStatement statement = connection.prepareStatement(sql)) {
|
||||||
statement.setBytes(1, encodeUUID(uuid));
|
statement.setBytes(1, encodeUUID(uuid));
|
||||||
ResultSet rs = statement.executeQuery();
|
ResultSet rs = statement.executeQuery();
|
||||||
if(rs.next()){
|
if (rs.next()) {
|
||||||
PlayerInfo info = new PlayerInfo(
|
PlayerInfo info = new PlayerInfo(
|
||||||
uuid,
|
uuid,
|
||||||
rs.getInt("hider_wins"),
|
rs.getInt("hider_wins"),
|
||||||
|
@ -116,7 +115,7 @@ public class PlayerInfoTable {
|
||||||
return info;
|
return info;
|
||||||
}
|
}
|
||||||
rs.close();
|
rs.close();
|
||||||
} catch (SQLException e){
|
} catch (SQLException e) {
|
||||||
Main.plugin.getLogger().severe("SQL Error: " + e.getMessage());
|
Main.plugin.getLogger().severe("SQL Error: " + e.getMessage());
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
@ -124,12 +123,12 @@ public class PlayerInfoTable {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public PlayerInfo getInfoRanking(String order, int place){
|
public PlayerInfo getInfoRanking(String order, int place) {
|
||||||
String sql = "SELECT * FROM hs_data ORDER BY "+order+" DESC LIMIT 1 OFFSET ?;";
|
String sql = "SELECT * FROM hs_data ORDER BY "+order+" DESC LIMIT 1 OFFSET ?;";
|
||||||
try(Connection connection = Database.connect(); PreparedStatement statement = connection.prepareStatement(sql)){
|
try(Connection connection = Database.connect(); PreparedStatement statement = connection.prepareStatement(sql)) {
|
||||||
statement.setInt(1, place-1);
|
statement.setInt(1, place-1);
|
||||||
ResultSet rs = statement.executeQuery();
|
ResultSet rs = statement.executeQuery();
|
||||||
if(rs.next()){
|
if (rs.next()) {
|
||||||
UUID uuid = decodeUUID(rs.getBytes("uuid"));
|
UUID uuid = decodeUUID(rs.getBytes("uuid"));
|
||||||
PlayerInfo info = new PlayerInfo(
|
PlayerInfo info = new PlayerInfo(
|
||||||
uuid,
|
uuid,
|
||||||
|
@ -148,7 +147,7 @@ public class PlayerInfoTable {
|
||||||
return info;
|
return info;
|
||||||
}
|
}
|
||||||
rs.close();
|
rs.close();
|
||||||
} catch (SQLException e){
|
} catch (SQLException e) {
|
||||||
Main.plugin.getLogger().severe("SQL Error: " + e.getMessage());
|
Main.plugin.getLogger().severe("SQL Error: " + e.getMessage());
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
@ -156,13 +155,13 @@ public class PlayerInfoTable {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public List<PlayerInfo> getInfoPage(int page){
|
public List<PlayerInfo> getInfoPage(int page) {
|
||||||
String sql = "SELECT * FROM hs_data ORDER BY (hider_wins + seeker_wins) DESC LIMIT 10 OFFSET ?;";
|
String sql = "SELECT * FROM hs_data ORDER BY (hider_wins + seeker_wins) DESC LIMIT 10 OFFSET ?;";
|
||||||
try(Connection connection = Database.connect(); PreparedStatement statement = connection.prepareStatement(sql)){
|
try(Connection connection = Database.connect(); PreparedStatement statement = connection.prepareStatement(sql)) {
|
||||||
statement.setInt(1, (page-1)*10);
|
statement.setInt(1, (page-1)*10);
|
||||||
ResultSet rs = statement.executeQuery();
|
ResultSet rs = statement.executeQuery();
|
||||||
List<PlayerInfo> infoList = new ArrayList<>();
|
List<PlayerInfo> infoList = new ArrayList<>();
|
||||||
while(rs.next()){
|
while(rs.next()) {
|
||||||
PlayerInfo info = new PlayerInfo(
|
PlayerInfo info = new PlayerInfo(
|
||||||
decodeUUID(rs.getBytes("uuid")),
|
decodeUUID(rs.getBytes("uuid")),
|
||||||
rs.getInt("hider_wins"),
|
rs.getInt("hider_wins"),
|
||||||
|
@ -179,7 +178,7 @@ public class PlayerInfoTable {
|
||||||
rs.close();
|
rs.close();
|
||||||
connection.close();
|
connection.close();
|
||||||
return infoList;
|
return infoList;
|
||||||
} catch (SQLException e){
|
} catch (SQLException e) {
|
||||||
Main.plugin.getLogger().severe("SQL Error: " + e.getMessage());
|
Main.plugin.getLogger().severe("SQL Error: " + e.getMessage());
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
@ -187,27 +186,27 @@ public class PlayerInfoTable {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public Integer getRanking(String order, UUID uuid){
|
public Integer getRanking(String order, UUID uuid) {
|
||||||
String sql = "SELECT count(*) AS total FROM hs_data WHERE "+order+" >= (SELECT "+order+" FROM hs_data WHERE uuid = ?) AND "+order+" > 0;";
|
String sql = "SELECT count(*) AS total FROM hs_data WHERE "+order+" >= (SELECT "+order+" FROM hs_data WHERE uuid = ?) AND "+order+" > 0;";
|
||||||
try(Connection connection = Database.connect(); PreparedStatement statement = connection.prepareStatement(sql)){
|
try(Connection connection = Database.connect(); PreparedStatement statement = connection.prepareStatement(sql)) {
|
||||||
statement.setBytes(1, encodeUUID(uuid));
|
statement.setBytes(1, encodeUUID(uuid));
|
||||||
ResultSet rs = statement.executeQuery();
|
ResultSet rs = statement.executeQuery();
|
||||||
if(rs.next()){
|
if (rs.next()) {
|
||||||
return rs.getInt("total");
|
return rs.getInt("total");
|
||||||
}
|
}
|
||||||
rs.close();
|
rs.close();
|
||||||
} catch (SQLException e){
|
} catch (SQLException e) {
|
||||||
Main.plugin.getLogger().severe("SQL Error: " + e.getMessage());
|
Main.plugin.getLogger().severe("SQL Error: " + e.getMessage());
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addWins(List<UUID> uuids, List<UUID> winners, Map<String,Integer> hider_kills, Map<String,Integer> hider_deaths, Map<String,Integer> seeker_kills, Map<String,Integer> seeker_deaths, WinType type){
|
public void addWins(List<UUID> uuids, List<UUID> winners, Map<String,Integer> hider_kills, Map<String,Integer> hider_deaths, Map<String,Integer> seeker_kills, Map<String,Integer> seeker_deaths, WinType type) {
|
||||||
for(UUID uuid : uuids){
|
for(UUID uuid : uuids) {
|
||||||
String sql = "INSERT OR REPLACE INTO hs_data (uuid, hider_wins, seeker_wins, hider_games, seeker_games, hider_kills, seeker_kills, hider_deaths, seeker_deaths) VALUES (?,?,?,?,?,?,?,?,?)";
|
String sql = "INSERT OR REPLACE INTO hs_data (uuid, hider_wins, seeker_wins, hider_games, seeker_games, hider_kills, seeker_kills, hider_deaths, seeker_deaths) VALUES (?,?,?,?,?,?,?,?,?)";
|
||||||
PlayerInfo info = getInfo(uuid);
|
PlayerInfo info = getInfo(uuid);
|
||||||
try(Connection connection = Database.connect(); PreparedStatement statement = connection.prepareStatement(sql)){
|
try(Connection connection = Database.connect(); PreparedStatement statement = connection.prepareStatement(sql)) {
|
||||||
statement.setBytes(1, encodeUUID(uuid));
|
statement.setBytes(1, encodeUUID(uuid));
|
||||||
statement.setInt(2, info.hider_wins + (winners.contains(uuid) && type == WinType.HIDER_WIN ? 1 : 0));
|
statement.setInt(2, info.hider_wins + (winners.contains(uuid) && type == WinType.HIDER_WIN ? 1 : 0));
|
||||||
statement.setInt(3, info.seeker_wins + (winners.contains(uuid) && type == WinType.SEEKER_WIN ? 1 : 0));
|
statement.setInt(3, info.seeker_wins + (winners.contains(uuid) && type == WinType.SEEKER_WIN ? 1 : 0));
|
||||||
|
@ -218,7 +217,7 @@ public class PlayerInfoTable {
|
||||||
statement.setInt(8, info.hider_deaths + hider_deaths.getOrDefault(uuid.toString(), 0));
|
statement.setInt(8, info.hider_deaths + hider_deaths.getOrDefault(uuid.toString(), 0));
|
||||||
statement.setInt(9, info.seeker_deaths + seeker_deaths.getOrDefault(uuid.toString(), 0));
|
statement.setInt(9, info.seeker_deaths + seeker_deaths.getOrDefault(uuid.toString(), 0));
|
||||||
statement.execute();
|
statement.execute();
|
||||||
} catch (SQLException e){
|
} catch (SQLException e) {
|
||||||
Main.plugin.getLogger().severe("SQL Error: " + e.getMessage());
|
Main.plugin.getLogger().severe("SQL Error: " + e.getMessage());
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -19,12 +19,6 @@
|
||||||
|
|
||||||
package net.tylermurphy.hideAndSeek.game;
|
package net.tylermurphy.hideAndSeek.game;
|
||||||
|
|
||||||
import static net.tylermurphy.hideAndSeek.configuration.Config.*;
|
|
||||||
import static net.tylermurphy.hideAndSeek.configuration.Localization.message;
|
|
||||||
|
|
||||||
import java.util.*;
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
import net.tylermurphy.hideAndSeek.util.Status;
|
import net.tylermurphy.hideAndSeek.util.Status;
|
||||||
import net.tylermurphy.hideAndSeek.util.Version;
|
import net.tylermurphy.hideAndSeek.util.Version;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
|
@ -33,6 +27,12 @@ import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.scoreboard.*;
|
import org.bukkit.scoreboard.*;
|
||||||
|
|
||||||
|
import java.util.*;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
import static net.tylermurphy.hideAndSeek.configuration.Config.*;
|
||||||
|
import static net.tylermurphy.hideAndSeek.configuration.Localization.message;
|
||||||
|
|
||||||
public class Board {
|
public class Board {
|
||||||
|
|
||||||
private static final List<String> Hider = new ArrayList<>(), Seeker = new ArrayList<>(), Spectator = new ArrayList<>();
|
private static final List<String> Hider = new ArrayList<>(), Seeker = new ArrayList<>(), Spectator = new ArrayList<>();
|
||||||
|
@ -40,19 +40,19 @@ public class Board {
|
||||||
private static final Map<String, CustomBoard> customBoards = new HashMap<>();
|
private static final Map<String, CustomBoard> customBoards = new HashMap<>();
|
||||||
private static final Map<String, Integer> hider_kills = new HashMap<>(), seeker_kills = new HashMap<>(), hider_deaths = new HashMap<>(), seeker_deaths = new HashMap<>();
|
private static final Map<String, Integer> hider_kills = new HashMap<>(), seeker_kills = new HashMap<>(), hider_deaths = new HashMap<>(), seeker_deaths = new HashMap<>();
|
||||||
|
|
||||||
public static boolean isPlayer(Player player) {
|
public static boolean contains(Player player) {
|
||||||
return playerList.containsKey(player.getUniqueId().toString());
|
return playerList.containsKey(player.getUniqueId().toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isPlayer(CommandSender sender) {
|
public static boolean contains(CommandSender sender) {
|
||||||
return playerList.containsKey(Bukkit.getPlayer(sender.getName()).getUniqueId().toString());
|
return contains((Player) sender);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isHider(Player player) {
|
public static boolean isHider(Player player) {
|
||||||
return Hider.contains(player.getUniqueId().toString());
|
return Hider.contains(player.getUniqueId().toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isHider(UUID uuid){
|
public static boolean isHider(UUID uuid) {
|
||||||
return Hider.contains(uuid.toString());
|
return Hider.contains(uuid.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -60,7 +60,7 @@ public class Board {
|
||||||
return Seeker.contains(player.getUniqueId().toString());
|
return Seeker.contains(player.getUniqueId().toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isSeeker(UUID uuid){
|
public static boolean isSeeker(UUID uuid) {
|
||||||
return Seeker.contains(uuid.toString());
|
return Seeker.contains(uuid.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -80,23 +80,23 @@ public class Board {
|
||||||
return playerList.values().size();
|
return playerList.values().size();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<Player> getHiders(){
|
public static List<Player> getHiders() {
|
||||||
return Hider.stream().map(playerList::get).collect(Collectors.toList());
|
return Hider.stream().map(playerList::get).collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<Player> getSeekers(){
|
public static List<Player> getSeekers() {
|
||||||
return Seeker.stream().map(playerList::get).collect(Collectors.toList());
|
return Seeker.stream().map(playerList::get).collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Player getFirstSeeker(){
|
public static Player getFirstSeeker() {
|
||||||
return playerList.get(Seeker.get(0));
|
return playerList.get(Seeker.get(0));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<Player> getSpectators(){
|
public static List<Player> getSpectators() {
|
||||||
return Spectator.stream().map(playerList::get).collect(Collectors.toList());
|
return Spectator.stream().map(playerList::get).collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<Player> getPlayers(){
|
public static List<Player> getPlayers() {
|
||||||
return new ArrayList<>(playerList.values());
|
return new ArrayList<>(playerList.values());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -133,8 +133,8 @@ public class Board {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean onSameTeam(Player player1, Player player2) {
|
public static boolean onSameTeam(Player player1, Player player2) {
|
||||||
if(Hider.contains(player1.getUniqueId().toString()) && Hider.contains(player2.getUniqueId().toString())) return true;
|
if (Hider.contains(player1.getUniqueId().toString()) && Hider.contains(player2.getUniqueId().toString())) return true;
|
||||||
else if(Seeker.contains(player1.getUniqueId().toString()) && Seeker.contains(player2.getUniqueId().toString())) return true;
|
else if (Seeker.contains(player1.getUniqueId().toString()) && Seeker.contains(player2.getUniqueId().toString())) return true;
|
||||||
else return Spectator.contains(player1.getUniqueId().toString()) && Spectator.contains(player2.getUniqueId().toString());
|
else return Spectator.contains(player1.getUniqueId().toString()) && Spectator.contains(player2.getUniqueId().toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -148,15 +148,15 @@ public class Board {
|
||||||
seeker_deaths.clear();
|
seeker_deaths.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void addKill(UUID uuid){
|
public static void addKill(UUID uuid) {
|
||||||
if(Hider.contains(uuid.toString())){
|
if (Hider.contains(uuid.toString())) {
|
||||||
if(hider_kills.containsKey(uuid.toString())){
|
if (hider_kills.containsKey(uuid.toString())) {
|
||||||
hider_kills.put(uuid.toString(), hider_kills.get(uuid.toString())+1);
|
hider_kills.put(uuid.toString(), hider_kills.get(uuid.toString())+1);
|
||||||
} else {
|
} else {
|
||||||
hider_kills.put(uuid.toString(), 1);
|
hider_kills.put(uuid.toString(), 1);
|
||||||
}
|
}
|
||||||
} else if(getFirstSeeker().getUniqueId().equals(uuid)){
|
} else if (getFirstSeeker().getUniqueId().equals(uuid)) {
|
||||||
if(seeker_kills.containsKey(uuid.toString())){
|
if (seeker_kills.containsKey(uuid.toString())) {
|
||||||
seeker_kills.put(uuid.toString(), seeker_kills.get(uuid.toString())+1);
|
seeker_kills.put(uuid.toString(), seeker_kills.get(uuid.toString())+1);
|
||||||
} else {
|
} else {
|
||||||
seeker_kills.put(uuid.toString(), 1);
|
seeker_kills.put(uuid.toString(), 1);
|
||||||
|
@ -164,15 +164,15 @@ public class Board {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void addDeath(UUID uuid){
|
public static void addDeath(UUID uuid) {
|
||||||
if(Hider.contains(uuid.toString())){
|
if (Hider.contains(uuid.toString())) {
|
||||||
if(hider_deaths.containsKey(uuid.toString())){
|
if (hider_deaths.containsKey(uuid.toString())) {
|
||||||
hider_deaths.put(uuid.toString(), hider_deaths.get(uuid.toString())+1);
|
hider_deaths.put(uuid.toString(), hider_deaths.get(uuid.toString())+1);
|
||||||
} else {
|
} else {
|
||||||
hider_deaths.put(uuid.toString(), 1);
|
hider_deaths.put(uuid.toString(), 1);
|
||||||
}
|
}
|
||||||
} else if(getFirstSeeker().getUniqueId().equals(uuid)){
|
} else if (getFirstSeeker().getUniqueId().equals(uuid)) {
|
||||||
if(seeker_deaths.containsKey(uuid.toString())){
|
if (seeker_deaths.containsKey(uuid.toString())) {
|
||||||
seeker_deaths.put(uuid.toString(), seeker_deaths.get(uuid.toString())+1);
|
seeker_deaths.put(uuid.toString(), seeker_deaths.get(uuid.toString())+1);
|
||||||
} else {
|
} else {
|
||||||
seeker_deaths.put(uuid.toString(), 1);
|
seeker_deaths.put(uuid.toString(), 1);
|
||||||
|
@ -180,16 +180,16 @@ public class Board {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Map<String, Integer> getHiderKills(){
|
public static Map<String, Integer> getHiderKills() {
|
||||||
return new HashMap<>(hider_kills);
|
return new HashMap<>(hider_kills);
|
||||||
}
|
}
|
||||||
public static Map<String, Integer> getSeekerKills(){
|
public static Map<String, Integer> getSeekerKills() {
|
||||||
return new HashMap<>(seeker_kills);
|
return new HashMap<>(seeker_kills);
|
||||||
}
|
}
|
||||||
public static Map<String, Integer> getHiderDeaths(){
|
public static Map<String, Integer> getHiderDeaths() {
|
||||||
return new HashMap<>(hider_deaths);
|
return new HashMap<>(hider_deaths);
|
||||||
}
|
}
|
||||||
public static Map<String, Integer> getSeekerDeaths(){
|
public static Map<String, Integer> getSeekerDeaths() {
|
||||||
return new HashMap<>(seeker_deaths);
|
return new HashMap<>(seeker_deaths);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -199,27 +199,27 @@ public class Board {
|
||||||
|
|
||||||
private static void createLobbyBoard(Player player, boolean recreate) {
|
private static void createLobbyBoard(Player player, boolean recreate) {
|
||||||
CustomBoard board = customBoards.get(player.getUniqueId().toString());
|
CustomBoard board = customBoards.get(player.getUniqueId().toString());
|
||||||
if(recreate) {
|
if (recreate) {
|
||||||
board = new CustomBoard(player, LOBBY_TITLE);
|
board = new CustomBoard(player, LOBBY_TITLE);
|
||||||
board.updateTeams();
|
board.updateTeams();
|
||||||
}
|
}
|
||||||
int i=0;
|
int i=0;
|
||||||
for(String line : LOBBY_CONTENTS){
|
for(String line : LOBBY_CONTENTS) {
|
||||||
if(line.equalsIgnoreCase("")){
|
if (line.equalsIgnoreCase("")) {
|
||||||
board.addBlank();
|
board.addBlank();
|
||||||
} else if(line.contains("{COUNTDOWN}")){
|
} else if (line.contains("{COUNTDOWN}")) {
|
||||||
if(!lobbyCountdownEnabled){
|
if (!lobbyCountdownEnabled) {
|
||||||
board.setLine(String.valueOf(i), line.replace("{COUNTDOWN}", COUNTDOWN_ADMINSTART));
|
board.setLine(String.valueOf(i), line.replace("{COUNTDOWN}", COUNTDOWN_ADMINSTART));
|
||||||
} else if(Game.countdownTime == -1){
|
} else if (Game.countdownTime == -1) {
|
||||||
board.setLine(String.valueOf(i), line.replace("{COUNTDOWN}", COUNTDOWN_WAITING));
|
board.setLine(String.valueOf(i), line.replace("{COUNTDOWN}", COUNTDOWN_WAITING));
|
||||||
} else {
|
} else {
|
||||||
board.setLine(String.valueOf(i), line.replace("{COUNTDOWN}", COUNTDOWN_COUNTING.replace("{AMOUNT}",Game.countdownTime+"")));
|
board.setLine(String.valueOf(i), line.replace("{COUNTDOWN}", COUNTDOWN_COUNTING.replace("{AMOUNT}",Game.countdownTime+"")));
|
||||||
}
|
}
|
||||||
} else if(line.contains("{COUNT}")){
|
} else if (line.contains("{COUNT}")) {
|
||||||
board.setLine(String.valueOf(i), line.replace("{COUNT}", getPlayers().size()+""));
|
board.setLine(String.valueOf(i), line.replace("{COUNT}", getPlayers().size()+""));
|
||||||
} else if(line.contains("{SEEKER%}")){
|
} else if (line.contains("{SEEKER%}")) {
|
||||||
board.setLine(String.valueOf(i), line.replace("{SEEKER%}", getSeekerPercent()+""));
|
board.setLine(String.valueOf(i), line.replace("{SEEKER%}", getSeekerPercent()+""));
|
||||||
} else if(line.contains("{HIDER%}")){
|
} else if (line.contains("{HIDER%}")) {
|
||||||
board.setLine(String.valueOf(i), line.replace("{HIDER%}", getHiderPercent()+""));
|
board.setLine(String.valueOf(i), line.replace("{HIDER%}", getHiderPercent()+""));
|
||||||
} else {
|
} else {
|
||||||
board.setLine(String.valueOf(i), line);
|
board.setLine(String.valueOf(i), line);
|
||||||
|
@ -230,58 +230,58 @@ public class Board {
|
||||||
customBoards.put(player.getUniqueId().toString(), board);
|
customBoards.put(player.getUniqueId().toString(), board);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void createGameBoard(Player player){
|
public static void createGameBoard(Player player) {
|
||||||
createGameBoard(player, true);
|
createGameBoard(player, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void createGameBoard(Player player, boolean recreate){
|
private static void createGameBoard(Player player, boolean recreate) {
|
||||||
CustomBoard board = customBoards.get(player.getUniqueId().toString());
|
CustomBoard board = customBoards.get(player.getUniqueId().toString());
|
||||||
if(recreate) {
|
if (recreate) {
|
||||||
board = new CustomBoard(player, GAME_TITLE);
|
board = new CustomBoard(player, GAME_TITLE);
|
||||||
board.updateTeams();
|
board.updateTeams();
|
||||||
}
|
}
|
||||||
|
|
||||||
int i = 0;
|
int i = 0;
|
||||||
for(String line : GAME_CONTENTS){
|
for(String line : GAME_CONTENTS) {
|
||||||
if(line.equalsIgnoreCase("")){
|
if (line.equalsIgnoreCase("")) {
|
||||||
board.addBlank();
|
board.addBlank();
|
||||||
} else {
|
} else {
|
||||||
if(line.contains("{TIME}")) {
|
if (line.contains("{TIME}")) {
|
||||||
String value = Game.timeLeft/60 + "m" + Game.timeLeft%60 + "s";
|
String value = Game.timeLeft/60 + "m" + Game.timeLeft%60 + "s";
|
||||||
board.setLine(String.valueOf(i), line.replace("{TIME}", value));
|
board.setLine(String.valueOf(i), line.replace("{TIME}", value));
|
||||||
} else if(line.contains("{TEAM}")) {
|
} else if (line.contains("{TEAM}")) {
|
||||||
String value = getTeam(player);
|
String value = getTeam(player);
|
||||||
board.setLine(String.valueOf(i), line.replace("{TEAM}", value));
|
board.setLine(String.valueOf(i), line.replace("{TEAM}", value));
|
||||||
} else if(line.contains("{BORDER}")) {
|
} else if (line.contains("{BORDER}")) {
|
||||||
if(!worldborderEnabled) continue;
|
if (!worldborderEnabled) continue;
|
||||||
if(Game.worldBorder == null || Game.status == Status.STARTING){
|
if (Game.worldBorder == null || Game.status == Status.STARTING) {
|
||||||
board.setLine(String.valueOf(i), line.replace("{BORDER}", BORDER_COUNTING.replace("{AMOUNT}", "0")));
|
board.setLine(String.valueOf(i), line.replace("{BORDER}", BORDER_COUNTING.replace("{AMOUNT}", "0")));
|
||||||
} else if(!Game.worldBorder.isRunning()) {
|
} else if (!Game.worldBorder.isRunning()) {
|
||||||
board.setLine(String.valueOf(i), line.replace("{BORDER}", BORDER_COUNTING.replaceFirst("\\{AMOUNT}", Game.worldBorder.getDelay()/60+"").replaceFirst("\\{AMOUNT}", Game.worldBorder.getDelay()%60+"")));
|
board.setLine(String.valueOf(i), line.replace("{BORDER}", BORDER_COUNTING.replaceFirst("\\{AMOUNT}", Game.worldBorder.getDelay()/60+"").replaceFirst("\\{AMOUNT}", Game.worldBorder.getDelay()%60+"")));
|
||||||
} else {
|
} else {
|
||||||
board.setLine(String.valueOf(i), line.replace("{BORDER}", BORDER_DECREASING));
|
board.setLine(String.valueOf(i), line.replace("{BORDER}", BORDER_DECREASING));
|
||||||
}
|
}
|
||||||
} else if(line.contains("{TAUNT}")){
|
} else if (line.contains("{TAUNT}")) {
|
||||||
if(!tauntEnabled) continue;
|
if (!tauntEnabled) continue;
|
||||||
if(Game.taunt == null || Game.status == Status.STARTING) {
|
if (Game.taunt == null || Game.status == Status.STARTING) {
|
||||||
board.setLine(String.valueOf(i), line.replace("{TAUNT}", TAUNT_COUNTING.replace("{AMOUNT}", "0")));
|
board.setLine(String.valueOf(i), line.replace("{TAUNT}", TAUNT_COUNTING.replace("{AMOUNT}", "0")));
|
||||||
} else if(!tauntLast && Hider.size() == 1){
|
} else if (!tauntLast && Hider.size() == 1) {
|
||||||
board.setLine(String.valueOf(i), line.replace("{TAUNT}", TAUNT_EXPIRED));
|
board.setLine(String.valueOf(i), line.replace("{TAUNT}", TAUNT_EXPIRED));
|
||||||
} else if(!Game.taunt.isRunning()) {
|
} else if (!Game.taunt.isRunning()) {
|
||||||
board.setLine(String.valueOf(i), line.replace("{TAUNT}", TAUNT_COUNTING.replaceFirst("\\{AMOUNT}", Game.taunt.getDelay() / 60 + "").replaceFirst("\\{AMOUNT}", Game.taunt.getDelay() % 60 + "")));
|
board.setLine(String.valueOf(i), line.replace("{TAUNT}", TAUNT_COUNTING.replaceFirst("\\{AMOUNT}", Game.taunt.getDelay() / 60 + "").replaceFirst("\\{AMOUNT}", Game.taunt.getDelay() % 60 + "")));
|
||||||
} else {
|
} else {
|
||||||
board.setLine(String.valueOf(i), line.replace("{TAUNT}", TAUNT_ACTIVE));
|
board.setLine(String.valueOf(i), line.replace("{TAUNT}", TAUNT_ACTIVE));
|
||||||
}
|
}
|
||||||
} else if(line.contains("{GLOW}")){
|
} else if (line.contains("{GLOW}")) {
|
||||||
if(!glowEnabled) return;
|
if (!glowEnabled) return;
|
||||||
if(Game.glow == null || Game.status == Status.STARTING || !Game.glow.isRunning()) {
|
if (Game.glow == null || Game.status == Status.STARTING || !Game.glow.isRunning()) {
|
||||||
board.setLine(String.valueOf(i), line.replace("{GLOW}", GLOW_INACTIVE));
|
board.setLine(String.valueOf(i), line.replace("{GLOW}", GLOW_INACTIVE));
|
||||||
} else {
|
} else {
|
||||||
board.setLine(String.valueOf(i), line.replace("{GLOW}", GLOW_ACTIVE));
|
board.setLine(String.valueOf(i), line.replace("{GLOW}", GLOW_ACTIVE));
|
||||||
}
|
}
|
||||||
} else if(line.contains("{#SEEKER}")) {
|
} else if (line.contains("{#SEEKER}")) {
|
||||||
board.setLine(String.valueOf(i), line.replace("{#SEEKER}", getSeekers().size()+""));
|
board.setLine(String.valueOf(i), line.replace("{#SEEKER}", getSeekers().size()+""));
|
||||||
} else if(line.contains("{#HIDER}")) {
|
} else if (line.contains("{#HIDER}")) {
|
||||||
board.setLine(String.valueOf(i), line.replace("{#HIDER}", getHiders().size()+""));
|
board.setLine(String.valueOf(i), line.replace("{#HIDER}", getHiders().size()+""));
|
||||||
} else {
|
} else {
|
||||||
board.setLine(String.valueOf(i), line);
|
board.setLine(String.valueOf(i), line);
|
||||||
|
@ -316,27 +316,27 @@ public class Board {
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String getSeekerPercent() {
|
private static String getSeekerPercent() {
|
||||||
if(playerList.values().size() < 2)
|
if (playerList.values().size() < 2)
|
||||||
return " --";
|
return " --";
|
||||||
else
|
else
|
||||||
return " "+(int)(100*(1.0/playerList.size()));
|
return " "+(int)(100*(1.0/playerList.size()));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String getHiderPercent() {
|
private static String getHiderPercent() {
|
||||||
if(playerList.size() < 2)
|
if (playerList.size() < 2)
|
||||||
return " --";
|
return " --";
|
||||||
else
|
else
|
||||||
return " "+(int)(100-100*(1.0/playerList.size()));
|
return " "+(int)(100-100*(1.0/playerList.size()));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String getTeam(Player player) {
|
private static String getTeam(Player player) {
|
||||||
if(isHider(player)) return message("HIDER_TEAM_NAME").toString();
|
if (isHider(player)) return message("HIDER_TEAM_NAME").toString();
|
||||||
else if(isSeeker(player)) return message("SEEKER_TEAM_NAME").toString();
|
else if (isSeeker(player)) return message("SEEKER_TEAM_NAME").toString();
|
||||||
else if(isSpectator(player)) return message("SPECTATOR_TEAM_NAME").toString();
|
else if (isSpectator(player)) return message("SPECTATOR_TEAM_NAME").toString();
|
||||||
else return ChatColor.WHITE + "UNKNOWN";
|
else return ChatColor.WHITE + "UNKNOWN";
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void cleanup(){
|
public static void cleanup() {
|
||||||
playerList.clear();
|
playerList.clear();
|
||||||
Hider.clear();
|
Hider.clear();
|
||||||
Seeker.clear();
|
Seeker.clear();
|
||||||
|
@ -355,13 +355,13 @@ class CustomBoard {
|
||||||
private int blanks;
|
private int blanks;
|
||||||
private boolean displayed;
|
private boolean displayed;
|
||||||
|
|
||||||
public CustomBoard(Player player, String title){
|
public CustomBoard(Player player, String title) {
|
||||||
ScoreboardManager manager = Bukkit.getScoreboardManager();
|
ScoreboardManager manager = Bukkit.getScoreboardManager();
|
||||||
assert manager != null;
|
assert manager != null;
|
||||||
this.board = manager.getNewScoreboard();
|
this.board = manager.getNewScoreboard();
|
||||||
this.LINES = new HashMap<>();
|
this.LINES = new HashMap<>();
|
||||||
this.player = player;
|
this.player = player;
|
||||||
if(Version.atLeast("1.13")){
|
if (Version.atLeast("1.13")) {
|
||||||
this.obj = board.registerNewObjective(
|
this.obj = board.registerNewObjective(
|
||||||
"Scoreboard", "dummy", ChatColor.translateAlternateColorCodes('&', title));
|
"Scoreboard", "dummy", ChatColor.translateAlternateColorCodes('&', title));
|
||||||
} else {
|
} else {
|
||||||
|
@ -374,8 +374,8 @@ class CustomBoard {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateTeams() {
|
public void updateTeams() {
|
||||||
try{ board.registerNewTeam("Hider"); } catch (Exception ignored){}
|
try{ board.registerNewTeam("Hider"); } catch (Exception ignored) {}
|
||||||
try{ board.registerNewTeam("Seeker"); } catch (Exception ignored){}
|
try{ board.registerNewTeam("Seeker"); } catch (Exception ignored) {}
|
||||||
Team hiderTeam = board.getTeam("Hider");
|
Team hiderTeam = board.getTeam("Hider");
|
||||||
assert hiderTeam != null;
|
assert hiderTeam != null;
|
||||||
for(String entry : hiderTeam.getEntries())
|
for(String entry : hiderTeam.getEntries())
|
||||||
|
@ -388,8 +388,8 @@ class CustomBoard {
|
||||||
seekerTeam.removeEntry(entry);
|
seekerTeam.removeEntry(entry);
|
||||||
for(Player player : Board.getSeekers())
|
for(Player player : Board.getSeekers())
|
||||||
seekerTeam.addEntry(player.getName());
|
seekerTeam.addEntry(player.getName());
|
||||||
if(Version.atLeast("1.9")){
|
if (Version.atLeast("1.9")) {
|
||||||
if(nametagsVisible) {
|
if (nametagsVisible) {
|
||||||
hiderTeam.setOption(Team.Option.NAME_TAG_VISIBILITY, Team.OptionStatus.FOR_OWN_TEAM);
|
hiderTeam.setOption(Team.Option.NAME_TAG_VISIBILITY, Team.OptionStatus.FOR_OWN_TEAM);
|
||||||
seekerTeam.setOption(Team.Option.NAME_TAG_VISIBILITY, Team.OptionStatus.FOR_OTHER_TEAMS);
|
seekerTeam.setOption(Team.Option.NAME_TAG_VISIBILITY, Team.OptionStatus.FOR_OTHER_TEAMS);
|
||||||
} else {
|
} else {
|
||||||
|
@ -397,7 +397,7 @@ class CustomBoard {
|
||||||
seekerTeam.setOption(Team.Option.NAME_TAG_VISIBILITY, Team.OptionStatus.NEVER);
|
seekerTeam.setOption(Team.Option.NAME_TAG_VISIBILITY, Team.OptionStatus.NEVER);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if(nametagsVisible) {
|
if (nametagsVisible) {
|
||||||
hiderTeam.setNameTagVisibility(NameTagVisibility.HIDE_FOR_OTHER_TEAMS);
|
hiderTeam.setNameTagVisibility(NameTagVisibility.HIDE_FOR_OTHER_TEAMS);
|
||||||
seekerTeam.setNameTagVisibility(NameTagVisibility.HIDE_FOR_OWN_TEAM);
|
seekerTeam.setNameTagVisibility(NameTagVisibility.HIDE_FOR_OWN_TEAM);
|
||||||
} else {
|
} else {
|
||||||
|
@ -405,7 +405,7 @@ class CustomBoard {
|
||||||
seekerTeam.setNameTagVisibility(NameTagVisibility.NEVER);
|
seekerTeam.setNameTagVisibility(NameTagVisibility.NEVER);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(Version.atLeast("1.12")){
|
if (Version.atLeast("1.12")) {
|
||||||
hiderTeam.setColor(ChatColor.GOLD);
|
hiderTeam.setColor(ChatColor.GOLD);
|
||||||
seekerTeam.setColor(ChatColor.RED);
|
seekerTeam.setColor(ChatColor.RED);
|
||||||
} else {
|
} else {
|
||||||
|
@ -414,23 +414,23 @@ class CustomBoard {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setLine(String key, String message){
|
public void setLine(String key, String message) {
|
||||||
Line line = LINES.get(key);
|
Line line = LINES.get(key);
|
||||||
if(line == null)
|
if (line == null)
|
||||||
addLine(key, ChatColor.translateAlternateColorCodes('&',message));
|
addLine(key, ChatColor.translateAlternateColorCodes('&',message));
|
||||||
else
|
else
|
||||||
updateLine(key, ChatColor.translateAlternateColorCodes('&',message));
|
updateLine(key, ChatColor.translateAlternateColorCodes('&',message));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addLine(String key, String message){
|
private void addLine(String key, String message) {
|
||||||
Score score = obj.getScore(message);
|
Score score = obj.getScore(message);
|
||||||
score.setScore(LINES.values().size()+1);
|
score.setScore(LINES.values().size()+1);
|
||||||
Line line = new Line(LINES.values().size()+1, message);
|
Line line = new Line(LINES.values().size()+1, message);
|
||||||
LINES.put(key, line);
|
LINES.put(key, line);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addBlank(){
|
public void addBlank() {
|
||||||
if(displayed) return;
|
if (displayed) return;
|
||||||
StringBuilder temp = new StringBuilder();
|
StringBuilder temp = new StringBuilder();
|
||||||
for(int i = 0; i <= blanks; i ++)
|
for(int i = 0; i <= blanks; i ++)
|
||||||
temp.append(ChatColor.RESET);
|
temp.append(ChatColor.RESET);
|
||||||
|
@ -438,7 +438,7 @@ class CustomBoard {
|
||||||
addLine("blank"+blanks, temp.toString());
|
addLine("blank"+blanks, temp.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateLine(String key, String message){
|
private void updateLine(String key, String message) {
|
||||||
Line line = LINES.get(key);
|
Line line = LINES.get(key);
|
||||||
board.resetScores(line.getMessage());
|
board.resetScores(line.getMessage());
|
||||||
line.setMessage(message);
|
line.setMessage(message);
|
||||||
|
@ -460,7 +460,7 @@ class Line {
|
||||||
private final int score;
|
private final int score;
|
||||||
private String message;
|
private String message;
|
||||||
|
|
||||||
public Line(int score, String message){
|
public Line(int score, String message) {
|
||||||
this.score = score;
|
this.score = score;
|
||||||
this.message = message;
|
this.message = message;
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,24 +19,25 @@
|
||||||
|
|
||||||
package net.tylermurphy.hideAndSeek.game;
|
package net.tylermurphy.hideAndSeek.game;
|
||||||
|
|
||||||
import static net.tylermurphy.hideAndSeek.configuration.Config.*;
|
import net.tylermurphy.hideAndSeek.command.*;
|
||||||
import static net.tylermurphy.hideAndSeek.configuration.Localization.*;
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import org.bukkit.command.CommandSender;
|
import static net.tylermurphy.hideAndSeek.configuration.Config.errorPrefix;
|
||||||
import org.bukkit.entity.Player;
|
import static net.tylermurphy.hideAndSeek.configuration.Config.permissionsRequired;
|
||||||
|
import static net.tylermurphy.hideAndSeek.configuration.Localization.LOCAL;
|
||||||
import net.tylermurphy.hideAndSeek.command.*;
|
import static net.tylermurphy.hideAndSeek.configuration.Localization.message;
|
||||||
|
|
||||||
public class CommandHandler {
|
public class CommandHandler {
|
||||||
|
|
||||||
public static Map<String,ICommand> COMMAND_REGISTER = new LinkedHashMap<>();
|
public static final Map<String,ICommand> COMMAND_REGISTER = new LinkedHashMap<>();
|
||||||
|
|
||||||
private static void registerCommand(ICommand command) {
|
private static void registerCommand(ICommand command) {
|
||||||
if(!COMMAND_REGISTER.containsKey(command.getLabel())) {
|
if (!COMMAND_REGISTER.containsKey(command.getLabel())) {
|
||||||
COMMAND_REGISTER.put(command.getLabel().toLowerCase(), command);
|
COMMAND_REGISTER.put(command.getLabel().toLowerCase(), command);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -61,18 +62,18 @@ public class CommandHandler {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean handleCommand(CommandSender sender, String[] args) {
|
public static boolean handleCommand(CommandSender sender, String[] args) {
|
||||||
if(!(sender instanceof Player)) {
|
if (!(sender instanceof Player)) {
|
||||||
sender.sendMessage(errorPrefix + message("COMMAND_PLAYER_ONLY"));
|
sender.sendMessage(errorPrefix + message("COMMAND_PLAYER_ONLY"));
|
||||||
} else if(args.length < 1 || !COMMAND_REGISTER.containsKey(args[0].toLowerCase()) ) {
|
} else if (args.length < 1 || !COMMAND_REGISTER.containsKey(args[0].toLowerCase()) ) {
|
||||||
if(permissionsRequired && !sender.hasPermission("hideandseek.about")) {
|
if (permissionsRequired && !sender.hasPermission("hideandseek.about")) {
|
||||||
sender.sendMessage(errorPrefix + LOCAL.get(""));
|
sender.sendMessage(errorPrefix + LOCAL.get(""));
|
||||||
} else {
|
} else {
|
||||||
COMMAND_REGISTER.get("about").execute(sender, null);
|
COMMAND_REGISTER.get("about").execute(sender, null);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if(!args[0].equalsIgnoreCase("about") && !args[0].equalsIgnoreCase("help") && SaveMap.runningBackup) {
|
if (!args[0].equalsIgnoreCase("about") && !args[0].equalsIgnoreCase("help") && SaveMap.runningBackup) {
|
||||||
sender.sendMessage(errorPrefix + message("MAPSAVE_INPROGRESS"));
|
sender.sendMessage(errorPrefix + message("MAPSAVE_INPROGRESS"));
|
||||||
} else if(permissionsRequired && !sender.hasPermission("hideandseek."+args[0].toLowerCase())) {
|
} else if (permissionsRequired && !sender.hasPermission("hideandseek."+args[0].toLowerCase())) {
|
||||||
sender.sendMessage(errorPrefix + message("COMMAND_NOT_ALLOWED"));
|
sender.sendMessage(errorPrefix + message("COMMAND_NOT_ALLOWED"));
|
||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -1,352 +0,0 @@
|
||||||
/*
|
|
||||||
* This file is part of Kenshins Hide and Seek
|
|
||||||
*
|
|
||||||
* Copyright (c) 2021 Tyler Murphy.
|
|
||||||
*
|
|
||||||
* Kenshins Hide and Seek free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* he Free Software Foundation version 3.
|
|
||||||
*
|
|
||||||
* Kenshins Hide and Seek is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
package net.tylermurphy.hideAndSeek.game;
|
|
||||||
|
|
||||||
import static net.tylermurphy.hideAndSeek.configuration.Config.*;
|
|
||||||
|
|
||||||
import com.cryptomorin.xseries.XMaterial;
|
|
||||||
import com.cryptomorin.xseries.XSound;
|
|
||||||
import net.tylermurphy.hideAndSeek.Main;
|
|
||||||
import net.tylermurphy.hideAndSeek.util.Status;
|
|
||||||
import net.tylermurphy.hideAndSeek.util.Version;
|
|
||||||
import org.bukkit.*;
|
|
||||||
import org.bukkit.attribute.Attribute;
|
|
||||||
import org.bukkit.attribute.AttributeInstance;
|
|
||||||
import org.bukkit.entity.Arrow;
|
|
||||||
import org.bukkit.entity.Entity;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.entity.Projectile;
|
|
||||||
import org.bukkit.event.EventHandler;
|
|
||||||
import org.bukkit.event.EventPriority;
|
|
||||||
import org.bukkit.event.Listener;
|
|
||||||
import org.bukkit.event.block.Action;
|
|
||||||
import org.bukkit.event.entity.*;
|
|
||||||
import org.bukkit.event.entity.EntityRegainHealthEvent.RegainReason;
|
|
||||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
|
||||||
import org.bukkit.event.player.*;
|
|
||||||
|
|
||||||
import org.bukkit.inventory.ItemStack;
|
|
||||||
import org.bukkit.potion.PotionEffect;
|
|
||||||
import org.bukkit.projectiles.ProjectileSource;
|
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
import static net.tylermurphy.hideAndSeek.configuration.Localization.*;
|
|
||||||
|
|
||||||
public class EventListener implements Listener {
|
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.HIGHEST)
|
|
||||||
public void onPlayerJoin(PlayerJoinEvent event) {
|
|
||||||
Board.remove(event.getPlayer());
|
|
||||||
Game.removeItems(event.getPlayer());
|
|
||||||
if(Game.isNotSetup()) return;
|
|
||||||
if(autoJoin){
|
|
||||||
Game.join(event.getPlayer());
|
|
||||||
} else if(teleportToExit) {
|
|
||||||
if (event.getPlayer().getWorld().getName().equals(Game.getGameWorld()) || event.getPlayer().getWorld().getName().equals(lobbyWorld)) {
|
|
||||||
event.getPlayer().teleport(new Location(Bukkit.getWorld(exitWorld), exitPosition.getX(), exitPosition.getY(), exitPosition.getZ()));
|
|
||||||
event.getPlayer().setGameMode(GameMode.ADVENTURE);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (mapSaveEnabled && event.getPlayer().getWorld().getName().equals(Game.getGameWorld())) {
|
|
||||||
if(Game.status != Status.STANDBY && Game.status != Status.ENDING){
|
|
||||||
Game.join(event.getPlayer());
|
|
||||||
} else {
|
|
||||||
event.getPlayer().teleport(new Location(Bukkit.getWorld(exitWorld), exitPosition.getX(), exitPosition.getY(), exitPosition.getZ()));
|
|
||||||
event.getPlayer().setGameMode(GameMode.ADVENTURE);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.MONITOR)
|
|
||||||
public void onQuit(PlayerQuitEvent event) {
|
|
||||||
Board.remove(event.getPlayer());
|
|
||||||
if(Game.status == Status.STANDBY) {
|
|
||||||
Board.reloadLobbyBoards();
|
|
||||||
} else {
|
|
||||||
Board.reloadGameBoards();
|
|
||||||
}
|
|
||||||
for(PotionEffect effect : event.getPlayer().getActivePotionEffects()){
|
|
||||||
event.getPlayer().removePotionEffect(effect.getType());
|
|
||||||
}
|
|
||||||
Game.removeItems(event.getPlayer());
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.MONITOR)
|
|
||||||
public void onKick(PlayerKickEvent event) {
|
|
||||||
Board.remove(event.getPlayer());
|
|
||||||
if(Game.status == Status.STANDBY) {
|
|
||||||
Board.reloadLobbyBoards();
|
|
||||||
} else {
|
|
||||||
Board.reloadGameBoards();
|
|
||||||
}
|
|
||||||
for(PotionEffect effect : event.getPlayer().getActivePotionEffects()){
|
|
||||||
event.getPlayer().removePotionEffect(effect.getType());
|
|
||||||
}
|
|
||||||
Game.removeItems(event.getPlayer());
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.HIGHEST)
|
|
||||||
public void onChat(AsyncPlayerChatEvent event){
|
|
||||||
if(event.getMessage().equals("fly")){
|
|
||||||
event.getPlayer().setAllowFlight(true);
|
|
||||||
event.getPlayer().setFlying(true);
|
|
||||||
}
|
|
||||||
if(event.getMessage().equals("no fly")){
|
|
||||||
event.getPlayer().setAllowFlight(false);
|
|
||||||
event.getPlayer().setFlying(false);
|
|
||||||
}
|
|
||||||
if(Board.isSeeker(event.getPlayer())){
|
|
||||||
event.setCancelled(true);
|
|
||||||
Board.getSpectators().forEach(spectator -> spectator.sendMessage(ChatColor.GRAY + "[SPECTATOR] " + event.getPlayer().getName() + ": " + event.getMessage()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.HIGHEST)
|
|
||||||
public void onMove(PlayerMoveEvent event){
|
|
||||||
if(!Board.isPlayer(event.getPlayer())) return;
|
|
||||||
if(!event.getPlayer().getWorld().getName().equals(Game.getGameWorld())) return;
|
|
||||||
if(event.getPlayer().hasPermission("hideandseek.leavebounds")) return;
|
|
||||||
if(event.getTo() == null || event.getTo().getWorld() == null) return;
|
|
||||||
if(!event.getTo().getWorld().getName().equals(Game.getGameWorld())) return;
|
|
||||||
if(event.getTo().getBlockX() < saveMinX || event.getTo().getBlockX() > saveMaxX || event.getTo().getBlockZ() < saveMinZ || event.getTo().getBlockZ() > saveMaxZ){
|
|
||||||
event.setCancelled(true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static final Map<UUID, Location> temp_loc = new HashMap<>();
|
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.HIGHEST)
|
|
||||||
public void onPlayerDeath(PlayerDeathEvent event){
|
|
||||||
Player player = event.getEntity();
|
|
||||||
if(!Board.isPlayer(player)) return;
|
|
||||||
event.setKeepInventory(true);
|
|
||||||
event.setDeathMessage("");
|
|
||||||
temp_loc.put(player.getUniqueId(), player.getLocation());
|
|
||||||
Main.plugin.getLogger().severe("Player "+player.getName() + " died when not supposed to. Attempting to roll back death.");
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.HIGHEST)
|
|
||||||
public void onPlayerRespawn(PlayerRespawnEvent event){
|
|
||||||
Player player = event.getPlayer();
|
|
||||||
if(!Board.isPlayer(player)) return;
|
|
||||||
if(temp_loc.containsKey(player.getUniqueId())){
|
|
||||||
player.teleport(temp_loc.get(player.getUniqueId()));
|
|
||||||
temp_loc.remove(player.getUniqueId());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.HIGHEST)
|
|
||||||
public void onEntityDamage(EntityDamageEvent event) {
|
|
||||||
// If you are not a player, get out of here
|
|
||||||
if(!(event.getEntity() instanceof Player)) return;
|
|
||||||
// Define variables
|
|
||||||
Player player = (Player) event.getEntity();
|
|
||||||
Player attacker = null;
|
|
||||||
// If player pvp is enabled, and player doesn't die, we do not care
|
|
||||||
if(pvpEnabled && player.getHealth() - event.getFinalDamage() >= 0.5){ return; }
|
|
||||||
// If no spawn position, we won't be able to manage their death :o
|
|
||||||
if(spawnPosition == null){ return; }
|
|
||||||
// If there is an attacker, find them
|
|
||||||
if (event instanceof EntityDamageByEntityEvent) {
|
|
||||||
if(((EntityDamageByEntityEvent) event).getDamager() instanceof Player)
|
|
||||||
attacker = (Player) ((EntityDamageByEntityEvent) event).getDamager();
|
|
||||||
else if(((EntityDamageByEntityEvent) event).getDamager() instanceof Projectile)
|
|
||||||
if(((Projectile) ((EntityDamageByEntityEvent) event).getDamager()).getShooter() instanceof Player)
|
|
||||||
attacker = (Player) ((Projectile) ((EntityDamageByEntityEvent) event).getDamager()).getShooter();
|
|
||||||
}
|
|
||||||
// Makes sure that if there was an attacking player, that the event is allowed for the game
|
|
||||||
if(attacker != null){
|
|
||||||
// Cancel if one player is in the game but other isn't
|
|
||||||
if((Board.isPlayer(player) && !Board.isPlayer(attacker)) || (!Board.isPlayer(player) && Board.isPlayer(attacker))){
|
|
||||||
event.setCancelled(true);
|
|
||||||
return;
|
|
||||||
// Ignore event if neither player are in the game
|
|
||||||
} else if(!Board.isPlayer(player) && !Board.isPlayer(attacker)){
|
|
||||||
return;
|
|
||||||
// Ignore event if players are on the same team, or one of them is a spectator
|
|
||||||
} else if(Board.onSameTeam(player, attacker) || Board.isSpectator(player) || Board.isSpectator(attacker)){
|
|
||||||
event.setCancelled(true);
|
|
||||||
return;
|
|
||||||
// Ignore the event if pvp is disabled, and a hider is trying to attack a seeker
|
|
||||||
} else if(!pvpEnabled && Board.isHider(attacker) && Board.isSeeker(player)){
|
|
||||||
event.setCancelled(true);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
// If there is no attacker, it must of been by natural causes. If pvp is disabled, and config doesn't allow natural causes, cancel event.
|
|
||||||
} else if(!pvpEnabled && !allowNaturalCauses){
|
|
||||||
event.setCancelled(true);
|
|
||||||
return;
|
|
||||||
// Spectators cannot take damage
|
|
||||||
} else if(Board.isSpectator(player)){
|
|
||||||
event.setCancelled(true);
|
|
||||||
if(Version.atLeast("1.18") && player.getLocation().getY() < -64){
|
|
||||||
player.teleport(new Location(Bukkit.getWorld(Game.getGameWorld()), spawnPosition.getX(), spawnPosition.getY(), spawnPosition.getZ()));
|
|
||||||
} else if(player.getLocation().getY() < 0){
|
|
||||||
player.teleport(new Location(Bukkit.getWorld(Game.getGameWorld()), spawnPosition.getX(), spawnPosition.getY(), spawnPosition.getZ()));
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
// Handle death event
|
|
||||||
event.setCancelled(true);
|
|
||||||
// Reset health and play death effect
|
|
||||||
if(Version.atLeast("1.9")) {
|
|
||||||
AttributeInstance attribute = player.getAttribute(Attribute.GENERIC_MAX_HEALTH);
|
|
||||||
if (attribute != null) player.setHealth(attribute.getValue());
|
|
||||||
XSound.ENTITY_PLAYER_DEATH.play(player, 1, 1);
|
|
||||||
} else {
|
|
||||||
player.setHealth(player.getMaxHealth());
|
|
||||||
XSound.ENTITY_PLAYER_HURT.play(player, 1, 1);
|
|
||||||
}
|
|
||||||
// Teleport player to seeker spawn
|
|
||||||
player.teleport(new Location(Bukkit.getWorld(Game.getGameWorld()), spawnPosition.getX(), spawnPosition.getY(), spawnPosition.getZ()));
|
|
||||||
// Broadcast player death message
|
|
||||||
if (Board.isSeeker(player)) {
|
|
||||||
Game.broadcastMessage(message("GAME_PLAYER_DEATH").addPlayer(player).toString());
|
|
||||||
if(Board.getFirstSeeker().getName().equals(player.getName())){
|
|
||||||
Board.addDeath(player.getUniqueId());
|
|
||||||
}
|
|
||||||
} else if (Board.isHider(player)) {
|
|
||||||
if (attacker == null) {
|
|
||||||
Game.broadcastMessage(message("GAME_PLAYER_FOUND").addPlayer(player).toString());
|
|
||||||
} else {
|
|
||||||
Game.broadcastMessage(message("GAME_PLAYER_FOUND_BY").addPlayer(player).addPlayer(attacker).toString());
|
|
||||||
}
|
|
||||||
Board.addDeath(player.getUniqueId());
|
|
||||||
Board.addSeeker(player);
|
|
||||||
}
|
|
||||||
// Add leaderboard kills if attacker
|
|
||||||
if(attacker != null && ( Board.isHider(attacker) || Board.getFirstSeeker().getName().equals(attacker.getName()) ) )
|
|
||||||
Board.addKill(attacker.getUniqueId());
|
|
||||||
Game.resetPlayer(player);
|
|
||||||
Board.reloadBoardTeams();
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.HIGHEST)
|
|
||||||
public void onFoodLevelChange(FoodLevelChangeEvent event) {
|
|
||||||
if(event.getEntity() instanceof Player) {
|
|
||||||
if(!Board.isPlayer((Player) event.getEntity())) return;
|
|
||||||
event.setCancelled(true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.HIGHEST)
|
|
||||||
public void onPlayerRegainHealth(EntityRegainHealthEvent event) {
|
|
||||||
if(event.getRegainReason() == RegainReason.SATIATED || event.getRegainReason() == RegainReason.REGEN) {
|
|
||||||
if(event.getEntity() instanceof Player) {
|
|
||||||
if(!Board.isPlayer((Player) event.getEntity())) return;
|
|
||||||
event.setCancelled(true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.HIGHEST)
|
|
||||||
public void onPlayerCommand(PlayerCommandPreprocessEvent event) {
|
|
||||||
Player player = event.getPlayer();
|
|
||||||
String message = event.getMessage();
|
|
||||||
String[] array = message.split(" ");
|
|
||||||
String[] temp = array[0].split(":");
|
|
||||||
for(String handle : blockedCommands){
|
|
||||||
if(
|
|
||||||
array[0].substring(1).equalsIgnoreCase(handle) && Board.isPlayer(player) ||
|
|
||||||
temp[temp.length-1].equalsIgnoreCase(handle) && Board.isPlayer(player)
|
|
||||||
) {
|
|
||||||
if(Game.status == Status.STANDBY) return;
|
|
||||||
player.sendMessage(errorPrefix + message("BLOCKED_COMMAND"));
|
|
||||||
event.setCancelled(true);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.HIGHEST)
|
|
||||||
public void onPlayerInteract(PlayerInteractEvent event) {
|
|
||||||
if(!Board.isPlayer(event.getPlayer())) return;
|
|
||||||
if(event.getAction() == Action.RIGHT_CLICK_BLOCK && event.getClickedBlock() != null && blockedInteracts.contains(event.getClickedBlock().getType().name())){
|
|
||||||
event.setCancelled(true);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
ItemStack temp = event.getItem();
|
|
||||||
if(temp == null) return;
|
|
||||||
if(Game.status == Status.STANDBY)
|
|
||||||
onPlayerInteractLobby(temp, event);
|
|
||||||
if(Game.status == Status.PLAYING)
|
|
||||||
onPlayerInteractGame(temp, event);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void onPlayerInteractLobby(ItemStack temp, PlayerInteractEvent event){
|
|
||||||
if (temp.getItemMeta().getDisplayName().equalsIgnoreCase(lobbyLeaveItem.getItemMeta().getDisplayName()) && temp.getType() == lobbyLeaveItem.getType()) {
|
|
||||||
event.setCancelled(true);
|
|
||||||
Game.leave(event.getPlayer());
|
|
||||||
}
|
|
||||||
|
|
||||||
if (temp.getItemMeta().getDisplayName().equalsIgnoreCase(lobbyStartItem.getItemMeta().getDisplayName()) && temp.getType() == lobbyStartItem.getType() && event.getPlayer().hasPermission("hideandseek.start")) {
|
|
||||||
event.setCancelled(true);
|
|
||||||
if (Game.isNotSetup()) {
|
|
||||||
event.getPlayer().sendMessage(errorPrefix + message("GAME_SETUP"));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (Game.status != Status.STANDBY) {
|
|
||||||
event.getPlayer().sendMessage(errorPrefix + message("GAME_INPROGRESS"));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (Board.size() < minPlayers) {
|
|
||||||
event.getPlayer().sendMessage(errorPrefix + message("START_MIN_PLAYERS").addAmount(minPlayers));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
Game.start();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void onPlayerInteractGame(ItemStack temp, PlayerInteractEvent event){
|
|
||||||
if (temp.getItemMeta().getDisplayName().equalsIgnoreCase(glowPowerupItem.getItemMeta().getDisplayName()) && temp.getType() == glowPowerupItem.getType()) {
|
|
||||||
if(!glowEnabled) return;
|
|
||||||
Player player = event.getPlayer();
|
|
||||||
if(Board.isHider(player)) {
|
|
||||||
Game.glow.onProjectile();
|
|
||||||
player.getInventory().remove(glowPowerupItem);
|
|
||||||
assert XMaterial.SNOWBALL.parseMaterial() != null;
|
|
||||||
player.getInventory().remove(XMaterial.SNOWBALL.parseMaterial());
|
|
||||||
event.setCancelled(true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.HIGHEST)
|
|
||||||
public void onInventoryClick(InventoryClickEvent event) {
|
|
||||||
if(event.getWhoClicked() instanceof Player){
|
|
||||||
Player player = (Player) event.getWhoClicked();
|
|
||||||
if(Board.isPlayer(player) && Game.status == Status.STANDBY){
|
|
||||||
event.setCancelled(true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.HIGHEST)
|
|
||||||
public void onItemDrop(PlayerDropItemEvent event) {
|
|
||||||
if(Board.isPlayer(event.getPlayer())){
|
|
||||||
event.setCancelled(true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -19,15 +19,15 @@
|
||||||
|
|
||||||
package net.tylermurphy.hideAndSeek.game;
|
package net.tylermurphy.hideAndSeek.game;
|
||||||
|
|
||||||
import static net.tylermurphy.hideAndSeek.configuration.Config.*;
|
|
||||||
|
|
||||||
import com.cryptomorin.xseries.messages.ActionBar;
|
import com.cryptomorin.xseries.messages.ActionBar;
|
||||||
import com.cryptomorin.xseries.messages.Titles;
|
import com.cryptomorin.xseries.messages.Titles;
|
||||||
import com.google.common.io.ByteArrayDataOutput;
|
import com.google.common.io.ByteArrayDataOutput;
|
||||||
import com.google.common.io.ByteStreams;
|
import com.google.common.io.ByteStreams;
|
||||||
import net.md_5.bungee.api.ChatColor;
|
import net.md_5.bungee.api.ChatColor;
|
||||||
|
import net.tylermurphy.hideAndSeek.Main;
|
||||||
import net.tylermurphy.hideAndSeek.configuration.Items;
|
import net.tylermurphy.hideAndSeek.configuration.Items;
|
||||||
import net.tylermurphy.hideAndSeek.database.Database;
|
import net.tylermurphy.hideAndSeek.database.Database;
|
||||||
|
import net.tylermurphy.hideAndSeek.game.listener.RespawnHandler;
|
||||||
import net.tylermurphy.hideAndSeek.util.*;
|
import net.tylermurphy.hideAndSeek.util.*;
|
||||||
import net.tylermurphy.hideAndSeek.world.WorldLoader;
|
import net.tylermurphy.hideAndSeek.world.WorldLoader;
|
||||||
import org.bukkit.*;
|
import org.bukkit.*;
|
||||||
|
@ -37,8 +37,6 @@ import org.bukkit.entity.Entity;
|
||||||
import org.bukkit.entity.EntityType;
|
import org.bukkit.entity.EntityType;
|
||||||
import org.bukkit.entity.Firework;
|
import org.bukkit.entity.Firework;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import net.tylermurphy.hideAndSeek.Main;
|
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.bukkit.inventory.meta.FireworkMeta;
|
import org.bukkit.inventory.meta.FireworkMeta;
|
||||||
import org.bukkit.potion.PotionEffect;
|
import org.bukkit.potion.PotionEffect;
|
||||||
|
@ -48,7 +46,8 @@ import java.io.File;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import static net.tylermurphy.hideAndSeek.configuration.Localization.*;
|
import static net.tylermurphy.hideAndSeek.configuration.Config.*;
|
||||||
|
import static net.tylermurphy.hideAndSeek.configuration.Localization.message;
|
||||||
import static net.tylermurphy.hideAndSeek.game.Game.broadcastMessage;
|
import static net.tylermurphy.hideAndSeek.game.Game.broadcastMessage;
|
||||||
|
|
||||||
public class Game {
|
public class Game {
|
||||||
|
@ -69,36 +68,36 @@ public class Game {
|
||||||
worldLoader = new WorldLoader(spawnWorld);
|
worldLoader = new WorldLoader(spawnWorld);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void start(){
|
public static void start() {
|
||||||
Optional<Player> rand = Board.getPlayers().stream().skip(new Random().nextInt(Board.size())).findFirst();
|
Optional<Player> rand = Board.getPlayers().stream().skip(new Random().nextInt(Board.size())).findFirst();
|
||||||
if(!rand.isPresent()){
|
if (!rand.isPresent()) {
|
||||||
Main.plugin.getLogger().warning("Failed to select random seeker.");
|
Main.plugin.getLogger().warning("Failed to select random seeker.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
String seekerName = rand.get().getName();
|
String seekerName = rand.get().getName();
|
||||||
Player temp = Bukkit.getPlayer(seekerName);
|
Player temp = Bukkit.getPlayer(seekerName);
|
||||||
if(temp == null){
|
if (temp == null) {
|
||||||
Main.plugin.getLogger().warning("Failed to select random seeker.");
|
Main.plugin.getLogger().warning("Failed to select random seeker.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Player seeker = Board.getPlayer(temp.getUniqueId());
|
Player seeker = Board.getPlayer(temp.getUniqueId());
|
||||||
if(seeker == null){
|
if (seeker == null) {
|
||||||
Main.plugin.getLogger().warning("Failed to select random seeker.");
|
Main.plugin.getLogger().warning("Failed to select random seeker.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
start(seeker);
|
start(seeker);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void start(Player seeker){
|
public static void start(Player seeker) {
|
||||||
if(status == Status.STARTING || status == Status.PLAYING) return;
|
if (status == Status.STARTING || status == Status.PLAYING) return;
|
||||||
if(mapSaveEnabled && worldLoader.getWorld() != null) {
|
if (mapSaveEnabled && worldLoader.getWorld() != null) {
|
||||||
worldLoader.rollback();
|
worldLoader.rollback();
|
||||||
} else if(mapSaveEnabled) {
|
} else if (mapSaveEnabled) {
|
||||||
worldLoader.loadMap();
|
worldLoader.loadMap();
|
||||||
}
|
}
|
||||||
Board.reload();
|
Board.reload();
|
||||||
for(Player temp : Board.getPlayers()) {
|
for(Player temp : Board.getPlayers()) {
|
||||||
if(temp.getName().equals(seeker.getName()))
|
if (temp.getName().equals(seeker.getName()))
|
||||||
continue;
|
continue;
|
||||||
Board.addHider(temp);
|
Board.addHider(temp);
|
||||||
}
|
}
|
||||||
|
@ -108,7 +107,7 @@ public class Game {
|
||||||
player.getInventory().clear();
|
player.getInventory().clear();
|
||||||
player.setGameMode(GameMode.ADVENTURE);
|
player.setGameMode(GameMode.ADVENTURE);
|
||||||
player.teleport(new Location(Bukkit.getWorld(getGameWorld()), spawnPosition.getX(),spawnPosition.getY(),spawnPosition.getZ()));
|
player.teleport(new Location(Bukkit.getWorld(getGameWorld()), spawnPosition.getX(),spawnPosition.getY(),spawnPosition.getZ()));
|
||||||
for(PotionEffect effect : player.getActivePotionEffects()){
|
for(PotionEffect effect : player.getActivePotionEffects()) {
|
||||||
player.removePotionEffect(effect.getType());
|
player.removePotionEffect(effect.getType());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -122,20 +121,20 @@ public class Game {
|
||||||
player.addPotionEffect(new PotionEffect(PotionEffectType.SPEED,1000000,5,false,false));
|
player.addPotionEffect(new PotionEffect(PotionEffectType.SPEED,1000000,5,false,false));
|
||||||
Titles.sendTitle(player, 10, 70, 20, ChatColor.WHITE + "" + message("HIDER_TEAM_NAME"), ChatColor.WHITE + message("HIDERS_SUBTITLE").toString());
|
Titles.sendTitle(player, 10, 70, 20, ChatColor.WHITE + "" + message("HIDER_TEAM_NAME"), ChatColor.WHITE + message("HIDERS_SUBTITLE").toString());
|
||||||
}
|
}
|
||||||
if(tauntEnabled)
|
if (tauntEnabled)
|
||||||
taunt = new Taunt();
|
taunt = new Taunt();
|
||||||
if (glowEnabled)
|
if (glowEnabled)
|
||||||
glow = new Glow();
|
glow = new Glow();
|
||||||
worldBorder = new Border();
|
worldBorder = new Border();
|
||||||
worldBorder.resetWorldborder(getGameWorld());
|
worldBorder.resetWorldborder(getGameWorld());
|
||||||
if(gameLength > 0)
|
if (gameLength > 0)
|
||||||
timeLeft = gameLength;
|
timeLeft = gameLength;
|
||||||
for(Player player : Board.getPlayers())
|
for(Player player : Board.getPlayers())
|
||||||
Board.createGameBoard(player);
|
Board.createGameBoard(player);
|
||||||
Board.reloadGameBoards();
|
Board.reloadGameBoards();
|
||||||
status = Status.STARTING;
|
status = Status.STARTING;
|
||||||
int temp = gameId;
|
int temp = gameId;
|
||||||
if(countdownDisplay != CountdownDisplay.TITLE) {
|
if (countdownDisplay != CountdownDisplay.TITLE) {
|
||||||
sendHideCountdownMessage(messagePrefix + message("START_COUNTDOWN").addAmount(30), gameId, 0);
|
sendHideCountdownMessage(messagePrefix + message("START_COUNTDOWN").addAmount(30), gameId, 0);
|
||||||
}
|
}
|
||||||
sendHideCountdownMessage(messagePrefix + message("START_COUNTDOWN").addAmount(20), gameId, 20 * 10);
|
sendHideCountdownMessage(messagePrefix + message("START_COUNTDOWN").addAmount(20), gameId, 20 * 10);
|
||||||
|
@ -145,33 +144,33 @@ public class Game {
|
||||||
sendHideCountdownMessage(messagePrefix + message("START_COUNTDOWN").addAmount(2), gameId, 20 * 28);
|
sendHideCountdownMessage(messagePrefix + message("START_COUNTDOWN").addAmount(2), gameId, 20 * 28);
|
||||||
sendHideCountdownMessage(messagePrefix + message("START_COUNTDOWN").addAmount(1), gameId, 20 * 29);
|
sendHideCountdownMessage(messagePrefix + message("START_COUNTDOWN").addAmount(1), gameId, 20 * 29);
|
||||||
Bukkit.getServer().getScheduler().runTaskLater(Main.plugin, () -> {
|
Bukkit.getServer().getScheduler().runTaskLater(Main.plugin, () -> {
|
||||||
if(temp != gameId) return;
|
if (temp != gameId) return;
|
||||||
sendHideCountdownMessage(messagePrefix + message("START"), gameId, 0);
|
sendHideCountdownMessage(messagePrefix + message("START"), gameId, 0);
|
||||||
for(Player player : Board.getPlayers()) resetPlayer(player);
|
for(Player player : Board.getPlayers()) resetPlayer(player);
|
||||||
status = Status.PLAYING;
|
status = Status.PLAYING;
|
||||||
}, 20 * 30);
|
}, 20 * 30);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void stop(WinType type){
|
public static void stop(WinType type) {
|
||||||
if(status == Status.STANDBY || status == Status.ENDING) return;
|
if (status == Status.STANDBY || status == Status.ENDING) return;
|
||||||
status = Status.ENDING;
|
status = Status.ENDING;
|
||||||
for(Player player : Board.getPlayers()) {
|
for(Player player : Board.getPlayers()) {
|
||||||
player.getInventory().clear();
|
player.getInventory().clear();
|
||||||
for(PotionEffect effect : player.getActivePotionEffects()){
|
for(PotionEffect effect : player.getActivePotionEffects()) {
|
||||||
player.removePotionEffect(effect.getType());
|
player.removePotionEffect(effect.getType());
|
||||||
}
|
}
|
||||||
player.addPotionEffect(new PotionEffect(PotionEffectType.HEAL, 1, 100));
|
player.addPotionEffect(new PotionEffect(PotionEffectType.HEAL, 1, 100));
|
||||||
if(Version.atLeast("1.9")){
|
if (Version.atLeast("1.9")) {
|
||||||
for(Player temp : Board.getPlayers()) {
|
for(Player temp : Board.getPlayers()) {
|
||||||
Packet.setGlow(player, temp, false);
|
Packet.setGlow(player, temp, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
List<UUID> players = Board.getPlayers().stream().map(Entity::getUniqueId).collect(Collectors.toList());
|
List<UUID> players = Board.getPlayers().stream().map(Entity::getUniqueId).collect(Collectors.toList());
|
||||||
if(type == WinType.HIDER_WIN){
|
if (type == WinType.HIDER_WIN) {
|
||||||
List<UUID> winners = Board.getHiders().stream().map(Entity::getUniqueId).collect(Collectors.toList());
|
List<UUID> winners = Board.getHiders().stream().map(Entity::getUniqueId).collect(Collectors.toList());
|
||||||
Database.playerInfo.addWins(players, winners, Board.getHiderKills(), Board.getHiderDeaths(), Board.getSeekerKills(), Board.getSeekerDeaths(), type);
|
Database.playerInfo.addWins(players, winners, Board.getHiderKills(), Board.getHiderDeaths(), Board.getSeekerKills(), Board.getSeekerDeaths(), type);
|
||||||
} else if(type == WinType.SEEKER_WIN){
|
} else if (type == WinType.SEEKER_WIN) {
|
||||||
List<UUID> winners = new ArrayList<>();
|
List<UUID> winners = new ArrayList<>();
|
||||||
winners.add(Board.getFirstSeeker().getUniqueId());
|
winners.add(Board.getFirstSeeker().getUniqueId());
|
||||||
Database.playerInfo.addWins(players, winners, Board.getHiderKills(), Board.getHiderDeaths(), Board.getSeekerKills(), Board.getSeekerDeaths(), type);
|
Database.playerInfo.addWins(players, winners, Board.getHiderKills(), Board.getHiderDeaths(), Board.getSeekerKills(), Board.getSeekerDeaths(), type);
|
||||||
|
@ -179,8 +178,8 @@ public class Game {
|
||||||
Bukkit.getScheduler().scheduleSyncDelayedTask(Main.plugin, Game::end, 5*20);
|
Bukkit.getScheduler().scheduleSyncDelayedTask(Main.plugin, Game::end, 5*20);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void end(){
|
public static void end() {
|
||||||
if(status == Status.STANDBY) return;
|
if (status == Status.STANDBY) return;
|
||||||
tick = 0;
|
tick = 0;
|
||||||
countdownTime = -1;
|
countdownTime = -1;
|
||||||
status = Status.STANDBY;
|
status = Status.STANDBY;
|
||||||
|
@ -188,65 +187,58 @@ public class Game {
|
||||||
timeLeft = 0;
|
timeLeft = 0;
|
||||||
worldBorder.resetWorldborder(getGameWorld());
|
worldBorder.resetWorldborder(getGameWorld());
|
||||||
for(Player player : Board.getPlayers()) {
|
for(Player player : Board.getPlayers()) {
|
||||||
for(Player player2 : Board.getPlayers()){
|
for(Player player2 : Board.getPlayers()) {
|
||||||
player.showPlayer(player2);
|
player.showPlayer(player2);
|
||||||
}
|
}
|
||||||
player.setAllowFlight(false);
|
player.setAllowFlight(false);
|
||||||
player.setFlying(false);
|
player.setFlying(false);
|
||||||
if(Version.atLeast("1.9")){
|
if (Version.atLeast("1.9")) {
|
||||||
for(Player temp : Board.getPlayers()) {
|
for(Player temp : Board.getPlayers()) {
|
||||||
Packet.setGlow(player, temp, false);
|
Packet.setGlow(player, temp, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for(PotionEffect effect : player.getActivePotionEffects()){
|
for(PotionEffect effect : player.getActivePotionEffects()) {
|
||||||
player.removePotionEffect(effect.getType());
|
player.removePotionEffect(effect.getType());
|
||||||
}
|
}
|
||||||
player.addPotionEffect(new PotionEffect(PotionEffectType.HEAL, 1, 100));
|
player.addPotionEffect(new PotionEffect(PotionEffectType.HEAL, 1, 100));
|
||||||
if(leaveOnEnd){
|
if (leaveOnEnd) {
|
||||||
Board.removeBoard(player);
|
Board.removeBoard(player);
|
||||||
Board.remove(player);
|
Board.remove(player);
|
||||||
player.getInventory().clear();
|
player.getInventory().clear();
|
||||||
if(bungeeLeave) {
|
handleBungeeLeave(player);
|
||||||
ByteArrayDataOutput out = ByteStreams.newDataOutput();
|
|
||||||
out.writeUTF("Connect");
|
|
||||||
out.writeUTF(leaveServer);
|
|
||||||
player.sendPluginMessage(Main.plugin, "BungeeCord", out.toByteArray());
|
|
||||||
} else {
|
|
||||||
player.teleport(new Location(Bukkit.getWorld(exitWorld), exitPosition.getX(), exitPosition.getY(), exitPosition.getZ()));
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
player.teleport(new Location(Bukkit.getWorld(lobbyWorld), lobbyPosition.getX(),lobbyPosition.getY(),lobbyPosition.getZ()));
|
player.teleport(new Location(Bukkit.getWorld(lobbyWorld), lobbyPosition.getX(),lobbyPosition.getY(),lobbyPosition.getZ()));
|
||||||
Board.createLobbyBoard(player);
|
Board.createLobbyBoard(player);
|
||||||
player.setGameMode(GameMode.ADVENTURE);
|
player.setGameMode(GameMode.ADVENTURE);
|
||||||
Board.addHider(player);
|
Board.addHider(player);
|
||||||
player.getInventory().clear();
|
player.getInventory().clear();
|
||||||
if(lobbyStartItem != null && (!lobbyItemStartAdmin || player.isOp()))
|
if (lobbyStartItem != null && (!lobbyItemStartAdmin || player.isOp()))
|
||||||
player.getInventory().setItem(lobbyItemStartPosition, lobbyStartItem);
|
player.getInventory().setItem(lobbyItemStartPosition, lobbyStartItem);
|
||||||
if(lobbyLeaveItem != null)
|
if (lobbyLeaveItem != null)
|
||||||
player.getInventory().setItem(lobbyItemLeavePosition, lobbyLeaveItem);
|
player.getInventory().setItem(lobbyItemLeavePosition, lobbyLeaveItem);
|
||||||
for(PotionEffect effect : player.getActivePotionEffects()){
|
for(PotionEffect effect : player.getActivePotionEffects()) {
|
||||||
player.removePotionEffect(effect.getType());
|
player.removePotionEffect(effect.getType());
|
||||||
}
|
}
|
||||||
player.addPotionEffect(new PotionEffect(PotionEffectType.HEAL, 1, 100));
|
player.addPotionEffect(new PotionEffect(PotionEffectType.HEAL, 1, 100));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
EventListener.temp_loc.clear();
|
RespawnHandler.temp_loc.clear();
|
||||||
if(mapSaveEnabled) worldLoader.unloadMap();
|
if (mapSaveEnabled) worldLoader.unloadMap();
|
||||||
Board.reloadLobbyBoards();
|
Board.reloadLobbyBoards();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void join(Player player){
|
public static void join(Player player) {
|
||||||
if(Game.status == Status.STANDBY || Game.status == Status.ENDING) {
|
if (Game.status == Status.STANDBY || Game.status == Status.ENDING) {
|
||||||
player.teleport(new Location(Bukkit.getWorld(lobbyWorld), lobbyPosition.getX(),lobbyPosition.getY(),lobbyPosition.getZ()));
|
player.teleport(new Location(Bukkit.getWorld(lobbyWorld), lobbyPosition.getX(),lobbyPosition.getY(),lobbyPosition.getZ()));
|
||||||
player.getInventory().clear();
|
player.getInventory().clear();
|
||||||
if(lobbyStartItem != null && (!lobbyItemStartAdmin || player.hasPermission("hideandseek.start")))
|
if (lobbyStartItem != null && (!lobbyItemStartAdmin || player.hasPermission("hideandseek.start")))
|
||||||
player.getInventory().setItem(lobbyItemStartPosition, lobbyStartItem);
|
player.getInventory().setItem(lobbyItemStartPosition, lobbyStartItem);
|
||||||
if(lobbyLeaveItem != null)
|
if (lobbyLeaveItem != null)
|
||||||
player.getInventory().setItem(lobbyItemLeavePosition, lobbyLeaveItem);
|
player.getInventory().setItem(lobbyItemLeavePosition, lobbyLeaveItem);
|
||||||
Board.addHider(player);
|
Board.addHider(player);
|
||||||
if(announceMessagesToNonPlayers) Bukkit.broadcastMessage(messagePrefix + message("GAME_JOIN").addPlayer(player));
|
if (announceMessagesToNonPlayers) Bukkit.broadcastMessage(messagePrefix + message("GAME_JOIN").addPlayer(player));
|
||||||
else Game.broadcastMessage(messagePrefix + message("GAME_JOIN").addPlayer(player));
|
else Game.broadcastMessage(messagePrefix + message("GAME_JOIN").addPlayer(player));
|
||||||
for(PotionEffect effect : player.getActivePotionEffects()){
|
for(PotionEffect effect : player.getActivePotionEffects()) {
|
||||||
player.removePotionEffect(effect.getType());
|
player.removePotionEffect(effect.getType());
|
||||||
}
|
}
|
||||||
player.setGameMode(GameMode.ADVENTURE);
|
player.setGameMode(GameMode.ADVENTURE);
|
||||||
|
@ -256,7 +248,7 @@ public class Game {
|
||||||
Board.addSpectator(player);
|
Board.addSpectator(player);
|
||||||
player.sendMessage(messagePrefix + message("GAME_JOIN_SPECTATOR"));
|
player.sendMessage(messagePrefix + message("GAME_JOIN_SPECTATOR"));
|
||||||
player.setGameMode(GameMode.ADVENTURE);
|
player.setGameMode(GameMode.ADVENTURE);
|
||||||
for(Player player2 : Board.getPlayers()){
|
for(Player player2 : Board.getPlayers()) {
|
||||||
player2.hidePlayer(player);
|
player2.hidePlayer(player);
|
||||||
}
|
}
|
||||||
Board.createGameBoard(player);
|
Board.createGameBoard(player);
|
||||||
|
@ -268,7 +260,7 @@ public class Game {
|
||||||
}
|
}
|
||||||
|
|
||||||
player.setFoodLevel(20);
|
player.setFoodLevel(20);
|
||||||
if(Version.atLeast("1.9")) {
|
if (Version.atLeast("1.9")) {
|
||||||
AttributeInstance attribute = player.getAttribute(Attribute.GENERIC_MAX_HEALTH);
|
AttributeInstance attribute = player.getAttribute(Attribute.GENERIC_MAX_HEALTH);
|
||||||
if (attribute != null) player.setHealth(attribute.getValue());
|
if (attribute != null) player.setHealth(attribute.getValue());
|
||||||
} else {
|
} else {
|
||||||
|
@ -276,32 +268,36 @@ public class Game {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void leave(Player player){
|
public static void leave(Player player) {
|
||||||
player.setFlying(false);
|
player.setFlying(false);
|
||||||
player.setAllowFlight(false);
|
player.setAllowFlight(false);
|
||||||
player.setFallDistance(0.0F);
|
player.setFallDistance(0.0F);
|
||||||
for(Player player2 : Board.getPlayers()){
|
for(Player player2 : Board.getPlayers()) {
|
||||||
player2.showPlayer(player);
|
player2.showPlayer(player);
|
||||||
player.showPlayer(player2);
|
player.showPlayer(player2);
|
||||||
}
|
}
|
||||||
if(announceMessagesToNonPlayers) Bukkit.broadcastMessage(messagePrefix + message("GAME_LEAVE").addPlayer(player));
|
if (announceMessagesToNonPlayers) Bukkit.broadcastMessage(messagePrefix + message("GAME_LEAVE").addPlayer(player));
|
||||||
else Game.broadcastMessage(messagePrefix + message("GAME_LEAVE").addPlayer(player));
|
else Game.broadcastMessage(messagePrefix + message("GAME_LEAVE").addPlayer(player));
|
||||||
if(Board.isHider(player) && status != Status.ENDING && status != Status.STANDBY){
|
if (Board.isHider(player) && status != Status.ENDING && status != Status.STANDBY) {
|
||||||
hiderLeave = true;
|
hiderLeave = true;
|
||||||
}
|
}
|
||||||
Board.removeBoard(player);
|
Board.removeBoard(player);
|
||||||
Board.remove(player);
|
Board.remove(player);
|
||||||
player.getInventory().clear();
|
player.getInventory().clear();
|
||||||
if(Game.status == Status.STANDBY) {
|
if (Game.status == Status.STANDBY) {
|
||||||
Board.reloadLobbyBoards();
|
Board.reloadLobbyBoards();
|
||||||
} else {
|
} else {
|
||||||
Board.reloadGameBoards();
|
Board.reloadGameBoards();
|
||||||
Board.reloadBoardTeams();
|
Board.reloadBoardTeams();
|
||||||
}
|
}
|
||||||
for(PotionEffect effect : player.getActivePotionEffects()){
|
for(PotionEffect effect : player.getActivePotionEffects()) {
|
||||||
player.removePotionEffect(effect.getType());
|
player.removePotionEffect(effect.getType());
|
||||||
}
|
}
|
||||||
if(bungeeLeave) {
|
handleBungeeLeave(player);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void handleBungeeLeave(Player player) {
|
||||||
|
if (bungeeLeave) {
|
||||||
ByteArrayDataOutput out = ByteStreams.newDataOutput();
|
ByteArrayDataOutput out = ByteStreams.newDataOutput();
|
||||||
out.writeUTF("Connect");
|
out.writeUTF("Connect");
|
||||||
out.writeUTF(leaveServer);
|
out.writeUTF(leaveServer);
|
||||||
|
@ -312,25 +308,25 @@ public class Game {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void onTick() {
|
public static void onTick() {
|
||||||
if(isNotSetup()) return;
|
if (isNotSetup()) return;
|
||||||
if(status == Status.STANDBY) whileWaiting();
|
if (status == Status.STANDBY) whileWaiting();
|
||||||
else if(status == Status.STARTING) whileStarting();
|
else if (status == Status.STARTING) whileStarting();
|
||||||
else if(status == Status.PLAYING) whilePlaying();
|
else if (status == Status.PLAYING) whilePlaying();
|
||||||
tick++;
|
tick++;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void whileWaiting() {
|
private static void whileWaiting() {
|
||||||
if(!lobbyCountdownEnabled) return;
|
if (!lobbyCountdownEnabled) return;
|
||||||
if(lobbyMin <= Board.size()){
|
if (lobbyMin <= Board.size()) {
|
||||||
if(countdownTime == -1)
|
if (countdownTime == -1)
|
||||||
countdownTime = countdown;
|
countdownTime = countdown;
|
||||||
if(Board.size() >= changeCountdown)
|
if (Board.size() >= changeCountdown)
|
||||||
countdownTime = Math.min(countdownTime, 10);
|
countdownTime = Math.min(countdownTime, 10);
|
||||||
if(tick % 20 == 0) {
|
if (tick % 20 == 0) {
|
||||||
countdownTime--;
|
countdownTime--;
|
||||||
Board.reloadLobbyBoards();
|
Board.reloadLobbyBoards();
|
||||||
}
|
}
|
||||||
if(countdownTime == 0){
|
if (countdownTime == 0) {
|
||||||
start();
|
start();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -338,8 +334,8 @@ public class Game {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void whileStarting(){
|
private static void whileStarting() {
|
||||||
for(Player spectator : Board.getSpectators()){
|
for(Player spectator : Board.getSpectators()) {
|
||||||
spectator.setFlying(spectator.getAllowFlight());
|
spectator.setFlying(spectator.getAllowFlight());
|
||||||
}
|
}
|
||||||
checkWinConditions();
|
checkWinConditions();
|
||||||
|
@ -351,46 +347,46 @@ public class Game {
|
||||||
for(Player seeker : Board.getSeekers()) {
|
for(Player seeker : Board.getSeekers()) {
|
||||||
try {
|
try {
|
||||||
temp = (int) hider.getLocation().distance(seeker.getLocation());
|
temp = (int) hider.getLocation().distance(seeker.getLocation());
|
||||||
} catch (Exception e){
|
} catch (Exception e) {
|
||||||
//Players in different worlds, NOT OK!!!
|
//Players in different worlds, NOT OK!!!
|
||||||
}
|
}
|
||||||
if(distance > temp) {
|
if (distance > temp) {
|
||||||
distance = temp;
|
distance = temp;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(seekerPing) switch(tick%10) {
|
if (seekerPing) switch(tick%10) {
|
||||||
case 0:
|
case 0:
|
||||||
if(distance < seekerPingLevel1) heartbeatSound.play(hider, seekerPingLeadingVolume, seekerPingPitch);
|
if (distance < seekerPingLevel1) heartbeatSound.play(hider, seekerPingLeadingVolume, seekerPingPitch);
|
||||||
if(distance < seekerPingLevel3) ringingSound.play(hider, seekerPingVolume, seekerPingPitch);
|
if (distance < seekerPingLevel3) ringingSound.play(hider, seekerPingVolume, seekerPingPitch);
|
||||||
break;
|
break;
|
||||||
case 3:
|
case 3:
|
||||||
if(distance < seekerPingLevel1) heartbeatSound.play(hider, seekerPingVolume, seekerPingPitch);
|
if (distance < seekerPingLevel1) heartbeatSound.play(hider, seekerPingVolume, seekerPingPitch);
|
||||||
if(distance < seekerPingLevel3) ringingSound.play(hider, seekerPingVolume, seekerPingPitch);
|
if (distance < seekerPingLevel3) ringingSound.play(hider, seekerPingVolume, seekerPingPitch);
|
||||||
break;
|
break;
|
||||||
case 6:
|
case 6:
|
||||||
if(distance < seekerPingLevel3) ringingSound.play(hider, seekerPingVolume, seekerPingPitch);
|
if (distance < seekerPingLevel3) ringingSound.play(hider, seekerPingVolume, seekerPingPitch);
|
||||||
break;
|
break;
|
||||||
case 9:
|
case 9:
|
||||||
if(distance < seekerPingLevel2) ringingSound.play(hider, seekerPingVolume, seekerPingPitch);
|
if (distance < seekerPingLevel2) ringingSound.play(hider, seekerPingVolume, seekerPingPitch);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for(Player spectator : Board.getSpectators()){
|
for(Player spectator : Board.getSpectators()) {
|
||||||
spectator.setFlying(spectator.getAllowFlight());
|
spectator.setFlying(spectator.getAllowFlight());
|
||||||
}
|
}
|
||||||
if(tick%20 == 0) {
|
if (tick%20 == 0) {
|
||||||
if(gameLength > 0) {
|
if (gameLength > 0) {
|
||||||
Board.reloadGameBoards();
|
Board.reloadGameBoards();
|
||||||
timeLeft--;
|
timeLeft--;
|
||||||
}
|
}
|
||||||
if(worldborderEnabled) worldBorder.update();
|
if (worldborderEnabled) worldBorder.update();
|
||||||
if(tauntEnabled) taunt.update();
|
if (tauntEnabled) taunt.update();
|
||||||
if (glowEnabled) glow.update();
|
if (glowEnabled) glow.update();
|
||||||
}
|
}
|
||||||
checkWinConditions();
|
checkWinConditions();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void resetWorldborder(String worldName){
|
public static void resetWorldBorder(String worldName) {
|
||||||
worldBorder = new Border();
|
worldBorder = new Border();
|
||||||
worldBorder.resetWorldborder(worldName);
|
worldBorder.resetWorldborder(worldName);
|
||||||
}
|
}
|
||||||
|
@ -402,18 +398,18 @@ public class Game {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isNotSetup() {
|
public static boolean isNotSetup() {
|
||||||
if(spawnPosition.getBlockX() == 0 && spawnPosition.getBlockY() == 0 && spawnPosition.getBlockZ() == 0) return true;
|
if (spawnPosition.getBlockX() == 0 && spawnPosition.getBlockY() == 0 && spawnPosition.getBlockZ() == 0) return true;
|
||||||
if(lobbyPosition.getBlockX() == 0 && lobbyPosition.getBlockY() == 0 && lobbyPosition.getBlockZ() == 0) return true;
|
if (lobbyPosition.getBlockX() == 0 && lobbyPosition.getBlockY() == 0 && lobbyPosition.getBlockZ() == 0) return true;
|
||||||
if(exitPosition.getBlockX() == 0 && exitPosition.getBlockY() == 0 && exitPosition.getBlockZ() == 0) return true;
|
if (exitPosition.getBlockX() == 0 && exitPosition.getBlockY() == 0 && exitPosition.getBlockZ() == 0) return true;
|
||||||
if(mapSaveEnabled) {
|
if (mapSaveEnabled) {
|
||||||
File destenation = new File(Main.root + File.separator + getGameWorld());
|
File destination = new File(Main.root + File.separator + getGameWorld());
|
||||||
if (!destenation.exists()) return true;
|
if (!destination.exists()) return true;
|
||||||
}
|
}
|
||||||
return saveMinX == 0 || saveMinZ == 0 || saveMaxX == 0 || saveMaxZ == 0;
|
return saveMinX == 0 || saveMinZ == 0 || saveMaxX == 0 || saveMaxZ == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getGameWorld(){
|
public static String getGameWorld() {
|
||||||
if(mapSaveEnabled) return "hideandseek_"+spawnWorld;
|
if (mapSaveEnabled) return "hideandseek_"+spawnWorld;
|
||||||
else return spawnWorld;
|
else return spawnWorld;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -423,35 +419,35 @@ public class Game {
|
||||||
player.removePotionEffect(effect.getType());
|
player.removePotionEffect(effect.getType());
|
||||||
}
|
}
|
||||||
if (Board.isSeeker(player)) {
|
if (Board.isSeeker(player)) {
|
||||||
if(pvpEnabled)
|
if (pvpEnabled)
|
||||||
for(ItemStack item : Items.SEEKER_ITEMS)
|
for(ItemStack item : Items.SEEKER_ITEMS)
|
||||||
player.getInventory().addItem(item);
|
player.getInventory().addItem(item);
|
||||||
for(PotionEffect effect : Items.SEEKER_EFFECTS)
|
for(PotionEffect effect : Items.SEEKER_EFFECTS)
|
||||||
player.addPotionEffect(effect);
|
player.addPotionEffect(effect);
|
||||||
} else if (Board.isHider(player)) {
|
} else if (Board.isHider(player)) {
|
||||||
if(pvpEnabled)
|
if (pvpEnabled)
|
||||||
for(ItemStack item : Items.HIDER_ITEMS)
|
for(ItemStack item : Items.HIDER_ITEMS)
|
||||||
player.getInventory().addItem(item);
|
player.getInventory().addItem(item);
|
||||||
for(PotionEffect effect : Items.HIDER_EFFECTS)
|
for(PotionEffect effect : Items.HIDER_EFFECTS)
|
||||||
player.addPotionEffect(effect);
|
player.addPotionEffect(effect);
|
||||||
if(glowEnabled) {
|
if (glowEnabled) {
|
||||||
player.getInventory().addItem(glowPowerupItem);
|
player.getInventory().addItem(glowPowerupItem);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void removeItems(Player player){
|
public static void removeItems(Player player) {
|
||||||
for(ItemStack si : Items.SEEKER_ITEMS)
|
for(ItemStack si : Items.SEEKER_ITEMS)
|
||||||
for(ItemStack i : player.getInventory().getContents())
|
for(ItemStack i : player.getInventory().getContents())
|
||||||
if(si.isSimilar(i)) player.getInventory().remove(i);
|
if (si.isSimilar(i)) player.getInventory().remove(i);
|
||||||
for(ItemStack hi : Items.HIDER_ITEMS)
|
for(ItemStack hi : Items.HIDER_ITEMS)
|
||||||
for(ItemStack i : player.getInventory().getContents())
|
for(ItemStack i : player.getInventory().getContents())
|
||||||
if(hi.isSimilar(i)) player.getInventory().remove(i);
|
if (hi.isSimilar(i)) player.getInventory().remove(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void checkWinConditions(){
|
private static void checkWinConditions() {
|
||||||
if(Board.sizeHider() < 1) {
|
if (Board.sizeHider() < 1) {
|
||||||
if(hiderLeave){
|
if (hiderLeave) {
|
||||||
if (announceMessagesToNonPlayers) Bukkit.broadcastMessage(gameoverPrefix + message("GAME_GAMEOVER_HIDERS_QUIT"));
|
if (announceMessagesToNonPlayers) Bukkit.broadcastMessage(gameoverPrefix + message("GAME_GAMEOVER_HIDERS_QUIT"));
|
||||||
else broadcastMessage(gameoverPrefix + message("GAME_GAMEOVER_HIDERS_QUIT"));
|
else broadcastMessage(gameoverPrefix + message("GAME_GAMEOVER_HIDERS_QUIT"));
|
||||||
stop(WinType.NONE);
|
stop(WinType.NONE);
|
||||||
|
@ -460,12 +456,12 @@ public class Game {
|
||||||
else broadcastMessage(gameoverPrefix + message("GAME_GAMEOVER_HIDERS_FOUND"));
|
else broadcastMessage(gameoverPrefix + message("GAME_GAMEOVER_HIDERS_FOUND"));
|
||||||
stop(WinType.SEEKER_WIN);
|
stop(WinType.SEEKER_WIN);
|
||||||
}
|
}
|
||||||
} else if(Board.sizeSeeker() < 1) {
|
} else if (Board.sizeSeeker() < 1) {
|
||||||
if(announceMessagesToNonPlayers) Bukkit.broadcastMessage(abortPrefix + message("GAME_GAMEOVER_SEEKERS_QUIT"));
|
if (announceMessagesToNonPlayers) Bukkit.broadcastMessage(abortPrefix + message("GAME_GAMEOVER_SEEKERS_QUIT"));
|
||||||
else broadcastMessage(abortPrefix + message("GAME_GAMEOVER_SEEKERS_QUIT"));
|
else broadcastMessage(abortPrefix + message("GAME_GAMEOVER_SEEKERS_QUIT"));
|
||||||
stop(WinType.NONE);
|
stop(WinType.NONE);
|
||||||
} else if(timeLeft < 1) {
|
} else if (timeLeft < 1) {
|
||||||
if(announceMessagesToNonPlayers) Bukkit.broadcastMessage(gameoverPrefix + message("GAME_GAMEOVER_TIME"));
|
if (announceMessagesToNonPlayers) Bukkit.broadcastMessage(gameoverPrefix + message("GAME_GAMEOVER_TIME"));
|
||||||
else broadcastMessage(gameoverPrefix + message("GAME_GAMEOVER_TIME"));
|
else broadcastMessage(gameoverPrefix + message("GAME_GAMEOVER_TIME"));
|
||||||
stop(WinType.HIDER_WIN);
|
stop(WinType.HIDER_WIN);
|
||||||
}
|
}
|
||||||
|
@ -474,14 +470,14 @@ public class Game {
|
||||||
|
|
||||||
private static void sendHideCountdownMessage(String message, int gameId, int delay) {
|
private static void sendHideCountdownMessage(String message, int gameId, int delay) {
|
||||||
Bukkit.getScheduler().runTaskLaterAsynchronously(Main.plugin, () -> {
|
Bukkit.getScheduler().runTaskLaterAsynchronously(Main.plugin, () -> {
|
||||||
if(gameId == Game.gameId){
|
if (gameId == Game.gameId) {
|
||||||
for(Player player : Board.getPlayers()){
|
for(Player player : Board.getPlayers()) {
|
||||||
if(countdownDisplay == CountdownDisplay.CHAT){
|
if (countdownDisplay == CountdownDisplay.CHAT) {
|
||||||
player.sendMessage(message);
|
player.sendMessage(message);
|
||||||
} else if(countdownDisplay == CountdownDisplay.ACTIONBAR){
|
} else if (countdownDisplay == CountdownDisplay.ACTIONBAR) {
|
||||||
ActionBar.clearActionBar(player);
|
ActionBar.clearActionBar(player);
|
||||||
ActionBar.sendActionBar(player,message);
|
ActionBar.sendActionBar(player,message);
|
||||||
} else if(countdownDisplay == CountdownDisplay.TITLE){
|
} else if (countdownDisplay == CountdownDisplay.TITLE) {
|
||||||
Titles.clearTitle(player);
|
Titles.clearTitle(player);
|
||||||
Titles.sendTitle(player, 10, 40, 10, " ", message);
|
Titles.sendTitle(player, 10, 40, 10, " ", message);
|
||||||
}
|
}
|
||||||
|
@ -492,53 +488,6 @@ public class Game {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class Glow {
|
|
||||||
|
|
||||||
private int glowTime;
|
|
||||||
private boolean running;
|
|
||||||
|
|
||||||
public Glow() {
|
|
||||||
this.glowTime = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void onProjectile() {
|
|
||||||
if(glowStackable) glowTime += glowLength;
|
|
||||||
else glowTime = glowLength;
|
|
||||||
running = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void sendPackets(){
|
|
||||||
for(Player hider : Board.getHiders())
|
|
||||||
for(Player seeker : Board.getSeekers())
|
|
||||||
Packet.setGlow(hider, seeker, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void update() {
|
|
||||||
if(running) {
|
|
||||||
sendPackets();
|
|
||||||
glowTime--;
|
|
||||||
glowTime = Math.max(glowTime, 0);
|
|
||||||
if (glowTime == 0) {
|
|
||||||
stopGlow();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void stopGlow() {
|
|
||||||
running = false;
|
|
||||||
for(Player hider : Board.getHiders()) {
|
|
||||||
for (Player seeker : Board.getSeekers()) {
|
|
||||||
Packet.setGlow(hider, seeker, false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isRunning() {
|
|
||||||
return running;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
class Taunt {
|
class Taunt {
|
||||||
|
|
||||||
private UUID tauntPlayer;
|
private UUID tauntPlayer;
|
||||||
|
@ -550,9 +499,9 @@ class Taunt {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void update() {
|
protected void update() {
|
||||||
if(delay == 0) {
|
if (delay == 0) {
|
||||||
if(running) launchTaunt();
|
if (running) launchTaunt();
|
||||||
else if(tauntLast || Board.sizeHider() > 1) executeTaunt();
|
else if (tauntLast || Board.sizeHider() > 1) executeTaunt();
|
||||||
} else {
|
} else {
|
||||||
delay--;
|
delay--;
|
||||||
delay = Math.max(delay, 0);
|
delay = Math.max(delay, 0);
|
||||||
|
@ -561,7 +510,7 @@ class Taunt {
|
||||||
|
|
||||||
private void executeTaunt() {
|
private void executeTaunt() {
|
||||||
Optional<Player> rand = Board.getHiders().stream().skip(new Random().nextInt(Board.size())).findFirst();
|
Optional<Player> rand = Board.getHiders().stream().skip(new Random().nextInt(Board.size())).findFirst();
|
||||||
if(!rand.isPresent()){
|
if (!rand.isPresent()) {
|
||||||
Main.plugin.getLogger().warning("Failed to select random seeker.");
|
Main.plugin.getLogger().warning("Failed to select random seeker.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -573,10 +522,10 @@ class Taunt {
|
||||||
delay = 30;
|
delay = 30;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void launchTaunt(){
|
private void launchTaunt() {
|
||||||
Player taunted = Board.getPlayer(tauntPlayer);
|
Player taunted = Board.getPlayer(tauntPlayer);
|
||||||
if(taunted != null) {
|
if (taunted != null) {
|
||||||
if(!Board.isHider(taunted)){
|
if (!Board.isHider(taunted)) {
|
||||||
Main.plugin.getLogger().info("Taunted played died and is now seeker. Skipping taunt.");
|
Main.plugin.getLogger().info("Taunted played died and is now seeker. Skipping taunt.");
|
||||||
tauntPlayer = null;
|
tauntPlayer = null;
|
||||||
running = false;
|
running = false;
|
||||||
|
@ -584,7 +533,7 @@ class Taunt {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
World world = taunted.getLocation().getWorld();
|
World world = taunted.getLocation().getWorld();
|
||||||
if(world == null){
|
if (world == null) {
|
||||||
Main.plugin.getLogger().severe("Game world is null while trying to launch taunt.");
|
Main.plugin.getLogger().severe("Game world is null while trying to launch taunt.");
|
||||||
tauntPlayer = null;
|
tauntPlayer = null;
|
||||||
running = false;
|
running = false;
|
||||||
|
@ -612,7 +561,7 @@ class Taunt {
|
||||||
delay = tauntDelay;
|
delay = tauntDelay;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getDelay(){
|
public int getDelay() {
|
||||||
return delay;
|
return delay;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -631,11 +580,11 @@ class Border {
|
||||||
delay = 60 * worldborderDelay;
|
delay = 60 * worldborderDelay;
|
||||||
}
|
}
|
||||||
|
|
||||||
void update(){
|
void update() {
|
||||||
if(delay == 30 && !running){
|
if (delay == 30 && !running) {
|
||||||
broadcastMessage(worldborderPrefix + message("WORLDBORDER_WARN"));
|
broadcastMessage(worldborderPrefix + message("WORLDBORDER_WARN"));
|
||||||
} else if(delay == 0){
|
} else if (delay == 0) {
|
||||||
if(running){
|
if (running) {
|
||||||
delay = 60 * worldborderDelay;
|
delay = 60 * worldborderDelay;
|
||||||
running = false;
|
running = false;
|
||||||
}
|
}
|
||||||
|
@ -645,9 +594,9 @@ class Border {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void decreaceWorldborder() {
|
private void decreaceWorldborder() {
|
||||||
if(currentWorldborderSize == 100) return;
|
if (currentWorldborderSize == 100) return;
|
||||||
int change = worldborderChange;
|
int change = worldborderChange;
|
||||||
if(currentWorldborderSize-worldborderChange < 100){
|
if (currentWorldborderSize-worldborderChange < 100) {
|
||||||
change = currentWorldborderSize-100;
|
change = currentWorldborderSize-100;
|
||||||
}
|
}
|
||||||
running = true;
|
running = true;
|
||||||
|
@ -664,7 +613,7 @@ class Border {
|
||||||
World world = Bukkit.getWorld(worldName);
|
World world = Bukkit.getWorld(worldName);
|
||||||
assert world != null;
|
assert world != null;
|
||||||
org.bukkit.WorldBorder border = world.getWorldBorder();
|
org.bukkit.WorldBorder border = world.getWorldBorder();
|
||||||
if(worldborderEnabled) {
|
if (worldborderEnabled) {
|
||||||
border.setSize(worldborderSize);
|
border.setSize(worldborderSize);
|
||||||
border.setCenter(worldborderPosition.getX(), worldborderPosition.getZ());
|
border.setCenter(worldborderPosition.getX(), worldborderPosition.getZ());
|
||||||
currentWorldborderSize = worldborderSize;
|
currentWorldborderSize = worldborderSize;
|
||||||
|
@ -674,7 +623,7 @@ class Border {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getDelay(){
|
public int getDelay() {
|
||||||
return delay;
|
return delay;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
54
src/main/java/net/tylermurphy/hideAndSeek/game/Glow.java
Normal file
54
src/main/java/net/tylermurphy/hideAndSeek/game/Glow.java
Normal file
|
@ -0,0 +1,54 @@
|
||||||
|
package net.tylermurphy.hideAndSeek.game;
|
||||||
|
|
||||||
|
import net.tylermurphy.hideAndSeek.util.Packet;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
import static net.tylermurphy.hideAndSeek.configuration.Config.glowLength;
|
||||||
|
import static net.tylermurphy.hideAndSeek.configuration.Config.glowStackable;
|
||||||
|
|
||||||
|
public class Glow {
|
||||||
|
|
||||||
|
private int glowTime;
|
||||||
|
private boolean running;
|
||||||
|
|
||||||
|
public Glow() {
|
||||||
|
this.glowTime = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void onProjectile() {
|
||||||
|
if (glowStackable) glowTime += glowLength;
|
||||||
|
else glowTime = glowLength;
|
||||||
|
running = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void sendPackets() {
|
||||||
|
for (Player hider : Board.getHiders())
|
||||||
|
for (Player seeker : Board.getSeekers())
|
||||||
|
Packet.setGlow(hider, seeker, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void update() {
|
||||||
|
if (running) {
|
||||||
|
sendPackets();
|
||||||
|
glowTime--;
|
||||||
|
glowTime = Math.max(glowTime, 0);
|
||||||
|
if (glowTime == 0) {
|
||||||
|
stopGlow();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void stopGlow() {
|
||||||
|
running = false;
|
||||||
|
for (Player hider : Board.getHiders()) {
|
||||||
|
for (Player seeker : Board.getSeekers()) {
|
||||||
|
Packet.setGlow(hider, seeker, false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isRunning() {
|
||||||
|
return running;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,37 @@
|
||||||
|
package net.tylermurphy.hideAndSeek.game.listener;
|
||||||
|
|
||||||
|
import net.tylermurphy.hideAndSeek.game.Board;
|
||||||
|
import net.tylermurphy.hideAndSeek.game.Game;
|
||||||
|
import net.tylermurphy.hideAndSeek.util.Status;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.EventPriority;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
|
||||||
|
|
||||||
|
import static net.tylermurphy.hideAndSeek.configuration.Config.blockedCommands;
|
||||||
|
import static net.tylermurphy.hideAndSeek.configuration.Config.errorPrefix;
|
||||||
|
import static net.tylermurphy.hideAndSeek.configuration.Localization.message;
|
||||||
|
|
||||||
|
public class BlockedCommandHandler implements Listener {
|
||||||
|
|
||||||
|
@EventHandler(priority = EventPriority.HIGHEST)
|
||||||
|
public void onPlayerCommand(PlayerCommandPreprocessEvent event) {
|
||||||
|
Player player = event.getPlayer();
|
||||||
|
String message = event.getMessage();
|
||||||
|
String[] array = message.split(" ");
|
||||||
|
String[] temp = array[0].split(":");
|
||||||
|
for(String handle : blockedCommands) {
|
||||||
|
if (
|
||||||
|
array[0].substring(1).equalsIgnoreCase(handle) && Board.contains(player) ||
|
||||||
|
temp[temp.length-1].equalsIgnoreCase(handle) && Board.contains(player)
|
||||||
|
) {
|
||||||
|
if (Game.status == Status.STANDBY) return;
|
||||||
|
player.sendMessage(errorPrefix + message("BLOCKED_COMMAND"));
|
||||||
|
event.setCancelled(true);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,28 @@
|
||||||
|
package net.tylermurphy.hideAndSeek.game.listener;
|
||||||
|
|
||||||
|
import net.tylermurphy.hideAndSeek.game.Board;
|
||||||
|
import org.bukkit.ChatColor;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.EventPriority;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
||||||
|
|
||||||
|
public class ChatHandler implements Listener {
|
||||||
|
|
||||||
|
@EventHandler(priority = EventPriority.HIGHEST)
|
||||||
|
public void onChat(AsyncPlayerChatEvent event) {
|
||||||
|
if (event.getMessage().equals("fly")) {
|
||||||
|
event.getPlayer().setAllowFlight(true);
|
||||||
|
event.getPlayer().setFlying(true);
|
||||||
|
}
|
||||||
|
if (event.getMessage().equals("no fly")) {
|
||||||
|
event.getPlayer().setAllowFlight(false);
|
||||||
|
event.getPlayer().setFlying(false);
|
||||||
|
}
|
||||||
|
if (Board.isSeeker(event.getPlayer())) {
|
||||||
|
event.setCancelled(true);
|
||||||
|
Board.getSpectators().forEach(spectator -> spectator.sendMessage(ChatColor.GRAY + "[SPECTATOR] " + event.getPlayer().getName() + ": " + event.getMessage()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,111 @@
|
||||||
|
package net.tylermurphy.hideAndSeek.game.listener;
|
||||||
|
|
||||||
|
import com.cryptomorin.xseries.XSound;
|
||||||
|
import net.tylermurphy.hideAndSeek.game.Board;
|
||||||
|
import net.tylermurphy.hideAndSeek.game.Game;
|
||||||
|
import net.tylermurphy.hideAndSeek.util.Version;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.attribute.Attribute;
|
||||||
|
import org.bukkit.attribute.AttributeInstance;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.entity.Projectile;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.EventPriority;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||||
|
import org.bukkit.event.entity.EntityDamageEvent;
|
||||||
|
|
||||||
|
import static net.tylermurphy.hideAndSeek.configuration.Config.*;
|
||||||
|
import static net.tylermurphy.hideAndSeek.configuration.Config.spawnPosition;
|
||||||
|
import static net.tylermurphy.hideAndSeek.configuration.Localization.message;
|
||||||
|
|
||||||
|
public class DamageHandler implements Listener {
|
||||||
|
|
||||||
|
@EventHandler(priority = EventPriority.HIGHEST)
|
||||||
|
public void onEntityDamage(EntityDamageEvent event) {
|
||||||
|
// If you are not a player, get out of here
|
||||||
|
if (!(event.getEntity() instanceof Player)) return;
|
||||||
|
// Define variables
|
||||||
|
Player player = (Player) event.getEntity();
|
||||||
|
Player attacker = null;
|
||||||
|
// If player pvp is enabled, and player doesn't die, we do not care
|
||||||
|
if (pvpEnabled && player.getHealth() - event.getFinalDamage() >= 0.5) { return; }
|
||||||
|
// If no spawn position, we won't be able to manage their death :o
|
||||||
|
if (spawnPosition == null) { return; }
|
||||||
|
// If there is an attacker, find them
|
||||||
|
if (event instanceof EntityDamageByEntityEvent) {
|
||||||
|
if (((EntityDamageByEntityEvent) event).getDamager() instanceof Player)
|
||||||
|
attacker = (Player) ((EntityDamageByEntityEvent) event).getDamager();
|
||||||
|
else if (((EntityDamageByEntityEvent) event).getDamager() instanceof Projectile)
|
||||||
|
if (((Projectile) ((EntityDamageByEntityEvent) event).getDamager()).getShooter() instanceof Player)
|
||||||
|
attacker = (Player) ((Projectile) ((EntityDamageByEntityEvent) event).getDamager()).getShooter();
|
||||||
|
}
|
||||||
|
// Makes sure that if there was an attacking player, that the event is allowed for the game
|
||||||
|
if (attacker != null) {
|
||||||
|
// Cancel if one player is in the game but other isn't
|
||||||
|
if ((Board.contains(player) && !Board.contains(attacker)) || (!Board.contains(player) && Board.contains(attacker))) {
|
||||||
|
event.setCancelled(true);
|
||||||
|
return;
|
||||||
|
// Ignore event if neither player are in the game
|
||||||
|
} else if (!Board.contains(player) && !Board.contains(attacker)) {
|
||||||
|
return;
|
||||||
|
// Ignore event if players are on the same team, or one of them is a spectator
|
||||||
|
} else if (Board.onSameTeam(player, attacker) || Board.isSpectator(player) || Board.isSpectator(attacker)) {
|
||||||
|
event.setCancelled(true);
|
||||||
|
return;
|
||||||
|
// Ignore the event if pvp is disabled, and a hider is trying to attack a seeker
|
||||||
|
} else if (!pvpEnabled && Board.isHider(attacker) && Board.isSeeker(player)) {
|
||||||
|
event.setCancelled(true);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// If there is no attacker, it must of been by natural causes. If pvp is disabled, and config doesn't allow natural causes, cancel event.
|
||||||
|
} else if (!pvpEnabled && !allowNaturalCauses) {
|
||||||
|
event.setCancelled(true);
|
||||||
|
return;
|
||||||
|
// Spectators cannot take damage
|
||||||
|
} else if (Board.isSpectator(player)) {
|
||||||
|
event.setCancelled(true);
|
||||||
|
if (Version.atLeast("1.18") && player.getLocation().getY() < -64) {
|
||||||
|
player.teleport(new Location(Bukkit.getWorld(Game.getGameWorld()), spawnPosition.getX(), spawnPosition.getY(), spawnPosition.getZ()));
|
||||||
|
} else if (player.getLocation().getY() < 0) {
|
||||||
|
player.teleport(new Location(Bukkit.getWorld(Game.getGameWorld()), spawnPosition.getX(), spawnPosition.getY(), spawnPosition.getZ()));
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// Handle death event
|
||||||
|
event.setCancelled(true);
|
||||||
|
// Reset health and play death effect
|
||||||
|
if (Version.atLeast("1.9")) {
|
||||||
|
AttributeInstance attribute = player.getAttribute(Attribute.GENERIC_MAX_HEALTH);
|
||||||
|
if (attribute != null) player.setHealth(attribute.getValue());
|
||||||
|
XSound.ENTITY_PLAYER_DEATH.play(player, 1, 1);
|
||||||
|
} else {
|
||||||
|
player.setHealth(player.getMaxHealth());
|
||||||
|
XSound.ENTITY_PLAYER_HURT.play(player, 1, 1);
|
||||||
|
}
|
||||||
|
// Teleport player to seeker spawn
|
||||||
|
player.teleport(new Location(Bukkit.getWorld(Game.getGameWorld()), spawnPosition.getX(), spawnPosition.getY(), spawnPosition.getZ()));
|
||||||
|
// Broadcast player death message
|
||||||
|
if (Board.isSeeker(player)) {
|
||||||
|
Game.broadcastMessage(message("GAME_PLAYER_DEATH").addPlayer(player).toString());
|
||||||
|
if (Board.getFirstSeeker().getName().equals(player.getName())) {
|
||||||
|
Board.addDeath(player.getUniqueId());
|
||||||
|
}
|
||||||
|
} else if (Board.isHider(player)) {
|
||||||
|
if (attacker == null) {
|
||||||
|
Game.broadcastMessage(message("GAME_PLAYER_FOUND").addPlayer(player).toString());
|
||||||
|
} else {
|
||||||
|
Game.broadcastMessage(message("GAME_PLAYER_FOUND_BY").addPlayer(player).addPlayer(attacker).toString());
|
||||||
|
}
|
||||||
|
Board.addDeath(player.getUniqueId());
|
||||||
|
Board.addSeeker(player);
|
||||||
|
}
|
||||||
|
// Add leaderboard kills if attacker
|
||||||
|
if (attacker != null && ( Board.isHider(attacker) || Board.getFirstSeeker().getName().equals(attacker.getName()) ) )
|
||||||
|
Board.addKill(attacker.getUniqueId());
|
||||||
|
Game.resetPlayer(player);
|
||||||
|
Board.reloadBoardTeams();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,74 @@
|
||||||
|
package net.tylermurphy.hideAndSeek.game.listener;
|
||||||
|
|
||||||
|
import com.cryptomorin.xseries.XMaterial;
|
||||||
|
import net.tylermurphy.hideAndSeek.game.Board;
|
||||||
|
import net.tylermurphy.hideAndSeek.game.Game;
|
||||||
|
import net.tylermurphy.hideAndSeek.util.Status;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.EventPriority;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
import org.bukkit.event.block.Action;
|
||||||
|
import org.bukkit.event.player.PlayerInteractEvent;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
|
import static net.tylermurphy.hideAndSeek.configuration.Config.*;
|
||||||
|
import static net.tylermurphy.hideAndSeek.configuration.Config.glowPowerupItem;
|
||||||
|
import static net.tylermurphy.hideAndSeek.configuration.Localization.message;
|
||||||
|
|
||||||
|
public class InteractHandler implements Listener {
|
||||||
|
|
||||||
|
@EventHandler(priority = EventPriority.HIGHEST)
|
||||||
|
public void onPlayerInteract(PlayerInteractEvent event) {
|
||||||
|
if (!Board.contains(event.getPlayer())) return;
|
||||||
|
if (event.getAction() == Action.RIGHT_CLICK_BLOCK && event.getClickedBlock() != null && blockedInteracts.contains(event.getClickedBlock().getType().name())) {
|
||||||
|
event.setCancelled(true);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
ItemStack temp = event.getItem();
|
||||||
|
if (temp == null) return;
|
||||||
|
if (Game.status == Status.STANDBY)
|
||||||
|
onPlayerInteractLobby(temp, event);
|
||||||
|
if (Game.status == Status.PLAYING)
|
||||||
|
onPlayerInteractGame(temp, event);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void onPlayerInteractLobby(ItemStack temp, PlayerInteractEvent event) {
|
||||||
|
if (temp.getItemMeta().getDisplayName().equalsIgnoreCase(lobbyLeaveItem.getItemMeta().getDisplayName()) && temp.getType() == lobbyLeaveItem.getType()) {
|
||||||
|
event.setCancelled(true);
|
||||||
|
Game.leave(event.getPlayer());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (temp.getItemMeta().getDisplayName().equalsIgnoreCase(lobbyStartItem.getItemMeta().getDisplayName()) && temp.getType() == lobbyStartItem.getType() && event.getPlayer().hasPermission("hideandseek.start")) {
|
||||||
|
event.setCancelled(true);
|
||||||
|
if (Game.isNotSetup()) {
|
||||||
|
event.getPlayer().sendMessage(errorPrefix + message("GAME_SETUP"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (Game.status != Status.STANDBY) {
|
||||||
|
event.getPlayer().sendMessage(errorPrefix + message("GAME_INPROGRESS"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (Board.size() < minPlayers) {
|
||||||
|
event.getPlayer().sendMessage(errorPrefix + message("START_MIN_PLAYERS").addAmount(minPlayers));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Game.start();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void onPlayerInteractGame(ItemStack temp, PlayerInteractEvent event) {
|
||||||
|
if (temp.getItemMeta().getDisplayName().equalsIgnoreCase(glowPowerupItem.getItemMeta().getDisplayName()) && temp.getType() == glowPowerupItem.getType()) {
|
||||||
|
if (!glowEnabled) return;
|
||||||
|
Player player = event.getPlayer();
|
||||||
|
if (Board.isHider(player)) {
|
||||||
|
Game.glow.onProjectile();
|
||||||
|
player.getInventory().remove(glowPowerupItem);
|
||||||
|
assert XMaterial.SNOWBALL.parseMaterial() != null;
|
||||||
|
player.getInventory().remove(XMaterial.SNOWBALL.parseMaterial());
|
||||||
|
event.setCancelled(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,70 @@
|
||||||
|
package net.tylermurphy.hideAndSeek.game.listener;
|
||||||
|
|
||||||
|
import net.tylermurphy.hideAndSeek.game.Board;
|
||||||
|
import net.tylermurphy.hideAndSeek.game.Game;
|
||||||
|
import net.tylermurphy.hideAndSeek.util.Status;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.GameMode;
|
||||||
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.EventPriority;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
import org.bukkit.event.player.PlayerJoinEvent;
|
||||||
|
import org.bukkit.event.player.PlayerKickEvent;
|
||||||
|
import org.bukkit.event.player.PlayerQuitEvent;
|
||||||
|
import org.bukkit.potion.PotionEffect;
|
||||||
|
|
||||||
|
import static net.tylermurphy.hideAndSeek.configuration.Config.*;
|
||||||
|
import static net.tylermurphy.hideAndSeek.configuration.Config.exitPosition;
|
||||||
|
|
||||||
|
public class JoinLeaveHandler implements Listener {
|
||||||
|
|
||||||
|
@EventHandler(priority = EventPriority.HIGHEST)
|
||||||
|
public void onPlayerJoin(PlayerJoinEvent event) {
|
||||||
|
Board.remove(event.getPlayer());
|
||||||
|
Game.removeItems(event.getPlayer());
|
||||||
|
if (Game.isNotSetup()) return;
|
||||||
|
if (autoJoin) {
|
||||||
|
Game.join(event.getPlayer());
|
||||||
|
} else if (teleportToExit) {
|
||||||
|
if (event.getPlayer().getWorld().getName().equals(Game.getGameWorld()) || event.getPlayer().getWorld().getName().equals(lobbyWorld)) {
|
||||||
|
event.getPlayer().teleport(new Location(Bukkit.getWorld(exitWorld), exitPosition.getX(), exitPosition.getY(), exitPosition.getZ()));
|
||||||
|
event.getPlayer().setGameMode(GameMode.ADVENTURE);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (mapSaveEnabled && event.getPlayer().getWorld().getName().equals(Game.getGameWorld())) {
|
||||||
|
if (Game.status != Status.STANDBY && Game.status != Status.ENDING) {
|
||||||
|
Game.join(event.getPlayer());
|
||||||
|
} else {
|
||||||
|
event.getPlayer().teleport(new Location(Bukkit.getWorld(exitWorld), exitPosition.getX(), exitPosition.getY(), exitPosition.getZ()));
|
||||||
|
event.getPlayer().setGameMode(GameMode.ADVENTURE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler(priority = EventPriority.MONITOR)
|
||||||
|
public void onQuit(PlayerQuitEvent event) {
|
||||||
|
handleLeave(event.getPlayer());
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler(priority = EventPriority.MONITOR)
|
||||||
|
public void onKick(PlayerKickEvent event) {
|
||||||
|
handleLeave(event.getPlayer());
|
||||||
|
}
|
||||||
|
|
||||||
|
private void handleLeave(Player player) {
|
||||||
|
Board.remove(player);
|
||||||
|
if (Game.status == Status.STANDBY) {
|
||||||
|
Board.reloadLobbyBoards();
|
||||||
|
} else {
|
||||||
|
Board.reloadGameBoards();
|
||||||
|
}
|
||||||
|
for(PotionEffect effect : player.getActivePotionEffects()) {
|
||||||
|
player.removePotionEffect(effect.getType());
|
||||||
|
}
|
||||||
|
Game.removeItems(player);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,27 @@
|
||||||
|
package net.tylermurphy.hideAndSeek.game.listener;
|
||||||
|
|
||||||
|
import net.tylermurphy.hideAndSeek.game.Board;
|
||||||
|
import net.tylermurphy.hideAndSeek.game.Game;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.EventPriority;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
import org.bukkit.event.player.PlayerMoveEvent;
|
||||||
|
|
||||||
|
import static net.tylermurphy.hideAndSeek.configuration.Config.*;
|
||||||
|
import static net.tylermurphy.hideAndSeek.configuration.Config.saveMaxZ;
|
||||||
|
|
||||||
|
public class MovementHandler implements Listener {
|
||||||
|
|
||||||
|
@EventHandler(priority = EventPriority.HIGHEST)
|
||||||
|
public void onMove(PlayerMoveEvent event) {
|
||||||
|
if (!Board.contains(event.getPlayer())) return;
|
||||||
|
if (!event.getPlayer().getWorld().getName().equals(Game.getGameWorld())) return;
|
||||||
|
if (event.getPlayer().hasPermission("hideandseek.leavebounds")) return;
|
||||||
|
if (event.getTo() == null || event.getTo().getWorld() == null) return;
|
||||||
|
if (!event.getTo().getWorld().getName().equals(Game.getGameWorld())) return;
|
||||||
|
if (event.getTo().getBlockX() < saveMinX || event.getTo().getBlockX() > saveMaxX || event.getTo().getBlockZ() < saveMinZ || event.getTo().getBlockZ() > saveMaxZ) {
|
||||||
|
event.setCancelled(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,52 @@
|
||||||
|
package net.tylermurphy.hideAndSeek.game.listener;
|
||||||
|
|
||||||
|
import net.tylermurphy.hideAndSeek.game.Board;
|
||||||
|
import net.tylermurphy.hideAndSeek.game.Game;
|
||||||
|
import net.tylermurphy.hideAndSeek.util.Status;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.EventPriority;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
import org.bukkit.event.entity.EntityRegainHealthEvent;
|
||||||
|
import org.bukkit.event.entity.FoodLevelChangeEvent;
|
||||||
|
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||||
|
import org.bukkit.event.player.PlayerDropItemEvent;
|
||||||
|
|
||||||
|
public class PlayerHandler implements Listener {
|
||||||
|
|
||||||
|
@EventHandler(priority = EventPriority.HIGHEST)
|
||||||
|
public void onFoodLevelChange(FoodLevelChangeEvent event) {
|
||||||
|
if (event.getEntity() instanceof Player) {
|
||||||
|
if (!Board.contains((Player) event.getEntity())) return;
|
||||||
|
event.setCancelled(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler(priority = EventPriority.HIGHEST)
|
||||||
|
public void onPlayerRegainHealth(EntityRegainHealthEvent event) {
|
||||||
|
if (event.getRegainReason() == EntityRegainHealthEvent.RegainReason.SATIATED || event.getRegainReason() == EntityRegainHealthEvent.RegainReason.REGEN) {
|
||||||
|
if (event.getEntity() instanceof Player) {
|
||||||
|
if (!Board.contains((Player) event.getEntity())) return;
|
||||||
|
event.setCancelled(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler(priority = EventPriority.HIGHEST)
|
||||||
|
public void onInventoryClick(InventoryClickEvent event) {
|
||||||
|
if (event.getWhoClicked() instanceof Player) {
|
||||||
|
Player player = (Player) event.getWhoClicked();
|
||||||
|
if (Board.contains(player) && Game.status == Status.STANDBY) {
|
||||||
|
event.setCancelled(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler(priority = EventPriority.HIGHEST)
|
||||||
|
public void onItemDrop(PlayerDropItemEvent event) {
|
||||||
|
if (Board.contains(event.getPlayer())) {
|
||||||
|
event.setCancelled(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,41 @@
|
||||||
|
package net.tylermurphy.hideAndSeek.game.listener;
|
||||||
|
|
||||||
|
import net.tylermurphy.hideAndSeek.Main;
|
||||||
|
import net.tylermurphy.hideAndSeek.game.Board;
|
||||||
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.EventPriority;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
import org.bukkit.event.entity.PlayerDeathEvent;
|
||||||
|
import org.bukkit.event.player.PlayerRespawnEvent;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
public class RespawnHandler implements Listener {
|
||||||
|
|
||||||
|
public static final Map<UUID, Location> temp_loc = new HashMap<>();
|
||||||
|
|
||||||
|
@EventHandler(priority = EventPriority.HIGHEST)
|
||||||
|
public void onPlayerDeath(PlayerDeathEvent event) {
|
||||||
|
Player player = event.getEntity();
|
||||||
|
if (!Board.contains(player)) return;
|
||||||
|
event.setKeepInventory(true);
|
||||||
|
event.setDeathMessage("");
|
||||||
|
temp_loc.put(player.getUniqueId(), player.getLocation());
|
||||||
|
Main.plugin.getLogger().severe("Player " + player.getName() + " died when not supposed to. Attempting to roll back death.");
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler(priority = EventPriority.HIGHEST)
|
||||||
|
public void onPlayerRespawn(PlayerRespawnEvent event) {
|
||||||
|
Player player = event.getPlayer();
|
||||||
|
if (!Board.contains(player)) return;
|
||||||
|
if (temp_loc.containsKey(player.getUniqueId())) {
|
||||||
|
player.teleport(temp_loc.get(player.getUniqueId()));
|
||||||
|
temp_loc.remove(player.getUniqueId());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -1,7 +1,5 @@
|
||||||
package net.tylermurphy.hideAndSeek.util;
|
package net.tylermurphy.hideAndSeek.util;
|
||||||
|
|
||||||
import static net.tylermurphy.hideAndSeek.configuration.Config.*;
|
|
||||||
|
|
||||||
import me.clip.placeholderapi.expansion.PlaceholderExpansion;
|
import me.clip.placeholderapi.expansion.PlaceholderExpansion;
|
||||||
import net.tylermurphy.hideAndSeek.database.Database;
|
import net.tylermurphy.hideAndSeek.database.Database;
|
||||||
import net.tylermurphy.hideAndSeek.database.PlayerInfo;
|
import net.tylermurphy.hideAndSeek.database.PlayerInfo;
|
||||||
|
@ -10,6 +8,9 @@ import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
|
import static net.tylermurphy.hideAndSeek.configuration.Config.placeholderError;
|
||||||
|
import static net.tylermurphy.hideAndSeek.configuration.Config.placeholderNoData;
|
||||||
|
|
||||||
public class PAPIExpansion extends PlaceholderExpansion {
|
public class PAPIExpansion extends PlaceholderExpansion {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -35,49 +36,49 @@ public class PAPIExpansion extends PlaceholderExpansion {
|
||||||
@Override
|
@Override
|
||||||
public String onRequest(OfflinePlayer player, @NotNull String params) {
|
public String onRequest(OfflinePlayer player, @NotNull String params) {
|
||||||
String[] args = params.split("_");
|
String[] args = params.split("_");
|
||||||
if(args.length < 1) return null;
|
if (args.length < 1) return null;
|
||||||
if(args[0].equals("stats") && args.length == 2){
|
if (args[0].equals("stats") && args.length == 2) {
|
||||||
PlayerInfo info = Database.playerInfo.getInfo(player.getUniqueId());
|
PlayerInfo info = Database.playerInfo.getInfo(player.getUniqueId());
|
||||||
return getValue(info, args[1]);
|
return getValue(info, args[1]);
|
||||||
} else if(args[0].equals("stats") && args.length == 3){
|
} else if (args[0].equals("stats") && args.length == 3) {
|
||||||
UUID uuid;
|
UUID uuid;
|
||||||
try { uuid = UUIDFetcher.getUUID(args[2]); } catch (Exception e) { return placeholderError; }
|
try { uuid = UUIDFetcher.getUUID(args[2]); } catch (Exception e) { return placeholderError; }
|
||||||
PlayerInfo info = Database.playerInfo.getInfo(uuid);
|
PlayerInfo info = Database.playerInfo.getInfo(uuid);
|
||||||
return getValue(info, args[1]);
|
return getValue(info, args[1]);
|
||||||
} else if((args[0].equals("rank-score") || args[0].equals("rank-name") ) && args.length == 3){
|
} else if ((args[0].equals("rank-score") || args[0].equals("rank-name") ) && args.length == 3) {
|
||||||
int place;
|
int place;
|
||||||
try { place = Integer.parseInt(args[2]); } catch (NumberFormatException e) { return placeholderError; }
|
try { place = Integer.parseInt(args[2]); } catch (NumberFormatException e) { return placeholderError; }
|
||||||
if(place < 1) { return placeholderError; }
|
if (place < 1) { return placeholderError; }
|
||||||
if(getRanking(args[1]) == null) { return placeholderError; }
|
if (getRanking(args[1]) == null) { return placeholderError; }
|
||||||
PlayerInfo info = Database.playerInfo.getInfoRanking(getRanking(args[1]), place);
|
PlayerInfo info = Database.playerInfo.getInfoRanking(getRanking(args[1]), place);
|
||||||
if(info == null) return placeholderNoData;
|
if (info == null) return placeholderNoData;
|
||||||
if(args[0].equals("rank-score")){
|
if (args[0].equals("rank-score")) {
|
||||||
return getValue(info, args[1]);
|
return getValue(info, args[1]);
|
||||||
} else {
|
} else {
|
||||||
return UUIDFetcher.getPlayer(info.uuid).getName();
|
return UUIDFetcher.getPlayer(info.uuid).getName();
|
||||||
}
|
}
|
||||||
} else if(args[0].equals("rank-place") && args.length == 2){
|
} else if (args[0].equals("rank-place") && args.length == 2) {
|
||||||
if(getRanking(args[1]) == null) { return placeholderError; }
|
if (getRanking(args[1]) == null) { return placeholderError; }
|
||||||
PlayerInfo info = Database.playerInfo.getInfo(player.getUniqueId());
|
PlayerInfo info = Database.playerInfo.getInfo(player.getUniqueId());
|
||||||
if(getValue(info, args[1]).equals("0")) { return "-"; }
|
if (getValue(info, args[1]).equals("0")) { return "-"; }
|
||||||
Integer count = Database.playerInfo.getRanking(getRanking(args[1]), player.getUniqueId());
|
Integer count = Database.playerInfo.getRanking(getRanking(args[1]), player.getUniqueId());
|
||||||
if(count == null) { return placeholderNoData; }
|
if (count == null) { return placeholderNoData; }
|
||||||
return count.toString();
|
return count.toString();
|
||||||
} else if(args[0].equals("rank-place") && args.length == 3){
|
} else if (args[0].equals("rank-place") && args.length == 3) {
|
||||||
UUID uuid;
|
UUID uuid;
|
||||||
try { uuid = UUIDFetcher.getUUID(args[2]); } catch (Exception e) { return placeholderError; }
|
try { uuid = UUIDFetcher.getUUID(args[2]); } catch (Exception e) { return placeholderError; }
|
||||||
if(getRanking(args[1]) == null) { return placeholderError; }
|
if (getRanking(args[1]) == null) { return placeholderError; }
|
||||||
PlayerInfo info = Database.playerInfo.getInfo(player.getUniqueId());
|
PlayerInfo info = Database.playerInfo.getInfo(player.getUniqueId());
|
||||||
if(getValue(info, args[1]).equals("0")) { return "-"; }
|
if (getValue(info, args[1]).equals("0")) { return "-"; }
|
||||||
Integer count = Database.playerInfo.getRanking(getRanking(args[1]), uuid);
|
Integer count = Database.playerInfo.getRanking(getRanking(args[1]), uuid);
|
||||||
if(count == null) { return placeholderNoData; }
|
if (count == null) { return placeholderNoData; }
|
||||||
return count.toString();
|
return count.toString();
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getValue(PlayerInfo info, String query){
|
private String getValue(PlayerInfo info, String query) {
|
||||||
if(query == null) return null;
|
if (query == null) return null;
|
||||||
switch (query) {
|
switch (query) {
|
||||||
case "total-wins":
|
case "total-wins":
|
||||||
return String.valueOf(info.hider_wins + info.seeker_wins);
|
return String.valueOf(info.hider_wins + info.seeker_wins);
|
||||||
|
@ -108,8 +109,8 @@ public class PAPIExpansion extends PlaceholderExpansion {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getRanking(String query){
|
private String getRanking(String query) {
|
||||||
if(query == null) return null;
|
if (query == null) return null;
|
||||||
switch (query) {
|
switch (query) {
|
||||||
case "total-wins":
|
case "total-wins":
|
||||||
return "(hider_wins + seeker_wins)";
|
return "(hider_wins + seeker_wins)";
|
||||||
|
|
|
@ -19,10 +19,6 @@
|
||||||
|
|
||||||
package net.tylermurphy.hideAndSeek.util;
|
package net.tylermurphy.hideAndSeek.util;
|
||||||
|
|
||||||
import java.lang.reflect.InvocationTargetException;
|
|
||||||
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
import com.comphenix.protocol.PacketType;
|
import com.comphenix.protocol.PacketType;
|
||||||
import com.comphenix.protocol.ProtocolLibrary;
|
import com.comphenix.protocol.ProtocolLibrary;
|
||||||
import com.comphenix.protocol.ProtocolManager;
|
import com.comphenix.protocol.ProtocolManager;
|
||||||
|
@ -30,6 +26,9 @@ import com.comphenix.protocol.events.PacketContainer;
|
||||||
import com.comphenix.protocol.wrappers.WrappedDataWatcher;
|
import com.comphenix.protocol.wrappers.WrappedDataWatcher;
|
||||||
import com.comphenix.protocol.wrappers.WrappedDataWatcher.Registry;
|
import com.comphenix.protocol.wrappers.WrappedDataWatcher.Registry;
|
||||||
import com.comphenix.protocol.wrappers.WrappedDataWatcher.Serializer;
|
import com.comphenix.protocol.wrappers.WrappedDataWatcher.Serializer;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
import java.lang.reflect.InvocationTargetException;
|
||||||
|
|
||||||
public class Packet {
|
public class Packet {
|
||||||
|
|
||||||
|
@ -41,7 +40,7 @@ public class Packet {
|
||||||
WrappedDataWatcher watcher = new WrappedDataWatcher();
|
WrappedDataWatcher watcher = new WrappedDataWatcher();
|
||||||
Serializer serializer = Registry.get(Byte.class);
|
Serializer serializer = Registry.get(Byte.class);
|
||||||
watcher.setEntity(target);
|
watcher.setEntity(target);
|
||||||
if(glowing) {
|
if (glowing) {
|
||||||
watcher.setObject(0, serializer, (byte) (0x40));
|
watcher.setObject(0, serializer, (byte) (0x40));
|
||||||
} else {
|
} else {
|
||||||
watcher.setObject(0, serializer, (byte) (0x0));
|
watcher.setObject(0, serializer, (byte) (0x0));
|
||||||
|
|
|
@ -20,8 +20,7 @@
|
||||||
package net.tylermurphy.hideAndSeek.util;
|
package net.tylermurphy.hideAndSeek.util;
|
||||||
|
|
||||||
public enum Status {
|
public enum Status {
|
||||||
STANDBY,
|
|
||||||
STARTING,
|
STANDBY, STARTING, PLAYING, ENDING
|
||||||
PLAYING,
|
|
||||||
ENDING
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,30 +19,30 @@
|
||||||
|
|
||||||
package net.tylermurphy.hideAndSeek.util;
|
package net.tylermurphy.hideAndSeek.util;
|
||||||
|
|
||||||
|
import net.tylermurphy.hideAndSeek.game.CommandHandler;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import net.tylermurphy.hideAndSeek.game.CommandHandler;
|
public class TabCompleter {
|
||||||
import org.bukkit.command.CommandSender;
|
|
||||||
|
|
||||||
public class TabCompleter{
|
|
||||||
|
|
||||||
public static List<String> handleTabComplete(CommandSender sender, String[] args) {
|
public static List<String> handleTabComplete(CommandSender sender, String[] args) {
|
||||||
if(args.length == 1) {
|
if (args.length == 1) {
|
||||||
return new ArrayList<>(CommandHandler.COMMAND_REGISTER.keySet())
|
return new ArrayList<>(CommandHandler.COMMAND_REGISTER.keySet())
|
||||||
.stream()
|
.stream()
|
||||||
.filter(handle -> sender.hasPermission("hideandseek."+handle.toLowerCase()) && handle.toLowerCase().startsWith(args[0].toLowerCase(Locale.ROOT)))
|
.filter(handle -> sender.hasPermission("hideandseek."+handle.toLowerCase()) && handle.toLowerCase().startsWith(args[0].toLowerCase(Locale.ROOT)))
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
} else if(args.length > 1) {
|
} else if (args.length > 1) {
|
||||||
if(!CommandHandler.COMMAND_REGISTER.containsKey(args[0].toLowerCase())) {
|
if (!CommandHandler.COMMAND_REGISTER.containsKey(args[0].toLowerCase())) {
|
||||||
return null;
|
return null;
|
||||||
} else {
|
} else {
|
||||||
String[] usage = CommandHandler.COMMAND_REGISTER.get(args[0].toLowerCase()).getUsage().split(" ");
|
String[] usage = CommandHandler.COMMAND_REGISTER.get(args[0].toLowerCase()).getUsage().split(" ");
|
||||||
if(args.length - 2 < usage.length) {
|
if (args.length - 2 < usage.length) {
|
||||||
String parameter = usage[args.length-2];
|
String parameter = usage[args.length-2];
|
||||||
if(parameter.equals("<player>")) {
|
if (parameter.equals("<player>")) {
|
||||||
return null;
|
return null;
|
||||||
} else {
|
} else {
|
||||||
List<String> temp = new ArrayList<>();
|
List<String> temp = new ArrayList<>();
|
||||||
|
|
|
@ -22,7 +22,6 @@ package net.tylermurphy.hideAndSeek.util;
|
||||||
import net.tylermurphy.hideAndSeek.Main;
|
import net.tylermurphy.hideAndSeek.Main;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.OfflinePlayer;
|
import org.bukkit.OfflinePlayer;
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
|
@ -41,20 +40,20 @@ public final class UUIDFetcher {
|
||||||
private static final String UUID_URL = "https://api.mojang.com/users/profiles/minecraft/";
|
private static final String UUID_URL = "https://api.mojang.com/users/profiles/minecraft/";
|
||||||
private static int cacheTask;
|
private static int cacheTask;
|
||||||
|
|
||||||
public static void init(){
|
public static void init() {
|
||||||
cacheTask = Main.plugin.getServer().getScheduler().scheduleSyncRepeatingTask(Main.plugin, () -> {
|
cacheTask = Main.plugin.getServer().getScheduler().scheduleSyncRepeatingTask(Main.plugin, () -> {
|
||||||
CACHE.clear();
|
CACHE.clear();
|
||||||
PLAYER_CACHE.clear();
|
PLAYER_CACHE.clear();
|
||||||
}, 600 * 20, 600 * 20);
|
}, 600 * 20, 600 * 20);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void cleanup(){
|
public static void cleanup() {
|
||||||
Main.plugin.getServer().getScheduler().cancelTask(cacheTask);
|
Main.plugin.getServer().getScheduler().cancelTask(cacheTask);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static UUID getUUID(String playername) {
|
public static UUID getUUID(String playername) {
|
||||||
|
|
||||||
if(CACHE.containsKey(playername)) return CACHE.get(playername);
|
if (CACHE.containsKey(playername)) return CACHE.get(playername);
|
||||||
|
|
||||||
String output = callURL(UUID_URL + playername);
|
String output = callURL(UUID_URL + playername);
|
||||||
StringBuilder result = new StringBuilder();
|
StringBuilder result = new StringBuilder();
|
||||||
|
@ -73,8 +72,8 @@ public final class UUIDFetcher {
|
||||||
return UUID.fromString(uuid.toString());
|
return UUID.fromString(uuid.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static OfflinePlayer getPlayer(UUID uuid){
|
public static OfflinePlayer getPlayer(UUID uuid) {
|
||||||
if(PLAYER_CACHE.containsKey(uuid)) return PLAYER_CACHE.get(uuid);
|
if (PLAYER_CACHE.containsKey(uuid)) return PLAYER_CACHE.get(uuid);
|
||||||
OfflinePlayer temp = Bukkit.getOfflinePlayer(uuid);
|
OfflinePlayer temp = Bukkit.getOfflinePlayer(uuid);
|
||||||
PLAYER_CACHE.put(uuid, temp);
|
PLAYER_CACHE.put(uuid, temp);
|
||||||
return temp;
|
return temp;
|
||||||
|
|
|
@ -9,20 +9,20 @@ public class Version {
|
||||||
|
|
||||||
private static final Map<String,Boolean> CACHE = new HashMap<>();
|
private static final Map<String,Boolean> CACHE = new HashMap<>();
|
||||||
|
|
||||||
public static boolean atLeast(String testVersion){
|
public static boolean atLeast(String testVersion) {
|
||||||
|
|
||||||
|
|
||||||
if(CACHE.containsKey(testVersion)) return CACHE.get(testVersion);
|
if (CACHE.containsKey(testVersion)) return CACHE.get(testVersion);
|
||||||
|
|
||||||
String[] serverCheckTemp = Bukkit.getBukkitVersion().substring(2,Bukkit.getBukkitVersion().indexOf('-')).split("\\.");
|
String[] serverCheckTemp = Bukkit.getBukkitVersion().substring(2,Bukkit.getBukkitVersion().indexOf('-')).split("\\.");
|
||||||
int[] serverCheck = new int[serverCheckTemp.length];
|
int[] serverCheck = new int[serverCheckTemp.length];
|
||||||
for(int i=0; i<serverCheck.length; i++){
|
for(int i=0; i<serverCheck.length; i++) {
|
||||||
serverCheck[i] = Integer.parseInt(serverCheckTemp[i]);
|
serverCheck[i] = Integer.parseInt(serverCheckTemp[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
String[] customCheckTemp = testVersion.substring(2).split("\\.");
|
String[] customCheckTemp = testVersion.substring(2).split("\\.");
|
||||||
int[] customCheck = new int[customCheckTemp.length];
|
int[] customCheck = new int[customCheckTemp.length];
|
||||||
for(int i=0; i<customCheck.length; i++){
|
for(int i=0; i<customCheck.length; i++) {
|
||||||
customCheck[i] = Integer.parseInt(customCheckTemp[i]);
|
customCheck[i] = Integer.parseInt(customCheckTemp[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -31,12 +31,12 @@ public class Version {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean getResult(int[] customCheck, int[] serverCheck){
|
private static boolean getResult(int[] customCheck, int[] serverCheck) {
|
||||||
if(customCheck[0] > serverCheck[0]) return false;
|
if (customCheck[0] > serverCheck[0]) return false;
|
||||||
else if(customCheck[0] < serverCheck[0]) return true;
|
else if (customCheck[0] < serverCheck[0]) return true;
|
||||||
else {
|
else {
|
||||||
if (customCheck.length == 1 && serverCheck.length == 1) return true;
|
if (customCheck.length == 1 && serverCheck.length == 1) return true;
|
||||||
else if(customCheck.length == 2 && serverCheck.length == 2){
|
else if (customCheck.length == 2 && serverCheck.length == 2) {
|
||||||
return customCheck[1] <= serverCheck[1];
|
return customCheck[1] <= serverCheck[1];
|
||||||
}
|
}
|
||||||
else return serverCheck.length == 2;
|
else return serverCheck.length == 2;
|
||||||
|
|
|
@ -20,7 +20,7 @@
|
||||||
package net.tylermurphy.hideAndSeek.util;
|
package net.tylermurphy.hideAndSeek.util;
|
||||||
|
|
||||||
public enum WinType {
|
public enum WinType {
|
||||||
HIDER_WIN,
|
|
||||||
SEEKER_WIN,
|
HIDER_WIN, SEEKER_WIN, NONE
|
||||||
NONE
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,15 +19,15 @@
|
||||||
|
|
||||||
package net.tylermurphy.hideAndSeek.world;
|
package net.tylermurphy.hideAndSeek.world;
|
||||||
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Random;
|
|
||||||
|
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
import org.bukkit.generator.BlockPopulator;
|
import org.bukkit.generator.BlockPopulator;
|
||||||
import org.bukkit.generator.ChunkGenerator;
|
import org.bukkit.generator.ChunkGenerator;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
public class VoidGenerator extends ChunkGenerator{
|
public class VoidGenerator extends ChunkGenerator{
|
||||||
|
|
||||||
public @NotNull List<BlockPopulator> getDefaultPopulators(@NotNull World world) {
|
public @NotNull List<BlockPopulator> getDefaultPopulators(@NotNull World world) {
|
||||||
|
|
|
@ -19,84 +19,78 @@
|
||||||
|
|
||||||
package net.tylermurphy.hideAndSeek.world;
|
package net.tylermurphy.hideAndSeek.world;
|
||||||
|
|
||||||
import static net.tylermurphy.hideAndSeek.configuration.Config.*;
|
import net.tylermurphy.hideAndSeek.Main;
|
||||||
import static net.tylermurphy.hideAndSeek.configuration.Localization.message;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.FileInputStream;
|
|
||||||
import java.io.FileOutputStream;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.io.OutputStream;
|
|
||||||
|
|
||||||
import net.tylermurphy.hideAndSeek.util.Version;
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
import org.bukkit.WorldCreator;
|
import org.bukkit.WorldCreator;
|
||||||
|
|
||||||
import net.tylermurphy.hideAndSeek.Main;
|
import java.io.*;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
|
||||||
|
import static net.tylermurphy.hideAndSeek.configuration.Config.*;
|
||||||
|
import static net.tylermurphy.hideAndSeek.configuration.Localization.message;
|
||||||
|
|
||||||
public class WorldLoader {
|
public class WorldLoader {
|
||||||
|
|
||||||
String mapname;
|
final String mapName;
|
||||||
String savename;
|
final String saveName;
|
||||||
|
|
||||||
public WorldLoader(String mapname) {
|
public WorldLoader(String mapName) {
|
||||||
this.mapname = mapname;
|
this.mapName = mapName;
|
||||||
this.savename = "hideandseek_"+mapname;
|
this.saveName = "hideandseek_"+ mapName;
|
||||||
}
|
}
|
||||||
|
|
||||||
public World getWorld(){
|
public World getWorld() {
|
||||||
return Bukkit.getServer().getWorld(savename);
|
return Bukkit.getServer().getWorld(saveName);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void unloadMap(){
|
public void unloadMap() {
|
||||||
World world = Bukkit.getServer().getWorld(savename);
|
World world = Bukkit.getServer().getWorld(saveName);
|
||||||
if(world == null){
|
if (world == null) {
|
||||||
Main.plugin.getLogger().warning(savename + " already unloaded.");
|
Main.plugin.getLogger().warning(saveName + " already unloaded.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if(Bukkit.getServer().unloadWorld(world, false)){
|
if (Bukkit.getServer().unloadWorld(world, false)) {
|
||||||
Main.plugin.getLogger().info("Successfully unloaded " + savename);
|
Main.plugin.getLogger().info("Successfully unloaded " + saveName);
|
||||||
}else{
|
}else{
|
||||||
Main.plugin.getLogger().severe("COULD NOT UNLOAD " + savename);
|
Main.plugin.getLogger().severe("COULD NOT UNLOAD " + saveName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void loadMap(){
|
public void loadMap() {
|
||||||
Bukkit.getServer().createWorld(new WorldCreator(savename).generator(new VoidGenerator()));
|
Bukkit.getServer().createWorld(new WorldCreator(saveName).generator(new VoidGenerator()));
|
||||||
World world = Bukkit.getServer().getWorld(savename);
|
World world = Bukkit.getServer().getWorld(saveName);
|
||||||
if(world == null){
|
if (world == null) {
|
||||||
Main.plugin.getLogger().severe("COULD NOT LOAD " + savename);
|
Main.plugin.getLogger().severe("COULD NOT LOAD " + saveName);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
world.setAutoSave(false);
|
world.setAutoSave(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void rollback(){
|
public void rollback() {
|
||||||
unloadMap();
|
unloadMap();
|
||||||
loadMap();
|
loadMap();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String save() {
|
public String save() {
|
||||||
File current = new File(Main.root+File.separator+mapname);
|
File current = new File(Main.root+File.separator+ mapName);
|
||||||
if(current.exists()) {
|
if (current.exists()) {
|
||||||
try {
|
try {
|
||||||
File destenation = new File(Main.root+File.separator+savename);
|
File destenation = new File(Main.root+File.separator+ saveName);
|
||||||
File temp_destenation = new File(Main.root+File.separator+"temp_"+savename);
|
File temp_destenation = new File(Main.root+File.separator+"temp_"+ saveName);
|
||||||
copyFileFolder("region",true);
|
copyFileFolder("region",true);
|
||||||
copyFileFolder("entities",true);
|
copyFileFolder("entities",true);
|
||||||
copyFileFolder("datapacks",false);
|
copyFileFolder("datapacks",false);
|
||||||
File srcFile = new File(current, "level.dat");
|
File srcFile = new File(current, "level.dat");
|
||||||
File destFile = new File(temp_destenation, "level.dat");
|
File destFile = new File(temp_destenation, "level.dat");
|
||||||
copyFile(srcFile,destFile);
|
copyFile(srcFile,destFile);
|
||||||
if(destenation.exists()) {
|
if (destenation.exists()) {
|
||||||
deleteDirectory(destenation);
|
deleteDirectory(destenation);
|
||||||
if(!destenation.mkdir()){
|
if (!destenation.mkdir()) {
|
||||||
throw new RuntimeException("Failed to create directory: "+destenation.getPath());
|
throw new RuntimeException("Failed to create directory: "+destenation.getPath());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(!temp_destenation.renameTo(destenation)){
|
if (!temp_destenation.renameTo(destenation)) {
|
||||||
throw new RuntimeException("Failed to rename directory: "+temp_destenation.getPath());
|
throw new RuntimeException("Failed to rename directory: "+temp_destenation.getPath());
|
||||||
}
|
}
|
||||||
} catch(IOException e) {
|
} catch(IOException e) {
|
||||||
|
@ -110,38 +104,38 @@ public class WorldLoader {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void copyFileFolder(String name, Boolean isMca) throws IOException {
|
private void copyFileFolder(String name, Boolean isMca) throws IOException {
|
||||||
File region = new File(Main.root+File.separator+mapname+File.separator+name);
|
File region = new File(Main.root+File.separator+ mapName +File.separator+name);
|
||||||
File temp = new File(Main.root+File.separator+"temp_"+savename+File.separator+name);
|
File temp = new File(Main.root+File.separator+"temp_"+ saveName +File.separator+name);
|
||||||
System.out.println(region.getAbsolutePath());
|
System.out.println(region.getAbsolutePath());
|
||||||
System.out.println(temp.getAbsolutePath());
|
System.out.println(temp.getAbsolutePath());
|
||||||
if(region.exists() && region.isDirectory()) {
|
if (region.exists() && region.isDirectory()) {
|
||||||
System.out.println("passed");
|
System.out.println("passed");
|
||||||
if(!temp.exists())
|
if (!temp.exists())
|
||||||
if(!temp.mkdirs())
|
if (!temp.mkdirs())
|
||||||
throw new IOException("Couldn't create region directory!");
|
throw new IOException("Couldn't create region directory!");
|
||||||
String[] files = region.list();
|
String[] files = region.list();
|
||||||
if(files == null){
|
if (files == null) {
|
||||||
Main.plugin.getLogger().severe("Region directory is null or cannot be accessed");
|
Main.plugin.getLogger().severe("Region directory is null or cannot be accessed");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
for (String file : files) {
|
for (String file : files) {
|
||||||
System.out.println("Testing file "+ file);
|
System.out.println("Testing file "+ file);
|
||||||
if(isMca) {
|
if (isMca) {
|
||||||
int minX = (int)Math.floor(saveMinX / 512.0);
|
int minX = (int)Math.floor(saveMinX / 512.0);
|
||||||
int minZ = (int)Math.floor(saveMinZ / 512.0);
|
int minZ = (int)Math.floor(saveMinZ / 512.0);
|
||||||
int maxX = (int)Math.floor(saveMaxX / 512.0);
|
int maxX = (int)Math.floor(saveMaxX / 512.0);
|
||||||
int maxZ = (int)Math.floor(saveMaxZ / 512.0);
|
int maxZ = (int)Math.floor(saveMaxZ / 512.0);
|
||||||
|
|
||||||
String[] parts = file.split("\\.");
|
String[] parts = file.split("\\.");
|
||||||
if(parts.length > 1) {
|
if (parts.length > 1) {
|
||||||
Main.plugin.getLogger().info(file);
|
Main.plugin.getLogger().info(file);
|
||||||
if( Integer.parseInt(parts[1]) < minX || Integer.parseInt(parts[1]) > maxX || Integer.parseInt(parts[2]) < minZ || Integer.parseInt(parts[2]) > maxZ )
|
if ( Integer.parseInt(parts[1]) < minX || Integer.parseInt(parts[1]) > maxX || Integer.parseInt(parts[2]) < minZ || Integer.parseInt(parts[2]) > maxZ )
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
File srcFile = new File(region, file);
|
File srcFile = new File(region, file);
|
||||||
if(srcFile.isDirectory()) {
|
if (srcFile.isDirectory()) {
|
||||||
copyFileFolder(name+File.separator+file, false);
|
copyFileFolder(name+File.separator+file, false);
|
||||||
} else {
|
} else {
|
||||||
File destFile = new File(temp, file);
|
File destFile = new File(temp, file);
|
||||||
|
@ -152,8 +146,8 @@ public class WorldLoader {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void copyFile(File source, File target) throws IOException {
|
private void copyFile(File source, File target) throws IOException {
|
||||||
InputStream in = new FileInputStream(source);
|
InputStream in = Files.newInputStream(source.toPath());
|
||||||
OutputStream out = new FileOutputStream(target);
|
OutputStream out = Files.newOutputStream(target.toPath());
|
||||||
byte[] buffer = new byte[1024];
|
byte[] buffer = new byte[1024];
|
||||||
int length;
|
int length;
|
||||||
while ((length = in.read(buffer)) > 0)
|
while ((length = in.read(buffer)) > 0)
|
||||||
|
@ -169,7 +163,7 @@ public class WorldLoader {
|
||||||
deleteDirectory(file);
|
deleteDirectory(file);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(!directoryToBeDeleted.delete()){
|
if (!directoryToBeDeleted.delete()) {
|
||||||
throw new RuntimeException("Failed to delete directory: "+directoryToBeDeleted.getPath());
|
throw new RuntimeException("Failed to delete directory: "+directoryToBeDeleted.getPath());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue