Skip to content

Commit

Permalink
More changes.
Browse files Browse the repository at this point in the history
  • Loading branch information
gravityfox committed Jul 11, 2016
1 parent e69b344 commit 8a563ec
Show file tree
Hide file tree
Showing 15 changed files with 117 additions and 158 deletions.
8 changes: 5 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,12 @@ genEventImpl {
includeSrc = [
'src/main/java/net/foxdenstudio/sponge/foxguard/plugin/event'
]
excludeSrc = []
excludeSrc = [
'src/main/java/net/foxdenstudio/sponge/foxguard/plugin/event/util'
]
outputDir = 'src/main/java/'
outputFactory = 'net.foxdenstudio.sponge.foxguard.util.FoxGuardEventFactory'
eventImplCreateMethod = 'net.foxdenstudio.sponge.foxguard.util.FGUtil.createEventImpl'
outputFactory = 'net.foxdenstudio.sponge.foxguard.plugin.event.util.FGEventFactory'
eventImplCreateMethod = 'org.spongepowered.api.event.SpongeEventFactoryUtils.createEventImpl'
sortPriorityPrefix = 'original'
groupingPrefixes = ['from': 'to']
validateCode = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
import net.foxdenstudio.sponge.foxguard.plugin.controller.IController;
import net.foxdenstudio.sponge.foxguard.plugin.event.FGUpdateEvent;
import net.foxdenstudio.sponge.foxguard.plugin.event.FGUpdateObjectEvent;
import net.foxdenstudio.sponge.foxguard.plugin.event.FoxGuardEvent;
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;
Expand Down Expand Up @@ -139,17 +141,7 @@ public boolean addWorldRegion(World world, IWorldRegion region) {
this.worldRegions.get(world).add(region);
this.regionCache.markDirty(region, RegionCache.DirtyType.ADDED);
FGStorageManager.getInstance().addObject(region);
Sponge.getGame().getEventManager().post(new FGUpdateObjectEvent() {
@Override
public IFGObject getTarget() {
return region;
}

@Override
public Cause getCause() {
return FoxGuardMain.getCause();
}
});
Sponge.getGame().getEventManager().post(FGEventFactory.createFGUpdateObjectEvent(FoxGuardMain.getCause(), region));
return true;
}

Expand All @@ -158,17 +150,7 @@ public boolean addRegion(IRegion region) {
this.regions.add(region);
this.regionCache.markDirty(region, RegionCache.DirtyType.ADDED);
FGStorageManager.getInstance().addObject(region);
Sponge.getGame().getEventManager().post(new FGUpdateObjectEvent() {
@Override
public IFGObject getTarget() {
return region;
}

@Override
public Cause getCause() {
return FoxGuardMain.getCause();
}
});
Sponge.getGame().getEventManager().post(FGEventFactory.createFGUpdateObjectEvent(FoxGuardMain.getCause(), region));
return true;
}

Expand Down Expand Up @@ -280,17 +262,7 @@ public boolean addHandler(IHandler handler) {
if (gethandler(handler.getName()) != null) return false;
handlers.add(handler);
FGStorageManager.getInstance().addObject(handler);
Sponge.getGame().getEventManager().post(new FGUpdateObjectEvent() {
@Override
public IFGObject getTarget() {
return handler;
}

@Override
public Cause getCause() {
return FoxGuardMain.getCause();
}
});
Sponge.getGame().getEventManager().post(FGEventFactory.createFGUpdateObjectEvent(FoxGuardMain.getCause(), handler));
return true;
}

Expand Down Expand Up @@ -323,17 +295,7 @@ public boolean removeHandler(IHandler handler) {
return false;
}
FGStorageManager.getInstance().removeObject(handler);
Sponge.getGame().getEventManager().post(new FGUpdateObjectEvent() {
@Override
public IFGObject getTarget() {
return handler;
}

@Override
public Cause getCause() {
return FoxGuardMain.getCause();
}
});
Sponge.getGame().getEventManager().post(FGEventFactory.createFGUpdateObjectEvent(FoxGuardMain.getCause(), handler));
handlers.remove(handler);
return true;
}
Expand All @@ -346,17 +308,7 @@ public boolean removeRegion(IRegion region) {
if (!this.regions.contains(region)) return false;
this.regions.remove(region);
FGStorageManager.getInstance().removeObject(region);
Sponge.getGame().getEventManager().post(new FGUpdateObjectEvent() {
@Override
public IFGObject getTarget() {
return region;
}

@Override
public Cause getCause() {
return FoxGuardMain.getCause();
}
});
Sponge.getGame().getEventManager().post(FGEventFactory.createFGUpdateObjectEvent(FoxGuardMain.getCause(), region));
this.regionCache.markDirty(region, RegionCache.DirtyType.REMOVED);
return true;
}
Expand All @@ -381,42 +333,21 @@ public boolean removeWorldRegion(IWorldRegion region) {
}
if (removed) {
FGStorageManager.getInstance().removeObject(region);
Sponge.getGame().getEventManager().post(new FGUpdateObjectEvent() {
@Override
public IFGObject getTarget() {
return region;
}

@Override
public Cause getCause() {
return FoxGuardMain.getCause();
}
});
// FGStorageManager.getInstance().markForDeletion(region);
Sponge.getGame().getEventManager().post(FGEventFactory.createFGUpdateObjectEvent(FoxGuardMain.getCause(), region));
this.regionCache.markDirty(region, RegionCache.DirtyType.REMOVED);
}
return removed;
}

