Skip to content

Commit

Permalink
Fixed an oversight, which made the config not get updated properly, m…
Browse files Browse the repository at this point in the history
…aking values glich out
  • Loading branch information
SmartGecko44 committed Mar 20, 2024
1 parent 82ae2b2 commit d1a1840
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 31 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>org.gecko</groupId>
<artifactId>Wauh</artifactId>
<version>6.0.0</version>
<version>6.1.0</version>
<packaging>jar</packaging>

<name>wauh</name>
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/org/gecko/wauh/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ public void onDisable() {
}

public int getRadiusLimit() {
config = configManager.getConfig();
playerRadiusLimit = config.getInt("playerRadiusLimit", playerRadiusLimit);
return playerRadiusLimit + 2;
}
Expand All @@ -163,7 +164,9 @@ public void setRadiusLimit(int newLimit) {
}

public int getTntRadiusLimit() {
config = configManager.getConfig();
tntRadiusLimit = config.getInt("tntRadiusLimit", tntRadiusLimit);
Bukkit.getConsoleSender().sendMessage(ChatColor.GREEN + "TNT Radius Limit: " + tntRadiusLimit);
return tntRadiusLimit + 2;
}

Expand All @@ -174,6 +177,7 @@ public void setTntRadiusLimit(int newLimit) {
}

public int getCreeperRadiusLimit() {
config = configManager.getConfig();
creeperRadiusLimit = config.getInt("creeperRadiusLimit", creeperRadiusLimit);
return creeperRadiusLimit + 2;
}
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/org/gecko/wauh/commands/Test.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ public boolean onCommand(CommandSender sender, Command cmd, String label, String
return false;
}

if (!configGUI.getGui().getTitle().equals("Test (WIP)")) {
configGUI.generateGUI();
}
configGUI.openGUI(player);
return true;
}
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/org/gecko/wauh/data/ConfigurationManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ private FileWriter getFileWriter() throws IOException {
}

public FileConfiguration getConfig() {
config = YamlConfiguration.loadConfiguration(configFile);
Bukkit.getConsoleSender().sendMessage(ChatColor.RED + config.saveToString());
return config;
}

