Compare commits
6 Commits
7c87de2a16
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
69dc87b718 | ||
|
|
de87781ee1 | ||
|
|
a07108e141 | ||
|
|
98fe1a696a | ||
|
|
e1527dad4c | ||
|
|
2a38080e6b |
@@ -5,8 +5,10 @@ import org.bukkit.command.PluginCommand;
|
|||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
import nl.interestingcorner.coordinates.commands.CoordinatesCommand;
|
import nl.interestingcorner.coordinates.commands.CoordinatesCommand;
|
||||||
|
import nl.interestingcorner.coordinates.db.Coordinate;
|
||||||
import nl.interestingcorner.coordinates.db.CoordinatesDatabaseManager;
|
import nl.interestingcorner.coordinates.db.CoordinatesDatabaseManager;
|
||||||
import nl.interestingcorner.coordinates.gui.CoordinatesGUIListener;
|
import nl.interestingcorner.coordinates.listeners.MapUseListener;
|
||||||
|
import nl.interestingcorner.core.MinecraftColor;
|
||||||
|
|
||||||
public class App extends JavaPlugin {
|
public class App extends JavaPlugin {
|
||||||
|
|
||||||
@@ -15,10 +17,9 @@ public class App extends JavaPlugin {
|
|||||||
getLogger().info("Eyooo we boutta get lit!");
|
getLogger().info("Eyooo we boutta get lit!");
|
||||||
CoordinatesDatabaseManager.INSTANCE.initialize(this);
|
CoordinatesDatabaseManager.INSTANCE.initialize(this);
|
||||||
getLogger().info("Successfully initialized database");
|
getLogger().info("Successfully initialized database");
|
||||||
|
|
||||||
getServer().getPluginManager().registerEvents(new CoordinatesGUIListener(), this);
|
|
||||||
registerCommands();
|
|
||||||
|
|
||||||
|
getServer().getPluginManager().registerEvents(new MapUseListener(), this);
|
||||||
|
registerCommands();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -27,15 +28,76 @@ public class App extends JavaPlugin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void registerCommands() {
|
private void registerCommands() {
|
||||||
registerSimgleCommand("ic-coords", new CoordinatesCommand());
|
registerSingleCommand("ic-coords", new CoordinatesCommand());
|
||||||
}
|
}
|
||||||
|
|
||||||
private void registerSimgleCommand(String name, CommandExecutor executor)
|
private void registerSingleCommand(String name, CommandExecutor executor) {
|
||||||
{
|
|
||||||
PluginCommand pc = this.getCommand(name);
|
PluginCommand pc = this.getCommand(name);
|
||||||
if (pc != null)
|
if (pc != null) {
|
||||||
{
|
|
||||||
pc.setExecutor(executor);
|
pc.setExecutor(executor);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
|
private void addOldCoordinates() {
|
||||||
|
CoordinatesDatabaseManager db = CoordinatesDatabaseManager.INSTANCE;
|
||||||
|
db.addCoordinate(new Coordinate(1, "The Tower", "Teleport to the Castle of Illusion",
|
||||||
|
new Coordinate.Position(2700, 65, 450), false, "the-old-world", MinecraftColor.GOLD));
|
||||||
|
db.addCoordinate(new Coordinate(12, "Temple of Tears", "Teleport to the temple in the sky",
|
||||||
|
new Coordinate.Position(2445, 218, -1902), false, "the-old-world", MinecraftColor.AQUA));
|
||||||
|
db.addCoordinate(new Coordinate(13, "Big village", "Teleport to a big ass village",
|
||||||
|
new Coordinate.Position(1828, 63, -845), false, "the-old-world", MinecraftColor.BLACK));
|
||||||
|
db.addCoordinate(new Coordinate(14, "Other village", "Teleport to yet another village",
|
||||||
|
new Coordinate.Position(1771, 64, -1626), false, "the-old-world", MinecraftColor.BLACK));
|
||||||
|
db.addCoordinate(new Coordinate(15, "Acacia village", "Teleport to acacia village",
|
||||||
|
new Coordinate.Position(2287, 63, -1492), false, "the-old-world", MinecraftColor.BLACK));
|
||||||
|
db.addCoordinate(new Coordinate(16, "Illager castle", "Teleport to an illager castle",
|
||||||
|
new Coordinate.Position(2694, 93, -1240), false, "the-old-world", MinecraftColor.GRAY));
|
||||||
|
db.addCoordinate(new Coordinate(17, "Huge honeycomb", "Hmmm honey", new Coordinate.Position(1650, 70, 637),
|
||||||
|
false, "the-old-world", MinecraftColor.BLACK));
|
||||||
|
db.addCoordinate(new Coordinate(18, "Mansion", "The big mansion next to The Tower",
|
||||||
|
new Coordinate.Position(2833, 66, 377), false, "the-old-world", MinecraftColor.DARK_AQUA));
|
||||||
|
db.addCoordinate(new Coordinate(19, "Village with labyrinth", "Big village with a labyrinth",
|
||||||
|
new Coordinate.Position(871, 66, 884), false, "the-old-world", MinecraftColor.BLACK));
|
||||||
|
db.addCoordinate(new Coordinate(20, "Ravine cave entrance", "Teleport to big cave entrance",
|
||||||
|
new Coordinate.Position(2080, 105, 1135), false, "the-old-world", MinecraftColor.BLACK));
|
||||||
|
db.addCoordinate(new Coordinate(21, "Skeleton spawner", "Get some XP made by Sienna",
|
||||||
|
new Coordinate.Position(2278, -9, 1484), false, "the-old-world", MinecraftColor.LIGHT_PURPLE));
|
||||||
|
db.addCoordinate(new Coordinate(22, "Nether portal", "Nether portal IN THE NETHER",
|
||||||
|
new Coordinate.Position(316, 81, 50), true, "the-old-world", MinecraftColor.RED));
|
||||||
|
db.addCoordinate(new Coordinate(25, "Home village", "The first home village",
|
||||||
|
new Coordinate.Position(2212, 69, 926), false, "the-old-world", MinecraftColor.GREEN));
|
||||||
|
db.addCoordinate(new Coordinate(26, "deep dark wool eiland", "ready to get your asshole ripped",
|
||||||
|
new Coordinate.Position(2626, -36, 1714), false, "the-old-world", MinecraftColor.DARK_BLUE));
|
||||||
|
db.addCoordinate(new Coordinate(27, "2nd Nether portal", "2nd nether portal IN THE NETHER",
|
||||||
|
new Coordinate.Position(264, 43, 106), true, "the-old-world", MinecraftColor.RED));
|
||||||
|
db.addCoordinate(new Coordinate(28, "Nether fortress", "Nether fortress IN THE NETHER",
|
||||||
|
new Coordinate.Position(85, 60, 423), true, "the-old-world", MinecraftColor.DARK_RED));
|
||||||
|
db.addCoordinate(new Coordinate(29, "Village hidden in the sand", "Also known as Sunagakure",
|
||||||
|
new Coordinate.Position(223, 75, 688), false, "the-old-world", MinecraftColor.YELLOW));
|
||||||
|
db.addCoordinate(new Coordinate(30, "deep dark", "deep down", new Coordinate.Position(2590, -17, -1690), false,
|
||||||
|
"the-old-world", MinecraftColor.DARK_BLUE));
|
||||||
|
db.addCoordinate(new Coordinate(31, "Mob farm", "mob farm maken voor xp en andere stuff enzo",
|
||||||
|
new Coordinate.Position(2471, 79, -440), false, "the-old-world", MinecraftColor.RED));
|
||||||
|
db.addCoordinate(new Coordinate(33, "Green cave", "NEW Green cave", new Coordinate.Position(10098, -10, 10076),
|
||||||
|
false, "the-old-world", MinecraftColor.GREEN));
|
||||||
|
db.addCoordinate(new Coordinate(34, "Castle", "Beautiful castle in plains biome",
|
||||||
|
new Coordinate.Position(9678, 90, 11222), false, "the-old-world", MinecraftColor.GOLD));
|
||||||
|
db.addCoordinate(new Coordinate(35, "RPG style city", "large village with a castle",
|
||||||
|
new Coordinate.Position(8904, 68, 11200), false, "the-old-world", MinecraftColor.AQUA));
|
||||||
|
db.addCoordinate(new Coordinate(36, "Abandoned castle", "Abandoned castle which we conquered",
|
||||||
|
new Coordinate.Position(9071, 74, 11022), false, "the-old-world", MinecraftColor.LIGHT_PURPLE));
|
||||||
|
db.addCoordinate(new Coordinate(37, "Portal", "New portal IN THE NETHER",
|
||||||
|
new Coordinate.Position(1136, 32, 1397), true, "the-old-world", MinecraftColor.RED));
|
||||||
|
db.addCoordinate(new Coordinate(38, "bee boss", "ga dood lol", new Coordinate.Position(3470, 64, 227), false,
|
||||||
|
"the-old-world", MinecraftColor.BLACK));
|
||||||
|
db.addCoordinate(new Coordinate(39, "bee boss 2.0", "ga dood neef", new Coordinate.Position(4045, 63, 130),
|
||||||
|
false, "the-old-world", MinecraftColor.BLACK));
|
||||||
|
db.addCoordinate(new Coordinate(40, "Ice biome", "RIP my boi titanic", new Coordinate.Position(4587, 63, 476),
|
||||||
|
false, "the-old-world", MinecraftColor.AQUA));
|
||||||
|
db.addCoordinate(new Coordinate(41, "Onderwater gang trap ofzo", "Neem water breathing of hoedje mee ofzo",
|
||||||
|
new Coordinate.Position(6156, 63, 2228), false, "the-old-world", MinecraftColor.GRAY));
|
||||||
|
db.addCoordinate(new Coordinate(42, "The hood", "da hood", new Coordinate.Position(8202, 70, 999580), false,
|
||||||
|
"the-old-world", MinecraftColor.GREEN));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -41,11 +41,6 @@ public class AddCoordinateCommandHandler implements CoordinatesCommandHandler {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
sender.sendMessage("Args after parsing:");
|
|
||||||
sender.sendMessage("0:" + parsedArgs.get(0));
|
|
||||||
sender.sendMessage("1:" + parsedArgs.get(1));
|
|
||||||
sender.sendMessage("2:" + parsedArgs.get(2));
|
|
||||||
|
|
||||||
String name = parsedArgs.get(0);
|
String name = parsedArgs.get(0);
|
||||||
String description = parsedArgs.get(1);
|
String description = parsedArgs.get(1);
|
||||||
String color = parsedArgs.get(2);
|
String color = parsedArgs.get(2);
|
||||||
@@ -66,6 +61,7 @@ public class AddCoordinateCommandHandler implements CoordinatesCommandHandler {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
player.sendMessage(MinecraftColor.BLUE.toColorCode() + "Adding coordinate '" + name + "' at your current location...");
|
||||||
//TODO check if item doesnt already exist, coordinate with same values, create isEquals method for coordinate
|
//TODO check if item doesnt already exist, coordinate with same values, create isEquals method for coordinate
|
||||||
return CoordinatesDatabaseManager.INSTANCE
|
return CoordinatesDatabaseManager.INSTANCE
|
||||||
.addCoordinate(name, // name
|
.addCoordinate(name, // name
|
||||||
@@ -84,12 +80,10 @@ public class AddCoordinateCommandHandler implements CoordinatesCommandHandler {
|
|||||||
private List<String> removeFirstArg(String[] args) {
|
private List<String> removeFirstArg(String[] args) {
|
||||||
List<String> onlyArgs = new ArrayList<>();
|
List<String> onlyArgs = new ArrayList<>();
|
||||||
|
|
||||||
sender.sendMessage("removeFirstArg: size of args is " + String.valueOf(args.length));
|
|
||||||
for (int i = 1; i < args.length; i++) {
|
for (int i = 1; i < args.length; i++) {
|
||||||
onlyArgs.add(args[i]);
|
onlyArgs.add(args[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
sender.sendMessage("removeFirstArg: size of onlyArgs is " + String.valueOf(onlyArgs.size()));
|
|
||||||
return onlyArgs;
|
return onlyArgs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -14,14 +14,12 @@ public class CoordinatesCommand implements CommandExecutor{
|
|||||||
sb.append(string);
|
sb.append(string);
|
||||||
sb.append(" ");
|
sb.append(" ");
|
||||||
}
|
}
|
||||||
|
|
||||||
sender.sendMessage("Args length: " + String.valueOf(args.length));
|
|
||||||
sender.sendMessage(sb.toString());
|
|
||||||
|
|
||||||
// strategy design pattern
|
// strategy design pattern
|
||||||
return switch (args[0]) {
|
return switch (args[0]) {
|
||||||
case "get" -> new GetCoordinatesCommandHandler().handleCommand(sender, args);
|
case "get" -> new GetCoordinatesCommandHandler().handleCommand(sender, args);
|
||||||
case "add" -> new AddCoordinateCommandHandler().handleCommand(sender, args);
|
case "add" -> new AddCoordinateCommandHandler().handleCommand(sender, args);
|
||||||
|
case "map" -> new GetMapCommandHandler().handleCommand(sender, args);
|
||||||
default -> false;
|
default -> false;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,42 +5,39 @@ import java.util.List;
|
|||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import nl.interestingcorner.coordinates.db.CoordinatesDatabaseManager;
|
|
||||||
import nl.interestingcorner.coordinates.db.Coordinate;
|
import nl.interestingcorner.coordinates.db.Coordinate;
|
||||||
|
import nl.interestingcorner.coordinates.db.CoordinatesDatabaseManager;
|
||||||
import nl.interestingcorner.coordinates.gui.CoordinatesGUI;
|
import nl.interestingcorner.coordinates.gui.CoordinatesGUI;
|
||||||
|
|
||||||
public class GetCoordinatesCommandHandler implements CoordinatesCommandHandler {
|
public class GetCoordinatesCommandHandler implements CoordinatesCommandHandler {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean handleCommand(CommandSender sender, String[] args) {
|
public boolean handleCommand(CommandSender sender, String[] args) {
|
||||||
if (sender instanceof Player player) {
|
try {
|
||||||
List<Coordinate> coords;
|
if (sender instanceof Player player) {
|
||||||
if (args.length < 2) {
|
List<Coordinate> coords;
|
||||||
coords = CoordinatesDatabaseManager.INSTANCE.getAllCoordinates();
|
if (args.length < 2) {
|
||||||
} else if (args[1].equalsIgnoreCase("world")) {
|
coords = CoordinatesDatabaseManager.INSTANCE.getAllCoordinates();
|
||||||
String world = player.getWorld().getName();
|
} else if (args[1].equalsIgnoreCase("world")) {
|
||||||
coords = CoordinatesDatabaseManager.INSTANCE.getAllCoordinates(world);
|
String world = player.getWorld().getName();
|
||||||
} else {
|
coords = CoordinatesDatabaseManager.INSTANCE.getAllCoordinates(world);
|
||||||
sender.sendMessage("Invalid argument: " + args[1]);
|
} else {
|
||||||
return false;
|
sender.sendMessage("Invalid argument: " + args[1]);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (coords.isEmpty()) {
|
||||||
|
player.sendMessage("No coordinates found! Add some with the §3/ic-coords §5add §fcommand.");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
CoordinatesGUI.open(player, coords);
|
||||||
}
|
}
|
||||||
|
return true;
|
||||||
if (coords.isEmpty()) {
|
} catch (Exception e) {
|
||||||
player.sendMessage("No coordinates found! Add some with the §3/ic-coords §5add §fcommand.");
|
sender.sendMessage("An error occurred while getting coordinates: " + e.getMessage());
|
||||||
return true;
|
return false;
|
||||||
}
|
|
||||||
|
|
||||||
StringBuilder res = new StringBuilder("Coordinates: ");
|
|
||||||
|
|
||||||
for (Coordinate coordinate : coords) {
|
|
||||||
res.append(coordinate.toString());
|
|
||||||
}
|
|
||||||
|
|
||||||
player.sendMessage(res.toString());
|
|
||||||
|
|
||||||
CoordinatesGUI.open(player, coords);
|
|
||||||
}
|
}
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,55 @@
|
|||||||
|
package nl.interestingcorner.coordinates.commands;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.bukkit.inventory.meta.ItemMeta;
|
||||||
|
|
||||||
|
import nl.interestingcorner.core.MinecraftColor;
|
||||||
|
|
||||||
|
public class GetMapCommandHandler implements CoordinatesCommandHandler {
|
||||||
|
public static final String MAP_ITEM_NAME = MinecraftColor.LIGHT_PURPLE + "Map of Coordinates";
|
||||||
|
public static final String MAP_ITEM_LORE = MinecraftColor.AQUA.toColorCode() + "This will take you anywhere!";
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean handleCommand(CommandSender sender, String[] args) {
|
||||||
|
if (!(sender instanceof Player player)) {
|
||||||
|
sender.sendMessage("This command can only be used by a player.");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create a custom map item
|
||||||
|
ItemStack map = new ItemStack(Material.FILLED_MAP);
|
||||||
|
ItemMeta meta = map.getItemMeta();
|
||||||
|
if (meta != null) {
|
||||||
|
meta.setDisplayName(MAP_ITEM_NAME);
|
||||||
|
List<String> lore = new ArrayList<>();
|
||||||
|
lore.add(MAP_ITEM_LORE);
|
||||||
|
meta.setLore(lore);
|
||||||
|
map.setItemMeta(meta);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Give the item to the player
|
||||||
|
player.getInventory().addItem(map);
|
||||||
|
player.sendMessage(MinecraftColor.GREEN.toColorCode() + "You received the Coordinates map! Right-click to use it.");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if the given item is the special map item.
|
||||||
|
* @param item The item to check.
|
||||||
|
* @return true if it is the special map, false otherwise.
|
||||||
|
*/
|
||||||
|
public static boolean isSpecialMap(ItemStack item) {
|
||||||
|
if (item == null || item.getType() != Material.FILLED_MAP) return false;
|
||||||
|
ItemMeta meta = item.getItemMeta();
|
||||||
|
if (meta == null) return false;
|
||||||
|
return meta.hasDisplayName() && meta.getDisplayName().equals(MAP_ITEM_NAME) &&
|
||||||
|
meta.hasLore() && meta.getLore() != null && meta.getLore().contains(MAP_ITEM_LORE);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -2,6 +2,7 @@ package nl.interestingcorner.coordinates.db;
|
|||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.bukkit.Location;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.bukkit.inventory.meta.ItemMeta;
|
import org.bukkit.inventory.meta.ItemMeta;
|
||||||
|
|
||||||
@@ -136,6 +137,56 @@ public class Coordinate {
|
|||||||
return itemStack;
|
return itemStack;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Converts this Coordinate to a Bukkit Location object
|
||||||
|
* @return the Location object
|
||||||
|
*/
|
||||||
|
public Location toLocation() {
|
||||||
|
return new Location(
|
||||||
|
org.bukkit.Bukkit.getWorld(this.world),
|
||||||
|
this.position.x(),
|
||||||
|
this.position.y(),
|
||||||
|
this.position.z()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a Coordinate object from an ItemStack
|
||||||
|
* @param item the ItemStack to convert
|
||||||
|
* @return the Coordinate object, or null if the ItemStack is not a valid Coordinate
|
||||||
|
*/
|
||||||
|
public static Coordinate fromItem(ItemStack item)
|
||||||
|
{
|
||||||
|
if (item == null || item.getItemMeta() == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
ItemMeta meta = item.getItemMeta();
|
||||||
|
if (meta == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
String name = meta.getDisplayName().replaceAll("§[0-9a-fk-or]", "");
|
||||||
|
|
||||||
|
List<String> lore = meta.getLore();
|
||||||
|
if (lore == null || lore.size() < 6) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
String description = lore.get(0).replaceAll("§[0-9a-fk-or]", "");
|
||||||
|
boolean nether = lore.get(1).contains("Nether Coordinate");
|
||||||
|
String xLine = lore.get(2);
|
||||||
|
String yLine = lore.get(3);
|
||||||
|
String zLine = lore.get(4);
|
||||||
|
String worldLine = lore.get(5);
|
||||||
|
|
||||||
|
int x = Integer.parseInt(xLine.substring(xLine.indexOf(":") + 2));
|
||||||
|
int y = Integer.parseInt(yLine.substring(yLine.indexOf(":") + 2));
|
||||||
|
int z = Integer.parseInt(zLine.substring(zLine.indexOf(":") + 2));
|
||||||
|
String world = worldLine.substring(worldLine.indexOf(":") + 2);
|
||||||
|
|
||||||
|
MinecraftColor color = MinecraftColor.fromMaterial(item.getType());
|
||||||
|
|
||||||
|
return new Coordinate(-1, name, description, new Position(x, y, z), nether, world, color);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object obj) {
|
public boolean equals(Object obj) {
|
||||||
if (this == obj)
|
if (this == obj)
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ import org.bukkit.plugin.java.JavaPlugin;
|
|||||||
|
|
||||||
import nl.interestingcorner.core.MinecraftColor;
|
import nl.interestingcorner.core.MinecraftColor;
|
||||||
import nl.interestingcorner.core.db.DatabaseManager;
|
import nl.interestingcorner.core.db.DatabaseManager;
|
||||||
|
import nl.interestingcorner.core.logging.Logger;
|
||||||
|
|
||||||
public enum CoordinatesDatabaseManager implements nl.interestingcorner.core.db.DatabaseInitializeListener{
|
public enum CoordinatesDatabaseManager implements nl.interestingcorner.core.db.DatabaseInitializeListener{
|
||||||
|
|
||||||
@@ -20,6 +21,8 @@ public enum CoordinatesDatabaseManager implements nl.interestingcorner.core.db.D
|
|||||||
private Connection connection;
|
private Connection connection;
|
||||||
private JavaPlugin app;
|
private JavaPlugin app;
|
||||||
|
|
||||||
|
private final String TAG = getClass().getSimpleName();
|
||||||
|
|
||||||
public void initialize(JavaPlugin app) {
|
public void initialize(JavaPlugin app) {
|
||||||
this.app = app;
|
this.app = app;
|
||||||
DatabaseManager.INSTANCE.registerDatabaseInitializeListener(this);
|
DatabaseManager.INSTANCE.registerDatabaseInitializeListener(this);
|
||||||
@@ -119,6 +122,8 @@ public enum CoordinatesDatabaseManager implements nl.interestingcorner.core.db.D
|
|||||||
this.app.getLogger().log(Level.SEVERE, "Error adding coordinate to database: {0}", e.getMessage());
|
this.app.getLogger().log(Level.SEVERE, "Error adding coordinate to database: {0}", e.getMessage());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Logger.INSTANCE.info(TAG, "Added coordinate '" + name + "' to database.");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,68 +1,26 @@
|
|||||||
package nl.interestingcorner.coordinates.gui;
|
package nl.interestingcorner.coordinates.gui;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.Material;
|
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.inventory.Inventory;
|
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.bukkit.inventory.meta.ItemMeta;
|
|
||||||
|
|
||||||
import nl.interestingcorner.coordinates.db.Coordinate;
|
import nl.interestingcorner.coordinates.db.Coordinate;
|
||||||
import nl.interestingcorner.core.MinecraftColor;
|
import nl.interestingcorner.core.gui.GUI;
|
||||||
|
|
||||||
public class CoordinatesGUI {
|
public class CoordinatesGUI {
|
||||||
public static void open(Player player, List<Coordinate> coordinates) {
|
public static void open(Player player, List<Coordinate> coords) {
|
||||||
|
List<ItemStack> items = new ArrayList<>();
|
||||||
int coordinatesAmount = coordinates.size();
|
|
||||||
int size;
|
for (Coordinate coord : coords) {
|
||||||
if (coordinatesAmount <= 9) {
|
ItemStack item = coord.toItem();
|
||||||
size = 9;
|
items.add(item);
|
||||||
} else {
|
|
||||||
// TODO handle if size is more than 54 - 9, add pagination
|
|
||||||
/**
|
|
||||||
* if more than 45, add pages. Split by 45 items per page.
|
|
||||||
* use bottom row leftmost and rightmost item for navigation.
|
|
||||||
* use paper item for page number display in middle.
|
|
||||||
* use lore of navigation items clicked to handle showing next/previous page.
|
|
||||||
* use player.getOpeninventory() to get current inventory and update or close it.
|
|
||||||
*/
|
|
||||||
|
|
||||||
// round up to nearest multiple of 9
|
|
||||||
size = ((coordinatesAmount / 9) + 1) * 9;
|
|
||||||
player.sendMessage("Size: " + size);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create an inventory with 9 slots and a title
|
GUI gui = new GUI("Coordinates", GUI.DEFAULT_PAGE_SIZE);
|
||||||
Inventory gui = Bukkit.createInventory(null, size, "Coordinates Menu");
|
gui.addItemClickListener(new TeleportItemClickListener());
|
||||||
|
gui.setItems(items);
|
||||||
for (Coordinate coordinate : coordinates) {
|
gui.show(player);
|
||||||
ItemStack item = createCoordinateItem(coordinate);
|
|
||||||
gui.addItem(item);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Open the GUI for the player
|
|
||||||
player.openInventory(gui);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static ItemStack createCoordinateItem(Coordinate coordinate) {
|
|
||||||
ItemStack itemStack = new ItemStack(coordinate.color.toMaterial());
|
|
||||||
ItemMeta meta = itemStack.getItemMeta();
|
|
||||||
if (meta == null) {
|
|
||||||
return itemStack;
|
|
||||||
}
|
|
||||||
meta.setDisplayName(coordinate.color.toColorCode() + coordinate.name);
|
|
||||||
meta.setLore(List.of(
|
|
||||||
MinecraftColor.WHITE.toColorCode() + coordinate.description,
|
|
||||||
coordinate.nether ? MinecraftColor.RED.toColorCode() + "Nether Coordinate" : "Overworld Coordinate",
|
|
||||||
"X: " + coordinate.position.x(),
|
|
||||||
"Y: " + coordinate.position.y(),
|
|
||||||
"Z: " + coordinate.position.z(),
|
|
||||||
"World: " + coordinate.world
|
|
||||||
));
|
|
||||||
itemStack.setItemMeta(meta);
|
|
||||||
|
|
||||||
return itemStack;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,33 +0,0 @@
|
|||||||
package nl.interestingcorner.coordinates.gui;
|
|
||||||
|
|
||||||
import org.bukkit.event.EventHandler;
|
|
||||||
import org.bukkit.event.Listener;
|
|
||||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.ChatColor;
|
|
||||||
|
|
||||||
public class CoordinatesGUIListener implements Listener{
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void onInventoryClick(InventoryClickEvent event) {
|
|
||||||
|
|
||||||
// Check if this is our custom GUI
|
|
||||||
if (event.getView().getTitle().equals("Coordinates Menu")) {
|
|
||||||
event.setCancelled(true); // Prevent taking the item
|
|
||||||
|
|
||||||
if (event.getCurrentItem() == null) return;
|
|
||||||
|
|
||||||
Player player = (Player) event.getWhoClicked();
|
|
||||||
|
|
||||||
switch (event.getSlot()) {
|
|
||||||
case 0 -> {
|
|
||||||
player.sendMessage(ChatColor.GREEN + "You clicked Add Coordinate!");
|
|
||||||
player.closeInventory();
|
|
||||||
// Here you could open another GUI or run a command
|
|
||||||
}
|
|
||||||
// Add other cases for other slots if needed
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
package nl.interestingcorner.coordinates.gui;
|
||||||
|
|
||||||
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
|
import nl.interestingcorner.coordinates.db.Coordinate;
|
||||||
|
import nl.interestingcorner.core.gui.GUI;
|
||||||
|
import nl.interestingcorner.core.gui.GUIItemClickListener;
|
||||||
|
import nl.interestingcorner.core.logging.Logger;
|
||||||
|
|
||||||
|
public class TeleportItemClickListener implements GUIItemClickListener {
|
||||||
|
|
||||||
|
private final String TAG = this.getClass().getSimpleName();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onItemClick(Player player, GUI gui, ItemStack item, int slot) {
|
||||||
|
|
||||||
|
Logger.INSTANCE.info(TAG, "Item clicked in slot " + slot + " by player " + player.getName());
|
||||||
|
Coordinate coordinate = Coordinate.fromItem(item);
|
||||||
|
|
||||||
|
if (coordinate != null) {
|
||||||
|
Location loc = coordinate.toLocation();
|
||||||
|
Logger.INSTANCE.info(TAG, "Teleporting player " + player.getName() + " to coordinate " + coordinate.name);
|
||||||
|
player.sendMessage("Teleporting you to " + coordinate.name);
|
||||||
|
player.teleport(loc);
|
||||||
|
player.sendTitle(coordinate.name, coordinate.description, 10, 70, 20);
|
||||||
|
player.closeInventory();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
package nl.interestingcorner.coordinates.listeners;
|
||||||
|
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
import org.bukkit.event.player.PlayerInteractEvent;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
|
import nl.interestingcorner.coordinates.commands.GetMapCommandHandler;
|
||||||
|
|
||||||
|
public class MapUseListener implements Listener {
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onPlayerUseMap(PlayerInteractEvent event) {
|
||||||
|
Player player = event.getPlayer();
|
||||||
|
ItemStack item = event.getItem();
|
||||||
|
|
||||||
|
if (GetMapCommandHandler.isSpecialMap(item)) {
|
||||||
|
event.setCancelled(true);
|
||||||
|
|
||||||
|
// execute command to show coordinates of this world
|
||||||
|
player.performCommand("ic-coords get world");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -7,4 +7,4 @@ depend: [IC-core]
|
|||||||
commands:
|
commands:
|
||||||
ic-coords:
|
ic-coords:
|
||||||
description: Main command for the coordinates
|
description: Main command for the coordinates
|
||||||
usage: /ic-coords get | add
|
usage: /ic-coords get | add | map
|
||||||
@@ -3,6 +3,8 @@ package nl.interestingcorner.core;
|
|||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
import nl.interestingcorner.core.db.DatabaseManager;
|
import nl.interestingcorner.core.db.DatabaseManager;
|
||||||
|
import nl.interestingcorner.core.gui.GUIInventoryClickListener;
|
||||||
|
import nl.interestingcorner.core.logging.Logger;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Core plugin class for the Interesting Corner plugin
|
* Core plugin class for the Interesting Corner plugin
|
||||||
@@ -11,6 +13,8 @@ public class App extends JavaPlugin {
|
|||||||
@Override
|
@Override
|
||||||
public void onEnable() {
|
public void onEnable() {
|
||||||
DatabaseManager.INSTANCE.initialize(this);
|
DatabaseManager.INSTANCE.initialize(this);
|
||||||
|
Logger.INSTANCE.initialize(this);
|
||||||
|
getServer().getPluginManager().registerEvents(GUIInventoryClickListener.INSTANCE, this);
|
||||||
getLogger().info("Core plugin loaded!");
|
getLogger().info("Core plugin loaded!");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -124,6 +124,20 @@ public enum MinecraftColor {
|
|||||||
return materialsMap.get(this);
|
return materialsMap.get(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Finds a MinecraftColor from a Material.
|
||||||
|
* @param material the material to find the color from
|
||||||
|
* @return the MinecraftColor corresponding to the material. White if not found.
|
||||||
|
*/
|
||||||
|
public static MinecraftColor fromMaterial(Material material) {
|
||||||
|
for (MinecraftColor color : MinecraftColor.values()) {
|
||||||
|
if (materialsMap.get(color) == material) {
|
||||||
|
return color;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return WHITE;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Converts this MinecraftColor to a corresponding Minecraft color code.
|
* Converts this MinecraftColor to a corresponding Minecraft color code.
|
||||||
* @return
|
* @return
|
||||||
|
|||||||
@@ -1,99 +1,159 @@
|
|||||||
package nl.interestingcorner.core.gui;
|
package nl.interestingcorner.core.gui;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
import org.bukkit.inventory.Inventory;
|
import org.bukkit.inventory.Inventory;
|
||||||
import org.bukkit.inventory.InventoryHolder;
|
import org.bukkit.inventory.InventoryHolder;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.bukkit.inventory.meta.ItemMeta;
|
||||||
|
|
||||||
public class GUI implements InventoryHolder {
|
public final class GUI implements InventoryHolder, Listener {
|
||||||
public static final int MAX_INVENTORY_SIZE = 54; // max size of inventory before pages are needed
|
public static final int MAX_INVENTORY_SIZE = 54; // max size of inventory before pages are needed
|
||||||
public static final int MAX_PAGE_INVENTORY_SIZE = 45; // max amount of items on a page
|
public static final int DEFAULT_PAGE_SIZE = 45; // default items per page (excluding navigation row)
|
||||||
|
public static final int PREVIOUS_PAGE_SLOT = 45; // slot for previous page button
|
||||||
|
public static final int NEXT_PAGE_SLOT = 53; // slot for next page button
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Inventory that will be displayed
|
* Inventory that will be displayed
|
||||||
*/
|
*/
|
||||||
private Inventory inventory;
|
private Inventory inventory;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Full list of items that the GUI holds
|
||||||
|
*/
|
||||||
|
private List<ItemStack> items;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Current page being displayed
|
* Current page being displayed
|
||||||
*/
|
*/
|
||||||
private int currentPage;
|
private int currentPage;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Items to be displayed in the GUI. This is the full list of items that can be displayed across all pages.
|
* Title of the GUI
|
||||||
*/
|
*/
|
||||||
private List<ItemStack> items;
|
private final String title;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Number of items per page
|
* Number of items per page
|
||||||
*/
|
*/
|
||||||
private int pageSize;
|
private final int pageSize;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the current page being displayed
|
* Listener for item click events
|
||||||
* @return the current page number
|
|
||||||
*/
|
*/
|
||||||
public int getCurrentPage() {
|
private final List<GUIItemClickListener> itemClickListeners;
|
||||||
return currentPage;
|
|
||||||
|
public GUI(String title, int pageSize) {
|
||||||
|
this.title = title;
|
||||||
|
this.pageSize = Math.min(pageSize, MAX_INVENTORY_SIZE);
|
||||||
|
this.items = new ArrayList<>();
|
||||||
|
this.currentPage = 0;
|
||||||
|
this.inventory = null;
|
||||||
|
this.itemClickListeners = new ArrayList<>();
|
||||||
|
addItemClickListener(new NavigationItemClickListener());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the current page to be displayed
|
|
||||||
* @param currentPage the page number to set
|
|
||||||
*/
|
|
||||||
public void setCurrentPage(int currentPage) {
|
|
||||||
this.currentPage = currentPage;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the list of items to be displayed in the GUI
|
|
||||||
* @return the list of items
|
|
||||||
*/
|
|
||||||
public List<ItemStack> getItems() {
|
|
||||||
return items;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the list of items to be displayed in the GUI
|
|
||||||
* @param items the list of items to set
|
|
||||||
*/
|
|
||||||
public void setItems(List<ItemStack> items) {
|
public void setItems(List<ItemStack> items) {
|
||||||
this.items = items;
|
this.items = new ArrayList<>(items);
|
||||||
|
this.currentPage = 0;
|
||||||
|
updateInventory();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public void addItemClickListener(GUIItemClickListener listener) {
|
||||||
* Gets the number of items per page
|
this.itemClickListeners.add(listener);
|
||||||
* @return the page size
|
|
||||||
*/
|
|
||||||
public int getPageSize() {
|
|
||||||
return pageSize;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public List<GUIItemClickListener> getItemClickListeners() {
|
||||||
* Sets the number of items per page
|
return this.itemClickListeners;
|
||||||
* @param pageSize the page size to set
|
|
||||||
*/
|
|
||||||
public void setPageSize(int pageSize) {
|
|
||||||
this.pageSize = pageSize;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public void addItem(ItemStack item) {
|
||||||
* Sets the inventory to be displayed
|
this.items.add(item);
|
||||||
* @param inventory the inventory to set
|
updateInventory();
|
||||||
*/
|
}
|
||||||
public void setInventory(Inventory inventory) {
|
|
||||||
this.inventory = inventory;
|
public void show(Player player) {
|
||||||
|
updateInventory();
|
||||||
|
player.openInventory(this.inventory);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void nextPage() {
|
||||||
|
if ((currentPage + 1) * pageSize < items.size()) {
|
||||||
|
currentPage++;
|
||||||
|
updateInventory();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void previousPage() {
|
||||||
|
if (currentPage > 0) {
|
||||||
|
currentPage--;
|
||||||
|
updateInventory();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getPagesAmount() {
|
||||||
|
return (int) Math.ceil((double) items.size() / pageSize);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void updateInventory() {
|
||||||
|
boolean needsPagination = items.size() > DEFAULT_PAGE_SIZE;
|
||||||
|
int inventorySize = needsPagination ? MAX_INVENTORY_SIZE : pageSize;
|
||||||
|
this.inventory = Bukkit.createInventory(this, inventorySize, title);
|
||||||
|
|
||||||
|
int itemsPerPage = needsPagination ? DEFAULT_PAGE_SIZE : pageSize;
|
||||||
|
int start = currentPage * itemsPerPage;
|
||||||
|
int end = Math.min(start + itemsPerPage, items.size());
|
||||||
|
List<ItemStack> pageItems = items.subList(start, end);
|
||||||
|
|
||||||
|
for (int i = 0; i < pageItems.size(); i++) {
|
||||||
|
if (needsPagination && i >= DEFAULT_PAGE_SIZE) {
|
||||||
|
// Fill only the top rows (0-44) with items if paginating
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
this.inventory.setItem(i, pageItems.get(i));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add navigation buttons if needed
|
||||||
|
if (needsPagination) {
|
||||||
|
if (currentPage > 0) {
|
||||||
|
// Slot 45: Previous Page
|
||||||
|
// use currentPage to show 1-based page number
|
||||||
|
ItemStack prevButton = createNavigationItem("Previous Page", (currentPage) + " / " + getPagesAmount());
|
||||||
|
this.inventory.setItem(PREVIOUS_PAGE_SLOT, prevButton);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((currentPage + 1) * pageSize < items.size()) {
|
||||||
|
// Slot 53: Next Page
|
||||||
|
// use currentPage + 2 to show 1-based page number
|
||||||
|
ItemStack nextButton = createNavigationItem("Next Page", (currentPage + 2) + " / " + getPagesAmount());
|
||||||
|
this.inventory.setItem(NEXT_PAGE_SLOT, nextButton);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private ItemStack createNavigationItem(String name, String description) {
|
||||||
|
ItemStack compass = new ItemStack(Material.COMPASS);
|
||||||
|
ItemMeta meta = compass.getItemMeta();
|
||||||
|
if (meta == null)
|
||||||
|
{
|
||||||
|
return compass;
|
||||||
|
}
|
||||||
|
|
||||||
|
meta.setDisplayName(name);
|
||||||
|
List<String> lore = new ArrayList<>();
|
||||||
|
lore.add(description);
|
||||||
|
meta.setLore(lore);
|
||||||
|
compass.setItemMeta(meta);
|
||||||
|
return compass;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Inventory getInventory() {
|
public Inventory getInventory() {
|
||||||
if (items.size() <= MAX_INVENTORY_SIZE) {
|
return this.inventory;
|
||||||
inventory = Bukkit.createInventory(this, MAX_INVENTORY_SIZE, "Coordinates Menu");
|
|
||||||
for (ItemStack item : items) {
|
|
||||||
inventory.addItem(item);
|
|
||||||
}
|
|
||||||
return inventory;
|
|
||||||
}
|
|
||||||
|
|
||||||
throw new UnsupportedOperationException("Paged inventory not yet implemented");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,40 +0,0 @@
|
|||||||
package nl.interestingcorner.core.gui;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.inventory.Inventory;
|
|
||||||
import org.bukkit.inventory.InventoryHolder;
|
|
||||||
import org.bukkit.inventory.ItemStack;
|
|
||||||
|
|
||||||
public class GUIBuilder {
|
|
||||||
|
|
||||||
public Inventory buildInventory(List<ItemStack> items) {
|
|
||||||
/**
|
|
||||||
* if more than 45, add pages. Split by 45 items per page.
|
|
||||||
* use bottom row leftmost and rightmost item for navigation.
|
|
||||||
* use paper item for page number display in middle.
|
|
||||||
* use lore of navigation items clicked to handle showing next/previous page.
|
|
||||||
* use player.getOpeninventory() to get current inventory and update or close
|
|
||||||
* it.
|
|
||||||
*/
|
|
||||||
|
|
||||||
int itemsAmount = items.size();
|
|
||||||
int pagesAmount = getPagesAmount(itemsAmount);
|
|
||||||
|
|
||||||
Inventory gui = Bukkit.createInventory(null, MAX_INVENTORY_SIZE, "Coordinates Menu");
|
|
||||||
|
|
||||||
for (ItemStack item : items) {
|
|
||||||
gui.addItem(item);
|
|
||||||
}
|
|
||||||
|
|
||||||
return gui;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static int getPagesAmount(int itemsAmount) {
|
|
||||||
if (itemsAmount > MAX_INVENTORY_SIZE) {
|
|
||||||
return ((itemsAmount / MAX_PAGE_INVENTORY_SIZE) + 1);
|
|
||||||
}
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
package nl.interestingcorner.core.gui;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||||
|
|
||||||
|
import nl.interestingcorner.core.logging.Logger;
|
||||||
|
|
||||||
|
public enum GUIInventoryClickListener implements Listener{
|
||||||
|
INSTANCE;
|
||||||
|
|
||||||
|
private final String TAG = this.getClass().getSimpleName();
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onInventoryClick(InventoryClickEvent event) {
|
||||||
|
if (event.getInventory().getHolder() instanceof GUI gui) {
|
||||||
|
Logger.INSTANCE.info(TAG, "Inventory click event detected");
|
||||||
|
|
||||||
|
List<GUIItemClickListener> itemClickListeners = gui.getItemClickListeners();
|
||||||
|
for (GUIItemClickListener itemClickListener : itemClickListeners)
|
||||||
|
{
|
||||||
|
event.setCancelled(true);
|
||||||
|
Logger.INSTANCE.info(TAG, "Sending click event to listener");
|
||||||
|
itemClickListener.onItemClick((Player) event.getWhoClicked(), gui, event.getCurrentItem(), event.getSlot());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
package nl.interestingcorner.core.gui;
|
||||||
|
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
|
public interface GUIItemClickListener {
|
||||||
|
void onItemClick(Player player, GUI gui, ItemStack item, int slot);
|
||||||
|
}
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
package nl.interestingcorner.core.gui;
|
||||||
|
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
|
public class NavigationItemClickListener implements GUIItemClickListener {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onItemClick(Player player, GUI gui, ItemStack item, int slot) {
|
||||||
|
if (slot == GUI.PREVIOUS_PAGE_SLOT) {
|
||||||
|
gui.previousPage();
|
||||||
|
player.closeInventory();
|
||||||
|
gui.show(player);
|
||||||
|
} else if (slot == GUI.NEXT_PAGE_SLOT) {
|
||||||
|
gui.nextPage();
|
||||||
|
player.closeInventory();
|
||||||
|
gui.show(player);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
package nl.interestingcorner.core.logging;
|
||||||
|
|
||||||
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
|
public enum Logger {
|
||||||
|
INSTANCE;
|
||||||
|
|
||||||
|
private JavaPlugin plugin;
|
||||||
|
|
||||||
|
public void initialize(JavaPlugin plugin) {
|
||||||
|
this.plugin = plugin;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void info(String tag, String message) {
|
||||||
|
if (this.plugin != null) {
|
||||||
|
this.plugin.getLogger().info("[" + tag + "] " + message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user