Merge pull request #53 from bobby29831/1.4.3

Implement better coding practices
This commit is contained in:
Tyler Murphy 2022-05-13 13:42:26 -04:00 committed by GitHub
commit 7d152668d7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
46 changed files with 1087 additions and 1008 deletions

View file

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

View file

@ -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();
@ -88,6 +84,17 @@ public class Main extends JavaPlugin implements Listener {
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);
} }

View file

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

View file

@ -19,15 +19,14 @@
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 {
@ -41,7 +40,7 @@ public class Join implements ICommand {
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;
} }

View file

@ -19,17 +19,14 @@
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 {
@ -43,7 +40,7 @@ public class Leave implements ICommand {
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;
} }

View file

@ -19,17 +19,16 @@
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 {

View file

@ -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,8 +27,8 @@ 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 {

View file

@ -19,15 +19,14 @@
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 {
@ -45,7 +44,7 @@ public class SetBorder implements ICommand {
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;
@ -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() {

View file

@ -19,14 +19,13 @@
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 {

View file

@ -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,7 +26,8 @@ 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 {

View file

@ -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,7 +26,8 @@ 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 {

View file

@ -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,8 +27,8 @@ 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 {

View file

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

View file

@ -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,13 +27,13 @@ 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) {
@ -46,7 +45,7 @@ public class Start implements ICommand {
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;
} }

View file

@ -19,13 +19,13 @@
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 {

View file

@ -27,8 +27,8 @@ 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 {

View file

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

View file

@ -39,7 +39,7 @@ 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,
@ -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(

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -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,12 +40,12 @@ 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) {

View file

@ -19,21 +19,22 @@
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())) {

View file

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

View file

@ -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 {
@ -206,14 +205,7 @@ public class Game {
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);
@ -230,7 +222,7 @@ public class Game {
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();
} }
@ -301,6 +293,10 @@ public class Game {
for(PotionEffect effect : player.getActivePotionEffects()) { for(PotionEffect effect : player.getActivePotionEffects()) {
player.removePotionEffect(effect.getType()); player.removePotionEffect(effect.getType());
} }
handleBungeeLeave(player);
}
private static void handleBungeeLeave(Player player) {
if (bungeeLeave) { if (bungeeLeave) {
ByteArrayDataOutput out = ByteStreams.newDataOutput(); ByteArrayDataOutput out = ByteStreams.newDataOutput();
out.writeUTF("Connect"); out.writeUTF("Connect");
@ -390,7 +386,7 @@ public class Game {
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);
} }
@ -406,8 +402,8 @@ public class Game {
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;
} }
@ -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;

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -19,14 +19,14 @@
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;
import org.bukkit.command.CommandSender;
public class TabCompleter { public class TabCompleter {
public static List<String> handleTabComplete(CommandSender sender, String[] args) { public static List<String> handleTabComplete(CommandSender sender, String[] args) {

View file

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

View file

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

View file

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

View file

@ -19,55 +19,49 @@
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);
@ -79,11 +73,11 @@ public class WorldLoader {
} }
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);
@ -110,8 +104,8 @@ 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()) {
@ -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)