Skip to content

Commit c117648

Browse files
committed
TextComponent.fromLegacy cmopatibility
1 parent b9d3a24 commit c117648

File tree

8 files changed

+25
-10
lines changed

8 files changed

+25
-10
lines changed

core/src/main/java/com/cryptomorin/xseries/base/XRegistry.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,10 @@
2626
import com.cryptomorin.xseries.base.annotations.XInfo;
2727
import com.cryptomorin.xseries.base.annotations.XMerge;
2828
import com.cryptomorin.xseries.particles.XParticle;
29-
import com.google.common.base.Preconditions;
3029
import org.bukkit.Keyed;
3130
import org.bukkit.NamespacedKey;
3231
import org.bukkit.Registry;
3332
import org.bukkit.enchantments.Enchantment;
34-
import org.bukkit.plugin.Plugin;
3533
import org.bukkit.potion.PotionEffectType;
3634
import org.jetbrains.annotations.ApiStatus;
3735
import org.jetbrains.annotations.NotNull;

core/src/main/java/com/cryptomorin/xseries/messages/ActionBar.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ public static void sendActionBar(@NotNull Plugin plugin, @NotNull Player player,
180180
} catch (NumberFormatException ignored) {
181181
}
182182
if (time >= 0)
183-
sendActionBar(plugin, player, TextComponent.fromLegacy(message.substring(end + 1)), time);
183+
sendActionBar(plugin, player, MessageComponents.fromLegacy(message.substring(end + 1)), time);
184184
}
185185
}
186186

core/src/main/java/com/cryptomorin/xseries/messages/MessageComponents.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,12 @@
2626
import com.cryptomorin.xseries.reflection.minecraft.MinecraftClassHandle;
2727
import com.cryptomorin.xseries.reflection.minecraft.MinecraftPackage;
2828
import net.md_5.bungee.api.chat.BaseComponent;
29+
import net.md_5.bungee.api.chat.TextComponent;
2930
import net.md_5.bungee.chat.ComponentSerializer;
3031
import org.jetbrains.annotations.ApiStatus;
3132

3233
import java.lang.invoke.MethodHandle;
34+
import java.util.regex.Pattern;
3335

3436
import static com.cryptomorin.xseries.reflection.XReflection.ofMinecraft;
3537

@@ -53,7 +55,7 @@ public final class MessageComponents {
5355
.method("public static IChatBaseComponent fromJSON(String jsonMessage)").returns(IChatBaseComponentClass)
5456
.reflect();
5557
} catch (Throwable ex) {
56-
throw new IllegalStateException(ex);
58+
fromJson = null;
5759
}
5860

5961
CraftChatMessage_fromJson = fromJson;
@@ -66,4 +68,11 @@ public static Object bungeeToVanilla(BaseComponent component) throws Throwable {
6668
String json = ComponentSerializer.toString(component);
6769
return CraftChatMessage_fromJson.invoke(json);
6870
}
71+
72+
private static final Pattern url = Pattern.compile("^(?:(https?)://)?([-\\w_.]{2,}\\.[a-z]{2,4})(/\\S*)?$");
73+
74+
@SuppressWarnings("deprecation")
75+
public static BaseComponent fromLegacy(String message) {
76+
return new TextComponent(TextComponent.fromLegacyText(message));
77+
}
6978
}

core/src/main/java/com/cryptomorin/xseries/messages/Titles.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
import com.cryptomorin.xseries.reflection.minecraft.MinecraftConnection;
2727
import com.cryptomorin.xseries.reflection.minecraft.MinecraftPackage;
2828
import net.md_5.bungee.api.chat.BaseComponent;
29-
import net.md_5.bungee.api.chat.TextComponent;
3029
import org.bukkit.configuration.ConfigurationSection;
3130
import org.bukkit.entity.Player;
3231
import org.jetbrains.annotations.NotNull;
@@ -185,7 +184,7 @@ public Titles(BaseComponent title, BaseComponent subtitle, int fadeIn, int stay,
185184
}
186185

187186
public Titles(String title, String subtitle, int fadeIn, int stay, int fadeOut) {
188-
this(TextComponent.fromLegacy(title), TextComponent.fromLegacy(subtitle), fadeIn, stay, fadeOut);
187+
this(MessageComponents.fromLegacy(title), MessageComponents.fromLegacy(subtitle), fadeIn, stay, fadeOut);
189188
}
190189

