Skip to content

Commit 35cea32

Browse files
v.1.1.0 part 1
- Added a superclass for GUIs to better build new GUI types in the future - Added a pagedGui - Simplified the code a bit - Added spacing variable to set how far apart the GUI components should be - Made area of freedom top move depending on the spacing variable - Changed the dev command to spawn a paged gui - Made the opening of the gui account for the selected page - Prob done more stuff, but I can't remember rn
1 parent aa19e38 commit 35cea32

File tree

15 files changed

+318
-86
lines changed

15 files changed

+318
-86
lines changed

build.gradle

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ wrapper {
4545
distributionType = Wrapper.DistributionType.ALL
4646
}
4747

48+
jar {
49+
destinationDirectory.set(file("/Users/linusglimm/Desktop/mineopoly stuff/servers/spigotTest/plugins"))
50+
}
51+
4852
tasks.withType(JavaCompile).configureEach {
4953
options.encoding = 'UTF-8'
5054

src/main/java/de/littleprogrammer/guiapi/GuiApi.java

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22

33
import de.littleprogrammer.guiapi.commands.SpawnCommand;
44
import de.littleprogrammer.guiapi.enums.ServerVersion;
5+
import de.littleprogrammer.guiapi.guis.Gui;
6+
import de.littleprogrammer.guiapi.guis.SimpleGui;
57
import de.littleprogrammer.guiapi.listeners.GuiEvents;
68
import de.littleprogrammer.guiapi.listeners.MoveListener;
7-
import org.bukkit.Bukkit;
89
import org.bukkit.entity.Player;
910
import org.bukkit.event.Listener;
1011
import org.bukkit.plugin.java.JavaPlugin;
@@ -14,21 +15,21 @@
1415
import java.util.Map;
1516
import java.util.UUID;
1617

17-
public final class GuiApi {
18+
public final class GuiApi extends JavaPlugin {
1819

1920
private JavaPlugin plugin;
2021
private static GuiApi instance;
2122
private ServerVersion version;
2223
private final Listener listener = new GuiEvents();
2324
private final Listener moveListener = new MoveListener();
24-
private Map<UUID, SimpleGui> guis = new HashMap<>();
25+
private Map<UUID, Gui> guis = new HashMap<>();
2526

26-
public GuiApi(JavaPlugin plugin) {
27+
/*public GuiApi(JavaPlugin plugin) {
2728
this.plugin = plugin;
2829
instance = this;
29-
}
30+
}*/
3031

31-
/*@Override
32+
@Override
3233
public void onEnable() {
3334
// Plugin startup logic
3435
this.plugin = this;
@@ -40,7 +41,7 @@ public void onEnable() {
4041
@Override
4142
public void onDisable() {
4243
// Plugin shutdown logic
43-
}*/
44+
}
4445

4546
public void init() {
4647
//This method checks the server version, to determine weather it should use the new 1.20.2 teleport interpolation or my own teleport interpolation
@@ -66,7 +67,7 @@ public void init() {
6667
getPlugin().getServer().getPluginManager().registerEvents(this.listener, this.plugin);
6768
getPlugin().getServer().getPluginManager().registerEvents(this.moveListener, this.plugin);
6869

69-
//this.getPlugin().getCommand("spawnGui").setExecutor(new SpawnCommand());
70+
this.getPlugin().getCommand("spawnGui").setExecutor(new SpawnCommand());
7071
}
7172

7273
public JavaPlugin getPlugin() {return this.plugin;}
@@ -78,15 +79,15 @@ public static BukkitScheduler getScheduler() {
7879
return GuiApi.getInstance().getPlugin().getServer().getScheduler();
7980
}
8081

81-
public SimpleGui getGUI(UUID uuid) {
82+
public Gui getGUI(UUID uuid) {
8283
return guis.get(uuid);
8384
}
8485

85-
public SimpleGui getGUI(Player player) {
86+
public Gui getGUI(Player player) {
8687
return guis.get(player.getUniqueId());
8788
}
8889

89-
public Map<UUID, SimpleGui> getGuis() {
90+
public Map<UUID, Gui> getGuis() {
9091
return guis;
9192
}
9293

src/main/java/de/littleprogrammer/guiapi/commands/SpawnCommand.java

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,21 @@
11
package de.littleprogrammer.guiapi.commands;
22

3-
import de.littleprogrammer.guiapi.SimpleGui;
3+
import de.littleprogrammer.guiapi.guis.PagedGui;
4+
import de.littleprogrammer.guiapi.guis.SimpleGui;
45
import de.littleprogrammer.guiapi.components.Button;
56
import de.littleprogrammer.guiapi.components.Text;
67
import org.bukkit.command.Command;
78
import org.bukkit.command.CommandExecutor;
89
import org.bukkit.command.CommandSender;
910
import org.bukkit.entity.Player;
1011

12+
import java.util.ArrayList;
13+
import java.util.List;
14+
1115
public class SpawnCommand implements CommandExecutor {
1216
@Override
1317
public boolean onCommand(CommandSender commandSender, Command command, String s, String[] strings) {
14-
Button button = new Button("\uE001", "\uE002", 1)
18+
/*Button button = new Button("\uE001", "\uE002", 1)
1519
.setSize(2)
1620
.onClick(event -> {
1721
event.getPlayer().sendMessage("You clicked a button1");
@@ -31,15 +35,24 @@ public boolean onCommand(CommandSender commandSender, Command command, String s,
3135
event.getPlayer().sendMessage("You clicked a button3");
3236
});
3337
34-
Text text = new Text("Here you can put\n some text. This is just for\n testing purposes.\n As you can see, \nit's working quite nicely and \nlook at this cool hovering effect.")
38+
Text text = new Text("Here you can put\n some text. This is just for\n testing purposes.\n As you can see, \nit's working quite nicely and \nlook at this cool hovering effect.", 0)
3539
.setSize(1.4f);
3640
3741
SimpleGui gui = new SimpleGui("Some title")
3842
.addContent(text)
3943
.addButton(button)
4044
.addButton(button2)
4145
.addButton(button3);
42-
gui.open((Player) commandSender);
46+
gui.open((Player) commandSender);*/
47+
48+
List<String> stringList = new ArrayList<>();
49+
stringList.add("String 1");
50+
stringList.add("String 2");
51+
stringList.add("String 3");
52+
53+
PagedGui pagedGui = new PagedGui("Title", 0);
54+
pagedGui.addContent(stringList);
55+
pagedGui.open((Player) commandSender);
4356

4457
return false;
4558
}

src/main/java/de/littleprogrammer/guiapi/components/Button.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package de.littleprogrammer.guiapi.components;
22

33
import de.littleprogrammer.guiapi.GuiApi;
4-
import de.littleprogrammer.guiapi.SimpleGui;
4+
import de.littleprogrammer.guiapi.guis.SimpleGui;
55
import de.littleprogrammer.guiapi.customeEvents.HoverButtonEvent;
66
import de.littleprogrammer.guiapi.customeEvents.UnHoverButtonEvent;
77
import de.littleprogrammer.guiapi.utils.Calculations;
@@ -39,7 +39,7 @@ public Button(String texture, String hoverTexture, int slot) {
3939
}
4040

4141
public void spawn() {
42-
textDisplay = (TextDisplay) simpleGui.getCenterLocation().getWorld().spawnEntity(Calculations.calculateComponentLocation(simpleGui, this, simpleGui.getButtonAmount()), EntityType.TEXT_DISPLAY);
42+
textDisplay = (TextDisplay) simpleGui.getCenterLocation().getWorld().spawnEntity(Calculations.calculateComponentLocation(simpleGui, this, simpleGui.getButtonAmount(), 30), EntityType.TEXT_DISPLAY);
4343
textDisplay.setCustomName(uuid.toString());
4444
textDisplay.setCustomNameVisible(false);
4545
textDisplay.setText(texture);

src/main/java/de/littleprogrammer/guiapi/components/Component.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package de.littleprogrammer.guiapi.components;
22

3-
import de.littleprogrammer.guiapi.SimpleGui;
43
import org.bukkit.entity.Display;
54
import org.bukkit.entity.Entity;
65
import org.bukkit.entity.Player;

src/main/java/de/littleprogrammer/guiapi/components/Text.java

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
package de.littleprogrammer.guiapi.components;
22

33
import de.littleprogrammer.guiapi.GuiApi;
4-
import de.littleprogrammer.guiapi.SimpleGui;
4+
import de.littleprogrammer.guiapi.guis.Gui;
5+
import de.littleprogrammer.guiapi.guis.SimpleGui;
56
import org.bukkit.entity.*;
67
import org.bukkit.util.Transformation;
78
import org.joml.Vector3f;
@@ -14,16 +15,23 @@ public class Text implements Component {
1415
private UUID uuid;
1516
private float size = 2;
1617
private TextDisplay textDisplay;
17-
private SimpleGui simpleGui;
18+
private Gui gui;
19+
private int slot;
1820

1921
public Text(String text) {
2022
this.text = text;
2123
uuid = UUID.randomUUID();
2224
}
2325

26+
public Text(String text, int slot) {
27+
this.text = text;
28+
this.slot = slot < 0 || slot > 3 ? 1 : slot;
29+
uuid = UUID.randomUUID();
30+
}
31+
2432
@Override
2533
public void spawn() {
26-
textDisplay = (TextDisplay) simpleGui.getCenterLocation().getWorld().spawnEntity(simpleGui.getCenterLocation(), EntityType.TEXT_DISPLAY);
34+
textDisplay = (TextDisplay) gui.getCenterLocation().getWorld().spawnEntity(gui.getCenterLocation(), EntityType.TEXT_DISPLAY);
2735
textDisplay.setCustomName(uuid.toString());
2836
textDisplay.setCustomNameVisible(false);
2937
textDisplay.setText(text);
@@ -53,16 +61,16 @@ public UUID getUniqueId() {
5361
return uuid;
5462
}
5563

56-
public SimpleGui getGui() {
57-
return simpleGui;
64+
public Gui getGui() {
65+
return gui;
5866
}
5967

6068
public float getSize() {
6169
return size;
6270
}
6371

64-
public void setGui(SimpleGui simpleGui) {
65-
this.simpleGui = simpleGui;
72+
public void setGui(Gui gui) {
73+
this.gui = gui;
6674
}
6775

6876
public Text setSize(float size) {
@@ -84,4 +92,12 @@ public void hide(Player player) {
8492
public void remove() {
8593
textDisplay.remove();
8694
}
95+
96+
public int getSlot() {
97+
return slot;
98+
}
99+
100+
public void setSlot(int slot) {
101+
this.slot = slot;
102+
}
87103
}

src/main/java/de/littleprogrammer/guiapi/customeEvents/HoverButtonEvent.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package de.littleprogrammer.guiapi.customeEvents;
22

3-
import de.littleprogrammer.guiapi.SimpleGui;
3+
import de.littleprogrammer.guiapi.guis.Gui;
4+
import de.littleprogrammer.guiapi.guis.SimpleGui;
45
import de.littleprogrammer.guiapi.components.Button;
56
import org.bukkit.entity.Player;
67
import org.bukkit.event.Event;
@@ -9,13 +10,13 @@
910
public class HoverButtonEvent extends Event {
1011
private static final HandlerList HANDLERS = new HandlerList();
1112

12-
private final SimpleGui gui;
13+
private final Gui gui;
1314
private final Player player;
1415
private final Button button;
1516
private final String hoverText;
1617
private final String text;
1718

18-
public HoverButtonEvent(SimpleGui gui, Player player, Button button, String hoverText, String text) {
19+
public HoverButtonEvent(Gui gui, Player player, Button button, String hoverText, String text) {
1920
this.gui = gui;
2021
this.player = player;
2122
this.button = button;
@@ -34,7 +35,7 @@ public static HandlerList getHandlerList() {
3435
return HANDLERS;
3536
}
3637

37-
public SimpleGui getGui() {
38+
public Gui getGui() {
3839
return gui;
3940
}
4041

src/main/java/de/littleprogrammer/guiapi/customeEvents/UnHoverButtonEvent.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package de.littleprogrammer.guiapi.customeEvents;
22

3-
import de.littleprogrammer.guiapi.SimpleGui;
3+
import de.littleprogrammer.guiapi.guis.Gui;
4+
import de.littleprogrammer.guiapi.guis.SimpleGui;
45
import de.littleprogrammer.guiapi.components.Button;
56
import org.bukkit.entity.Player;
67
import org.bukkit.event.Event;
@@ -9,13 +10,13 @@
910
public class UnHoverButtonEvent extends Event {
1011
private static final HandlerList HANDLERS = new HandlerList();
1112

12-
private final SimpleGui gui;
13+
private final Gui gui;
1314
private final Player player;
1415
private final Button button;
1516
private final String hoverText;
1617
private final String text;
1718

18-
public UnHoverButtonEvent(SimpleGui gui, Player player, Button button, String hoverText, String text) {
19+
public UnHoverButtonEvent(Gui gui, Player player, Button button, String hoverText, String text) {
1920
this.gui = gui;
2021
this.player = player;
2122
this.button = button;
@@ -34,7 +35,7 @@ public static HandlerList getHandlerList() {
3435
return HANDLERS;
3536
}
3637

37-
public SimpleGui getGui() {
38+
public Gui getGui() {
3839
return gui;
3940
}
4041

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
package de.littleprogrammer.guiapi.guis;
2+
3+
import de.littleprogrammer.guiapi.components.Component;
4+
import org.bukkit.Location;
5+
import org.bukkit.entity.Player;
6+
7+
import java.util.*;
8+
9+
public abstract class Gui {
10+
public UUID uuid;
11+
public Player player;
12+
public Location centerLocation;
13+
public boolean open;
14+
public Map<UUID, Component> components;
15+
public int spacing;
16+
17+
public Gui(UUID uuid, boolean open) {
18+
this.uuid = uuid;
19+
this.open = open;
20+
21+
this.components = new HashMap<>();
22+
}
23+
24+
public abstract void open(Player player);
25+
public abstract void close();
26+
public abstract void updatePosition(Location location);
27+
28+
public void setUuid(UUID uuid) {
29+
this.uuid = uuid;
30+
}
31+
32+
public void setPlayer(Player player) {
33+
this.player = player;
34+
}
35+
36+
public void setCenterLocation(Location centerLocation) {
37+
this.centerLocation = centerLocation;
38+
}
39+
40+
public void setOpen(boolean open) {
41+
this.open = open;
42+
}
43+
44+
public boolean isOpen() {
45+
return open;
46+
}
47+
48+
public Component getComponent(UUID uuid) {
49+
return components.get(uuid);
50+
}
51+
52+
public Location getCenterLocation() {
53+
return centerLocation;
54+
}
55+
56+
public Player getPlayer() {
57+
return player;
58+
}
59+
60+
public List<Component> getComponents() {
61+
return new ArrayList<>(components.values());
62+
}
63+
64+
public void setSpacing(int spacing) {
65+
this.spacing = spacing;
66+
}
67+
68+
public int getSpacing() {
69+
return spacing;
70+
}
71+
}

0 commit comments

Comments
 (0)