1.3.3 beta 2
This commit is contained in:
parent
8cf4d881dc
commit
6e09da9150
17 changed files with 473 additions and 36 deletions
5
pom.xml
5
pom.xml
|
@ -39,5 +39,10 @@
|
||||||
<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>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</project>
|
</project>
|
|
@ -7,7 +7,9 @@ import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
import net.tylermurphy.hideAndSeek.database.Database;
|
||||||
import net.tylermurphy.hideAndSeek.game.Status;
|
import net.tylermurphy.hideAndSeek.game.Status;
|
||||||
|
import net.tylermurphy.hideAndSeek.util.UUIDFetcher;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
|
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
|
@ -36,6 +38,7 @@ public class Main extends JavaPlugin implements Listener {
|
||||||
public Board board;
|
public Board board;
|
||||||
public WorldLoader worldLoader;
|
public WorldLoader worldLoader;
|
||||||
public Status status = Status.STANDBY;
|
public Status status = Status.STANDBY;
|
||||||
|
public Database database;
|
||||||
private BukkitTask onTickTask;
|
private BukkitTask onTickTask;
|
||||||
|
|
||||||
public void onEnable() {
|
public void onEnable() {
|
||||||
|
@ -64,10 +67,19 @@ public class Main extends JavaPlugin implements Listener {
|
||||||
board = new Board();
|
board = new Board();
|
||||||
board.reload();
|
board.reload();
|
||||||
|
|
||||||
|
//Database
|
||||||
|
database = new Database();
|
||||||
|
database.init();
|
||||||
|
|
||||||
|
//UUIDFetcher Cache
|
||||||
|
UUIDFetcher.init();
|
||||||
|
|
||||||
|
//Init game
|
||||||
|
game = new Game();
|
||||||
|
|
||||||
// Start Tick Timer
|
// Start Tick Timer
|
||||||
onTickTask = Bukkit.getServer().getScheduler().runTaskTimer(this, () -> {
|
onTickTask = Bukkit.getServer().getScheduler().runTaskTimer(this, () -> {
|
||||||
try{
|
try{
|
||||||
game = new Game();
|
|
||||||
game.onTick();
|
game.onTick();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
@ -79,6 +91,7 @@ public class Main extends JavaPlugin implements Listener {
|
||||||
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(CommandSender sender, Command cmd,String label, String[] args) {
|
||||||
|
|
|
@ -3,6 +3,7 @@ package net.tylermurphy.hideAndSeek.command;
|
||||||
import static net.tylermurphy.hideAndSeek.configuration.Config.*;
|
import static net.tylermurphy.hideAndSeek.configuration.Config.*;
|
||||||
|
|
||||||
import net.tylermurphy.hideAndSeek.game.Status;
|
import net.tylermurphy.hideAndSeek.game.Status;
|
||||||
|
import net.tylermurphy.hideAndSeek.game.WinType;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
|
|
||||||
|
@ -20,7 +21,7 @@ public class Stop implements ICommand {
|
||||||
if(Main.plugin.status == Status.STARTING || Main.plugin.status == Status.PLAYING) {
|
if(Main.plugin.status == Status.STARTING || Main.plugin.status == Status.PLAYING) {
|
||||||
if(announceMessagesToNonPlayers) Bukkit.broadcastMessage(abortPrefix + message("STOP"));
|
if(announceMessagesToNonPlayers) Bukkit.broadcastMessage(abortPrefix + message("STOP"));
|
||||||
else Util.broadcastMessage(abortPrefix + message("STOP"));
|
else Util.broadcastMessage(abortPrefix + message("STOP"));
|
||||||
Main.plugin.game.stop();
|
Main.plugin.game.stop(WinType.NONE);
|
||||||
} else {
|
} else {
|
||||||
sender.sendMessage(errorPrefix + message("GAME_NOT_INPROGRESS"));
|
sender.sendMessage(errorPrefix + message("GAME_NOT_INPROGRESS"));
|
||||||
}
|
}
|
||||||
|
|
60
src/main/java/net/tylermurphy/hideAndSeek/command/Top.java
Normal file
60
src/main/java/net/tylermurphy/hideAndSeek/command/Top.java
Normal file
|
@ -0,0 +1,60 @@
|
||||||
|
package net.tylermurphy.hideAndSeek.command;
|
||||||
|
|
||||||
|
import net.tylermurphy.hideAndSeek.Main;
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
String message = String.format(
|
||||||
|
"%s------- %sLEADERBOARD %s(Page %s) %s-------\n",
|
||||||
|
ChatColor.WHITE, ChatColor.BOLD, ChatColor.GRAY, page, ChatColor.WHITE);
|
||||||
|
List<PlayerInfo> infos = Main.plugin.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 = message + String.format("%s%s. %s%s %s%s\n",
|
||||||
|
color, i, ChatColor.RED, info.wins, ChatColor.WHITE, name);
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
sender.sendMessage(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getLabel() {
|
||||||
|
return "top";
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getUsage() {
|
||||||
|
return "<page>";
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDescription() {
|
||||||
|
return "Gets the top players in the server.";
|
||||||
|
}
|
||||||
|
}
|
66
src/main/java/net/tylermurphy/hideAndSeek/command/Wins.java
Normal file
66
src/main/java/net/tylermurphy/hideAndSeek/command/Wins.java
Normal file
|
@ -0,0 +1,66 @@
|
||||||
|
package net.tylermurphy.hideAndSeek.command;
|
||||||
|
|
||||||
|
import com.comphenix.protocol.PacketType;
|
||||||
|
import net.tylermurphy.hideAndSeek.Main;
|
||||||
|
import net.tylermurphy.hideAndSeek.database.PlayerInfo;
|
||||||
|
import net.tylermurphy.hideAndSeek.util.CommandHandler;
|
||||||
|
import net.tylermurphy.hideAndSeek.util.UUIDFetcher;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.ChatColor;
|
||||||
|
import org.bukkit.OfflinePlayer;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
|
||||||
|
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) {
|
||||||
|
uuid = Main.plugin.getServer().getPlayer(sender.getName()).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 = Main.plugin.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.";
|
||||||
|
}
|
||||||
|
}
|
|
@ -173,7 +173,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();
|
||||||
|
|
|
@ -0,0 +1,30 @@
|
||||||
|
package net.tylermurphy.hideAndSeek.database;
|
||||||
|
|
||||||
|
import net.tylermurphy.hideAndSeek.Main;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.sql.Connection;
|
||||||
|
import java.sql.DriverManager;
|
||||||
|
import java.sql.SQLException;
|
||||||
|
|
||||||
|
public class Database {
|
||||||
|
|
||||||
|
private final File databaseFile = new File(Main.data, "database.db");
|
||||||
|
|
||||||
|
public PlayerInfoTable playerInfo;
|
||||||
|
|
||||||
|
protected 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void init(){
|
||||||
|
playerInfo = new PlayerInfoTable();
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,18 @@
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,109 @@
|
||||||
|
package net.tylermurphy.hideAndSeek.database;
|
||||||
|
|
||||||
|
import net.tylermurphy.hideAndSeek.Main;
|
||||||
|
import net.tylermurphy.hideAndSeek.game.WinType;
|
||||||
|
import net.tylermurphy.hideAndSeek.util.Util;
|
||||||
|
|
||||||
|
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 = Main.plugin.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 = Main.plugin.database.connect(); PreparedStatement statement = connection.prepareStatement(sql)){
|
||||||
|
InputStream is = Util.convertUniqueId(uuid);
|
||||||
|
byte[] bytes = new byte[is.available()];
|
||||||
|
is.read(bytes);
|
||||||
|
statement.setBytes(1, bytes);
|
||||||
|
ResultSet rs = statement.executeQuery();
|
||||||
|
if(rs.next()){
|
||||||
|
PlayerInfo info = new PlayerInfo(
|
||||||
|
uuid,
|
||||||
|
rs.getInt("wins"),
|
||||||
|
rs.getInt("seeker_wins"),
|
||||||
|
rs.getInt("hider_wins"),
|
||||||
|
rs.getInt("games_played")
|
||||||
|
);
|
||||||
|
return info;
|
||||||
|
}
|
||||||
|
} 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 = Main.plugin.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(
|
||||||
|
Util.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 boolean 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 = Main.plugin.database.connect(); PreparedStatement statement = connection.prepareStatement(sql)){
|
||||||
|
InputStream is = Util.convertUniqueId(uuid);
|
||||||
|
byte[] bytes = new byte[is.available()];
|
||||||
|
is.read(bytes);
|
||||||
|
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 false;
|
||||||
|
} catch (IOException e) {
|
||||||
|
Main.plugin.getLogger().severe("IO Error: " + e.getMessage());
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -10,6 +10,7 @@ import org.bukkit.Bukkit;
|
||||||
import org.bukkit.GameMode;
|
import org.bukkit.GameMode;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.Sound;
|
import org.bukkit.Sound;
|
||||||
|
import org.bukkit.entity.Entity;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import net.tylermurphy.hideAndSeek.Main;
|
import net.tylermurphy.hideAndSeek.Main;
|
||||||
|
@ -18,7 +19,11 @@ import net.tylermurphy.hideAndSeek.util.Util;
|
||||||
import org.bukkit.potion.PotionEffect;
|
import org.bukkit.potion.PotionEffect;
|
||||||
import org.bukkit.potion.PotionEffectType;
|
import org.bukkit.potion.PotionEffectType;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
import java.util.UUID;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import static net.tylermurphy.hideAndSeek.configuration.Localization.*;
|
import static net.tylermurphy.hideAndSeek.configuration.Localization.*;
|
||||||
import static net.tylermurphy.hideAndSeek.configuration.Config.*;
|
import static net.tylermurphy.hideAndSeek.configuration.Config.*;
|
||||||
|
@ -80,11 +85,13 @@ public class Game {
|
||||||
Util.sendDelayedMessage(messagePrefix + message("START_COUNTDOWN").addAmount(3), Main.plugin.game.gameId, 20 * 27);
|
Util.sendDelayedMessage(messagePrefix + message("START_COUNTDOWN").addAmount(3), Main.plugin.game.gameId, 20 * 27);
|
||||||
Util.sendDelayedMessage(messagePrefix + message("START_COUNTDOWN").addAmount(2), Main.plugin.game.gameId, 20 * 28);
|
Util.sendDelayedMessage(messagePrefix + message("START_COUNTDOWN").addAmount(2), Main.plugin.game.gameId, 20 * 28);
|
||||||
Util.sendDelayedMessage(messagePrefix + message("START_COUNTDOWN").addAmount(1), Main.plugin.game.gameId, 20 * 29);
|
Util.sendDelayedMessage(messagePrefix + message("START_COUNTDOWN").addAmount(1), Main.plugin.game.gameId, 20 * 29);
|
||||||
Bukkit.getServer().getScheduler().runTaskLater(Main.plugin, new Runnable() {
|
if(gameLength > 0) {
|
||||||
public void run() {
|
timeLeft = gameLength;
|
||||||
|
}
|
||||||
|
Bukkit.getServer().getScheduler().runTaskLater(Main.plugin, () -> {
|
||||||
if(temp != Main.plugin.game.gameId) return;
|
if(temp != Main.plugin.game.gameId) return;
|
||||||
Util.broadcastMessage(messagePrefix + message("START"));
|
Util.broadcastMessage(messagePrefix + message("START"));
|
||||||
Main.plugin.status = Status.PLAYING;
|
|
||||||
for(Player player : Main.plugin.board.getPlayers()) {
|
for(Player player : Main.plugin.board.getPlayers()) {
|
||||||
Util.resetPlayer(player);
|
Util.resetPlayer(player);
|
||||||
}
|
}
|
||||||
|
@ -103,20 +110,26 @@ public class Game {
|
||||||
glow = new Glow(Main.plugin.game.gameId);
|
glow = new Glow(Main.plugin.game.gameId);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(gameLength > 0) {
|
Main.plugin.status = Status.PLAYING;
|
||||||
timeLeft = gameLength;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}, 20 * 30);
|
}, 20 * 30);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void stop(){
|
public void stop(WinType type){
|
||||||
if(Main.plugin.status == Status.STANDBY) return;
|
if(Main.plugin.status == Status.STANDBY) return;
|
||||||
tick = 0;
|
tick = 0;
|
||||||
countdownTime = -1;
|
countdownTime = -1;
|
||||||
Main.plugin.status = Status.STANDBY;
|
Main.plugin.status = Status.STANDBY;
|
||||||
Main.plugin.game.gameId++;
|
Main.plugin.game.gameId++;
|
||||||
timeLeft = 0;
|
timeLeft = 0;
|
||||||
|
List<UUID> players = Main.plugin.board.getPlayers().stream().map(Entity::getUniqueId).collect(Collectors.toList());
|
||||||
|
if(type == WinType.HIDER_WIN){
|
||||||
|
List<UUID> winners = Main.plugin.board.getHiders().stream().map(Entity::getUniqueId).collect(Collectors.toList());
|
||||||
|
Main.plugin.database.playerInfo.addWins(players, winners, type);
|
||||||
|
} else if(type == WinType.SEEKER_WIN){
|
||||||
|
List<UUID> winners = new ArrayList<>();
|
||||||
|
winners.add(Main.plugin.board.getFirstSeeker().getUniqueId());
|
||||||
|
Main.plugin.database.playerInfo.addWins(players, winners, type);
|
||||||
|
}
|
||||||
Worldborder.resetWorldborder("hideandseek_"+spawnWorld);
|
Worldborder.resetWorldborder("hideandseek_"+spawnWorld);
|
||||||
for(Player player : Main.plugin.board.getPlayers()) {
|
for(Player player : Main.plugin.board.getPlayers()) {
|
||||||
Main.plugin.board.createLobbyBoard(player);
|
Main.plugin.board.createLobbyBoard(player);
|
||||||
|
@ -146,12 +159,12 @@ public class Game {
|
||||||
if(( Main.plugin.status == Status.STARTING || Main.plugin.status == Status.PLAYING ) && Main.plugin.board.sizeHider() < 1) {
|
if(( Main.plugin.status == Status.STARTING || Main.plugin.status == Status.PLAYING ) && Main.plugin.board.sizeHider() < 1) {
|
||||||
if(announceMessagesToNonPlayers) Bukkit.broadcastMessage(gameoverPrefix + message("GAME_GAMEOVER_HIDERS_FOUND"));
|
if(announceMessagesToNonPlayers) Bukkit.broadcastMessage(gameoverPrefix + message("GAME_GAMEOVER_HIDERS_FOUND"));
|
||||||
else Util.broadcastMessage(gameoverPrefix + message("GAME_GAMEOVER_HIDERS_FOUND"));
|
else Util.broadcastMessage(gameoverPrefix + message("GAME_GAMEOVER_HIDERS_FOUND"));
|
||||||
stop();
|
stop(WinType.SEEKER_WIN);
|
||||||
}
|
}
|
||||||
if(( Main.plugin.status == Status.STARTING || Main.plugin.status == Status.PLAYING ) && Main.plugin.board.sizeSeeker() < 1) {
|
if(( Main.plugin.status == Status.STARTING || Main.plugin.status == Status.PLAYING ) && Main.plugin.board.sizeSeeker() < 1) {
|
||||||
if(announceMessagesToNonPlayers) Bukkit.broadcastMessage(abortPrefix + message("GAME_GAMEOVER_SEEKERS_QUIT"));
|
if(announceMessagesToNonPlayers) Bukkit.broadcastMessage(abortPrefix + message("GAME_GAMEOVER_SEEKERS_QUIT"));
|
||||||
else Util.broadcastMessage(abortPrefix + message("GAME_GAMEOVER_SEEKERS_QUIT"));
|
else Util.broadcastMessage(abortPrefix + message("GAME_GAMEOVER_SEEKERS_QUIT"));
|
||||||
stop();
|
stop(WinType.NONE);
|
||||||
}
|
}
|
||||||
|
|
||||||
tick++;
|
tick++;
|
||||||
|
@ -219,7 +232,7 @@ public class Game {
|
||||||
if(timeLeft < 1) {
|
if(timeLeft < 1) {
|
||||||
if(announceMessagesToNonPlayers) Bukkit.broadcastMessage(gameoverPrefix + message("GAME_GAMEOVER_TIME"));
|
if(announceMessagesToNonPlayers) Bukkit.broadcastMessage(gameoverPrefix + message("GAME_GAMEOVER_TIME"));
|
||||||
else Util.broadcastMessage(gameoverPrefix + message("GAME_GAMEOVER_TIME"));
|
else Util.broadcastMessage(gameoverPrefix + message("GAME_GAMEOVER_TIME"));
|
||||||
stop();
|
stop(WinType.HIDER_WIN);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,7 @@
|
||||||
|
package net.tylermurphy.hideAndSeek.game;
|
||||||
|
|
||||||
|
public enum WinType {
|
||||||
|
HIDER_WIN,
|
||||||
|
SEEKER_WIN,
|
||||||
|
NONE
|
||||||
|
}
|
|
@ -73,6 +73,10 @@ public class Board {
|
||||||
return Seeker.stream().map(playerName -> playerList.get(playerName)).collect(Collectors.toList());
|
return Seeker.stream().map(playerName -> playerList.get(playerName)).collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Player getFirstSeeker(){
|
||||||
|
return playerList.get(Seeker.get(0));
|
||||||
|
}
|
||||||
|
|
||||||
public List<Player> getSpectators(){
|
public List<Player> getSpectators(){
|
||||||
return Spectator.stream().map(playerName -> playerList.get(playerName)).collect(Collectors.toList());
|
return Spectator.stream().map(playerName -> playerList.get(playerName)).collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,8 @@ package net.tylermurphy.hideAndSeek.util;
|
||||||
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.*;
|
||||||
|
|
||||||
|
import java.lang.annotation.Retention;
|
||||||
|
import java.lang.annotation.RetentionPolicy;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
@ -38,6 +40,8 @@ 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, Command cmd, String label, String[] args) {
|
||||||
|
|
|
@ -0,0 +1,84 @@
|
||||||
|
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('-');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -3,10 +3,13 @@ package net.tylermurphy.hideAndSeek.util;
|
||||||
import static net.tylermurphy.hideAndSeek.configuration.Config.*;
|
import static net.tylermurphy.hideAndSeek.configuration.Config.*;
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
|
import java.nio.ByteBuffer;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
import com.google.common.io.ByteStreams;
|
||||||
import net.md_5.bungee.api.ChatColor;
|
import net.md_5.bungee.api.ChatColor;
|
||||||
import net.tylermurphy.hideAndSeek.configuration.Items;
|
import net.tylermurphy.hideAndSeek.configuration.Items;
|
||||||
import net.tylermurphy.hideAndSeek.configuration.LocalizationString;
|
import net.tylermurphy.hideAndSeek.configuration.LocalizationString;
|
||||||
|
@ -92,4 +95,22 @@ public class Util {
|
||||||
for(ItemStack i : player.getInventory().getContents())
|
for(ItemStack i : player.getInventory().getContents())
|
||||||
if(hi.isSimilar(i)) player.getInventory().remove(i);
|
if(hi.isSimilar(i)) player.getInventory().remove(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static InputStream convertUniqueId(UUID uuid) {
|
||||||
|
byte[] bytes = new byte[16];
|
||||||
|
ByteBuffer.wrap(bytes)
|
||||||
|
.putLong(uuid.getMostSignificantBits())
|
||||||
|
.putLong(uuid.getLeastSignificantBits());
|
||||||
|
return new ByteArrayInputStream(bytes);
|
||||||
|
}
|
||||||
|
|
||||||
|
public 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 e) {}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -60,7 +60,8 @@ Localization:
|
||||||
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: "Der Spieler hat keine Gameplay-Informationen."
|
||||||
|
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
|
||||||
type: "de-DE"
|
type: "de-DE"
|
||||||
|
|
|
@ -60,6 +60,8 @@ Localization:
|
||||||
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
|
||||||
|
|
Loading…
Reference in a new issue