Skip to content

Commit

Permalink
lots and lots of changes.
Browse files Browse the repository at this point in the history
  • Loading branch information
gravityfox committed Oct 30, 2016
1 parent 2f3871e commit 6f0c18b
Show file tree
Hide file tree
Showing 26 changed files with 613 additions and 551 deletions.
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#Wed Oct 19 05:45:51 PDT 2016
#Wed Oct 19 06:20:21 PDT 2016
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import net.foxdenstudio.sponge.foxcore.plugin.state.FCStateManager;
import net.foxdenstudio.sponge.foxcore.plugin.util.Aliases;
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;
Expand All @@ -51,6 +52,7 @@
import net.minecrell.mcstats.SpongeStatsLite;
import org.slf4j.Logger;
import org.spongepowered.api.Game;
import org.spongepowered.api.Sponge;
import org.spongepowered.api.command.CommandCallable;
import org.spongepowered.api.command.CommandMapping;
import org.spongepowered.api.config.ConfigDir;
Expand All @@ -71,6 +73,7 @@
import org.spongepowered.api.plugin.Dependency;
import org.spongepowered.api.plugin.Plugin;
import org.spongepowered.api.plugin.PluginContainer;
import org.spongepowered.api.service.economy.EconomyService;
import org.spongepowered.api.service.permission.PermissionService;
import org.spongepowered.api.service.permission.SubjectData;
import org.spongepowered.api.service.user.UserStorageService;
Expand All @@ -81,6 +84,7 @@
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Optional;
import java.util.Set;

