Skip to content

Commit de17083

Browse files
v.1.1.0 part 4
- Removed an unused sout - Added the option to have a 3rd button in the middle of the left and right arrows - Added option to change the texts on the left and right buttons - Added some methods to the API easier to use - Changed GuiApi.java so it's an API again - Changed SpawnCommand to give an example of how to spawn a paged GUI
1 parent 98c2ff1 commit de17083

File tree

5 files changed

+70
-17
lines changed

5 files changed

+70
-17
lines changed

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
import java.util.Map;
1616
import java.util.UUID;
1717

18-
public final class GuiApi extends JavaPlugin {
18+
public final class GuiApi /*extends JavaPlugin*/ {
1919

2020
private JavaPlugin plugin;
2121
private static GuiApi instance;
@@ -24,12 +24,12 @@ public final class GuiApi extends JavaPlugin {
2424
private final Listener moveListener = new MoveListener();
2525
private Map<UUID, Gui> guis = new HashMap<>();
2626

27-
/*public GuiApi(JavaPlugin plugin) {
27+
public GuiApi(JavaPlugin plugin) {
2828
this.plugin = plugin;
2929
instance = this;
30-
}*/
30+
}
3131

32-
@Override
32+
/*@Override
3333
public void onEnable() {
3434
// Plugin startup logic
3535
this.plugin = this;
@@ -41,7 +41,7 @@ public void onEnable() {
4141
@Override
4242
public void onDisable() {
4343
// Plugin shutdown logic
44-
}
44+
}*/
4545

4646
public void init() {
4747
//This method checks the server version, to determine weather it should use the new 1.20.2 teleport interpolation or my own teleport interpolation
@@ -67,7 +67,7 @@ public void init() {
6767
getPlugin().getServer().getPluginManager().registerEvents(this.listener, this.plugin);
6868
getPlugin().getServer().getPluginManager().registerEvents(this.moveListener, this.plugin);
6969

70-
this.getPlugin().getCommand("spawnGui").setExecutor(new SpawnCommand());
70+
//this.getPlugin().getCommand("spawnGui").setExecutor(new SpawnCommand());
7171
}
7272

7373
public JavaPlugin getPlugin() {return this.plugin;}

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,16 @@ public boolean onCommand(CommandSender commandSender, Command command, String s,
6060
stringList.add(ChatColor.DARK_BLUE.toString() + ChatColor.BOLD + "Stooooppp!!!\n" + ChatColor.RESET + ChatColor.WHITE + "Lorem ipsum dolor\n sit amet,\n consetetur sadipscing\n elitr, sed diam\n nonumy eirmod\n tempor invidunt ut\n labore et dolore\n magna aliquyam");
6161
stringList.add(ChatColor.DARK_GREEN.toString() + ChatColor.BOLD + "The end.\n" + ChatColor.RESET + ChatColor.WHITE + "Lorem ipsum dolor\n sit amet,\n consetetur sadipscing\n elitr, sed diam\n nonumy eirmod\n tempor invidunt ut\n labore et dolore\n magna aliquyam");
6262

63-
PagedGui pagedGui = new PagedGui("Title", 0);
63+
Button button2 = new Button("close", "CLOSE", 1).onClick(event -> {
64+
event.getPlayer().sendMessage("You clicked the close button!");
65+
});
66+
67+
PagedGui pagedGui = new PagedGui("Title", 0).addButton(button2);
68+
pagedGui.setSpacing(30);
69+
pagedGui.setContentSpacing(50);
6470
pagedGui.addContent(stringList);
6571
pagedGui.open((Player) commandSender);
72+
pagedGui.setLeftButtonText("left", "lll").setRightButtonText("right", "rrr");
6673

6774
return false;
6875
}

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,10 @@ public int getSlot() {
136136
return slot;
137137
}
138138

139+
public void setSlot(int slot) {
140+
this.slot = slot;
141+
}
142+
139143
public void setGui(Gui gui) {
140144
this.gui = gui;
141145
}
@@ -152,4 +156,12 @@ public void setHover(boolean hover) {
152156
public boolean isHover() {
153157
return hover;
154158
}
159+
160+
public void setTexture(String texture) {
161+
this.texture = texture;
162+
}
163+
164+
public void setHoverTexture(String hoverTexture) {
165+
this.hoverTexture = hoverTexture;
166+
}
155167
}

src/main/java/de/littleprogrammer/guiapi/guis/PagedGui.java

Lines changed: 43 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,18 @@ public class PagedGui extends Gui {
1919
private List<String> contents;
2020
private List<Text> texts;
2121
private Button leftButton;
22+
private Button middleButton;
2223
private Button rightButton;
24+
private float contentSize = 1.3f;
25+
private int contentSpacing = 60;
2326

2427
public PagedGui(String title, int page) {
2528
super(UUID.randomUUID(), false);
2629

2730
this.page = page;
2831
this.contents = new ArrayList<>();
2932
this.texts = new ArrayList<>();
33+
this.title = title;
3034

3135
setSpacing(60);
3236
}
@@ -42,9 +46,8 @@ public void open(Player player) {
4246
centerLocation = new Location(player.getWorld(), 0, 0, 0);
4347

4448
for (int i = 0; i < 3; i++) {
45-
System.out.println("Setting of: " + contents.get(i));
4649
if (contents.size() >= i) {
47-
Text text = new Text(contents.get(i + page), i + 1).setSize(1f);
50+
Text text = new Text(contents.get(i + page), i + 1).setSize(contentSize);
4851
text.setGui(this);
4952
texts.add(text);
5053
components.put(text.getUniqueId(), text);
@@ -62,7 +65,7 @@ public void open(Player player) {
6265
leftButton.setGui(this);
6366
buttons.put(leftButton.getUniqueId(), leftButton);
6467

65-
rightButton = new Button(">", ">>", 2).onClick(event -> {
68+
rightButton = new Button(">", ">>", 3).onClick(event -> {
6669
if (GuiApi.getInstance().getGuis().get(player.getUniqueId()) instanceof PagedGui) {
6770
PagedGui gui = (PagedGui) GuiApi.getInstance().getGuis().get(player.getUniqueId());
6871
System.out.println("Page " + gui.getPage() + " texts size " + contents.size() + " bool " + (gui.getPage() < contents.size() - 3));
@@ -103,28 +106,28 @@ public void updatePosition(Location playerLoc) {
103106

104107
if (GuiApi.getInstance().getVersion().equals(ServerVersion.PRE_1_20_2)) {
105108
for (Text text : texts) {
106-
Location newComponentLocation = Calculations.calculateComponentLocation(this, text, 3, spacing);
109+
Location newComponentLocation = Calculations.calculateComponentLocation(this, text, 3, contentSpacing);
107110

108111
TeleportInterpolator teleportInterpolator = new TeleportInterpolator(text.getEntity(), newComponentLocation, 5, 1);
109112
teleportInterpolator.startInterpolation();
110113
}
111114

112115
for (Button button : buttons.values()) {
113-
Location newComponentLocation = Calculations.calculateComponentLocation(this, button, 2, 35);
116+
Location newComponentLocation = Calculations.calculateComponentLocation(this, button, 3, spacing);
114117

115118
TeleportInterpolator teleportInterpolator = new TeleportInterpolator(button.getEntity(), newComponentLocation, 5, 1);
116119
teleportInterpolator.startInterpolation();
117120
}
118121
} else {
119122
for (Text text : texts) {
120-
Location newComponentLocation = Calculations.calculateComponentLocation(this, text, 3, spacing);
123+
Location newComponentLocation = Calculations.calculateComponentLocation(this, text, 3, contentSpacing);
121124

122125
text.getDisplay().setTeleportDuration(5);
123126
text.getDisplay().teleport(newComponentLocation);
124127
}
125128

126129
for (Button button : buttons.values()) {
127-
Location newComponentLocation = Calculations.calculateComponentLocation(this, button, 2, 35);
130+
Location newComponentLocation = Calculations.calculateComponentLocation(this, button, 3, spacing);
128131

129132
button.getDisplay().setTeleportDuration(5);
130133
button.getDisplay().teleport(newComponentLocation);
@@ -140,6 +143,17 @@ private void changePage(int newPage) {
140143
this.page = newPage;
141144
}
142145

146+
public PagedGui addButton(Button button) {
147+
if (middleButton == null) {
148+
button.setSlot(2);
149+
components.put(button.getUniqueId(), button);
150+
buttons.put(button.getUniqueId(), button);
151+
middleButton = button;
152+
button.setGui(this);
153+
}
154+
return this;
155+
}
156+
143157
public void setContents(List<String> contents) {
144158
this.contents = contents;
145159
}
@@ -154,6 +168,10 @@ public void addContent(String content) {
154168
this.contents.add(content);
155169
}
156170

171+
public List<String> getContents() {
172+
return contents;
173+
}
174+
157175
public String getTitle() {
158176
return title;
159177
}
@@ -162,7 +180,23 @@ public int getPage() {
162180
return page;
163181
}
164182

165-
public List<Text> getTexts() {
166-
return texts;
183+
public void setContentSize(float contentSize) {
184+
this.contentSize = contentSize;
185+
}
186+
187+
public void setContentSpacing(int contentSpacing) {
188+
this.contentSpacing = contentSpacing;
189+
}
190+
191+
public PagedGui setLeftButtonText(String text, String hoverText) {
192+
leftButton.setTexture(text);
193+
leftButton.setHoverTexture(hoverText);
194+
return this;
195+
}
196+
197+
public PagedGui setRightButtonText(String text, String hoverText) {
198+
rightButton.setTexture(text);
199+
rightButton.setHoverTexture(hoverText);
200+
return this;
167201
}
168202
}

src/main/resources/plugin.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ api-version: '1.19'
55
authors: [LittleProgrammer]
66
description: An API to make 3D Gui's in minecraft
77
commands:
8-
spawnGui:
8+
#spawnGui:

0 commit comments

Comments
 (0)