1.3.1 build 2

This commit is contained in:
Tyler Murphy 2021-10-28 23:09:28 -04:00
parent 27dc2bbf90
commit 3ebb86268a
17 changed files with 368 additions and 191 deletions

2
.gitignore vendored
View file

@ -4,3 +4,5 @@ project
bin/
target/
.git/
.idea
hideandseek-plugin.iml

View file

@ -1,23 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>hideandseek-plugin</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
</natures>
</projectDescription>

18
pom.xml
View file

@ -1,8 +1,14 @@
<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>
<?xml version="1.0" encoding="UTF-8"?>
<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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>net.tylermurphy</groupId>
<artifactId>HideAndSeek</artifactId>
<version>1.3.0</version>
<version>1.3.1</version>
<name>Hide and Seek Plugin</name>
<build>
<plugins>
<plugin>
@ -16,6 +22,7 @@
</plugin>
</plugins>
</build>
<repositories>
<repository>
<id>spigot-repo</id>
@ -26,6 +33,7 @@
<url>https://repo.dmulloy2.net/repository/public/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>org.spigotmc</groupId>
@ -40,4 +48,10 @@
<version>4.7.0</version>
</dependency>
</dependencies>
<properties>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
</properties>
</project>

View file

@ -61,10 +61,8 @@ public class Main extends JavaPlugin implements Listener {
data = this.getDataFolder();
// Init Configuration
Main.plugin.saveResource("localization.yml", false);
Main.plugin.saveResource("config.yml", false);
Config.loadConfig();
Localization.init();
Localization.loadLocalization();
// Create World Loader
worldLoader = new WorldLoader(spawnWorld);

View file

@ -40,6 +40,7 @@ public class EventListener implements Listener {
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);
}
}

View file

