First parts of displaying a GUI
This commit is contained in:
@@ -13,34 +13,39 @@ public class GetCoordinatesCommandHandler implements CoordinatesCommandHandler {
|
||||
|
||||
@Override
|
||||
public boolean handleCommand(CommandSender sender, String[] args) {
|
||||
if (sender instanceof Player player) {
|
||||
List<Coordinate> coords;
|
||||
if (args.length < 2) {
|
||||
coords = CoordinatesDatabaseManager.INSTANCE.getAllCoordinates();
|
||||
} else if (args[1].equalsIgnoreCase("world")) {
|
||||
String world = player.getWorld().getName();
|
||||
coords = CoordinatesDatabaseManager.INSTANCE.getAllCoordinates(world);
|
||||
} else {
|
||||
sender.sendMessage("Invalid argument: " + args[1]);
|
||||
return false;
|
||||
try {
|
||||
if (sender instanceof Player player) {
|
||||
List<Coordinate> coords;
|
||||
if (args.length < 2) {
|
||||
coords = CoordinatesDatabaseManager.INSTANCE.getAllCoordinates();
|
||||
} else if (args[1].equalsIgnoreCase("world")) {
|
||||
String world = player.getWorld().getName();
|
||||
coords = CoordinatesDatabaseManager.INSTANCE.getAllCoordinates(world);
|
||||
} else {
|
||||
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;
|
||||
}
|
||||
|
||||
StringBuilder res = new StringBuilder("Coordinates: ");
|
||||
|
||||
for (Coordinate coordinate : coords) {
|
||||
res.append(coordinate.toString());
|
||||
}
|
||||
|
||||
player.sendMessage(res.toString());
|
||||
|
||||
CoordinatesGUI.open(player, coords);
|
||||
}
|
||||
|
||||
if (coords.isEmpty()) {
|
||||
player.sendMessage("No coordinates found! Add some with the §3/ic-coords §5add §fcommand.");
|
||||
return true;
|
||||
}
|
||||
|
||||
StringBuilder res = new StringBuilder("Coordinates: ");
|
||||
|
||||
for (Coordinate coordinate : coords) {
|
||||
res.append(coordinate.toString());
|
||||
}
|
||||
|
||||
player.sendMessage(res.toString());
|
||||
|
||||
CoordinatesGUI.open(player, coords);
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
package nl.interestingcorner.coordinates.gui;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
import nl.interestingcorner.coordinates.db.Coordinate;
|
||||
import nl.interestingcorner.core.gui.GUI;
|
||||
@@ -11,12 +14,21 @@ import nl.interestingcorner.core.gui.GUI;
|
||||
public class CoordinatesGUI {
|
||||
public static void open(Player player, List<Coordinate> coords) {
|
||||
// Convert coordinates to ItemStacks for GUI display
|
||||
List<ItemStack> items = coords.stream()
|
||||
.map(coord -> {
|
||||
ItemStack item = coord.toItem();
|
||||
return item;
|
||||
})
|
||||
.toList();
|
||||
|
||||
List<ItemStack> items = new ArrayList<>();
|
||||
|
||||
for (Coordinate coord : coords) {
|
||||
ItemStack item = coord.toItem();
|
||||
items.add(item);
|
||||
}
|
||||
|
||||
for (int i = 0; i < 90; i++) {
|
||||
ItemStack item = new ItemStack(Material.AMETHYST_BLOCK);
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
meta.setDisplayName("Test Item " + (i + 1));
|
||||
item.setItemMeta(meta);
|
||||
items.add(item);
|
||||
}
|
||||
|
||||
GUI gui = new GUI("Coordinates", GUI.DEFAULT_PAGE_SIZE);
|
||||
gui.setItems(items);
|
||||
|
||||
Reference in New Issue
Block a user