public boolean link(ILinkable linkable, IHandler handler) {
if (linkable == null || handler == null || linkable.getHandlers().contains(handler)) return false;
Sponge.getGame().getEventManager().post(new FGUpdateEvent() {
@Override
public Cause getCause() {
return FoxGuardMain.getCause();
}
});
Sponge.getGame().getEventManager().post(FGEventFactory.createFGUpdateEvent(FoxGuardMain.getCause()));
return !(handler instanceof GlobalHandler && !(linkable instanceof GlobalWorldRegion || linkable instanceof GlobalRegion)) && linkable.addHandler(handler);
}

public boolean unlink(ILinkable linkable, IHandler handler) {
if (linkable == null || handler == null || !linkable.getHandlers().contains(handler)) return false;
Sponge.getGame().getEventManager().post(new FGUpdateEvent() {
@Override
public Cause getCause() {
return FoxGuardMain.getCause();
}
});
Sponge.getGame().getEventManager().post(FGEventFactory.createFGUpdateEvent(FoxGuardMain.getCause()));
return !(handler instanceof GlobalHandler) && linkable.removeHandler(handler);
}

Expand Down Expand Up @@ -463,4 +394,5 @@ public static boolean isNameValid(String name) {
public void markDirty(IRegion region, RegionCache.DirtyType type) {
regionCache.markDirty(region, type);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -544,7 +544,7 @@ public synchronized void loadRegions() {
logger.info("Region info loaded! Name: \"" + name +
"\", Category: \"" + category +
"\", Type: \"" + type +
"\", Enabled: \"" + enabled + "\"");
"\", Enabled: " + enabled);
if (name.equalsIgnoreCase(GlobalRegion.NAME)) {
logger.info("Global region found! Skipping...");
return;
Expand Down Expand Up @@ -626,10 +626,10 @@ public synchronized void loadWorldRegions(World world) {
type = metaDB.exists("type") ? metaDB.atomicString("type").createOrOpen().get() : typeMap.get(name);
enabled = metaDB.exists("enabled") ? metaDB.atomicBoolean("enabled").createOrOpen().get() : enabledMap.get(name);
}
logger.info("World region info loaded! Name: " + name +
logger.info("World region info loaded! Name: \"" + name +
"\", Category: \"" + category +
"\", Type: \"" + type +
"\", Enabled: \"" + enabled + "\"");
"\", Enabled: " + enabled);
if (name.equalsIgnoreCase(GlobalWorldRegion.NAME)) {
logger.info("Global world region found! Skipping...");
return;
Expand Down Expand Up @@ -714,11 +714,11 @@ public synchronized void loadHandlers() {
enabled = metaDB.exists("enabled") ? metaDB.atomicBoolean("enabled").createOrOpen().get() : enabledMap.get(name);
priority = metaDB.exists("priority") ? metaDB.atomicInteger("priority").createOrOpen().get() : priorityMap.get(name);
}
logger.info("Handler info loaded! Name: " + name +
logger.info("Handler info loaded! Name: \"" + name +
"\", Category: \"" + category +
"\", Type: \"" + type +
"\", Enabled: \"" + enabled +
"\", Priority: \"" + priority + "\"");
"\", Enabled: " + enabled +
", Priority: " + priority);
if (name.equalsIgnoreCase(GlobalHandler.NAME)) {
logger.info("Global handler found! Skipping...");
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ public void serverStopping(GameStoppingServerEvent event) {

@Listener
public void worldUnload(UnloadWorldEvent event) {
logger.info("Unloading world \"" + event.getTargetWorld().getName() + "\"");
FGStorageManager.getInstance().saveWorldRegions(event.getTargetWorld());
FGManager.getInstance().unloadWorld(event.getTargetWorld());
}
Expand Down Expand Up @@ -268,7 +269,7 @@ private void registerFactories() {
manager.registerHandlerFactory(new DebugHandler.Factory());

//manager.registerControllerFactory(new MessageController.Factory());
manager.registerControllerFactory(new LogicController.Factory());
//manager.registerControllerFactory(new LogicController.Factory());
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,9 @@ public CommandResult process(CommandSource source, String arguments) throws Comm
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(TextColors.GOLD, "Name: "), Text.of(TextColors.RESET, region.getName() + "\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.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()
.append(Text.of(TextColors.GOLD, "Enabled: "))
Expand All @@ -122,7 +124,9 @@ public CommandResult process(CommandSource source, String arguments) throws Comm
.build());
if (region instanceof IWorldRegion)
builder.append(Text.of(TextColors.GOLD, "World: "), Text.of(TextColors.RESET, ((IWorldRegion) region).getWorld().getName() + "\n"));
builder.append(Text.of(TextColors.GREEN, "------- Details -------\n"));
builder.append(Text.of(TextActions.suggestCommand("/foxguard modify region " + FGUtil.genWorldFlag(region) + region.getName() + " "),
TextActions.showText(Text.of("Click to modify region \"" + region.getName() + "\"")),
TextColors.GREEN, "------- Details -------\n"));
builder.append(region.details(source, parse.args.length < 3 ? "" : parse.args[2]));
outboundLinks(builder, region, source);
} else {
Expand All @@ -143,7 +147,9 @@ public CommandResult process(CommandSource source, String arguments) throws Comm
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(TextColors.GOLD, "Name: "), Text.of(TextColors.RESET, handler.getName() + "\n"));
builder.append(Text.of(TextActions.runCommand("/foxguard detail handler " + handler.getName()),
TextActions.showText(Text.of("View details for handler \"" + handler.getName() + "\"")),
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()
.append(Text.of(TextColors.GOLD, "Enabled: "))
Expand All @@ -157,7 +163,9 @@ public CommandResult process(CommandSource source, String arguments) throws Comm
.onClick(TextActions.suggestCommand("/foxguard prio " + handler.getName() + " "))
.onHover(TextActions.showText(Text.of("Click to change priority")))
.build());
builder.append(Text.of(TextColors.GREEN, "------- Details -------\n"));
builder.append(Text.of(TextActions.suggestCommand("/foxguard modify handler " + handler.getName() + " "),
TextActions.showText(Text.of("Click to modify handler \"" + handler.getName() + "\"")),
TextColors.GREEN, "------- Details -------\n"));
Text objectDetails = handler.details(source, parse.args.length < 3 ? "" : parse.args[2]);
if (objectDetails == null) objectDetails = Text.of();
builder.append(objectDetails);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public CommandResult process(CommandSource source, String arguments) throws Comm
if (parse.args.length < 2) throw new CommandException(Text.of("Must specify a handler!"));
IHandler handler = FGManager.getInstance().gethandler(parse.args[1]);
if (handler == null)
throw new CommandException(Text.of("No handler with name \"" + parse.args[0] + "\"!"));
throw new CommandException(Text.of("No handler with name \"" + parse.args[1] + "\"!"));
if (region.getHandlers().contains(handler))
throw new CommandException(Text.of("Already linked!"));
boolean success = FGManager.getInstance().link(region, handler);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ public List<String> getSuggestions(CommandSource source, String arguments) throw
.parse();
if (parse.current.type.equals(AdvCmdParser.CurrentElement.ElementType.ARGUMENT)) {
if (parse.current.index == 0)
return Arrays.asList(FGManager.TYPES).stream()
return Arrays.asList("regions", "handlers", "controllers").stream()
.filter(new StartsWithPredicate(parse.current.token))
.map(args -> parse.current.prefix + args)
.collect(GuavaCollectors.toImmutableList());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,40 +125,13 @@ public CommandResult process(CommandSource source, String arguments) throws Comm
"command!"));
return CommandResult.empty();
}
AdvCmdParser.ParseResult parse = AdvCmdParser.builder().arguments(arguments).parse();
if (parse.args.length > 0) {
Text.Builder builder = Text.builder();
builder.append(Text.of(TextColors.GOLD, "\n-----------------------------\n"));
IFlag flag = FlagOld.flagFrom(parse.args[0]);
if (flag != null) {
for (Set<IFlag> level : flag.getHierarchy()) {
for (IFlag f : level) {
builder.append(Text.of(f.flagName() + " "));
}
builder.append(Text.NEW_LINE);
}
source.sendMessage(builder.build());
}
}

return CommandResult.empty();
}


@Override
public List<String> getSuggestions(CommandSource source, String arguments) throws
CommandException {
if (!testPermission(source)) return ImmutableList.of();
AdvCmdParser.ParseResult parse = AdvCmdParser.builder()
.arguments(arguments)
.excludeCurrent(true)
.autoCloseQuotes(true)
.parse();
return FlagOld.getFlags().stream()
.map(IFlag::flagName)
.filter(new StartsWithPredicate(parse.current.token))
.map(args -> parse.current.prefix + args)
.collect(GuavaCollectors.toImmutableList());
public List<String> getSuggestions(CommandSource source, String arguments) throws CommandException {
return ImmutableList.of();
}

/*@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,18 @@
package net.foxdenstudio.sponge.foxguard.plugin.event;

import org.spongepowered.api.event.Event;
import org.spongepowered.api.event.cause.Cause;
import org.spongepowered.api.eventgencore.annotation.AbsoluteSortPosition;

public interface FoxGuardEvent extends Event {

/**
* Get the cause for the event.
*
* @return The last cause
*/
@Override
@AbsoluteSortPosition(0)
Cause getCause();

}
Loading

0 comments on commit 8a563ec

Please sign in to comment.