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