Beginnings of a proper hook for world protection. Client intiates a request to the server. Server validates if the request is going to be allowed (via an event). If the event is not canceled, then the server allows the action to occur.
This commit is contained in:
parent
9ece2719de
commit
c078794880
7 changed files with 136 additions and 14 deletions
|
@ -21,6 +21,7 @@ import ee3.client.core.handlers.RenderTickHandler;
|
|||
import ee3.common.block.ModBlocks;
|
||||
import ee3.common.core.CommonProxy;
|
||||
import ee3.common.core.CreativeTabEE3;
|
||||
import ee3.common.core.handlers.ModActionHandler;
|
||||
import ee3.common.core.handlers.AddonHandler;
|
||||
import ee3.common.core.handlers.ConfigurationHandler;
|
||||
import ee3.common.core.handlers.EntityLivingHandler;
|
||||
|
@ -30,6 +31,7 @@ import ee3.common.core.handlers.LocalizationHandler;
|
|||
import ee3.common.core.handlers.PacketHandler;
|
||||
import ee3.common.core.handlers.PlayerDestroyItemHandler;
|
||||
import ee3.common.core.handlers.VersionCheckTickHandler;
|
||||
import ee3.common.core.handlers.WorldTransmutationHandler;
|
||||
import ee3.common.core.helper.LogHelper;
|
||||
import ee3.common.core.helper.VersionHelper;
|
||||
import ee3.common.item.ModItems;
|
||||
|
@ -108,6 +110,10 @@ public class EquivalentExchange3 {
|
|||
// Register the EntityLiving Handler
|
||||
MinecraftForge.EVENT_BUS.register(new EntityLivingHandler());
|
||||
|
||||
MinecraftForge.EVENT_BUS.register(new ModActionHandler());
|
||||
|
||||
MinecraftForge.EVENT_BUS.register(new WorldTransmutationHandler());
|
||||
|
||||
// Register the DrawBlockHighlight Handler
|
||||
proxy.registerDrawBlockHighlightHandler();
|
||||
|
||||
|
|
13
ee3_common/ee3/common/core/handlers/ModActionHandler.java
Normal file
13
ee3_common/ee3/common/core/handlers/ModActionHandler.java
Normal file
|
@ -0,0 +1,13 @@
|
|||
package ee3.common.core.handlers;
|
||||
|
||||
import ee3.common.event.ModActionEvent;
|
||||
import net.minecraftforge.event.ForgeSubscribe;
|
||||
|
||||
public class ModActionHandler {
|
||||
|
||||
@ForgeSubscribe
|
||||
public void onModActionEvent(ModActionEvent event) {
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,14 @@
|
|||
package ee3.common.core.handlers;
|
||||
|
||||
import ee3.common.event.WorldTransmutationEvent;
|
||||
import net.minecraftforge.event.ForgeSubscribe;
|
||||
|
||||
|
||||
public class WorldTransmutationHandler {
|
||||
|
||||
@ForgeSubscribe
|
||||
public void onWorldTransmutationEvent(WorldTransmutationEvent event) {
|
||||
System.out.println(event.toString());
|
||||
}
|
||||
|
||||
}
|
39
ee3_common/ee3/common/event/ModActionEvent.java
Normal file
39
ee3_common/ee3/common/event/ModActionEvent.java
Normal file
|
@ -0,0 +1,39 @@
|
|||
package ee3.common.event;
|
||||
|
||||
import static net.minecraftforge.event.Event.Result.DEFAULT;
|
||||
import static net.minecraftforge.event.Event.Result.DENY;
|
||||
import ee3.common.lib.ModAction;
|
||||
import net.minecraft.src.EntityPlayer;
|
||||
import net.minecraftforge.event.Cancelable;
|
||||
import net.minecraftforge.event.entity.player.PlayerEvent;
|
||||
|
||||
@Cancelable
|
||||
public class ModActionEvent extends PlayerEvent {
|
||||
|
||||
public final ModAction modAction;
|
||||
public final int x, y, z;
|
||||
public final int sideHit;
|
||||
|
||||
public Result allowEvent;
|
||||
|
||||
public ModActionEvent(EntityPlayer player, ModAction modAction, int x, int y, int z, int sideHit) {
|
||||
|
||||
super(player);
|
||||
this.modAction = modAction;
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
this.sideHit = sideHit;
|
||||
if (sideHit == -1) {
|
||||
allowEvent = DENY;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCanceled(boolean cancel)
|
||||
{
|
||||
super.setCanceled(cancel);
|
||||
allowEvent = (cancel ? DENY : allowEvent == DENY ? DENY : DEFAULT);
|
||||
}
|
||||
|
||||
}
|
29
ee3_common/ee3/common/event/WorldTransmutationEvent.java
Normal file
29
ee3_common/ee3/common/event/WorldTransmutationEvent.java
Normal file
|
@ -0,0 +1,29 @@
|
|||
package ee3.common.event;
|
||||
|
||||
import net.minecraft.src.EntityPlayer;
|
||||
import net.minecraft.src.World;
|
||||
import net.minecraftforge.event.Event;
|
||||
|
||||
public class WorldTransmutationEvent extends Event {
|
||||
|
||||
public final EntityPlayer player;
|
||||
public final World world;
|
||||
public final int originX, originY, originZ;
|
||||
public final byte sideHit;
|
||||
public final byte rangeX, rangeY, rangeZ;
|
||||
public final String data;
|
||||
|
||||
public WorldTransmutationEvent(EntityPlayer player, World world, int originX, int originY, int originZ, byte sideHit, byte rangeX, byte rangeY, byte rangeZ, String data) {
|
||||
|
||||
this.player = player;
|
||||
this.world = world;
|
||||
this.originX = originX;
|
||||
this.originY = originY;
|
||||
this.originZ = originZ;
|
||||
this.sideHit = sideHit;
|
||||
this.rangeX = rangeX;
|
||||
this.rangeY = rangeY;
|
||||
this.rangeZ = rangeZ;
|
||||
this.data = data;
|
||||
}
|
||||
}
|
14
ee3_common/ee3/common/lib/ModAction.java
Normal file
14
ee3_common/ee3/common/lib/ModAction.java
Normal file
|
@ -0,0 +1,14 @@
|
|||
package ee3.common.lib;
|
||||
|
||||
|
||||
public enum ModAction {
|
||||
|
||||
TRANSMUTATION(WorldEvents.TRANSMUTATION);
|
||||
|
||||
public int actionId;
|
||||
|
||||
ModAction(int actionId) {
|
||||
this.actionId = actionId;
|
||||
}
|
||||
|
||||
}
|
|
@ -7,7 +7,15 @@ import java.io.IOException;
|
|||
import net.minecraft.src.EntityPlayer;
|
||||
import net.minecraft.src.INetworkManager;
|
||||
import net.minecraft.src.World;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.event.Event;
|
||||
import net.minecraftforge.event.Event.Result;
|
||||
import net.minecraftforge.event.entity.player.PlayerInteractEvent.Action;
|
||||
import cpw.mods.fml.common.network.Player;
|
||||
import ee3.common.event.ModActionEvent;
|
||||
import ee3.common.event.WorldTransmutationEvent;
|
||||
import ee3.common.lib.ModAction;
|
||||
import ee3.common.lib.WorldEvents;
|
||||
|
||||
public class PacketWorldEvent extends PacketEE {
|
||||
|
||||
|
@ -92,20 +100,6 @@ public class PacketWorldEvent extends PacketEE {
|
|||
|
||||
public void execute(INetworkManager manager, Player player) {
|
||||
|
||||
System.out.println("World Event Packet received");
|
||||
System.out.println("eventType: " + eventType);
|
||||
System.out.println("originX: " + originX);
|
||||
System.out.println("originY: " + originY);
|
||||
System.out.println("originZ: " + originZ);
|
||||
System.out.println("sideHit: " + sideHit);
|
||||
System.out.println("rangeX: " + rangeX);
|
||||
System.out.println("rangeY: " + rangeY);
|
||||
System.out.println("rangeZ: " + rangeZ);
|
||||
System.out.println("data: " + data);
|
||||
|
||||
EntityPlayer thePlayer = (EntityPlayer) player;
|
||||
World world = thePlayer.worldObj;
|
||||
|
||||
/*
|
||||
* Server knows the world, the player, and all the packet data
|
||||
* Server checks (for each block);
|
||||
|
@ -117,6 +111,19 @@ public class PacketWorldEvent extends PacketEE {
|
|||
* so Range would be 1, 2, 4, 6
|
||||
* 1 + 0, 1 + 1, 1 + 3, 1 + 5
|
||||
*/
|
||||
|
||||
EntityPlayer thePlayer = (EntityPlayer) player;
|
||||
ModActionEvent modActionEvent;
|
||||
WorldTransmutationEvent worldTransmutationEvent;
|
||||
|
||||
modActionEvent= new ModActionEvent(thePlayer, ModAction.TRANSMUTATION, originX, originY, originZ, (int) sideHit);
|
||||
MinecraftForge.EVENT_BUS.post(modActionEvent);
|
||||
|
||||
if (modActionEvent.allowEvent != Result.DENY) {
|
||||
worldTransmutationEvent = new WorldTransmutationEvent(thePlayer, thePlayer.worldObj, originX, originY, originZ, sideHit, rangeX, rangeY, rangeZ, data);
|
||||
MinecraftForge.EVENT_BUS.post(worldTransmutationEvent);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue