mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2024-11-25 14:46:45 +01:00
Start moving commands to new message system
This commit is contained in:
parent
1881cdc9ab
commit
5442c7cc2e
@ -27,6 +27,7 @@ package com.plotsquared.core.command;
|
||||
|
||||
import com.plotsquared.core.PlotSquared;
|
||||
import com.plotsquared.core.configuration.Captions;
|
||||
import com.plotsquared.core.configuration.caption.TranslatableCaption;
|
||||
import com.plotsquared.core.database.DBFunc;
|
||||
import com.plotsquared.core.player.PlotPlayer;
|
||||
import com.plotsquared.core.plot.Plot;
|
||||
@ -35,6 +36,7 @@ import com.plotsquared.core.util.Permissions;
|
||||
import com.plotsquared.core.util.TabCompletions;
|
||||
import com.plotsquared.core.util.task.RunnableVal2;
|
||||
import com.plotsquared.core.util.task.RunnableVal3;
|
||||
import net.kyori.adventure.text.minimessage.Template;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
@ -70,9 +72,10 @@ public class Add extends Command {
|
||||
MainUtil.getUUIDsFromString(args[0], (uuids, throwable) -> {
|
||||
if (throwable != null) {
|
||||
if (throwable instanceof TimeoutException) {
|
||||
Captions.FETCHING_PLAYERS_TIMEOUT.send(player);
|
||||
player.sendMessage(TranslatableCaption.of("players.fetching_players_timeout"));
|
||||
} else {
|
||||
Captions.INVALID_PLAYER.send(player, args[0]);
|
||||
player.sendMessage(TranslatableCaption.of("errors.invalid_player"),
|
||||
Template.of("value", args[0]));
|
||||
}
|
||||
future.completeExceptionally(throwable);
|
||||
return;
|
||||
@ -86,17 +89,20 @@ public class Add extends Command {
|
||||
if (uuid == DBFunc.EVERYONE && !(
|
||||
Permissions.hasPermission(player, Captions.PERMISSION_TRUST_EVERYONE) || Permissions
|
||||
.hasPermission(player, Captions.PERMISSION_ADMIN_COMMAND_TRUST))) {
|
||||
MainUtil.sendMessage(player, Captions.INVALID_PLAYER, MainUtil.getName(uuid));
|
||||
player.sendMessage(TranslatableCaption.of("errors.invalid_player"),
|
||||
Template.of("value", MainUtil.getName(uuid)));
|
||||
iterator.remove();
|
||||
continue;
|
||||
}
|
||||
if (plot.isOwner(uuid)) {
|
||||
MainUtil.sendMessage(player, Captions.ALREADY_ADDED, MainUtil.getName(uuid));
|
||||
player.sendMessage(TranslatableCaption.of("member.already_added"),
|
||||
Template.of("player", MainUtil.getName(uuid)));
|
||||
iterator.remove();
|
||||
continue;
|
||||
}
|
||||
if (plot.getMembers().contains(uuid)) {
|
||||
MainUtil.sendMessage(player, Captions.ALREADY_ADDED, MainUtil.getName(uuid));
|
||||
player.sendMessage(TranslatableCaption.of("member.already_added"),
|
||||
Template.of("player", MainUtil.getName(uuid)));
|
||||
iterator.remove();
|
||||
continue;
|
||||
}
|
||||
@ -117,7 +123,7 @@ public class Add extends Command {
|
||||
}
|
||||
plot.addMember(uuid);
|
||||
PlotSquared.get().getEventDispatcher().callMember(player, plot, uuid, true);
|
||||
MainUtil.sendMessage(player, Captions.MEMBER_ADDED);
|
||||
player.sendMessage(TranslatableCaption.of("member.member_added"));
|
||||
}
|
||||
}, null);
|
||||
} catch (final Throwable exception) {
|
||||
|
@ -27,13 +27,14 @@ package com.plotsquared.core.command;
|
||||
|
||||
import com.plotsquared.core.PlotSquared;
|
||||
import com.plotsquared.core.configuration.Captions;
|
||||
import com.plotsquared.core.configuration.caption.TranslatableCaption;
|
||||
import com.plotsquared.core.location.Location;
|
||||
import com.plotsquared.core.player.PlotPlayer;
|
||||
import com.plotsquared.core.plot.Plot;
|
||||
import com.plotsquared.core.util.MainUtil;
|
||||
import com.plotsquared.core.util.MathMan;
|
||||
import com.plotsquared.core.util.Permissions;
|
||||
import com.plotsquared.core.util.query.PlotQuery;
|
||||
import net.kyori.adventure.text.minimessage.Template;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
@ -55,18 +56,19 @@ public class Alias extends SubCommand {
|
||||
@Override public boolean onCommand(PlotPlayer<?> player, String[] args) {
|
||||
|
||||
if (args.length == 0) {
|
||||
Captions.COMMAND_SYNTAX.send(player, getUsage());
|
||||
sendUsage(player);
|
||||
return false;
|
||||
}
|
||||
|
||||
Location location = player.getLocation();
|
||||
Plot plot = location.getPlotAbs();
|
||||
if (plot == null) {
|
||||
return !sendMessage(player, Captions.NOT_IN_PLOT);
|
||||
player.sendMessage(TranslatableCaption.of("errors.not_in_plot"));
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!plot.hasOwner()) {
|
||||
sendMessage(player, Captions.PLOT_NOT_CLAIMED);
|
||||
player.sendMessage(TranslatableCaption.of("working.plot_not_claimed"));
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -78,7 +80,7 @@ public class Alias extends SubCommand {
|
||||
switch (args[0].toLowerCase()) {
|
||||
case "set":
|
||||
if (args.length != 2) {
|
||||
Captions.COMMAND_SYNTAX.send(player, getUsage());
|
||||
sendUsage(player);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -86,15 +88,15 @@ public class Alias extends SubCommand {
|
||||
|| isPermitted(player, Captions.PERMISSION_ALIAS_SET_OBSOLETE);
|
||||
admin = isPermitted(player, Captions.PERMISSION_ADMIN_ALIAS_SET);
|
||||
if (!admin && !owner) {
|
||||
MainUtil.sendMessage(player, Captions.NO_PLOT_PERMS);
|
||||
player.sendMessage(TranslatableCaption.of("permission.no_plot_perms"));
|
||||
return false;
|
||||
}
|
||||
if (permission) { // is either admin or owner
|
||||
setAlias(player, plot, args[1]);
|
||||
return true;
|
||||
} else {
|
||||
MainUtil.sendMessage(player, Captions.NO_PERMISSION,
|
||||
Captions.PERMISSION_ALIAS_SET.getTranslated());
|
||||
player.sendMessage(TranslatableCaption.of("permission.no_permission"),
|
||||
Template.of("node", Captions.PERMISSION_ALIAS_SET.getTranslated()));
|
||||
}
|
||||
|
||||
break;
|
||||
@ -102,18 +104,18 @@ public class Alias extends SubCommand {
|
||||
permission = isPermitted(player, Captions.PERMISSION_ALIAS_REMOVE);
|
||||
admin = isPermitted(player, Captions.PERMISSION_ADMIN_ALIAS_REMOVE);
|
||||
if (!admin && !owner) {
|
||||
MainUtil.sendMessage(player, Captions.NO_PLOT_PERMS);
|
||||
player.sendMessage(TranslatableCaption.of("permission.no_plot_perms"));
|
||||
return false;
|
||||
}
|
||||
if (permission) {
|
||||
result = removeAlias(player, plot);
|
||||
} else {
|
||||
MainUtil.sendMessage(player, Captions.NO_PERMISSION,
|
||||
Captions.PERMISSION_ALIAS_REMOVE.getTranslated());
|
||||
player.sendMessage(TranslatableCaption.of("permission.no_permission"),
|
||||
Template.of("node", Captions.PERMISSION_ALIAS_REMOVE.getTranslated()));
|
||||
}
|
||||
break;
|
||||
default:
|
||||
Captions.COMMAND_SYNTAX.send(player, getUsage());
|
||||
sendUsage(player);
|
||||
result = false;
|
||||
}
|
||||
|
||||
@ -137,29 +139,27 @@ public class Alias extends SubCommand {
|
||||
|
||||
private void setAlias(PlotPlayer player, Plot plot, String alias) {
|
||||
if (alias.isEmpty()) {
|
||||
Captions.COMMAND_SYNTAX.send(player, getUsage());
|
||||
sendUsage(player);
|
||||
} else if (alias.length() >= 50) {
|
||||
MainUtil.sendMessage(player, Captions.ALIAS_TOO_LONG);
|
||||
} else if (alias.contains(" ")) {
|
||||
Captions.NOT_VALID_VALUE.send(player);
|
||||
player.sendMessage(TranslatableCaption.of("alias.alias_too_long"));
|
||||
} else if (MathMan.isInteger(alias)) {
|
||||
Captions.NOT_VALID_VALUE.send(player);
|
||||
player.sendMessage(TranslatableCaption.of("flag.not_valid_value")); // TODO this is obviously wrong
|
||||
} else {
|
||||
if (PlotQuery.newQuery().inArea(plot.getArea())
|
||||
.withAlias(alias)
|
||||
.anyMatch()) {
|
||||
MainUtil.sendMessage(player, Captions.ALIAS_IS_TAKEN);
|
||||
player.sendMessage(TranslatableCaption.of("alias.alias_is_taken"));
|
||||
return;
|
||||
}
|
||||
PlotSquared.get().getImpromptuUUIDPipeline().getSingle(alias, ((uuid, throwable) -> {
|
||||
if (throwable instanceof TimeoutException) {
|
||||
MainUtil.sendMessage(player, Captions.FETCHING_PLAYERS_TIMEOUT);
|
||||
player.sendMessage(TranslatableCaption.of("players.fetching_players_timeout"));
|
||||
} else if (uuid != null) {
|
||||
MainUtil.sendMessage(player, Captions.ALIAS_IS_TAKEN);
|
||||
player.sendMessage(TranslatableCaption.of("alias.alias_is_taken"));
|
||||
} else {
|
||||
plot.setAlias(alias);
|
||||
MainUtil.sendMessage(player,
|
||||
Captions.ALIAS_SET_TO.getTranslated().replaceAll("%alias%", alias));
|
||||
player.sendMessage(TranslatableCaption.of("alias.alias_set_to"),
|
||||
Template.of("alias", alias));
|
||||
}
|
||||
}));
|
||||
}
|
||||
@ -167,7 +167,8 @@ public class Alias extends SubCommand {
|
||||
|
||||
private boolean removeAlias(PlotPlayer<?> player, Plot plot) {
|
||||
plot.setAlias(null);
|
||||
MainUtil.sendMessage(player, Captions.ALIAS_REMOVED.getTranslated());
|
||||
player.sendMessage(TranslatableCaption.of("permission.no_permission"),
|
||||
Template.of("node", Captions.PERMISSION_ALIAS_REMOVE.getTranslated()));
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -29,6 +29,7 @@ import com.plotsquared.core.PlotSquared;
|
||||
import com.plotsquared.core.configuration.Captions;
|
||||
import com.plotsquared.core.configuration.ConfigurationSection;
|
||||
import com.plotsquared.core.configuration.ConfigurationUtil;
|
||||
import com.plotsquared.core.configuration.caption.TranslatableCaption;
|
||||
import com.plotsquared.core.events.TeleportCause;
|
||||
import com.plotsquared.core.generator.AugmentedUtils;
|
||||
import com.plotsquared.core.generator.HybridPlotWorld;
|
||||
@ -39,7 +40,6 @@ import com.plotsquared.core.plot.PlotArea;
|
||||
import com.plotsquared.core.plot.PlotAreaTerrainType;
|
||||
import com.plotsquared.core.plot.PlotAreaType;
|
||||
import com.plotsquared.core.plot.PlotId;
|
||||
import com.plotsquared.core.plot.message.PlotMessage;
|
||||
import com.plotsquared.core.setup.PlotAreaBuilder;
|
||||
import com.plotsquared.core.util.MainUtil;
|
||||
import com.plotsquared.core.util.MathMan;
|
||||
@ -65,6 +65,7 @@ import com.sk89q.worldedit.math.BlockVector2;
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
import com.sk89q.worldedit.regions.CuboidRegion;
|
||||
import com.sk89q.worldedit.regions.Region;
|
||||
import net.kyori.adventure.text.minimessage.Template;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
@ -85,31 +86,32 @@ public class Area extends SubCommand {
|
||||
|
||||
@Override public boolean onCommand(final PlotPlayer<?> player, String[] args) {
|
||||
if (args.length == 0) {
|
||||
Captions.COMMAND_SYNTAX.send(player, getUsage());
|
||||
sendUsage(player);
|
||||
return false;
|
||||
}
|
||||
switch (args[0].toLowerCase()) {
|
||||
case "single":
|
||||
if (player instanceof ConsolePlayer) {
|
||||
MainUtil.sendMessage(player, Captions.IS_CONSOLE);
|
||||
player.sendMessage(RequiredType.CONSOLE.getErrorMessage());
|
||||
return false;
|
||||
}
|
||||
if (!Permissions.hasPermission(player, Captions.PERMISSION_AREA_CREATE)) {
|
||||
MainUtil.sendMessage(player, Captions.NO_PERMISSION, Captions.PERMISSION_AREA_CREATE);
|
||||
player.sendMessage(TranslatableCaption.of("permission.no_permission"),
|
||||
Template.of("node", Captions.PERMISSION_AREA_CREATE.getTranslated()));
|
||||
return false;
|
||||
}
|
||||
if (args.length < 2) {
|
||||
MainUtil.sendMessage(player, Captions.SINGLE_AREA_NEEDS_NAME);
|
||||
player.sendMessage(TranslatableCaption.of("single.single_area_needs_name"));
|
||||
return false;
|
||||
}
|
||||
final PlotArea existingArea = PlotSquared.get().getPlotArea(player.getLocation().getWorld(), args[1]);
|
||||
if (existingArea != null && existingArea.getId().equalsIgnoreCase(args[1])) {
|
||||
MainUtil.sendMessage(player, Captions.SINGLE_AREA_NAME_TAKEN);
|
||||
player.sendMessage(TranslatableCaption.of("single.single_area_name_taken"));
|
||||
return false;
|
||||
}
|
||||
final LocalSession localSession = WorldEdit.getInstance().getSessionManager().getIfPresent(player.toActor());
|
||||
if (localSession == null) {
|
||||
MainUtil.sendMessage(player, Captions.SINGLE_AREA_MISSING_SELECTION);
|
||||
player.sendMessage(TranslatableCaption.of("single.single_area_missing_selection"));
|
||||
return false;
|
||||
}
|
||||
Region playerSelectedRegion = null;
|
||||
@ -117,16 +119,16 @@ public class Area extends SubCommand {
|
||||
playerSelectedRegion = localSession.getSelection(((Player) player.toActor()).getWorld());
|
||||
} catch (final Exception ignored) {}
|
||||
if (playerSelectedRegion == null) {
|
||||
MainUtil.sendMessage(player, Captions.SINGLE_AREA_MISSING_SELECTION);
|
||||
player.sendMessage(TranslatableCaption.of("single.single_area_missing_selection"));
|
||||
return false;
|
||||
}
|
||||
if (playerSelectedRegion.getWidth() != playerSelectedRegion.getLength()) {
|
||||
MainUtil.sendMessage(player, Captions.SINGLE_AREA_NOT_SQUARE);
|
||||
player.sendMessage(TranslatableCaption.of("single.single_area_not_square"));
|
||||
return false;
|
||||
}
|
||||
if (PlotSquared.get().getPlotAreaManager().getPlotAreas(
|
||||
Objects.requireNonNull(playerSelectedRegion.getWorld()).getName(), CuboidRegion.makeCuboid(playerSelectedRegion)).length != 0) {
|
||||
MainUtil.sendMessage(player, Captions.SINGLE_AREA_OVERLAPPING);
|
||||
player.sendMessage(TranslatableCaption.of("single.single_area_overlapping"));
|
||||
}
|
||||
// Alter the region
|
||||
final BlockVector3 playerSelectionMin = playerSelectedRegion.getMinimumPoint();
|
||||
@ -157,7 +159,7 @@ public class Area extends SubCommand {
|
||||
"GEN_ROAD_SCHEMATIC" + File.separator + hybridPlotWorld.getWorldName() + File.separator +
|
||||
hybridPlotWorld.getId());
|
||||
if (!parentFile.exists() && !parentFile.mkdirs()) {
|
||||
MainUtil.sendMessage(player, Captions.SINGLE_AREA_COULD_NOT_MAKE_DIRECTORIES);
|
||||
player.sendMessage(TranslatableCaption.of("single.single_area_could_not_make_directories"));
|
||||
return false;
|
||||
}
|
||||
final File file = new File(parentFile, "plot.schem");
|
||||
@ -170,7 +172,7 @@ public class Area extends SubCommand {
|
||||
Operations.complete(forwardExtentCopy);
|
||||
clipboardWriter.write(clipboard);
|
||||
} catch (final Exception e) {
|
||||
MainUtil.sendMessage(player, Captions.SINGLE_AREA_FAILED_TO_SAVE);
|
||||
player.sendMessage(TranslatableCaption.of("single.single_area_failed_to_save"));
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
@ -208,7 +210,7 @@ public class Area extends SubCommand {
|
||||
final String world = SetupUtils.manager.setupWorld(singleBuilder);
|
||||
if (WorldUtil.IMP.isWorld(world)) {
|
||||
PlotSquared.get().loadWorld(world, null);
|
||||
MainUtil.sendMessage(player, Captions.SINGLE_AREA_CREATED);
|
||||
player.sendMessage(TranslatableCaption.of("single.single_area_created"));
|
||||
} else {
|
||||
MainUtil.sendMessage(player,
|
||||
"An error occurred while creating the world: " + hybridPlotWorld
|
||||
@ -221,7 +223,8 @@ public class Area extends SubCommand {
|
||||
case "setup":
|
||||
case "create":
|
||||
if (!Permissions.hasPermission(player, Captions.PERMISSION_AREA_CREATE)) {
|
||||
Captions.NO_PERMISSION.send(player, Captions.PERMISSION_AREA_CREATE);
|
||||
player.sendMessage(TranslatableCaption.of("permission.no_permission"),
|
||||
Template.of("node", Captions.PERMISSION_AREA_CREATE.getTranslated()));
|
||||
return false;
|
||||
}
|
||||
switch (args.length) {
|
||||
@ -240,8 +243,9 @@ public class Area extends SubCommand {
|
||||
}
|
||||
Location location = player.getLocation();
|
||||
player.setMeta("area_pos1", location);
|
||||
Captions.SET_ATTRIBUTE.send(player, "area_pos1",
|
||||
location.getX() + "," + location.getZ());
|
||||
player.sendMessage(TranslatableCaption.of("set.set_attribute"),
|
||||
Template.of("attribute", "area_pos1"),
|
||||
Template.of("value", location.getX() + "," + location.getZ()));
|
||||
MainUtil.sendMessage(player,
|
||||
"You will now set pos2: /plot area create pos2"
|
||||
+ "\nNote: The chosen plot size may result in the created area not exactly matching your second position.");
|
||||
@ -277,8 +281,8 @@ public class Area extends SubCommand {
|
||||
Set<PlotArea> areas =
|
||||
PlotSquared.get().getPlotAreas(area.getWorldName(), region);
|
||||
if (!areas.isEmpty()) {
|
||||
Captions.CLUSTER_INTERSECTION
|
||||
.send(player, areas.iterator().next().toString());
|
||||
player.sendMessage(TranslatableCaption.of("cluster.cluster_intersection"),
|
||||
Template.of("cluster", areas.iterator().next().toString()));
|
||||
return false;
|
||||
}
|
||||
PlotAreaBuilder builder = PlotAreaBuilder.ofPlotArea(area)
|
||||
@ -301,7 +305,7 @@ public class Area extends SubCommand {
|
||||
final String world = SetupUtils.manager.setupWorld(builder);
|
||||
if (WorldUtil.IMP.isWorld(world)) {
|
||||
PlotSquared.get().loadWorld(world, null);
|
||||
Captions.SETUP_FINISHED.send(player);
|
||||
player.sendMessage(TranslatableCaption.of("setup.setup_finished"));
|
||||
player.teleport(WorldUtil.IMP.getSpawn(world),
|
||||
TeleportCause.COMMAND);
|
||||
if (area.getTerrain() != PlotAreaTerrainType.ALL) {
|
||||
@ -342,7 +346,8 @@ public class Area extends SubCommand {
|
||||
PlotSquared.get().IMP.getDefaultGenerator(), null, null);
|
||||
PlotArea other = PlotSquared.get().getPlotArea(pa.getWorldName(), id);
|
||||
if (other != null && Objects.equals(pa.getId(), other.getId())) {
|
||||
Captions.SETUP_WORLD_TAKEN.send(player, pa.toString());
|
||||
player.sendMessage(TranslatableCaption.of("setup.setup_world_taken"),
|
||||
Template.of("value", pa.toString()));
|
||||
return false;
|
||||
}
|
||||
Set<PlotArea> areas = PlotSquared.get().getPlotAreas(pa.getWorldName());
|
||||
@ -416,7 +421,8 @@ public class Area extends SubCommand {
|
||||
}
|
||||
if (pa.getType() != PlotAreaType.PARTIAL) {
|
||||
if (WorldUtil.IMP.isWorld(pa.getWorldName())) {
|
||||
Captions.SETUP_WORLD_TAKEN.send(player, pa.getWorldName());
|
||||
player.sendMessage(TranslatableCaption.of("setup.setup_world_taken"),
|
||||
Template.of("value", pa.getWorldName()));
|
||||
return false;
|
||||
}
|
||||
Runnable run = () -> {
|
||||
@ -432,7 +438,7 @@ public class Area extends SubCommand {
|
||||
builder.generatorName(PlotSquared.imp().getPluginName());
|
||||
String world = SetupUtils.manager.setupWorld(builder);
|
||||
if (WorldUtil.IMP.isWorld(world)) {
|
||||
Captions.SETUP_FINISHED.send(player);
|
||||
player.sendMessage(TranslatableCaption.of("setup.setup_finished"));
|
||||
player.teleport(WorldUtil.IMP.getSpawn(world),
|
||||
TeleportCause.COMMAND);
|
||||
} else {
|
||||
@ -481,7 +487,8 @@ public class Area extends SubCommand {
|
||||
case "i":
|
||||
case "info": {
|
||||
if (!Permissions.hasPermission(player, Captions.PERMISSION_AREA_INFO)) {
|
||||
Captions.NO_PERMISSION.send(player, Captions.PERMISSION_AREA_INFO);
|
||||
player.sendMessage(TranslatableCaption.of("permission.no_permission"),
|
||||
Template.of("node", Captions.PERMISSION_AREA_INFO.getTranslated()));
|
||||
return false;
|
||||
}
|
||||
PlotArea area;
|
||||
@ -498,9 +505,10 @@ public class Area extends SubCommand {
|
||||
}
|
||||
if (area == null) {
|
||||
if (args.length == 2) {
|
||||
Captions.NOT_VALID_PLOT_WORLD.send(player, args[1]);
|
||||
player.sendMessage(TranslatableCaption.of("errors.not_valid_plot_world"),
|
||||
Template.of("value", args[1]));
|
||||
} else {
|
||||
Captions.NOT_IN_PLOT_WORLD.send(player);
|
||||
player.sendMessage(TranslatableCaption.of("errors.not_in_plot_world"));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@ -535,7 +543,8 @@ public class Area extends SubCommand {
|
||||
case "l":
|
||||
case "list":
|
||||
if (!Permissions.hasPermission(player, Captions.PERMISSION_AREA_LIST)) {
|
||||
Captions.NO_PERMISSION.send(player, Captions.PERMISSION_AREA_LIST);
|
||||
player.sendMessage(TranslatableCaption.of("permission.no_permission"),
|
||||
Template.of("node", Captions.PERMISSION_AREA_LIST.getTranslated()));
|
||||
return false;
|
||||
}
|
||||
int page;
|
||||
@ -599,7 +608,8 @@ public class Area extends SubCommand {
|
||||
case "reset":
|
||||
case "regenerate": {
|
||||
if (!Permissions.hasPermission(player, Captions.PERMISSION_AREA_REGEN)) {
|
||||
Captions.NO_PERMISSION.send(player, Captions.PERMISSION_AREA_REGEN);
|
||||
player.sendMessage(TranslatableCaption.of("permission.no_permission"),
|
||||
Template.of("node", Captions.PERMISSION_AREA_REGEN.getTranslated()));
|
||||
return false;
|
||||
}
|
||||
final PlotArea area = player.getApplicablePlotArea();
|
||||
@ -628,7 +638,8 @@ public class Area extends SubCommand {
|
||||
case "visit":
|
||||
case "tp":
|
||||
if (!Permissions.hasPermission(player, Captions.PERMISSION_AREA_TP)) {
|
||||
Captions.NO_PERMISSION.send(player, Captions.PERMISSION_AREA_TP);
|
||||
player.sendMessage(TranslatableCaption.of("permission.no_permission"),
|
||||
Template.of("node", Captions.PERMISSION_AREA_TP.getTranslated()));
|
||||
return false;
|
||||
}
|
||||
if (args.length != 2) {
|
||||
@ -637,7 +648,8 @@ public class Area extends SubCommand {
|
||||
}
|
||||
PlotArea area = PlotSquared.get().getPlotAreaByString(args[1]);
|
||||
if (area == null) {
|
||||
Captions.NOT_VALID_PLOT_WORLD.send(player, args[1]);
|
||||
player.sendMessage(TranslatableCaption.of("errors.not_valid_plot_world"),
|
||||
Template.of("value", args[1]));
|
||||
return false;
|
||||
}
|
||||
Location center;
|
||||
@ -667,7 +679,7 @@ public class Area extends SubCommand {
|
||||
+ "\n$1Stop the server and delete it from these locations.");
|
||||
return true;
|
||||
}
|
||||
Captions.COMMAND_SYNTAX.send(player, getUsage());
|
||||
sendUsage(player);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -30,6 +30,7 @@ import com.plotsquared.core.PlotSquared;
|
||||
import com.plotsquared.core.configuration.CaptionUtility;
|
||||
import com.plotsquared.core.configuration.Captions;
|
||||
import com.plotsquared.core.configuration.Settings;
|
||||
import com.plotsquared.core.configuration.caption.TranslatableCaption;
|
||||
import com.plotsquared.core.database.DBFunc;
|
||||
import com.plotsquared.core.events.PlayerAutoPlotEvent;
|
||||
import com.plotsquared.core.events.PlotAutoMergeEvent;
|
||||
@ -47,6 +48,7 @@ import com.plotsquared.core.util.Permissions;
|
||||
import com.plotsquared.core.util.task.AutoClaimFinishTask;
|
||||
import com.plotsquared.core.util.task.RunnableVal;
|
||||
import com.plotsquared.core.util.task.TaskManager;
|
||||
import net.kyori.adventure.text.minimessage.Template;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@ -81,10 +83,10 @@ public class Auto extends SubCommand {
|
||||
if (player.hasPersistentMeta("grantedPlots")) {
|
||||
int grantedPlots = Ints.fromByteArray(player.getPersistentMeta("grantedPlots"));
|
||||
if (diff < 0 && grantedPlots < sizeX * sizeZ) {
|
||||
MainUtil.sendMessage(player, Captions.CANT_CLAIM_MORE_PLOTS);
|
||||
player.sendMessage(TranslatableCaption.of("permission.cant_claim_more_plots"));
|
||||
return false;
|
||||
} else if (diff >= 0 && grantedPlots + diff < sizeX * sizeZ) {
|
||||
MainUtil.sendMessage(player, Captions.CANT_CLAIM_MORE_PLOTS);
|
||||
player.sendMessage(TranslatableCaption.of("permission.cant_claim_more_plots"));
|
||||
return false;
|
||||
} else {
|
||||
int left = grantedPlots + diff < 0 ? 0 : diff - sizeX * sizeZ;
|
||||
@ -93,11 +95,12 @@ public class Auto extends SubCommand {
|
||||
} else {
|
||||
player.setPersistentMeta("grantedPlots", Ints.toByteArray(left));
|
||||
}
|
||||
MainUtil.sendMessage(player, Captions.REMOVED_GRANTED_PLOT,
|
||||
"" + (grantedPlots - left), "" + left);
|
||||
player.sendMessage(TranslatableCaption.of("economy.removed_granted_plot"),
|
||||
Template.of("usedGrants", String.valueOf(grantedPlots - left)),
|
||||
Template.of("remainingGrants", String.valueOf(left)));
|
||||
}
|
||||
} else {
|
||||
MainUtil.sendMessage(player, Captions.CANT_CLAIM_MORE_PLOTS);
|
||||
player.sendMessage(TranslatableCaption.of("permission.cant_claim_more_plots"));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@ -173,7 +176,7 @@ public class Auto extends SubCommand {
|
||||
plotarea = PlotSquared.get().getPlotAreaManager().getAllPlotAreas()[0];
|
||||
}
|
||||
if (plotarea == null) {
|
||||
MainUtil.sendMessage(player, Captions.NOT_IN_PLOT_WORLD);
|
||||
player.sendMessage(TranslatableCaption.of("errors.not_in_plot_world"));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@ -224,12 +227,12 @@ public class Auto extends SubCommand {
|
||||
size_z = event.getSize_z();
|
||||
schematic = event.getSchematic();
|
||||
if (!force && mega && !Permissions.hasPermission(player, Captions.PERMISSION_AUTO_MEGA)) {
|
||||
MainUtil.sendMessage(player, Captions.NO_PERMISSION,
|
||||
CaptionUtility.format(player, Captions.PERMISSION_AUTO_MEGA));
|
||||
player.sendMessage(TranslatableCaption.of("permission.no_permission"),
|
||||
Template.of("node", Captions.PERMISSION_AUTO_MEGA.getTranslated()));
|
||||
}
|
||||
if (!force && size_x * size_z > Settings.Claim.MAX_AUTO_AREA) {
|
||||
MainUtil.sendMessage(player, Captions.CANT_CLAIM_MORE_PLOTS_NUM,
|
||||
Settings.Claim.MAX_AUTO_AREA + "");
|
||||
player.sendMessage(TranslatableCaption.of("permission.cant_claim_more_plots_num"),
|
||||
Template.of("amount", String.valueOf(Settings.Claim.MAX_AUTO_AREA)));
|
||||
return false;
|
||||
}
|
||||
final int allowed_plots = player.getAllowedPlots();
|
||||
@ -274,7 +277,7 @@ public class Auto extends SubCommand {
|
||||
return true;
|
||||
} else {
|
||||
if (plotarea.getType() == PlotAreaType.PARTIAL) {
|
||||
MainUtil.sendMessage(player, Captions.NO_FREE_PLOTS);
|
||||
player.sendMessage(TranslatableCaption.of("errors.no_free_plots"));
|
||||
return false;
|
||||
}
|
||||
while (true) {
|
||||
|
@ -26,10 +26,12 @@
|
||||
package com.plotsquared.core.command;
|
||||
|
||||
import com.plotsquared.core.PlotSquared;
|
||||
import com.plotsquared.core.configuration.Caption;
|
||||
import com.plotsquared.core.configuration.Captions;
|
||||
import com.plotsquared.core.configuration.StaticCaption;
|
||||
import com.plotsquared.core.configuration.caption.TranslatableCaption;
|
||||
import com.plotsquared.core.configuration.file.YamlConfiguration;
|
||||
import com.plotsquared.core.player.PlotPlayer;
|
||||
import com.plotsquared.core.plot.message.PlotMessage;
|
||||
import com.plotsquared.core.util.MainUtil;
|
||||
import com.plotsquared.core.util.MathMan;
|
||||
import com.plotsquared.core.util.Permissions;
|
||||
@ -38,6 +40,7 @@ import com.plotsquared.core.util.StringMan;
|
||||
import com.plotsquared.core.util.task.RunnableVal2;
|
||||
import com.plotsquared.core.util.task.RunnableVal3;
|
||||
import lombok.SneakyThrows;
|
||||
import net.kyori.adventure.text.minimessage.Template;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.io.IOException;
|
||||
@ -247,7 +250,7 @@ public abstract class Command {
|
||||
}
|
||||
|
||||
public <T> void paginate(PlotPlayer player, List<T> c, int size, int page,
|
||||
RunnableVal3<Integer, T, PlotMessage> add, String baseCommand, String header) {
|
||||
RunnableVal3<Integer, T, Caption> add, String baseCommand, String header) {
|
||||
// Calculate pages & index
|
||||
if (page < 0) {
|
||||
page = 0;
|
||||
@ -307,19 +310,19 @@ public abstract class Command {
|
||||
if (this.parent == null) {
|
||||
MainCommand.getInstance().help.displayHelp(player, null, 0);
|
||||
} else {
|
||||
Captions.COMMAND_SYNTAX.send(player, getUsage());
|
||||
sendUsage(player);
|
||||
}
|
||||
return CompletableFuture.completedFuture(false);
|
||||
}
|
||||
if (this.allCommands.isEmpty()) {
|
||||
player.sendMessage(
|
||||
"Not Implemented: https://github.com/IntellectualSites/PlotSquared/issues/new");
|
||||
StaticCaption.of("Not Implemented: https://issues.intellectualsites.com/newIssue?project=PS"));
|
||||
return CompletableFuture.completedFuture(false);
|
||||
}
|
||||
Command cmd = getCommand(args[0]);
|
||||
if (cmd == null) {
|
||||
if (this.parent != null) {
|
||||
Captions.COMMAND_SYNTAX.send(player, getUsage());
|
||||
sendUsage(player);
|
||||
return CompletableFuture.completedFuture(false);
|
||||
}
|
||||
// Help command
|
||||
@ -334,11 +337,11 @@ public abstract class Command {
|
||||
} catch (IllegalArgumentException ignored) {
|
||||
}
|
||||
// Command recommendation
|
||||
MainUtil.sendMessage(player, Captions.NOT_VALID_SUBCOMMAND);
|
||||
player.sendMessage(TranslatableCaption.of("commandconfig.not_valid_subcommand"));
|
||||
List<Command> commands = getCommands(player);
|
||||
if (commands.isEmpty()) {
|
||||
MainUtil.sendMessage(player, Captions.DID_YOU_MEAN,
|
||||
MainCommand.getInstance().help.getUsage());
|
||||
player.sendMessage(TranslatableCaption.of("commandconfig.did_you_mean"),
|
||||
Template.of("value", MainCommand.getInstance().help.getUsage()));
|
||||
return CompletableFuture.completedFuture(false);
|
||||
}
|
||||
HashSet<String> setArgs = new HashSet<>(args.length);
|
||||
@ -356,7 +359,8 @@ public abstract class Command {
|
||||
if (cmd == null) {
|
||||
cmd = new StringComparison<>(args[0], this.allCommands).getMatchObject();
|
||||
}
|
||||
MainUtil.sendMessage(player, Captions.DID_YOU_MEAN, cmd.getUsage());
|
||||
player.sendMessage(TranslatableCaption.of("commandconfig.did_you_mean"),
|
||||
Template.of("value", cmd.getUsage()));
|
||||
return CompletableFuture.completedFuture(false);
|
||||
}
|
||||
String[] newArgs = Arrays.copyOfRange(args, 1, args.length);
|
||||
@ -388,7 +392,9 @@ public abstract class Command {
|
||||
failed = failed || reqArgs[i].parse(args[i]) == null;
|
||||
}
|
||||
if (failed) {
|
||||
Captions.COMMAND_SYNTAX.send(player, StringMan.join(fullSplit, " "));
|
||||
// TODO improve or remove the Argument system
|
||||
player.sendMessage(TranslatableCaption.of("commandconfig.command_syntax"),
|
||||
Template.of("value", StringMan.join(fullSplit, " ")));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@ -470,13 +476,12 @@ public abstract class Command {
|
||||
}
|
||||
if (!this.required.allows(player)) {
|
||||
if (message) {
|
||||
MainUtil.sendMessage(player, this.required == RequiredType.PLAYER ?
|
||||
Captions.IS_CONSOLE :
|
||||
Captions.NOT_CONSOLE);
|
||||
player.sendMessage(this.required.getErrorMessage());
|
||||
}
|
||||
} else if (!Permissions.hasPermission(player, getPermission())) {
|
||||
if (message) {
|
||||
Captions.NO_PERMISSION.send(player, getPermission());
|
||||
player.sendMessage(TranslatableCaption.of("permission.no_permission"),
|
||||
Template.of("node", getPermission()));
|
||||
}
|
||||
} else {
|
||||
return true;
|
||||
@ -497,6 +502,11 @@ public abstract class Command {
|
||||
}
|
||||
}
|
||||
|
||||
public void sendUsage(PlotPlayer<?> player) {
|
||||
player.sendMessage(TranslatableCaption.of("commandconfig.command_syntax"),
|
||||
Template.of("value", getUsage()));
|
||||
}
|
||||
|
||||
public String getUsage() {
|
||||
if (this.usage != null && !this.usage.isEmpty()) {
|
||||
if (this.usage.startsWith("/")) {
|
||||
@ -592,13 +602,13 @@ public abstract class Command {
|
||||
return this.getFullId().hashCode();
|
||||
}
|
||||
|
||||
public void checkTrue(boolean mustBeTrue, Captions message, Object... args) {
|
||||
public void checkTrue(boolean mustBeTrue, Captions message, Template... args) {
|
||||
if (!mustBeTrue) {
|
||||
throw new CommandException(message, args);
|
||||
}
|
||||
}
|
||||
|
||||
public <T extends Object> T check(T object, Captions message, Object... args) {
|
||||
public <T extends Object> T check(T object, Captions message, Template... args) {
|
||||
if (object == null) {
|
||||
throw new CommandException(message, args);
|
||||
}
|
||||
@ -615,17 +625,17 @@ public abstract class Command {
|
||||
|
||||
|
||||
public static class CommandException extends RuntimeException {
|
||||
private final Object[] args;
|
||||
private final Captions message;
|
||||
private final Template[] args;
|
||||
private final Caption message;
|
||||
|
||||
public CommandException(Captions message, Object... args) {
|
||||
public CommandException(Caption message, Template... args) {
|
||||
this.message = message;
|
||||
this.args = args;
|
||||
}
|
||||
|
||||
public void perform(PlotPlayer player) {
|
||||
if (player != null && message != null) {
|
||||
message.send(player, args);
|
||||
player.sendMessage(message, args);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -27,6 +27,7 @@ package com.plotsquared.core.command;
|
||||
|
||||
import com.plotsquared.core.configuration.Captions;
|
||||
import com.plotsquared.core.configuration.Settings;
|
||||
import com.plotsquared.core.configuration.caption.TranslatableCaption;
|
||||
import com.plotsquared.core.location.Location;
|
||||
import com.plotsquared.core.player.ConsolePlayer;
|
||||
import com.plotsquared.core.player.PlotPlayer;
|
||||
@ -244,7 +245,7 @@ public class MainCommand extends Command {
|
||||
player.setMeta(PlotPlayer.META_LOCATION, newLoc);
|
||||
player.setMeta(PlotPlayer.META_LAST_PLOT, newPlot);
|
||||
} else {
|
||||
Captions.BORDER.send(player);
|
||||
player.sendMessage(TranslatableCaption.of("border.border"));
|
||||
}
|
||||
// Trim command
|
||||
args = Arrays.copyOfRange(args, 1, args.length);
|
||||
@ -275,7 +276,7 @@ public class MainCommand extends Command {
|
||||
};
|
||||
args = Arrays.copyOfRange(args, 1, args.length);
|
||||
} else {
|
||||
Captions.INVALID_COMMAND_FLAG.send(player);
|
||||
player.sendMessage(TranslatableCaption.of("errors.invalid_command_flag"));
|
||||
return CompletableFuture.completedFuture(false);
|
||||
}
|
||||
}
|
||||
@ -288,9 +289,10 @@ public class MainCommand extends Command {
|
||||
e.printStackTrace();
|
||||
String message = e.getLocalizedMessage();
|
||||
if (message != null) {
|
||||
Captions.ERROR.send(player, message);
|
||||
player.sendMessage(TranslatableCaption.of("errors.error"),
|
||||
net.kyori.adventure.text.minimessage.Template.of("value", message));
|
||||
} else {
|
||||
Captions.ERROR.send(player);
|
||||
player.sendMessage(TranslatableCaption.of("errors.error"));
|
||||
}
|
||||
}
|
||||
// Reset command scope //
|
||||
|
@ -25,8 +25,21 @@
|
||||
*/
|
||||
package com.plotsquared.core.command;
|
||||
|
||||
import com.plotsquared.core.configuration.Caption;
|
||||
import com.plotsquared.core.configuration.StaticCaption;
|
||||
import com.plotsquared.core.configuration.caption.TranslatableCaption;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public enum RequiredType {
|
||||
CONSOLE, PLAYER, NONE;
|
||||
CONSOLE(TranslatableCaption.of("console.is_console")),
|
||||
PLAYER(TranslatableCaption.of("console.not_console")),
|
||||
NONE(StaticCaption.of("Something went wrong: RequiredType=NONE")); // this caption should never be sent
|
||||
|
||||
private final Caption caption;
|
||||
|
||||
RequiredType(Caption caption) {
|
||||
this.caption = caption;
|
||||
}
|
||||
|
||||
public boolean allows(CommandCaller player) {
|
||||
if (this == RequiredType.NONE) {
|
||||
@ -34,4 +47,8 @@ public enum RequiredType {
|
||||
}
|
||||
return this == player.getSuperCaller();
|
||||
}
|
||||
|
||||
@NotNull public Caption getErrorMessage() {
|
||||
return this.caption;
|
||||
}
|
||||
}
|
||||
|
@ -26,6 +26,7 @@
|
||||
package com.plotsquared.core.configuration;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.plotsquared.core.configuration.caption.LocaleHolder;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@ -52,12 +53,8 @@ public final class StaticCaption implements Caption {
|
||||
return new StaticCaption(Preconditions.checkNotNull(text, "Text may not be null"));
|
||||
}
|
||||
|
||||
@Override public String getTranslated() {
|
||||
return this.value;
|
||||
@Override
|
||||
public @NotNull String getComponent(@NotNull LocaleHolder localeHolder) {
|
||||
return this.value; // can't be translated
|
||||
}
|
||||
|
||||
@Override public boolean usePrefix() {
|
||||
return this.usePrefix;
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user