Skip to content

Commit c175af7

Browse files
committed
Port patches from 2.9
1 parent 355399b commit c175af7

4 files changed

Lines changed: 19 additions & 12 deletions

File tree

core/src/main/java/be/isach/ultracosmetics/command/subcommands/SubCommandToggle.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,18 +76,18 @@ private void toggle(CommandSender sender, Player targetPlayer, String type, Stri
7676
return;
7777
}
7878

79-
Object[] categories = Arrays.stream(Category.values()).filter(category -> category.isEnabled() && category.toString().toLowerCase().startsWith(type)).toArray();
80-
if (categories.length != 1) {
79+
Optional<Category> categories = Arrays.stream(Category.values()).filter(category -> category.isEnabled() && category.toString().toLowerCase().startsWith(type)).findFirst();
80+
if (!categories.isPresent()) {
8181
sender.sendMessage(MessageManager.getMessage("Prefix") + ERROR_PREFIX + "Invalid category.");
8282
return;
8383
}
84-
Category category = (Category) categories[0];
84+
Category category = categories.get();
8585
boolean suits = category == Category.SUITS;
8686
ArmorSlot slot = null;
8787
if (suits) {
8888
try {
8989
slot = ArmorSlot.getByName(cosm.split(":")[1].toUpperCase());
90-
} catch (IllegalArgumentException e) {
90+
} catch (ArrayIndexOutOfBoundsException | IllegalArgumentException e) {
9191
sender.sendMessage(MessageManager.getMessage("Prefix") + ERROR_PREFIX + "/uc toggle suit <suit type:suit piece> <player>.");
9292
return;
9393
}

core/src/main/java/be/isach/ultracosmetics/cosmetics/gadgets/GadgetPortalGun.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ private boolean portalTeleportCheck(PortalLoc portalLoc, PortalLoc dest) {
106106
}
107107

108108
// 'distanceSquared' is faster than 'distance', and sqrt(1) == 1 anyway
109-
if (playerLoc.distanceSquared(portalLoc.getLocation()) > 1) return false;
109+
if (playerLoc.getWorld() != getPlayer().getWorld() || playerLoc.distanceSquared(portalLoc.getLocation()) > 1) return false;
110110
teleported = true;
111111
Location loc = dest.getLocation().clone();
112112
BlockFace destFace = dest.getFace();

core/src/main/java/be/isach/ultracosmetics/player/profile/CosmeticsProfile.java

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
11
package be.isach.ultracosmetics.player.profile;
22

3-
import java.util.UUID;
4-
import java.util.Map.Entry;
5-
6-
import org.bukkit.Bukkit;
7-
83
import be.isach.ultracosmetics.UltraCosmetics;
94
import be.isach.ultracosmetics.UltraCosmeticsData;
105
import be.isach.ultracosmetics.config.SettingsManager;
@@ -17,24 +12,35 @@
1712
import be.isach.ultracosmetics.cosmetics.type.SuitType;
1813
import be.isach.ultracosmetics.player.UltraPlayer;
1914

15+
import org.bukkit.Bukkit;
16+
17+
import java.util.Map.Entry;
18+
import java.util.UUID;
19+
2020
public abstract class CosmeticsProfile {
2121
protected final UltraPlayer ultraPlayer;
2222
protected final UUID uuid;
2323
protected final UltraCosmetics ultraCosmetics;
2424
protected final PlayerData data;
25+
2526
public CosmeticsProfile(UltraPlayer ultraPlayer, UltraCosmetics ultraCosmetics) {
2627
this.ultraPlayer = ultraPlayer;
2728
this.uuid = ultraPlayer.getUUID();
2829
this.ultraCosmetics = ultraCosmetics;
2930
this.data = new PlayerData(uuid);
3031
Bukkit.getScheduler().runTaskAsynchronously(ultraCosmetics, () -> {
3132
load();
32-
if (!UltraCosmeticsData.get().areCosmeticsProfilesEnabled()) return;
33+
if (!shouldLoadCosmetics()) return;
3334
Bukkit.getScheduler().runTask(ultraCosmetics, () -> equip());
3435
});
3536
}
3637

38+
protected static boolean shouldLoadCosmetics() {
39+
return UltraCosmeticsData.get().areCosmeticsProfilesEnabled();
40+
}
41+
3742
protected abstract void load();
43+
3844
public abstract void save();
3945

4046
public void equip() {

core/src/main/java/be/isach/ultracosmetics/player/profile/PlayerData.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ public Map<ArmorSlot,SuitType> getEnabledSuitParts() {
9999
*/
100100
public void loadFromFile() {
101101
SettingsManager sm = SettingsManager.getData(uuid);
102-
if (sm.fileConfiguration.isConfigurationSection("enabled")) {
102+
if (UltraCosmeticsData.get().areCosmeticsProfilesEnabled() && sm.fileConfiguration.isConfigurationSection("enabled")) {
103103
cosmeticsFromFile(sm);
104104
}
105105

@@ -204,6 +204,7 @@ public void loadFromSQL() {
204204
ammo.put(type, (int) properties.get(Table.cleanCosmeticName(type)));
205205
}
206206
keys = (int) properties.get(ProfileKey.KEYS.getSqlKey());
207+
if (!UltraCosmeticsData.get().areCosmeticsProfilesEnabled()) return;
207208
for (Category cat : Category.enabled()) {
208209
if (cat == Category.SUITS) {
209210
for (ArmorSlot slot : ArmorSlot.values()) {

0 commit comments

Comments
 (0)