Skip to content

Commit

Permalink
Merge pull request #33 from SmartGecko44/custom-items
Browse files Browse the repository at this point in the history
Fixed permissions, fixed name formatting, fixed BedrockListener, added new command
  • Loading branch information
SmartGecko44 authored Dec 13, 2023
2 parents b28e65c + 582c191 commit 245d50c
Show file tree
Hide file tree
Showing 20 changed files with 221 additions and 320 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>5.4.0</version>
<version>5.5.0</version>
<packaging>jar</packaging>

<name>wauh</name>
Expand Down
7 changes: 3 additions & 4 deletions src/main/java/org/gecko/wauh/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@
import org.bukkit.ChatColor;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.plugin.java.JavaPlugin;
import org.gecko.wauh.commands.SetRadiusLimitCommand;
import org.gecko.wauh.commands.StopWauh;
import org.gecko.wauh.commands.ToggleRemovalView;
import org.gecko.wauh.commands.test;
import org.gecko.wauh.commands.*;
import org.gecko.wauh.data.ConfigurationManager;
import org.gecko.wauh.gui.ConfigGUI;
import org.gecko.wauh.listeners.*;
Expand Down Expand Up @@ -59,6 +56,8 @@ public void onEnable() {
this.getCommand("setradiuslimit").setTabCompleter(new SetRadiusLimitCommand(this));
this.getCommand("toggleremovalview").setExecutor(new ToggleRemovalView(this));
this.getCommand("test").setExecutor(new test(configGUI));
this.getCommand("givecustomitems").setExecutor(new GiveCustomItems());
this.getCommand("givecustomitems").setTabCompleter(new SetRadiusLimitCommand(this));
}

@Override
Expand Down
79 changes: 79 additions & 0 deletions src/main/java/org/gecko/wauh/commands/GiveCustomItems.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
package org.gecko.wauh.commands;

import org.bukkit.Material;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabCompleter;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.gecko.wauh.items.TriggerItems;

import java.util.ArrayList;
import java.util.List;

public class GiveCustomItems implements CommandExecutor, TabCompleter {

@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
TriggerItems items = new TriggerItems();
if (sender instanceof Player) {
if (args.length == 1) {
String operation = args[0].toLowerCase();

if (operation.equals("bucket") || operation.equals("barrier") || operation.equals("bedrock") || operation.equals("tsunami") || operation.equals("all")) {
ItemStack customBucket = items.createCustomItem(Material.BUCKET, "Water Drainer", (short) 0, "Removes all fluids", "Custom Bucket");
ItemStack customBarrier = items.createCustomItem(Material.BARRIER, "Surface Remover", (short) 0, "Removes grass and dirt blocks", "Custom Barrier");
ItemStack customBedrock = items.createCustomItem(Material.BEDROCK, "Block Obliterator", (short) 0, "Removes almost all blocks", "Custom Bedrock");
ItemStack customTsunami = items.createCustomItem(Material.WATER_BUCKET, "Tsunami Bucket", (short) 0, "Creates a tsunami if you shift + right click on a block", "Custom Tsunami");
switch (operation) {
case "bucket":
((Player) sender).getInventory().addItem(customBucket);
break;
case "barrier":
((Player) sender).getInventory().addItem(customBarrier);
break;
case "bedrock":
((Player) sender).getInventory().addItem(customBedrock);
break;
case "tsunami":
((Player) sender).getInventory().addItem(customTsunami);
break;
default:
((Player) sender).getInventory().addItem(customBucket, customBarrier, customBedrock, customTsunami);
break;
}
} else return true;
} else {
sender.sendMessage("Usage: /givecustomitems [bucket/barrier/bedrock/tsunami/all]");
return true;
}
} else {
sender.sendMessage("Only players can execute this command");
return true;
}
return true;
}

@Override
public List<String> onTabComplete(CommandSender commandSender, Command command, String alias, String[] args) {
List<String> completions = new ArrayList<>();

if (args.length == 1) {
String input = args[0].toLowerCase();

if ("bucket".startsWith(input)) {
completions.add("bucket");
} else if ("barrier".startsWith(input)) {
completions.add("barrier");
} else if ("bedrock".startsWith(input)) {
completions.add("bedrock");
} else if ("tsunami".startsWith(input)) {
completions.add("tsunami");
} else if ("all".startsWith(input)) {
completions.add("all");
}
}
return completions;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ public List<String> onTabComplete(CommandSender sender, Command cmd, String alia
completions.add("creeper");
}
}

return completions;
}
}
2 changes: 1 addition & 1 deletion src/main/java/org/gecko/wauh/commands/test.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import org.gecko.wauh.gui.ConfigGUI;

