Skip to content

Commit

Permalink
Lots of region bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
gravityfox committed Jul 16, 2016
1 parent 8a563ec commit 7bdb083
Show file tree
Hide file tree
Showing 12 changed files with 401 additions and 52 deletions.
2 changes: 1 addition & 1 deletion FoxCore
Original file line number Diff line number Diff line change
Expand Up @@ -395,4 +395,8 @@ public void markDirty(IRegion region, RegionCache.DirtyType type) {
regionCache.markDirty(region, type);
}

public void clearRegionCache(){
this.regionCache.clearCaches();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,9 @@ public CommandResult process(CommandSource source, String arguments) throws Comm
Text.Builder builder = Text.builder();
builder.append(Text.of(TextColors.GOLD, "\n-----------------------------------------------------\n"));
if (parse.args.length < 3 || parse.args[2].isEmpty() || parse.flags.containsKey("all")) {
builder.append(Text.of(TextColors.GREEN, "------- General -------\n"));
builder.append(Text.of(TextActions.runCommand("/foxguard detail region " + FGUtil.genWorldFlag(region) + region.getName()),
TextActions.showText(Text.of("View details for region \"" + region.getName() + "\"")),
TextColors.GREEN, "------- General -------\n",
TextColors.GOLD, "Name: ", TextColors.RESET, region.getName() + "\n"));
builder.append(Text.of(TextColors.GOLD, "Type: "), Text.of(TextColors.RESET, region.getLongTypeName() + "\n"));
builder.append(Text.builder()
Expand Down Expand Up @@ -146,9 +146,9 @@ public CommandResult process(CommandSource source, String arguments) throws Comm
Text.Builder builder = Text.builder();
builder.append(Text.of(TextColors.GOLD, "\n-----------------------------------------------------\n"));
if (parse.args.length <= 2 || parse.args[2].isEmpty() || parse.flags.containsKey("all")) {
builder.append(Text.of(TextColors.GREEN, "------- General -------\n"));
builder.append(Text.of(TextActions.runCommand("/foxguard detail handler " + handler.getName()),
TextActions.showText(Text.of("View details for handler \"" + handler.getName() + "\"")),
TextColors.GREEN, "------- General -------\n",
TextColors.GOLD, "Name: ", TextColors.RESET, handler.getName() + "\n"));
builder.append(Text.of(TextColors.GOLD, "Type: "), Text.of(TextColors.RESET, handler.getLongTypeName() + "\n"));
builder.append(Text.builder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,24 +31,25 @@
import net.foxdenstudio.sponge.foxcore.plugin.state.FCStateManager;
import net.foxdenstudio.sponge.foxguard.plugin.FGManager;
import net.foxdenstudio.sponge.foxguard.plugin.FoxGuardMain;
import net.foxdenstudio.sponge.foxguard.plugin.event.FGUpdateEvent;
import net.foxdenstudio.sponge.foxguard.plugin.event.util.FGEventFactory;
import net.foxdenstudio.sponge.foxguard.plugin.handler.GlobalHandler;
import net.foxdenstudio.sponge.foxguard.plugin.handler.IHandler;
import net.foxdenstudio.sponge.foxguard.plugin.object.IFGObject;
import net.foxdenstudio.sponge.foxguard.plugin.object.IGlobal;
import net.foxdenstudio.sponge.foxguard.plugin.region.IRegion;
import net.foxdenstudio.sponge.foxguard.plugin.region.world.GlobalWorldRegion;
import net.foxdenstudio.sponge.foxguard.plugin.region.world.IWorldRegion;
import net.foxdenstudio.sponge.foxguard.plugin.state.HandlersStateField;
import net.foxdenstudio.sponge.foxguard.plugin.state.RegionsStateField;
import net.foxdenstudio.sponge.foxguard.plugin.util.FGUtil;
import net.foxdenstudio.sponge.foxguard.plugin.util.RegionCache;
import org.spongepowered.api.Sponge;
import org.spongepowered.api.command.CommandCallable;
import org.spongepowered.api.command.CommandException;
import org.spongepowered.api.command.CommandResult;
import org.spongepowered.api.command.CommandSource;
import org.spongepowered.api.command.args.ArgumentParseException;
import org.spongepowered.api.entity.living.player.Player;
import org.spongepowered.api.event.cause.Cause;
import org.spongepowered.api.text.Text;
import org.spongepowered.api.text.format.TextColors;
import org.spongepowered.api.util.GuavaCollectors;
Expand Down Expand Up @@ -108,21 +109,11 @@ public CommandResult process(CommandSource source, String arguments) throws Comm
}
FCStateManager.instance().getStateMap().get(source).flush(RegionsStateField.ID, HandlersStateField.ID);
if (successes == 1 && failures == 0) {
Sponge.getGame().getEventManager().post(new FGUpdateEvent() {
@Override
public Cause getCause() {
return FoxGuardMain.getCause();
}
});
Sponge.getGame().getEventManager().post(FGEventFactory.createFGUpdateEvent(FoxGuardMain.getCause()));
source.sendMessage(Text.of(TextColors.GREEN, "Successfully " + (this.enableState ? "enabled" : "disabled") + " object!"));
return CommandResult.success();
} else if (successes > 0) {
Sponge.getGame().getEventManager().post(new FGUpdateEvent() {
@Override
public Cause getCause() {
return FoxGuardMain.getCause();
}
});
Sponge.getGame().getEventManager().post(FGEventFactory.createFGUpdateEvent(FoxGuardMain.getCause()));
source.sendMessage(Text.of(TextColors.GREEN, "Successfully " + (this.enableState ? "enabled" : "disabled") + " objects with "
+ successes + " successes" + (failures > 0 ? " and " + failures + " failures!" : "!")));
return CommandResult.builder().successCount(successes).build();
Expand Down Expand Up @@ -158,29 +149,19 @@ public Cause getCause() {
}
if (regions.isEmpty()) throw new CommandException(Text.of("Must specify at least one region!"));
for (IRegion region : regions) {
if (region instanceof GlobalWorldRegion || region.isEnabled() == this.enableState) failures++;
if (region instanceof IGlobal || region.isEnabled() == this.enableState) failures++;
else {
region.setIsEnabled(this.enableState);
successes++;
}
}
FCStateManager.instance().getStateMap().get(source).flush(RegionsStateField.ID);
if (successes == 1 && failures == 0) {
Sponge.getGame().getEventManager().post(new FGUpdateEvent() {
@Override
public Cause getCause() {
return FoxGuardMain.getCause();
}
});
Sponge.getGame().getEventManager().post(FGEventFactory.createFGUpdateEvent(FoxGuardMain.getCause()));
source.sendMessage(Text.of(TextColors.GREEN, "Successfully " + (this.enableState ? "enabled" : "disabled") + " region!"));
return CommandResult.success();
} else if (successes > 0) {
Sponge.getGame().getEventManager().post(new FGUpdateEvent() {
@Override
public Cause getCause() {
return FoxGuardMain.getCause();
}
});
Sponge.getGame().getEventManager().post(FGEventFactory.createFGUpdateEvent(FoxGuardMain.getCause()));
source.sendMessage(Text.of(TextColors.GREEN, "Successfully " + (this.enableState ? "enabled" : "disabled") + " regions with "
+ successes + " successes" + (failures > 0 ? " and " + failures + " failures!" : "!")));
return CommandResult.builder().successCount(successes).build();
Expand All @@ -205,29 +186,19 @@ public Cause getCause() {
}
if (handlers.isEmpty()) throw new CommandException(Text.of("Must specify at least one handler!"));
for (IHandler handler : handlers) {
if (handler instanceof GlobalHandler || handler.isEnabled() == this.enableState) failures++;
if (handler instanceof IGlobal || handler.isEnabled() == this.enableState) failures++;
else {
handler.setIsEnabled(this.enableState);
successes++;
}
}
FCStateManager.instance().getStateMap().get(source).flush(HandlersStateField.ID);
if (successes == 1 && failures == 0) {
Sponge.getGame().getEventManager().post(new FGUpdateEvent() {
@Override
public Cause getCause() {
return FoxGuardMain.getCause();
}
});
Sponge.getGame().getEventManager().post(FGEventFactory.createFGUpdateEvent(FoxGuardMain.getCause()));
source.sendMessage(Text.of(TextColors.GREEN, "Successfully " + (this.enableState ? "enabled" : "disabled") + " handler!"));
return CommandResult.success();
} else if (successes > 0) {
Sponge.getGame().getEventManager().post(new FGUpdateEvent() {
@Override
public Cause getCause() {
return FoxGuardMain.getCause();
}
});
Sponge.getGame().getEventManager().post(FGEventFactory.createFGUpdateEvent(FoxGuardMain.getCause()));
source.sendMessage(Text.of(TextColors.GREEN, "Successfully " + (this.enableState ? "enabled" : "disabled") + " handlers with "
+ successes + " successes" + (failures > 0 ? " and " + failures + " failures!" : "!")));
return CommandResult.builder().successCount(successes).build();
Expand Down Expand Up @@ -266,22 +237,22 @@ else if (parse.current.index > 0) {
}
}
if (world == null) return FGManager.getInstance().getRegions().stream()
.filter(region -> region.isEnabled() != this.enableState && !(region instanceof GlobalWorldRegion))
.filter(region -> region.isEnabled() != this.enableState && !(region instanceof IGlobal))
.map(IFGObject::getName)
.filter(new StartsWithPredicate(parse.current.token))
.filter(alias -> !isIn(parse.args, alias))
.map(args -> parse.current.prefix + args)
.collect(GuavaCollectors.toImmutableList());
return FGManager.getInstance().getAllRegions(world).stream()
.filter(region -> region.isEnabled() != this.enableState && !(region instanceof GlobalWorldRegion))
.filter(region -> region.isEnabled() != this.enableState && !(region instanceof IGlobal))
.map(IFGObject::getName)
.filter(new StartsWithPredicate(parse.current.token))
.filter(alias -> !isIn(parse.args, alias))
.map(args -> parse.current.prefix + args)
.collect(GuavaCollectors.toImmutableList());
} else if (isIn(HANDLERS_ALIASES, parse.args[0])) {
return FGManager.getInstance().getHandlers().stream()
.filter(handler -> handler.isEnabled() != this.enableState && !(handler instanceof GlobalHandler))
.filter(handler -> handler.isEnabled() != this.enableState && !(handler instanceof IGlobal))
.map(IFGObject::getName)
.filter(new StartsWithPredicate(parse.current.token))
.filter(alias -> !isIn(parse.args, alias))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -777,17 +777,17 @@ public EventResult handle(@Nullable User user, FlagBitSet flags, ExtraContext ex

@Override
public String getShortTypeName() {
return "Basic";
return "Group";
}

@Override
public String getLongTypeName() {
return "Basic";
return "Group";
}

@Override
public String getUniqueTypeString() {
return "basic";
return "group";
}

@Override
Expand Down Expand Up @@ -1207,7 +1207,7 @@ public String getPermission() {

public static class Factory implements IHandlerFactory {

private static final String[] ALIASES = {"basic", "base"};
private static final String[] ALIASES = {"group", "permgroup"};

@Override
public IHandler create(String name, int priority, String arguments, CommandSource source) throws CommandException {
Expand Down Expand Up @@ -1271,7 +1271,7 @@ public String[] getAliases() {

@Override
public String getType() {
return "basic";
return "group";
}

@Override
Expand Down
Loading

0 comments on commit 7bdb083

Please sign in to comment.