Skip to content

Commit

Permalink
Added some missing messages.
Browse files Browse the repository at this point in the history
  • Loading branch information
LinoxGH committed Aug 31, 2021
1 parent 39d49a0 commit 6eed12c
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 36 deletions.
12 changes: 9 additions & 3 deletions src/main/java/me/linoxgh/cratesenhanced/CrateListeners.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import me.linoxgh.cratesenhanced.data.Crate;
import me.linoxgh.cratesenhanced.data.CrateStorage;
import me.linoxgh.cratesenhanced.data.CrateType;
import me.linoxgh.cratesenhanced.data.MessageStorage;
import me.linoxgh.cratesenhanced.data.rewards.Reward;
import me.linoxgh.cratesenhanced.gui.ListRewardMenu;
import org.bukkit.Bukkit;
Expand All @@ -33,11 +34,13 @@
public class CrateListeners implements Listener {
private final CratesEnhanced plugin;
private final CrateStorage crates;
private final MessageStorage messages;
private final Set<BlockPosition> cooldowns;

CrateListeners(@NotNull CratesEnhanced plugin, @NotNull CrateStorage crates) {
CrateListeners(@NotNull CratesEnhanced plugin, @NotNull CrateStorage crates, @NotNull MessageStorage messages) {
this.plugin = plugin;
this.crates = crates;
this.messages = messages;
cooldowns = new HashSet<>();
Bukkit.getPluginManager().registerEvents(this, plugin);
}
Expand Down Expand Up @@ -95,10 +98,13 @@ public void onBreak(BlockBreakEvent e) {
Crate crate = crates.getCrate(new BlockPosition(b.getX(), b.getY(), b.getZ(), b.getWorld().getName()));
if (crate == null) return;

if (!p.hasPermission("crates.delete")) return;
if (!p.hasPermission("crates.delete")) {
e.setCancelled(true);
return;
}

crates.removeCrate(crate.getName());
p.sendMessage("§aSuccessfully removed the crate.");
p.sendMessage(messages.getMessage("gameplay.crate-interaction.break"));
}

@EventHandler
Expand Down
29 changes: 15 additions & 14 deletions src/main/java/me/linoxgh/cratesenhanced/CratesEnhanced.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,28 +46,28 @@ public void onEnable() {
ioManager.loadMessages();
ioManager.checkFiles();
if (ioManager.loadCrateTypes()) {
getLogger().info("Successfully loaded crate types.");
getLogger().info(messageStorage.getMessage("general.loading.success-cratetype"));
} else {
getLogger().warning("Could not load crate types.");
getLogger().warning(messageStorage.getMessage("general.loading.fail-cratetype"));
}
if (ioManager.loadCrates()) {
getLogger().info("Successfully loaded crates.");
getLogger().info(messageStorage.getMessage("general.loading.success-crate"));
} else {
getLogger().warning("Could not load crates.");
getLogger().warning(messageStorage.getMessage("general.loading.fail-crate"));
}

if (!setupEconomy()) {
isVaultEnabled = false;
getLogger().warning("Could not find Vault, continuing without it.");
getLogger().warning("Because of this, money rewards will be inaccessible.");
getLogger().warning(messageStorage.getMessage("general.loading.fail-vault1"));
getLogger().warning(messageStorage.getMessage("general.loading.fail-vault2"));
} else {
isVaultEnabled = true;
getLogger().info("Vault found. Enabling Vault support.");
getLogger().info(messageStorage.getMessage("general.loading.success-vault"));
}

getCommand("crates").setExecutor(new MainCommand(crateStorage, guiTracker, messageStorage));

new CrateListeners(this, crateStorage);
new CrateListeners(this, crateStorage, messageStorage);
new GuiListeners(this, crateStorage, guiTracker);

if (getConfig().getBoolean("metrics-enabled")) enableMetrics();
Expand All @@ -77,22 +77,22 @@ public void onEnable() {
public void onDisable() {
if (!crateStorage.getCrateTypes().isEmpty()) {
if (ioManager.saveCrateTypes()) {
getLogger().info("Successfully saved crate types.");
getLogger().info(messageStorage.getMessage("general.saving.success-cratetype"));
} else {
getLogger().warning("Could not save crate types.");
getLogger().warning(messageStorage.getMessage("general.saving.fail-cratetype"));
}
} else {
getLogger().info("There was no crate types to save.");
getLogger().info(messageStorage.getMessage("general.saving.none-cratetype"));
}

if (!crateStorage.getCrates().isEmpty()) {
if (ioManager.saveCrates()) {
getLogger().info("Successfully saved crates.");
getLogger().info(messageStorage.getMessage("general.saving.success-crate"));
} else {
getLogger().warning("Could not save crates.");
getLogger().warning(messageStorage.getMessage("general.saving.fail-crate"));
}
} else {
getLogger().info("There was no crates to save.");
getLogger().info(messageStorage.getMessage("general.saving.none-crate"));
}
}

Expand All @@ -117,5 +117,6 @@ public static boolean isVaultEnabled() {

private void enableMetrics() {
new Metrics(this, 12500);
getLogger().info(messageStorage.getMessage("general.loading.metrics"));
}
}
28 changes: 9 additions & 19 deletions src/main/java/me/linoxgh/cratesenhanced/io/IOManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ public class IOManager {
private final MessageStorage messages;

private final FileConfiguration cfg;
private final File configFile;
private final File cratesFile;
private final File crateTypesFile;

Expand All @@ -35,26 +34,25 @@ public IOManager(@NotNull CratesEnhanced plugin, @NotNull CrateStorage crates, @
this.messages = messages;

this.cfg = plugin.getConfig();
configFile = new File(plugin.getDataFolder().getPath() + File.separator + ".config.yml");
cratesFile = new File(plugin.getDataFolder().getPath() + File.separator + "crates.dat");
crateTypesFile = new File(plugin.getDataFolder().getPath() + File.separator + "crate-types.dat");
}

@SuppressWarnings("ResultOfMethodCallIgnored")
public void checkFiles() {
try {
cratesFile.getParentFile().mkdirs();
cratesFile.createNewFile();
crateTypesFile.getParentFile().mkdirs();
crateTypesFile.createNewFile();
} catch (IOException e) {
plugin.getLogger().warning("Failed to create the crates.dat file.");
plugin.getLogger().warning(messages.getMessage("general.loading.fail-createcratetype"));
e.printStackTrace();
}

try {
crateTypesFile.getParentFile().mkdirs();
crateTypesFile.createNewFile();
cratesFile.getParentFile().mkdirs();
cratesFile.createNewFile();
} catch (IOException e) {
plugin.getLogger().warning("§4Failed to create the crate-types.dat file.");
plugin.getLogger().warning(messages.getMessage("general.loading.fail-createcrate"));
e.printStackTrace();
}
}
Expand All @@ -63,25 +61,17 @@ public void loadMessages() {
ConfigurationSection messages = cfg.getConfigurationSection("messages");
if (messages == null) messages = cfg.createSection("messages");

StringBuilder path = new StringBuilder();
for (String masterKey : messages.getKeys(false)) {
path.append(masterKey).append(".");

ConfigurationSection masterMessages = messages.getConfigurationSection(masterKey);
if (masterMessages == null) masterMessages = messages.createSection(masterKey);
if (masterMessages == null) continue;

for (String subKey : masterMessages.getKeys(false)) {
path.append(subKey).append(".");

ConfigurationSection subMessages = masterMessages.getConfigurationSection(subKey);
if (subMessages == null) subMessages = masterMessages.createSection(subKey);
if (subMessages == null) continue;

for (String key : subMessages.getKeys(false)) {
path.append(key);

String message = subMessages.getString(key);
this.messages.addMessage(path.toString(), message == null ? "ERROR" : message);
path = new StringBuilder();
this.messages.addMessage(masterKey + "." + subKey + "." + key, message == null ? "ERROR" : message);
}
}
}
Expand Down
27 changes: 27 additions & 0 deletions src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,33 @@ metrics-enabled: true
# Only change the texts inside quotes.
#
messages:
general:
loading:
fail-createcratetype: "Failed to create the crate-types.dat file."
fail-createcrate: "Failed to create the crates.dat file."
fail-cratetype: "Could not load crate types."
fail-crate: "Could not load crates."
fail-vault1: "Could not find Vault, continuing without it."
fail-vault2: "Because of this, money rewards will be inaccessible."
success-cratetype: "Successfully loaded crate types."
success-crate: "Successfully loaded crates."
success-vault: "Vault found. Enabling Vault support."
metrics: "bStats metrics enabled. You can disable this in config file."

saving:
fail-cratetype: "Could not save crate types."
fail-crate: "Could not save crates."
none-cratetype: "There was no crate types to save."
none-crate: "There was no crates to save."
success-cratetype: "Successfully saved crate types."
success-crate: "Successfully saved crates."


gameplay:
crate-interaction:
break: "§aSuccessfully removed the crate."


commands:
general:
no-permission: "&4You do not have enough permission to use this command."
Expand Down

0 comments on commit 6eed12c

Please sign in to comment.