Skip to content

Commit 45d5674

Browse files
committed
Fixed skull meta inconsistencies error & clear trails button
1 parent 9c4ce8c commit 45d5674

10 files changed

Lines changed: 627 additions & 229 deletions

File tree

RPGHorsesPlugin/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
</properties>
1515

1616
<artifactId>RPGHorsesPlugin</artifactId>
17-
<version>1.2.22</version>
17+
<version>1.2.23</version>
1818

1919
<repositories>
2020
<repository>

RPGHorsesPlugin/src/main/java/org/plugins/rpghorses/RPGHorsesMain.java

Lines changed: 300 additions & 32 deletions
Large diffs are not rendered by default.

RPGHorsesPlugin/src/main/java/org/plugins/rpghorses/guis/instances/TrailsGUI.java

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,27 @@
1212
import org.plugins.rpghorses.horses.RPGHorse;
1313
import org.plugins.rpghorses.utils.ItemUtil;
1414

15+
import java.util.HashMap;
1516
import java.util.HashSet;
1617

1718
public class TrailsGUI {
1819

19-
private final RPGHorse rpgHorse;
20-
private final Inventory inventory;
20+
private final RPGHorse rpgHorse;
21+
private final Inventory inventory;
2122
private final HashSet<TrailGUIItem> trails, unknownTrails;
2223
@Getter
2324
private TrailGUIItem currentTrail;
2425

25-
public TrailsGUI(RPGHorse rpgHorse, Inventory inventory, HashSet<TrailGUIItem> trails, HashSet<TrailGUIItem> unknownTrails) {
26+
public TrailsGUI(RPGHorse rpgHorse, Inventory inventory, HashSet<TrailGUIItem> trails, HashSet<TrailGUIItem> unknownTrails, TrailGUIItem currentTrail) {
2627
this.rpgHorse = rpgHorse;
2728
this.inventory = inventory;
2829
this.trails = trails;
2930
this.unknownTrails = unknownTrails;
31+
this.currentTrail = currentTrail;
32+
33+
if (currentTrail != null) {
34+
ItemUtil.addDurabilityGlow(inventory.getItem(currentTrail.getSlot()));
35+
}
3036
}
3137

3238
public RPGHorse getRpgHorse() {
@@ -43,11 +49,11 @@ public boolean applyTrail(int slot) {
4349
if (trailGUIItem == null || unknownTrails.contains(trailGUIItem)) return false;
4450

4551
if (currentTrail != null) {
46-
currentTrail.getItem().removeEnchantment(Enchantment.DURABILITY);
52+
inventory.getItem(currentTrail.getSlot()).removeEnchantment(Enchantment.DURABILITY);
4753
}
4854

4955
currentTrail = trailGUIItem;
50-
ItemUtil.addDurabilityGlow(currentTrail.getItem());
56+
ItemUtil.addDurabilityGlow(inventory.getItem(currentTrail.getSlot()));
5157
String trailName = currentTrail.getTrailName();
5258

5359
if (RPGHorsesMain.getVersion().getWeight() < 9) {
@@ -60,19 +66,23 @@ public boolean applyTrail(int slot) {
6066
}
6167

6268
public boolean removeTrail() {
69+
boolean hadTrail = false;
70+
6371
if (currentTrail != null) {
6472
currentTrail.getItem().removeEnchantment(Enchantment.DURABILITY);
6573
}
6674

6775
currentTrail = null;
6876

6977
if (RPGHorsesMain.getVersion().getWeight() < 9) {
78+
hadTrail = ((LegacyHorseInfo) rpgHorse.getHorseInfo()).getEffect() != null;
7079
((LegacyHorseInfo) rpgHorse.getHorseInfo()).setEffect(null);
7180
} else {
81+
hadTrail = rpgHorse.getParticle() != null;
7282
rpgHorse.setParticle(null);
7383
}
7484

75-
return true;
85+
return hadTrail;
7686
}
7787

7888
public TrailGUIItem getTrailGUIItem(int slot) {

RPGHorsesPlugin/src/main/java/org/plugins/rpghorses/managers/gui/MarketGUIManager.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
import org.plugins.rpghorses.managers.HorseOwnerManager;
1818
import org.plugins.rpghorses.managers.SQLManager;
1919
import org.plugins.rpghorses.players.HorseOwner;
20-
import org.plugins.rpghorses.utils.SkinValueUtil;
20+
import org.plugins.rpghorses.utils.HorseSkins;
2121
import roryslibrary.configs.CustomConfig;
2222
import roryslibrary.util.DebugUtil;
2323
import org.plugins.rpghorses.utils.ItemUtil;
@@ -69,7 +69,7 @@ public int getBackSlot() {
6969

7070
public ItemStack getHorseItem(RPGHorse rpgHorse) {
7171
ItemStack item = horseItem.clone();
72-
return SkinValueUtil.applySkin(rpgHorse, item);
72+
return HorseSkins.applySkin(rpgHorse, item);
7373
}
7474

7575
public void setupMarketGUI() {

RPGHorsesPlugin/src/main/java/org/plugins/rpghorses/managers/gui/StableGUIManager.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@
1616
import org.plugins.rpghorses.managers.HorseOwnerManager;
1717
import org.plugins.rpghorses.managers.RPGHorseManager;
1818
import org.plugins.rpghorses.players.HorseOwner;
19+
import org.plugins.rpghorses.utils.HorseSkins;
1920
import org.plugins.rpghorses.utils.RPGMessagingUtil;
2021
import org.plugins.rpghorses.utils.ItemUtil;
21-
import org.plugins.rpghorses.utils.SkinValueUtil;
2222
import roryslibrary.util.MessagingUtil;
2323
import roryslibrary.util.TimeUtil;
2424

@@ -128,14 +128,14 @@ public ItemStack getHorseItem(RPGHorse rpgHorse) {
128128
ItemStack item;
129129
if (rpgHorse.isInMarket()) {
130130
item = marketHorseItem.clone();
131-
if (plugin.getConfig().isSet("stable-options.market-horse-item.skin-value")) {
131+
if (plugin.getConfig().isSet("stable-options.market-horse-item.skin-value") || plugin.getConfig().isSet("stable-options.market-horse-item.textures-url")) {
132132
return item;
133133
}
134134
} else {
135135
item = rpgHorse.isDead() ? this.deadHorseItem.clone() : this.aliveHorseItem.clone();
136136
}
137137

138-
return SkinValueUtil.applySkin(rpgHorse, item);
138+
return HorseSkins.applySkin(rpgHorse, item);
139139
}
140140

141141
public void setupStableGUI(HorseOwner horseOwner) {
Lines changed: 64 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package org.plugins.rpghorses.managers.gui;
22

33
import org.bukkit.Bukkit;
4+
import org.bukkit.Effect;
45
import org.bukkit.configuration.file.FileConfiguration;
56
import org.bukkit.entity.Player;
67
import org.bukkit.inventory.Inventory;
@@ -13,61 +14,68 @@
1314
import org.plugins.rpghorses.guis.TrailGUIItem;
1415
import org.plugins.rpghorses.guis.instances.HorseGUI;
1516
import org.plugins.rpghorses.guis.instances.TrailsGUI;
17+
import org.plugins.rpghorses.horseinfo.LegacyHorseInfo;
1618
import org.plugins.rpghorses.horses.RPGHorse;
1719
import org.plugins.rpghorses.managers.HorseOwnerManager;
1820
import org.plugins.rpghorses.managers.ParticleManager;
1921
import org.plugins.rpghorses.players.HorseOwner;
20-
import org.plugins.rpghorses.utils.RPGMessagingUtil;
2122
import org.plugins.rpghorses.utils.ItemUtil;
23+
import org.plugins.rpghorses.utils.RPGMessagingUtil;
24+
import org.plugins.rpghorses.version.Version;
2225

23-
import java.util.ArrayList;
24-
import java.util.HashSet;
25-
import java.util.List;
26+
import java.util.*;
2627

2728
public class TrailGUIManager {
28-
29+
2930
private final RPGHorsesMain plugin;
3031
private final ParticleManager particleManager;
3132
private final HorseOwnerManager horseOwnerManager;
32-
33+
3334
private ItemStack unknownTrailItem, trailItem, fillItem;
3435
private GUIItem clearTrailItem, backItem;
35-
private List<TrailGUIItem> validTrails = new ArrayList<>();
36+
private final LinkedHashMap<String, TrailGUIItem> validTrails = new LinkedHashMap<>();
3637
private int rows = 3;
37-
38+
3839
public TrailGUIManager(RPGHorsesMain plugin, ParticleManager particleManager, HorseOwnerManager horseOwnerManager) {
3940
this.plugin = plugin;
4041
this.particleManager = particleManager;
4142
this.horseOwnerManager = horseOwnerManager;
42-
43+
4344
reload();
4445
}
45-
46+
4647
public void reload() {
4748
validTrails.clear();
48-
49+
4950
FileConfiguration config = plugin.getConfig();
50-
51+
5152
String path = "trail-gui-options.";
52-
53+
5354
unknownTrailItem = ItemUtil.getItemStack(config, path + "unknown-trail");
5455
trailItem = ItemUtil.getItemStack(config, path + "trail-item");
5556
clearTrailItem = new GUIItem(ItemUtil.getItemStack(config, path + "clear-trail-item"), ItemPurpose.CLEAR_TRAIL, true, ItemUtil.getSlot(config, path + "clear-trail-item"));
5657
fillItem = ItemUtil.getItemStack(config, path + "fill-item");
5758
backItem = new GUIItem(ItemUtil.getItemStack(config, path + "back-item"), ItemPurpose.BACK, true, ItemUtil.getSlot(config, path + "back-item"));
58-
59+
5960
for (String trailName : config.getConfigurationSection(path + "trails").getKeys(false)) {
6061
if (particleManager.isValidParticle(trailName)) {
6162
ItemStack item = trailItem.clone();
6263
ItemMeta itemMeta = trailItem.getItemMeta();
63-
ItemMeta newMeta = ItemUtil.applyCustomHead(itemMeta.clone(), config.getString(path + "trails." + trailName));
64+
ItemMeta newMeta;
65+
66+
if (Version.getVersion().getWeight() >= Version.v1_20.getWeight()) {
67+
newMeta = ItemUtil.applyCustomHead(itemMeta.clone(), config.getString(path + "trails." + trailName + ".textures-url", ""), config.getString(path + "trails." + trailName + ".skin-value", ""));
68+
} else {
69+
newMeta = ItemUtil.applyCustomHead(itemMeta.clone(), config.getString(path + "trails." + trailName, ""));
70+
}
71+
6472
if (newMeta != null) {
6573
item.setItemMeta(newMeta);
6674
}
67-
validTrails.add(replacePlaceholders(new TrailGUIItem(item, ItemPurpose.TRAIL, true, -1, trailName)));
75+
validTrails.put(trailName, replacePlaceholders(new TrailGUIItem(item, ItemPurpose.TRAIL, true, -1, trailName)));
6876
}
6977
}
70-
78+
7179
int totalTrails = validTrails.size(), slot = 10, trailsLeft = totalTrails, row = 1;
7280
int skipSlot = -1;
7381
if (trailsLeft < 7) {
@@ -78,14 +86,14 @@ public void reload() {
7886
slot += ((7 - trailsLeft) / 2);
7987
}
8088
}
81-
82-
for (TrailGUIItem trailGUIItem : validTrails) {
89+
90+
for (TrailGUIItem trailGUIItem : validTrails.values()) {
8391
if (slot == skipSlot) {
8492
slot++;
8593
}
86-
94+
8795
trailGUIItem.setSlot(slot);
88-
96+
8997
trailsLeft--;
9098
if ((totalTrails - trailsLeft) % 7 == 0) {
9199
row++;
@@ -102,29 +110,30 @@ public void reload() {
102110
slot++;
103111
}
104112
}
105-
113+
106114
rows = row + 3;
107-
backItem.setSlot(((rows - 1) * 9) + 4);
108-
115+
backItem.setSlot(((rows - 1) * 9) + 3);
116+
clearTrailItem.setSlot(((rows - 1) * 9) + 5);
117+
109118
for (HorseOwner horseOwner : horseOwnerManager.getHorseOwners().values()) {
110119
if (horseOwner.getGUILocation() == GUILocation.TRAILS_GUI) {
111120
horseOwner.openTrailsGUI(setupTrailsGUI(horseOwner.getHorseGUI()));
112121
}
113122
}
114-
123+
115124
}
116-
125+
117126
public TrailsGUI setupTrailsGUI(HorseGUI horseGUI) {
118127
RPGHorse rpgHorse = horseGUI.getRpgHorse();
119128
Player p = rpgHorse.getHorseOwner().getPlayer();
120-
129+
121130
HashSet<TrailGUIItem> trails = new HashSet<>(), unknownTrails = new HashSet<>();
122-
131+
123132
Inventory inv = Bukkit.createInventory(p, rows * 9, RPGMessagingUtil.format(plugin.getConfig().getString("trail-gui-options.title")));
124133

125134
boolean perHorsePerms = plugin.getConfig().getBoolean("trails-options.per-horse-permissions", false);
126135
boolean hasStarPerm = perHorsePerms ? p.hasPermission("rpghorses.trail." + horseGUI.getRpgHorse().getIndex() + ".*") : p.hasPermission("rpghorses.trail.*");
127-
for (TrailGUIItem trailGUIItem : validTrails) {
136+
for (TrailGUIItem trailGUIItem : validTrails.values()) {
128137
ItemStack item;
129138
if (hasStarPerm || (perHorsePerms && p.hasPermission("rpghorses.trail." + horseGUI.getRpgHorse().getIndex() + "." + trailGUIItem.getTrailName().toLowerCase())) || (!perHorsePerms && p.hasPermission("rpghorses.trail." + trailGUIItem.getTrailName().toLowerCase()))) {
130139
trails.add(trailGUIItem);
@@ -133,53 +142,67 @@ public TrailsGUI setupTrailsGUI(HorseGUI horseGUI) {
133142
unknownTrails.add(trailGUIItem);
134143
item = unknownTrailItem;
135144
}
136-
inv.setItem(trailGUIItem.getSlot(), item);
145+
inv.setItem(trailGUIItem.getSlot(), item.clone());
137146
}
138-
147+
139148
inv.setItem(backItem.getSlot(), backItem.getItem());
140149
inv.setItem(clearTrailItem.getSlot(), clearTrailItem.getItem());
141-
150+
142151
for (int i = 0; i < inv.getSize(); i++) {
143152
if (inv.getItem(i) == null) {
144153
inv.setItem(i, fillItem);
145154
}
146155
}
147-
148-
return new TrailsGUI(rpgHorse, inv, trails, unknownTrails);
156+
157+
TrailGUIItem currentTrail = null;
158+
159+
if (RPGHorsesMain.getVersion().getWeight() < 9) {
160+
Effect effect = ((LegacyHorseInfo) rpgHorse.getHorseInfo()).getEffect();
161+
if (effect != null) {
162+
currentTrail = validTrails.get(effect.name());
163+
}
164+
} else {
165+
String particleName = rpgHorse.getParticle() == null ? null : rpgHorse.getParticle().name();
166+
if (particleName != null) {
167+
currentTrail = validTrails.get(particleName);
168+
}
169+
}
170+
171+
return new TrailsGUI(rpgHorse, inv, trails, unknownTrails, currentTrail);
149172
}
150-
173+
151174
public TrailGUIItem replacePlaceholders(TrailGUIItem trailGUIItem) {
152175
String name = "";
153176
for (String word : trailGUIItem.getTrailName().toLowerCase().replace("_", " ").split("\\s")) {
154177
name += word.substring(0, 1).toUpperCase() + word.substring(1) + " ";
155178
}
156179
name = name.trim();
157-
180+
158181
ItemMeta itemMeta = trailGUIItem.getItem().getItemMeta();
159-
182+
160183
if (itemMeta.hasDisplayName()) {
161184
itemMeta.setDisplayName(itemMeta.getDisplayName().replace("{TRAIL}", name));
162185
}
163-
186+
164187
if (itemMeta.hasLore()) {
165188
List<String> lore = new ArrayList<>();
166189
for (String line : itemMeta.getLore()) {
167190
lore.add(line.replace("{TRAIL}", name));
168191
}
169192
itemMeta.setLore(lore);
170193
}
171-
194+
172195
trailGUIItem.getItem().setItemMeta(itemMeta);
173196
return trailGUIItem;
174197
}
175-
198+
176199
public ItemPurpose getItemPurpose(int slot, TrailsGUI trailsGUI) {
177200
if (slot == backItem.getSlot()) {
178201
return ItemPurpose.BACK;
179202
} else if (slot == clearTrailItem.getSlot()) {
180203
return ItemPurpose.CLEAR_TRAIL;
181204
}
182-
205+
183206
return trailsGUI.getItemPurpose(slot);
184207
}
185208
}

0 commit comments

Comments
 (0)