Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

[Server][Unsolved] AttackEntityEvent, is retreiving the Player possible?

Featured Replies

Posted

Hi!

 

I'm rather new to this, but I will try to be as straightforward as possible.

 

(I did read the rules -- But this code snippet isn't really so big I should have to upload it elsewhere, right?)

 

 

I'm developing a MCPC(Bukkit + Forge) server plugin.

    @ForgeSubscribe
     public void onAttackEntityEvent(AttackEntityEvent event){
    	
   
    	
    
    	
    	
    	Bukkit.getServer().broadcastMessage("You hit something!");
    	
    }
   

   

 

My main question here is how I am to go about retrieving the player from this event. Right now it does not even broadcast any message. (I've imported the bukkit libraries aswell.)

 

What I want to do is import the Player(Attacker) from this event, and then use it in another method from a mod library. Then, I want to put the player in a scoreboard team.

 

Also, I think I need the obfuscated EntityPlayer, "sq".

 

Is this possible?

 

 

 

Thanks in advance,

 

SurMjölk

 

 

Important edit, or TL;DR Edit:

 

////////////

 

 

It's probably important to note that my main concern is not being able to retrive the player as "Sq player" or "EntityPlayer", which are two of what seems to be applicable players for the mod method I'm trying to use.

///////////

Just check if the attacking entity is not null (to make sure) and if it's an instanceof ENtityPlayer.

Don't ask for support per PM! They'll get ignored! | If a post helped you, click the "Thank You" button at the top right corner of said post! |

mah twitter

This thread makes me sad because people just post copy-paste-ready code when it's obvious that the OP has little to no programming experience. This is not how learning works.

  • Author

@SanAndreasP

Hi and thank you for your reply!

 

I'm completely new to this. I could, however, do what you asked for already, from looking at code snippets I found over this help section forum :)

 

But! The problem is that I'm not sure how to define the player at all. And this whole obfuscation process confuses me, I'd like to learn more about it - If it is relevant to my problem. Could you maybe write me a sample code on how to handle what I asked for? That would be ace!

 

I know it's on a basic level but it's really this one thing I want to learn and I've been browsing for a soloution for quite a while today!

 

Instead of using forge events (which I don't know at all), you could use Bukkit events (which I do).

 

 

import org.bukkit.entity.Player;
import org.bukkit.event.entity.EntityDamageByEntityEvent;

@EventHandler
public void <whatever>(EntityDamageByEntityEvent e) {
Player player = (Player) e.getDamager();
player.sendMessage("You hit something!"); // Bukkit.getServer().broadcastMessage() sends it to everyone
// Call to method from mod library here (attacker's data stored in variable "player")
}

 

 

Note that your class will have to implement org.bukkit.event.Listener. If you choose to place the listener in a different class to your main one, in the onEnable() function in your main class, you will need to add:

 

getServer().getPluginManager().registerEvents(new <class name here>(), this);

 

This is how it is done in Bukkit, anyway. Not sure if it changes for ForgeBukkit.

  • Author

@J15t98J

 

Hi and thanks for your reply!

 

Unfournately I cannot do that, because:

 

a. Using the Bukkit class does not check for mod mob entities, or at least not the ones in the mod I am using. Is there a way to do this?

 

b. The method I want to use requires me to have the obfuscated "sq" Player. Can you get this through bukkit aswell? Because I get an error when I try to import the sq class.

a. Anything registered properly as an entity should fire that listener when you hit it. What mod is it?

 

b. What are you trying to do with it / do you need it for? And what method (from what library) is it?

  • Author

 

The mod is called LOTR mod.

 

 

a. Iit did broadcast something when I killed a cow but not an orc. :/

 

b. The mod has faction points. To return the value of a certain player, you'd want to use LOTRLevelData.getAlignment(player). I spoke to the mod author about this.

 

 

  • Author

I have done that ages ago, but the bukkit player class doesn't include sq as far as I am aware.

 

I'm pretty sure I tried going pure bukkit first but it didn't work.

Currently referencing the MCPC jar, seems to be the best way since you don't have to worry about duplicates.

  • Author

Is there nobody who can help me with this? Like, could someone declare it impossible without modfying the actual mod source?

I doubt it is though, I highly doubt that...

 

 

 

  • Author

I don't recommend developing directly for MCPC+. Either do pure Bukkit or pure forge, in their proper environment. MCPC+ is not meant to be developed against, it's just there to run Bukkit plugins and forge mods side by side.

So first thing: Decide if you want a forge mod or a bukkit plugin. then go that route. Both will work with MCPC.

 

Hi. I like cameracraft. It's nice.

 

I guess I have to go forge then, since Bukkit cannot retrive "Sq" type players (EntityPlayer), and so I cannot use my desired method in Bukkit since it requires Sq.

 

Still, problem isn't solved.  :(  This might help solving some stuff though.

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...

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.