Hey guys, I need help... I made some very simple plugins before (WelcomeRulezz, EnderpearlDisable,...) I want to make a plugin but I don't know how to start... With the plugin you can't die or lose any hearts but it looks like you are taking damage if you get hit. It's like god mode. But when you get hit it looks like you take damage instead of not moving or not taking anything with regular god mode. The plugin should have a file of names to put players in that have the ability. If someone can get me started, it would be much appreciated. Something with EntityDamageEvent? EDIT by Moderator: merged posts, please use the edit button instead of double posting.
So you want to have all the effects the damage without the damage ? It's simple, in the damage event just set the victim's health to 20 instead of cancelling the event.... hmm, but I think if you just add to the HP it stacks up over 20 and it could help against verry big criticals like falling.... I never did this tough.
no, I mean where do I have to put the number 20 (if I want 20) So I have the event: Code: onPlayerDamage(EntityDamageEvent event) { } what should I do in between those brackets to tell bukkit I want the player to have 20 HP...? Thanks...
Thank you manniL, I gave you a Like I still have a problem, in the EntityDamageEvent, I can't define Player. The error I get is: The method getPlayer() is undefined for the type EntityDamageEvent Which Event should I have to use? anyone? EDIT by Moderator: merged posts, please use the edit button instead of double posting.
It's getEntity(), you must check if it's instanceof Player and then cast it to Player. Code: Entity ent = event.getEntity(); if(ent instanceof Player) { Player player = (Player)ent; player.setHealth(20); }
Also, if you're using Eclipse press ctrl+space after a dot to print a list of available methods for that class... like: player. and ctrl+space. I dunno about other IDEs.
It's not working... here's my code: - the main class Code: package me.wannezz.SemiGod; import java.util.logging.Logger; import org.bukkit.plugin.PluginManager; import org.bukkit.plugin.java.JavaPlugin; public class SemiGod extends JavaPlugin { Logger log = Logger.getLogger("Minecraft"); @Override public void onDisable() { log.info("[SemiGod] has been disabled"); } @Override public void onEnable() { log.info("[SemiGod] has been enabled"); PluginManager manager = this.getServer().getPluginManager(); manager.registerEvents(new DamageListener(), this); } } The Listener: Code: package me.wannezz.SemiGod; import org.bukkit.entity.Entity; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.entity.EntityDamageEvent; public class DamageListener implements Listener { @EventHandler public void onPlayerDamage(EntityDamageEvent event) { Entity entity = event.getEntity(); if(entity instanceof Player) { Player player = (Player)entity; player.setHealth(20); } } } This is the error I get in the console... Code: 19:11:46 [SEVERE] Could not pass event EntityDamageEvent to SemiGod org.bukkit.event.EventException at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.ja va:303) at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.jav a:62) at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.j ava:441) at net.minecraft.server.EntityLiving.a(EntityLiving.java:819) at net.minecraft.server.EntityHuman.a(EntityHuman.java:1191) at net.minecraft.server.Entity.a(Entity.java:686) at net.minecraft.server.EntityPlayer.b(EntityPlayer.java:467) at net.minecraft.server.NetServerHandler.a(NetServerHandler.java:413) at net.minecraft.server.Packet10Flying.handle(SourceFile:126) at net.minecraft.server.NetworkManager.b(NetworkManager.java:229) at net.minecraft.server.NetServerHandler.a(NetServerHandler.java:112) at net.minecraft.server.NetworkListenThread.a(NetworkListenThread.java:7 8) at net.minecraft.server.MinecraftServer.w(MinecraftServer.java:549) at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:447) at net.minecraft.server.ThreadServerApplication.run(SourceFile:490) Caused by: java.lang.IllegalArgumentException: Health must be between 0 and 20 at org.bukkit.craftbukkit.entity.CraftLivingEntity.setHealth(CraftLiving Entity.java:55) at me.wannezz.SemiGod.DamageListener.onPlayerDamage(DamageListener.java: 20) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.ja va:301) ... 14 more I don't know what to do... EDIT by Moderator: merged posts, please use the edit button instead of double posting.
Hmm... Are you sure you set it to 20 ? If you did, it could be a bukkit issue :/ are you using recommended builds ? EDIT: or maybe it's between exclusive, 1-19 try 19.
In my plugin i use health too, and i can sat the health at 20 and at 0. I don' t know why there is an error but you could try, it works in my plugin: Code: @EventHandler public void onPlayerDamage(EntityDamageEvent event) { Player player = event.getPlayer(); player.setHealth(20); }
The error is solved, but when I tested it, there is still damage when you fall, if you are drowning, you always have 9 hearts, and if you get hurt by hunger, you always have 9 and a half hearts... Does anyone know how to solve this?
But then the effects will be gone, isn't it? I want it have like others can see you have damage, but you actually don't get hurt... Anyone? EDIT by Moderator: merged posts, please use the edit button instead of double posting.
Lol if he's problems with this then a scheduled task would be crazy Ps i can't do scheduled tasks so its not really an insult hehe
But when you use scheduled tasks, you can die when you fall more than 30 blocks deep. Maby there is a way to give the player an enchanted armour, that is invisible