Skip to content

Commit e22c3ea

Browse files
committed
Made GUIComponent width measurement account for custom spaces
1 parent 876e37e commit e22c3ea

File tree

5 files changed

+17
-9
lines changed

5 files changed

+17
-9
lines changed

pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>com.sentropic.guiapi</groupId>
88
<artifactId>GUI_API</artifactId>
9-
<version>1.1.1</version>
9+
<version>1.2</version>
1010
<packaging>jar</packaging>
1111

1212
<name>GUI API</name>
@@ -70,7 +70,7 @@
7070
<dependency>
7171
<groupId>org.spigotmc</groupId>
7272
<artifactId>spigot-api</artifactId>
73-
<version>1.16.1-R0.1-SNAPSHOT</version>
73+
<version>1.16.5-R0.1-SNAPSHOT</version>
7474
<scope>provided</scope>
7575
</dependency>
7676
<dependency>

src/main/java/com/sentropic/guiapi/GUIManager.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import org.bukkit.Bukkit;
55
import org.bukkit.entity.Player;
66
import org.bukkit.event.EventHandler;
7+
import org.bukkit.event.EventPriority;
78
import org.bukkit.event.Listener;
89
import org.bukkit.event.player.PlayerJoinEvent;
910
import org.bukkit.event.player.PlayerQuitEvent;
@@ -59,14 +60,14 @@ public GUI getGUI(Player player) {
5960
}
6061
}
6162

62-
@EventHandler
63+
@EventHandler(priority = EventPriority.LOWEST)
6364
public void onPlayerLeave(PlayerQuitEvent event) {
6465
Player player = event.getPlayer();
6566
GUIS.remove(this.getGUI(player));
6667
player.removeMetadata(METADATA_KEY, GUIAPI.getPlugin());
6768
}
6869

69-
@EventHandler
70+
@EventHandler(priority = EventPriority.LOWEST)
7071
public void onPlayerJoin(PlayerJoinEvent event) {
7172
createGUI(event.getPlayer());
7273
}

src/main/java/com/sentropic/guiapi/gui/Font.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,13 @@ public class Font {
5151
DEFAULT.registerWidth('@', 7);
5252
DEFAULT.registerWidth('~', 7);
5353

54+
for (Map.Entry<Integer,String> entry : GUI.POS_SPACES.entrySet()) {
55+
DEFAULT.registerWidth(entry.getValue().charAt(0), entry.getKey());
56+
}
57+
for (Map.Entry<Integer,String> entry : GUI.NEG_SPACES.entrySet()) {
58+
DEFAULT.registerWidth(entry.getValue().charAt(0), -entry.getKey());
59+
}
60+
5461
register(DEFAULT);
5562
}
5663

src/main/java/com/sentropic/guiapi/gui/GUI.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public class GUI {
2424
private static final GUIComponent defaultComponent =
2525
new GUIComponent(ID_DEFAULT, new TextComponent(), 0, Alignment.LEFT, false);
2626

27-
private static final Map<Integer,String> POS_SPACES = new HashMap<Integer,String>() {{
27+
static final Map<Integer,String> POS_SPACES = Collections.unmodifiableMap(new HashMap<Integer,String>() {{
2828
put(1024, "\uF82F");
2929
put(512, "\uF82E");
3030
put(256, "\uF82D");
@@ -40,8 +40,8 @@ public class GUI {
4040
put(3, "\uF823");
4141
put(2, "\uF822");
4242
put(1, "\uF821");
43-
}};
44-
private static final Map<Integer,String> NEG_SPACES = new HashMap<Integer,String>() {{
43+
}});
44+
static final Map<Integer,String> NEG_SPACES = Collections.unmodifiableMap(new HashMap<Integer,String>() {{
4545
put(1, "\uF801");
4646
put(2, "\uF802");
4747
put(3, "\uF803");
@@ -57,7 +57,7 @@ public class GUI {
5757
put(256, "\uF80D");
5858
put(512, "\uF80E");
5959
put(1024, "\uF80F");
60-
}};
60+
}});
6161

6262
// API code
6363

src/main/resources/plugin.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: GUIAPI
2-
version: 1.1.1
2+
version: 1.2
33
main: com.sentropic.guiapi.GUIAPI
44
api-version: 1.16
55
softdepend: [ProtocolLib]

0 commit comments

Comments
 (0)