@ -7,7 +7,7 @@ public class About implements ICommand {
public void execute(CommandSender sender, String[] args) {
sender.sendMessage(
String.format("%s%sHide and Seek %s(1.3.0%s)\n", ChatColor.AQUA, ChatColor.BOLD, ChatColor.GRAY,ChatColor.WHITE,ChatColor.GRAY) +
String.format("%s%sHide and Seek %s(1.3.1%s)\n", ChatColor.AQUA, ChatColor.BOLD, ChatColor.GRAY,ChatColor.WHITE,ChatColor.GRAY) +
String.format("%sAuthor: %s[KenshinEto]\n", ChatColor.GRAY, ChatColor.WHITE) +
String.format("%sHelp Command: %s/hs %shelp", ChatColor.GRAY, ChatColor.AQUA, ChatColor.WHITE)
);

View file

@ -19,7 +19,7 @@ public class Reload implements ICommand {
return;
}
Config.loadConfig();
Localization.init();
Localization.loadLocalization();
sender.sendMessage(messagePrefix + message("CONFIG_RELOAD"));
}

View file

@ -26,9 +26,7 @@ public class SetBorder implements ICommand {
}
if(args.length < 2) {
worldborderEnabled = false;
Map<String, Object> temp = new HashMap<String,Object>();
temp.put("enabled", false);
addToSection("worldBorder",temp);
addToConfig("worldBorder.enabled",false);
saveConfig();
sender.sendMessage(messagePrefix + message("WORLDBORDER_DISABLE"));
Worldborder.resetWorldborder(spawnWorld);
@ -60,13 +58,11 @@ public class SetBorder implements ICommand {
worldborderSize = num;
worldborderDelay = delay;
worldborderEnabled = true;
Map<String, Object> temp = new HashMap<String,Object>();
temp.put("x", worldborderPosition.getBlockX());
temp.put("z", worldborderPosition.getBlockZ());
temp.put("delay", worldborderDelay);
temp.put("size", worldborderSize);
temp.put("enabled", true);
addToSection("worldBorder",temp);
addToConfig("worldBorder.x", worldborderPosition.getBlockX());
addToConfig("worldBorder.z", worldborderPosition.getBlockZ());
addToConfig("worldBorder.delay", worldborderDelay);
addToConfig("worldBorder.size", worldborderSize);
addToConfig("worldBorder.enabled", true);
sender.sendMessage(messagePrefix + message("WORLDBORDER_ENABLE").addAmount(num).addAmount(delay));
saveConfig();
Worldborder.resetWorldborder(spawnWorld);

View file

@ -27,11 +27,10 @@ public class SetExitLocation implements ICommand {
exitPosition = newExitPosition;
sender.sendMessage(messagePrefix + message("EXIT_SPAWN"));
Map<String, Object> temp = new HashMap<String,Object>();
temp.put("x", exitPosition.getX());
temp.put("y", exitPosition.getY());
temp.put("z", exitPosition.getZ());
temp.put("world", player.getLocation().getWorld().getName());
addToSection("spawns.exit",temp);
addToConfig("spawns.exit.x", exitPosition.getX());
addToConfig("spawns.exit.y", exitPosition.getY());
addToConfig("spawns.exit.z", exitPosition.getZ());
addToConfig("spawns.exit.world", player.getLocation().getWorld().getName());
saveConfig();
}

View file

@ -26,12 +26,10 @@ public class SetLobbyLocation implements ICommand {
}
lobbyPosition = newLobbyPosition;
sender.sendMessage(messagePrefix + message("LOBBY_SPAWN"));
Map<String, Object> temp = new HashMap<String,Object>();
temp.put("x", lobbyPosition.getX());
temp.put("y", lobbyPosition.getY());
temp.put("z", lobbyPosition.getZ());
temp.put("world", player.getLocation().getWorld().getName());
addToSection("spawns.lobby",temp);
addToConfig("spawns.lobby.x", lobbyPosition.getX());
addToConfig("spawns.lobby.y", lobbyPosition.getY());
addToConfig("spawns.lobby.z", lobbyPosition.getZ());
addToConfig("spawns.lobby.world", player.getLocation().getWorld().getName());
saveConfig();
}

View file

@ -10,6 +10,8 @@ import org.bukkit.entity.Player;
import org.bukkit.util.Vector;
import net.tylermurphy.hideAndSeek.Main;
import static net.tylermurphy.hideAndSeek.configuration.Config.addToConfig;
import static net.tylermurphy.hideAndSeek.configuration.Localization.*;
public class SetSpawnLocation implements ICommand {
@ -30,12 +32,10 @@ public class SetSpawnLocation implements ICommand {
}
spawnPosition = newSpawnPosition;
sender.sendMessage(messagePrefix + message("GAME_SPAWN"));
Map<String, Object> temp = new HashMap<String,Object>();
temp.put("x", spawnPosition.getX());
temp.put("y", spawnPosition.getY());
temp.put("z", spawnPosition.getZ());
temp.put("world", player.getLocation().getWorld().getName());
addToSection("spawns.game",temp);
addToConfig("spawns.game.x", spawnPosition.getX());
addToConfig("spawns.game.y", spawnPosition.getY());
addToConfig("spawns.game.z", spawnPosition.getZ());
addToConfig("spawns.game.world", player.getLocation().getWorld().getName());
saveConfig();
}

View file

@ -1,16 +1,20 @@
package net.tylermurphy.hideAndSeek.configuration;
import java.io.File;
import java.util.Map;
import java.util.Map.Entry;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.util.Vector;
import net.tylermurphy.hideAndSeek.Main;
public class Config {
static ConfigManager manager;
public static String
messagePrefix,
errorPrefix,
@ -46,95 +50,78 @@ public class Config {
saveMaxX,
saveMaxZ;
public static FileConfiguration getConfig() {
return Main.plugin.getConfig();
}
public static void saveConfig() {
Main.plugin.saveConfig();
}
public static void loadConfig() {
Main.plugin.reloadConfig();
manager = new ConfigManager("config.yml");
//Spawn
spawnPosition = new Vector(
getConfig().getDouble("spawns.game.x"),
Math.max(0,Math.min(255,getConfig().getDouble("spawns.game.y"))),
getConfig().getDouble("spawns.game.z")
manager.getDouble("spawns.game.x"),
Math.max(0, Math.min(255, manager.getDouble("spawns.game.y"))),
manager.getDouble("spawns.game.z")
);
spawnWorld = getConfig().getString("spawns.game.world");
spawnWorld = manager.getString("spawns.game.world");
///Lobby
lobbyPosition = new Vector(
getConfig().getDouble("spawns.lobby.x"),
Math.max(0,Math.min(255,getConfig().getDouble("spawns.lobby.y"))),
getConfig().getDouble("spawns.lobby.z")
manager.getDouble("spawns.lobby.x"),
Math.max(0, Math.min(255, manager.getDouble("spawns.lobby.y"))),
manager.getDouble("spawns.lobby.z")
);
lobbyWorld = getConfig().getString("spawns.lobby.world");
lobbyWorld = manager.getString("spawns.lobby.world");
announceMessagesToNonPlayers = getConfig().getBoolean("announceMessagesToNonPlayers");
announceMessagesToNonPlayers = manager.getBoolean("announceMessagesToNonPlayers");
exitPosition = new Vector(
getConfig().getDouble("spawns.exit.x"),
Math.max(0,Math.min(255,getConfig().getDouble("spawns.exit.y"))),
getConfig().getDouble("spawns.exit.z")
manager.getDouble("spawns.exit.x"),
Math.max(0, Math.min(255, manager.getDouble("spawns.exit.y"))),
manager.getDouble("spawns.exit.z")
);
exitWorld = getConfig().getString("spawns.exit.world");
exitWorld = manager.getString("spawns.exit.world");
//World border
worldborderPosition = new Vector(
getConfig().getInt("worldBorder.x"),
manager.getInt("worldBorder.x"),
0,
getConfig().getInt("worldBorder.z")
manager.getInt("worldBorder.z")
);
worldborderSize = Math.max(100,getConfig().getInt("worldBorder.size"));
worldborderDelay = Math.max(1,getConfig().getInt("worldBorder.delay"));
worldborderEnabled = getConfig().getBoolean("worldBorder.enabled");
worldborderSize = Math.max(100, manager.getInt("worldBorder.size"));
worldborderDelay = Math.max(1, manager.getInt("worldBorder.delay"));
worldborderEnabled = manager.getBoolean("worldBorder.enabled");
//Prefix
char SYMBOLE = '\u00A7';
String SYMBOLE_STRING = new String(new char[] {SYMBOLE});
String SYMBOLE_STRING = new String(new char[]{SYMBOLE});
messagePrefix = getConfig().getString("prefix.default").replace("&", SYMBOLE_STRING);
errorPrefix = getConfig().getString("prefix.error").replace("&", SYMBOLE_STRING);
tauntPrefix = getConfig().getString("prefix.taunt").replace("&", SYMBOLE_STRING);
worldborderPrefix = getConfig().getString("prefix.border").replace("&", SYMBOLE_STRING);
abortPrefix = getConfig().getString("prefix.abort").replace("&", SYMBOLE_STRING);
gameoverPrefix = getConfig().getString("prefix.gameover").replace("&", SYMBOLE_STRING);
warningPrefix = getConfig().getString("prefix.warning").replace("&", SYMBOLE_STRING);
messagePrefix = manager.getString("prefix.default").replace("&", SYMBOLE_STRING);
errorPrefix = manager.getString("prefix.error").replace("&", SYMBOLE_STRING);
tauntPrefix = manager.getString("prefix.taunt").replace("&", SYMBOLE_STRING);
worldborderPrefix = manager.getString("prefix.border").replace("&", SYMBOLE_STRING);
abortPrefix = manager.getString("prefix.abort").replace("&", SYMBOLE_STRING);
gameoverPrefix = manager.getString("prefix.gameover").replace("&", SYMBOLE_STRING);
warningPrefix = manager.getString("prefix.warning").replace("&", SYMBOLE_STRING);
//Map Bounds
saveMinX = getConfig().getInt("bounds.min.x");
saveMinZ = getConfig().getInt("bounds.min.z");
saveMaxX = getConfig().getInt("bounds.max.x");
saveMaxZ = getConfig().getInt("bounds.max.z");
saveMinX = manager.getInt("bounds.min.x");
saveMinZ = manager.getInt("bounds.min.z");
saveMaxX = manager.getInt("bounds.max.x");
saveMaxZ = manager.getInt("bounds.max.z");
//Other
nametagsVisible = getConfig().getBoolean("nametagsVisible");
permissionsRequired = getConfig().getBoolean("permissionsRequired");
minPlayers = Math.max(2,getConfig().getInt("minPlayers"));
gameLength = getConfig().getInt("gameLength");
nametagsVisible = manager.getBoolean("nametagsVisible");
permissionsRequired = manager.getBoolean("permissionsRequired");
minPlayers = Math.max(2, manager.getInt("minPlayers"));
gameLength = manager.getInt("gameLength");
getConfig().options().copyDefaults(true);
saveConfig();
}
public static void addToSection(String sectionName, Map<String,Object> values) {
ConfigurationSection section = getConfig().getConfigurationSection(sectionName);
if(section == null) section = getConfig().createSection(sectionName);
Map<String,Object> sectionValues = section.getValues(true);
for(Entry<String, Object> entry : values.entrySet()) {
sectionValues.put(entry.getKey(), entry.getValue());
}
getConfig().createSection(sectionName, sectionValues);
saveConfig();
manager.saveConfig();
}
public static void addToConfig(String path, Object value) {
getConfig().set(path, value);
manager.set(path, value);
}
public static void saveConfig() {
manager.saveConfig();
}
}

View file

@ -0,0 +1,156 @@
package net.tylermurphy.hideAndSeek.configuration;
import net.tylermurphy.hideAndSeek.Main;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.YamlConfiguration;
import java.io.*;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.util.Map;
public class ConfigManager {
private File file;
private YamlConfiguration config,defaultConfig;
public ConfigManager(String filename){
this.file = new File(Main.plugin.getDataFolder(), filename);
if(!file.exists()){
saveDefaultConfiguration();
}
this.config = YamlConfiguration.loadConfiguration(file);
InputStream input = Main.plugin.getResource(file.getName());
InputStreamReader reader = new InputStreamReader(input);
this.defaultConfig = YamlConfiguration.loadConfiguration(reader);
try{
input.close();
reader.close();
} catch (IOException e){}
}
private void saveDefaultConfiguration(){
try{
InputStream input = Main.plugin.getResource(file.getName());
java.nio.file.Files.copy(input, file.toPath());
input.close();
} catch(IOException e){
e.printStackTrace();
}
}
public void addToSection(String sectionName, Map<String,Object> values) {
ConfigurationSection section = config.getConfigurationSection(sectionName);
if(section == null) section = config.createSection(sectionName);
Map<String,Object> sectionValues = section.getValues(true);
for(Map.Entry<String, Object> entry : values.entrySet()) {
sectionValues.put(entry.getKey(), entry.getValue());
}
config.createSection(sectionName, sectionValues);
}
public void addToConfig(String path, Object value) {
config.set(path, value);
}
public double getDouble(String path){
double value = config.getDouble(path);
if(value == 0.0D){
return defaultConfig.getDouble(path);
} else {
return value;
}
}
public int getInt(String path){
int value = config.getInt(path);
if(value == 0){
return defaultConfig.getInt(path);
} else {
return value;
}
}
public String getString(String path){
String value = config.getString(path);
if(value == null){
return defaultConfig.getString(path);
} else {
return value;
}
}
public boolean getBoolean(String path){
boolean value = config.getBoolean(path);
if(value == false){
return defaultConfig.getBoolean(path);
} else {
return value;
}
}
public ConfigurationSection getConfigurationSection(String path){
ConfigurationSection section = config.getConfigurationSection(path);
if(section == null){
return defaultConfig.getConfigurationSection(path);
} else {
return section;
}
}
public void set(String path, Object value){
config.set(path, value);
}
public void saveConfig(){
try {
InputStream is = Main.plugin.getResource(file.getName());
StringBuilder textBuilder = new StringBuilder();
Reader reader = new BufferedReader(new InputStreamReader(is, Charset.forName(StandardCharsets.UTF_8.name())));
int c = 0;
while((c = reader.read()) != -1){
textBuilder.append((char) c);
}
String yamlString = textBuilder.toString();
Map<String, Object> temp = config.getValues(true);
for(Map.Entry<String, Object> entry: temp.entrySet()){
System.out.println(entry.getKey() + " " + entry.getValue().getClass().getName());
if(entry.getValue() instanceof Integer || entry.getValue() instanceof Double || entry.getValue() instanceof String || entry.getValue() instanceof Boolean){
String[] parts = entry.getKey().split("\\.");
int index = 0;
int i = 0;
for(String part : parts) {
if(i == 0) {
index = yamlString.indexOf(part, index);
} else {
index = yamlString.indexOf(" " + part, index);
index++;
}
i++;
if(index == -1) break;
}
if(index == -1) continue;;
int start = yamlString.indexOf(' ', index);
int end = yamlString.indexOf('\n', index);
String replace = entry.getValue().toString();
if(entry.getValue() instanceof String){
replace = "\"" + replace + "\"";
}
StringBuilder builder = new StringBuilder(yamlString);
builder.replace(start+1, end, replace);
yamlString = builder.toString();
}
}
PrintWriter out = new PrintWriter(file);
out.print(yamlString);
out.close();
} catch (IOException e){
e.printStackTrace();
}
}
}

View file

@ -16,44 +16,29 @@ public class Localization {
public static final Map<String,LocalizationString> LOCAL = new HashMap<String,LocalizationString>();
static YamlConfiguration config, defaultConfig;
static File location;
private static ConfigManager manager;
public static boolean init() {
public static boolean loadLocalization() {
Main.plugin.saveResource("localization.yml", false);
String path = Main.data.getAbsolutePath()+File.separator + "localization.yml";
location = new File(path);
config = YamlConfiguration.loadConfiguration(location);
manager = new ConfigManager("localization.yml");
InputStream is = Main.plugin.getResource("localization.yml");
InputStreamReader isr = new InputStreamReader(is);
defaultConfig = YamlConfiguration.loadConfiguration(isr);
for(String key : config.getConfigurationSection("Localization").getKeys(false)) {
for(String key : manager.getConfigurationSection("Localization").getKeys(false)) {
LOCAL.put(
key,
new LocalizationString( ChatColor.translateAlternateColorCodes('&', config.getString("Localization."+key) ) )
new LocalizationString( ChatColor.translateAlternateColorCodes('&', manager.getString("Localization."+key) ) )
);
}
manager.saveConfig();
return true;
}
public static LocalizationString message(String key) {
LocalizationString temp = LOCAL.get(key);
if(temp == null) {
config.set("Localization."+key, defaultConfig.getString("Localization."+key));
try {
config.save(location);
} catch (IOException e) {
Main.plugin.getLogger().severe(e.getMessage());
}
LOCAL.put(key,
new LocalizationString( ChatColor.translateAlternateColorCodes('&', defaultConfig.getString("Localization."+key) ) )
);
return new LocalizationString(LOCAL.get(key).toString());
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());
}
}

View file

@ -2,9 +2,12 @@ package net.tylermurphy.hideAndSeek.util;
import static net.tylermurphy.hideAndSeek.configuration.Config.*;
import java.io.File;
import java.io.*;
import net.md_5.bungee.api.ChatColor;
import net.tylermurphy.hideAndSeek.configuration.LocalizationString;
import org.bukkit.Bukkit;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player;
import net.tylermurphy.hideAndSeek.Main;
@ -23,6 +26,7 @@ public class Util {
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;
}
@ -35,4 +39,27 @@ public class Util {
}, delay);
}
public YamlConfiguration loadDefaultConfig(String name) {
YamlConfiguration defaultConfig = null;
InputStream deafult_stream = null;
InputStreamReader default_stream_reader = null;
try {
deafult_stream = Class.class.getResourceAsStream(name + ".yml");
default_stream_reader = new InputStreamReader(deafult_stream);
defaultConfig = YamlConfiguration.loadConfiguration(default_stream_reader);
} catch (Exception e) {
// No Issue Here
} finally {
try {
deafult_stream.close();
default_stream_reader.close();
} catch (IOException e) {
e.printStackTrace();
}
}
return defaultConfig;
}
}

View file

@ -42,13 +42,34 @@ spawns:
# The worldborder closes every interval, whish is evey [delay] in minutes.
# Thw worldborder stharts at [size], and decreaces 100 blocks every interval.
# x & z are the center location. [enabled] is whenever the border is enabled.
# You can choose if Hiders are warned 30 seconds before the border moves.
worldBorder:
x: 0
z: 0
delay: 10
size: 500
warn: true
enabled: false
# The taunt will activate every delay set in seconds. It will spawn a firework
# on a random Hider to alert a Seeker where someone may be. You can choose
# to publially show the taunt countdown, and have the taunt run with only
# one Hider left.
taunt:
delay: 360
whenLastPerson: false
showCountdown: true
enabled: true
# The glow powerup allows all Hiders to see where every Seeker is. It last for
# the amount of time set in seconds. You can allow it to be stackable, meaning
# when multiple Hiders use the powerup at the same time, it stacks the times, or
# just overwrites. Only Hiders can see that the Seekers are glowing.
glow:
time: 30
stackable: true
enabled: true
# The message prefixes displayed before messages. The message contents themselvs
# can be changed in localization.yml.
prefix:
@ -59,3 +80,19 @@ prefix:
abort: '&cAbort > &f'
gameover: '&aGame Over > &f'
warning: '&cWarning > &f'
# ---------------------------------------------------------- #
# ONLY EDIT BEYOND THIS POINT IF YOU KNOW WHAT YOU ARE DOING #
# ---------------------------------------------------------- #
# The 2 coordinate bounds that will contain your hideAndSeek map. Its reccomended
# that you use /hs setbounds for this, and not edit this directly, as breaking
# this section will completly break the entire plugin when you run /hs mapsave.
bounds:
min:
x: 0
z: 0
max:
x: 0
z: 0

View file

@ -1,6 +1,6 @@
name: HideAndSeek
main: net.tylermurphy.hideAndSeek.Main
version: 1.3.0
version: 1.3.1
author: KenshinEto
load: STARTUP
api-version: 1.17