Jump to content

[1.7.10] Detecting spawn/plugin protection


LemADEC

Recommended Posts

I'm trying to fix a few spawn bypasses in mods, notably ArsMagica2.

For block placing, I was able to use ForgeEventFactory.onPlayerBlockPlace and ForgeEventFactory.onPlayerMultiBlockPlace. It's a bit tedious, but it does the job.

 

What about entity attack? Notably, how can I detect if a player can attack an entity in an area?

Link to comment
Share on other sites

There's also an event (BlockBreakEvent?) for breaking blocks, for reference.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

Thanks for your answers!

 

Original code is here: https://github.com/LemADEC/ArsMagica2/blob/master/src/main/java/am2/AMEventHandler.java#L583

 

@SubscribeEvent
public void onEntityHurt(LivingHurtEvent event){
...
	Entity entitySource = event.source.getSourceOfDamage();
	if ( entitySource instanceof EntityPlayer
	  && ((EntityPlayer)entitySource).inventory.armorInventory[2] != null
	  && ((EntityPlayer)entitySource).inventory.armorInventory[2].getItem() == ItemsCommonProxy.earthGuardianArmor
	  && ((EntityPlayer)entitySource).getCurrentEquippedItem() == null ){
		event.ammount += 4;

		double deltaZ = event.entityLiving.posZ - entitySource.posZ;
		double deltaX = event.entityLiving.posX - entitySource.posX;
		double angle = Math.atan2(deltaZ, deltaX);
		double speed = ((EntityPlayer)entitySource).isSprinting() ? 3 : 2;
		double vertSpeed = ((EntityPlayer)entitySource).isSprinting() ? 0.5 : 0.325;

		if (event.entityLiving instanceof EntityPlayer){
			AMNetHandler.INSTANCE.sendVelocityAddPacket(event.entityLiving.worldObj, event.entityLiving, speed * Math.cos(angle), vertSpeed, speed * Math.sin(angle));
		}else{
			event.entityLiving.motionX += (speed * Math.cos(angle));
			event.entityLiving.motionZ += (speed * Math.sin(angle));
			event.entityLiving.motionY += vertSpeed;
		}
		event.entityLiving.worldObj.playSoundAtEntity(event.entityLiving, "arsmagica2:spell.cast.earth", 0.4f, event.entityLiving.worldObj.rand.nextFloat() * 0.1F + 0.9F);
	}
...
}

 

 

I've tried using AttackEntityEvent as such:

 

...
	Entity entitySource = event.source.getSourceOfDamage();
	if ( entitySource instanceof EntityPlayer
	  && ((EntityPlayer)entitySource).inventory.armorInventory[2] != null
	  && ((EntityPlayer)entitySource).inventory.armorInventory[2].getItem() == ItemsCommonProxy.earthGuardianArmor
	  && ((EntityPlayer)entitySource).getCurrentEquippedItem() == null){
		if (!MinecraftForge.EVENT_BUS.post(new AttackEntityEvent((EntityPlayer)entitySource, event.entity))){
			event.ammount += 4;

			double deltaZ = event.entityLiving.posZ - entitySource.posZ;
			double deltaX = event.entityLiving.posX - entitySource.posX;
			double angle = Math.atan2(deltaZ, deltaX);
			double speed = ((EntityPlayer)entitySource).isSprinting() ? 3 : 2;
			double vertSpeed = ((EntityPlayer)entitySource).isSprinting() ? 0.5 : 0.325;

			if (event.entityLiving instanceof EntityPlayer){
				AMNetHandler.INSTANCE.sendVelocityAddPacket(event.entityLiving.worldObj, event.entityLiving, speed * Math.cos(angle), vertSpeed, speed * Math.sin(angle));
			}else{
				event.entityLiving.motionX += (speed * Math.cos(angle));
				event.entityLiving.motionZ += (speed * Math.sin(angle));
				event.entityLiving.motionY += vertSpeed;
			}
			event.entityLiving.worldObj.playSoundAtEntity(event.entityLiving, "arsmagica2:spell.cast.earth", 0.4f, event.entityLiving.worldObj.rand.nextFloat() * 0.1F + 0.9F);
		}
	}
...

 

Sadly, it doesn't seem to get cancelled whether I'm inside or outside a protected area (spawn with WorldGuard in my case).

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.