Expand Down
81 changes: 51 additions & 30 deletions src/main/java/org/gecko/wauh/gui/ConfigGUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,15 @@ public class ConfigGUI implements Listener {
public ConfigGUI(Main plugin) {
configManager = new ConfigurationManager(plugin);
config = configManager.getConfig();
this.gui = Bukkit.createInventory(null, 45, "Test (WIP)");
File dir = new File("plugins/Wauh");
this.configFile = new File(dir, "data.yml");
this.plugin = plugin;

generateGUI();
}

public void generateGUI() {
this.gui = Bukkit.createInventory(null, 45, "Test (WIP)");
fillBorders(createButtonItem(Material.STAINED_GLASS_PANE, "§r", (short) 5, null, null), 45, false);
// Initialize GUI content
initializeGUI();
Expand Down Expand Up @@ -207,42 +211,55 @@ private boolean isClickEventValid(InventoryClickEvent event) {
}

private void handleItemClick(Player player, ItemStack clickedItem) {
if (clickedItem != null && (clickedItem.getType() == Material.INK_SACK || clickedItem.getType() == Material.PAPER)) {
NBTItem nbtItem = new NBTItem(clickedItem);
String identifier = nbtItem.getString("Ident");
short data = clickedItem.getDurability();
if (clickedItem != null && (clickedItem.getType() == Material.INK_SACK || clickedItem.getType() == Material.PAPER || clickedItem.getType() == Material.CONCRETE)) {
NBTItem nbtItem = new NBTItem(clickedItem);
String identifier = nbtItem.getString("Ident");
short data = clickedItem.getDurability();

if (handleButtonFeatures(player, identifier, data)) {
return; // Button feature handling succeeded
}
if (handleButtonFeatures(player, identifier, data)) {
return; // Button feature handling succeeded
}

if (clickedItem.getType() == Material.PAPER && (identifier.equalsIgnoreCase("Reset"))) {
confirmationPrompt("Reset config?", player);
}
if (clickedItem.getType() == Material.PAPER && (identifier.equalsIgnoreCase("Reset"))) {
confirmationPrompt("Reset config?", player);
}

}
}

private boolean handleButtonFeatures(Player player, String identifier, short data) {
if (identifier.equalsIgnoreCase(ENABLE_BUCKET)) {
handleButtonClick(player, identifier, data, BUCKET_ENABLED, 1, "Liquid removal enabled!", "Liquid removal disabled!");
return true;
} else if (identifier.equalsIgnoreCase(ENABLE_BARRIER)) {
handleButtonClick(player, identifier, data, BARRIER_ENABLED, 2, "Surface removal enabled!", "Surface removal disabled!");
return true;
} else if (identifier.equalsIgnoreCase(ENABLE_BEDROCK)) {
handleButtonClick(player, identifier, data, BEDROCK_ENABLED, 3, "All block removal enabled!", "All block removal disabled!");
return true;
} else if (identifier.equalsIgnoreCase(ENABLE_TSUNAMI)) {
handleButtonClick(player, identifier, data, TSUNAMI_ENABLED, 4, "Tsunami enabled!", "Tsunami disabled!");
return true;
} else if (identifier.equalsIgnoreCase(ENABLE_CREEPER)) {
handleButtonClick(player, identifier, data, CREEPER_ENABLED, 5, "Custom creeper explosions enabled!", "Custom creeper explosions disabled!");
return true;
} else if (identifier.equalsIgnoreCase(ENABLE_TNT)) {
handleButtonClick(player, identifier, data, TNT_ENABLED, 6, "Custom TNT explosions enabled!", "Custom TNT explosions disabled!");
return true;
} else return false; // No button feature handled
if (gui.getTitle().equals("Test (WIP)")) {
if (identifier.equalsIgnoreCase(ENABLE_BUCKET)) {
handleButtonClick(player, identifier, data, BUCKET_ENABLED, 1, "Liquid removal enabled!", "Liquid removal disabled!");
return true;
} else if (identifier.equalsIgnoreCase(ENABLE_BARRIER)) {
handleButtonClick(player, identifier, data, BARRIER_ENABLED, 2, "Surface removal enabled!", "Surface removal disabled!");
return true;
} else if (identifier.equalsIgnoreCase(ENABLE_BEDROCK)) {
handleButtonClick(player, identifier, data, BEDROCK_ENABLED, 3, "All block removal enabled!", "All block removal disabled!");
return true;
} else if (identifier.equalsIgnoreCase(ENABLE_TSUNAMI)) {
handleButtonClick(player, identifier, data, TSUNAMI_ENABLED, 4, "Tsunami enabled!", "Tsunami disabled!");
return true;
} else if (identifier.equalsIgnoreCase(ENABLE_CREEPER)) {
handleButtonClick(player, identifier, data, CREEPER_ENABLED, 5, "Custom creeper explosions enabled!", "Custom creeper explosions disabled!");
return true;
} else if (identifier.equalsIgnoreCase(ENABLE_TNT)) {
handleButtonClick(player, identifier, data, TNT_ENABLED, 6, "Custom TNT explosions enabled!", "Custom TNT explosions disabled!");
return true;
}
} else if (gui.getTitle().equals("Reset config?")) {
if (identifier.equalsIgnoreCase("cancel")) {
player.closeInventory();
player.sendMessage(ChatColor.RED + "Config reset cancelled");
return true;
} else if (identifier.equalsIgnoreCase("confirm")) {
resetConfig(player);
player.closeInventory();
return true;
}
}
return false;
}

private void resetConfig(Player player) {
Expand Down Expand Up @@ -321,4 +338,8 @@ private void confirmationPrompt(String prompt, Player player) {
gui.setItem(9 + 6, createButtonItem(Material.CONCRETE, ChatColor.GREEN + "Confirm", (short) 13, null, "confirm"));
player.openInventory(gui);
}

public Inventory getGui() {
return gui;
}
}

0 comments on commit d1a1840

Please sign in to comment.