Skip to content
This repository has been archived by the owner on Nov 3, 2022. It is now read-only.

Commit

Permalink
Refresh the /jails command, add /jail tp.
Browse files Browse the repository at this point in the history
Removed /jails info - purpose folded into /jails

Fixes #677
  • Loading branch information
dualspiral committed Feb 18, 2017
1 parent ae10d09 commit 5b13319
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,32 +5,32 @@
package io.github.nucleuspowered.nucleus.modules.jail.commands;

import com.google.inject.Inject;
import io.github.nucleuspowered.nucleus.api.nucleusdata.NamedLocation;
import io.github.nucleuspowered.nucleus.argumentparsers.JailArgument;
import io.github.nucleuspowered.nucleus.internal.LocationData;
import io.github.nucleuspowered.nucleus.internal.annotations.NoCooldown;
import io.github.nucleuspowered.nucleus.internal.annotations.NoCost;
import io.github.nucleuspowered.nucleus.internal.annotations.NoWarmup;
import io.github.nucleuspowered.nucleus.internal.annotations.Permissions;
import io.github.nucleuspowered.nucleus.internal.annotations.RegisterCommand;
import io.github.nucleuspowered.nucleus.internal.annotations.RunAsync;
import io.github.nucleuspowered.nucleus.internal.command.AbstractCommand;
import io.github.nucleuspowered.nucleus.internal.command.ReturnMessageException;
import io.github.nucleuspowered.nucleus.internal.permissions.SuggestedLevel;
import io.github.nucleuspowered.nucleus.modules.jail.handlers.JailHandler;
import org.spongepowered.api.command.CommandResult;
import org.spongepowered.api.command.CommandSource;
import org.spongepowered.api.command.args.CommandContext;
import org.spongepowered.api.command.args.CommandElement;
import org.spongepowered.api.command.args.GenericArguments;
import org.spongepowered.api.entity.Transform;
import org.spongepowered.api.entity.living.player.Player;
import org.spongepowered.api.text.Text;
import org.spongepowered.api.text.format.TextColors;
import org.spongepowered.api.world.World;