public class test implements CommandExecutor {
ConfigGUI configGUI;
final ConfigGUI configGUI;

public test(ConfigGUI configGUI) {
this.configGUI = configGUI;
Expand Down
25 changes: 15 additions & 10 deletions src/main/java/org/gecko/wauh/data/ConfigurationManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,7 @@ public ConfigurationManager(Main plugin) {
logger.log(Level.SEVERE, "Config file could not be created");
} else {
Bukkit.getConsoleSender().sendMessage(ChatColor.GREEN + "Config file created!");
FileWriter writer = new FileWriter(configFile);
writer.write("playerRadiusLimit: 20\n");
writer.write("tntRadiusLimit: 5\n");
writer.write("creeperRadiusLimit: 5\n");
writer.write("Bucket enabled: 1\n");
writer.write("Barrier enabled: 1\n");
writer.write("Bedrock enabled: 1\n");
writer.write("Tsunami enabled: 1\n");
writer.write("Creeper enabled: 0\n");
writer.write("TNT enabled: 1\n");
FileWriter writer = getFileWriter();
writer.close();
}
}
Expand All @@ -59,6 +50,20 @@ public ConfigurationManager(Main plugin) {
}
}

private FileWriter getFileWriter() throws IOException {
FileWriter writer = new FileWriter(configFile);
writer.write("playerRadiusLimit: 20\n");
writer.write("tntRadiusLimit: 5\n");
writer.write("creeperRadiusLimit: 5\n");
writer.write("Bucket enabled: 1\n");
writer.write("Barrier enabled: 1\n");
writer.write("Bedrock enabled: 1\n");
writer.write("Tsunami enabled: 1\n");
writer.write("Creeper enabled: 0\n");
writer.write("TNT enabled: 1\n");
return writer;
}

