Merge pull request #20 from tylermurphy534/1.3.3

1.3.3
This commit is contained in:
Tyler Murphy 2021-12-30 12:17:32 -05:00 committed by GitHub
commit 31d60d7d23
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
50 changed files with 2542 additions and 1335 deletions

12
pom.xml
View file

@ -1,7 +1,7 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"><modelVersion>4.0.0</modelVersion> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"><modelVersion>4.0.0</modelVersion>
<groupId>net.tylermurphy</groupId> <groupId>net.tylermurphy</groupId>
<artifactId>HideAndSeek</artifactId> <artifactId>HideAndSeek</artifactId>
<version>1.3.2</version> <version>1.3.3</version>
<name>Hide and Seek Plugin</name> <name>Hide and Seek Plugin</name>
<build> <build>
<plugins> <plugins>
@ -39,5 +39,15 @@
<artifactId>ProtocolLib</artifactId> <artifactId>ProtocolLib</artifactId>
<version>4.7.0</version> <version>4.7.0</version>
</dependency> </dependency>
<dependency>
<groupId>org.xerial</groupId>
<artifactId>sqlite-jdbc</artifactId>
<version>3.36.0.3</version>
</dependency>
<dependency>
<groupId>org.jetbrains</groupId>
<artifactId>annotations</artifactId>
<version>23.0.0</version>
</dependency>
</dependencies> </dependencies>
</project> </project>

View file

