Updates KnarLib
All checks were successful
KnarCraft/PermissionSigns/pipeline/head This commit looks good
All checks were successful
KnarCraft/PermissionSigns/pipeline/head This commit looks good
This commit is contained in:
parent
a3578fe754
commit
d082e8348a
2
pom.xml
2
pom.xml
@ -112,7 +112,7 @@
|
||||
<dependency>
|
||||
<groupId>net.knarcraft</groupId>
|
||||
<artifactId>knarlib</artifactId>
|
||||
<version>1.2.4</version>
|
||||
<version>1.2.5</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
@ -55,7 +55,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
public final class PermissionSigns extends JavaPlugin {
|
||||
|
||||
private static PermissionSigns instance;
|
||||
private Translator translator;
|
||||
private StringFormatter stringFormatter;
|
||||
private Configuration configuration;
|
||||
|
||||
@ -77,21 +76,12 @@ public final class PermissionSigns extends JavaPlugin {
|
||||
return instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the translator
|
||||
*
|
||||
* @return <p>The translator</p>
|
||||
*/
|
||||
public @NotNull Translator getTranslator() {
|
||||
return translator;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the string formatter
|
||||
*
|
||||
* @return <p>The string formatter</p>
|
||||
*/
|
||||
public @NotNull StringFormatter stringFormatter() {
|
||||
public @NotNull StringFormatter getStringFormatter() {
|
||||
return stringFormatter;
|
||||
}
|
||||
|
||||
@ -129,7 +119,7 @@ public final class PermissionSigns extends JavaPlugin {
|
||||
this.saveDefaultConfig();
|
||||
config.options().copyDefaults(true);
|
||||
|
||||
translator = new Translator();
|
||||
Translator translator = new Translator();
|
||||
translator.registerMessageCategory(Translatable.ALREADY_HAS_PERMISSIONS);
|
||||
stringFormatter = new StringFormatter(this.getDescription().getName(), translator);
|
||||
configuration = new Configuration(this.getConfig(), translator, this.getDataFolder());
|
||||
|
@ -16,7 +16,7 @@ public class AboutCommand implements CommandExecutor {
|
||||
@Override
|
||||
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label,
|
||||
@NotNull String[] args) {
|
||||
StringFormatter stringFormatter = PermissionSigns.getInstance().stringFormatter();
|
||||
StringFormatter stringFormatter = PermissionSigns.getInstance().getStringFormatter();
|
||||
stringFormatter.displaySuccessMessage(sender, "Permission Signs plugin created by " + ChatColor.GOLD +
|
||||
"EpicKnarvik97");
|
||||
stringFormatter.displaySuccessMessage(sender, "Plugin version: " +
|
||||
|
@ -18,7 +18,7 @@ public class CancelCommand implements CommandExecutor {
|
||||
@Override
|
||||
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label,
|
||||
@NotNull String[] args) {
|
||||
StringFormatter stringFormatter = PermissionSigns.getInstance().stringFormatter();
|
||||
StringFormatter stringFormatter = PermissionSigns.getInstance().getStringFormatter();
|
||||
|
||||
if (sender instanceof Player player) {
|
||||
if (sender.hasPermission("permissionsigns.admin.create")) {
|
||||
|
@ -26,7 +26,7 @@ public class CreateCommand implements CommandExecutor {
|
||||
//Name and permission(s) required, but duration and cost optional
|
||||
String usage = "/ps create <name> <description> <permission,permission> [cost] [duration] - Used for creating" +
|
||||
" a new permission sign";
|
||||
StringFormatter stringFormatter = PermissionSigns.getInstance().stringFormatter();
|
||||
StringFormatter stringFormatter = PermissionSigns.getInstance().getStringFormatter();
|
||||
|
||||
if (!(sender instanceof Player)) {
|
||||
stringFormatter.displayErrorMessage(sender, Translatable.COMMAND_PLAYER_ONLY);
|
||||
@ -64,7 +64,7 @@ public class CreateCommand implements CommandExecutor {
|
||||
String name = arguments[0];
|
||||
String description = replaceUnderscoresWithSpaces(arguments[1]);
|
||||
String[] permissions = arguments[2].replaceAll("\\?", " ").split(",");
|
||||
StringFormatter stringFormatter = PermissionSigns.getInstance().stringFormatter();
|
||||
StringFormatter stringFormatter = PermissionSigns.getInstance().getStringFormatter();
|
||||
|
||||
for (String permission : permissions) {
|
||||
if (!permission.contains(":")) {
|
||||
|
@ -18,7 +18,7 @@ public class ReloadCommand implements CommandExecutor {
|
||||
@Override
|
||||
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label,
|
||||
@NotNull String[] args) {
|
||||
StringFormatter stringFormatter = PermissionSigns.getInstance().stringFormatter();
|
||||
StringFormatter stringFormatter = PermissionSigns.getInstance().getStringFormatter();
|
||||
if (sender.hasPermission("permissionsigns.admin.reload")) {
|
||||
SignManager.loadSigns();
|
||||
PermissionManager.loadTemporaryPermissions();
|
||||
|
@ -1,7 +1,6 @@
|
||||
package net.knarcraft.permissionsigns.container;
|
||||
|
||||
import net.knarcraft.knarlib.formatting.StringFormatter;
|
||||
import net.knarcraft.knarlib.formatting.Translator;
|
||||
import net.knarcraft.permissionsigns.PermissionSigns;
|
||||
import net.knarcraft.permissionsigns.config.Translatable;
|
||||
import net.knarcraft.permissionsigns.manager.EconomyManager;
|
||||
@ -147,10 +146,10 @@ public class PermissionSign {
|
||||
* @return <p>The lines used to draw this permission sign</p>
|
||||
*/
|
||||
public @NotNull String[] getSignLines() {
|
||||
Translator translator = PermissionSigns.getInstance().getTranslator();
|
||||
StringFormatter stringFormatter = PermissionSigns.getInstance().getStringFormatter();
|
||||
String[] lines = new String[4];
|
||||
lines[0] = translator.getTranslatedMessage(Translatable.SIGN_PREFIX);
|
||||
lines[1] = StringFormatter.replacePlaceholder(translator.getTranslatedMessage(
|
||||
lines[0] = stringFormatter.getUnformattedColoredMessage(Translatable.SIGN_PREFIX);
|
||||
lines[1] = StringFormatter.replacePlaceholder(stringFormatter.getUnformattedColoredMessage(
|
||||
Translatable.SIGN_NAME_FORMAT), "{name}", getName());
|
||||
lines[2] = getDurationString();
|
||||
lines[3] = getCostString();
|
||||
@ -176,7 +175,8 @@ public class PermissionSign {
|
||||
*/
|
||||
public @NotNull String getDurationString() {
|
||||
if (duration == 0) {
|
||||
return PermissionSigns.getInstance().getTranslator().getTranslatedMessage(Translatable.SIGN_PERMANENT);
|
||||
return PermissionSigns.getInstance().getStringFormatter().getUnformattedColoredMessage(
|
||||
Translatable.SIGN_PERMANENT);
|
||||
} else {
|
||||
if (sortedUnits == null) {
|
||||
initializeUnits();
|
||||
@ -199,7 +199,8 @@ public class PermissionSign {
|
||||
*/
|
||||
public @NotNull String getCostString() {
|
||||
if (cost == 0) {
|
||||
return PermissionSigns.getInstance().getTranslator().getTranslatedMessage(Translatable.SIGN_COST_FREE);
|
||||
return PermissionSigns.getInstance().getStringFormatter().getUnformattedColoredMessage(
|
||||
Translatable.SIGN_COST_FREE);
|
||||
} else {
|
||||
return EconomyManager.format(cost);
|
||||
}
|
||||
@ -225,10 +226,10 @@ public class PermissionSign {
|
||||
*/
|
||||
private @NotNull String formatDurationString(double duration, @NotNull Translatable translatable,
|
||||
boolean castToInt) {
|
||||
Translator translator = PermissionSigns.getInstance().getTranslator();
|
||||
String durationFormat = translator.getTranslatedMessage(Translatable.SIGN_DURATION_FORMAT);
|
||||
StringFormatter stringFormatter = PermissionSigns.getInstance().getStringFormatter();
|
||||
String durationFormat = stringFormatter.getUnformattedColoredMessage(Translatable.SIGN_DURATION_FORMAT);
|
||||
durationFormat = StringFormatter.replacePlaceholder(durationFormat, "{unit}",
|
||||
translator.getTranslatedMessage(translatable));
|
||||
stringFormatter.getUnformattedColoredMessage(translatable));
|
||||
return StringFormatter.replacePlaceholder(durationFormat, "{duration}",
|
||||
castToInt ? String.valueOf((int) duration) : String.valueOf(duration));
|
||||
}
|
||||
|
@ -190,7 +190,7 @@ public class BlockListener implements Listener {
|
||||
return;
|
||||
}
|
||||
|
||||
StringFormatter stringFormatter = PermissionSigns.getInstance().stringFormatter();
|
||||
StringFormatter stringFormatter = PermissionSigns.getInstance().getStringFormatter();
|
||||
if (!player.hasPermission("permissionsigns.admin.create")) {
|
||||
event.setCancelled(true);
|
||||
stringFormatter.displayErrorMessage(player, Translatable.PERMISSION_SIGN_DESTROY_DENY);
|
||||
|
@ -1,7 +1,7 @@
|
||||
package net.knarcraft.permissionsigns.listener;
|
||||
|
||||
import net.knarcraft.knarlib.formatting.StringFormatter;
|
||||
import net.knarcraft.knarlib.formatting.Translator;
|
||||
import net.knarcraft.knarlib.formatting.StringReplacer;
|
||||
import net.knarcraft.permissionsigns.PermissionSigns;
|
||||
import net.knarcraft.permissionsigns.config.Translatable;
|
||||
import net.knarcraft.permissionsigns.container.PermissionSign;
|
||||
@ -77,7 +77,7 @@ public class SignListener implements Listener {
|
||||
return;
|
||||
}
|
||||
if (!player.hasPermission("permissionsigns.use")) {
|
||||
PermissionSigns.getInstance().stringFormatter().displayErrorMessage(player,
|
||||
PermissionSigns.getInstance().getStringFormatter().displayErrorMessage(player,
|
||||
Translatable.INTERACT_PERMISSION_MISSING);
|
||||
return;
|
||||
}
|
||||
@ -105,22 +105,28 @@ public class SignListener implements Listener {
|
||||
* @return <p>The information to display</p>
|
||||
*/
|
||||
private String getSignInfoText(@NotNull PermissionSign sign) {
|
||||
Translator translator = PermissionSigns.getInstance().getTranslator();
|
||||
String rawSignInfo = translator.getTranslatedMessage(Translatable.SIGN_INFO);
|
||||
StringFormatter stringFormatter = PermissionSigns.getInstance().getStringFormatter();
|
||||
String rawSignInfo = stringFormatter.getUnformattedColoredMessage(Translatable.SIGN_INFO);
|
||||
StringBuilder permissionString = new StringBuilder();
|
||||
List<String> permissionNodes = sign.getPermissionNodes();
|
||||
|
||||
if (permissionNodes.size() == 1) {
|
||||
permissionString = new StringBuilder(permissionNodes.get(0));
|
||||
} else {
|
||||
for (String permissionNode : permissionNodes) {
|
||||
String format = translator.getTranslatedMessage(Translatable.SIGN_INFO_PERMISSION_FORMAT);
|
||||
String format = stringFormatter.getUnformattedColoredMessage(Translatable.SIGN_INFO_PERMISSION_FORMAT);
|
||||
permissionString.append(StringFormatter.replacePlaceholder(format, "{permission}", permissionNode));
|
||||
}
|
||||
}
|
||||
|
||||
return StringFormatter.replacePlaceholders(rawSignInfo, new String[]{"{Name}", "{Description}", "{Permissions}",
|
||||
"{Cost}", "{Duration}"}, new String[]{sign.getName(), sign.getDescription(),
|
||||
permissionString.toString(), sign.getCostString(), sign.getDurationString()});
|
||||
StringReplacer replacer = new StringReplacer(rawSignInfo);
|
||||
replacer.add("{Name}", sign.getName());
|
||||
replacer.add("{Description}", sign.getDescription());
|
||||
replacer.add("{Permissions}", permissionString.toString());
|
||||
replacer.add("{Cost}", sign.getCostString());
|
||||
replacer.add("{Duration}", sign.getDurationString());
|
||||
|
||||
return replacer.replace();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -142,7 +148,7 @@ public class SignListener implements Listener {
|
||||
hasAllPermissions = false;
|
||||
}
|
||||
}
|
||||
StringFormatter stringFormatter = PermissionSigns.getInstance().stringFormatter();
|
||||
StringFormatter stringFormatter = PermissionSigns.getInstance().getStringFormatter();
|
||||
if (hasAllPermissions) {
|
||||
stringFormatter.displayErrorMessage(player, Translatable.ALREADY_HAS_PERMISSIONS);
|
||||
return;
|
||||
@ -183,12 +189,12 @@ public class SignListener implements Listener {
|
||||
}
|
||||
}
|
||||
|
||||
StringFormatter stringFormatter = PermissionSigns.getInstance().stringFormatter();
|
||||
StringFormatter stringFormatter = PermissionSigns.getInstance().getStringFormatter();
|
||||
String grantedPermissions = permissionsJoiner.toString();
|
||||
if (permissionSign.getDuration() > 0) {
|
||||
stringFormatter.displaySuccessMessage(player, stringFormatter.replacePlaceholders(
|
||||
Translatable.PERMISSIONS_GRANTED, new String[]{"{permissions}", "{time}"},
|
||||
new String[]{grantedPermissions, permissionSign.getDurationString()}));
|
||||
Translatable.PERMISSIONS_GRANTED, List.of("{permissions}", "{time}"),
|
||||
List.of(grantedPermissions, permissionSign.getDurationString())));
|
||||
} else {
|
||||
stringFormatter.displaySuccessMessage(player, stringFormatter.replacePlaceholder(
|
||||
Translatable.PERMISSIONS_GRANTED_PERMANENTLY, "{permissions}", grantedPermissions));
|
||||
@ -225,7 +231,7 @@ public class SignListener implements Listener {
|
||||
sign.setWaxed(true);
|
||||
sign.update();
|
||||
|
||||
PermissionSigns.getInstance().stringFormatter().displaySuccessMessage(player,
|
||||
PermissionSigns.getInstance().getStringFormatter().displaySuccessMessage(player,
|
||||
Translatable.PERMISSION_SIGN_CREATED);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user