-
-
Save wesserboy/3a757d716d72e54b4731 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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