Skip to content

Commit

Permalink
[Fix] reload command not reloading
Browse files Browse the repository at this point in the history
  • Loading branch information
Dzious committed Nov 15, 2020
1 parent 6756c9c commit 489c5fc
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 25 deletions.
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
package com.dzious.bukkit.enchantcontrol.command;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.dzious.bukkit.enchantcontrol.EnchantControl;
import com.dzious.bukkit.enchantcontrol.utils.Utils;

import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.command.ConsoleCommandSender;
import org.bukkit.command.TabCompleter;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.bukkit.configuration.InvalidConfigurationException;

public class CommandEnchantControl implements CommandExecutor, TabCompleter {

Expand All @@ -22,10 +23,7 @@ public class CommandEnchantControl implements CommandExecutor, TabCompleter {

private Map<String, List<String>> tabComplete = new HashMap<>();

List<String> enchantcontrolTabComplete = Arrays.asList(
"reload"
);

List<String> enchantcontrolTabComplete = Arrays.asList("reload");

public CommandEnchantControl(EnchantControl plugin) {
this.plugin = plugin;
Expand All @@ -35,9 +33,17 @@ public CommandEnchantControl(EnchantControl plugin) {
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
plugin.getLogManager().logDebugConsole("Enchant Control Command");
if (sender instanceof ConsoleCommandSender) {
if (args.length > 0 && args[0] == "reload") {
plugin.getLogManager().logDebugConsole("length : " + args.length);
for (int i = 0; i < args.length; i++)
plugin.getLogManager().logDebugConsole("arg[" + i + "] : " + args[i]);

if (args.length > 0 && args[0].equalsIgnoreCase("reload")) {
try {
plugin.getConfigManager().reload();
plugin.getEnchantmentManager().reload();
} catch (IOException | InvalidConfigurationException e) {
plugin.getLogManager().logSevere("Config file does not exists. Reload failed.");
e.printStackTrace();
}
return (true);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
package com.dzious.bukkit.enchantcontrol.plugin;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.dzious.bukkit.enchantcontrol.EnchantControl;

import org.bukkit.ChatColor;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;

import java.util.*;

public class EnchantmentManager {

private EnchantControl plugin;
Expand Down Expand Up @@ -47,9 +51,9 @@ public void reload()

for (Map.Entry<Enchantment, Integer> enchantment : enchantments.entrySet()) {
plugin.getLogManager().logDebugConsole("Currently processing : " + ChatColor.GREEN + enchantment.getKey() + ChatColor.WHITE + ". It's level is " + ChatColor.RED + enchantment.getValue());
String[] enchantmentId = enchantment.toString().split(":");
if (plugin.getConfigManager().doPathExist("enchantment." + enchantmentId[0] + "." + enchantmentId[1])) {
int newLevel = plugin.getConfigManager().getIntFromPath("enchantment." + enchantmentId[0] + "." + enchantmentId[1]);
String[] enchantmentId = enchantment.getKey().getKey().toString().split(":");
if (plugin.getConfigManager().doPathExist("enchantments." + enchantmentId[0] + "." + enchantmentId[1])) {
int newLevel = plugin.getConfigManager().getIntFromPath("enchantments." + enchantmentId[0] + "." + enchantmentId[1]);
if (enchantment.getValue() != newLevel) {
plugin.getLogManager().logDebugConsole("Replaced " + enchantment.getKey() + ". Old value was " + enchantment.getValue() + ", new value is " + newLevel + ".");
enchantment.setValue(newLevel);
Expand Down
27 changes: 20 additions & 7 deletions src/com/dzious/bukkit/enchantcontrol/utils/ConfigManager.java
Original file line number Diff line number Diff line change
@@ -1,20 +1,33 @@
package com.dzious.bukkit.enchantcontrol.utils;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

import com.dzious.bukkit.enchantcontrol.EnchantControl;

import org.bukkit.configuration.InvalidConfigurationException;
import org.bukkit.configuration.file.FileConfiguration;

import java.io.File;
import java.util.*;

public class ConfigManager {
private FileConfiguration configFile = null;
private final EnchantControl plugin;

public ConfigManager (EnchantControl plugin) {
File file = new File(plugin.getDataFolder(), "config.yml");
public ConfigManager(EnchantControl plugin) {
this.plugin = plugin;
File file = new File(this.plugin.getDataFolder(), "config.yml");
if (file.exists() == false)
plugin.saveDefaultConfig();
configFile = plugin.getConfig();
this.plugin.saveDefaultConfig();
configFile = this.plugin.getConfig();
}

public void reload() throws FileNotFoundException, IOException, InvalidConfigurationException {
File file = new File(plugin.getDataFolder(), "config.yml");
configFile.load(file);
}

public boolean doPathExist (String path) {
Expand Down

0 comments on commit 489c5fc

Please sign in to comment.