@ -1,103 +1,89 @@
/*
* 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; package net.tylermurphy.hideAndSeek;
import static net.tylermurphy.hideAndSeek.configuration.Config.spawnWorld;
import java.io.File; import java.io.File;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map;
import net.tylermurphy.hideAndSeek.database.Database;
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.entity.Player;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.scheduler.BukkitTask; import org.bukkit.scheduler.BukkitTask;
import net.tylermurphy.hideAndSeek.bukkit.CommandHandler; import net.tylermurphy.hideAndSeek.game.CommandHandler;
import net.tylermurphy.hideAndSeek.bukkit.EventListener; import net.tylermurphy.hideAndSeek.game.EventListener;
import net.tylermurphy.hideAndSeek.bukkit.TabCompleter; import net.tylermurphy.hideAndSeek.util.TabCompleter;
import net.tylermurphy.hideAndSeek.bukkit.Tick; import net.tylermurphy.hideAndSeek.game.Game;
import net.tylermurphy.hideAndSeek.configuration.Config; import net.tylermurphy.hideAndSeek.configuration.Config;
import net.tylermurphy.hideAndSeek.configuration.Localization; import net.tylermurphy.hideAndSeek.configuration.Localization;
import net.tylermurphy.hideAndSeek.configuration.Items; import net.tylermurphy.hideAndSeek.configuration.Items;
import net.tylermurphy.hideAndSeek.events.Glow; import net.tylermurphy.hideAndSeek.game.Board;
import net.tylermurphy.hideAndSeek.events.Taunt; import org.jetbrains.annotations.NotNull;
import net.tylermurphy.hideAndSeek.events.Worldborder;
import net.tylermurphy.hideAndSeek.util.Board;
import net.tylermurphy.hideAndSeek.world.WorldLoader;
public class Main extends JavaPlugin implements Listener { public class Main extends JavaPlugin implements Listener {
public static Main plugin; public static Main plugin;
public static File root, data; public static File root, data;
public Taunt taunt;
public Glow glow;
public Worldborder worldborder;
public Board board;
public WorldLoader worldLoader;
public Map<String,Player> playerList = new HashMap<String,Player>();
public String status = "Standby";
public int timeLeft = 0, gameId = 0;;
private BukkitTask onTickTask; private BukkitTask onTickTask;
public void onEnable() { public void onEnable() {
plugin = this; plugin = this;
// Setup Initial Player Count
getServer().getPluginManager().registerEvents(new EventListener(), this);
// Get Data Folder
root = this.getServer().getWorldContainer(); root = this.getServer().getWorldContainer();
data = this.getDataFolder(); data = this.getDataFolder();
getServer().getPluginManager().registerEvents(new EventListener(), this);
// Init Configuration
Config.loadConfig(); Config.loadConfig();
Localization.loadLocalization(); Localization.loadLocalization();
Items.loadItems(); Items.loadItems();
// Create World Loader
worldLoader = new WorldLoader(spawnWorld);
// Register Commands
CommandHandler.registerCommands(); CommandHandler.registerCommands();
Board.reload();
//Board Database.init();
board = new Board(); UUIDFetcher.init();
board.reload();
// Start Tick Timer
onTickTask = Bukkit.getServer().getScheduler().runTaskTimer(this, () -> { onTickTask = Bukkit.getServer().getScheduler().runTaskTimer(this, () -> {
try{ try{
Tick.onTick(); Game.onTick();
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
},0,1); },0,1);
} }
public void onDisable() { public void onDisable() {
if(onTickTask != null) if(onTickTask != null)
onTickTask.cancel(); onTickTask.cancel();
UUIDFetcher.cleanup();
} }
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { public boolean onCommand(@NotNull CommandSender sender, @NotNull Command cmd, @NotNull String label, String[] args) {
return CommandHandler.handleCommand(sender, cmd, label, args); return CommandHandler.handleCommand(sender, args);
} }
public List<String> onTabComplete(CommandSender sender, Command command, String label, String[] args) { public List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, String[] args) {
return TabCompleter.handleTabComplete(sender, command, label, args); return TabCompleter.handleTabComplete(sender, args);
} }
} }

View file

@ -1,163 +0,0 @@
package net.tylermurphy.hideAndSeek.bukkit;
import static net.tylermurphy.hideAndSeek.configuration.Config.*;
import net.tylermurphy.hideAndSeek.command.Join;
import org.bukkit.Bukkit;
import org.bukkit.GameMode;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.Sound;
import org.bukkit.attribute.Attribute;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.entity.Snowball;
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 org.bukkit.event.entity.EntityRegainHealthEvent;
import org.bukkit.event.entity.EntityRegainHealthEvent.RegainReason;
import org.bukkit.event.entity.FoodLevelChangeEvent;
import org.bukkit.event.entity.ProjectileLaunchEvent;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerKickEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import net.tylermurphy.hideAndSeek.util.Packet;
import net.tylermurphy.hideAndSeek.util.Util;
import net.tylermurphy.hideAndSeek.Main;
import org.bukkit.potion.PotionEffect;
import static net.tylermurphy.hideAndSeek.configuration.Localization.*;
public class EventListener implements Listener {
@EventHandler
public void onPlayerJoin(PlayerJoinEvent event) {
event.getPlayer().setLevel(0);
Main.plugin.board.remove(event.getPlayer());
if(!Util.isSetup()) return;
if(autoJoin){
Join.join(event.getPlayer());
} else if(teleportToExit) {
if (event.getPlayer().getWorld().getName().equals("hideandseek_" + spawnWorld) || 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 (event.getPlayer().getWorld().getName().equals("hideandseek_" + spawnWorld)) {
event.getPlayer().teleport(new Location(Bukkit.getWorld(exitWorld), exitPosition.getX(), exitPosition.getY(), exitPosition.getZ()));
event.getPlayer().setGameMode(GameMode.ADVENTURE);
}
}
}
@EventHandler
public void onQuit(PlayerQuitEvent event) {
Main.plugin.board.remove(event.getPlayer());
if(Main.plugin.status.equals("Standby")) {
Main.plugin.board.reloadLobbyBoards();
} else {
Main.plugin.board.reloadGameBoards();
}
for(PotionEffect effect : event.getPlayer().getActivePotionEffects()){
event.getPlayer().removePotionEffect(effect.getType());
}
}
@EventHandler
public void onKick(PlayerKickEvent event) {
Main.plugin.board.remove(event.getPlayer());
if(Main.plugin.status.equals("Standby")) {
Main.plugin.board.reloadLobbyBoards();
} else {
Main.plugin.board.reloadGameBoards();
}
for(PotionEffect effect : event.getPlayer().getActivePotionEffects()){
event.getPlayer().removePotionEffect(effect.getType());
}
}
@EventHandler(priority = EventPriority.HIGHEST)
public void onEntityDamage(EntityDamageEvent event) {
try {
if (event.getEntity() instanceof Player) {
Player p = (Player) event.getEntity();
if (!Main.plugin.board.isPlayer(p)) return;
if (!Main.plugin.status.equals("Playing")) {
event.setCancelled(true);
return;
}
Player attacker = null;
if (event instanceof EntityDamageByEntityEvent) {
Entity damager = ((EntityDamageByEntityEvent) event).getDamager();
if (damager instanceof Player) {
attacker = (Player) damager;
if (Main.plugin.board.onSameTeam(p, attacker)) event.setCancelled(true);
if (Main.plugin.board.isSpectator(p)) event.setCancelled(true);
}
}
Player player = (Player) event.getEntity();
if (player.getHealth() - event.getDamage() < 0 || !pvpEnabled) {
if (spawnPosition == null) return;
event.setCancelled(true);
player.setHealth(player.getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue());
player.teleport(new Location(Bukkit.getWorld("hideandseek_" + spawnWorld), spawnPosition.getX(), spawnPosition.getY(), spawnPosition.getZ()));
Packet.playSound(player, Sound.ENTITY_PLAYER_DEATH, 1, 1);
if (Main.plugin.board.isSeeker(player)) {
Bukkit.broadcastMessage(message("GAME_PLAYER_DEATH").addPlayer(event.getEntity()).toString());
}
if (Main.plugin.board.isHider(player)) {
if (attacker == null) {
Util.broadcastMessage(message("GAME_PLAYER_FOUND").addPlayer(event.getEntity()).toString());
} else {
Util.broadcastMessage(message("GAME_PLAYER_FOUND_BY").addPlayer(event.getEntity()).addPlayer(attacker).toString());
}
Main.plugin.board.addSeeker(player);
}
Util.resetPlayer(player);
Main.plugin.board.reloadBoardTeams();
}
}
} catch (Exception e){
//Has shown to cause problems, so ignore if exception
}
}
@EventHandler(priority = EventPriority.HIGHEST)
public void onProjectile(ProjectileLaunchEvent event) {
if(!Main.plugin.status.equals("Playing")) return;
if(event.getEntity() instanceof Snowball) {
if(!glowEnabled) return;
Snowball snowball = (Snowball) event.getEntity();
if(snowball.getShooter() instanceof Player) {
Player player = (Player) snowball.getShooter();
if(Main.plugin.board.isHider(player)) {
Main.plugin.glow.onProjectilve();
snowball.remove();
player.getInventory().remove(Material.SNOWBALL);
}
}
}
}
@EventHandler(priority = EventPriority.HIGHEST)
public void onFoodLevelChange(FoodLevelChangeEvent event) {
if(event.getEntity() instanceof Player) {
if(!Main.plugin.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(!Main.plugin.board.isPlayer((Player) event.getEntity())) return;
event.setCancelled(true);
}
}
}
}

View file

@ -1,85 +0,0 @@
package net.tylermurphy.hideAndSeek.bukkit;
import static net.tylermurphy.hideAndSeek.configuration.Config.*;
import org.bukkit.Bukkit;
import org.bukkit.Sound;
import org.bukkit.entity.Player;
import net.tylermurphy.hideAndSeek.Main;
import net.tylermurphy.hideAndSeek.command.Stop;
import net.tylermurphy.hideAndSeek.util.Packet;
import net.tylermurphy.hideAndSeek.util.Util;
import static net.tylermurphy.hideAndSeek.configuration.Localization.*;
public class Tick {
static int tick = 0;
public static void onTick() {
if(Main.plugin.status.equals("Standby")) tick = 0;
else if(Main.plugin.status.equals("Playing")) onPlaying();
if(( Main.plugin.status.equals("Starting") || Main.plugin.status.equals("Playing") ) && Main.plugin.board.sizeHider() < 1) {
if(announceMessagesToNonPlayers) Bukkit.broadcastMessage(gameoverPrefix + message("GAME_GAMEOVER_HIDERS_FOUND"));
else Util.broadcastMessage(gameoverPrefix + message("GAME_GAMEOVER_HIDERS_FOUND"));
Stop.onStop();
}
if(( Main.plugin.status.equals("Starting") || Main.plugin.status.equals("Playing") ) && Main.plugin.board.sizeSeeker() < 1) {
if(announceMessagesToNonPlayers) Bukkit.broadcastMessage(abortPrefix + message("GAME_GAMEOVER_SEEKERS_QUIT"));
else Util.broadcastMessage(abortPrefix + message("GAME_GAMEOVER_SEEKERS_QUIT"));
Stop.onStop();
}
}
private static void onPlaying() {
if(tick<1000000) tick++;
else tick = 1;
for(Player hider : Main.plugin.board.getHiders()) {
int distance = 100, temp = 100;
for(Player seeker : Main.plugin.board.getSeekers()) {
try {
temp = (int) hider.getLocation().distance(seeker.getLocation());
} catch (Exception e){
//Players in different worlds, NOT OK!!!
}
if(distance > temp) {
distance = temp;
}
}
switch(tick%10) {
case 0:
if(distance < 30) Packet.playSound(hider, Sound.BLOCK_NOTE_BLOCK_BASEDRUM, .5f, 1f);
if(distance < 10) Packet.playSound(hider, Sound.BLOCK_NOTE_BLOCK_BIT, .3f, 1f);
break;
case 3:
if(distance < 30) Packet.playSound(hider, Sound.BLOCK_NOTE_BLOCK_BASEDRUM, .3f, 1f);
if(distance < 10) Packet.playSound(hider, Sound.BLOCK_NOTE_BLOCK_BIT, .3f, 1f);
break;
case 6:
if(distance < 10) Packet.playSound(hider, Sound.BLOCK_NOTE_BLOCK_BIT, .3f, 1f);
break;
case 9:
if(distance < 20) Packet.playSound(hider, Sound.BLOCK_NOTE_BLOCK_BIT, .3f, 1f);
break;
}
}
if(tick%20 == 0) {
if(gameLength > 0) {
Main.plugin.board.reloadGameBoards();
Main.plugin.timeLeft--;
if(Main.plugin.timeLeft < 1) {
if(announceMessagesToNonPlayers) Bukkit.broadcastMessage(gameoverPrefix + message("GAME_GAMEOVER_TIME"));
else Util.broadcastMessage(gameoverPrefix + message("GAME_GAMEOVER_TIME"));
Stop.onStop();
}
}
}
}
}

View file

@ -1,3 +1,22 @@
/*
* 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.command; package net.tylermurphy.hideAndSeek.command;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
@ -7,7 +26,7 @@ public class About implements ICommand {
public void execute(CommandSender sender, String[] args) { public void execute(CommandSender sender, String[] args) {
sender.sendMessage( sender.sendMessage(
String.format("%s%sHide and Seek %s(1.3.2%s)\n", ChatColor.AQUA, ChatColor.BOLD, ChatColor.GRAY,ChatColor.WHITE,ChatColor.GRAY) + String.format("%s%sHide and Seek %s(%s1.3.3%s)\n", ChatColor.AQUA, ChatColor.BOLD, ChatColor.GRAY,ChatColor.WHITE,ChatColor.GRAY) +
String.format("%sAuthor: %s[KenshinEto]\n", ChatColor.GRAY, ChatColor.WHITE) + String.format("%sAuthor: %s[KenshinEto]\n", ChatColor.GRAY, ChatColor.WHITE) +
String.format("%sHelp Command: %s/hs %shelp", ChatColor.GRAY, ChatColor.AQUA, ChatColor.WHITE) String.format("%sHelp Command: %s/hs %shelp", ChatColor.GRAY, ChatColor.AQUA, ChatColor.WHITE)
); );

View file

@ -1,19 +1,38 @@
/*
* 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.command; package net.tylermurphy.hideAndSeek.command;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import net.md_5.bungee.api.ChatColor; import net.md_5.bungee.api.ChatColor;
import net.tylermurphy.hideAndSeek.bukkit.CommandHandler; import net.tylermurphy.hideAndSeek.game.CommandHandler;
public class Help implements ICommand { public class Help implements ICommand {
public void execute(CommandSender sender, String[] args) { public void execute(CommandSender sender, String[] args) {
String message = ""; StringBuilder message = new StringBuilder();
for(ICommand command : CommandHandler.COMMAND_REGISTER.values()) { for(ICommand command : CommandHandler.COMMAND_REGISTER.values()) {
message += String.format("%s/hs %s%s %s%s\n %s%s%s", ChatColor.AQUA, ChatColor.WHITE, command.getLabel().toLowerCase(), ChatColor.BLUE, command.getUsage(), ChatColor.GRAY, ChatColor.ITALIC, command.getDescription()+"\n"); message.append(String.format("%s/hs %s%s %s%s\n %s%s%s", ChatColor.AQUA, ChatColor.WHITE, command.getLabel().toLowerCase(), ChatColor.BLUE, command.getUsage(), ChatColor.GRAY, ChatColor.ITALIC, command.getDescription() + "\n"));
} }
message = message.substring(0, message.length()-1); message = new StringBuilder(message.substring(0, message.length() - 1));
sender.sendMessage(message); sender.sendMessage(message.toString());
} }
public String getLabel() { public String getLabel() {

View file

@ -1,15 +1,34 @@
/*
* 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.command; package net.tylermurphy.hideAndSeek.command;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
public interface ICommand { public interface ICommand {
public void execute(CommandSender sender, String[] args); void execute(CommandSender sender, String[] args);
public String getLabel(); String getLabel();
String getUsage();
public String getUsage(); String getDescription();
public String getDescription();
} }

View file

@ -1,22 +1,38 @@
/*
* 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.command; package net.tylermurphy.hideAndSeek.command;
import static net.tylermurphy.hideAndSeek.configuration.Config.*; import static net.tylermurphy.hideAndSeek.configuration.Config.*;
import net.tylermurphy.hideAndSeek.game.Board;
import net.tylermurphy.hideAndSeek.game.Game;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.GameMode;
import org.bukkit.Location;
import org.bukkit.attribute.Attribute;
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 net.tylermurphy.hideAndSeek.util.Util;
import static net.tylermurphy.hideAndSeek.configuration.Localization.*; import static net.tylermurphy.hideAndSeek.configuration.Localization.*;
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(!Util.isSetup()) { if(Game.isNotSetup()) {
sender.sendMessage(errorPrefix + message("GAME_SETUP")); sender.sendMessage(errorPrefix + message("GAME_SETUP"));
return; return;
} }
@ -25,34 +41,12 @@ public class Join implements ICommand {
sender.sendMessage(errorPrefix + message("COMMAND_ERROR")); sender.sendMessage(errorPrefix + message("COMMAND_ERROR"));
return; return;
} }
if(Main.plugin.board.isPlayer(player)){ if(Board.isPlayer(player)){
sender.sendMessage(errorPrefix + message("GAME_INGAME")); sender.sendMessage(errorPrefix + message("GAME_INGAME"));
return; return;
} }
join(player); Game.join(player);
}
public static void join(Player player){
if(Main.plugin.status.equals("Standby")) {
player.getInventory().clear();
Main.plugin.board.addHider(player);
if(announceMessagesToNonPlayers) Bukkit.broadcastMessage(messagePrefix + message("GAME_JOIN").addPlayer(player));
else Util.broadcastMessage(messagePrefix + message("GAME_JOIN").addPlayer(player));
player.teleport(new Location(Bukkit.getWorld(lobbyWorld), lobbyPosition.getX(),lobbyPosition.getY(),lobbyPosition.getZ()));
player.setGameMode(GameMode.ADVENTURE);
Main.plugin.board.createLobbyBoard(player);
Main.plugin.board.reloadLobbyBoards();
} else {
Main.plugin.board.addSpectator(player);
player.sendMessage(messagePrefix + message("GAME_JOIN_SPECTATOR"));
player.setGameMode(GameMode.SPECTATOR);
Main.plugin.board.createGameBoard(player);
player.teleport(new Location(Bukkit.getWorld("hideandseek_"+spawnWorld), spawnPosition.getX(),spawnPosition.getY(),spawnPosition.getZ()));
}
player.setFoodLevel(20);
player.setHealth(player.getAttribute(Attribute.GENERIC_MAX_HEALTH).getBaseValue());
} }
public String getLabel() { public String getLabel() {

View file

@ -1,20 +1,40 @@
/*
* 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.command; package net.tylermurphy.hideAndSeek.command;
import static net.tylermurphy.hideAndSeek.configuration.Config.*; import static net.tylermurphy.hideAndSeek.configuration.Config.*;
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.Bukkit;
import org.bukkit.Location; 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 net.tylermurphy.hideAndSeek.Main;
import net.tylermurphy.hideAndSeek.util.Util;
import static net.tylermurphy.hideAndSeek.configuration.Localization.*; import static net.tylermurphy.hideAndSeek.configuration.Localization.*;
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(!Util.isSetup()) { if(Game.isNotSetup()) {
sender.sendMessage(errorPrefix + message("GAME_SETUP")); sender.sendMessage(errorPrefix + message("GAME_SETUP"));
return; return;
} }
@ -23,20 +43,20 @@ public class Leave implements ICommand {
sender.sendMessage(errorPrefix + message("COMMAND_ERROR")); sender.sendMessage(errorPrefix + message("COMMAND_ERROR"));
return; return;
} }
if(!Main.plugin.board.isPlayer(player)) { if(!Board.isPlayer(player)) {
sender.sendMessage(errorPrefix + message("GAME_NOT_INGAME")); sender.sendMessage(errorPrefix + message("GAME_NOT_INGAME"));
return; return;
} }
if(announceMessagesToNonPlayers) Bukkit.broadcastMessage(messagePrefix + message("GAME_LEAVE").addPlayer(player)); if(announceMessagesToNonPlayers) Bukkit.broadcastMessage(messagePrefix + message("GAME_LEAVE").addPlayer(player));
else Util.broadcastMessage(messagePrefix + message("GAME_LEAVE").addPlayer(player)); else Game.broadcastMessage(messagePrefix + message("GAME_LEAVE").addPlayer(player));
Main.plugin.board.removeBoard(player); Board.removeBoard(player);
Main.plugin.board.remove(player); Board.remove(player);
player.teleport(new Location(Bukkit.getWorld(exitWorld), exitPosition.getX(), exitPosition.getY(), exitPosition.getZ())); player.teleport(new Location(Bukkit.getWorld(exitWorld), exitPosition.getX(), exitPosition.getY(), exitPosition.getZ()));
if(Main.plugin.status.equals("Standby")) { if(Game.status == Status.STANDBY) {
Main.plugin.board.reloadLobbyBoards(); Board.reloadLobbyBoards();
} else { } else {
Main.plugin.board.reloadGameBoards(); Board.reloadGameBoards();
Main.plugin.board.reloadBoardTeams(); Board.reloadBoardTeams();
} }
} }

View file

@ -1,11 +1,31 @@
/*
* 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.command; package net.tylermurphy.hideAndSeek.command;
import static net.tylermurphy.hideAndSeek.configuration.Config.*; import static net.tylermurphy.hideAndSeek.configuration.Config.*;
import net.tylermurphy.hideAndSeek.configuration.Items; import net.tylermurphy.hideAndSeek.configuration.Items;
import net.tylermurphy.hideAndSeek.game.Game;
import net.tylermurphy.hideAndSeek.util.Status;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import net.tylermurphy.hideAndSeek.Main;
import net.tylermurphy.hideAndSeek.configuration.Config; import net.tylermurphy.hideAndSeek.configuration.Config;
import net.tylermurphy.hideAndSeek.configuration.Localization; import net.tylermurphy.hideAndSeek.configuration.Localization;
@ -15,7 +35,7 @@ public class Reload implements ICommand {
public void execute(CommandSender sender, String[] args) { public void execute(CommandSender sender, String[] args) {
if(!Main.plugin.status.equals("Standby")) { if(Game.status != Status.STANDBY) {
sender.sendMessage(errorPrefix + message("GAME_INPROGRESS")); sender.sendMessage(errorPrefix + message("GAME_INPROGRESS"));
return; return;
} }

View file

@ -1,8 +1,30 @@
/*
* 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.command; package net.tylermurphy.hideAndSeek.command;
import static net.tylermurphy.hideAndSeek.configuration.Config.*; import static net.tylermurphy.hideAndSeek.configuration.Config.*;
import net.tylermurphy.hideAndSeek.game.Game;
import net.tylermurphy.hideAndSeek.util.Status;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.World;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.scheduler.BukkitRunnable; import org.bukkit.scheduler.BukkitRunnable;
@ -14,7 +36,7 @@ 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(!Main.plugin.status.equals("Standby")) { if(Game.status != Status.STANDBY) {
sender.sendMessage(errorPrefix + message("GAME_INPROGRESS")); sender.sendMessage(errorPrefix + message("GAME_INPROGRESS"));
return; return;
} }
@ -24,11 +46,15 @@ public class SaveMap implements ICommand {
} }
sender.sendMessage(messagePrefix + message("MAPSAVE_START")); sender.sendMessage(messagePrefix + message("MAPSAVE_START"));
sender.sendMessage(warningPrefix + message("MAPSAVE_WARNING")); sender.sendMessage(warningPrefix + message("MAPSAVE_WARNING"));
Bukkit.getServer().getWorld(spawnWorld).save(); World world = Bukkit.getServer().getWorld(spawnWorld);
if(world == null){
throw new RuntimeException("Unable to get world: " + spawnWorld);
}
world.save();
BukkitRunnable runnable = new BukkitRunnable() { BukkitRunnable runnable = new BukkitRunnable() {
public void run() { public void run() {
sender.sendMessage( sender.sendMessage(
Main.plugin.worldLoader.save() Game.worldLoader.save()
); );
runningBackup = false; runningBackup = false;
} }

View file

@ -1,22 +1,38 @@
/*
* 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.command; package net.tylermurphy.hideAndSeek.command;
import static net.tylermurphy.hideAndSeek.configuration.Config.*; import static net.tylermurphy.hideAndSeek.configuration.Config.*;
import java.util.HashMap; import net.tylermurphy.hideAndSeek.game.Game;
import java.util.Map; 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 net.tylermurphy.hideAndSeek.Main;
import net.tylermurphy.hideAndSeek.events.Worldborder;
import static net.tylermurphy.hideAndSeek.configuration.Localization.*; import static net.tylermurphy.hideAndSeek.configuration.Localization.*;
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(!Main.plugin.status.equals("Standby")) { if(Game.status != Status.STANDBY) {
sender.sendMessage(errorPrefix + message("GAME_INPROGRESS")); sender.sendMessage(errorPrefix + message("GAME_INPROGRESS"));
return; return;
} }
@ -29,7 +45,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"));
Worldborder.resetWorldborder(spawnWorld); Game.resetWorldborder(spawnWorld);
return; return;
} }
int num,delay; int num,delay;
@ -65,7 +81,7 @@ public class SetBorder implements ICommand {
addToConfig("worldBorder.enabled", true); addToConfig("worldBorder.enabled", true);
sender.sendMessage(messagePrefix + message("WORLDBORDER_ENABLE").addAmount(num).addAmount(delay)); sender.sendMessage(messagePrefix + message("WORLDBORDER_ENABLE").addAmount(num).addAmount(delay));
saveConfig(); saveConfig();
Worldborder.resetWorldborder(spawnWorld); Game.resetWorldborder(spawnWorld);
} }
public String getLabel() { public String getLabel() {

View file

@ -1,17 +1,37 @@
/*
* 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.command; package net.tylermurphy.hideAndSeek.command;
import static net.tylermurphy.hideAndSeek.configuration.Config.*; import static net.tylermurphy.hideAndSeek.configuration.Config.*;
import net.tylermurphy.hideAndSeek.game.Game;
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 net.tylermurphy.hideAndSeek.Main;
import static net.tylermurphy.hideAndSeek.configuration.Localization.*; import static net.tylermurphy.hideAndSeek.configuration.Localization.*;
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(!Main.plugin.status.equals("Standby")) { if(Game.status != Status.STANDBY) {
sender.sendMessage(errorPrefix + message("GAME_INPROGRESS")); sender.sendMessage(errorPrefix + message("GAME_INPROGRESS"));
return; return;
} }

View file

@ -1,21 +1,39 @@
/*
* 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.command; package net.tylermurphy.hideAndSeek.command;
import static net.tylermurphy.hideAndSeek.configuration.Config.*; import static net.tylermurphy.hideAndSeek.configuration.Config.*;
import java.util.HashMap; import net.tylermurphy.hideAndSeek.game.Game;
import java.util.Map; import net.tylermurphy.hideAndSeek.util.Status;
import org.bukkit.World;
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 net.tylermurphy.hideAndSeek.Main;
import static net.tylermurphy.hideAndSeek.configuration.Localization.*; import static net.tylermurphy.hideAndSeek.configuration.Localization.*;
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(!Main.plugin.status.equals("Standby")) { if(Game.status != Status.STANDBY) {
sender.sendMessage(errorPrefix + message("GAME_INPROGRESS")); sender.sendMessage(errorPrefix + message("GAME_INPROGRESS"));
return; return;
} }
@ -28,7 +46,11 @@ public class SetExitLocation implements ICommand {
newExitPosition.setX(player.getLocation().getBlockX()); newExitPosition.setX(player.getLocation().getBlockX());
newExitPosition.setY(player.getLocation().getBlockY()); newExitPosition.setY(player.getLocation().getBlockY());
newExitPosition.setZ(player.getLocation().getBlockZ()); newExitPosition.setZ(player.getLocation().getBlockZ());
exitWorld = player.getLocation().getWorld().getName(); World world = player.getLocation().getWorld();
if(world == null){
throw new RuntimeException("Unable to get world: " + spawnWorld);
}
exitWorld = world.getName();
exitPosition = newExitPosition; exitPosition = newExitPosition;
sender.sendMessage(messagePrefix + message("EXIT_SPAWN")); sender.sendMessage(messagePrefix + message("EXIT_SPAWN"));
addToConfig("spawns.exit.x", exitPosition.getX()); addToConfig("spawns.exit.x", exitPosition.getX());

View file

@ -1,21 +1,39 @@
/*
* 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.command; package net.tylermurphy.hideAndSeek.command;
import static net.tylermurphy.hideAndSeek.configuration.Config.*; import static net.tylermurphy.hideAndSeek.configuration.Config.*;
import java.util.HashMap; import net.tylermurphy.hideAndSeek.game.Game;
import java.util.Map; import net.tylermurphy.hideAndSeek.util.Status;
import org.bukkit.World;
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 net.tylermurphy.hideAndSeek.Main;
import static net.tylermurphy.hideAndSeek.configuration.Localization.*; import static net.tylermurphy.hideAndSeek.configuration.Localization.*;
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(!Main.plugin.status.equals("Standby")) { if(Game.status != Status.STANDBY) {
sender.sendMessage(errorPrefix + message("GAME_INPROGRESS")); sender.sendMessage(errorPrefix + message("GAME_INPROGRESS"));
return; return;
} }
@ -28,7 +46,11 @@ public class SetLobbyLocation implements ICommand {
newLobbyPosition.setX(player.getLocation().getBlockX()); newLobbyPosition.setX(player.getLocation().getBlockX());
newLobbyPosition.setY(player.getLocation().getBlockY()); newLobbyPosition.setY(player.getLocation().getBlockY());
newLobbyPosition.setZ(player.getLocation().getBlockZ()); newLobbyPosition.setZ(player.getLocation().getBlockZ());
lobbyWorld = player.getLocation().getWorld().getName(); World world = player.getLocation().getWorld();
if(world == null){
throw new RuntimeException("Unable to get world: " + spawnWorld);
}
lobbyWorld = world.getName();
lobbyPosition = newLobbyPosition; lobbyPosition = newLobbyPosition;
sender.sendMessage(messagePrefix + message("LOBBY_SPAWN")); sender.sendMessage(messagePrefix + message("LOBBY_SPAWN"));
addToConfig("spawns.lobby.x", lobbyPosition.getX()); addToConfig("spawns.lobby.x", lobbyPosition.getX());

View file

@ -1,23 +1,41 @@
/*
* 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.command; package net.tylermurphy.hideAndSeek.command;
import static net.tylermurphy.hideAndSeek.configuration.Config.*; import static net.tylermurphy.hideAndSeek.configuration.Config.*;
import java.util.HashMap; import net.tylermurphy.hideAndSeek.game.Game;
import java.util.Map; import net.tylermurphy.hideAndSeek.util.Status;
import net.tylermurphy.hideAndSeek.world.WorldLoader;
import org.bukkit.World;
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 net.tylermurphy.hideAndSeek.Main;
import static net.tylermurphy.hideAndSeek.configuration.Config.addToConfig; import static net.tylermurphy.hideAndSeek.configuration.Config.addToConfig;
import static net.tylermurphy.hideAndSeek.configuration.Localization.*; import static net.tylermurphy.hideAndSeek.configuration.Localization.*;
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(!Main.plugin.status.equals("Standby")) { if(Game.status != Status.STANDBY) {
sender.sendMessage(errorPrefix + message("GAME_INPROGRESS")); sender.sendMessage(errorPrefix + message("GAME_INPROGRESS"));
return; return;
} }
@ -34,7 +52,15 @@ public class SetSpawnLocation implements ICommand {
sender.sendMessage(errorPrefix + message("WORLDBORDER_POSITION")); sender.sendMessage(errorPrefix + message("WORLDBORDER_POSITION"));
return; return;
} }
spawnWorld = player.getLocation().getWorld().getName(); World world = player.getLocation().getWorld();
if(world == null){
throw new RuntimeException("Unable to get world: " + spawnWorld);
}
if(!world.getName().equals(spawnWorld)){
Game.worldLoader.unloadMap();
Game.worldLoader = new WorldLoader(world.getName());
}
spawnWorld = world.getName();
spawnPosition = newSpawnPosition; spawnPosition = newSpawnPosition;
sender.sendMessage(messagePrefix + message("GAME_SPAWN")); sender.sendMessage(messagePrefix + message("GAME_SPAWN"));
addToConfig("spawns.game.x", spawnPosition.getX()); addToConfig("spawns.game.x", spawnPosition.getX());

View file

@ -1,3 +1,22 @@
/*
* 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.command; package net.tylermurphy.hideAndSeek.command;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
@ -17,24 +36,24 @@ public class Setup implements ICommand {
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").toString(); 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").toString(); 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").toString(); 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").toString(); msg = msg + "\n" + message("SETUP_BOUNDS");
count++; count++;
} }
File destenation = new File(Main.root+File.separator+"hideandseek_"+spawnWorld); File destenation = new File(Main.root+File.separator+"hideandseek_"+spawnWorld);
if(!destenation.exists()) { if(!destenation.exists()) {
msg = msg + "\n" + message("SETUP_SAVEMAP").toString(); msg = msg + "\n" + message("SETUP_SAVEMAP");
count++; count++;
} }
if(count < 1) { if(count < 1) {

View file

@ -1,140 +1,75 @@
/*
* 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.command; package net.tylermurphy.hideAndSeek.command;
import static net.tylermurphy.hideAndSeek.configuration.Localization.*; import static net.tylermurphy.hideAndSeek.configuration.Localization.*;
import org.bukkit.Bukkit; import net.tylermurphy.hideAndSeek.game.Board;
import org.bukkit.GameMode; import net.tylermurphy.hideAndSeek.game.Game;
import org.bukkit.Location; import net.tylermurphy.hideAndSeek.util.Status;
import org.bukkit.Material;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.inventory.meta.PotionMeta;
import org.bukkit.potion.PotionData;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
import org.bukkit.potion.PotionType;
import net.md_5.bungee.api.ChatColor;
import net.tylermurphy.hideAndSeek.Main; import net.tylermurphy.hideAndSeek.Main;
import net.tylermurphy.hideAndSeek.events.Glow;
import net.tylermurphy.hideAndSeek.events.Taunt;
import net.tylermurphy.hideAndSeek.events.Worldborder;
import net.tylermurphy.hideAndSeek.util.Util;
import static net.tylermurphy.hideAndSeek.configuration.Config.*; import static net.tylermurphy.hideAndSeek.configuration.Config.*;
import java.util.ArrayList; import java.util.Optional;
import java.util.List;
import java.util.Random; import java.util.Random;
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(!Util.isSetup()) { if(Game.isNotSetup()) {
sender.sendMessage(errorPrefix + message("GAME_SETUP")); sender.sendMessage(errorPrefix + message("GAME_SETUP"));
return; return;
} }
if(!Main.plugin.status.equals("Standby")) { if(Game.status != Status.STANDBY) {
sender.sendMessage(errorPrefix + message("GAME_INPROGRESS")); sender.sendMessage(errorPrefix + message("GAME_INPROGRESS"));
return; return;
} }
if(!Main.plugin.board.isPlayer(sender)) { if(!Board.isPlayer(sender)) {
sender.sendMessage(errorPrefix + message("GAME_NOT_INGAME")); sender.sendMessage(errorPrefix + message("GAME_NOT_INGAME"));
return; return;
} }
if(Main.plugin.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;
} }
if(Bukkit.getServer().getWorld("hideandseek_"+spawnWorld) != null) {
Main.plugin.worldLoader.rollback();
} else {
Main.plugin.worldLoader.loadMap();
}
String seekerName; String seekerName;
if(args.length < 1) { if(args.length < 1) {
seekerName = Main.plugin.board.getPlayers().stream().skip(new Random().nextInt(Main.plugin.board.size())).findFirst().get().getName(); Optional<Player> rand = Board.getPlayers().stream().skip(new Random().nextInt(Board.size())).findFirst();
if(!rand.isPresent()){
Main.plugin.getLogger().warning("Failed to select random seeker.");
return;
}
seekerName = rand.get().getName();
} else { } else {
seekerName = args[0]; seekerName = args[0];
} }
Player seeker = Main.plugin.board.getPlayer(seekerName); Player seeker = Board.getPlayer(seekerName);
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;
} }
Main.plugin.board.reload(); Game.start(seeker);
for(Player temp : Main.plugin.board.getPlayers()) {
if(temp.getName().equals(seeker.getName()))
continue;
Main.plugin.board.addHider(temp);
}
Main.plugin.board.addSeeker(seeker);
currentWorldborderSize = worldborderSize;
for(Player player : Main.plugin.board.getPlayers()) {
player.getInventory().clear();
player.setGameMode(GameMode.ADVENTURE);
player.teleport(new Location(Bukkit.getWorld("hideandseek_"+spawnWorld), spawnPosition.getX(),spawnPosition.getY(),spawnPosition.getZ()));
for(PotionEffect effect : player.getActivePotionEffects()){
player.removePotionEffect(effect.getType());
}
}
for(Player player : Main.plugin.board.getSeekers()) {
player.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS,1000000,127,false,false));
player.addPotionEffect(new PotionEffect(PotionEffectType.SLOW,1000000,127,false,false));
player.sendTitle(ChatColor.RED + "" + ChatColor.BOLD + "SEEKER", ChatColor.WHITE + message("SEEKERS_SUBTITLE").toString(), 10, 70, 20);
}
for(Player player : Main.plugin.board.getHiders()) {
player.addPotionEffect(new PotionEffect(PotionEffectType.SPEED,1000000,5,false,false));
player.sendTitle(ChatColor.GOLD + "" + ChatColor.BOLD + "HIDER", ChatColor.WHITE + message("HIDERS_SUBTITLE").toString(), 10, 70, 20);
}
Worldborder.resetWorldborder("hideandseek_"+spawnWorld);
for(Player player : Main.plugin.board.getPlayers()){
Main.plugin.board.createGameBoard(player);
}
Main.plugin.board.reloadGameBoards();
Main.plugin.status = "Starting";
int temp = Main.plugin.gameId;
Util.broadcastMessage(messagePrefix + message("START_COUNTDOWN").addAmount(30));
Util.sendDelayedMessage(messagePrefix + message("START_COUNTDOWN").addAmount(20), Main.plugin.gameId, 20 * 10);
Util.sendDelayedMessage(messagePrefix + message("START_COUNTDOWN").addAmount(10), Main.plugin.gameId, 20 * 20);
Util.sendDelayedMessage(messagePrefix + message("START_COUNTDOWN").addAmount(5), Main.plugin.gameId, 20 * 25);
Util.sendDelayedMessage(messagePrefix + message("START_COUNTDOWN").addAmount(3), Main.plugin.gameId, 20 * 27);
Util.sendDelayedMessage(messagePrefix + message("START_COUNTDOWN").addAmount(2), Main.plugin.gameId, 20 * 28);
Util.sendDelayedMessage(messagePrefix + message("START_COUNTDOWN").addAmount(1), Main.plugin.gameId, 20 * 29);
Bukkit.getServer().getScheduler().runTaskLater(Main.plugin, new Runnable() {
public void run() {
if(temp != Main.plugin.gameId) return;
Util.broadcastMessage(messagePrefix + message("START"));
Main.plugin.status = "Playing";
for(Player player : Main.plugin.board.getPlayers()) {
Util.resetPlayer(player);
}
Main.plugin.worldborder = null;
Main.plugin.taunt = null;
Main.plugin.glow = null;
if(worldborderEnabled) {
Main.plugin.worldborder = new Worldborder(Main.plugin.gameId);
Main.plugin.worldborder.schedule();
}
if(tauntEnabled) {
Main.plugin.taunt = new Taunt(Main.plugin.gameId);
Main.plugin.taunt.schedule();
}
if (glowEnabled) {
Main.plugin.glow = new Glow(Main.plugin.gameId);
}
if(gameLength > 0) {
Main.plugin.timeLeft = gameLength;
}
}
}, 20 * 30);
} }
public String getLabel() { public String getLabel() {

View file

@ -1,36 +1,47 @@
/*
* 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.command; package net.tylermurphy.hideAndSeek.command;
import static net.tylermurphy.hideAndSeek.configuration.Config.*; import static net.tylermurphy.hideAndSeek.configuration.Config.*;
import net.tylermurphy.hideAndSeek.game.Game;
import net.tylermurphy.hideAndSeek.util.Status;
import net.tylermurphy.hideAndSeek.util.WinType;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.GameMode;
import org.bukkit.Location;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
import net.tylermurphy.hideAndSeek.Main;
import net.tylermurphy.hideAndSeek.events.Worldborder;
import net.tylermurphy.hideAndSeek.util.Packet;
import net.tylermurphy.hideAndSeek.util.Util;
import static net.tylermurphy.hideAndSeek.configuration.Localization.*; import static net.tylermurphy.hideAndSeek.configuration.Localization.*;
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(!Util.isSetup()) { 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(Main.plugin.status.equals("Starting") || Main.plugin.status.equals("Playing")) { if(Game.status == Status.STARTING || Game.status == Status.PLAYING) {
if(announceMessagesToNonPlayers) Bukkit.broadcastMessage(abortPrefix + message("STOP")); if(announceMessagesToNonPlayers) Bukkit.broadcastMessage(abortPrefix + message("STOP"));
else Util.broadcastMessage(abortPrefix + message("STOP")); else Game.broadcastMessage(abortPrefix + message("STOP"));
onStop(); Game.stop(WinType.NONE);
} else { } else {
sender.sendMessage(errorPrefix + message("GAME_NOT_INPROGRESS")); sender.sendMessage(errorPrefix + message("GAME_NOT_INPROGRESS"));
return;
} }
} }
@ -38,30 +49,6 @@ public class Stop implements ICommand {
return "stop"; return "stop";
} }
public static void onStop() {
if(Main.plugin.status.equals("Standby")) return;
Main.plugin.status = "Standby";
Main.plugin.gameId++;
Main.plugin.timeLeft = 0;
Worldborder.resetWorldborder("hideandseek_"+spawnWorld);
for(Player player : Main.plugin.board.getPlayers()) {
Main.plugin.board.createLobbyBoard(player);
player.setGameMode(GameMode.ADVENTURE);
Main.plugin.board.addHider(player);
player.getInventory().clear();
player.teleport(new Location(Bukkit.getWorld(lobbyWorld), lobbyPosition.getX(),lobbyPosition.getY(),lobbyPosition.getZ()));
for(PotionEffect effect : player.getActivePotionEffects()){
player.removePotionEffect(effect.getType());
}
player.addPotionEffect(new PotionEffect(PotionEffectType.HEAL, 1, 100));
for(Player temp : Main.plugin.board.getPlayers()) {
Packet.setGlow(player, temp, false);
}
}
Main.plugin.worldLoader.unloadMap();
Main.plugin.board.reloadLobbyBoards();
}
public String getUsage() { public String getUsage() {
return ""; return "";
} }

View file

@ -0,0 +1,80 @@
/*
* 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.command;
import net.tylermurphy.hideAndSeek.Main;
import net.tylermurphy.hideAndSeek.database.Database;
import net.tylermurphy.hideAndSeek.database.PlayerInfo;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import java.util.List;
import static net.tylermurphy.hideAndSeek.configuration.Config.*;
import static net.tylermurphy.hideAndSeek.configuration.Localization.*;
public class Top implements ICommand {
public void execute(CommandSender sender, String[] args) {
int page;
if(args.length == 0) page = 1;
else try{
page = Integer.parseInt(args[0]);
} catch(Exception e){
sender.sendMessage(errorPrefix + message("WORLDBORDER_INVALID_INPUT").addAmount(args[0]));
return;
}
if(page < 1){
sender.sendMessage(errorPrefix + message("WORLDBORDER_INVALID_INPUT").addAmount(page));
return;
}
StringBuilder message = new StringBuilder(String.format(
"%s------- %sLEADERBOARD %s(Page %s) %s-------\n",
ChatColor.WHITE, ChatColor.BOLD, ChatColor.GRAY, page, ChatColor.WHITE));
List<PlayerInfo> infos = Database.playerInfo.getInfoPage(page);
int i = 1 + (page-1)*10;
for(PlayerInfo info : infos){
String name = Main.plugin.getServer().getOfflinePlayer(info.uuid).getName();
ChatColor color;
switch (i){
case 1: color = ChatColor.YELLOW; break;
case 2: color = ChatColor.GRAY; break;
case 3: color = ChatColor.GOLD; break;
default: color = ChatColor.WHITE; break;
}
message.append(String.format("%s%s. %s%s %s%s\n",
color, i, ChatColor.RED, info.wins, ChatColor.WHITE, name));
i++;
}
sender.sendMessage(message.toString());
}
public String getLabel() {
return "top";
}
public String getUsage() {
return "<page>";
}
public String getDescription() {
return "Gets the top players in the server.";
}
}

View file

@ -0,0 +1,88 @@
/*
* 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.command;
import net.tylermurphy.hideAndSeek.Main;
import net.tylermurphy.hideAndSeek.database.Database;
import net.tylermurphy.hideAndSeek.database.PlayerInfo;
import net.tylermurphy.hideAndSeek.util.UUIDFetcher;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import java.util.UUID;
import static net.tylermurphy.hideAndSeek.configuration.Config.*;
import static net.tylermurphy.hideAndSeek.configuration.Localization.*;
public class Wins implements ICommand {
public void execute(CommandSender sender, String[] args) {
Main.plugin.getServer().getScheduler().runTaskAsynchronously(Main.plugin, () -> {
UUID uuid;
String name;
if(args.length == 0) {
Player player = Main.plugin.getServer().getPlayer(sender.getName());
if(player == null){
sender.sendMessage(errorPrefix + message("START_INVALID_NAME").addPlayer(sender.getName()));
return;
}
uuid = player.getUniqueId();
name = sender.getName();
}
else {
try {
name = args[0];
uuid = UUIDFetcher.getUUID(args[0]);
} catch (Exception e){
sender.sendMessage(errorPrefix + message("START_INVALID_NAME").addPlayer(args[0]));
return;
}
}
PlayerInfo info = Database.playerInfo.getInfo(uuid);
if(info == null){
sender.sendMessage(errorPrefix + message("NO_GAME_INFO"));
return;
}
String message = ChatColor.WHITE + "" + ChatColor.BOLD + "==============================\n";
message = message + message("INFORMATION_FOR").addPlayer(name) + "\n";
message = message + "==============================\n";
message = message + String.format("%sTOTAL WINS: %s%s\n%sHIDER WINS: %s%s\n%sSEEKER WINS: %s%s\n%sGAMES PLAYED: %s",
ChatColor.YELLOW, ChatColor.WHITE, info.wins, ChatColor.GOLD, ChatColor.WHITE, info.hider_wins,
ChatColor.RED, ChatColor.WHITE, info.seeker_wins, ChatColor.WHITE, info.games_played);
message = message + ChatColor.WHITE + "" + ChatColor.BOLD + "\n==============================";
sender.sendMessage(message);
});
}
public String getLabel() {
return "wins";
}
public String getUsage() {
return "<player>";
}
public String getDescription() {
return "Get the win information for yourself or another player.";
}
}

View file

@ -1,3 +1,22 @@
/*
* 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.configuration; package net.tylermurphy.hideAndSeek.configuration;
import org.bukkit.util.Vector; import org.bukkit.util.Vector;
@ -37,7 +56,8 @@ public class Config {
glowStackable, glowStackable,
pvpEnabled, pvpEnabled,
autoJoin, autoJoin,
teleportToExit; teleportToExit,
lobbyCountdownEnabled;
public static int public static int
minPlayers, minPlayers,
@ -50,7 +70,11 @@ public class Config {
saveMaxX, saveMaxX,
saveMaxZ, saveMaxZ,
tauntDelay, tauntDelay,
glowLength; glowLength,
countdown,
changeCountdown,
lobbyMin,
lobbyMax;
public static void loadConfig() { public static void loadConfig() {
@ -121,10 +145,17 @@ public class Config {
glowStackable = manager.getBoolean("glow.stackable"); glowStackable = manager.getBoolean("glow.stackable");
glowEnabled = manager.getBoolean("glow.enabled"); glowEnabled = manager.getBoolean("glow.enabled");
//Lobby
minPlayers = Math.max(2, manager.getInt("minPlayers"));
countdown = Math.max(10,manager.getInt("lobby.countdown"));
changeCountdown = Math.max(minPlayers,manager.getInt("lobby.changeCountdown"));
lobbyMin = Math.max(minPlayers,manager.getInt("lobby.min"));
lobbyMax = manager.getInt("lobby.max");
lobbyCountdownEnabled = manager.getBoolean("lobby.enabled");
//Other //Other
nametagsVisible = manager.getBoolean("nametagsVisible"); nametagsVisible = manager.getBoolean("nametagsVisible");
permissionsRequired = manager.getBoolean("permissionsRequired"); permissionsRequired = manager.getBoolean("permissionsRequired");
minPlayers = Math.max(2, manager.getInt("minPlayers"));
gameLength = manager.getInt("gameLength"); gameLength = manager.getInt("gameLength");
pvpEnabled = manager.getBoolean("pvp"); pvpEnabled = manager.getBoolean("pvp");
autoJoin = manager.getBoolean("autoJoin"); autoJoin = manager.getBoolean("autoJoin");

View file

@ -1,3 +1,22 @@
/*
* 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.configuration; package net.tylermurphy.hideAndSeek.configuration;
import net.tylermurphy.hideAndSeek.Main; import net.tylermurphy.hideAndSeek.Main;
@ -11,17 +30,20 @@ import java.util.Map;
public class ConfigManager { public class ConfigManager {
private File file; private final File file;
private YamlConfiguration config,defaultConfig; private YamlConfiguration config,defaultConfig;
private String defaultFilename; private String defaultFilename;
public ConfigManager(String filename){ public ConfigManager(String filename){
this.file = new File(Main.plugin.getDataFolder(), filename); this.file = new File(Main.data, filename);
this.defaultFilename = file.getName(); this.defaultFilename = file.getName();
File folder = Main.plugin.getDataFolder(); File folder = Main.data;
if(!folder.exists()) if(!folder.exists()){
folder.mkdirs(); if(!folder.mkdirs()){
throw new RuntimeException("Failed to make directory: " + file.getPath());
}
}
if(!file.exists()){ if(!file.exists()){
saveDefaultConfiguration(); saveDefaultConfiguration();
@ -30,18 +52,21 @@ public class ConfigManager {
this.config = YamlConfiguration.loadConfiguration(file); this.config = YamlConfiguration.loadConfiguration(file);
InputStream input = Main.plugin.getResource(file.getName()); InputStream input = Main.plugin.getResource(file.getName());
if(input == null){
throw new RuntimeException("Could not create input stream for "+file.getPath());
}
InputStreamReader reader = new InputStreamReader(input); InputStreamReader reader = new InputStreamReader(input);
this.defaultConfig = YamlConfiguration.loadConfiguration(reader); this.defaultConfig = YamlConfiguration.loadConfiguration(reader);
try{ try{
input.close(); input.close();
reader.close(); reader.close();
} catch (IOException e){} } catch (IOException ignored){}
} }
public ConfigManager(String filename, String defaultFilename){ public ConfigManager(String filename, String defaultFilename){
this.defaultFilename = defaultFilename; this.defaultFilename = defaultFilename;
this.file = new File(Main.plugin.getDataFolder(), filename); this.file = new File(Main.data, filename);
if(!file.exists()){ if(!file.exists()){
saveDefaultConfiguration(); saveDefaultConfiguration();
@ -50,6 +75,9 @@ public class ConfigManager {
this.config = YamlConfiguration.loadConfiguration(file); this.config = YamlConfiguration.loadConfiguration(file);
InputStream input = Main.plugin.getResource(defaultFilename); InputStream input = Main.plugin.getResource(defaultFilename);
if(input == null){
throw new RuntimeException("Could not create input stream for "+defaultFilename);
}
InputStreamReader reader = new InputStreamReader(input); InputStreamReader reader = new InputStreamReader(input);
this.defaultConfig = YamlConfiguration.loadConfiguration(reader); this.defaultConfig = YamlConfiguration.loadConfiguration(reader);
try{ try{
@ -65,6 +93,9 @@ public class ConfigManager {
private void saveDefaultConfiguration(){ private void saveDefaultConfiguration(){
try{ try{
InputStream input = Main.plugin.getResource(defaultFilename); InputStream input = Main.plugin.getResource(defaultFilename);
if(input == null){
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){
@ -72,10 +103,6 @@ public class ConfigManager {
} }
} }
public void addToConfig(String path, Object value) {
config.set(path, value);
}
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){
@ -111,6 +138,9 @@ public class ConfigManager {
this.defaultFilename = newDefaultFilename; this.defaultFilename = newDefaultFilename;
InputStream input = Main.plugin.getResource(defaultFilename); InputStream input = Main.plugin.getResource(defaultFilename);
if(input == null){
throw new RuntimeException("Could not create input stream for "+defaultFilename);
}
InputStreamReader reader = new InputStreamReader(input); InputStreamReader reader = new InputStreamReader(input);
this.config = YamlConfiguration.loadConfiguration(reader); this.config = YamlConfiguration.loadConfiguration(reader);
this.defaultConfig = YamlConfiguration.loadConfiguration(reader); this.defaultConfig = YamlConfiguration.loadConfiguration(reader);
@ -119,7 +149,7 @@ public class ConfigManager {
public boolean getBoolean(String path){ public boolean getBoolean(String path){
boolean value = config.getBoolean(path); boolean value = config.getBoolean(path);
if(value == false){ if(!value){
return defaultConfig.getBoolean(path); return defaultConfig.getBoolean(path);
} else { } else {
return true; return true;
@ -142,9 +172,12 @@ public class ConfigManager {
public void saveConfig(){ public void saveConfig(){
try { try {
InputStream is = Main.plugin.getResource(defaultFilename); InputStream is = Main.plugin.getResource(defaultFilename);
if(is == null){
throw new RuntimeException("Could not create input stream for "+defaultFilename);
}
StringBuilder textBuilder = new StringBuilder(); StringBuilder textBuilder = new StringBuilder();
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 = 0; int c;
while((c = reader.read()) != -1){ while((c = reader.read()) != -1){
textBuilder.append((char) c); textBuilder.append((char) c);
} }
@ -165,7 +198,7 @@ public class ConfigManager {
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();
@ -173,7 +206,6 @@ public class ConfigManager {
if(entry.getValue() instanceof String){ if(entry.getValue() instanceof String){
replace = "\"" + replace + "\""; replace = "\"" + replace + "\"";
} }
System.out.println(entry.getKey() + " " + index + " " + start + " " + end);
StringBuilder builder = new StringBuilder(yamlString); StringBuilder builder = new StringBuilder(yamlString);
builder.replace(start+1, end, replace); builder.replace(start+1, end, replace);
yamlString = builder.toString(); yamlString = builder.toString();

View file

@ -1,3 +1,22 @@
/*
* 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.configuration; package net.tylermurphy.hideAndSeek.configuration;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
@ -78,6 +97,7 @@ public class Items {
if(material == Material.POTION || material == Material.SPLASH_POTION || material == Material.LINGERING_POTION){ if(material == Material.POTION || material == Material.SPLASH_POTION || material == Material.LINGERING_POTION){
PotionMeta meta = getPotionMeta(stack, item); PotionMeta meta = getPotionMeta(stack, item);
stack.setItemMeta(meta); stack.setItemMeta(meta);
} else { } else {
ConfigurationSection enchantments = item.getConfigurationSection("enchantments"); ConfigurationSection enchantments = item.getConfigurationSection("enchantments");
if (enchantments != null) if (enchantments != null)

View file

@ -1,3 +1,22 @@
/*
* 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.configuration; package net.tylermurphy.hideAndSeek.configuration;
import java.io.File; import java.io.File;
@ -10,7 +29,7 @@ public class Localization {
public static final Map<String,LocalizationString> LOCAL = new HashMap<>(); public static final Map<String,LocalizationString> LOCAL = new HashMap<>();
private static String[][] CHANGES = {{"WORLDBORDER_DECREASING"}}; private static final String[][] CHANGES = {{"WORLDBORDER_DECREASING"}};
public static void loadLocalization() { public static void loadLocalization() {
@ -48,7 +67,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());
} }

View file

@ -1,48 +1,56 @@
/*
* 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.configuration; package net.tylermurphy.hideAndSeek.configuration;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;
public class LocalizationString { public class LocalizationString {
String message; String message;
public LocalizationString(String message) { public LocalizationString(String message) {
this.message = message; this.message = message;
} }
public LocalizationString addPlayer(Entity player) { public LocalizationString addPlayer(Entity player) {
this.message = message.replaceFirst("\\{PLAYER\\}", player.getName()); this.message = message.replaceFirst("\\{PLAYER}", player.getName());
return this; return this;
} }
public LocalizationString addPlayer(CommandSender player) { public LocalizationString addPlayer(String player) {
this.message = message.replaceFirst("\\{PLAYER\\}", player.getName()); this.message = message.replaceFirst("\\{PLAYER}", player);
return this; return this;
} }
public LocalizationString addPlayer(String player) { public LocalizationString addAmount(Integer value) {
this.message = message.replaceFirst("\\{PLAYER\\}", player); this.message = message.replaceFirst("\\{AMOUNT}", value.toString());
return this; return this;
} }
public LocalizationString addAmount(Integer value) { public LocalizationString addAmount(String value) {
this.message = message.replaceFirst("\\{AMOUNT\\}", value.toString()); this.message = message.replaceFirst("\\{AMOUNT}", value);
return this; return this;
} }
public LocalizationString addAmount(String value) { public String toString() {
this.message = message.replaceFirst("\\{AMOUNT\\}", value.toString()); return message;
return this; }
}
}
public LocalizationString addAmount(Float value) {
this.message = message.replaceFirst("\\{AMOUNT\\}", value.toString());
return this;
}
public String toString() {
return message;
}
}

View file

@ -0,0 +1,73 @@
/*
* 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.database;
import com.google.common.io.ByteStreams;
import net.tylermurphy.hideAndSeek.Main;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.nio.ByteBuffer;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.UUID;
public class Database {
private static final File databaseFile = new File(Main.data, "database.db");
public static PlayerInfoTable playerInfo;
protected static Connection connect() {
Connection conn = null;
try {
String url = "jdbc:sqlite:"+databaseFile;
conn = DriverManager.getConnection(url);
} catch (SQLException e) {
System.out.println(e.getMessage());
}
return conn;
}
protected static InputStream convertUniqueId(UUID uuid) {
byte[] bytes = new byte[16];
ByteBuffer.wrap(bytes)
.putLong(uuid.getMostSignificantBits())
.putLong(uuid.getLeastSignificantBits());
return new ByteArrayInputStream(bytes);
}
protected static UUID convertBinaryStream(InputStream stream) {
ByteBuffer buffer = ByteBuffer.allocate(16);
try {
buffer.put(ByteStreams.toByteArray(stream));
buffer.flip();
return new UUID(buffer.getLong(), buffer.getLong());
} catch (IOException ignored) {}
return null;
}
public static void init(){
playerInfo = new PlayerInfoTable();
}
}

View file

@ -0,0 +1,37 @@
/*
* 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.database;
import java.util.UUID;
public class PlayerInfo {
public UUID uuid;
public int wins, hider_wins, seeker_wins, games_played;
public PlayerInfo(UUID uuid, int wins, int hider_wins, int seeker_wins, int games_played){
this.uuid = uuid;
this.wins = wins;
this.hider_wins = hider_wins;
this.seeker_wins = seeker_wins;
this.games_played = games_played;
}
}

View file

@ -0,0 +1,129 @@
/*
* 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.database;
import net.tylermurphy.hideAndSeek.Main;
import net.tylermurphy.hideAndSeek.util.WinType;
import java.io.IOException;
import java.io.InputStream;
import java.sql.*;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
public class PlayerInfoTable {
protected PlayerInfoTable(){
String sql = "CREATE TABLE IF NOT EXISTS player_info (\n"
+ " uuid BINARY(16) PRIMARY KEY,\n"
+ " wins int NOT NULL,\n"
+ " seeker_wins int NOT NULL,\n"
+ " hider_wins int NOT NULL,\n"
+ " games_played int NOT NULL\n"
+ ");";
try(Connection connection = Database.connect(); Statement statement = connection.createStatement()){
statement.execute(sql);
} catch (SQLException e){
Main.plugin.getLogger().severe("SQL Error: " + e.getMessage());
}
}
public PlayerInfo getInfo(UUID uuid){
String sql = "SELECT * FROM player_info WHERE uuid = ?;";
try(Connection connection = Database.connect(); PreparedStatement statement = connection.prepareStatement(sql)){
InputStream is = Database.convertUniqueId(uuid);
byte[] bytes = new byte[is.available()];
if(is.read(bytes) == -1){
throw new IOException("Failed to read bytes from input stream");
}
statement.setBytes(1, bytes);
ResultSet rs = statement.executeQuery();
if(rs.next()){
return new PlayerInfo(
uuid,
rs.getInt("wins"),
rs.getInt("seeker_wins"),
rs.getInt("hider_wins"),
rs.getInt("games_played")
);
}
} catch (SQLException e){
Main.plugin.getLogger().severe("SQL Error: " + e.getMessage());
} catch (IOException e) {
Main.plugin.getLogger().severe("IO Error: " + e.getMessage());
e.printStackTrace();
}
return new PlayerInfo(uuid, 0, 0, 0, 0);
}
public List<PlayerInfo> getInfoPage(int page){
String sql = "SELECT * FROM player_info ORDER BY wins DESC LIMIT 10 OFFSET ?;";
try(Connection connection = Database.connect(); PreparedStatement statement = connection.prepareStatement(sql)){
statement.setInt(1, (page-1)*10);
ResultSet rs = statement.executeQuery();
List<PlayerInfo> infoList = new ArrayList<>();
while(rs.next()){
PlayerInfo info = new PlayerInfo(
Database.convertBinaryStream(rs.getBinaryStream("uuid")),
rs.getInt("wins"),
rs.getInt("seeker_wins"),
rs.getInt("hider_wins"),
rs.getInt("games_played")
);
infoList.add(info);
}
return infoList;
} catch (SQLException e){
Main.plugin.getLogger().severe("SQL Error: " + e.getMessage());
}
return null;
}
public void addWins(List<UUID> uuids, List<UUID> winners, WinType type){
for(UUID uuid : uuids){
String sql = "INSERT OR REPLACE INTO player_info (uuid, wins, seeker_wins, hider_wins, games_played) VALUES (?,?,?,?,?)";
PlayerInfo info = getInfo(uuid);
try(Connection connection = Database.connect(); PreparedStatement statement = connection.prepareStatement(sql)){
InputStream is = Database.convertUniqueId(uuid);
byte[] bytes = new byte[is.available()];
if(is.read(bytes) == -1){
throw new IOException("Failed to read bytes from input stream");
}
statement.setBytes(1, bytes);
statement.setInt(2, info.wins + (winners.contains(uuid) ? 1 : 0));
statement.setInt(3, info.seeker_wins + (winners.contains(uuid) && type == WinType.SEEKER_WIN ? 1 : 0));
statement.setInt(4, info.hider_wins + (winners.contains(uuid) && type == WinType.HIDER_WIN ? 1 : 0));
statement.setInt(5, info.games_played + 1);
statement.execute();
} catch (SQLException e){
Main.plugin.getLogger().severe("SQL Error: " + e.getMessage());
e.printStackTrace();
return;
} catch (IOException e) {
Main.plugin.getLogger().severe("IO Error: " + e.getMessage());
e.printStackTrace();
}
}
}
}

View file

@ -1,65 +0,0 @@
package net.tylermurphy.hideAndSeek.events;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import net.tylermurphy.hideAndSeek.Main;
import net.tylermurphy.hideAndSeek.util.Packet;
import static net.tylermurphy.hideAndSeek.configuration.Config.*;
public class Glow {
private final int temp;
private int glowTime;
private boolean running;
public Glow(int temp) {
this.temp = temp;
this.glowTime = 0;
}
public void onProjectilve() {
if(glowStackable) glowTime += glowLength;
else glowTime = glowLength;
if(!running)
startGlow();
}
private void startGlow() {
running = true;
for(Player hider : Main.plugin.board.getHiders()) {
for(Player seeker : Main.plugin.board.getSeekers()) {
Packet.setGlow(hider, seeker, true);
}
}
waitGlow();
}
private void waitGlow() {
Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(Main.plugin, () -> {
if(temp != Main.plugin.gameId) return;
glowTime--;
glowTime = Math.max(glowTime, 0);
if(glowTime == 0) {
stopGlow();
} else {
waitGlow();
}
}, 20);
}
private void stopGlow() {
running = false;
for(Player hider : Main.plugin.board.getHiders()) {
for (Player seeker : Main.plugin.board.getSeekers()) {
Packet.setGlow(hider, seeker, false);
}
}
}
public boolean isRunning() {
return running;
}
}

View file

@ -1,101 +0,0 @@
package net.tylermurphy.hideAndSeek.events;
import static net.tylermurphy.hideAndSeek.configuration.Config.*;
import org.bukkit.Bukkit;
import org.bukkit.Color;
import org.bukkit.FireworkEffect;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Firework;
import org.bukkit.entity.Player;
import org.bukkit.inventory.meta.FireworkMeta;
import net.tylermurphy.hideAndSeek.Main;
import net.tylermurphy.hideAndSeek.util.Util;
import static net.tylermurphy.hideAndSeek.configuration.Localization.*;
public class Taunt {
private final int temp;
private String tauntPlayer;
private int delay;
private boolean running;
public Taunt(int temp) {
this.temp = temp;
this.delay = 0;
}
public void schedule() {
delay = tauntDelay;
waitTaunt();
}
private void waitTaunt() {
Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(Main.plugin, () -> {
if(delay == 0) {
if(!tauntLast && Main.plugin.board.size() < 2) return;
else executeTaunt();
} else {
delay--;
waitTaunt();
}
},20);
}
private void executeTaunt() {
if(temp != Main.plugin.gameId) return;
Player taunted = null;
int rand = (int) (Math.random()*Main.plugin.board.sizeHider());
for(Player player : Main.plugin.board.getPlayers()) {
if(Main.plugin.board.isHider(player)) {
rand--;
if(rand==0) {
taunted = player;
break;
}
}
}
if(taunted != null) {
running = true;
taunted.sendMessage(message("TAUNTED").toString());
Util.broadcastMessage(tauntPrefix + message("TAUNT"));
tauntPlayer = taunted.getName();
Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(Main.plugin, () -> {
if(temp != Main.plugin.gameId) return;
Player taunted1 = Main.plugin.board.getPlayer(tauntPlayer);
if(taunted1 != null) {
Firework fw = (Firework) taunted1.getLocation().getWorld().spawnEntity(taunted1.getLocation(), EntityType.FIREWORK);
FireworkMeta fwm = fw.getFireworkMeta();
fwm.setPower(4);
fwm.addEffect(FireworkEffect.builder()
.withColor(Color.BLUE)
.withColor(Color.RED)
.withColor(Color.YELLOW)
.with(FireworkEffect.Type.STAR)
.with(FireworkEffect.Type.BALL)
.with(FireworkEffect.Type.BALL_LARGE)
.flicker(true)
.withTrail()
.build());
fw.setFireworkMeta(fwm);
Util.broadcastMessage(tauntPrefix + message("TAUNT_ACTIVATE"));
}
tauntPlayer = "";
running = false;
schedule();
},20*30);
} else {
schedule();
}
}
public int getDelay(){
return delay;
}
public boolean isRunning() {
return running;
}
}

View file

@ -1,74 +0,0 @@
package net.tylermurphy.hideAndSeek.events;
import static net.tylermurphy.hideAndSeek.configuration.Localization.*;
import static net.tylermurphy.hideAndSeek.configuration.Config.*;
import org.bukkit.Bukkit;
import org.bukkit.World;
import org.bukkit.WorldBorder;
import net.tylermurphy.hideAndSeek.Main;
import net.tylermurphy.hideAndSeek.util.Util;
public class Worldborder {
private final int temp;
private int delay;
private boolean running;
public Worldborder(int temp) {
this.temp = temp;
}
public void schedule() {
delay = 60*worldborderDelay;
running = false;
waitBorder();
}
private void waitBorder(){
Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(Main.plugin, () -> {
if(delay == 0) decreaceWorldborder();
else {
delay--; waitBorder();
}
}, 20);
}
private void decreaceWorldborder() {
if(temp != Main.plugin.gameId) return;
if(currentWorldborderSize-100 > 100) {
running = true;
Util.broadcastMessage(worldborderPrefix + message("WORLDBORDER_DECREASING"));
currentWorldborderSize -= 100;
World world = Bukkit.getWorld("hideandseek_"+spawnWorld);
WorldBorder border = world.getWorldBorder();
border.setSize(border.getSize()-100,30);
schedule();
}
}
public static void resetWorldborder(String worldName) {
if(worldborderEnabled) {
World world = Bukkit.getWorld(worldName);
WorldBorder border = world.getWorldBorder();
border.setSize(worldborderSize);
border.setCenter(worldborderPosition.getX(), worldborderPosition.getZ());
currentWorldborderSize = worldborderSize;
} else {
World world = Bukkit.getWorld(worldName);
WorldBorder border = world.getWorldBorder();
border.setSize(30000000);
border.setCenter(0, 0);
}
}
public int getDelay(){
return delay;
}
public boolean isRunning() {
return running;
}
}

View file

@ -0,0 +1,374 @@
/*
* 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 java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import net.tylermurphy.hideAndSeek.util.Status;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.scoreboard.*;
public class Board {
private static final List<String> Hider = new ArrayList<>(), Seeker = new ArrayList<>(), Spectator = new ArrayList<>();
private static final Map<String, Player> playerList = new HashMap<>();
private static final Map<String, CustomBoard> customBoards = new HashMap<>();
public static boolean isPlayer(Player player) {
return playerList.containsKey(player.getName());
}
public static boolean isPlayer(String name){
return playerList.containsKey(name);
}
public static boolean isPlayer(CommandSender sender) {
return playerList.containsKey(sender.getName());
}
public static boolean isHider(Player player) {
return Hider.contains(player.getName());
}
public static boolean isSeeker(Player player) {
return Seeker.contains(player.getName());
}
public static boolean isSpectator(Player player) {
return Spectator.contains(player.getName());
}
public static int sizeHider() {
return Hider.size();
}
public static int sizeSeeker() {
return Seeker.size();
}
public static int size() {
return playerList.values().size();
}
public static List<Player> getHiders(){
return Hider.stream().map(playerList::get).collect(Collectors.toList());
}
public static List<Player> getSeekers(){
return Seeker.stream().map(playerList::get).collect(Collectors.toList());
}
public static Player getFirstSeeker(){
return playerList.get(Seeker.get(0));
}
public static List<Player> getSpectators(){
return Spectator.stream().map(playerList::get).collect(Collectors.toList());
}
public static List<Player> getPlayers(){
return new ArrayList<>(playerList.values());
}
public static Player getPlayer(String name) {
return playerList.get(name);
}
public static void addHider(Player player) {
Hider.add(player.getName());
Seeker.remove(player.getName());
Spectator.remove(player.getName());
playerList.put(player.getName(), player);
}
public static void addSeeker(Player player) {
Hider.remove(player.getName());
Seeker.add(player.getName());
Spectator.remove(player.getName());
playerList.put(player.getName(), player);
}
public static void addSpectator(Player player) {
Hider.remove(player.getName());
Seeker.remove(player.getName());
Spectator.add(player.getName());
playerList.put(player.getName(), player);
}
public static void remove(Player player) {
Hider.remove(player.getName());
Seeker.remove(player.getName());
Spectator.remove(player.getName());
playerList.remove(player.getName());
}
public static boolean onSameTeam(Player player1, Player player2) {
if(Hider.contains(player1.getName()) && Hider.contains(player2.getName())) return true;
else if(Seeker.contains(player1.getName()) && Seeker.contains(player2.getName())) return true;
else return Spectator.contains(player1.getName()) && Spectator.contains(player2.getName());
}
public static void reload() {
Hider.clear();
Seeker.clear();
Spectator.clear();
}
public static void createLobbyBoard(Player player) {
createLobbyBoard(player, true);
}
private static void createLobbyBoard(Player player, boolean recreate) {
CustomBoard board = customBoards.get(player.getName());
if(recreate) {
board = new CustomBoard(player, "&l&eHIDE AND SEEK");
board.updateTeams();
}
board.setLine("hiders", ChatColor.BOLD + "" + ChatColor.YELLOW + "HIDER %" + ChatColor.WHITE + getHiderPercent());
board.setLine("seekers", ChatColor.BOLD + "" + ChatColor.RED + "SEEKER %" + ChatColor.WHITE + getSeekerPercent());
board.addBlank();
board.setLine("players", "Players: " + playerList.values().size());
board.addBlank();
if(lobbyCountdownEnabled){
if(Game.countdownTime == -1){
board.setLine("waiting", "Waiting for players...");
} else {
board.setLine("waiting", "Starting in: "+ChatColor.GREEN + Game.countdownTime+"s");
}
} else {
board.setLine("waiting", "Waiting for gamemaster...");
}
board.display();
customBoards.put(player.getName(), board);
}
public static void createGameBoard(Player player){
createGameBoard(player, true);
}
private static void createGameBoard(Player player, boolean recreate){
CustomBoard board = customBoards.get(player.getName());
if(recreate) {
board = new CustomBoard(player, "&l&eHIDE AND SEEK");
board.updateTeams();
}
board.setLine("hiders", ChatColor.BOLD + "" + ChatColor.YELLOW + "HIDERS:" + ChatColor.WHITE + " " + Hider.size());
board.setLine("seekers", ChatColor.BOLD + "" + ChatColor.RED + "SEEKERS:" + ChatColor.WHITE + " " + Seeker.size());
board.addBlank();
if(glowEnabled){
if(Game.glow == null || Game.status == Status.STARTING || !Game.glow.isRunning())
board.setLine("glow", "Glow: " + ChatColor.RED + "Inactive");
else
board.setLine("glow", "Glow: " + ChatColor.GREEN + "Active");
}
if(tauntEnabled && tauntCountdown){
if(Game.taunt == null || Game.status == Status.STARTING)
board.setLine("taunt", "Taunt: " + ChatColor.YELLOW + "0m0s");
else if(!tauntLast && Hider.size() == 1){
board.setLine("taunt", "Taunt: " + ChatColor.YELLOW + "Expired");
} else if(!Game.taunt.isRunning())
board.setLine("taunt", "Taunt: " + ChatColor.YELLOW + Game.taunt.getDelay()/60 + "m" + Game.taunt.getDelay()%60 + "s");
else
board.setLine("taunt", "Taunt: " + ChatColor.YELLOW + "Active");
}
if(worldborderEnabled){
if(Game.worldBorder == null || Game.status == Status.STARTING){
board.setLine("board", "WorldBorder: " + ChatColor.YELLOW + "0m0s");
} else if(!Game.worldBorder.isRunning()) {
board.setLine("board", "WorldBorder: " + ChatColor.YELLOW + Game.worldBorder.getDelay()/60 + "m" + Game.worldBorder.getDelay()%60 + "s");
} else {
board.setLine("board", "WorldBorder: " + ChatColor.YELLOW + "Decreasing");
}
}
if(glowEnabled || (tauntEnabled && tauntCountdown) || worldborderEnabled)
board.addBlank();
board.setLine("time", "Time Left: " + ChatColor.GREEN + Game.timeLeft/60 + "m" + Game.timeLeft%60 + "s");
board.addBlank();
board.setLine("team", "Team: " + getTeam(player));
board.display();
customBoards.put(player.getName(), board);
}
public static void removeBoard(Player player) {
ScoreboardManager manager = Bukkit.getScoreboardManager();
assert manager != null;
player.setScoreboard(manager.getMainScoreboard());
customBoards.remove(player.getName());
}
public static void reloadLobbyBoards() {
for(Player player : playerList.values())
createLobbyBoard(player, false);
}
public static void reloadGameBoards() {
for(Player player : playerList.values())
createGameBoard(player, false);
}
public static void reloadBoardTeams() {
for(CustomBoard board : customBoards.values())
board.updateTeams();
}
private static String getSeekerPercent() {
if(playerList.values().size() < 2)
return " --";
else
return " "+(int)(100*(1.0/playerList.size()));
}
private static String getHiderPercent() {
if(playerList.size() < 2)
return " --";
else
return " "+(int)(100-100*(1.0/playerList.size()));
}
private static String getTeam(Player player) {
if(isHider(player)) return ChatColor.GOLD + "HIDER";
else if(isSeeker(player)) return ChatColor.RED + "SEEKER";
else if(isSpectator(player)) return ChatColor.GRAY + "SPECTATOR";
else return ChatColor.WHITE + "UNKNOWN";
}
}
class CustomBoard {
private final Scoreboard board;
private final Objective obj;
private final Player player;
private final Map<String,Line> LINES;
private int blanks;
private boolean displayed;
public CustomBoard(Player player, String title){
ScoreboardManager manager = Bukkit.getScoreboardManager();
assert manager != null;
this.board = manager.getNewScoreboard();
this.LINES = new HashMap<>();
this.player = player;
this.obj = board.registerNewObjective(
"Scoreboard", "dummy", ChatColor.translateAlternateColorCodes('&', title));
this.blanks = 0;
this.displayed = false;
this.updateTeams();
}
public void updateTeams() {
try{ board.registerNewTeam("Hider"); } catch (Exception ignored){}
try{ board.registerNewTeam("Seeker"); } catch (Exception ignored){}
Team hiderTeam = board.getTeam("Hider");
assert hiderTeam != null;
for(String entry : hiderTeam.getEntries())
hiderTeam.removeEntry(entry);
for(Player player : Board.getHiders())
hiderTeam.addEntry(player.getName());
Team seekerTeam = board.getTeam("Seeker");
assert seekerTeam != null;
for(String entry : seekerTeam.getEntries())
seekerTeam.removeEntry(entry);
for(Player player : Board.getSeekers())
seekerTeam.addEntry(player.getName());
if(nametagsVisible) {
hiderTeam.setOption(Team.Option.NAME_TAG_VISIBILITY, Team.OptionStatus.FOR_OWN_TEAM);
seekerTeam.setOption(Team.Option.NAME_TAG_VISIBILITY, Team.OptionStatus.FOR_OTHER_TEAMS);
} else {
hiderTeam.setOption(Team.Option.NAME_TAG_VISIBILITY, Team.OptionStatus.NEVER);
seekerTeam.setOption(Team.Option.NAME_TAG_VISIBILITY, Team.OptionStatus.NEVER);
}
hiderTeam.setColor(ChatColor.GOLD);
seekerTeam.setColor(ChatColor.RED);
}
public void setLine(String key, String message){
Line line = LINES.get(key);
if(line == null)
addLine(key, message);
else
updateLine(key, message);
}
private void addLine(String key, String message){
Score score = obj.getScore(message);
score.setScore(LINES.values().size()+1);
Line line = new Line(LINES.values().size()+1, message);
LINES.put(key, line);
}
public void addBlank(){
if(displayed) return;
StringBuilder temp = new StringBuilder();
for(int i = 0; i <= blanks; i ++)
temp.append(ChatColor.RESET);
blanks++;
addLine("blank"+blanks, temp.toString());
}
private void updateLine(String key, String message){
Line line = LINES.get(key);
board.resetScores(line.getMessage());
line.setMessage(message);
Score newScore = obj.getScore(message);
newScore.setScore(line.getScore());
}
public void display() {
displayed = true;
obj.setDisplaySlot(DisplaySlot.SIDEBAR);
player.setScoreboard(board);
}
}
class Line {
private final int score;
private String message;
public Line(int score, String message){
this.score = score;
this.message = message;
}
public int getScore() {
return score;
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
}

View file

@ -1,4 +1,23 @@
package net.tylermurphy.hideAndSeek.bukkit; /*
* 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 static net.tylermurphy.hideAndSeek.configuration.Config.*;
import static net.tylermurphy.hideAndSeek.configuration.Localization.*; import static net.tylermurphy.hideAndSeek.configuration.Localization.*;
@ -7,7 +26,6 @@ import java.util.Arrays;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.Map; import java.util.Map;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -15,7 +33,7 @@ import net.tylermurphy.hideAndSeek.command.*;
public class CommandHandler { public class CommandHandler {
public static Map<String,ICommand> COMMAND_REGISTER = new LinkedHashMap<String,ICommand>(); public static 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())) {
@ -38,10 +56,12 @@ public class CommandHandler {
registerCommand(new SetBounds()); registerCommand(new SetBounds());
registerCommand(new Join()); registerCommand(new Join());
registerCommand(new Leave()); registerCommand(new Leave());
registerCommand(new Top());
registerCommand(new Wins());
} }
public static boolean handleCommand(CommandSender sender, Command cmd, String label, String[] args) { public static boolean handleCommand(CommandSender sender, String[] args) {
if(sender instanceof Player == false) { 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")) {
@ -50,7 +70,7 @@ public class CommandHandler {
COMMAND_REGISTER.get("about").execute(sender, null); COMMAND_REGISTER.get("about").execute(sender, null);
} }
} else { } else {
if(!args[0].toLowerCase().equals("about") && !args[0].toLowerCase().equals("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"));
@ -66,8 +86,4 @@ public class CommandHandler {
return true; return true;
} }
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
return CommandHandler.handleCommand(sender, command, label, args);
}
} }

View file

@ -0,0 +1,264 @@
/*
* 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 net.tylermurphy.hideAndSeek.Main;
import net.tylermurphy.hideAndSeek.util.Status;
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.Snowball;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.*;
import org.bukkit.event.entity.EntityRegainHealthEvent.RegainReason;
import org.bukkit.event.player.*;
import net.tylermurphy.hideAndSeek.util.Packet;
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("hideandseek_" + spawnWorld) || 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 (event.getPlayer().getWorld().getName().equals("hideandseek_" + spawnWorld)) {
if(Game.status != Status.STANDBY){
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(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(!event.getPlayer().getWorld().getName().equals("hideandseek_" + spawnWorld)) return;
if(event.getPlayer().hasPermission("hideandseek.leavebounds")) return;
if(event.getTo() == null || event.getTo().getWorld() == null) return;
if(!event.getTo().getWorld().getName().equals("hideandseek_" + spawnWorld)) 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) {
try {
if (event.getEntity() instanceof Player) {
Player player = (Player) event.getEntity();
if (!Board.isPlayer(player)) {
if (event instanceof EntityDamageByEntityEvent) {
Entity damager = ((EntityDamageByEntityEvent) event).getDamager();
if (damager instanceof Player) {
if(Board.isPlayer(damager)){
event.setCancelled(true);
return;
}
}
}
}
if (Game.status != Status.PLAYING) {
event.setCancelled(true);
return;
}
Player attacker = null;
if (event instanceof EntityDamageByEntityEvent) {
Entity damager = ((EntityDamageByEntityEvent) event).getDamager();
if (damager instanceof Player) {
attacker = (Player) damager;
if (Board.onSameTeam(player, attacker)) event.setCancelled(true);
if (Board.isSpectator(player)) event.setCancelled(true);
} else if(damager instanceof Arrow){
ProjectileSource source = ((Arrow) damager).getShooter();
if(source instanceof Player){
attacker = (Player) source;
if (Board.onSameTeam(player, attacker)) event.setCancelled(true);
if (Board.isSpectator(player)) event.setCancelled(true);
}
}
}
if (player.getHealth() - event.getDamage() < 0 || !pvpEnabled) {
if (spawnPosition == null) return;
event.setCancelled(true);
AttributeInstance attribute = player.getAttribute(Attribute.GENERIC_MAX_HEALTH);
if(attribute != null)
player.setHealth(attribute.getValue());
player.teleport(new Location(Bukkit.getWorld("hideandseek_" + spawnWorld), spawnPosition.getX(), spawnPosition.getY(), spawnPosition.getZ()));
Packet.playSound(player, Sound.ENTITY_PLAYER_DEATH, 1, 1);
if (Board.isSeeker(player)) {
Bukkit.broadcastMessage(message("GAME_PLAYER_DEATH").addPlayer(player).toString());
}
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.addSeeker(player);
}
Game.resetPlayer(player);
Board.reloadBoardTeams();
}
}
} catch (Exception e){
Main.plugin.getLogger().severe("Entity Damage Event Error: " + e.getMessage());
}
}
@EventHandler(priority = EventPriority.HIGHEST)
public void onProjectile(ProjectileLaunchEvent event) {
if(Game.status != Status.PLAYING) return;
if(event.getEntity() instanceof Snowball) {
if(!glowEnabled) return;
Snowball snowball = (Snowball) event.getEntity();
if(snowball.getShooter() instanceof Player) {
Player player = (Player) snowball.getShooter();
if(Board.isHider(player)) {
Game.glow.onProjectile();
snowball.remove();
player.getInventory().remove(Material.SNOWBALL);
}
}
}
}
@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(" ");
if(array[0].equalsIgnoreCase("/kill")){
if(Board.isPlayer(player)){
Main.plugin.getLogger().info("Blocking "+player.getName()+ "from running /kill with anyone associated in the lobby");
event.setCancelled(true);
} else if(array.length > 1){
for(int i=1; i<array.length; i++){
if(Board.isPlayer(array[i])){
Main.plugin.getLogger().info("Blocking "+player.getName()+ "from running /kill with anyone associated in the lobby");
event.setCancelled(true);
return;
}
}
}
}
}
}

View file

@ -0,0 +1,543 @@
/*
* This file is part of Kenshins Hide and Seek
*
* Copyright (c) 2020-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 net.md_5.bungee.api.ChatColor;
import net.tylermurphy.hideAndSeek.configuration.Items;
import net.tylermurphy.hideAndSeek.database.Database;
import net.tylermurphy.hideAndSeek.util.Status;
import net.tylermurphy.hideAndSeek.util.WinType;
import net.tylermurphy.hideAndSeek.world.WorldLoader;
import org.bukkit.*;
import org.bukkit.attribute.Attribute;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Firework;
import org.bukkit.entity.Player;
import net.tylermurphy.hideAndSeek.Main;
import net.tylermurphy.hideAndSeek.util.Packet;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.FireworkMeta;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
import java.beans.EventHandler;
import java.io.File;
import java.util.*;
import java.util.stream.Collectors;
import static net.tylermurphy.hideAndSeek.configuration.Localization.*;
import static net.tylermurphy.hideAndSeek.game.Game.broadcastMessage;
public class Game {
public static Taunt taunt;
public static Glow glow;
public static Border worldBorder;
public static WorldLoader worldLoader;
public static int tick = 0;
public static int countdownTime = -1;
public static int gameId = 0;
public static int timeLeft = 0;
public static Status status = Status.STANDBY;
static {
worldLoader = new WorldLoader(spawnWorld);
}
public static void start(Player seeker){
if(status == Status.STARTING || status == Status.PLAYING) return;
if(worldLoader.getWorld() != null) {
worldLoader.rollback();
} else {
worldLoader.loadMap();
}
Board.reload();
for(Player temp : Board.getPlayers()) {
if(temp.getName().equals(seeker.getName()))
continue;
Board.addHider(temp);
}
Board.addSeeker(seeker);
currentWorldborderSize = worldborderSize;
for(Player player : Board.getPlayers()) {
player.getInventory().clear();
player.setGameMode(GameMode.ADVENTURE);
player.teleport(new Location(Bukkit.getWorld("hideandseek_"+spawnWorld), spawnPosition.getX(),spawnPosition.getY(),spawnPosition.getZ()));
for(PotionEffect effect : player.getActivePotionEffects()){
player.removePotionEffect(effect.getType());
}
}
for(Player player : Board.getSeekers()) {
player.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS,1000000,127,false,false));
player.addPotionEffect(new PotionEffect(PotionEffectType.SLOW,1000000,127,false,false));
player.sendTitle(ChatColor.RED + "" + ChatColor.BOLD + "SEEKER", ChatColor.WHITE + message("SEEKERS_SUBTITLE").toString(), 10, 70, 20);
}
for(Player player : Board.getHiders()) {
player.addPotionEffect(new PotionEffect(PotionEffectType.SPEED,1000000,5,false,false));
player.sendTitle(ChatColor.GOLD + "" + ChatColor.BOLD + "HIDER", ChatColor.WHITE + message("HIDERS_SUBTITLE").toString(), 10, 70, 20);
}
if(tauntEnabled)
taunt = new Taunt();
if (glowEnabled)
glow = new Glow();
worldBorder = new Border();
worldBorder.resetWorldborder("hideandseek_"+spawnWorld);
if(gameLength > 0)
timeLeft = gameLength;
for(Player player : Board.getPlayers())
Board.createGameBoard(player);
Board.reloadGameBoards();
status = Status.STARTING;
int temp = gameId;
broadcastMessage(messagePrefix + message("START_COUNTDOWN").addAmount(30));
sendDelayedMessage(messagePrefix + message("START_COUNTDOWN").addAmount(20), gameId, 20 * 10);
sendDelayedMessage(messagePrefix + message("START_COUNTDOWN").addAmount(10), gameId, 20 * 20);
sendDelayedMessage(messagePrefix + message("START_COUNTDOWN").addAmount(5), gameId, 20 * 25);
sendDelayedMessage(messagePrefix + message("START_COUNTDOWN").addAmount(3), gameId, 20 * 27);
sendDelayedMessage(messagePrefix + message("START_COUNTDOWN").addAmount(2), gameId, 20 * 28);
sendDelayedMessage(messagePrefix + message("START_COUNTDOWN").addAmount(1), gameId, 20 * 29);
Bukkit.getServer().getScheduler().runTaskLater(Main.plugin, () -> {
if(temp != gameId) return;
broadcastMessage(messagePrefix + message("START"));
for(Player player : Board.getPlayers()) resetPlayer(player);
status = Status.PLAYING;
}, 20 * 30);
}
public static void stop(WinType type){
if(status == Status.STANDBY) return;
tick = 0;
countdownTime = -1;
status = Status.STANDBY;
gameId++;
timeLeft = 0;
List<UUID> players = Board.getPlayers().stream().map(Entity::getUniqueId).collect(Collectors.toList());
if(type == WinType.HIDER_WIN){
List<UUID> winners = Board.getHiders().stream().map(Entity::getUniqueId).collect(Collectors.toList());
Database.playerInfo.addWins(players, winners, type);
} else if(type == WinType.SEEKER_WIN){
List<UUID> winners = new ArrayList<>();
winners.add(Board.getFirstSeeker().getUniqueId());
Database.playerInfo.addWins(players, winners, type);
}
worldBorder.resetWorldborder("hideandseek_"+spawnWorld);
for(Player player : Board.getPlayers()) {
Board.createLobbyBoard(player);
player.setGameMode(GameMode.ADVENTURE);
Board.addHider(player);
player.getInventory().clear();
player.teleport(new Location(Bukkit.getWorld(lobbyWorld), lobbyPosition.getX(),lobbyPosition.getY(),lobbyPosition.getZ()));
for(PotionEffect effect : player.getActivePotionEffects()){
player.removePotionEffect(effect.getType());
}
player.addPotionEffect(new PotionEffect(PotionEffectType.HEAL, 1, 100));
for(Player temp : Board.getPlayers()) {
Packet.setGlow(player, temp, false);
}
}
EventListener.temp_loc.clear();
worldLoader.unloadMap();
Board.reloadLobbyBoards();
}
public static boolean isNotSetup() {
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(exitPosition.getBlockX() == 0 && exitPosition.getBlockY() == 0 && exitPosition.getBlockZ() == 0) return true;
File destenation = new File(Main.root+File.separator+"hideandseek_"+spawnWorld);
if(!destenation.exists()) return true;
return saveMinX == 0 || saveMinZ == 0 || saveMaxX == 0 || saveMaxZ == 0;
}
public static void onTick() {
if(isNotSetup()) return;
if(status == Status.STANDBY) whileWaiting();
else if(status == Status.STARTING) whileStarting();
else if(status == Status.PLAYING) whilePlaying();
tick++;
}
public static void resetWorldborder(String worldName){
worldBorder.resetWorldborder(worldName);
}
public static void broadcastMessage(String message) {
for(Player player : Board.getPlayers()) {
player.sendMessage(message);
}
}
public static void resetPlayer(Player player) {
player.getInventory().clear();
for (PotionEffect effect : player.getActivePotionEffects()) {
player.removePotionEffect(effect.getType());
}
if (Board.isSeeker(player)) {
if(pvpEnabled)
for(ItemStack item : Items.SEEKER_ITEMS)
player.getInventory().addItem(item);
for(PotionEffect effect : Items.SEEKER_EFFECTS)
player.addPotionEffect(effect);
} else if (Board.isHider(player)) {
if(pvpEnabled)
for(ItemStack item : Items.HIDER_ITEMS)
player.getInventory().addItem(item);
for(PotionEffect effect : Items.HIDER_EFFECTS)
player.addPotionEffect(effect);
if(glowEnabled) {
ItemStack snowball = new ItemStack(Material.SNOWBALL, 1);
ItemMeta snowballMeta = snowball.getItemMeta();
assert snowballMeta != null;
snowballMeta.setDisplayName("Glow Powerup");
List<String> snowballLore = new ArrayList<>();
snowballLore.add("Throw to make all seekers glow");
snowballLore.add("Last 30s, all hiders can see it");
snowballLore.add("Time stacks on multi use");
snowballMeta.setLore(snowballLore);
snowball.setItemMeta(snowballMeta);
player.getInventory().addItem(snowball);
}
}
}
public static void join(Player player){
if(Game.status == Status.STANDBY) {
player.getInventory().clear();
Board.addHider(player);
if(announceMessagesToNonPlayers) Bukkit.broadcastMessage(messagePrefix + message("GAME_JOIN").addPlayer(player));
else Game.broadcastMessage(messagePrefix + message("GAME_JOIN").addPlayer(player));
player.teleport(new Location(Bukkit.getWorld(lobbyWorld), lobbyPosition.getX(),lobbyPosition.getY(),lobbyPosition.getZ()));
player.setGameMode(GameMode.ADVENTURE);
Board.createLobbyBoard(player);
Board.reloadLobbyBoards();
} else {
Board.addSpectator(player);
player.sendMessage(messagePrefix + message("GAME_JOIN_SPECTATOR"));
player.setGameMode(GameMode.SPECTATOR);
Board.createGameBoard(player);
player.teleport(new Location(Bukkit.getWorld("hideandseek_"+spawnWorld), spawnPosition.getX(),spawnPosition.getY(),spawnPosition.getZ()));
player.sendTitle(ChatColor.GRAY + "" + ChatColor.BOLD + "SPECTATING", ChatColor.WHITE + message("SPECTATOR_SUBTITLE").toString(), 10, 70, 20);
}
player.setFoodLevel(20);
player.setHealth(Objects.requireNonNull(player.getAttribute(Attribute.GENERIC_MAX_HEALTH)).getBaseValue());
}
public static void removeItems(Player player){
for(ItemStack si : Items.SEEKER_ITEMS)
for(ItemStack i : player.getInventory().getContents())
if(si.isSimilar(i)) player.getInventory().remove(i);
for(ItemStack hi : Items.HIDER_ITEMS)
for(ItemStack i : player.getInventory().getContents())
if(hi.isSimilar(i)) player.getInventory().remove(i);
}
private static void whileWaiting() {
if(lobbyCountdownEnabled){
if(lobbyMin <= Board.size()){
if(countdownTime == -1)
countdownTime = countdown;
if(Board.size() >= changeCountdown)
countdownTime = Math.min(countdownTime, 10);
if(tick % 20 == 0)
countdownTime--;
if(countdownTime == 0){
Optional<Player> rand = Board.getPlayers().stream().skip(new Random().nextInt(Board.size())).findFirst();
if(!rand.isPresent()){
Main.plugin.getLogger().warning("Failed to select random seeker.");
return;
}
String seekerName = rand.get().getName();
Player seeker = Board.getPlayer(seekerName);
start(seeker);
}
} else {
countdownTime = -1;
}
}
}
private static void whileStarting(){
checkWinConditions();
}
private static void whilePlaying() {
for(Player hider : Board.getHiders()) {
int distance = 100, temp = 100;
for(Player seeker : Board.getSeekers()) {
try {
temp = (int) hider.getLocation().distance(seeker.getLocation());
} catch (Exception e){
//Players in different worlds, NOT OK!!!
}
if(distance > temp) {
distance = temp;
}
}
switch(tick%10) {
case 0:
if(distance < 30) Packet.playSound(hider, Sound.BLOCK_NOTE_BLOCK_BASEDRUM, .5f, 1f);
if(distance < 10) Packet.playSound(hider, Sound.BLOCK_NOTE_BLOCK_BIT, .3f, 1f);
break;
case 3:
if(distance < 30) Packet.playSound(hider, Sound.BLOCK_NOTE_BLOCK_BASEDRUM, .3f, 1f);
if(distance < 10) Packet.playSound(hider, Sound.BLOCK_NOTE_BLOCK_BIT, .3f, 1f);
break;
case 6:
if(distance < 10) Packet.playSound(hider, Sound.BLOCK_NOTE_BLOCK_BIT, .3f, 1f);
break;
case 9:
if(distance < 20) Packet.playSound(hider, Sound.BLOCK_NOTE_BLOCK_BIT, .3f, 1f);
break;
}
}
if(tick%20 == 0) {
if(gameLength > 0) {
Board.reloadGameBoards();
timeLeft--;
}
if(worldborderEnabled) worldBorder.update();
if(tauntEnabled) taunt.update();
if (glowEnabled) glow.update();
}
checkWinConditions();
}
private static void checkWinConditions(){
if(Board.sizeHider() < 1) {
if(announceMessagesToNonPlayers) Bukkit.broadcastMessage(gameoverPrefix + message("GAME_GAMEOVER_HIDERS_FOUND"));
else broadcastMessage(gameoverPrefix + message("GAME_GAMEOVER_HIDERS_FOUND"));
stop(WinType.SEEKER_WIN);
} else if(Board.sizeSeeker() < 1) {
if(announceMessagesToNonPlayers) Bukkit.broadcastMessage(abortPrefix + message("GAME_GAMEOVER_SEEKERS_QUIT"));
else broadcastMessage(abortPrefix + message("GAME_GAMEOVER_SEEKERS_QUIT"));
stop(WinType.NONE);
} else if(timeLeft < 1) {
if(announceMessagesToNonPlayers) Bukkit.broadcastMessage(gameoverPrefix + message("GAME_GAMEOVER_TIME"));
else broadcastMessage(gameoverPrefix + message("GAME_GAMEOVER_TIME"));
stop(WinType.HIDER_WIN);
}
}
private static void sendDelayedMessage(String message, int gameId, int delay) {
Bukkit.getScheduler().runTaskLaterAsynchronously(Main.plugin, () -> {
if(gameId == Game.gameId)
broadcastMessage(message);
}, delay);
}
}
class Glow {
private int glowTime;
private boolean running;
public Glow() {
this.glowTime = 0;
}
public void onProjectile() {
if(glowStackable) glowTime += glowLength;
else glowTime = glowLength;
if(!running)
startGlow();
}
private void startGlow() {
running = true;
for(Player hider : Board.getHiders()) {
for(Player seeker : Board.getSeekers()) {
Packet.setGlow(hider, seeker, true);
}
}
}
protected void update() {
if(running) {
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 {
private String tauntPlayer;
private int delay;
private boolean running;
public Taunt() {
this.delay = tauntDelay;
}
protected void update() {
if(delay == 0) {
if(running) launchTaunt();
else if(tauntLast || Board.sizeHider() > 1) executeTaunt();
} else {
delay--;
delay = Math.max(delay, 0);
}
}
private void executeTaunt() {
Optional<Player> rand = Board.getHiders().stream().skip(new Random().nextInt(Board.size())).findFirst();
if(!rand.isPresent()){
Main.plugin.getLogger().warning("Failed to select random seeker.");
return;
}
Player taunted = rand.get();
taunted.sendMessage(message("TAUNTED").toString());
broadcastMessage(tauntPrefix + message("TAUNT"));
tauntPlayer = taunted.getName();
running = true;
delay = 30;
}
private void launchTaunt(){
Player taunted = Board.getPlayer(tauntPlayer);
if(taunted != null) {
if(!Board.isHider(taunted)){
Main.plugin.getLogger().info("Taunted played died and is now seeker. Skipping taunt.");
tauntPlayer = "";
running = false;
delay = tauntDelay;
return;
}
World world = taunted.getLocation().getWorld();
if(world == null){
Main.plugin.getLogger().severe("Game world is null while trying to launch taunt.");
tauntPlayer = "";
running = false;
delay = tauntDelay;
return;
}
Firework fw = (Firework) world.spawnEntity(taunted.getLocation(), EntityType.FIREWORK);
FireworkMeta fwm = fw.getFireworkMeta();
fwm.setPower(4);
fwm.addEffect(FireworkEffect.builder()
.withColor(Color.BLUE)
.withColor(Color.RED)
.withColor(Color.YELLOW)
.with(FireworkEffect.Type.STAR)
.with(FireworkEffect.Type.BALL)
.with(FireworkEffect.Type.BALL_LARGE)
.flicker(true)
.withTrail()
.build());
fw.setFireworkMeta(fwm);
broadcastMessage(tauntPrefix + message("TAUNT_ACTIVATE"));
}
tauntPlayer = "";
running = false;
delay = tauntDelay;
}
public int getDelay(){
return delay;
}
public boolean isRunning() {
return running;
}
}
class Border {
private int delay;
private boolean running;
public Border() {
delay = 60 * worldborderDelay;
}
void update(){
if(delay == 30 && !running){
broadcastMessage(worldborderPrefix + message("WORLDBORDER_WARN"));
} else if(delay == 0){
if(running){
delay = 60 * worldborderDelay;
running = false;
}
else decreaceWorldborder();
}
delay--;
}
private void decreaceWorldborder() {
if(currentWorldborderSize-100 > 100) {
running = true;
broadcastMessage(worldborderPrefix + message("WORLDBORDER_DECREASING"));
currentWorldborderSize -= 100;
World world = Bukkit.getWorld("hideandseek_"+spawnWorld);
assert world != null;
org.bukkit.WorldBorder border = world.getWorldBorder();
border.setSize(border.getSize()-100,30);
delay = 30;
}
}
public void resetWorldborder(String worldName) {
World world = Bukkit.getWorld(worldName);
assert world != null;
org.bukkit.WorldBorder border = world.getWorldBorder();
if(worldborderEnabled) {
border.setSize(worldborderSize);
border.setCenter(worldborderPosition.getX(), worldborderPosition.getZ());
currentWorldborderSize = worldborderSize;
} else {
border.setSize(30000000);
border.setCenter(0, 0);
}
}
public int getDelay(){
return delay;
}
public boolean isRunning() {
return running;
}
}

View file

@ -1,257 +0,0 @@
package net.tylermurphy.hideAndSeek.util;
import static net.tylermurphy.hideAndSeek.configuration.Config.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.scoreboard.DisplaySlot;
import org.bukkit.scoreboard.Objective;
import org.bukkit.scoreboard.Score;
import org.bukkit.scoreboard.Scoreboard;
import org.bukkit.scoreboard.Team;
import org.bukkit.scoreboard.Team.Option;
import org.bukkit.scoreboard.Team.OptionStatus;
import net.tylermurphy.hideAndSeek.Main;
public class Board {
private List<String> Hider, Seeker, Spectator;
private Map<String, Player> playerList = new HashMap<String,Player>();
private Map<String, CustomBoard> customBoards = new HashMap<String, CustomBoard>();
public boolean isPlayer(Player player) {
return playerList.containsKey(player.getName());
}
public boolean isPlayer(CommandSender sender) {
return playerList.containsKey(sender.getName());
}
public boolean isHider(Player player) {
return Hider.contains(player.getName());
}
public boolean isSeeker(Player player) {
return Seeker.contains(player.getName());
}
public boolean isSpectator(Player player) {
return Spectator.contains(player.getName());
}
public int sizeHider() {
return Hider.size();
}
public int sizeSeeker() {
return Seeker.size();
}
public int sizeSpectator() {
return Spectator.size();
}
public int size() {
return playerList.values().size();
}
public List<Player> getHiders(){
return Hider.stream().map(playerName -> playerList.get(playerName)).collect(Collectors.toList());
}
public List<Player> getSeekers(){
return Seeker.stream().map(playerName -> playerList.get(playerName)).collect(Collectors.toList());
}
public List<Player> getSpectators(){
return Spectator.stream().map(playerName -> playerList.get(playerName)).collect(Collectors.toList());
}
public List<Player> getPlayers(){
return new ArrayList<Player>(playerList.values());
}
public Player getPlayer(String name) {
return playerList.get(name);
}
public void addHider(Player player) {
Hider.add(player.getName());
Seeker.remove(player.getName());
Spectator.remove(player.getName());
playerList.put(player.getName(), player);
}
public void addSeeker(Player player) {
Hider.remove(player.getName());
Seeker.add(player.getName());
Spectator.remove(player.getName());
playerList.put(player.getName(), player);
}
public void addSpectator(Player player) {
Hider.remove(player.getName());
Seeker.remove(player.getName());
Spectator.add(player.getName());
playerList.put(player.getName(), player);
}
public void remove(Player player) {
Hider.remove(player.getName());
Seeker.remove(player.getName());
Spectator.remove(player.getName());
playerList.remove(player.getName());
}
public boolean onSameTeam(Player player1, Player player2) {
if(Hider.contains(player1.getName()) && Hider.contains(player2.getName())) return true;
else if(Seeker.contains(player1.getName()) && Seeker.contains(player2.getName())) return true;
else if(Spectator.contains(player1.getName()) && Spectator.contains(player2.getName())) return true;
else return false;
}
public void reload() {
Hider = new ArrayList<String>();
Seeker = new ArrayList<String>();
Spectator = new ArrayList<String>();
}
public void reset() {
Hider.clear();
Seeker.clear();
Spectator.clear();
}
private void createTeamsForBoard(Scoreboard board) {
Team hiderTeam = board.registerNewTeam("Hider");
for(String name : Hider)
hiderTeam.addEntry(name);
Team seekerTeam = board.registerNewTeam("Seeker");
for(String name : Seeker)
seekerTeam.addEntry(name);
if(nametagsVisible) {
hiderTeam.setOption(Option.NAME_TAG_VISIBILITY, OptionStatus.FOR_OWN_TEAM);
seekerTeam.setOption(Option.NAME_TAG_VISIBILITY, OptionStatus.FOR_OTHER_TEAMS);
} else {
hiderTeam.setOption(Option.NAME_TAG_VISIBILITY, OptionStatus.NEVER);
seekerTeam.setOption(Option.NAME_TAG_VISIBILITY, OptionStatus.NEVER);
}
}
public void createLobbyBoard(Player player) {
createLobbyBoard(player, true);
}
private void createLobbyBoard(Player player, boolean recreate) {
CustomBoard board = customBoards.get(player.getName());
if(recreate) {
board = new CustomBoard(player, "&l&eHIDE AND SEEK");
board.updateTeams();
}
board.setLine("hiders", ChatColor.BOLD + "" + ChatColor.YELLOW + "HIDER%" + ChatColor.WHITE + getHiderPercent());
board.setLine("seekers", ChatColor.BOLD + "" + ChatColor.RED + "SEEKER%" + ChatColor.WHITE + getSeekerPercent());
board.addBlank();
board.setLine("players", "Players: " + playerList.values().size());
board.addBlank();
board.setLine("waiting", "Waiting to start...");
board.display();
customBoards.put(player.getName(), board);
}
public void createGameBoard(Player player){
createGameBoard(player, true);
}
private void createGameBoard(Player player, boolean recreate){
CustomBoard board = customBoards.get(player.getName());
if(recreate) {
board = new CustomBoard(player, "&l&eHIDE AND SEEK");
}
board.setLine("hiders", ChatColor.BOLD + "" + ChatColor.YELLOW + "HIDERS:" + ChatColor.WHITE + " " + Hider.size());
board.setLine("seekers", ChatColor.BOLD + "" + ChatColor.RED + "SEEKERS:" + ChatColor.WHITE + " " + Seeker.size());
board.addBlank();
if(glowEnabled){
if(Main.plugin.glow == null || Main.plugin.status.equals("Starting") || !Main.plugin.glow.isRunning())
board.setLine("glow", "Glow: " + ChatColor.RED + "Inactive");
else
board.setLine("glow", "Glow: " + ChatColor.GREEN + "Active");
}
if(tauntEnabled && tauntCountdown){
if(Main.plugin.taunt == null || Main.plugin.status.equals("Starting"))
board.setLine("taunt", "Taunt: " + ChatColor.YELLOW + "0m0s");
else if(!tauntLast && Hider.size() == 1){
board.setLine("taunt", "Taunt: " + ChatColor.YELLOW + "Expired");
} else if(!Main.plugin.taunt.isRunning())
board.setLine("taunt", "Taunt: " + ChatColor.YELLOW + Main.plugin.taunt.getDelay()/60 + "m" + Main.plugin.taunt.getDelay()%60 + "s");
else
board.setLine("taunt", "Taunt: " + ChatColor.YELLOW + "Active");
}
if(worldborderEnabled){
if(Main.plugin.worldborder == null || Main.plugin.status.equals("Starting")){
board.setLine("board", "WorldBorder: " + ChatColor.YELLOW + "0m0s");
} else if(!Main.plugin.worldborder.isRunning()) {
board.setLine("board", "WorldBorder: " + ChatColor.YELLOW + Main.plugin.worldborder.getDelay()/60 + "m" + Main.plugin.worldborder.getDelay()%60 + "s");
} else {
board.setLine("board", "WorldBorder: " + ChatColor.YELLOW + "Decreasing");
}
}
if(glowEnabled || (tauntEnabled && tauntCountdown) || worldborderEnabled)
board.addBlank();
board.setLine("time", "Time Left: " + ChatColor.GREEN + Main.plugin.timeLeft/60 + "m" + Main.plugin.timeLeft%60 + "s");
board.addBlank();
board.setLine("team", "Team: " + getTeam(player));
board.display();
customBoards.put(player.getName(), board);
}
public void removeBoard(Player player) {
player.setScoreboard(Bukkit.getScoreboardManager().getMainScoreboard());
customBoards.remove(player.getName());
}
public void reloadLobbyBoards() {
for(Player player : playerList.values())
createLobbyBoard(player, false);
}
public void reloadGameBoards() {
for(Player player : playerList.values())
createGameBoard(player, false);
}
public void reloadBoardTeams() {
for(CustomBoard board : customBoards.values())
board.updateTeams();
}
private String getSeekerPercent() {
if(playerList.values().size() < 2)
return " --";
else
return " "+(int)(100*(1.0/playerList.size()));
}
private String getHiderPercent() {
if(playerList.size() < 2)
return " --";
else
return " "+(int)(100-100*(1.0/playerList.size()));
}
private String getTeam(Player player) {
if(isHider(player)) return ChatColor.GOLD + "HIDER";
else if(isSeeker(player)) return ChatColor.RED + "SEEKER";
else if(isSpectator(player)) return ChatColor.GRAY + "SPECTATOR";
else return ChatColor.WHITE + "UNKNOWN";
}
}

View file

@ -1,121 +0,0 @@
package net.tylermurphy.hideAndSeek.util;
import net.tylermurphy.hideAndSeek.Main;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
import org.bukkit.scoreboard.*;
import java.util.HashMap;
import java.util.Map;
import static net.tylermurphy.hideAndSeek.configuration.Config.*;
public class CustomBoard {
private final Scoreboard board;
private final Objective obj;
private final Player player;
private final Map<String,Line> LINES;
private int blanks;
private boolean displayed;
public CustomBoard(Player player, String title){
this.board = Bukkit.getScoreboardManager().getNewScoreboard();
this.LINES = new HashMap<String,Line>();
this.player = player;
this.obj = board.registerNewObjective(
"Scoreboard", "dummy", ChatColor.translateAlternateColorCodes('&', title));
this.blanks = 0;
this.displayed = false;
this.updateTeams();
}
public void updateTeams() {
try{ board.registerNewTeam("Hider"); } catch (Exception e){}
try{ board.registerNewTeam("Seeker"); } catch (Exception e){}
Team hiderTeam = board.getTeam("Hider");
for(String entry : hiderTeam.getEntries())
hiderTeam.removeEntry(entry);
for(Player player : Main.plugin.board.getHiders())
hiderTeam.addEntry(player.getName());
Team seekerTeam = board.getTeam("Seeker");
for(String entry : seekerTeam.getEntries())
seekerTeam.removeEntry(entry);
for(Player player : Main.plugin.board.getSeekers())
seekerTeam.addEntry(player.getName());
if(nametagsVisible) {
hiderTeam.setOption(Team.Option.NAME_TAG_VISIBILITY, Team.OptionStatus.FOR_OWN_TEAM);
seekerTeam.setOption(Team.Option.NAME_TAG_VISIBILITY, Team.OptionStatus.FOR_OTHER_TEAMS);
} else {
hiderTeam.setOption(Team.Option.NAME_TAG_VISIBILITY, Team.OptionStatus.NEVER);
seekerTeam.setOption(Team.Option.NAME_TAG_VISIBILITY, Team.OptionStatus.NEVER);
}
hiderTeam.setColor(ChatColor.GOLD);
seekerTeam.setColor(ChatColor.RED);
}
public void setLine(String key, String message){
Line line = LINES.get(key);
if(line == null)
addLine(key, message);
else
updateLine(key, message);
}
private void addLine(String key, String message){
Score score = obj.getScore(message);
score.setScore(LINES.values().size()+1);
Line line = new Line(LINES.values().size()+1, message);
LINES.put(key, line);
}
public void addBlank(){
if(displayed) return;
String temp = "";
for(int i = 0; i <= blanks; i ++)
temp += ChatColor.RESET;
blanks++;
addLine("blank"+blanks, temp);
}
private void updateLine(String key, String message){
Line line = LINES.get(key);
board.resetScores(line.getMessage());
line.setMessage(message);
Score newScore = obj.getScore(message);
newScore.setScore(line.getScore());
}
public void display() {
displayed = true;
obj.setDisplaySlot(DisplaySlot.SIDEBAR);
player.setScoreboard(board);
}
}
class Line {
private int score;
private String message;
public Line(int score, String message){
this.score = score;
this.message = message;
}
public int getScore() {
return score;
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
}

View file

@ -1,3 +1,22 @@
/*
* 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.util; package net.tylermurphy.hideAndSeek.util;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;
@ -16,7 +35,7 @@ import com.comphenix.protocol.wrappers.WrappedDataWatcher.Serializer;
public class Packet { public class Packet {
private static ProtocolManager protocolManager = ProtocolLibrary.getProtocolManager(); private static final ProtocolManager protocolManager = ProtocolLibrary.getProtocolManager();
public static void playSound(Player player, Sound sound, float volume, float pitch) { public static void playSound(Player player, Sound sound, float volume, float pitch) {
PacketContainer packet = protocolManager.createPacket(PacketType.Play.Server.NAMED_SOUND_EFFECT); PacketContainer packet = protocolManager.createPacket(PacketType.Play.Server.NAMED_SOUND_EFFECT);

View file

@ -0,0 +1,26 @@
/*
* 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.util;
public enum Status {
STANDBY,
STARTING,
PLAYING
}

View file

@ -1,18 +1,37 @@
package net.tylermurphy.hideAndSeek.bukkit; /*
* 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.util;
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 org.bukkit.command.Command; import net.tylermurphy.hideAndSeek.game.CommandHandler;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
public class TabCompleter{ public class TabCompleter{
public static List<String> handleTabComplete(CommandSender sender, Command command, String label, String[] args) { public static List<String> handleTabComplete(CommandSender sender, String[] args) {
if(args.length == 1) { if(args.length == 1) {
return new ArrayList<String>(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());
@ -26,7 +45,7 @@ public class TabCompleter{
if(parameter.equals("<player>")) { if(parameter.equals("<player>")) {
return null; return null;
} else { } else {
List<String> temp = new ArrayList<String>(); List<String> temp = new ArrayList<>();
temp.add(parameter.replace("<", "").replace(">", "")); temp.add(parameter.replace("<", "").replace(">", ""));
return temp; return temp;
} }

View file

@ -0,0 +1,106 @@
/*
* 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.util;
import net.tylermurphy.hideAndSeek.Main;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLConnection;
import java.nio.charset.Charset;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
public final class UUIDFetcher {
private static final Map<String,UUID> CACHE = new HashMap<>();
private static final String UUID_URL = "https://api.mojang.com/users/profiles/minecraft/";
private static int cacheTask;
public static void init(){
cacheTask = Main.plugin.getServer().getScheduler().scheduleSyncRepeatingTask(Main.plugin, CACHE::clear,600*20, 600*20);
}
public static void cleanup(){
Main.plugin.getServer().getScheduler().cancelTask(cacheTask);
}
public static UUID getUUID(String playername) {
if(CACHE.containsKey(playername)) return CACHE.get(playername);
String output = callURL(UUID_URL + playername);
StringBuilder result = new StringBuilder();
readData(output, result);
String u = result.toString();
StringBuilder uuid = new StringBuilder();
for (int i = 0; i <= 31; i++) {
uuid.append(u.charAt(i));
if (i == 7 || i == 11 || i == 15 || i == 19) {
uuid.append('-');
}
}
CACHE.put(playername, UUID.fromString(uuid.toString()));
return UUID.fromString(uuid.toString());
}
private static void readData(String toRead, StringBuilder result) {
for (int i = toRead.length() - 3; i >= 0; i--) {
if (toRead.charAt(i) != '"') {
result.insert(0, toRead.charAt(i));
} else {
break;
}
}
}
private static String callURL(String urlStr) {
StringBuilder sb = new StringBuilder();
URLConnection urlConn;
InputStreamReader in;
try {
URL url = new URL(urlStr);
urlConn = url.openConnection();
if (urlConn != null) {
urlConn.setReadTimeout(60 * 1000);
}
if (urlConn != null && urlConn.getInputStream() != null) {
in = new InputStreamReader(urlConn.getInputStream(),
Charset.defaultCharset());
BufferedReader bufferedReader = new BufferedReader(in);
int cp;
while ((cp = bufferedReader.read()) != -1) {
sb.append((char) cp);
}
bufferedReader.close();
in.close();
}
} catch (Exception e) {
e.printStackTrace();
}
return sb.toString();
}
}

View file

@ -1,85 +0,0 @@
package net.tylermurphy.hideAndSeek.util;
import static net.tylermurphy.hideAndSeek.configuration.Config.*;
import java.io.*;
import java.util.ArrayList;
import java.util.List;
import net.md_5.bungee.api.ChatColor;
import net.tylermurphy.hideAndSeek.configuration.Items;
import net.tylermurphy.hideAndSeek.configuration.LocalizationString;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.Player;
import net.tylermurphy.hideAndSeek.Main;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.inventory.meta.PotionMeta;
import org.bukkit.potion.PotionData;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
import org.bukkit.potion.PotionType;
public class Util {
public static void broadcastMessage(String message) {
for(Player player : Main.plugin.board.getPlayers()) {
player.sendMessage(message);
}
}
public static boolean isSetup() {
if(spawnPosition.getBlockX() == 0 && spawnPosition.getBlockY() == 0 && spawnPosition.getBlockZ() == 0) return false;
if(lobbyPosition.getBlockX() == 0 && lobbyPosition.getBlockY() == 0 && lobbyPosition.getBlockZ() == 0) return false;
if(exitPosition.getBlockX() == 0 && exitPosition.getBlockY() == 0 && exitPosition.getBlockZ() == 0) return false;
File destenation = new File(Main.root+File.separator+"hideandseek_"+spawnWorld);
if(!destenation.exists()) return false;
if(saveMinX == 0 || saveMinZ == 0 || saveMaxX == 0 || saveMaxZ == 0) return false;
return true;
}
public static void sendDelayedMessage(String message, int gameId, int delay) {
Bukkit.getScheduler().runTaskLaterAsynchronously(Main.plugin, new Runnable() {
public void run() {
if(gameId == Main.plugin.gameId)
Util.broadcastMessage(message);
}
}, delay);
}
public static void resetPlayer(Player player) {
player.getInventory().clear();
for (PotionEffect effect : player.getActivePotionEffects()) {
player.removePotionEffect(effect.getType());
}
if (Main.plugin.board.isSeeker(player)) {
if(pvpEnabled)
for(ItemStack item : Items.SEEKER_ITEMS)
player.getInventory().addItem(item);
for(PotionEffect effect : Items.SEEKER_EFFECTS)
player.addPotionEffect(effect);
} else if (Main.plugin.board.isHider(player)) {
if(pvpEnabled)
for(ItemStack item : Items.HIDER_ITEMS)
player.getInventory().addItem(item);
for(PotionEffect effect : Items.HIDER_EFFECTS)
player.addPotionEffect(effect);
if(glowEnabled) {
ItemStack snowball = new ItemStack(Material.SNOWBALL, 1);
ItemMeta snowballMeta = snowball.getItemMeta();
snowballMeta.setDisplayName("Glow Powerup");
List<String> snowballLore = new ArrayList<String>();
snowballLore.add("Throw to make all seekers glow");
snowballLore.add("Last 30s, all hiders can see it");
snowballLore.add("Time stacks on multi use");
snowballMeta.setLore(snowballLore);
snowball.setItemMeta(snowballMeta);
player.getInventory().addItem(snowball);
}
}
}
}

View file

@ -0,0 +1,26 @@
/*
* 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.util;
public enum WinType {
HIDER_WIN,
SEEKER_WIN,
NONE
}

View file

@ -1,3 +1,22 @@
/*
* 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.world; package net.tylermurphy.hideAndSeek.world;
import java.util.Collections; import java.util.Collections;
@ -7,11 +26,12 @@ 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;
public class VoidGenerator extends ChunkGenerator{ public class VoidGenerator extends ChunkGenerator{
public List<BlockPopulator> getDefaultPopulators(World world) { public @NotNull List<BlockPopulator> getDefaultPopulators(@NotNull World world) {
return Collections.<BlockPopulator>emptyList(); return Collections.emptyList();
} }
public boolean shouldGenerateNoise() { public boolean shouldGenerateNoise() {
@ -42,10 +62,11 @@ public class VoidGenerator extends ChunkGenerator{
return false; return false;
} }
public boolean canSpawn(World world, int x, int z) { public boolean canSpawn(@NotNull World world, int x, int z) {
return true; return true;
} }
public ChunkData generateChunkData(World world, Random random, int x, int z, BiomeGrid biome) { return createChunkData(world); } // Backwards compatibility
public @NotNull ChunkData generateChunkData(@NotNull World world, @NotNull Random random, int x, int z, @NotNull BiomeGrid biome) { return createChunkData(world); }
} }

View file

@ -1,3 +1,22 @@
/*
* 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.world; package net.tylermurphy.hideAndSeek.world;
import static net.tylermurphy.hideAndSeek.configuration.Config.*; import static net.tylermurphy.hideAndSeek.configuration.Config.*;
@ -11,6 +30,7 @@ import java.io.InputStream;
import java.io.OutputStream; import java.io.OutputStream;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.World;
import org.bukkit.WorldCreator; import org.bukkit.WorldCreator;
import net.tylermurphy.hideAndSeek.Main; import net.tylermurphy.hideAndSeek.Main;
@ -25,8 +45,17 @@ public class WorldLoader {
this.savename = "hideandseek_"+mapname; this.savename = "hideandseek_"+mapname;
} }
public World getWorld(){
return Bukkit.getServer().getWorld(savename);
}
public void unloadMap(){ public void unloadMap(){
if(Bukkit.getServer().unloadWorld(Bukkit.getServer().getWorld(savename), false)){ World world = Bukkit.getServer().getWorld(savename);
if(world == null){
Main.plugin.getLogger().warning(savename + " already unloaded.");
return;
}
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);
@ -35,7 +64,12 @@ public class WorldLoader {
public void loadMap(){ public void loadMap(){
Bukkit.getServer().createWorld(new WorldCreator(savename).generator(new VoidGenerator())); Bukkit.getServer().createWorld(new WorldCreator(savename).generator(new VoidGenerator()));
Bukkit.getServer().getWorld(savename).setAutoSave(false); World world = Bukkit.getServer().getWorld(savename);
if(world == null){
Main.plugin.getLogger().severe("COULD NOT LOAD " + savename);
return;
}
world.setAutoSave(false);
} }
public void rollback(){ public void rollback(){
@ -57,9 +91,13 @@ public class WorldLoader {
copyFile(srcFile,destFile); copyFile(srcFile,destFile);
if(destenation.exists()) { if(destenation.exists()) {
deleteDirectory(destenation); deleteDirectory(destenation);
destenation.mkdir(); if(!destenation.mkdir()){
throw new RuntimeException("Failed to create directory: "+destenation.getPath());
}
}
if(!temp_destenation.renameTo(destenation)){
throw new RuntimeException("Failed to rename directory: "+temp_destenation.getPath());
} }
temp_destenation.renameTo(destenation);
} catch(IOException e) { } catch(IOException e) {
e.printStackTrace(); e.printStackTrace();
return errorPrefix + message("COMMAND_ERROR"); return errorPrefix + message("COMMAND_ERROR");
@ -77,7 +115,11 @@ public class WorldLoader {
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){
Main.plugin.getLogger().severe("Region directory is null or cannot be accessed");
return;
}
for (String file : files) { for (String file : files) {
if(isMca) { if(isMca) {
@ -86,7 +128,7 @@ public class WorldLoader {
int maxX = (int)Math.floor(saveMaxX / 32.0); int maxX = (int)Math.floor(saveMaxX / 32.0);
int maxZ = (int)Math.floor(saveMaxZ / 32.0); int maxZ = (int)Math.floor(saveMaxZ / 32.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 )
@ -116,14 +158,16 @@ public class WorldLoader {
out.close(); out.close();
} }
private boolean deleteDirectory(File directoryToBeDeleted) { private void deleteDirectory(File directoryToBeDeleted) {
File[] allContents = directoryToBeDeleted.listFiles(); File[] allContents = directoryToBeDeleted.listFiles();
if (allContents != null) { if (allContents != null) {
for (File file : allContents) { for (File file : allContents) {
deleteDirectory(file); deleteDirectory(file);
} }
} }
return directoryToBeDeleted.delete(); if(!directoryToBeDeleted.delete()){
throw new RuntimeException("Failed to delete directory: "+directoryToBeDeleted.getPath());
}
} }
} }

View file

@ -79,9 +79,20 @@ prefix:
gameover: '&aGame Over > &f' gameover: '&aGame Over > &f'
warning: '&cWarning > &f' warning: '&cWarning > &f'
# This is the section if you want a standard "waiting for players" lobby. You can specify
# the standard countdown length under [countdown] (min 10 seconds). Then once the lobby gets to a size specified
# by [changeCountdown], the timer will automatically go to 10 seconds. [min] is the minimum players
# to start the countdown. [max] is the lobby cap, set to -1 to remove maximum cap.
lobby:
countdown: 60
changeCountdown: 5
min: 3
max: 10
enabled: true
# Changes the default plugin language. Currently, Supported localizations are: # Changes the default plugin language. Currently, Supported localizations are:
# en-US (United States) # en-US (English - United States)
# de-DE (German) # de-DE (German - Germany)
local: "en-US" local: "en-US"
# ---------------------------------------------------------- # # ---------------------------------------------------------- #

View file

@ -36,6 +36,7 @@ Localization:
WORLDBORDER_POSITION: "Spawn muss mindestens 100 Blöcke vom Zentrum der World Border entfernt sein." WORLDBORDER_POSITION: "Spawn muss mindestens 100 Blöcke vom Zentrum der World Border entfernt sein."
WORLDBORDER_ENABLE: "Setze World Border zentriert von dieser Position aus. Größe: {AMOUNT}. Verzögerung: {AMOUNT}." WORLDBORDER_ENABLE: "Setze World Border zentriert von dieser Position aus. Größe: {AMOUNT}. Verzögerung: {AMOUNT}."
WORLDBORDER_DECREASING: "World Norder schrumpoft 100 Blöcke über die nächsten 30 Sekunden!" WORLDBORDER_DECREASING: "World Norder schrumpoft 100 Blöcke über die nächsten 30 Sekunden!"
WORLDBORDER_WARN: "Die Weltgrenze wird in den nächsten 30er Jahren schrumpfen!"
TAUNTED: "$c$oOh nein! Du wurdest geärgert!" TAUNTED: "$c$oOh nein! Du wurdest geärgert!"
TAUNT: "Ein zufälliger Hider wird in den nächsten 30 Sekunden geärgert." TAUNT: "Ein zufälliger Hider wird in den nächsten 30 Sekunden geärgert."
TAUNT_ACTIVATE: "Ärgern wurde aktiviert" TAUNT_ACTIVATE: "Ärgern wurde aktiviert"
@ -46,7 +47,7 @@ Localization:
SETUP_EXIT: "&c&l- &fTeleport-Position für das Spielende festlegen mit /hs setexit" SETUP_EXIT: "&c&l- &fTeleport-Position für das Spielende festlegen mit /hs setexit"
SETUP_SAVEMAP: "&c&l- &fHide and Seek Weltkarte speichern mit /hs savemap (nach /hs setspawn)" SETUP_SAVEMAP: "&c&l- &fHide and Seek Weltkarte speichern mit /hs savemap (nach /hs setspawn)"
SETUP_COMPLETE: "Alles eingerichtet! Hide and Seek ist spielbereit." SETUP_COMPLETE: "Alles eingerichtet! Hide and Seek ist spielbereit."
SETUP_BOUNDS: "&c&l- &fBitte legen Sie Spielgrenzen in 2 gegenüberliegenden Ecken der Spielkarte fest, /hs setbounds" SETUP_BOUNDS: "&c&l- &fSpielgrenze in 2 gegenüberliegenden Ecken der Welt festlegen mit /hs setbounds"
GAME_SPAWN: "Teleport-Position für Spielbeginn festgelegt" GAME_SPAWN: "Teleport-Position für Spielbeginn festgelegt"
LOBBY_SPAWN: "Teleport-Position für Lobby festgelegt" LOBBY_SPAWN: "Teleport-Position für Lobby festgelegt"
EXIT_SPAWN: "Teleport-Position für Spielende festgelegt" EXIT_SPAWN: "Teleport-Position für Spielende festgelegt"
@ -57,9 +58,12 @@ Localization:
STOP: "Das Spiel wurde gestoppt." STOP: "Das Spiel wurde gestoppt."
HIDERS_SUBTITLE: "Verstecke dich gut vor den Seekern!" HIDERS_SUBTITLE: "Verstecke dich gut vor den Seekern!"
SEEKERS_SUBTITLE: "Finde alle Hider!" SEEKERS_SUBTITLE: "Finde alle Hider!"
SPECTATOR_SUBTITLE: "Du bist mitten im spiel beigetreten."
BOUNDS_WRONG_WORLD: "Führe diesen Befehl bitte in der Spielwelt aus." BOUNDS_WRONG_WORLD: "Führe diesen Befehl bitte in der Spielwelt aus."
BOUNDS: "Grenzen erfolgreich an dieser Position gesetzt. ({AMOUNT}/2)" BOUNDS: "Grenzen erfolgreich an dieser Position gesetzt. ({AMOUNT}/2)"
NOT_AT_ZERO: "Bitte nicht an einer Position setzen, die eine Koordinate bei 0 enthält." NOT_AT_ZERO: "Bitte nicht an einer Position setzen, die eine Koordinate bei 0 enthält."
NO_GAME_INFO: "Keine Informationen zum Gameplay für diesen Spieler vorhanden."
INFORMATION_FOR: "Gewinninformationen für {PLAYER}:"
# DO NOT EDIT IT OR IT MAY BREAK OR RESET FILE # DO NOT EDIT IT OR IT MAY BREAK OR RESET FILE
version: 2 version: 2

View file

@ -36,6 +36,7 @@ Localization:
WORLDBORDER_POSITION: "Spawn position must be 100 from world border center." WORLDBORDER_POSITION: "Spawn position must be 100 from world border center."
WORLDBORDER_ENABLE: "Set border center to current location, size to {AMOUNT}, and delay to {AMOUNT}." WORLDBORDER_ENABLE: "Set border center to current location, size to {AMOUNT}, and delay to {AMOUNT}."
WORLDBORDER_DECREASING: "World border decreasing by 100 blocks over the next 30s." WORLDBORDER_DECREASING: "World border decreasing by 100 blocks over the next 30s."
WORLDBORDER_WARN: "World border will shrink in the next 30s!"
TAUNTED: "$c$oOh no! You have been chosen to be taunted." TAUNTED: "$c$oOh no! You have been chosen to be taunted."
TAUNT: "A random hider will be taunted in the next 30s." TAUNT: "A random hider will be taunted in the next 30s."
TAUNT_ACTIVATE: "Taunt has been activated." TAUNT_ACTIVATE: "Taunt has been activated."
@ -57,9 +58,12 @@ Localization:
STOP: "Game has been force stopped." STOP: "Game has been force stopped."
HIDERS_SUBTITLE: "Hide away from the seekers" HIDERS_SUBTITLE: "Hide away from the seekers"
SEEKERS_SUBTITLE: "Eliminate all hiders" SEEKERS_SUBTITLE: "Eliminate all hiders"
SPECTATOR_SUBTITLE: "You joined mid-game."
BOUNDS_WRONG_WORLD: "Please run this command in the game world." BOUNDS_WRONG_WORLD: "Please run this command in the game world."
BOUNDS: "Successfully set bounds at this position ({AMOUNT}/2)." BOUNDS: "Successfully set bounds at this position ({AMOUNT}/2)."
NOT_AT_ZERO: "Please do not set at a location containing a coordinate at 0." NOT_AT_ZERO: "Please do not set at a location containing a coordinate at 0."
NO_GAME_INFO: "Player has no gameplay information."
INFORMATION_FOR: "Win information for {PLAYER}:"
# DO NOT EDIT IT OR IT MAY BREAK OR RESET FILE # DO NOT EDIT IT OR IT MAY BREAK OR RESET FILE
version: 2 version: 2

View file

@ -1,6 +1,6 @@
name: HideAndSeek name: HideAndSeek
main: net.tylermurphy.hideAndSeek.Main main: net.tylermurphy.hideAndSeek.Main
version: 1.3.2 version: 1.3.3
author: KenshinEto author: KenshinEto
load: STARTUP load: STARTUP
api-version: 1.14 api-version: 1.14
@ -28,6 +28,7 @@ permissions:
hideandseek.savemap: true hideandseek.savemap: true
hideandseek.join: true hideandseek.join: true
hideandseek.leave: true hideandseek.leave: true
hideandseek.leavebounds: true
hideandseek.about: hideandseek.about:
description: Allows you to run the about command description: Allows you to run the about command
default: true default: true
@ -70,3 +71,6 @@ permissions:
hideandseek.leave: hideandseek.leave:
description: Allows you to leave the game manual lobby description: Allows you to leave the game manual lobby
default: true default: true
hideandseek.leavebounds:
description: Allows players to leave specified game bounderies
default: op