public FileConfiguration getConfig() {
return config;
}
Expand Down
66 changes: 34 additions & 32 deletions src/main/java/org/gecko/wauh/gui/ConfigGUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public class ConfigGUI implements Listener {

private final Inventory gui;
private final int size = 45;
ConfigurationManager configManager;
final ConfigurationManager configManager;
FileConfiguration config;
private final File configFile;
private final Logger logger = Logger.getLogger(Main.class.getName());
Expand Down Expand Up @@ -111,11 +111,17 @@ private void fillBorders(ItemStack borderItem) {
}


private ItemStack createButtonItem(Material material, String name, short data, List<String> lore, String ident) {
private ItemStack createButtonItem(Material material, String name, short data, String lore, String ident) {
List<String> loreToString;
if (lore != null) {
loreToString = Collections.singletonList(lore);
} else {
loreToString = null;
}
ItemStack item = new ItemStack(material, 1, data);
ItemMeta meta = item.getItemMeta();
meta.setDisplayName(name);
meta.setLore(lore);
meta.setLore(loreToString);
item.setItemMeta(meta);

NBTItem nbtItem = new NBTItem(item);
Expand All @@ -129,17 +135,17 @@ public void openGUI(Player player) {
int creeperLimit = plugin.getCreeperRadiusLimit() - 2;
int tntLimit = plugin.getTntRadiusLimit() - 2;
gui.setItem(9 + 1, createButtonItem(Material.BUCKET, ChatColor.RESET + "Liquid removal", (short) 0, null, null));
gui.setItem(9 * 2 + 1, createButtonItem(Material.ENDER_PEARL, ChatColor.RESET + String.valueOf(playerLimit), (short) 0, Collections.singletonList(ChatColor.RESET + "" + ChatColor.DARK_PURPLE + "This value is managed by the player radius limit."), null));
gui.setItem(9 * 2 + 1, createButtonItem(Material.ENDER_PEARL, ChatColor.RESET + String.valueOf(playerLimit), (short) 0, ChatColor.RESET + "" + ChatColor.DARK_PURPLE + "This value is managed by the player radius limit.", null));
gui.setItem(9 + 2, createButtonItem(Material.BARRIER, ChatColor.RESET + "Surface removal", (short) 0, null, null));
gui.setItem(9 * 2 + 2, createButtonItem(Material.ENDER_PEARL, ChatColor.RESET + String.valueOf(playerLimit), (short) 0, Collections.singletonList(ChatColor.RESET + "" + ChatColor.DARK_PURPLE + "This value is managed by the player radius limit."), null));
gui.setItem(9 * 2 + 2, createButtonItem(Material.ENDER_PEARL, ChatColor.RESET + String.valueOf(playerLimit), (short) 0, ChatColor.RESET + "" + ChatColor.DARK_PURPLE + "This value is managed by the player radius limit.", null));
gui.setItem(9 + 3, createButtonItem(Material.BEDROCK, ChatColor.RESET + "All block removal", (short) 0, null, null));
gui.setItem(9 * 2 + 3, createButtonItem(Material.ENDER_PEARL, ChatColor.RESET + String.valueOf(playerLimit), (short) 0, Collections.singletonList(ChatColor.RESET + "" + ChatColor.DARK_PURPLE + "This value is managed by the player radius limit."), null));
gui.setItem(9 * 2 + 3, createButtonItem(Material.ENDER_PEARL, ChatColor.RESET + String.valueOf(playerLimit), (short) 0, ChatColor.RESET + "" + ChatColor.DARK_PURPLE + "This value is managed by the player radius limit.", null));
gui.setItem(9 + 4, createButtonItem(Material.WATER_BUCKET, ChatColor.RESET + "Tsunami", (short) 0, null, null));
gui.setItem(9 * 2 + 4, createButtonItem(Material.ENDER_PEARL, ChatColor.RESET + String.valueOf(playerLimit), (short) 0, Collections.singletonList(ChatColor.RESET + "" + ChatColor.DARK_PURPLE + "This value is managed by the player radius limit."), null));
gui.setItem(9 * 2 + 4, createButtonItem(Material.ENDER_PEARL, ChatColor.RESET + String.valueOf(playerLimit), (short) 0, ChatColor.RESET + "" + ChatColor.DARK_PURPLE + "This value is managed by the player radius limit.", null));
gui.setItem(9 + 5, createButtonItem(Material.SKULL_ITEM, ChatColor.RESET + "Custom creeper explosions", (short) 4, null, null));
gui.setItem(9 * 2 + 5, createButtonItem(Material.ENDER_PEARL, ChatColor.RESET + String.valueOf(creeperLimit), (short) 0, Collections.singletonList(ChatColor.RESET + "" + ChatColor.DARK_PURPLE + "This value is managed by the creeper radius limit."), null));
gui.setItem(9 * 2 + 5, createButtonItem(Material.ENDER_PEARL, ChatColor.RESET + String.valueOf(creeperLimit), (short) 0, ChatColor.RESET + "" + ChatColor.DARK_PURPLE + "This value is managed by the creeper radius limit.", null));
gui.setItem(9 + 6, createButtonItem(Material.TNT, ChatColor.RESET + "Custom TNT explosions", (short) 0, null, null));
gui.setItem(9 * 2 + 6, createButtonItem(Material.ENDER_PEARL, ChatColor.RESET + String.valueOf(tntLimit), (short) 0, Collections.singletonList(ChatColor.RESET + "" + ChatColor.DARK_PURPLE + "This value is managed by the TNT radius limit."), null));
gui.setItem(9 * 2 + 6, createButtonItem(Material.ENDER_PEARL, ChatColor.RESET + String.valueOf(tntLimit), (short) 0, ChatColor.RESET + "" + ChatColor.DARK_PURPLE + "This value is managed by the TNT radius limit.", null));
player.openInventory(gui);
}

Expand Down Expand Up @@ -246,15 +252,15 @@ public void onInventoryClick(InventoryClickEvent event) {

if (clickedItem.getType() == Material.PAPER) {
if (identifier.equalsIgnoreCase("Reset")) {
resetConfig(plugin, player);
resetConfig(player);
}
}

}
}
}

private void resetConfig(Main plugin, Player player) {
private void resetConfig(Player player) {
try {
// Create the data.yml file if it doesn't exist
if (!configFile.exists()) {
Expand All @@ -263,16 +269,7 @@ private void resetConfig(Main plugin, Player player) {
logger.log(Level.SEVERE, "Config file could not be created");
} else {
Bukkit.getConsoleSender().sendMessage(ChatColor.GREEN + "Config file created!");
FileWriter writer = new FileWriter(configFile);
writer.write("playerRadiusLimit: 20\n");
writer.write("tntRadiusLimit: 5\n");
writer.write("creeperRadiusLimit: 5\n");
writer.write("Bucket enabled: 1\n");
writer.write("Barrier enabled: 1\n");
writer.write("Bedrock enabled: 1\n");
writer.write("Tsunami enabled: 1\n");
writer.write("Creeper enabled: 0\n");
writer.write("TNT enabled: 1\n");
FileWriter writer = getFileWriter();
writer.close();
}
} else {
Expand All @@ -288,16 +285,7 @@ private void resetConfig(Main plugin, Player player) {
player.sendMessage(ChatColor.RED + "Config file could not be reset");
} else {
Bukkit.getConsoleSender().sendMessage(ChatColor.GREEN + "Config file created!");
FileWriter writer = new FileWriter(configFile);
writer.write("playerRadiusLimit: 20\n");
writer.write("tntRadiusLimit: 5\n");
writer.write("creeperRadiusLimit: 5\n");
writer.write("Bucket enabled: 1\n");
writer.write("Barrier enabled: 1\n");
writer.write("Bedrock enabled: 1\n");
writer.write("Tsunami enabled: 1\n");
writer.write("Creeper enabled: 0\n");
writer.write("TNT enabled: 1\n");
FileWriter writer = getFileWriter();
writer.close();
player.sendMessage(ChatColor.GREEN + "Config reset!");
}
Expand All @@ -306,8 +294,22 @@ private void resetConfig(Main plugin, Player player) {

this.config = YamlConfiguration.loadConfiguration(configFile);
} catch (IOException ex) {
plugin.getLogger().log(Level.SEVERE, "Could not reset config file", ex);
logger.log(Level.SEVERE, "Could not reset config file", ex);
}
}

private FileWriter getFileWriter() throws IOException {
FileWriter writer = new FileWriter(configFile);
writer.write("playerRadiusLimit: 20\n");
writer.write("tntRadiusLimit: 5\n");
writer.write("creeperRadiusLimit: 5\n");
writer.write("Bucket enabled: 1\n");
writer.write("Barrier enabled: 1\n");
writer.write("Bedrock enabled: 1\n");
writer.write("Tsunami enabled: 1\n");
writer.write("Creeper enabled: 0\n");
writer.write("TNT enabled: 1\n");
return writer;
}

}
11 changes: 0 additions & 11 deletions src/main/java/org/gecko/wauh/informations/RemovalInfo.java

This file was deleted.

29 changes: 29 additions & 0 deletions src/main/java/org/gecko/wauh/items/TriggerItems.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package org.gecko.wauh.items;

import de.tr7zw.changeme.nbtapi.NBTItem;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;

import java.util.Collections;
import java.util.List;

public class TriggerItems {

public ItemStack createCustomItem(Material material, String name, short data, String lore, String ident) {
ItemStack item = new ItemStack(material, 1, data);
name = ChatColor.RESET + name;
lore = ChatColor.RESET + "" + ChatColor.DARK_PURPLE + lore;
List<String> loreToList = Collections.singletonList(lore);
ItemMeta meta = item.getItemMeta();
meta.setDisplayName(name);
meta.setLore(loreToList);
item.setItemMeta(meta);

NBTItem nbtItem = new NBTItem(item);
nbtItem.setString("Ident", ident);

return nbtItem.getItem();
}
}
5 changes: 4 additions & 1 deletion src/main/java/org/gecko/wauh/listeners/BarrierListener.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.gecko.wauh.listeners;

import de.tr7zw.changeme.nbtapi.NBTItem;
import net.md_5.bungee.api.ChatMessageType;
import net.md_5.bungee.api.chat.TextComponent;
import org.bukkit.Bukkit;
Expand Down Expand Up @@ -59,14 +60,16 @@ public void barrierBreakEventHandler(BlockBreakEvent event) {
BucketListener bucketListener = Main.getPlugin(Main.class).getBucketListener();
BedrockListener bedrockListener = Main.getPlugin(Main.class).getBedrockListener();
WaterBucketListener waterBucketListener = Main.getPlugin(Main.class).getWaterBucketListener();
NBTItem nbtItem = new NBTItem(event.getPlayer().getInventory().getItemInMainHand());
String identifier = nbtItem.getString("Ident");
radiusLimit = Main.getPlugin(Main.class).getRadiusLimit();
realRadiusLimit = radiusLimit - 2;
if (realRadiusLimit > 1) {
if (!bucketListener.wauhRemovalActive && !blockRemovalActive && !bedrockListener.allRemovalActive && !waterBucketListener.tsunamiActive) {
Player player = event.getPlayer();
if (IMMUTABLE_MATERIALS.contains(event.getBlock().getType())) {
// Check if the bucket is filling with water
if (player.getInventory().getItemInMainHand().getType() == Material.BARRIER) {
if (player.getInventory().getItemInMainHand().getType() == Material.BARRIER && identifier.equalsIgnoreCase("Custom Barrier")) {
blockRemovalActive = true;
limitReached = false;
clickedLocation = event.getBlock().getLocation();
Expand Down
Loading

0 comments on commit 245d50c

Please sign in to comment.