mysql support, always glow, countdown_last, kill stat change, game board null fix

This commit is contained in:
Tyler Murphy 2022-05-17 19:26:00 -04:00
parent b74b813636
commit 13e6b38aa9
18 changed files with 146 additions and 110 deletions

View file

@ -41,8 +41,10 @@
<artifact>*:*</artifact>
<excludes>
<exclude>META-INF/*.MF</exclude>
<exclude>META-INF/*.md</exclude>
<exclude>META-INF</exclude>
<exclude>META-INF/*.MD</exclude>
<exclude>META-INF/*.SF</exclude>
<exclude>META-INF/*.DSA</exclude>
<exclude>META-INF/*.RSA</exclude>
<exclude>sqlite-jdbc.properties</exclude>
</excludes>
</filter>

View file

@ -22,6 +22,7 @@ package net.tylermurphy.hideAndSeek.command;
import net.tylermurphy.hideAndSeek.Main;
import net.tylermurphy.hideAndSeek.database.util.PlayerInfo;
import org.bukkit.ChatColor;
import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Player;
import java.util.List;
@ -54,7 +55,13 @@ public class Top implements ICommand {
return;
}
for(PlayerInfo info : infos) {
String name = Main.getInstance().getServer().getOfflinePlayer(info.getUniqueId()).getName();
OfflinePlayer temp = Main.getInstance().getServer().getOfflinePlayer(info.getUniqueId());
String name;
if(temp == null){
name = Main.getInstance().getDatabase().getNameData().getName(info.getUniqueId());
} else {
name = temp.getName();
}
ChatColor color;
switch (i) {
case 1: color = ChatColor.YELLOW; break;

View file

@ -37,23 +37,21 @@ public class Wins implements ICommand {
UUID uuid;
String name;
if (args.length == 0) {
Player player = Main.getInstance().getServer().getPlayer(sender.getName());
if (player == null) {
sender.sendMessage(errorPrefix + message("START_INVALID_NAME").addPlayer(sender.getName()));
return;
}
uuid = player.getUniqueId();
uuid = sender.getUniqueId();
name = sender.getName();
}
else {
try {
name = args[0];
name = args[0];
if(Main.getInstance().getServer().getOfflinePlayer(args[0]) == null){
uuid = Main.getInstance().getDatabase().getNameData().getUUID(args[0]);
} else {
uuid = Main.getInstance().getServer().getOfflinePlayer(args[0]).getUniqueId();
} catch (Exception e) {
sender.sendMessage(errorPrefix + message("START_INVALID_NAME").addPlayer(args[0]));
return;
}
}
if(uuid == null){
sender.sendMessage(errorPrefix + message("START_INVALID_NAME").addPlayer(args[0]));
return;
}
PlayerInfo info = Main.getInstance().getDatabase().getGameData().getInfo(uuid);
if (info == null) {
sender.sendMessage(errorPrefix + message("NO_GAME_INFO"));

View file

@ -55,7 +55,13 @@ public class Config {
locale,
leaveServer,
placeholderError,
placeholderNoData;
placeholderNoData,
databaseType,
databaseHost,
databasePort,
databaseUser,
databasePass,
databaseName;
public static Vector
spawnPosition,
@ -71,6 +77,7 @@ public class Config {
tauntEnabled,
tauntCountdown,
tauntLast,
alwaysGlow,
glowEnabled,
glowStackable,
pvpEnabled,
@ -218,9 +225,10 @@ public class Config {
tauntLast = config.getBoolean("taunt.whenLastPerson");
//Glow
alwaysGlow = config.getBoolean("alwaysGlow") && Main.getInstance().supports(9);
glowLength = Math.max(1, config.getInt("glow.time"));
glowStackable = config.getBoolean("glow.stackable");
glowEnabled = config.getBoolean("glow.enabled") && Main.getInstance().supports(9);
glowEnabled = config.getBoolean("glow.enabled") && Main.getInstance().supports(9) && !alwaysGlow;
if (glowEnabled) {
glowPowerupItem = createItemStack("glow");
}
@ -314,6 +322,19 @@ public class Config {
teleportItem = createItemStack("spectatorItems.teleport");
teleportItemPosition = config.getInt("spectatorItems.teleport.position");
//Database
databaseHost = config.getString("databaseHost");
databasePort = config.getString("databasePort");
databaseUser = config.getString("databaseUser");
databasePass = config.getString("databasePass");
databaseName = config.getString("databaseName");
databaseType = config.getString("databaseType").toUpperCase();
if(!databaseType.equals("SQLITE") && !databaseType.equals("MYSQL")){
Main.getInstance().getLogger().warning("databaseType: "+databaseType+" is not a valid configuration option!");
databaseType = "SQLITE";
}
}
public static void addToConfig(String path, Object value) {

View file

@ -205,6 +205,10 @@ public class ConfigManager {
}
}
public ConfigurationSection getDefaultConfigurationSection(String path) {
return defaultConfig.getConfigurationSection(path);
}
public void set(String path, Object value) {
config.set(path, value);
}

View file

@ -28,6 +28,7 @@ import java.util.Map;
public class Localization {
public static final Map<String,LocalizationString> LOCAL = new HashMap<>();
public static final Map<String,LocalizationString> DEFAULT_LOCAL = new HashMap<>();
private static final Map<String,String[][]> CHANGES = new HashMap<String,String[][]>() {{
put("en-US", new String[][]{{"WORLDBORDER_DECREASING"},{"START","TAUNTED"}});
@ -63,15 +64,26 @@ public class Localization {
LOCAL.put(
key,
new LocalizationString( ChatColor.translateAlternateColorCodes('&', manager.getString("Localization."+key) ) )
);
);
}
for(String key : manager.getDefaultConfigurationSection("Localization").getKeys(false)) {
DEFAULT_LOCAL.put(
key,
new LocalizationString( ChatColor.translateAlternateColorCodes('&', manager.getString("Localization."+key) ) )
);
}
}
public static LocalizationString message(String key) {
LocalizationString temp = LOCAL.get(key);
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.");
LocalizationString message = LOCAL.get(key);
if (message == null) {
LocalizationString defaultMessage = DEFAULT_LOCAL.get(key);
if(defaultMessage == 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(defaultMessage.toString());
}
return new LocalizationString(temp.toString());
return new LocalizationString(message.toString());
}
}

View file

@ -22,6 +22,7 @@ package net.tylermurphy.hideAndSeek.database;
import com.google.common.io.ByteStreams;
import net.tylermurphy.hideAndSeek.Main;
import net.tylermurphy.hideAndSeek.database.connections.DatabaseConnection;
import net.tylermurphy.hideAndSeek.database.connections.MySQLConnection;
import net.tylermurphy.hideAndSeek.database.connections.SQLiteConnection;
import java.io.ByteArrayInputStream;
@ -32,6 +33,8 @@ import java.sql.Connection;
import java.sql.SQLException;
import java.util.UUID;
import static net.tylermurphy.hideAndSeek.configuration.Config.databaseType;
public class Database {
private final GameDataTable playerInfo;
@ -40,7 +43,11 @@ public class Database {
public Database(){
connection = new SQLiteConnection();
if(databaseType.equals("SQLITE")) {
connection = new SQLiteConnection();
} else {
connection = new MySQLConnection();
}
playerInfo = new GameDataTable(this);

View file

@ -25,26 +25,22 @@ import com.zaxxer.hikari.HikariDataSource;
import java.sql.Connection;
import java.sql.SQLException;
import static net.tylermurphy.hideAndSeek.configuration.Config.*;
public class MySQLConnection implements DatabaseConnection {
private final HikariConfig config;
private final HikariDataSource ds;
public MySQLConnection(){
String host = "to be implemented";
String port = "to be implemented";
String user = "to be implemented";
String pass = "to be implemented";
HikariConfig config = new HikariConfig();
config = new HikariConfig();
config.setJdbcUrl("jdbc:mariadb://"+host+":"+port+"/kenbot");
config.setJdbcUrl("jdbc:mariadb://"+databaseHost+":"+databasePort+"/"+databaseName);
config.addDataSourceProperty("cachePrepStmts", "true");
config.addDataSourceProperty("prepStmtCacheSize", "250");
config.addDataSourceProperty("prepStmtCacheSqlLimit", "2048");
config.addDataSourceProperty("user", user);
config.addDataSourceProperty("password",pass);
config.addDataSourceProperty("user", databaseUser);
config.addDataSourceProperty("password",databasePass);
config.addDataSourceProperty("autoCommit", "true");
config.setAutoCommit(true);
config.setMaximumPoolSize(20);

View file

@ -153,7 +153,7 @@ public class Board {
} else {
hider_kills.put(uuid.toString(), 1);
}
} else if (getFirstSeeker().getUniqueId().equals(uuid)) {
} else if (Seeker.contains(uuid.toString())) {
if (seeker_kills.containsKey(uuid.toString())) {
seeker_kills.put(uuid.toString(), seeker_kills.get(uuid.toString())+1);
} else {
@ -169,7 +169,7 @@ public class Board {
} else {
hider_deaths.put(uuid.toString(), 1);
}
} else if (getFirstSeeker().getUniqueId().equals(uuid)) {
} else if (Seeker.contains(uuid.toString())) {
if (seeker_deaths.containsKey(uuid.toString())) {
seeker_deaths.put(uuid.toString(), seeker_deaths.get(uuid.toString())+1);
} else {
@ -234,7 +234,7 @@ public class Board {
private void createGameBoard(Player player, boolean recreate) {
CustomBoard board = customBoards.get(player.getUniqueId().toString());
if (recreate) {
if (recreate || board == null) {
board = new CustomBoard(player, GAME_TITLE);
board.updateTeams();
}

View file

@ -242,12 +242,14 @@ public class Game {
private void whileStarting() {
if(gameTick % 20 == 0) {
if (startingTimer % 5 == 0 || startingTimer < 4) {
if (startingTimer % 5 == 0 || startingTimer < 5) {
String message;
if (startingTimer == 0) {
message = message("START").toString();
status = Status.PLAYING;
board.getPlayers().forEach(player -> PlayerLoader.resetPlayer(player, board));
} else if (startingTimer == 1){
message = message("START_COUNTDOWN_LAST").addAmount(startingTimer).toString();
} else {
message = message("START_COUNTDOWN").addAmount(startingTimer).toString();
}
@ -305,7 +307,7 @@ public class Game {
}
if (worldBorderEnabled) worldBorder.update();
if (tauntEnabled) taunt.update();
if (glowEnabled) glow.update();
if (glowEnabled || alwaysGlow) glow.update();
}
board.getSpectators().forEach(spectator -> spectator.setFlying(spectator.getAllowFlight()));
checkWinConditions();

View file

@ -10,8 +10,7 @@ import org.bukkit.entity.Player;
import java.lang.reflect.InvocationTargetException;
import static net.tylermurphy.hideAndSeek.configuration.Config.glowLength;
import static net.tylermurphy.hideAndSeek.configuration.Config.glowStackable;
import static net.tylermurphy.hideAndSeek.configuration.Config.*;
public class Glow {
@ -37,6 +36,10 @@ public class Glow {
}
public void update() {
if(alwaysGlow){
sendPackets();
return;
}
if (running) {
sendPackets();
glowTime--;

View file

@ -96,21 +96,18 @@ public class DamageHandler implements Listener {
// Broadcast player death message
if (board.isSeeker(player)) {
game.broadcastMessage(message("GAME_PLAYER_DEATH").addPlayer(player).toString());
if (board.getFirstSeeker().getName().equals(player.getName())) {
board.addDeath(player.getUniqueId());
}
} else if (board.isHider(player)) {
if (attacker == null) {
game.broadcastMessage(message("GAME_PLAYER_FOUND").addPlayer(player).toString());
} else {
game.broadcastMessage(message("GAME_PLAYER_FOUND_BY").addPlayer(player).addPlayer(attacker).toString());
}
board.addDeath(player.getUniqueId());
board.addSeeker(player);
}
// Add leaderboard kills if attacker
if (attacker != null && ( board.isHider(attacker) || board.getFirstSeeker().getName().equals(attacker.getName()) ) )
board.addKill(attacker.getUniqueId());
// Add leaderboard stats
board.addDeath(player.getUniqueId());
if (attacker != null) board.addKill(attacker.getUniqueId());
//Reload player
PlayerLoader.resetPlayer(player, board);
board.reloadBoardTeams();
}

View file

@ -23,8 +23,8 @@ public class JoinLeaveHandler implements Listener {
@EventHandler(priority = EventPriority.HIGHEST)
public void onPlayerJoin(PlayerJoinEvent event) {
if(!Main.getInstance().getDatabase().getNameData().update(event.getPlayer().getUniqueId(), event.getPlayer().getDisplayName())){
Main.getInstance().getLogger().warning("Failed to save name data for user: " + event.getPlayer().getDisplayName());
if(!Main.getInstance().getDatabase().getNameData().update(event.getPlayer().getUniqueId(), event.getPlayer().getName())){
Main.getInstance().getLogger().warning("Failed to save name data for user: " + event.getPlayer().getName());
}
Main.getInstance().getBoard().remove(event.getPlayer());
removeItems(event.getPlayer());

View file

@ -39,15 +39,17 @@ public class PAPIExpansion extends PlaceholderExpansion {
Database database = Main.getInstance().getDatabase();
String[] args = params.split("_");
if (args.length < 1) return null;
if (args[0].equals("stats") && args.length == 2) {
PlayerInfo info = database.getGameData().getInfo(player.getUniqueId());
if (args[0].equals("stats") && (args.length == 2 || args.length == 3)) {
PlayerInfo info = null;
if(args.length == 2) {
database.getGameData().getInfo(player.getUniqueId());
} else {
UUID uuid;
try { uuid = Main.getInstance().getServer().getOfflinePlayer(args[2]).getUniqueId(); } catch (Exception e) { return placeholderError; }
info = database.getGameData().getInfo(uuid);
}
if (info == null) return placeholderNoData;
return getValue(info, args[1]);
} else if (args[0].equals("stats") && args.length == 3) {
UUID uuid;
try { uuid = Main.getInstance().getServer().getOfflinePlayer(args[2]).getUniqueId(); } catch (Exception e) { return placeholderError; }
PlayerInfo info = database.getGameData().getInfo(uuid);
return getValue(info, args[1]);
} else if ((args[0].equals("rank-score") || args[0].equals("rank-name") ) && args.length == 3) {
int place;
try { place = Integer.parseInt(args[2]); } catch (NumberFormatException e) { return placeholderError; }
@ -60,24 +62,21 @@ public class PAPIExpansion extends PlaceholderExpansion {
} else {
return Main.getInstance().getServer().getOfflinePlayer(info.getUniqueId()).getName();
}
} else if (args[0].equals("rank-place") && args.length == 2) {
} else if (args[0].equals("rank-place") && (args.length == 2 || args.length == 3)) {
if (getRanking(args[1]) == null) { return placeholderError; }
PlayerInfo info = database.getGameData().getInfo(player.getUniqueId());
PlayerInfo info = null;
if(args.length == 2){
database.getGameData().getInfo(player.getUniqueId());
} else {
UUID uuid;
try { uuid = Main.getInstance().getServer().getOfflinePlayer(args[2]).getUniqueId(); } catch (Exception e) { return placeholderError; }
info = database.getGameData().getInfo(uuid);
}
if (info == null) return placeholderNoData;
if (getValue(info, args[1]).equals("0")) { return "-"; }
Integer count = database.getGameData().getRanking(getRanking(args[1]), player.getUniqueId());
if (count == null) { return placeholderNoData; }
return count.toString();
} else if (args[0].equals("rank-place") && args.length == 3) {
UUID uuid;
try { uuid = Main.getInstance().getServer().getOfflinePlayer(args[2]).getUniqueId(); } catch (Exception e) { return placeholderError; }
if (getRanking(args[1]) == null) { return placeholderError; }
PlayerInfo info = database.getGameData().getInfo(player.getUniqueId());
if (info == null) return placeholderNoData;
if (getValue(info, args[1]).equals("0")) { return "-"; }
Integer count = database.getGameData().getRanking(getRanking(args[1]), uuid);
if (count == null) { return placeholderNoData; }
return count.toString();
}
return null;
}

View file

@ -94,6 +94,26 @@ leaveServer: hub
# default: true
mapSaveEnabled: true
# How you want to store game data. If you are running a single server, sqlite is fine, as no setup is necessary.
# But if you want the data to go across multiple servers, you can switch it to mysql.
# WARNING: Data is not saved across databases. You have to migrate the data yourself!
#
# SQLITE - A single database.db file in the plugin folder, good for a single server.
#
# MYSQL - Uses a mysql server to store data, good for multi-server setups or large servers.
#
# default: SQLITE
databaseType: SQLITE
# The following settings are used for MYSQL databases ONLY. If you are running SQLITE, these
# will be ignored. If you are running MYSQL, you need to provide the database host url, database
# host port (usually 3306), database username, and database password.
databaseHost: localhost
databasePort: 3306
databaseUser: root
databasePass:
databaseName: hideandseek
# The world border closes every interval, which is evey [delay] in minutes.
# Thw world border starts at [size], and decreases 100 blocks every interval.
# x & z are the center location. [enabled] is whenever the border is enabled.
@ -132,6 +152,14 @@ glow:
material: SNOWBALL
model-data: 0
# This has the same glow effect as the glow powerup in that all seekers positions get
# shown to hiders. But enabling this force disables the powerup, and instead always shows
# the seekers positions to the hiders. Good for small maps. Since the glow effect wasn't added
# until Minecraft 1.9, any server running 1.8 will have this disabled regardless of the
# options below.
# default: false
alwaysGlow: false
# The message prefixes displayed before messages. The message contents themselves
# can be changed in localization.yml.
prefix:

View file

@ -56,6 +56,7 @@ Localization:
START_MIN_PLAYERS: "Um das Spiel zu starten benötigst du mindestens {AMOUNT} Spieler."
START_INVALID_NAME: "Ungültiger Spieler: {PLAYER}."
START_COUNTDOWN: "Die Hider haben {AMOUNT} Sekunden Zeit sich zu verstecken!"
START_COUNTDOWN_LAST: "Die Hider haben {AMOUNT} Sekunde Zeit sich zu verstecken!"
START: "Los, Seeker! Es ist Zeit, die Hider zu finden."
STOP: "Das Spiel wurde gestoppt."
HIDER_TEAM_NAME: "&6&lHIDER"

View file

@ -57,6 +57,7 @@ Localization:
START_MIN_PLAYERS: "You must have at least {AMOUNT} players to start."
START_INVALID_NAME: "Invalid player: {PLAYER}."
START_COUNTDOWN: "Hiders have {AMOUNT} seconds to hide!"
START_COUNTDOWN_LAST: "Hiders have {AMOUNT} second to hide!"
START: "Attention SEEKERS, its time to find the hiders!"
STOP: "Game has been force stopped."
HIDER_TEAM_NAME: "&6&lHIDER"

View file

@ -1,42 +0,0 @@
/*
* This file is part of Kenshins Hide and Seek
*
* Copyright (c) 2022 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/>.
*
*/
import be.seeseemelk.mockbukkit.MockBukkit;
import be.seeseemelk.mockbukkit.ServerMock;
import net.tylermurphy.hideAndSeek.Main;
import org.junit.After;
import org.junit.Before;
public class MainTest {
private ServerMock server;
private Main plugin;
@Before
public void setUp() {
server = MockBukkit.mock();
plugin = MockBukkit.load(Main.class);
}
@After
public void tearDown() {
MockBukkit.unmock();
}
}