Solved Kit Magma

Discussion in 'Spigot Plugin Development' started by Fearowness, Aug 1, 2020.

  1. hey guys, i'm creating a PvP server and i want help with the Magma Kit.
    the player with this kit is immune to lava and fire damage and ticks, and if an enemy hits him there's a chance of the enemy getting on fire. but there's one more thing i would like to add to this kit and i don't know how.
    here's the code i have:
    Code (Text):
    public static List<Material> blocks = Arrays.asList(Material.WATER,Material.STATIONARY_WATER);
        public static ArrayList<Player> NaAgua = new ArrayList<>();
     
        @EventHandler
        public void MagmaEvent1(EntityDamageEvent e) {
            Player p = (Player) e.getEntity();
            if (KitAPI.ComKit(p, "Magma")) {
                if ((e.getCause() == DamageCause.FIRE) || (e.getCause() == DamageCause.FIRE_TICK) || (e.getCause() == DamageCause.LAVA)) {
                    e.setCancelled(true);
                }
            }
        }
     
        @EventHandler
        public void MagmaEvent (EntityDamageByEntityEvent e) {
            if (e.getEntity() instanceof Player && e.getDamager() instanceof LivingEntity) {
                Player p = (Player) e.getEntity();
                if (KitAPI.ComKit(p, "Magma")) {
                    double r = new Random().nextDouble();
                    if (r < 0.33) {
                        LivingEntity b = (LivingEntity) e.getDamager();
                        b.setFireTicks(100);
                    }
                }
            }
        }
     
        @EventHandler
        public void MagmaEvent2 (PlayerMoveEvent e) {
            Player p = e.getPlayer();
            if (KitAPI.ComKit(p, "Magma")) {
            Material block = e.getTo().getBlock().getRelative(BlockFace.DOWN).getRelative(BlockFace.UP).getRelative(BlockFace.NORTH).getRelative(BlockFace.EAST).getRelative(BlockFace.SOUTH).getRelative(BlockFace.WEST).getType();
            if (!blocks.contains(block)) {
                NaAgua.remove(p);
            } else {
                if (blocks.contains(block)) {
                    NaAgua.add(p);
                }
            }
            }
        }
     
        @EventHandler
        public void MagmaEvent3 (EntityDamageEvent e) {
            Player p = (Player) e.getEntity();
            if (KitAPI.ComKit(p, "Magma")) {
                if (NaAgua.contains(p)) {
                }
            }
        }
    the ArrayList "NaAgua" means InWater, im brazillian. so, there's an ArrayList cause i've thinked of doing this way i was trying to do. if the magma is in the water, he will get damage ticks like fire ticks or maybe lava. if (NaAgua.contains(p)) {
    ....??
    i just don't know how to do to the player gets these damages. anyone can help me please? i was in the right way?
     
  2. I can think of 2 ways to do that.

    First would be to have a BukkitRunnable that checks every 20 ticks if a magma kit player is inside water and then deal damage to them.

    Another option is to save the time when a player enters or leaves water with the PlayerMovementEvent. Then check how long the player has been in water with a BukkitRunnable that executes every 1 or 2 ticks and deal damage to them if it’s been longer than 1 second (and then update the time the player entered the water)
     
  3. @MightyOne nice man, but i don't know how to do this damage to the magma, u know? i didn't even know what event should i use. i was thinking of use EntityDamageEvent, it's right? can u send me the code or how can i do this damage to the magma please?
     
  4. Events are just like notifications for other plugins. If you just want to damage a player then use Player#damage().
     
  5. what is Player#damage()? i'm quite new with java man, i don't know how can i do damage to the player. can u explain step by step?
     
  6. I recommed you to read spigot api documentation. Player#damage()
     
  7. Code (Text):
    @SuppressWarnings("deprecation")
        @EventHandler
        public void MagmaEvent3 (EntityDamageEvent e) {
            Player p = (Player) e.getEntity();
            if (KitAPI.ComKit(p, "Magma")) {
                if (NaAgua.contains(p)) {
                    Bukkit.getScheduler().scheduleSyncDelayedTask(Main.plugin, new BukkitRunnable() {
                        public void run() {
                            p.damage(1.0D);
                        }
                    }, 20L);
                }
            }
        }
    i did like this but it didn't worked. why?
     
  8. anyone knows why it didn't worked?
     
  9. YOU are creating the damage. There is no event being fired. YOU have to start BukkitRunnable right when the plugin is being enabled
     
  10. i dit it work, but the player is taking sooo much dmg. this is my code:
    Code (Text):
    @EventHandler
        public void MagmaEvent2 (PlayerMoveEvent e) {
            Player p = e.getPlayer();
            if (KitAPI.ComKit(p, "Magma")) {
            Material block = e.getTo().getBlock().getRelative(BlockFace.DOWN).getRelative(BlockFace.UP).getRelative(BlockFace.NORTH).getRelative(BlockFace.EAST).getRelative(BlockFace.SOUTH).getRelative(BlockFace.WEST).getType();
                    Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(Main.plugin, new Runnable() {
                        public void run() {
                        if (blocks.contains(block)) {
                            p.setHealth(p.getHealth() -0.5);
                          }
                        }
                    }, 20L);
                }
            }
    i already tried of doing the check if the player is in the water in 20 ticks but the player still taking so much dmg and is delayed task, so the player still takes damage even if he isn't in the water. how can i solve this?
     
  11. You want to check if some players are in water every 20 ticks. That means you want create code that runs every 20 ticks right from the server start.
    The server start = public void onEnable() for you. Put the Bukkit.scheduleSyncRepeatingTask()... somewhere there, right in the beginning of your plugin.
     
  12. but it is already there. this is my onEnable:
    Code (Text):
    public void onEnable() {
            instance = this;
            plugin = (Plugin)this;
            RegistrarEventos();
            RegistrarComandos();
            RegistrarKits();
            this.AutoMessanger = new AutoBroadcast(this);
            AutoBroadcast.start();
            plugin = this;
            instance = this;
            cfg = getConfig();
            m = this;
    RegistrarKits(); is the KitsRegister, that register the magma kit. or i need to put it again and alone?
     
  13. i've tried to do the same i did with my AutoBroadcast:
    Code (Text):
    private static Main main;
       
          public AutoBroadcast(Main pl) {
            main = pl;
          }
       
          public static void start() {
                Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask((Plugin)main, new Runnable() {
                      String[] msg = new String[] { String.valueOf(Main.nome) + ChatColor.GOLD + "Precisa de ajuda? Procure algum " + ChatColor.DARK_PURPLE + ChatColor.ITALIC + "Moderador " + ChatColor.GOLD + "ou " + ChatColor.RED + "" + ChatColor.ITALIC + "Admin " + ChatColor.GOLD + "online.",
                          String.valueOf(Main.nome) + ChatColor.GOLD + "Para reportar um Player, utilize " + ChatColor.YELLOW + ChatColor.BOLD + "/report <Player> <Motivo>" + ChatColor.GOLD + ".",
                          String.valueOf(Main.nome) + ChatColor.GOLD + "Não perca os eventos valendo " + ChatColor.GREEN + ChatColor.BOLD + "VIP" + ChatColor.GOLD + ", " + ChatColor.BLUE + ChatColor.BOLD + "MVP" + ChatColor.GOLD + " ou  até " + ChatColor.BOLD + "PRO" + ChatColor.GOLD + ".",
                          String.valueOf(Main.nome) + ChatColor.GOLD + "Em breve servidores de " + ChatColor.AQUA + ChatColor.BOLD + "Hunger Games" + ChatColor.GOLD + "! Aguardem...",
                          String.valueOf(Main.nome) + ChatColor.GOLD + "Caso você seja " + ChatColor.BOLD + "PRO" + ChatColor.GOLD + ", você pode usar o comando " + ChatColor.YELLOW + ChatColor.BOLD + "/tag " + ChatColor.GOLD + "e escolher a sua Tag.",
                          String.valueOf(Main.nome) + ChatColor.GOLD + "Para ver suas Estatísticas, utilize " + ChatColor.YELLOW + ChatColor.BOLD + "/stats" + ChatColor.GOLD + ".",
                          String.valueOf(Main.nome) + ChatColor.GOLD + "O evento Rei da Mesa têm como prêmio a Tag " + ChatColor.YELLOW + ChatColor.BOLD + "RDM" + ChatColor.GOLD + " ou então o vencedor ganhará uma semana de " + ChatColor.BOLD + "PRO" + ChatColor.GOLD + "."};
                   
                      public void run() {
                          Bukkit.getServer().broadcastMessage(this.msg[(new Random()).nextInt(this.msg.length)]);
                      }
                    },  0L, 6000L);
              }
    this is my autobc code, and there's what i've tried with magma:
    Code (Text):
    @EventHandler
        public void MagmaEvent2 (PlayerMoveEvent e) {
            Player p = e.getPlayer();
            if (KitAPI.ComKit(p, "Magma")) {
            Material block = e.getTo().getBlock().getRelative(BlockFace.DOWN).getRelative(BlockFace.UP).getRelative(BlockFace.NORTH).getRelative(BlockFace.EAST).getRelative(BlockFace.SOUTH).getRelative(BlockFace.WEST).getType();
            Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask((Plugin)main, new Runnable() {
                        public void run() {
                            if (blocks.contains(block)) {
                                p.setHealth(p.getHealth() -1);
                            }
                        }
                    }, 0L, 20L);
            }
        }
     
        public static void magma() {
            for (Player p : Bukkit.getServer().getOnlinePlayers()) {
                Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask((Plugin)main, new Runnable() {
                    public void run() {
                        if (blocks.contains(block)) {
                            p.setHealth(p.getHealth() -1);
                        }
                    }
                }, 0L, 20L);
            }
        }
    it says that "block cannot be resolve to a variable" bcause the block is in PlayerMoveEvent. what should i do now? how could i check? with hashmap? or arraylist?
     
  14. Well you created an @EventHandler for a PlayerMoveEvent there. So what your code probably does is every tick a player moves while being water they get damage. And I think that’s not what you want. Or am I wrong?
     
  15. i just can't think about that man, for me i was doing right. i really don't know how to do it :(
     
  16. I don't quite understand what you mean, But If you want the 'Magma User' to get damage while being in water, You can create a new event (PlayerMoveEvent) check if the player has the Magma Kit and Is in water (check by player's location) and then do player.damage(4.0D);

    I don't know why you created an ArrayList for being in water.
     
    • Agree Agree x 1
  17. @teddyyy yeah man thanks it worked very well, thank you so much!! :D