Fixes default values not being copied for messages
This commit is contained in:
parent
8f704f9d87
commit
943a273423
@ -70,9 +70,8 @@ public class BlockHunt extends JavaPlugin implements Listener {
|
|||||||
|
|
||||||
private static PluginDescriptionFile pluginDescriptionFile;
|
private static PluginDescriptionFile pluginDescriptionFile;
|
||||||
public static BlockHunt plugin;
|
public static BlockHunt plugin;
|
||||||
public String rootPermission = BlockHunt.getPluginDescriptionFile().getName().toLowerCase() + ".";
|
public String rootPermission;
|
||||||
|
|
||||||
@SuppressWarnings("serial")
|
|
||||||
public static final List<String> BlockHuntCMD = new ArrayList<>() {
|
public static final List<String> BlockHuntCMD = new ArrayList<>() {
|
||||||
{
|
{
|
||||||
add("info");
|
add("info");
|
||||||
@ -129,7 +128,8 @@ public class BlockHunt extends JavaPlugin implements Listener {
|
|||||||
|
|
||||||
ConfigurationSerialization.registerClass(Arena.class, "BlockHuntArena");
|
ConfigurationSerialization.registerClass(Arena.class, "BlockHuntArena");
|
||||||
|
|
||||||
pluginDescriptionFile = getDescription();
|
BlockHunt.pluginDescriptionFile = getDescription();
|
||||||
|
this.rootPermission = BlockHunt.getPluginDescriptionFile().getName().toLowerCase() + ".";
|
||||||
plugin = this;
|
plugin = this;
|
||||||
|
|
||||||
ConfigManager.newFiles();
|
ConfigManager.newFiles();
|
||||||
@ -271,7 +271,8 @@ public class BlockHunt extends JavaPlugin implements Listener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (Player player : arena.seekers) {
|
for (Player player : arena.seekers) {
|
||||||
if (player.getInventory().getItem(0) == null || player.getInventory().getItem(0).getType() != Material.DIAMOND_SWORD) {
|
ItemStack item = player.getInventory().getItem(0);
|
||||||
|
if (item == null || item.getType() != Material.DIAMOND_SWORD) {
|
||||||
player.getInventory().clear(); // semi prevent duping infinite swords. TODO: Fix this properly
|
player.getInventory().clear(); // semi prevent duping infinite swords. TODO: Fix this properly
|
||||||
ItemStack i = new ItemStack(Material.DIAMOND_SWORD, 1);
|
ItemStack i = new ItemStack(Material.DIAMOND_SWORD, 1);
|
||||||
i.addUnsafeEnchantment(Enchantment.DAMAGE_ALL, 10);
|
i.addUnsafeEnchantment(Enchantment.DAMAGE_ALL, 10);
|
||||||
@ -316,7 +317,8 @@ public class BlockHunt extends JavaPlugin implements Listener {
|
|||||||
ArrayList<String> remainingBlocks = new ArrayList<>();
|
ArrayList<String> remainingBlocks = new ArrayList<>();
|
||||||
for (Player arenaPlayer : arena.playersInArena) {
|
for (Player arenaPlayer : arena.playersInArena) {
|
||||||
if (!arena.seekers.contains(arenaPlayer)) {
|
if (!arena.seekers.contains(arenaPlayer)) {
|
||||||
String block = arenaPlayer.getInventory().getItem(8).getType().name();
|
ItemStack item = arenaPlayer.getInventory().getItem(8);
|
||||||
|
String block = item == null ? Material.AIR.name() : item.getType().name();
|
||||||
block = WordUtils.capitalizeFully(block.replace("_", " "));
|
block = WordUtils.capitalizeFully(block.replace("_", " "));
|
||||||
if (!remainingBlocks.contains(block)) { //Don't print double up block names.
|
if (!remainingBlocks.contains(block)) { //Don't print double up block names.
|
||||||
remainingBlocks.add(block);
|
remainingBlocks.add(block);
|
||||||
@ -356,8 +358,9 @@ public class BlockHunt extends JavaPlugin implements Listener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (moveLoc != null) {
|
if (moveLoc != null && block != null) {
|
||||||
if (moveLoc.getX() == pLoc.getX() && moveLoc.getY() == pLoc.getY() && moveLoc.getZ() == pLoc.getZ()) {
|
if (moveLoc.getX() == pLoc.getX() && moveLoc.getY() == pLoc.getY() &&
|
||||||
|
moveLoc.getZ() == pLoc.getZ()) {
|
||||||
if (block.getAmount() > 1) {
|
if (block.getAmount() > 1) {
|
||||||
block.setAmount(block.getAmount() - 1);
|
block.setAmount(block.getAmount() - 1);
|
||||||
} else {
|
} else {
|
||||||
@ -436,24 +439,6 @@ public class BlockHunt extends JavaPlugin implements Listener {
|
|||||||
return pluginDescriptionFile;
|
return pluginDescriptionFile;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Args to String. Makes 1 string.
|
|
||||||
*
|
|
||||||
* @param input String list which should be converted to a string.
|
|
||||||
* @param startArg Start on this length.
|
|
||||||
* @return The converted string.
|
|
||||||
*/
|
|
||||||
public static String stringBuilder(String[] input, int startArg) {
|
|
||||||
if (input.length - startArg <= 0) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
StringBuilder sb = new StringBuilder(input[startArg]);
|
|
||||||
for (int i = ++startArg; i < input.length; i++) {
|
|
||||||
sb.append(' ').append(input[i]);
|
|
||||||
}
|
|
||||||
return sb.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command cmd, @NotNull String label, String[] args) {
|
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command cmd, @NotNull String label, String[] args) {
|
||||||
Player player = null;
|
Player player = null;
|
||||||
@ -465,9 +450,9 @@ public class BlockHunt extends JavaPlugin implements Listener {
|
|||||||
String[] argsSplit = null;
|
String[] argsSplit = null;
|
||||||
String[] argsSplitAlias = null;
|
String[] argsSplitAlias = null;
|
||||||
|
|
||||||
if (command.args != null && command.argsalias != null) {
|
if (command.args != null && command.argumentAliases != null) {
|
||||||
argsSplit = command.args.split("/");
|
argsSplit = command.args.split("/");
|
||||||
argsSplitAlias = command.argsalias.split("/");
|
argsSplitAlias = command.argumentAliases.split("/");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cmd.getName().equalsIgnoreCase(command.label)) {
|
if (cmd.getName().equalsIgnoreCase(command.label)) {
|
||||||
|
@ -63,6 +63,7 @@ public class SignsHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isSign(Location location) {
|
public static boolean isSign(Location location) {
|
||||||
|
//TODO: This seems really inefficient
|
||||||
for (String sign : MemoryStorage.signs.getFile().getKeys(false)) {
|
for (String sign : MemoryStorage.signs.getFile().getKeys(false)) {
|
||||||
Location loc = (Location) MemoryStorage.signs.getFile().get(sign + ".location");
|
Location loc = (Location) MemoryStorage.signs.getFile().get(sign + ".location");
|
||||||
if (loc == null) {
|
if (loc == null) {
|
||||||
|
@ -105,7 +105,7 @@ public enum MessageKey implements Key {
|
|||||||
ERROR_NO_ARENA("%TAG%ENo arena found with the name '%A%name%%E'.", "error.noArena"),
|
ERROR_NO_ARENA("%TAG%ENo arena found with the name '%A%name%%E'.", "error.noArena"),
|
||||||
ERROR_ONLY_IN_GAME("%TAG%EThis is an only in-game command!", "error.onlyInGame"),
|
ERROR_ONLY_IN_GAME("%TAG%EThis is an only in-game command!", "error.onlyInGame"),
|
||||||
ERROR_JOIN_ALREADY_JOINED("%TAG%EYou've already joined an arena!", "error.joinAlreadyJoined"),
|
ERROR_JOIN_ALREADY_JOINED("%TAG%EYou've already joined an arena!", "error.joinAlreadyJoined"),
|
||||||
ERROR_JOIN_NO_BLOCKS_SET("%TAG%EThere are none blocks set for this arena. Notify the administrator.",
|
ERROR_JOIN_NO_BLOCKS_SET("%TAG%EThere are no blocks set for this arena. Notify the administrator.",
|
||||||
"error.joinNoBlocksSet"),
|
"error.joinNoBlocksSet"),
|
||||||
ERROR_JOIN_WARPS_NOT_SET("%TAG%EThere are no warps set for this arena. Notify the administrator.",
|
ERROR_JOIN_WARPS_NOT_SET("%TAG%EThere are no warps set for this arena. Notify the administrator.",
|
||||||
"error.joinWarpsNotSet"),
|
"error.joinWarpsNotSet"),
|
||||||
|
@ -28,5 +28,5 @@ public enum Permission {
|
|||||||
this.perm = perm;
|
this.perm = perm;
|
||||||
this.type = type;
|
this.type = type;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -13,7 +13,7 @@ public class CommandManager {
|
|||||||
public final String name;
|
public final String name;
|
||||||
public final String label;
|
public final String label;
|
||||||
public final String args;
|
public final String args;
|
||||||
public final String argsalias;
|
public final String argumentAliases;
|
||||||
public final Permission permission;
|
public final Permission permission;
|
||||||
public final Key help;
|
public final Key help;
|
||||||
public final boolean enabled;
|
public final boolean enabled;
|
||||||
@ -21,12 +21,12 @@ public class CommandManager {
|
|||||||
public final DefaultCommand CMD;
|
public final DefaultCommand CMD;
|
||||||
public final String usage;
|
public final String usage;
|
||||||
|
|
||||||
public CommandManager(String name, String label, String args, String argsalias, Permission permission, Key help, Boolean enabled, List<String> mainTABlist,
|
public CommandManager(String name, String label, String args, String argumentAliases, Permission permission, Key help, Boolean enabled, List<String> mainTABlist,
|
||||||
DefaultCommand CMD, String usage) {
|
DefaultCommand CMD, String usage) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.label = label;
|
this.label = label;
|
||||||
this.args = args;
|
this.args = args;
|
||||||
this.argsalias = argsalias;
|
this.argumentAliases = argumentAliases;
|
||||||
this.permission = permission;
|
this.permission = permission;
|
||||||
this.help = help;
|
this.help = help;
|
||||||
this.enabled = enabled;
|
this.enabled = enabled;
|
||||||
|
@ -4,7 +4,7 @@ import net.knarcraft.blockhunt.BlockHunt;
|
|||||||
import net.knarcraft.blockhunt.MemoryStorage;
|
import net.knarcraft.blockhunt.MemoryStorage;
|
||||||
import net.knarcraft.blockhunt.config.ConfigKey;
|
import net.knarcraft.blockhunt.config.ConfigKey;
|
||||||
import net.knarcraft.blockhunt.config.Key;
|
import net.knarcraft.blockhunt.config.Key;
|
||||||
import org.bukkit.configuration.ConfigurationSection;
|
import net.knarcraft.blockhunt.config.MessageKey;
|
||||||
import org.bukkit.configuration.file.FileConfiguration;
|
import org.bukkit.configuration.file.FileConfiguration;
|
||||||
import org.bukkit.configuration.file.YamlConfiguration;
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
|
|
||||||
@ -12,12 +12,9 @@ import java.io.File;
|
|||||||
|
|
||||||
public class ConfigManager {
|
public class ConfigManager {
|
||||||
|
|
||||||
|
|
||||||
private final String fileName;
|
private final String fileName;
|
||||||
private final File file;
|
private final File file;
|
||||||
private final FileConfiguration fileC;
|
private final FileConfiguration fileC;
|
||||||
private final ConfigurationSection fileCS;
|
|
||||||
private final File fileLocation;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Use this class to create an automated config file.
|
* Use this class to create an automated config file.
|
||||||
@ -27,10 +24,9 @@ public class ConfigManager {
|
|||||||
public ConfigManager(String fileName) {
|
public ConfigManager(String fileName) {
|
||||||
this.fileName = fileName;
|
this.fileName = fileName;
|
||||||
this.file = new File(BlockHunt.plugin.getDataFolder(), fileName + ".yml");
|
this.file = new File(BlockHunt.plugin.getDataFolder(), fileName + ".yml");
|
||||||
this.fileLocation = BlockHunt.plugin.getDataFolder();
|
|
||||||
this.fileC = new YamlConfiguration();
|
this.fileC = new YamlConfiguration();
|
||||||
this.checkFile();
|
this.checkFile();
|
||||||
this.fileCS = fileC.getConfigurationSection("");
|
fileC.getConfigurationSection("");
|
||||||
this.load();
|
this.load();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -44,10 +40,9 @@ public class ConfigManager {
|
|||||||
this.fileName = fileName;
|
this.fileName = fileName;
|
||||||
File directory = new File(BlockHunt.plugin.getDataFolder(), subdirectory);
|
File directory = new File(BlockHunt.plugin.getDataFolder(), subdirectory);
|
||||||
this.file = new File(directory, fileName + ".yml");
|
this.file = new File(directory, fileName + ".yml");
|
||||||
this.fileLocation = directory;
|
|
||||||
this.fileC = new YamlConfiguration();
|
this.fileC = new YamlConfiguration();
|
||||||
this.checkFile();
|
this.checkFile();
|
||||||
this.fileCS = fileC.getConfigurationSection("");
|
fileC.getConfigurationSection("");
|
||||||
this.load();
|
this.load();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -58,7 +53,8 @@ public class ConfigManager {
|
|||||||
public static void newFiles() {
|
public static void newFiles() {
|
||||||
ConfigManager.setDefaults();
|
ConfigManager.setDefaults();
|
||||||
for (String fileName : MemoryStorage.newFiles) {
|
for (String fileName : MemoryStorage.newFiles) {
|
||||||
MessageManager.sendMessage(null, "%TAG%WCouldn't find '%A%fileName%.yml%W'%A creating new one.", "fileName-" + fileName);
|
MessageManager.sendMessage(null, "%TAG%WCouldn't find '%A%fileName%.yml%W'%A creating new one.",
|
||||||
|
"fileName-" + fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
MemoryStorage.newFiles.clear();
|
MemoryStorage.newFiles.clear();
|
||||||
@ -68,11 +64,16 @@ public class ConfigManager {
|
|||||||
* Add config settings to the files if they don't exist.
|
* Add config settings to the files if they don't exist.
|
||||||
*/
|
*/
|
||||||
public static void setDefaults() {
|
public static void setDefaults() {
|
||||||
for (ConfigKey value : ConfigKey.values()) {
|
setDefaults(ConfigKey.values());
|
||||||
value.getConfigManager().load();
|
setDefaults(MessageKey.values());
|
||||||
if (value.getConfigManager().getFile().get(value.getPath()) == null) {
|
}
|
||||||
value.getConfigManager().getFile().set(value.getPath(), value.getDefaultValue());
|
|
||||||
value.getConfigManager().save();
|
private static void setDefaults(Key[] configKeys) {
|
||||||
|
for (Key key : configKeys) {
|
||||||
|
key.getConfigManager().load();
|
||||||
|
if (key.getConfigManager().getFile().get(key.getPath()) == null) {
|
||||||
|
key.getConfigManager().getFile().set(key.getPath(), key.getDefaultValue());
|
||||||
|
key.getConfigManager().save();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,11 +1,15 @@
|
|||||||
package net.knarcraft.blockhunt.manager;
|
package net.knarcraft.blockhunt.manager;
|
||||||
|
|
||||||
|
import net.knarcraft.blockhunt.BlockHunt;
|
||||||
import net.knarcraft.blockhunt.MemoryStorage;
|
import net.knarcraft.blockhunt.MemoryStorage;
|
||||||
import net.knarcraft.blockhunt.config.ConfigKey;
|
import net.knarcraft.blockhunt.config.ConfigKey;
|
||||||
import net.knarcraft.blockhunt.config.Key;
|
import net.knarcraft.blockhunt.config.Key;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
|
import java.util.logging.Level;
|
||||||
|
|
||||||
public class MessageManager {
|
public class MessageManager {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -35,14 +39,16 @@ public class MessageManager {
|
|||||||
* player.getName();
|
* player.getName();
|
||||||
*/
|
*/
|
||||||
public static void sendFMessage(Player player, Key location, String... vars) {
|
public static void sendFMessage(Player player, Key location, String... vars) {
|
||||||
if (player == null) {
|
Object value = location.getConfigManager().getFile().get(location.getPath());
|
||||||
Bukkit.getConsoleSender().sendMessage(
|
if (value == null) {
|
||||||
MessageManager.replaceAll(location.getConfigManager().getFile().get(
|
BlockHunt.plugin.getLogger().log(Level.SEVERE, "Unable to read value for " + location.getPath());
|
||||||
location.getPath()).toString().replaceAll("%player%", "Console"), vars));
|
Objects.requireNonNullElseGet(player, Bukkit::getConsoleSender).sendMessage("An error occurred while " +
|
||||||
} else {
|
"generating a BlockHunt message. Please notify an administrator.");
|
||||||
player.sendMessage(MessageManager.replaceAll(location.getConfigManager().getFile().get(
|
return;
|
||||||
location.getPath()).toString().replaceAll("%player%", player.getDisplayName()), vars));
|
|
||||||
}
|
}
|
||||||
|
String playerString = player == null ? "Console" : player.getDisplayName();
|
||||||
|
String message = MessageManager.replaceAll(value.toString().replaceAll("%player%", playerString), vars);
|
||||||
|
Objects.requireNonNullElseGet(player, Bukkit::getConsoleSender).sendMessage(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -69,7 +69,7 @@ error-protocolLibNotInstalled='%TAG%EThe plugin ''%AProtocolLib%E'' is required
|
|||||||
error-noArena='%TAG%ENo arena found with the name ''%A%name%%E''.'
|
error-noArena='%TAG%ENo arena found with the name ''%A%name%%E''.'
|
||||||
error-onlyInGame='%TAG%EThis is an only in-game command!'
|
error-onlyInGame='%TAG%EThis is an only in-game command!'
|
||||||
error-joinAlreadyJoined='%TAG%EYou''ve already joined an arena!'
|
error-joinAlreadyJoined='%TAG%EYou''ve already joined an arena!'
|
||||||
error-joinNoBlocksSet='%TAG%EThere are none blocks set for this arena. Notify the administrator.'
|
error-joinNoBlocksSet='%TAG%EThere are no blocks set for this arena. Notify the administrator.'
|
||||||
error-joinWarpsNotSet='%TAG%EThere are no warps set for this arena. Notify the administrator.'
|
error-joinWarpsNotSet='%TAG%EThere are no warps set for this arena. Notify the administrator.'
|
||||||
error-joinArenaInGame='%TAG%EThis game has already started.'
|
error-joinArenaInGame='%TAG%EThis game has already started.'
|
||||||
error-joinFull='%TAG%EUnable to join this arena. It''s full!'
|
error-joinFull='%TAG%EUnable to join this arena. It''s full!'
|
||||||
|
@ -69,7 +69,7 @@ error-protocolLibNotInstalled='%TAG%EThe plugin ''%AProtocolLib%E'' is required
|
|||||||
error-noArena='%TAG%ENo arena found with the name ''%A%name%%E''.'
|
error-noArena='%TAG%ENo arena found with the name ''%A%name%%E''.'
|
||||||
error-onlyInGame='%TAG%EThis is an only in-game command!'
|
error-onlyInGame='%TAG%EThis is an only in-game command!'
|
||||||
error-joinAlreadyJoined='%TAG%EYou''ve already joined an arena!'
|
error-joinAlreadyJoined='%TAG%EYou''ve already joined an arena!'
|
||||||
error-joinNoBlocksSet='%TAG%EThere are none blocks set for this arena. Notify the administrator.'
|
error-joinNoBlocksSet='%TAG%EThere are no blocks set for this arena. Notify the administrator.'
|
||||||
error-joinWarpsNotSet='%TAG%EThere are no warps set for this arena. Notify the administrator.'
|
error-joinWarpsNotSet='%TAG%EThere are no warps set for this arena. Notify the administrator.'
|
||||||
error-joinArenaInGame='%TAG%EThis game has already started.'
|
error-joinArenaInGame='%TAG%EThis game has already started.'
|
||||||
error-joinFull='%TAG%EUnable to join this arena. It''s full!'
|
error-joinFull='%TAG%EUnable to join this arena. It''s full!'
|
||||||
|
@ -79,7 +79,7 @@ error:
|
|||||||
noArena: '%TAG%ENo arena found with the name ''%A%name%%E''.'
|
noArena: '%TAG%ENo arena found with the name ''%A%name%%E''.'
|
||||||
onlyInGame: '%TAG%EThis is an only in-game command!'
|
onlyInGame: '%TAG%EThis is an only in-game command!'
|
||||||
joinAlreadyJoined: '%TAG%EYou''ve already joined an arena!'
|
joinAlreadyJoined: '%TAG%EYou''ve already joined an arena!'
|
||||||
joinNoBlocksSet: '%TAG%EThere are none blocks set for this arena. Notify the administrator.'
|
joinNoBlocksSet: '%TAG%EThere are no blocks set for this arena. Notify the administrator.'
|
||||||
joinWarpsNotSet: '%TAG%EThere are no warps set for this arena. Notify the administrator.'
|
joinWarpsNotSet: '%TAG%EThere are no warps set for this arena. Notify the administrator.'
|
||||||
joinArenaInGame: '%TAG%EThis game has already started.'
|
joinArenaInGame: '%TAG%EThis game has already started.'
|
||||||
joinFull: '%TAG%EUnable to join this arena. It''s full!'
|
joinFull: '%TAG%EUnable to join this arena. It''s full!'
|
||||||
|
Loading…
x
Reference in New Issue
Block a user