Skip to content

Commit

Permalink
Made improvements.
Browse files Browse the repository at this point in the history
Locatable command sources are now able to use relative coordinates and
omit things like world parameters. Why you want to do this i don't know,
but in theory this makes things more future proof.
  • Loading branch information
gravityfox committed Nov 18, 2016
1 parent 3c34fbb commit 78b8457
Show file tree
Hide file tree
Showing 22 changed files with 1,102 additions and 236 deletions.
2 changes: 1 addition & 1 deletion FoxCore
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,7 @@
import net.foxdenstudio.sponge.foxguard.plugin.command.*;
import net.foxdenstudio.sponge.foxguard.plugin.controller.LogicController;
import net.foxdenstudio.sponge.foxguard.plugin.flag.FlagRegistry;
import net.foxdenstudio.sponge.foxguard.plugin.handler.BasicHandler;
import net.foxdenstudio.sponge.foxguard.plugin.handler.DebugHandler;
import net.foxdenstudio.sponge.foxguard.plugin.handler.GroupHandler;
import net.foxdenstudio.sponge.foxguard.plugin.handler.StaticHandler;
import net.foxdenstudio.sponge.foxguard.plugin.handler.*;
import net.foxdenstudio.sponge.foxguard.plugin.listener.*;
import net.foxdenstudio.sponge.foxguard.plugin.misc.FGContextCalculator;
import net.foxdenstudio.sponge.foxguard.plugin.object.factory.FGFactoryManager;
Expand Down Expand Up @@ -289,6 +286,7 @@ private void registerFactories() {
manager.registerHandlerFactory(new StaticHandler.Factory());
manager.registerHandlerFactory(new BasicHandler.Factory());
manager.registerHandlerFactory(new GroupHandler.Factory());
manager.registerHandlerFactory(new PermissionHandler.Factory());
manager.registerHandlerFactory(new DebugHandler.Factory());

//manager.registerControllerFactory(new MessageController.Factory());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
import org.spongepowered.api.util.GuavaCollectors;
import org.spongepowered.api.util.StartsWithPredicate;
import org.spongepowered.api.util.Tristate;
import org.spongepowered.api.world.Locatable;
import org.spongepowered.api.world.Location;
import org.spongepowered.api.world.World;

Expand Down Expand Up @@ -97,7 +98,7 @@ public CommandResult process(@Nonnull CommandSource source, @Nonnull String argu
String worldName = parse.flags.get("world");
World world = null;
if (isWorldRegion) {
if (source instanceof Player) world = ((Player) source).getWorld();
if (source instanceof Locatable) world = ((Locatable) source).getWorld();
if (!worldName.isEmpty()) {
Optional<World> optWorld = Sponge.getGame().getServer().getWorld(worldName);
if (optWorld.isPresent()) {
Expand Down Expand Up @@ -257,7 +258,7 @@ else if (parse.current.index == 1) {
} else if (isIn(WORLDREGIONS_ALIASES, parse.args[0])) {
String worldName = parse.flags.get("world");
World world = null;
if (source instanceof Player) world = ((Player) source).getWorld();
if (source instanceof Locatable) world = ((Locatable) source).getWorld();
if (!worldName.isEmpty()) {
Optional<World> optWorld = Sponge.getGame().getServer().getWorld(worldName);
if (optWorld.isPresent()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
import org.spongepowered.api.text.format.TextColors;
import org.spongepowered.api.util.GuavaCollectors;
import org.spongepowered.api.util.StartsWithPredicate;
import org.spongepowered.api.world.Locatable;
import org.spongepowered.api.world.Location;
import org.spongepowered.api.world.World;

Expand Down Expand Up @@ -90,7 +91,7 @@ public CommandResult process(CommandSource source, String arguments) throws Comm
if (region == null) {
String worldName = parse.flags.get("world");
World world = null;
if (source instanceof Player) world = ((Player) source).getWorld();
if (source instanceof Locatable) world = ((Locatable) source).getWorld();
if (!worldName.isEmpty()) {
Optional<World> optWorld = Sponge.getGame().getServer().getWorld(worldName);
if (optWorld.isPresent()) {
Expand Down Expand Up @@ -149,7 +150,7 @@ else if (parse.current.index == 1) {
if (isIn(REGIONS_ALIASES, parse.args[0])) {
String worldName = parse.flags.get("world");
World world = null;
if (source instanceof Player) world = ((Player) source).getWorld();
if (source instanceof Locatable) world = ((Locatable) source).getWorld();
if (!worldName.isEmpty()) {
Optional<World> optWorld = Sponge.getGame().getServer().getWorld(worldName);
if (optWorld.isPresent()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import net.foxdenstudio.sponge.foxcore.plugin.command.util.AdvCmdParser;
import net.foxdenstudio.sponge.foxcore.plugin.command.util.FlagMapper;
import net.foxdenstudio.sponge.foxguard.plugin.FGManager;
import net.foxdenstudio.sponge.foxguard.plugin.FoxGuardMain;
import net.foxdenstudio.sponge.foxguard.plugin.controller.IController;
import net.foxdenstudio.sponge.foxguard.plugin.handler.IHandler;
import net.foxdenstudio.sponge.foxguard.plugin.object.IFGObject;
Expand All @@ -49,6 +50,7 @@
import org.spongepowered.api.text.format.TextStyles;
import org.spongepowered.api.util.GuavaCollectors;
import org.spongepowered.api.util.StartsWithPredicate;
import org.spongepowered.api.world.Locatable;
import org.spongepowered.api.world.Location;
import org.spongepowered.api.world.World;

Expand Down Expand Up @@ -95,7 +97,7 @@ public CommandResult process(CommandSource source, String arguments) throws Comm
if (region == null) {
String worldName = parse.flags.get("world");
World world = null;
if (source instanceof Player) world = ((Player) source).getWorld();
if (source instanceof Locatable) world = ((Locatable) source).getWorld();
if (!worldName.isEmpty()) {
Optional<World> optWorld = Sponge.getGame().getServer().getWorld(worldName);
if (optWorld.isPresent()) {
Expand Down Expand Up @@ -136,6 +138,12 @@ public CommandResult process(CommandSource source, String arguments) throws Comm
builder.append(objectDetails);
} catch (Exception e) {
builder.append(Text.of(TextColors.RED, TextStyles.ITALIC, "There was an error getting details for region \"" + region.getName() + "\"."));
FoxGuardMain.instance().getLogger().error(
(region instanceof IWorldRegion ? "Worldregion \"" : "Region \"")
+ region.getName() + "\" of type \"" + region.getLongTypeName() + "\""
+ (region instanceof IWorldRegion ? " in world \"" + ((IWorldRegion) region).getWorld().getName() + "\"" : "")
+ " threw an exception while getting details", e
);
}
outboundLinks(builder, region, source);
} else {
Expand All @@ -148,6 +156,12 @@ public CommandResult process(CommandSource source, String arguments) throws Comm
builder.append(objectDetails);
} catch (Exception e) {
builder.append(Text.of(TextColors.RED, TextStyles.ITALIC, "There was an error getting details for region \"" + region.getName() + "\"."));
FoxGuardMain.instance().getLogger().error(
(region instanceof IWorldRegion ? "Worldregion \"" : "Region \"")
+ region.getName() + "\" of type \"" + region.getLongTypeName() + "\""
+ (region instanceof IWorldRegion ? " in world \"" + ((IWorldRegion) region).getWorld().getName() + "\"" : "")
+ " threw an exception while getting details", e
);
}
}
source.sendMessage(builder.build());
Expand Down Expand Up @@ -187,6 +201,9 @@ public CommandResult process(CommandSource source, String arguments) throws Comm
builder.append(objectDetails);
} catch (Exception e) {
builder.append(Text.of(TextColors.RED, TextStyles.ITALIC, "There was an error getting details for handler \"" + handler.getName() + "\"."));
FoxGuardMain.instance().getLogger().error(
"Handler \"" + handler.getName() + "\" of type \"" + handler.getLongTypeName() + "\" threw an exception while getting details", e
);
}
builder.append(Text.of(TextColors.GREEN, "\n------- Inbound Links -------"));
List<IController> controllerList = FGManager.getInstance().getControllers().stream()
Expand Down Expand Up @@ -278,6 +295,9 @@ public CommandResult process(CommandSource source, String arguments) throws Comm
builder.append(objectDetails);
} catch (Exception e) {
builder.append(Text.of(TextColors.RED, TextStyles.ITALIC, "There was an error getting details for handler \"" + handler.getName() + "\"."));
FoxGuardMain.instance().getLogger().error(
"Handler \"" + handler.getName() + "\" of type \"" + handler.getLongTypeName() + "\" threw an exception while getting details", e
);
}
}
source.sendMessage(builder.build());
Expand Down Expand Up @@ -360,7 +380,7 @@ else if (parse.current.index == 1) {
if (isIn(REGIONS_ALIASES, parse.args[0])) {
String worldName = parse.flags.get("world");
World world = null;
if (source instanceof Player) world = ((Player) source).getWorld();
if (source instanceof Locatable) world = ((Locatable) source).getWorld();
if (!worldName.isEmpty()) {
Optional<World> optWorld = Sponge.getGame().getServer().getWorld(worldName);
if (optWorld.isPresent()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
import org.spongepowered.api.text.format.TextColors;
import org.spongepowered.api.util.GuavaCollectors;
import org.spongepowered.api.util.StartsWithPredicate;
import org.spongepowered.api.world.Locatable;
import org.spongepowered.api.world.Location;
import org.spongepowered.api.world.World;

Expand Down Expand Up @@ -127,7 +128,7 @@ public CommandResult process(CommandSource source, String arguments) throws Comm
} else if (isIn(REGIONS_ALIASES, parse.args[0])) {
String worldName = parse.flags.get("world");
World world = null;
if (source instanceof Player) world = ((Player) source).getWorld();
if (source instanceof Locatable) world = ((Locatable) source).getWorld();
if (!worldName.isEmpty()) {
Optional<World> optWorld = Sponge.getGame().getServer().getWorld(worldName);
if (optWorld.isPresent()) {
Expand Down Expand Up @@ -230,7 +231,7 @@ else if (parse.current.index > 0) {
if (isIn(REGIONS_ALIASES, parse.args[0])) {
String worldName = parse.flags.get("world");
World world = null;
if (source instanceof Player) world = ((Player) source).getWorld();
if (source instanceof Locatable) world = ((Locatable) source).getWorld();
if (!worldName.isEmpty()) {
Optional<World> optWorld = Sponge.getGame().getServer().getWorld(worldName);
if (optWorld.isPresent()) {
Expand Down Expand Up @@ -297,8 +298,6 @@ public Optional<Text> getHelp(CommandSource source) {

@Override
public Text getUsage(CommandSource source) {
if (source instanceof Player)
return Text.of((this.enableState ? "enable" : "disable") + " <region [--w:<worldname>] | handler> [names]...");
else return Text.of((this.enableState ? "enable" : "disable") + " <region <worldname> | handler> [names]...");
return Text.of((this.enableState ? "enable" : "disable") + " <region [--w:worldname]> | handler> [names]...");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
import net.foxdenstudio.sponge.foxguard.plugin.handler.IHandler;
import net.foxdenstudio.sponge.foxguard.plugin.listener.PlayerMoveListener;
import net.foxdenstudio.sponge.foxguard.plugin.region.IRegion;
import net.foxdenstudio.sponge.foxguard.plugin.region.world.IWorldRegion;
import net.foxdenstudio.sponge.foxguard.plugin.util.FGUtil;
import org.spongepowered.api.Sponge;
import org.spongepowered.api.command.CommandException;
Expand All @@ -50,6 +49,7 @@
import org.spongepowered.api.text.format.TextColors;
import org.spongepowered.api.util.GuavaCollectors;
import org.spongepowered.api.util.StartsWithPredicate;
import org.spongepowered.api.world.Locatable;
import org.spongepowered.api.world.Location;
import org.spongepowered.api.world.World;

Expand Down Expand Up @@ -89,7 +89,7 @@ public CommandResult process(CommandSource source, String arguments) throws Comm

String worldName = parse.flags.get("world");
World world = null;
if (source instanceof Player) world = ((Player) source).getWorld();
if (source instanceof Locatable) world = ((Locatable) source).getWorld();
if (!worldName.isEmpty()) {
Optional<World> optWorld = Sponge.getGame().getServer().getWorld(worldName);
if (optWorld.isPresent()) {
Expand All @@ -102,8 +102,8 @@ public CommandResult process(CommandSource source, String arguments) throws Comm
if (world == null) throw new CommandException(Text.of("Must specify a world!"));
double x, y, z;
Vector3d pPos = null;
if (source instanceof Player)
pPos = ((Player) source).getLocation().getPosition();
if (source instanceof Locatable)
pPos = ((Locatable) source).getLocation().getPosition();
if (parse.args.length == 0) {
if (pPos == null)
throw new CommandException(Text.of("Must specify coordinates!"));
Expand Down Expand Up @@ -154,24 +154,20 @@ public CommandResult process(CommandSource source, String arguments) throws Comm
if (selectedRegions.contains(region)) {
output.append(Text.of(TextColors.GRAY, "[+]"));
output.append(Text.of(TextColors.RED,
TextActions.runCommand("/foxguard s r remove " +
(region instanceof IWorldRegion ? ("--w:" + ((IWorldRegion) region).getWorld() + " ") : "") +
region.getName()),
TextActions.runCommand("/foxguard s r remove " + FGUtil.genWorldFlag(region) + region.getName()),
TextActions.showText(Text.of("Remove from state buffer")),
"[-]"));
} else {
output.append(Text.of(TextColors.GREEN,
TextActions.runCommand("/foxguard s r add " +
(region instanceof IWorldRegion ? ("--w:" + ((IWorldRegion) region).getWorld().getName() + " ") : "") +
region.getName()),
TextActions.runCommand("/foxguard s r add " + FGUtil.genWorldFlag(region) + region.getName()),
TextActions.showText(Text.of("Add to state buffer")),
"[+]"));
output.append(Text.of(TextColors.GRAY, "[-]"));
}
output.append(Text.of(" "));
}
output.append(Text.of(FGUtil.getColorForObject(region),
TextActions.runCommand("/foxguard detail region" + (region instanceof IWorldRegion ? (" --w:" + ((IWorldRegion) region).getWorld().getName() + " ") : "") + region.getName()),
TextActions.runCommand("/foxguard detail region " + FGUtil.genWorldFlag(region) + region.getName()),
TextActions.showText(Text.of("View details")),
FGUtil.getRegionName(region, false)));
if (regionListIterator.hasNext()) output.append(Text.NEW_LINE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
import org.spongepowered.api.text.format.TextColors;
import org.spongepowered.api.util.GuavaCollectors;
import org.spongepowered.api.util.StartsWithPredicate;
import org.spongepowered.api.world.Locatable;
import org.spongepowered.api.world.Location;
import org.spongepowered.api.world.World;

Expand Down Expand Up @@ -97,7 +98,7 @@ public CommandResult process(CommandSource source, String arguments) throws Comm
World world = null;
if (region == null) {
String worldName = parse.flags.get("world");
if (source instanceof Player) world = ((Player) source).getWorld();
if (source instanceof Locatable) world = ((Locatable) source).getWorld();
if (!worldName.isEmpty()) {
Optional<World> optWorld = Sponge.getGame().getServer().getWorld(worldName);
if (optWorld.isPresent()) {
Expand Down Expand Up @@ -143,7 +144,7 @@ public List<String> getSuggestions(CommandSource source, String arguments, @Null
if (parse.current.index == 0) {
String worldName = parse.flags.get("world");
World world = null;
if (source instanceof Player) world = ((Player) source).getWorld();
if (source instanceof Locatable) world = ((Locatable) source).getWorld();
if (!worldName.isEmpty()) {
Optional<World> optWorld = Sponge.getGame().getServer().getWorld(worldName);
if (optWorld.isPresent()) {
Expand All @@ -165,7 +166,7 @@ public List<String> getSuggestions(CommandSource source, String arguments, @Null
if (region == null) {
String worldName = parse.flags.get("world");
World world = null;
if (source instanceof Player) world = ((Player) source).getWorld();
if (source instanceof Locatable) world = ((Locatable) source).getWorld();
if (!worldName.isEmpty()) {
Optional<World> optWorld = Sponge.getGame().getServer().getWorld(worldName);
if (optWorld.isPresent()) {
Expand Down
Loading

0 comments on commit 78b8457

Please sign in to comment.