Skip to content

Commit e7f1a63

Browse files
Im-FranTheProgramSrc
authored andcommitted
Working on BrowserGUI fixes (Search Button not working)
1 parent 6d7e908 commit e7f1a63

File tree

4 files changed

+140
-110
lines changed

4 files changed

+140
-110
lines changed

dependency-reduced-pom.xml

Lines changed: 9 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<groupId>xyz.theprogramsrc</groupId>
55
<artifactId>SuperCoreAPI</artifactId>
66
<name>SuperCoreAPI</name>
7-
<version>4.0.0</version>
7+
<version>4.2.10_BETA4</version>
88
<build>
99
<sourceDirectory>src/main/java</sourceDirectory>
1010
<defaultGoal>clean package</defaultGoal>
@@ -14,7 +14,7 @@
1414
<directory>src/main/resources</directory>
1515
</resource>
1616
</resources>
17-
<finalName>${artifactId}</finalName>
17+
<finalName>${project.artifactId}</finalName>
1818
<plugins>
1919
<plugin>
2020
<artifactId>maven-compiler-plugin</artifactId>
@@ -64,7 +64,7 @@
6464
<dependency>
6565
<groupId>org.spigotmc</groupId>
6666
<artifactId>spigot-api</artifactId>
67-
<version>1.16.1-R0.1-SNAPSHOT</version>
67+
<version>1.16.3-R0.1-SNAPSHOT</version>
6868
<scope>provided</scope>
6969
<exclusions>
7070
<exclusion>
@@ -88,7 +88,7 @@
8888
<dependency>
8989
<groupId>net.md-5</groupId>
9090
<artifactId>bungeecord-api</artifactId>
91-
<version>1.16-R0.2</version>
91+
<version>1.16-R0.3</version>
9292
<scope>provided</scope>
9393
<exclusions>
9494
<exclusion>
@@ -124,7 +124,7 @@
124124
<dependency>
125125
<groupId>org.spigotmc</groupId>
126126
<artifactId>spigot</artifactId>
127-
<version>1.15.2-R0.1-20200625.172449-18</version>
127+
<version>1.16.3-R0.1-20201003.002207-3</version>
128128
<scope>provided</scope>
129129
</dependency>
130130
<dependency>
@@ -151,35 +151,15 @@
151151
</exclusion>
152152
</exclusions>
153153
</dependency>
154-
<dependency>
155-
<groupId>org.junit.jupiter</groupId>
156-
<artifactId>junit-jupiter</artifactId>
157-
<version>RELEASE</version>
158-
<scope>test</scope>
159-
<exclusions>
160-
<exclusion>
161-
<artifactId>junit-jupiter-api</artifactId>
162-
<groupId>org.junit.jupiter</groupId>
163-
</exclusion>
164-
<exclusion>
165-
<artifactId>junit-jupiter-params</artifactId>
166-
<groupId>org.junit.jupiter</groupId>
167-
</exclusion>
168-
<exclusion>
169-
<artifactId>junit-jupiter-engine</artifactId>
170-
<groupId>org.junit.jupiter</groupId>
171-
</exclusion>
172-
</exclusions>
173-
</dependency>
174154
</dependencies>
175155
<distributionManagement>
176156
<repository>
177-
<id>codemc-releases</id>
178-
<url>https://repo.codemc.io/repository/maven-releases/</url>
157+
<id>theprogramsrc-releases</id>
158+
<url>https://repo.theprogramsrc.xyz/repository/maven-releases/</url>
179159
</repository>
180160
<snapshotRepository>
181-
<id>codemc-snapshots</id>
182-
<url>https://repo.codemc.io/repository/maven-snapshots/</url>
161+
<id>theprogramsrc-snapshots</id>
162+
<url>https://repo.theprogramsrc.xyz/repository/maven-snapshots/</url>
183163
</snapshotRepository>
184164
</distributionManagement>
185165
<properties>
Lines changed: 43 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,57 @@
11
package xyz.theprogramsrc.supercoreapi.plugin;
22