@Plugin(id = "foxguard",
Expand Down Expand Up @@ -120,6 +124,7 @@ public final class FoxGuardMain {
private SpongeStatsLite stats;

private UserStorageService userStorage;
private EconomyService economyService = null;

private boolean loaded = false;

Expand All @@ -135,28 +140,28 @@ public static FoxGuardMain instance() {
//my uuid - f275f223-1643-4fac-9fb8-44aaf5b4b371

@Listener
public void gameConstruct(GameConstructionEvent event) {
public void construct(GameConstructionEvent event) {
instanceField = this;
}

@Listener
public void gamePreInit(GamePreInitializationEvent event) {
public void preInit(GamePreInitializationEvent event) {
logger.info("Beginning FoxGuard initialization");
logger.info("Version: " + container.getVersion().orElse("Unknown"));
logger.info("Loading configs");
new FGConfigManager();
logger.info("Saving configs");
FGConfigManager.getInstance().save();

logger.info("Initializing FoxGuard manager instance");
FGManager.init();

logger.info("Starting MCStats metrics extension");
stats.start();
}

@Listener
public void gameInit(GameInitializationEvent event) {
logger.info("Initializing FoxGuard manager instance");
FGManager.init();

public void init(GameInitializationEvent event) {
logger.info("Registering regions state field");
FCStateManager.instance().registerStateFactory(new RegionsStateFieldFactory(), RegionsStateField.ID, RegionsStateField.ID, Aliases.REGIONS_ALIASES);
logger.info("Registering handlers state field");
Expand All @@ -165,10 +170,6 @@ public void gameInit(GameInitializationEvent event) {
FCStateManager.instance().registerStateFactory(new ControllersStateFieldFactory(), ControllersStateField.ID, ControllersStateField.ID, Aliases.CONTROLLERS_ALIASES);
logger.info("Registering FoxGuard object factories");
registerFactories();
logger.info("Registering commands");
registerCommands();
logger.info("Setting default player permissions");
configurePermissions();
logger.info("Getting User Storage");
userStorage = game.getServiceManager().provide(UserStorageService.class).get();
logger.info("Registering event listeners");
Expand All @@ -189,36 +190,8 @@ public void serverStarting(GameStartingServerEvent event) {
}

@Listener
public void serverStopping(GameStoppingServerEvent event) {
FGStorageManager.getInstance().saveRegions();
FGStorageManager.getInstance().saveHandlers();
logger.info("Saving configs");
FGConfigManager.getInstance().save();
}

@Listener
public void worldUnload(UnloadWorldEvent event) {
logger.info("Unloading world \"" + event.getTargetWorld().getName() + "\"");
FGStorageManager.getInstance().saveWorldRegions(event.getTargetWorld());
FGManager.getInstance().unloadWorld(event.getTargetWorld());
}

@Listener
public void worldLoad(LoadWorldEvent event) {
logger.info("Initializing global worldregion for world: \"" + event.getTargetWorld().getName() + "\"");
FGManager.getInstance().initWorld(event.getTargetWorld());
logger.info("Loading worldregions for world: \"" + event.getTargetWorld().getName() + "\"");
FGStorageManager.getInstance().loadWorldRegions(event.getTargetWorld());
if (loaded) {
logger.info("Loading links for world : \"" + event.getTargetWorld().getName() + "\"");
FGStorageManager.getInstance().loadWorldRegionLinks(event.getTargetWorld());
}
}

/**
* A private method that registers the list of commands, their aliases, and the command class.
*/
private void registerCommands() {
public void registerCommands(GameInitializationEvent event) {
logger.info("Registering commands");
fgDispatcher = new FCCommandDispatcher("/foxguard",
"FoxGuard commands for managing world protection. Use /help foxguard for subcommands.");

Expand All @@ -245,6 +218,50 @@ private void registerCommands() {
game.getCommandManager().register(this, fgDispatcher, "foxguard", "foxg", "fguard", "fg");
}

@Listener
public void setupEconomy(GamePostInitializationEvent event) {
Optional<EconomyService> economyServiceOptional = Sponge.getGame().getServiceManager().provide(EconomyService.class);
if(economyServiceOptional.isPresent()){
economyService = economyServiceOptional.get();

}
}

@Listener
public void configurePermissions(GamePostInitializationEvent event) {
logger.info("Configuring permissions");
PermissionService service = game.getServiceManager().provide(PermissionService.class).get();
service.getDefaultData().setPermission(SubjectData.GLOBAL_CONTEXT, "foxguard.override", Tristate.FALSE);
service.registerContextCalculator(new FGContextCalculator());
}

@Listener
public void serverStopping(GameStoppingServerEvent event) {
FGStorageManager.getInstance().saveRegions();
FGStorageManager.getInstance().saveHandlers();
logger.info("Saving configs");
FGConfigManager.getInstance().save();
}

@Listener
public void worldUnload(UnloadWorldEvent event) {
logger.info("Unloading world \"" + event.getTargetWorld().getName() + "\"");
FGStorageManager.getInstance().saveWorldRegions(event.getTargetWorld());
FGManager.getInstance().unloadWorld(event.getTargetWorld());
}

@Listener
public void worldLoad(LoadWorldEvent event) {
logger.info("Initializing global worldregion for world: \"" + event.getTargetWorld().getName() + "\"");
FGManager.getInstance().initWorld(event.getTargetWorld());
logger.info("Loading worldregions for world: \"" + event.getTargetWorld().getName() + "\"");
FGStorageManager.getInstance().loadWorldRegions(event.getTargetWorld());
if (loaded) {
logger.info("Loading links for world : \"" + event.getTargetWorld().getName() + "\"");
FGStorageManager.getInstance().loadWorldRegionLinks(event.getTargetWorld());
}
}

private void registerCoreCommands(FCCommandDispatcher dispatcher) {
Text.Builder builder = Text.builder();
builder.append(Text.of(TextColors.GOLD, "FoxGuard World Protection Plugin\n"));
Expand Down Expand Up @@ -272,9 +289,10 @@ private void registerFactories() {
manager.registerHandlerFactory(new DebugHandler.Factory());

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


/**
* A private method that registers the Listener class and the corresponding event class.
*/
Expand All @@ -293,15 +311,6 @@ private void registerListeners() {
eventManager.registerListener(this, DamageEntityEvent.class, Order.LATE, new DamageListener());
}

/**
* A private method that sets up the permissions.
*/
private void configurePermissions() {
PermissionService service = game.getServiceManager().provide(PermissionService.class).get();
service.getDefaultData().setPermission(SubjectData.GLOBAL_CONTEXT, "foxguard.override", Tristate.FALSE);
service.registerContextCalculator(new FGContextCalculator());
}

/**
* @return A Logger instance for this plugin.
*/
Expand Down Expand Up @@ -341,4 +350,8 @@ public boolean isLoaded() {
public static Cause getCause() {
return instance().pluginCause;
}

public EconomyService getEconomyService() {
return economyService;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
import javax.annotation.Nullable;
import java.util.List;
import java.util.Optional;
import java.util.stream.Stream;

import static net.foxdenstudio.sponge.foxcore.plugin.util.Aliases.*;

Expand Down Expand Up @@ -290,7 +291,9 @@ private void outboundLinks(Text.Builder builder, ILinkable linkable, CommandSour
builder.append(Text.of(TextColors.GREEN, "\n------- Outbound Links -------"));
if (linkable.getHandlers().size() == 0)
builder.append(Text.of(TextStyles.ITALIC, "\nNo outbound links!"));
linkable.getHandlers().stream().sorted((o1, o2) -> o1.getName().compareToIgnoreCase(o2.getName())).forEach(handler -> {
Stream<IHandler> handlerStream = linkable.getHandlers().stream();
if(!(linkable instanceof IController)) handlerStream = handlerStream.sorted((o1, o2) -> o1.getName().compareToIgnoreCase(o2.getName()));
handlerStream.forEach(handler -> {
builder.append(Text.NEW_LINE);
if (source instanceof Player) {
List<IHandler> selectedHandlers = FGUtil.getSelectedHandlers(source);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,33 +23,23 @@
* THE SOFTWARE.
*/

package net.foxdenstudio.sponge.foxguard.plugin.flag;
package net.foxdenstudio.sponge.foxguard.plugin.command.link;

import org.spongepowered.api.util.Tristate;
import net.foxdenstudio.sponge.foxguard.plugin.controller.IController;

import java.util.List;
import java.util.HashSet;
import java.util.Set;

/**
* Created by Fox on 4/2/2016.
* Created by Fox on 10/24/2016.
*/
public interface IFlag {
public class CyclicLinkChecker {

String flagName();
Set<IController> network = new HashSet<>();
Set<LinkEntry> proposedLinks;

IFlag[] getParents();
public CyclicLinkChecker(Set<LinkEntry> proposedLinks) {
this.proposedLinks = proposedLinks;
}

/**
* Gets the hierarchy of the flag. This behavior is very specific, and is already implemented in
* {@link FlagOld#getHierarchyStatic(IFlag)} for use by other plugins wishing to implement {@code IFlag}.
*
* @return A list of ordered sets representing the hierarchy of the flag.
*/
List<Set<IFlag>> getHierarchy();

/**
* @param input
* @return
*/
Tristate resolve(Tristate input);
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
/**
* Created by Fox on 4/20/2016.
*/
public class LinkEntry {
public final class LinkEntry {

public ILinkable linkable;
public IHandler handler;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import net.foxdenstudio.sponge.foxcore.common.util.CacheMap;
import net.foxdenstudio.sponge.foxcore.plugin.util.Aliases;
import net.foxdenstudio.sponge.foxguard.plugin.FGManager;
import net.foxdenstudio.sponge.foxguard.plugin.controller.IController;
Expand All @@ -51,7 +52,7 @@
/**
* Created by Fox on 4/19/2016.
*/
public class LinkageParser {
public final class LinkageParser {

private static final String REGEX = "[>()]|([\"'])(?:\\\\.|[^\\\\>(),])*?\\1|(?:\\\\.|[^\"'\\s>(),])+";
private static final Pattern PATTERN = Pattern.compile(REGEX);
Expand Down Expand Up @@ -230,17 +231,15 @@ private Set<IExpression> parseSegment(String segmentString, CommandSource source
} else if (Aliases.isIn(Aliases.CONTROLLERS_ALIASES, name)) {
set.add(new ExpressionStub(ImmutableSet.copyOf(FGUtil.getSelectedControllers(source))));
}
} else if (token.startsWith("^")) {
IController controller = FGManager.getInstance().getController(token.substring(1));
if (controller != null) stubObjects.add(controller);
} else if (stage == Stage.START) {
IRegion region = FGManager.getInstance().getRegionFromWorld(currentWorld, token);
if (region != null) stubObjects.add(region);
} else {
if (token.startsWith("^")) {
IController controller = FGManager.getInstance().getController(token.substring(1));
if (controller != null) stubObjects.add(controller);
} else if (stage == Stage.START) {
IRegion region = FGManager.getInstance().getRegionFromWorld(currentWorld, token);
if (region != null) stubObjects.add(region);
} else {
IHandler handler = FGManager.getInstance().gethandler(token);
if (handler != null) stubObjects.add(handler);
}
IHandler handler = FGManager.getInstance().gethandler(token);
if (handler != null) stubObjects.add(handler);
}
}
}
Expand Down Expand Up @@ -298,7 +297,8 @@ public Set<LinkEntry> getLinks() {
}

public class Result {

public Set<LinkEntry> entries = new HashSet<>();
public Map<String, String> flags = new CacheMap<>((k, m) -> "");
}

public class ExpressionStub implements IExpression {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,12 @@
import net.foxdenstudio.sponge.foxguard.plugin.FGManager;
import net.foxdenstudio.sponge.foxguard.plugin.handler.HandlerBase;
import net.foxdenstudio.sponge.foxguard.plugin.handler.IHandler;
import net.foxdenstudio.sponge.foxguard.plugin.object.IFGObject;
import org.mapdb.DB;
import org.mapdb.DBMaker;
import org.mapdb.Serializer;

import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;

Expand Down Expand Up @@ -64,4 +69,25 @@ public void clearHandlers() {
this.handlers.clear();
}

@Override
public void loadLinks(Path directory) {
try (DB linksDB = DBMaker.fileDB(directory.resolve("links.foxdb").normalize().toString()).make()) {
List<String> linksList = linksDB.indexTreeList("links", Serializer.STRING).createOrOpen();
handlers.clear();
linksList.stream()
.filter(name -> !this.name.equalsIgnoreCase(name))
.map(name -> FGManager.getInstance().gethandler(name))
.filter(handler -> handler != null)
.forEach(handlers::add);

}
}

protected void saveLinks(Path directory){
try (DB linksDB = DBMaker.fileDB(directory.resolve("links.foxdb").normalize().toString()).make()) {
List<String> linksList = linksDB.indexTreeList("links", Serializer.STRING).createOrOpen();
linksList.clear();
handlers.stream().map(IFGObject::getName).forEach(linksList::add);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,8 @@ public interface IController extends IHandler, ILinkable {
*/
int maxLinks();

default boolean canLinkToItself() {
return false;
}

}
Loading

0 comments on commit 6f0c18b

Please sign in to comment.