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;
|
||||
public static BlockHunt plugin;
|
||||
public String rootPermission = BlockHunt.getPluginDescriptionFile().getName().toLowerCase() + ".";
|
||||
public String rootPermission;
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
public static final List<String> BlockHuntCMD = new ArrayList<>() {
|
||||
{
|
||||
add("info");
|
||||
@ -129,7 +128,8 @@ public class BlockHunt extends JavaPlugin implements Listener {
|
||||
|
||||
ConfigurationSerialization.registerClass(Arena.class, "BlockHuntArena");
|
||||
|
||||
pluginDescriptionFile = getDescription();
|
||||
BlockHunt.pluginDescriptionFile = getDescription();
|
||||
this.rootPermission = BlockHunt.getPluginDescriptionFile().getName().toLowerCase() + ".";
|
||||
plugin = this;
|
||||
|
||||
ConfigManager.newFiles();
|
||||
@ -271,7 +271,8 @@ public class BlockHunt extends JavaPlugin implements Listener {
|
||||
}
|
||||
|
||||
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
|
||||
ItemStack i = new ItemStack(Material.DIAMOND_SWORD, 1);
|
||||
i.addUnsafeEnchantment(Enchantment.DAMAGE_ALL, 10);
|
||||
@ -316,7 +317,8 @@ public class BlockHunt extends JavaPlugin implements Listener {
|
||||
ArrayList<String> remainingBlocks = new ArrayList<>();
|
||||
for (Player arenaPlayer : arena.playersInArena) {
|
||||
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("_", " "));
|
||||
if (!remainingBlocks.contains(block)) { //Don't print double up block names.
|
||||
remainingBlocks.add(block);
|
||||
@ -356,8 +358,9 @@ public class BlockHunt extends JavaPlugin implements Listener {
|
||||
}
|
||||
}
|
||||
|
||||
if (moveLoc != null) {
|
||||
if (moveLoc.getX() == pLoc.getX() && moveLoc.getY() == pLoc.getY() && moveLoc.getZ() == pLoc.getZ()) {
|
||||
if (moveLoc != null && block != null) {
|
||||
if (moveLoc.getX() == pLoc.getX() && moveLoc.getY() == pLoc.getY() &&
|
||||
moveLoc.getZ() == pLoc.getZ()) {
|
||||
if (block.getAmount() > 1) {
|
||||
block.setAmount(block.getAmount() - 1);
|
||||
} else {
|
||||
@ -436,24 +439,6 @@ public class BlockHunt extends JavaPlugin implements Listener {
|
||||
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
|
||||
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command cmd, @NotNull String label, String[] args) {
|
||||
Player player = null;
|
||||
@ -465,9 +450,9 @@ public class BlockHunt extends JavaPlugin implements Listener {
|
||||
String[] argsSplit = null;
|
||||
String[] argsSplitAlias = null;
|
||||
|
||||
if (command.args != null && command.argsalias != null) {
|
||||
if (command.args != null && command.argumentAliases != null) {
|
||||
argsSplit = command.args.split("/");
|
||||
argsSplitAlias = command.argsalias.split("/");
|
||||
argsSplitAlias = command.argumentAliases.split("/");
|
||||
}
|
||||
|
||||
if (cmd.getName().equalsIgnoreCase(command.label)) {
|
||||
|
@ -63,6 +63,7 @@ public class SignsHandler {
|
||||
}
|
||||
|
||||
public static boolean isSign(Location location) {
|
||||
//TODO: This seems really inefficient
|
||||
for (String sign : MemoryStorage.signs.getFile().getKeys(false)) {
|
||||
Location loc = (Location) MemoryStorage.signs.getFile().get(sign + ".location");
|
||||
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_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_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_JOIN_WARPS_NOT_SET("%TAG%EThere are no warps set for this arena. Notify the administrator.",
|
||||
"error.joinWarpsNotSet"),
|
||||
|
@ -28,5 +28,5 @@ public enum Permission {
|
||||
this.perm = perm;
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -13,7 +13,7 @@ public class CommandManager {
|
||||
public final String name;
|
||||
public final String label;
|
||||
public final String args;
|
||||
public final String argsalias;
|
||||
public final String argumentAliases;
|
||||
public final Permission permission;
|
||||
public final Key help;
|
||||
public final boolean enabled;
|
||||
@ -21,12 +21,12 @@ public class CommandManager {
|
||||
public final DefaultCommand CMD;
|
||||
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) {
|
||||
this.name = name;
|
||||
this.label = label;
|
||||
this.args = args;
|
||||
this.argsalias = argsalias;
|
||||
this.argumentAliases = argumentAliases;
|
||||
this.permission = permission;
|
||||
this.help = help;
|
||||
this.enabled = enabled;
|
||||
|
@ -4,7 +4,7 @@ import net.knarcraft.blockhunt.BlockHunt;
|
||||
import net.knarcraft.blockhunt.MemoryStorage;
|
||||
import net.knarcraft.blockhunt.config.ConfigKey;
|
||||
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.YamlConfiguration;
|
||||
|
||||
@ -12,12 +12,9 @@ import java.io.File;
|
||||
|
||||
public class ConfigManager {
|
||||
|
||||
|
||||
private final String fileName;
|
||||
private final File file;
|
||||
private final FileConfiguration fileC;
|
||||
private final ConfigurationSection fileCS;
|
||||
private final File fileLocation;
|
||||
|
||||
/**
|
||||
* Use this class to create an automated config file.
|
||||
@ -27,10 +24,9 @@ public class ConfigManager {
|
||||
public ConfigManager(String fileName) {
|
||||
this.fileName = fileName;
|
||||
this.file = new File(BlockHunt.plugin.getDataFolder(), fileName + ".yml");
|
||||
this.fileLocation = BlockHunt.plugin.getDataFolder();
|
||||
this.fileC = new YamlConfiguration();
|
||||
this.checkFile();
|
||||
this.fileCS = fileC.getConfigurationSection("");
|
||||
fileC.getConfigurationSection("");
|
||||
this.load();
|
||||
}
|
||||
|
||||
@ -44,10 +40,9 @@ public class ConfigManager {
|
||||
this.fileName = fileName;
|
||||
File directory = new File(BlockHunt.plugin.getDataFolder(), subdirectory);
|
||||
this.file = new File(directory, fileName + ".yml");
|
||||
this.fileLocation = directory;
|
||||
this.fileC = new YamlConfiguration();
|
||||
this.checkFile();
|
||||
this.fileCS = fileC.getConfigurationSection("");
|
||||
fileC.getConfigurationSection("");
|
||||
this.load();
|
||||
}
|
||||
|
||||
@ -58,7 +53,8 @@ public class ConfigManager {
|
||||
public static void newFiles() {
|
||||
ConfigManager.setDefaults();
|
||||
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();
|
||||
@ -68,11 +64,16 @@ public class ConfigManager {
|
||||
* Add config settings to the files if they don't exist.
|
||||
*/
|
||||
public static void setDefaults() {
|
||||
for (ConfigKey value : ConfigKey.values()) {
|
||||
value.getConfigManager().load();
|
||||
if (value.getConfigManager().getFile().get(value.getPath()) == null) {
|
||||
value.getConfigManager().getFile().set(value.getPath(), value.getDefaultValue());
|
||||
value.getConfigManager().save();
|
||||
setDefaults(ConfigKey.values());
|
||||
setDefaults(MessageKey.values());
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
import net.knarcraft.blockhunt.BlockHunt;
|
||||
import net.knarcraft.blockhunt.MemoryStorage;
|
||||
import net.knarcraft.blockhunt.config.ConfigKey;
|
||||
import net.knarcraft.blockhunt.config.Key;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.logging.Level;
|
||||
|
||||
public class MessageManager {
|
||||
|
||||
/**
|
||||
@ -35,14 +39,16 @@ public class MessageManager {
|
||||
* player.getName();
|
||||
*/
|
||||
public static void sendFMessage(Player player, Key location, String... vars) {
|
||||
if (player == null) {
|
||||
Bukkit.getConsoleSender().sendMessage(
|
||||
MessageManager.replaceAll(location.getConfigManager().getFile().get(
|
||||
location.getPath()).toString().replaceAll("%player%", "Console"), vars));
|
||||
} else {
|
||||
player.sendMessage(MessageManager.replaceAll(location.getConfigManager().getFile().get(
|
||||
location.getPath()).toString().replaceAll("%player%", player.getDisplayName()), vars));
|
||||
Object value = location.getConfigManager().getFile().get(location.getPath());
|
||||
if (value == null) {
|
||||
BlockHunt.plugin.getLogger().log(Level.SEVERE, "Unable to read value for " + location.getPath());
|
||||
Objects.requireNonNullElseGet(player, Bukkit::getConsoleSender).sendMessage("An error occurred while " +
|
||||
"generating a BlockHunt message. Please notify an administrator.");
|
||||
return;
|
||||
}
|
||||
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-onlyInGame='%TAG%EThis is an only in-game command!'
|
||||
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-joinArenaInGame='%TAG%EThis game has already started.'
|
||||
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-onlyInGame='%TAG%EThis is an only in-game command!'
|
||||
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-joinArenaInGame='%TAG%EThis game has already started.'
|
||||
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''.'
|
||||
onlyInGame: '%TAG%EThis is an only in-game command!'
|
||||
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.'
|
||||
joinArenaInGame: '%TAG%EThis game has already started.'
|
||||
joinFull: '%TAG%EUnable to join this arena. It''s full!'
|
||||
|
Loading…
Reference in New Issue
Block a user