@NoCooldown
@NoCost
@NoWarmup
@Permissions(prefix = "jail", suggestedLevel = SuggestedLevel.MOD)
@RunAsync
@RegisterCommand(value = "info", subcommandOf = JailsCommand.class)
public class JailInfoCommand extends AbstractCommand<CommandSource> {
@RegisterCommand(value = "tp", subcommandOf = JailsCommand.class)
@Permissions(prefix = "jail", mainOverride = "list", suggestedLevel = SuggestedLevel.MOD)
public class JailTeleportCommand extends AbstractCommand<Player> {

private final String jailKey = "jail";
@Inject private JailHandler handler;
Expand All @@ -40,13 +40,14 @@ public CommandElement[] getArguments() {
return new CommandElement[] {GenericArguments.onlyOne(new JailArgument(Text.of(jailKey), handler))};
}

@Override
public CommandResult executeCommand(CommandSource src, CommandContext args) throws Exception {
LocationData wl = args.<LocationData>getOne(jailKey).get();
src.sendMessage(Text.builder().append(plugin.getMessageProvider().getTextMessageWithFormat("command.jail.info.name"))
.append(Text.of(": ", TextColors.GREEN, wl.getName())).build());
src.sendMessage(Text.builder().append(plugin.getMessageProvider().getTextMessageWithFormat("command.jail.info.location"))
.append(Text.of(": ", TextColors.GREEN, wl.toLocationString())).build());
@Override protected CommandResult executeCommand(Player src, CommandContext args) throws Exception {
NamedLocation location = args.<NamedLocation>getOne(jailKey).get();
Transform<World> location1 = location.getTransform().orElseThrow(
() -> new ReturnMessageException(plugin.getMessageProvider().getTextMessageWithFormat("command.jails.tp.noworld", location.getName()))
);

src.setTransform(location1);
src.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("command.jails.tp.success", location.getName()));
return CommandResult.success();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
package io.github.nucleuspowered.nucleus.modules.jail.commands;

import com.google.inject.Inject;
import io.github.nucleuspowered.nucleus.Util;
import io.github.nucleuspowered.nucleus.api.nucleusdata.NamedLocation;
import io.github.nucleuspowered.nucleus.internal.annotations.NoCooldown;
import io.github.nucleuspowered.nucleus.internal.annotations.NoCost;
Expand All @@ -24,6 +25,8 @@
import org.spongepowered.api.text.action.TextActions;
import org.spongepowered.api.text.format.TextColors;
import org.spongepowered.api.text.format.TextStyles;
import org.spongepowered.api.world.Location;
import org.spongepowered.api.world.World;

import java.util.List;
import java.util.Map;
Expand All @@ -33,7 +36,7 @@
@NoCost
@NoWarmup
@RunAsync
@RegisterCommand("jails")
@RegisterCommand(value = "jails")
@Permissions(prefix = "jail", mainOverride = "list", suggestedLevel = SuggestedLevel.MOD)
public class JailsCommand extends AbstractCommand<CommandSource> {

Expand All @@ -50,12 +53,29 @@ public CommandResult executeCommand(CommandSource src, CommandContext args) thro
}

List<Text> lt = mjs.entrySet().stream()
.map(x -> Text.builder(x.getKey().toLowerCase()).color(TextColors.GREEN).style(TextStyles.UNDERLINE)
.onClick(TextActions.runCommand("/jails info " + x.getKey().toLowerCase()))
.onHover(TextActions.showText(plugin.getMessageProvider().getTextMessageWithFormat("command.jails.jailprompt", x.getKey().toLowerCase()))).build())
.map(x -> createJail(x.getValue(), x.getKey()))
.collect(Collectors.toList());

ps.builder().title(plugin.getMessageProvider().getTextMessageWithFormat("command.jails.list.header")).padding(Text.of(TextColors.GREEN, "-")).contents(lt).sendTo(src);
Util.getPaginationBuilder(src)
.title(plugin.getMessageProvider().getTextMessageWithFormat("command.jails.list.header")).padding(Text.of(TextColors.GREEN, "-"))
.contents(lt).sendTo(src);
return CommandResult.success();
}

private Text createJail(NamedLocation data, String name) {
if (data == null || !data.getLocation().isPresent()) {
return Text.builder(name).color(TextColors.RED).onHover(TextActions.showText(plugin.getMessageProvider().getTextMessageWithFormat
("command.jails.unavailable"))).build();
}

Location<World> world = data.getLocation().get();
Text.Builder inner = Text.builder(name).color(TextColors.GREEN).style(TextStyles.ITALIC)
.onClick(TextActions.runCommand("/jails tp " + name))
.onHover(TextActions.showText(plugin.getMessageProvider().getTextMessageWithFormat("command.jails.warpprompt", name)));

return Text.builder().append(inner.build())
.append(plugin.getMessageProvider().getTextMessageWithFormat("command.warps.warploc",
world.getExtent().getName(), world.getBlockPosition().toString()
)).build();
}
}
5 changes: 4 additions & 1 deletion src/main/resources/assets/nucleus/messages.properties
Original file line number Diff line number Diff line change
Expand Up @@ -913,13 +913,16 @@ command.jail.jail.nojail=&cYou must specify a jail!
command.jail.reason=You have been jailed!

command.jails.list.header=&aJail List
command.jails.jailprompt=Click to see information about {0}.
command.jails.set.exists=&cThe jail &e{0} &calready exists.
command.jails.set.success=&aThe jail &e{0} &awas created.
command.jails.set.error=&cUnable to create the jail &e{0}&c.
command.jails.del.success=&aThe jail &e{0} &awas deleted.
command.jails.del.error=&cUnable to delete the jail &e{0}&c.
command.jails.nojails=&cThere are no jails.
command.jails.unavailable=&cThat jail is in an unloaded or deleted world.
command.jails.warpprompt=Click here to warp to the jail &e{0}
command.jails.tp.noworld=&cCould not warp to the jail named &e{0}&c, the world is unloaded and may have been deleted.
command.jails.tp.success=&aWarped to the jail &e{0}&a.
command.jail.info.name=&aJail Name
command.jail.info.location=&aLocation

Expand Down

0 comments on commit 5b13319

Please sign in to comment.