191190
public Titles copy() {
@@ -211,7 +210,7 @@ public void send(Player player) {
211210
public static void sendTitle(@NotNull Player player,
212211
int fadeIn, int stay, int fadeOut,
213212
@Nullable String title, @Nullable String subtitle) {
214-
sendTitle(player, fadeIn, stay, fadeOut, TextComponent.fromLegacy(title), TextComponent.fromLegacy(subtitle));
213+
sendTitle(player, fadeIn, stay, fadeOut, MessageComponents.fromLegacy(title), MessageComponents.fromLegacy(subtitle));
215214
}
216215

217216
public static void sendTitle(@NotNull Player player,
@@ -341,12 +340,12 @@ public BaseComponent getSubtitle() {
341340

342341
@Deprecated
343342
public void setTitle(String title) {
344-
this.title = TextComponent.fromLegacy(title);
343+
this.title = MessageComponents.fromLegacy(title);
345344
}
346345

347346
@Deprecated
348347
public void setSubtitle(String subtitle) {
349-
this.subtitle = TextComponent.fromLegacy(subtitle);
348+
this.subtitle = MessageComponents.fromLegacy(subtitle);
350349
}
351350

352351
public void setTitle(BaseComponent title) {

core/src/main/java/com/cryptomorin/xseries/profiles/lock/KeyedLock.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,12 @@
2222

2323
package com.cryptomorin.xseries.profiles.lock;
2424

25+
import org.jetbrains.annotations.ApiStatus;
26+
2527
import java.util.concurrent.locks.Lock;
2628
import java.util.concurrent.locks.ReentrantLock;
2729

30+
@ApiStatus.Internal
2831
public final class KeyedLock<K> implements AutoCloseable {
2932
private final KeyedLockMap<K> map;
3033
protected final K key;

core/src/main/java/com/cryptomorin/xseries/profiles/lock/KeyedLockMap.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,12 @@
2222

2323
package com.cryptomorin.xseries.profiles.lock;
2424

25+
import org.jetbrains.annotations.ApiStatus;
26+
2527
import java.util.HashMap;
2628
import java.util.Map;
2729

30+
@ApiStatus.Internal
2831
public final class KeyedLockMap<K> {
2932
private final Map<K, KeyedLock<K>> locks = new HashMap<>();
3033

core/src/main/java/com/cryptomorin/xseries/profiles/lock/MojangRequestQueue.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,11 @@
2222

2323
package com.cryptomorin.xseries.profiles.lock;
2424

25+
import org.jetbrains.annotations.ApiStatus;
26+
2527
import java.util.UUID;
2628

29+
@ApiStatus.Internal
2730
public final class MojangRequestQueue {
2831
public static final KeyedLockMap<String> USERNAME_REQUESTS = new KeyedLockMap<>();
2932
public static final KeyedLockMap<UUID> UUID_REQUESTS = new KeyedLockMap<>();

core/src/test/com/cryptomorin/xseries/test/XSeriesTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,6 @@ private static void testXMaterial() {
317317
assertSame(XMaterial.matchXMaterial("CLAY_BRICK"), XMaterial.BRICK);
318318
assertMaterial("MELON", "MELON");
319319

320-
assertNotNull(XMaterial.ACACIA_SIGN.parseItem(), "Acacia Sign is null");
321320
assertMaterial("COMMAND_BLOCK", XMaterial.COMMAND_BLOCK);
322321
assertMaterial("STEP:1", XMaterial.SANDSTONE_SLAB);
323322
assertMaterial("WOOD_BUTTON", XMaterial.OAK_BUTTON);
@@ -329,6 +328,7 @@ private static void testXMaterial() {
329328
assertMaterial("INK_SACK:4", XMaterial.LAPIS_LAZULI);
330329

331330
if (XMaterial.supports(14)) {
331+
assertNotNull(XMaterial.ACACIA_SIGN.parseItem(), "Acacia Sign is null");
332332
assertMaterial(XMaterial.RED_DYE, Material.RED_DYE);
333333
assertMaterial(XMaterial.GREEN_DYE, Material.GREEN_DYE);
334334
assertMaterial(XMaterial.BLACK_DYE, Material.BLACK_DYE);

0 commit comments

Comments
 (0)