Skip to content

Commit

Permalink
Added a bunch of things.
Browse files Browse the repository at this point in the history
Added movement flags.
Bug fixes.
A lot of changes.
  • Loading branch information
gravityfox committed Jan 17, 2016
1 parent 93da82a commit 1183382
Show file tree
Hide file tree
Showing 26 changed files with 641 additions and 142 deletions.
2 changes: 1 addition & 1 deletion FoxCore
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@

import java.io.File;
import java.io.IOException;
import java.util.EnumMap;
import java.util.Map;

public final class FGConfigManager {

Expand All @@ -41,6 +43,7 @@ public final class FGConfigManager {
private boolean forceLoad;
private boolean purgeDatabases;

private Map<Module, Boolean> modules = new EnumMap<>(Module.class);

public FGConfigManager() {
if (instance == null) instance = this;
Expand Down Expand Up @@ -71,6 +74,9 @@ private void load() {

forceLoad = root.getNode("storage", "forceLoad").getBoolean(false);
purgeDatabases = root.getNode("storage", "purgeDatabases").getBoolean(true);
for (Module m : Module.values()) {
this.modules.put(m, root.getNode("module", m.name).getBoolean(true));
}

//--------------------------------------------------------------------------------------------------------------
}
Expand Down Expand Up @@ -108,6 +114,11 @@ public void save() {
"However, they will still be overwritten if a new database is made with the same name.")
.setValue(purgeDatabases);

for (Module m : Module.values()) {
root.getNode("module", m.name).setValue(this.modules.get(m));
}


//--------------------------------------------------------------------------------------------------------------
try {
loader.save(root);
Expand All @@ -124,4 +135,18 @@ public boolean purgeDatabases() {
return purgeDatabases;
}

public Map<Module, Boolean> getModules() {
return this.modules;
}

public enum Module {
MOVEMENT("movement");

String name;

Module(String name) {
this.name = name;
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,16 @@
import com.flowpowered.math.vector.Vector3i;
import com.google.common.collect.ImmutableList;
import net.foxdenstudio.sponge.foxcore.plugin.util.CallbackHashMap;
import net.foxdenstudio.sponge.foxguard.plugin.event.FGUpdateEvent;
import net.foxdenstudio.sponge.foxguard.plugin.event.FGUpdateObjectEvent;
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.region.GlobalRegion;
import net.foxdenstudio.sponge.foxguard.plugin.region.IRegion;
import org.spongepowered.api.Server;
import org.spongepowered.api.Sponge;
import org.spongepowered.api.event.cause.Cause;
import org.spongepowered.api.world.World;

import java.util.ArrayList;
Expand Down Expand Up @@ -92,6 +96,17 @@ public boolean addRegion(World world, IRegion region) {
region.setWorld(world);
this.regions.get(world).add(region);
this.regionCache.get(world).clear();
Sponge.getGame().getEventManager().post(new FGUpdateObjectEvent() {
@Override
public IFGObject getTarget() {
return region;
}

@Override
public Cause getCause() {
return Cause.of(FoxGuardMain.instance());
}
});
FGStorageManager.getInstance().unmarkForDeletion(region);
FGStorageManager.getInstance().updateRegion(region);
return true;
Expand Down Expand Up @@ -133,6 +148,17 @@ public boolean addHandler(IHandler handler) {
if (handler == null) return false;
if (gethandler(handler.getName()) != null) return false;
handlers.add(handler);
Sponge.getGame().getEventManager().post(new FGUpdateObjectEvent() {
@Override
public IFGObject getTarget() {
return handler;
}

@Override
public Cause getCause() {
return Cause.of(FoxGuardMain.instance());
}
});
FGStorageManager.getInstance().unmarkForDeletion(handler);
FGStorageManager.getInstance().updateHandler(handler);
return true;
Expand Down Expand Up @@ -161,6 +187,17 @@ private boolean removeHandler(IHandler handler) {
if (!this.handlers.contains(handler)) {
return false;
}
Sponge.getGame().getEventManager().post(new FGUpdateObjectEvent() {
@Override
public IFGObject getTarget() {
return handler;
}

@Override
public Cause getCause() {
return Cause.of(FoxGuardMain.instance());
}
});
FGStorageManager.getInstance().markForDeletion(handler);
handlers.remove(handler);
return true;
Expand All @@ -180,6 +217,17 @@ private boolean removeRegion(World world, IRegion region) {
if (!this.regions.get(world).contains(region)) {
return false;
}
Sponge.getGame().getEventManager().post(new FGUpdateObjectEvent() {
@Override
public IFGObject getTarget() {
return region;
}

@Override
public Cause getCause() {
return Cause.of(FoxGuardMain.instance());
}
});
FGStorageManager.getInstance().markForDeletion(region);
this.regions.get(world).remove(region);
this.regionCache.get(world).clear();
Expand All @@ -199,6 +247,12 @@ public boolean link(World world, String regionName, String handlerName) {

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

Expand All @@ -215,6 +269,12 @@ private boolean unlink(World world, String regionName, String handlerName) {

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

Expand Down Expand Up @@ -255,7 +315,7 @@ public void populateWorld(World world) {
addRegion(world, gr);
}

public void unloadWorld(World world){
public void unloadWorld(World world) {
this.regions.remove(world);
}

Expand All @@ -266,6 +326,7 @@ public GlobalHandler getGlobalHandler() {
private List<IRegion> calculateRegionsForChunk(Vector3i chunk, World world) {
List<IRegion> cache = new ArrayList<>();
this.getRegionsList(world).stream()
.filter(IFGObject::isEnabled)
.filter(region -> region.isInChunk(chunk))
.forEach(cache::add);
return cache;
Expand Down
Loading

0 comments on commit 1183382

Please sign in to comment.