mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2025-06-25 10:14:42 +02:00
progress
This commit is contained in:
@ -25,14 +25,27 @@
|
||||
*/
|
||||
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 {
|
||||
|
||||
/**
|
||||
* Send the player a message.
|
||||
*
|
||||
* @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>
|
||||
|
@ -33,7 +33,7 @@ public interface Caption {
|
||||
|
||||
String getTranslated();
|
||||
|
||||
default String formatted() {
|
||||
@Deprecated default String formatted() {
|
||||
return StringMan.replaceFromMap(getTranslated(), Captions.replacements);
|
||||
}
|
||||
|
||||
|
@ -25,7 +25,9 @@
|
||||
*/
|
||||
package com.plotsquared.core.configuration;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@RequiredArgsConstructor
|
||||
public final class StaticCaption implements Caption {
|
||||
@ -33,10 +35,23 @@ public final class StaticCaption implements Caption {
|
||||
private final String value;
|
||||
private final boolean usePrefix;
|
||||
|
||||
public StaticCaption(final String value) {
|
||||
/**
|
||||
* @deprecated Use {@link #of(String)}
|
||||
*/
|
||||
@Deprecated public StaticCaption(final String value) {
|
||||
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() {
|
||||
return this.value;
|
||||
}
|
||||
|
@ -45,6 +45,7 @@ import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public final class CaptionLoader {
|
||||
|
||||
private static final Gson GSON = new GsonBuilder().create();
|
||||
private static final Pattern FILE_NAME_PATTERN = Pattern.compile("messages_(.*)\\.json");
|
||||
|
||||
@ -82,4 +83,5 @@ public final class CaptionLoader {
|
||||
}
|
||||
return new LocalizedCaptionMap(locale, captions);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -31,6 +31,7 @@ import java.util.Locale;
|
||||
import java.util.Map;
|
||||
|
||||
public class LocalizedCaptionMap implements CaptionMap {
|
||||
|
||||
private final Locale locale;
|
||||
private final Map<TranslatableCaption, String> captions;
|
||||
|
||||
@ -54,4 +55,5 @@ public class LocalizedCaptionMap implements CaptionMap {
|
||||
@Override public Locale getLocale() {
|
||||
return this.locale;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -32,6 +32,7 @@ import java.util.Locale;
|
||||
import java.util.Map;
|
||||
|
||||
public class PerUserLocaleCaptionMap extends LocalizedCaptionMap {
|
||||
|
||||
private final Map<Locale, CaptionMap> localeMap;
|
||||
|
||||
public PerUserLocaleCaptionMap(Map<Locale, CaptionMap> localeMap) {
|
||||
|
@ -25,10 +25,12 @@
|
||||
*/
|
||||
package com.plotsquared.core.configuration.caption;
|
||||
|
||||
import com.plotsquared.core.PlotSquared;
|
||||
import com.plotsquared.core.configuration.Caption;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public final class TranslatableCaption implements Caption {
|
||||
|
||||
@NotNull private final String key;
|
||||
|
||||
private TranslatableCaption(@NotNull String key) {
|
||||
@ -50,4 +52,5 @@ public final class TranslatableCaption implements Caption {
|
||||
@NotNull public String getKey() {
|
||||
return this.key;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user