Regen by block

Discussion in 'Plugin Development' started by Danne123, May 11, 2014.

Thread Status:
Not open for further replies.
  1. Offline

    Danne123

    Got this now and i want it to make so it will remove the regen when going away from the block
    Code:java
    1. public void regenPlayers(PlayerMoveEvent e)
    2. {
    3. Player p = e.getPlayer();
    4. if ((p.hasPermission("blockregen.use")) &&
    5. (!p.hasPotionEffect(PotionEffectType.REGENERATION)))
    6. {
    7. Block under = e.getPlayer().getLocation().getBlock().getRelative(BlockFace.DOWN);
    8. if (under.getType().equals(Material.SPONGE))
    9. {
    10. e.getPlayer().sendMessage(ChatColor.LIGHT_PURPLE + "" + ChatColor.ITALIC + " Here is your Regeneration!");
    11. e.getPlayer().addPotionEffect(new PotionEffect(PotionEffectType.REGENERATION, Integer.MAX_VALUE, 10));
    12. }
    13. else if (this.regenPlayers.contains(e.getPlayer().getUniqueId()))
    14. if (!(BLOCK == Matrial.SPONGE.removePotionEffect(PotionEffectType.REGENERATION) ))
    15. {
    16. this.regenPlayers.remove(e.getPlayer().getUniqueId());;
    Ps : new with java
     
  2. Offline

    Plugers11

    LOLOLOLOL

    Ehh

    Code:java
    1. @EventHandler
    2. public void on(PlayerMoveEvent e){
    3. Block under = (Block) e.getPlayer().getLocation().getBlock().getLocation().subtract(0.0D, -1.0D, 0.0D);
    4. if(under.getType().equals(Material.SPONGE)){
    5. e.getPlayer().addPotionEffect(new PotionEffect(PotionEffectType.REGENERATION, Integer.MAX_VALUE, 100));
    6.  
    7.  
    8. }else{
    9.  
    10. }
    11. }


    Danne123
     
  3. Offline

    GeorgeeeHD

    Danne123 instead of doing Integer.MAX_VALUE for the time, do something like 1 second. So as long as they are on the sponge, they can get regen, but if the leave, 1 second later they won't have it.
     
  4. Offline

    Danne123

    Did get this when move
    Code:
    19:35:34 [SEVERE] Could not pass event PlayerMoveEvent to BlockRegen v1.1
    19:35:35 org.bukkit.event.EventException
    19:35:35    at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:294) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.3-63-g8356f65-b3075jnks]
    19:35:35    at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.3-63-g8356f65-b3075jnks]
    19:35:35    at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:501) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-63-g8356f65-b3075jnks]
    19:35:35    at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:486) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-63-g8356f65-b3075jnks]
    19:35:35    at net.minecraft.server.v1_7_R3.PlayerConnection.a(PlayerConnection.java:235) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-63-g8356f65-b3075jnks]
    19:35:35    at net.minecraft.server.v1_7_R3.PacketPlayInFlying.a(SourceFile:137) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-63-g8356f65-b3075jnks]
    19:35:35    at net.minecraft.server.v1_7_R3.PacketPlayInPositionLook.handle(SourceFile:20) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-63-g8356f65-b3075jnks]
    19:35:35    at net.minecraft.server.v1_7_R3.NetworkManager.a(NetworkManager.java:157) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-63-g8356f65-b3075jnks]
    19:35:35    at net.minecraft.server.v1_7_R3.ServerConnection.c(SourceFile:134) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-63-g8356f65-b3075jnks]
    19:35:35    at net.minecraft.server.v1_7_R3.MinecraftServer.v(MinecraftServer.java:667) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-63-g8356f65-b3075jnks]
    19:35:35    at net.minecraft.server.v1_7_R3.DedicatedServer.v(DedicatedServer.java:260) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-63-g8356f65-b3075jnks]
    19:35:35    at net.minecraft.server.v1_7_R3.MinecraftServer.u(MinecraftServer.java:558) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-63-g8356f65-b3075jnks]
    19:35:35    at net.minecraft.server.v1_7_R3.MinecraftServer.run(MinecraftServer.java:469) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-63-g8356f65-b3075jnks]
    19:35:35    at net.minecraft.server.v1_7_R3.ThreadServerApplication.run(SourceFile:628) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-63-g8356f65-b3075jnks]
    19:35:35 Caused by: java.lang.ClassCastException: org.bukkit.Location cannot be cast to org.bukkit.block.Block
    19:35:35    at danne.blockregen.blockregen.blockregen.on(blockregen.java:41) ~[?:?]
    19:35:35    at sun.reflect.GeneratedMethodAccessor5.invoke(Unknown Source) ~[?:?]
    19:35:35    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.7.0]
    19:35:35    at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.7.0]
    19:35:35    at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:292) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.3-63-g8356f65-b3075jnks]
    19:35:35    ... 13 more
    @Plugers11
     
  5. Danne123
    Use
    Code:java
    1. Block under = e.getPlayer().getLocation().getBlock().getLocation().subtract(0.0D, -1.0D, 0.0D).getBlock();
     
  6. Offline

    DanilaFe

    How about using a task scheduler instead? It would be less heavy on memory.
    Code:java
    1. //Place this in onEnable()
    2. Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(this, new Runnable(){
    3.  
    4. @Override
    5. public void run() {
    6.  
    7. for(Player p: Bukkit.getServer().getOnlinePlayers()){
    8. int x = p.getLocation().getBlockX();
    9. int y = p.getLocation().getBlockY();
    10. int z = p.getLocation().getBlockZ();
    11.  
    12. Block under = p.getWorld().getBlockAt(x,y-1,z);
    13. if(under.getType() == Material.SPONGE){
    14. p.addPotionEffect(new PotionEffect(PotionEffectType.REGENERATION, 20, 2));
    15. }
    16. }
    17.  
    18. }
    19.  
    20. }, 20, 20);


    He forgot another major thing -

    Block under = (Block) e.getPlayer().getLocation().getBlock().getLocation().subtract(0.0D, -1.0D, 0.0D);

    On the left side of that statement is a block. On the right side, there is a location. You can't convert a location to a bock.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 8, 2016
Thread Status:
Not open for further replies.

Share This Page