Skip to content

Instantly share code, notes, and snippets.

@wesserboy
Created July 2, 2014 10:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wesserboy/3a757d716d72e54b4731 to your computer and use it in GitHub Desktop.
Save wesserboy/3a757d716d72e54b4731 to your computer and use it in GitHub Desktop.
package chunkedPVP.eventHandlers;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.ChatComponentTranslation;
import net.minecraft.util.EntityDamageSource;
import net.minecraft.world.World;
import net.minecraft.world.chunk.Chunk;
import net.minecraftforge.event.entity.player.AttackEntityEvent;
import chunkedPVP.worldData.ChunkedPVPWorldData;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
public class LivingUpdateEventHandler {
@SubscribeEvent
public void onAttackEntityEvent(AttackEntityEvent event){
if(!event.entityPlayer.worldObj.isRemote){
if(event.target instanceof EntityPlayer){
World world = event.entityPlayer.worldObj;
ChunkedPVPWorldData data = ChunkedPVPWorldData.forWorld(world);
EntityPlayer player = event.entityPlayer;
Chunk chunk = world.getChunkFromBlockCoords((int)event.target.posX, (int)event.target.posZ);
if(!data.hasChunk(chunk)){
event.setCanceled(true);
player.addChatComponentMessage(new ChatComponentTranslation("PVP is not allowed in this chunk!"));
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment