Skip to content

Commit

Permalink
Changed things and stuff.
Browse files Browse the repository at this point in the history
  • Loading branch information
gravityfox committed Jan 8, 2016
1 parent 00ca960 commit 5ec45e5
Show file tree
Hide file tree
Showing 9 changed files with 59 additions and 21 deletions.
2 changes: 1 addition & 1 deletion FoxCore
Original file line number Diff line number Diff line change
Expand Up @@ -147,9 +147,9 @@ public void gameInit(GameInitializationEvent event) {
logger.info("Setting default player permissions");
configurePermissions();
logger.info("Registering Regions state field");
FCStateManager.instance().registerStateFactory(new RegionsStateFieldFactory(), RegionsStateField.class, RegionsStateField.ID, RegionsStateField.ID, Aliases.REGIONS_ALIASES);
FCStateManager.instance().registerStateFactory(new RegionsStateFieldFactory(), RegionsStateField.ID, RegionsStateField.ID, Aliases.REGIONS_ALIASES);
logger.info("Registering Handlers state field");
FCStateManager.instance().registerStateFactory(new HandlersStateFieldFactory(),HandlersStateField.class, HandlersStateField.ID, HandlersStateField.ID, Aliases.HANDLERS_ALIASES);
FCStateManager.instance().registerStateFactory(new HandlersStateFieldFactory(), HandlersStateField.ID, HandlersStateField.ID, Aliases.HANDLERS_ALIASES);
logger.info("Starting MCStats metrics extension");
try {
Metrics metrics = new Metrics(game, game.getPluginManager().fromInstance(this).get());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
package net.foxdenstudio.sponge.foxguard.plugin.listener;

import com.flowpowered.math.GenericMath;
import com.flowpowered.math.vector.Vector2i;
import com.flowpowered.math.vector.Vector3i;
import net.foxdenstudio.sponge.foxcore.plugin.command.CommandDebug;
import net.foxdenstudio.sponge.foxguard.plugin.FGManager;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
package net.foxdenstudio.sponge.foxguard.plugin.listener;

import com.flowpowered.math.GenericMath;
import com.flowpowered.math.vector.Vector2i;
import com.flowpowered.math.vector.Vector3d;
import com.flowpowered.math.vector.Vector3i;
import net.foxdenstudio.sponge.foxguard.plugin.FGManager;
Expand Down Expand Up @@ -80,16 +79,6 @@ public void handle(InteractEvent event) throws Exception {
}
if (typeFlag == null) return;
List<IHandler> handlerList = new ArrayList<>();
/*
if (event.getInteractionPoint().isPresent()) {
loc = event.getInteractionPoint().get();
System.out.println(loc);
FGManager.instance().getRegionListAsStream(world).filter(region -> region.isInRegion(loc))
.forEach(region -> region.getHandlers().stream()
.filter(handler -> !handlerList.contains(handler))
.forEach(handlerList::add));
} else {
*/
final Vector3d finalLoc = loc;
Vector3i chunk = new Vector3i(
GenericMath.floor(loc.getX() / 16.0),
Expand All @@ -102,7 +91,7 @@ public void handle(InteractEvent event) throws Exception {
.filter(IFGObject::isEnabled)
.filter(handler -> !handlerList.contains(handler))
.forEach(handlerList::add));
//}

Collections.sort(handlerList);
int currPriority = handlerList.get(0).getPriority();
Tristate flagState = Tristate.UNDEFINED;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,19 @@
package net.foxdenstudio.sponge.foxguard.plugin.listener;

import com.flowpowered.math.GenericMath;
import com.flowpowered.math.vector.Vector3d;
import com.flowpowered.math.vector.Vector3i;
import com.google.common.collect.ImmutableList;
import net.foxdenstudio.sponge.foxguard.plugin.FGManager;
import net.foxdenstudio.sponge.foxguard.plugin.handler.IHandler;
import net.foxdenstudio.sponge.foxguard.plugin.object.IFGObject;
import org.spongepowered.api.entity.living.player.Player;
import org.spongepowered.api.event.EventListener;
import org.spongepowered.api.event.entity.DisplaceEntityEvent;
import org.spongepowered.api.world.World;

import java.util.Collections;
import java.util.LinkedList;

/**
* Created by Fox on 1/4/2016.
Expand All @@ -10,6 +22,45 @@
public class PlayerMoveListener implements EventListener<DisplaceEntityEvent.Move.TargetPlayer> {
@Override
public void handle(DisplaceEntityEvent.Move.TargetPlayer event) throws Exception {
if (event.isCancelled()) return;
Player player = event.getTargetEntity();
World world = player.getWorld();
Vector3d from = event.getFromTransform().getPosition(), to = event.getToTransform().getPosition();
LinkedList<IHandler> fromList = new LinkedList<>(), toList = new LinkedList<>();

FGManager.getInstance().getRegionsList(world, new Vector3i(
GenericMath.floor(from.getX() / 16.0),
GenericMath.floor(from.getY() / 16.0),
GenericMath.floor(from.getZ() / 16.0))).stream()
.filter(region -> region.isInRegion(from))
.filter(IFGObject::isEnabled)
.forEach(region -> region.getHandlers().stream()
.filter(IFGObject::isEnabled)
.filter(handler -> !fromList.contains(handler))
.forEach(fromList::add));

FGManager.getInstance().getRegionsList(world, new Vector3i(
GenericMath.floor(to.getX() / 16.0),
GenericMath.floor(to.getY() / 16.0),
GenericMath.floor(to.getZ() / 16.0))).stream()
.filter(region -> region.isInRegion(to))
.filter(IFGObject::isEnabled)
.forEach(region -> region.getHandlers().stream()
.filter(IFGObject::isEnabled)
.filter(handler -> !toList.contains(handler))
.forEach(toList::add));


ImmutableList.copyOf(fromList).stream()
.filter(toList::contains)
.forEach(handler -> {
fromList.remove(handler);
toList.remove(handler);
});

Collections.sort(fromList);
Collections.sort(toList);


}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@

package net.foxdenstudio.sponge.foxguard.plugin.region;

import com.flowpowered.math.vector.Vector2i;
import com.flowpowered.math.vector.Vector3d;
import com.flowpowered.math.vector.Vector3i;
import net.foxdenstudio.sponge.foxguard.plugin.object.IFGObject;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@

package net.foxdenstudio.sponge.foxguard.plugin.state.factory;

import net.foxdenstudio.sponge.foxcore.plugin.command.util.SourceState;
import net.foxdenstudio.sponge.foxcore.plugin.state.IStateField;
import net.foxdenstudio.sponge.foxcore.plugin.state.SourceState;
import net.foxdenstudio.sponge.foxcore.plugin.state.factory.IStateFieldFactory;
import net.foxdenstudio.sponge.foxguard.plugin.state.HandlersStateField;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@

package net.foxdenstudio.sponge.foxguard.plugin.state.factory;

import net.foxdenstudio.sponge.foxcore.plugin.command.util.SourceState;
import net.foxdenstudio.sponge.foxcore.plugin.state.IStateField;
import net.foxdenstudio.sponge.foxcore.plugin.state.SourceState;
import net.foxdenstudio.sponge.foxcore.plugin.state.factory.IStateFieldFactory;
import net.foxdenstudio.sponge.foxguard.plugin.state.RegionsStateField;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,12 @@ public static TextColor getColorForHandler(IHandler handler) {

@SuppressWarnings("unchecked")
public static List<IRegion> getSelectedRegions(CommandSource source) {
return ((RegionsStateField) FCStateManager.instance().getStateMap().get(source).get(RegionsStateField.ID)).getList();
return ((RegionsStateField) FCStateManager.instance().getStateMap().get(source).getOrCreate(RegionsStateField.ID).get()).getList();
}

@SuppressWarnings("unchecked")
public static List<IHandler> getSelectedHandlers(CommandSource source) {
return ((HandlersStateField) FCStateManager.instance().getStateMap().get(source).get(HandlersStateField.ID)).getList();
return ((HandlersStateField) FCStateManager.instance().getStateMap().get(source).getOrCreate(HandlersStateField.ID).get()).getList();
}

}

0 comments on commit 5ec45e5

Please sign in to comment.