#Issue with a simple plugin (new to making plugins)

1 messages · Page 1 of 1 (latest)

cerulean warren
#

main:

package wands.wands;

import org.bukkit.Bukkit;
import org.bukkit.event.Listener;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.java.JavaPlugin;

public final class Wands extends JavaPlugin {

@Override
public void onEnable() {
    registerEvents(this,new WandOfSouls(this));
}

@Override
public void onDisable() {
    // Plugin shutdown logic
}

public static void registerEvents(final Plugin plugin, final Listener... listeners) {
    for(final Listener listener : listeners) {
        Bukkit.getServer().getPluginManager().registerEvents(listener, plugin);
    }
}

}

class:

package wands.wands;

import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Item;
import org.bukkit.entity.Player;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.plugin.Plugin;

public class WandOfSouls implements Listener {
private Plugin plugin;

public WandOfSouls(final Plugin plugin) {this.plugin = plugin;}
private void hitEnemy(EntityDamageByEntityEvent event) {
    Entity subject = event.getEntity();
        if (subject.getLastDamageCause() instanceof Player) {
            Player p = (Player) event.getDamager();
            if (p.getInventory().getItemInMainHand().equals(Material.STICK)) {
                World world = subject.getWorld();
                Location location = subject.getLocation();
                world.strikeLightningEffect(location);
        }
    }
}

}

#

i cant seem to get lightning to strike the entity that is hit

weak abyss
#

What happens instead?

cerulean warren
#

nothing

#

nothing is written to console

weak abyss
#

Is your listener registered?

cerulean warren
#

not sure what that means xD

weak abyss
#

Do you have the main class on you?

cerulean warren
#

yeah

#

package wands.wands;

import org.bukkit.Bukkit;
import org.bukkit.event.Listener;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.java.JavaPlugin;

public final class Wands extends JavaPlugin {

@Override
public void onEnable() {
    registerEvents(this,new WandOfSouls(this));
}

@Override
public void onDisable() {
    // Plugin shutdown logic
}

public static void registerEvents(final Plugin plugin, final Listener... listeners) {
    for(final Listener listener : listeners) {
        Bukkit.getServer().getPluginManager().registerEvents(listener, plugin);
    }
}

}

weak abyss
#

So in order for this other listener class to work ("implements Listener" at the top)

#

Okay so you do register it

cerulean warren
#

i tried adding messages to the entity if it s a plyer and to the damager at each step

#

but not a single message appeared

#

so it probably isnt running the event

weak abyss
#

Do you get any errors?

cerulean warren
#

no

#

[14:06:12] [User Authenticator #2/INFO]: UUID of player FoxyHarribo is d4d5f3bc-ccf8-466a-b390-e5509d507cb0
[14:06:13] [Server thread/INFO]: FoxyHarribo joined the game
[14:06:13] [Server thread/INFO]: FoxyHarribo[/25.60.5.204:52420] logged in with entity id 313 at ([world]61.4566697967154, 64.0, 81.19443417846524)

weak abyss
#

Oh I see it now

cerulean warren
#

my friend joined and hit me

#

nothing went through

weak abyss
#

Your hitEnemy method is missing an

@EventHandler
#

at the top

cerulean warren
#

when does evenhandler need to be used

#

and when does override need to be used

weak abyss
#

The @Override is a java thingy that is related to OOP and overriding the methods of parent classes

cerulean warren
#

EventHandler not applicable to constructor

#

nevermind got it

#

thanks for your help ill go and test it

#

same issue as before, no errors and no lightning striked

weak abyss
cerulean warren
#

where i say main and class

#

that is main and class respectively not part of the code

weak abyss
#

Make the hitEnemy public

cerulean warren
#

alright

#

same problem :/

#

console says nothing and no lightning strikes