3-
import org.bukkit.Bukkit;
4-
import org.bukkit.ChatColor;
5-
import org.bukkit.plugin.java.JavaPlugin;
3+
import org.bukkit.entity.Player;
4+
import xyz.theprogramsrc.supercoreapi.spigot.commands.CommandResult;
5+
import xyz.theprogramsrc.supercoreapi.spigot.commands.SpigotCommand;
6+
import xyz.theprogramsrc.supercoreapi.spigot.guis.action.ClickAction;
7+
import xyz.theprogramsrc.supercoreapi.spigot.guis.precreated.MaterialBrowser;
8+
import xyz.theprogramsrc.supercoreapi.spigot.utils.SpigotConsole;
9+
import xyz.theprogramsrc.supercoreapi.spigot.utils.xseries.XMaterial;
10+
11+
public class SpigotPlugin extends xyz.theprogramsrc.supercoreapi.spigot.SpigotPlugin {
612

7-
public class SpigotPlugin extends JavaPlugin {
813

914
@Override
10-
public void onEnable() {
11-
this.log("&3SuperCoreAPI &awas loaded as .jar file");
15+
public void onPluginLoad() {
16+
1217
}
1318

1419
@Override
15-
public void onDisable() {
16-
this.log("&3SuperCoreAPI &awas disabled");
20+
public void onPluginEnable() {
21+
new Command();
1722
}
1823

19-
private void log(String s){
20-
Bukkit.getConsoleSender().sendMessage(c(s));
24+
@Override
25+
public void onPluginDisable() {
26+
2127
}
2228

23-
private String c(String s){
24-
return ChatColor.translateAlternateColorCodes('&', s);
29+
static class Command extends SpigotCommand {
30+
31+
@Override
32+
public String getCommand() {
33+
return "scapi";
34+
}
35+
36+
@Override
37+
public CommandResult onPlayerExecute(Player player, String[] args) {
38+
new MaterialBrowser(player){
39+
@Override
40+
public void onBack(ClickAction clickAction) {
41+
this.close();
42+
}
43+
44+
@Override
45+
public void onSelect(ClickAction clickAction, XMaterial xMaterial) {
46+
clickAction.getPlayer().getInventory().addItem(xMaterial.parseItem());
47+
}
48+
}.open();
49+
return CommandResult.COMPLETED;
50+
}
51+
52+
@Override
53+
public CommandResult onConsoleExecute(SpigotConsole console, String[] args) {
54+
return CommandResult.COMPLETED;
55+
}
2556
}
2657
}

src/main/java/xyz/theprogramsrc/supercoreapi/spigot/guis/BrowserGUI.java

Lines changed: 36 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
package xyz.theprogramsrc.supercoreapi.spigot.guis;
22

3+
import org.bukkit.ChatColor;
34
import org.bukkit.entity.Player;
45
import xyz.theprogramsrc.supercoreapi.global.translations.Base;
5-
import xyz.theprogramsrc.supercoreapi.global.utils.Utils;
66
import xyz.theprogramsrc.supercoreapi.spigot.dialog.Dialog;
77
import xyz.theprogramsrc.supercoreapi.spigot.guis.action.ClickAction;
88
import xyz.theprogramsrc.supercoreapi.spigot.guis.objects.GUIRows;
99
import xyz.theprogramsrc.supercoreapi.spigot.items.SimpleItem;
1010

11-
import java.util.Arrays;
12-
import java.util.Iterator;
11+
import java.util.ArrayList;
1312
import java.util.List;
1413
import java.util.stream.Collectors;
1514

@@ -35,16 +34,34 @@ protected GUIRows getRows() {
3534
@Override
3635
public GUIButton[] getButtons() {
3736
OBJ[] objs = this.getObjects();
38-
List<OBJ> objectsFound = Arrays.stream(objs).filter(o-> this.searchTerm == null || new SimpleItem(this.getButton(o).getItemStack()).getDisplayName().toLowerCase().contains(this.searchTerm.toLowerCase())).collect(Collectors.toList());
39-
int index0 = this.page * maxItemsPerPage;
40-
int index1 = Math.min(index0 + maxItemsPerPage, objectsFound.size());
41-
List<GUIButton> buttons = objectsFound.subList(index0, index1).stream().map(this::getButton).collect(Collectors.toList());
37+
List<OBJ> objectsFound = new ArrayList<>();
38+
for (OBJ obj : objs) {
39+
if(obj != null){
40+
if(this.searchTerm == null){
41+
objectsFound.add(obj);
42+
}else{
43+
GUIButton button = this.getButton(obj);
44+
String name = ChatColor.stripColor(new SimpleItem(button.getItemStack()).getDisplayName()).toLowerCase();
45+
if(name.contains(ChatColor.stripColor(this.searchTerm.toLowerCase()))){
46+
objectsFound.add(obj);
47+
}
48+
}
49+
}
50+
}
51+
int index0 = this.page * this.maxItemsPerPage;
52+
int index1 = Math.min(index0 + this.maxItemsPerPage, objectsFound.size());
53+
int maxPages = (int)Math.round(Math.ceil((double)objectsFound.size() / (double)maxItemsPerPage));
54+
List<GUIButton> buttons1 = new ArrayList<>();
4255
int slot = 0;
43-
for(Iterator<GUIButton> it = buttons.iterator(); it.hasNext(); ++slot){
44-
it.next().setSlot(slot);
56+
for (GUIButton b : objectsFound.subList(index0, index1).stream().map(this::getButton).collect(Collectors.toList())) {
57+
b.setSlot(slot);
58+
buttons1.add(b);
59+
slot++;
4560
}
61+
List<GUIButton> buttons = new ArrayList<>(buttons1);
62+
buttons1.clear(); // Save memory
63+
objectsFound.clear(); // Save memory
4664

47-
int maxPages = (int)Math.round(Math.ceil((double)objectsFound.size() / (double)maxItemsPerPage));
4865
buttons.add(new GUIButton(49, this.searchTerm == null ? this.getPreloadedItems().getSearchItem() : this.getPreloadedItems().getEndSearchItem()).setAction(a -> {
4966
if(this.searchTerm == null){
5067
new Dialog(this.getPlayer()){
@@ -66,17 +83,16 @@ public String getActionbar() {
6683

6784
@Override
6885
public boolean onResult(String playerInput) {
69-
this.getSpigotTasks().runTask(()-> {
70-
BrowserGUI.this.searchTerm = playerInput;
71-
BrowserGUI.this.page = 0;
72-
BrowserGUI.this.open();
73-
});
86+
BrowserGUI.this.searchTerm = playerInput;
7487
return true;
7588
}
76-
};
89+
}.setRecall(player ->{
90+
this.page = 0;
91+
this.open();
92+
});
7793
}else{
78-
this.page = 0;
7994
this.searchTerm = null;
95+
this.page = 0;
8096
this.open();
8197
}
8298
}));
@@ -95,7 +111,9 @@ public boolean onResult(String playerInput) {
95111
}));
96112
}
97113

98-
return buttons.stream().filter(Utils::nonNull).toArray(GUIButton[]::new);
114+
GUIButton[] guiButtons = new GUIButton[buttons.size()];
115+
guiButtons = buttons.toArray(guiButtons);
116+
return guiButtons;
99117
}
100118

101119
/**

0 commit comments

Comments
 (0)