Skip to content

Commit

Permalink
fix: Fixed legacy chars replacement in LegacyUtils
Browse files Browse the repository at this point in the history
  • Loading branch information
4drian3d committed Jul 17, 2023
1 parent ab3316b commit c7845ce
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 23 deletions.
Expand Up @@ -147,7 +147,7 @@ static final class Builder implements Expansion.Builder {
nonNullOrEmptyString(key, "Placeholder key");
requireNonNull(audiencePlaceholder, "the audience placeholder cannot be null");

if (this.audiencePlaceholders == null) this.audiencePlaceholders = new HashSet<>(5);
if (this.audiencePlaceholders == null) this.audiencePlaceholders = new HashSet<>();

this.audiencePlaceholders.add(Tags.single(expansionName+key, audiencePlaceholder));
return this;
Expand All @@ -158,7 +158,7 @@ static final class Builder implements Expansion.Builder {
nonNullOrEmptyString(key, "Placeholder key");
requireNonNull(relationalPlaceholder, "the relational placeholder cannot be null");

if (this.relationalPlaceholders == null) this.relationalPlaceholders = new HashSet<>(4);
if (this.relationalPlaceholders == null) this.relationalPlaceholders = new HashSet<>();

this.relationalPlaceholders.add(Tags.relational(expansionName+"rel_"+key, relationalPlaceholder));
return this;
Expand All @@ -169,7 +169,7 @@ static final class Builder implements Expansion.Builder {
nonNullOrEmptyString(key, "Placeholder key");
requireNonNull(function, "the global placeholder cannot be null");

if(this.globalPlaceholders == null) this.globalPlaceholders = TagResolver.builder();
if (this.globalPlaceholders == null) this.globalPlaceholders = TagResolver.builder();

this.globalPlaceholders.tag(expansionName+key, function);
return this;
Expand All @@ -180,7 +180,7 @@ static final class Builder implements Expansion.Builder {
nonNullOrEmptyString(key, "Placeholder key");
requireNonNull(tag, "the tag cannot be null");

if(this.globalPlaceholders == null) this.globalPlaceholders = TagResolver.builder();
if (this.globalPlaceholders == null) this.globalPlaceholders = TagResolver.builder();

this.globalPlaceholders.tag(expansionName+key, tag);
return this;
Expand Down Expand Up @@ -212,10 +212,11 @@ static final class Builder implements Expansion.Builder {
}

@Override
public boolean equals(Object o){
if (this==o) return true;
if (o == null || o.getClass() != ExpansionImpl.class) return false;
return ((ExpansionImpl)o).name.equals(this.name);
public boolean equals(final Object o) {
if (this == o) return true;
if (!(o instanceof Expansion that)) return false;

return that.name().equalsIgnoreCase(this.name());
}

@Override
Expand Down
@@ -1,17 +1,16 @@
package io.github.miniplaceholders.api;

import java.util.Objects;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;

import io.github.miniplaceholders.api.enums.Platform;
import org.jetbrains.annotations.NotNull;

import io.github.miniplaceholders.connect.InternalPlatform;
import net.kyori.adventure.audience.Audience;
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.Objects;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;

import static io.github.miniplaceholders.api.utils.Resolvers.applyIfNotEmpty;
import static java.util.Objects.requireNonNull;

Expand Down
Expand Up @@ -25,20 +25,22 @@ private LegacyUtils() {
.build();

/**
* Parse a string with possible legacy symbols
* Parse a string with possible legacy Ampersand/Section symbols
*
* @param string the string
* @return a parsed string
* @since 1.0.0
*/
public static @NotNull Component parsePossibleLegacy(@Nullable String string) {
if (string == null || string.isBlank()) return Component.empty();
if (string.indexOf('&') != 0) {
return miniMessage().deserialize(
miniMessage().serialize(LEGACY_HEX_SERIALIZER.deserialize(string))
);
} else {
if (string == null || string.isEmpty()) return Component.empty();
if (string.indexOf(LegacyComponentSerializer.SECTION_CHAR) != -1) {
string = string.replace(LegacyComponentSerializer.SECTION_CHAR, LegacyComponentSerializer.AMPERSAND_CHAR);
}
if (string.indexOf(LegacyComponentSerializer.AMPERSAND_CHAR) == -1) {
return miniMessage().deserialize(string);
}
return miniMessage().deserialize(
miniMessage().serialize(LEGACY_HEX_SERIALIZER.deserialize(string))
);
}
}
6 changes: 4 additions & 2 deletions api/src/main/java/module-info.java
@@ -1,11 +1,13 @@
/** MiniPlaceholders API Module */
open module io.github.miniplaceholders.api {
requires io.github.miniplaceholders.connect;

requires net.kyori.adventure;
requires net.kyori.adventure.text.minimessage;
requires net.kyori.adventure.text.serializer.legacy;
requires net.kyori.examination.api;

requires static org.jetbrains.annotations;
requires io.github.miniplaceholders.connect;
requires net.kyori.adventure.text.serializer.legacy;

exports io.github.miniplaceholders.api;
exports io.github.miniplaceholders.api.enums;
Expand Down

0 comments on commit c7845ce

Please sign in to comment.