This commit is contained in:
Alexander Söderberg 2020-07-04 18:53:03 +02:00
parent e3759d059a
commit c784c69eb3
No known key found for this signature in database
GPG Key ID: C0207FF7EA146678
11 changed files with 137 additions and 10 deletions

View File

@ -35,6 +35,7 @@ dependencies {
implementation("net.luckperms:api:5.1") implementation("net.luckperms:api:5.1")
implementation("net.ess3:EssentialsX:2.17.2") implementation("net.ess3:EssentialsX:2.17.2")
implementation("net.alpenblock:BungeePerms:4.0-dev-106") implementation("net.alpenblock:BungeePerms:4.0-dev-106")
implementation("net.kyori:adventure-text-platform-bukkit:4.0.0-SNAPSHOT")
compile("se.hyperver.hyperverse:Core:0.6.0-SNAPSHOT"){ transitive = false } compile("se.hyperver.hyperverse:Core:0.6.0-SNAPSHOT"){ transitive = false }
compile('com.sk89q:squirrelid:1.0.0-SNAPSHOT'){ transitive = false } compile('com.sk89q:squirrelid:1.0.0-SNAPSHOT'){ transitive = false }
} }
@ -91,7 +92,7 @@ shadowJar {
dependencies { dependencies {
include(dependency(":PlotSquared-Core")) include(dependency(":PlotSquared-Core"))
include(dependency("io.papermc:paperlib:1.0.2")) include(dependency("io.papermc:paperlib:1.0.2"))
include(dependency("net.kyori:text-adapter-bukkit:3.0.3")) include(dependency("net.kyori:adventure-text-platform-bukkit:4.0.0-SNAPSHOT"))
include(dependency("org.bstats:bstats-bukkit:1.7")) include(dependency("org.bstats:bstats-bukkit:1.7"))
include(dependency("org.khelekore:prtree:1.7.0-SNAPSHOT")) include(dependency("org.khelekore:prtree:1.7.0-SNAPSHOT"))
include(dependency("com.sk89q:squirrelid:1.0.0-SNAPSHOT")) include(dependency("com.sk89q:squirrelid:1.0.0-SNAPSHOT"))

View File

@ -28,8 +28,10 @@ package com.plotsquared.bukkit.player;
import com.google.common.base.Charsets; import com.google.common.base.Charsets;
import com.plotsquared.bukkit.util.BukkitUtil; import com.plotsquared.bukkit.util.BukkitUtil;
import com.plotsquared.core.PlotSquared; import com.plotsquared.core.PlotSquared;
import com.plotsquared.core.configuration.Caption;
import com.plotsquared.core.configuration.Captions; import com.plotsquared.core.configuration.Captions;
import com.plotsquared.core.configuration.Settings; import com.plotsquared.core.configuration.Settings;
import com.plotsquared.core.configuration.caption.VariableReplacement;
import com.plotsquared.core.events.TeleportCause; import com.plotsquared.core.events.TeleportCause;
import com.plotsquared.core.location.Location; import com.plotsquared.core.location.Location;
import com.plotsquared.core.player.PlotPlayer; import com.plotsquared.core.player.PlotPlayer;
@ -225,7 +227,12 @@ public class BukkitPlayer extends PlotPlayer<Player> {
return this.player.isPermissionSet(permission); return this.player.isPermissionSet(permission);
} }
@Override public void sendMessage(String message) { @Override public void sendMessage(@NotNull final Caption caption,
@NotNull final VariableReplacement... replacements) {
}
@Deprecated @Override public void sendMessage(String message) {
message = message.replace('\u2010', '%').replace('\u2020', '&').replace('\u2030', '&'); message = message.replace('\u2010', '%').replace('\u2020', '&').replace('\u2030', '&');
if (!StringMan.isEqual(this.getMeta("lastMessage"), message) || ( if (!StringMan.isEqual(this.getMeta("lastMessage"), message) || (
System.currentTimeMillis() - this.<Long>getMeta("lastMessageTime") > 5000)) { System.currentTimeMillis() - this.<Long>getMeta("lastMessageTime") > 5000)) {

View File

@ -18,6 +18,9 @@ dependencies {
implementation("org.jetbrains.kotlin:kotlin-stdlib:1.3.72") implementation("org.jetbrains.kotlin:kotlin-stdlib:1.3.72")
implementation("org.jetbrains:annotations:19.0.0") implementation("org.jetbrains:annotations:19.0.0")
implementation("org.khelekore:prtree:1.7.0-SNAPSHOT") implementation("org.khelekore:prtree:1.7.0-SNAPSHOT")
// Adventure related stuff
implementation('net.kyori:adventure-api:4.0.0-SNAPSHOT')
implementation('net.kyori:adventure-text-minimessage:3.0.0-SNAPSHOT')
} }
sourceCompatibility = 1.8 sourceCompatibility = 1.8
@ -71,11 +74,12 @@ task copyFiles {
shadowJar { shadowJar {
dependencies { dependencies {
include(dependency("net.kyori:text-api:3.0.2")) include(dependency('net.kyori:adventure-api:4.0.0-SNAPSHOT'))
include(dependency("net.kyori:text-serializer-gson:3.0.2")) include(dependency('net.kyori:adventure-gson:4.0.0-SNAPSHOT'))
include(dependency("net.kyori:text-serializer-legacy:3.0.2")) include(dependency('net.kyori:adventure-legacy:4.0.0-SNAPSHOT'))
include(dependency("net.kyori:text-serializer-plain:3.0.2")) include(dependency('net.kyori:adventure-plain:4.0.0-SNAPSHOT'))
include(dependency("org.khelekore:prtree:1.7.0-SNAPSHOT")) include(dependency('net.kyori:adventure-text-minimessage:3.0.0-SNAPSHOT'))
include(dependency('org.khelekore:prtree:1.7.0-SNAPSHOT'))
} }
relocate('net.kyori.text', 'com.plotsquared.formatting.text') relocate('net.kyori.text', 'com.plotsquared.formatting.text')
relocate("org.json", "com.plotsquared.json") { relocate("org.json", "com.plotsquared.json") {

View File

@ -25,14 +25,27 @@
*/ */
package com.plotsquared.core.command; package com.plotsquared.core.command;
import com.plotsquared.core.configuration.Caption;
import com.plotsquared.core.configuration.caption.VariableReplacement;
import org.jetbrains.annotations.NotNull;
public interface CommandCaller { public interface CommandCaller {
/** /**
* Send the player a message. * Send the player a message.
* *
* @param message the message to send * @param message the message to send
* @deprecated Use static captions instead
*/ */
void sendMessage(String message); @Deprecated void sendMessage(String message);
/**
* Send a message to the command caller
*
* @param caption Caption to send
* @param replacements Variable replacements
*/
void sendMessage(@NotNull Caption caption, @NotNull VariableReplacement... replacements);
/** /**
* Check the player's permissions. <i>Will be cached if permission caching is enabled.</i> * Check the player's permissions. <i>Will be cached if permission caching is enabled.</i>

View File

@ -33,7 +33,7 @@ public interface Caption {
String getTranslated(); String getTranslated();
default String formatted() { @Deprecated default String formatted() {
return StringMan.replaceFromMap(getTranslated(), Captions.replacements); return StringMan.replaceFromMap(getTranslated(), Captions.replacements);
} }

View File

@ -25,7 +25,9 @@
*/ */
package com.plotsquared.core.configuration; package com.plotsquared.core.configuration;
import com.google.common.base.Preconditions;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import org.jetbrains.annotations.NotNull;
@RequiredArgsConstructor @RequiredArgsConstructor
public final class StaticCaption implements Caption { public final class StaticCaption implements Caption {
@ -33,10 +35,23 @@ public final class StaticCaption implements Caption {
private final String value; private final String value;
private final boolean usePrefix; private final boolean usePrefix;
public StaticCaption(final String value) { /**
* @deprecated Use {@link #of(String)}
*/
@Deprecated public StaticCaption(final String value) {
this(value, true); this(value, true);
} }
/**
* Create a new static caption from the given text
*
* @param text Text
* @return Created caption
*/
@NotNull public static StaticCaption of(@NotNull final String text) {
return new StaticCaption(Preconditions.checkNotNull(text, "Text may not be null"));
}
@Override public String getTranslated() { @Override public String getTranslated() {
return this.value; return this.value;
} }

View File

@ -45,6 +45,7 @@ import java.util.stream.Collectors;
import java.util.stream.Stream; import java.util.stream.Stream;
public final class CaptionLoader { public final class CaptionLoader {
private static final Gson GSON = new GsonBuilder().create(); private static final Gson GSON = new GsonBuilder().create();
private static final Pattern FILE_NAME_PATTERN = Pattern.compile("messages_(.*)\\.json"); private static final Pattern FILE_NAME_PATTERN = Pattern.compile("messages_(.*)\\.json");
@ -82,4 +83,5 @@ public final class CaptionLoader {
} }
return new LocalizedCaptionMap(locale, captions); return new LocalizedCaptionMap(locale, captions);
} }
} }

View File

@ -31,6 +31,7 @@ import java.util.Locale;
import java.util.Map; import java.util.Map;
public class LocalizedCaptionMap implements CaptionMap { public class LocalizedCaptionMap implements CaptionMap {
private final Locale locale; private final Locale locale;
private final Map<TranslatableCaption, String> captions; private final Map<TranslatableCaption, String> captions;
@ -54,4 +55,5 @@ public class LocalizedCaptionMap implements CaptionMap {
@Override public Locale getLocale() { @Override public Locale getLocale() {
return this.locale; return this.locale;
} }
} }

View File

@ -32,6 +32,7 @@ import java.util.Locale;
import java.util.Map; import java.util.Map;
public class PerUserLocaleCaptionMap extends LocalizedCaptionMap { public class PerUserLocaleCaptionMap extends LocalizedCaptionMap {
private final Map<Locale, CaptionMap> localeMap; private final Map<Locale, CaptionMap> localeMap;
public PerUserLocaleCaptionMap(Map<Locale, CaptionMap> localeMap) { public PerUserLocaleCaptionMap(Map<Locale, CaptionMap> localeMap) {

View File

@ -25,10 +25,12 @@
*/ */
package com.plotsquared.core.configuration.caption; package com.plotsquared.core.configuration.caption;
import com.plotsquared.core.PlotSquared;
import com.plotsquared.core.configuration.Caption; import com.plotsquared.core.configuration.Caption;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
public final class TranslatableCaption implements Caption { public final class TranslatableCaption implements Caption {
@NotNull private final String key; @NotNull private final String key;
private TranslatableCaption(@NotNull String key) { private TranslatableCaption(@NotNull String key) {
@ -50,4 +52,5 @@ public final class TranslatableCaption implements Caption {
@NotNull public String getKey() { @NotNull public String getKey() {
return this.key; return this.key;
} }
} }

View File

@ -0,0 +1,79 @@
/*
* _____ _ _ _____ _
* | __ \| | | | / ____| | |
* | |__) | | ___ | |_| (___ __ _ _ _ __ _ _ __ ___ __| |
* | ___/| |/ _ \| __|\___ \ / _` | | | |/ _` | '__/ _ \/ _` |
* | | | | (_) | |_ ____) | (_| | |_| | (_| | | | __/ (_| |
* |_| |_|\___/ \__|_____/ \__, |\__,_|\__,_|_| \___|\__,_|
* | |
* |_|
* PlotSquared plot management system for Minecraft
* Copyright (C) 2020 IntellectualSites
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.plotsquared.core.configuration.caption;
import lombok.EqualsAndHashCode;
import lombok.ToString;
import org.jetbrains.annotations.NotNull;
import java.util.Objects;
/**
* Key-value pair used as replacement of variables in {@link com.plotsquared.core.configuration.Caption captions}
*/
@ToString
@EqualsAndHashCode
public final class VariableReplacement {
private final String key;
private final String value;
private VariableReplacement(@NotNull final String key, @NotNull final String value) {
this.key = Objects.requireNonNull(key, "Key may not be null");
this.value = Objects.requireNonNull(value, "Value may not be null");
}
/**
* Create a new variable replacement from a key-value pair
*
* @param key Replacement key
* @param value Replacement value
* @return Replacement instance
*/
@NotNull public static VariableReplacement keyed(@NotNull final String key,
@NotNull final String value) {
return new VariableReplacement(key, value);
}
/**
* Get the replacement key
*
* @return Replacement key
*/
@NotNull public String getKey() {
return this.key;
}
/**
* Get the replacement value
*
* @return Replacement value
*/
@NotNull public String getValue() {
return this.value;
}
}