Util.this.damage error

Discussion in 'Plugin Development' started by Evaluations, Oct 5, 2014.

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

    Evaluations

    So I've basically found some pretty old code that spawns 4 bots around the player to check for forcefield.

    But I get a red line under "damage"

    Code: Util.java
    Code:java
    1. package me.blowns.main;
    2.  
    3. import org.bukkit.Bukkit;
    4. import org.bukkit.Location;
    5. import org.bukkit.World;
    6. import org.bukkit.entity.EntityType;
    7. import org.bukkit.entity.Player;
    8. import org.bukkit.entity.Villager;
    9. import org.bukkit.scheduler.BukkitScheduler;
    10.  
    11. public class Util
    12. {
    13. public static void checkPlayer(Player t)
    14. {
    15. Player bot1 = (Player)t.getLocation().getWorld().spawnEntity(new Location(t.getWorld(), t.getLocation().getX(), t.getLocation().getY(), t.getLocation().getZ() + 2.0D), EntityType.PLAYER);
    16. bot1.setCustomName("Enher");
    17. bot1.setCustomNameVisible(true);
    18.  
    19. final Player bot2 = (Player)t.getLocation().getWorld().spawnEntity(new Location(t.getWorld(), t.getLocation().getX() + 2.0D, t.getLocation().getY(), t.getLocation().getZ()), EntityType.PLAYER);
    20. bot2.setCustomName("akwosz");
    21. bot2.setCustomNameVisible(true);
    22.  
    23.  
    24. final Player bot3 = (Player)t.getLocation().getWorld().spawnEntity(new Location(t.getWorld(), t.getLocation().getX() - 2.0D, t.getLocation().getY(), t.getLocation().getZ()), EntityType.PLAYER);
    25. bot3.setCustomName("ron_s1");
    26. bot3.setCustomNameVisible(true);
    27.  
    28. final Player bot4 = (Player)t.getLocation().getWorld().spawnEntity(new Location(t.getWorld(), t.getLocation().getX(), t.getLocation().getY(), t.getLocation().getZ() - 2.0D), EntityType.PLAYER);
    29. bot4.setCustomName("_soki");
    30. bot4.setCustomNameVisible(true);
    31.  
    32.  
    33. Bukkit.getScheduler().scheduleSyncDelayedTask(Main.pl, new Runnable()
    34. {
    35. public void run()
    36. {
    37. Util.this.damage(20.0D);
    38. bot2.damage(20.0D);
    39. bot3.damage(20.0D);
    40. bot4.damage(20.0D);
    41. }
    42. }, 50L);
    43. }
    44. }
    45.  

    Error: http://prntscr.com/4thtk3



    If you want the other 2 classes, please comment.

    Thanks
     
  2. Offline

    timtower Administrator Administrator Moderator

    Evaluations You don't have a damage method in your util class.
    And spawning bots probably isn't that easy.
     
  3. Offline

    eyamaz

    Moved to Development
     
  4. Offline

    Evaluations

    Sorry about that xD

    Thanks, I'll look into it

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 14, 2016
  5. Offline

    Evaluations

    Mind help me making a damage method?
     
  6. Offline

    SmooshCakez

    It
    Code:java
    1. public void damage(double amount) {
    2. ...
    3. }

    is done.
     
  7. Offline

    MomsKnife

    Probably want something like this, just made it, super bored.

    Code:java
    1. package com.julian.annihilation; // Created by Julian on 2014-10-07
    2.  
    3. import org.bukkit.Bukkit;
    4. import org.bukkit.Location;
    5. import org.bukkit.World;
    6. import org.bukkit.entity.Entity;
    7. import org.bukkit.entity.EntityType;
    8. import org.bukkit.entity.Player;
    9. import org.bukkit.event.EventHandler;
    10. import org.bukkit.event.Listener;
    11. import org.bukkit.event.entity.EntityDamageByEntityEvent;
    12. import org.bukkit.scheduler.BukkitRunnable;
    13.  
    14. import java.util.HashMap;
    15. import java.util.UUID;
    16.  
    17. public class Test implements Listener {
    18. public Integer getHits(Player p) {
    19. return hits.get(p.getUniqueId());
    20. }
    21.  
    22. public void addHit(Player p) {
    23. if (hits.containsKey(p.getUniqueId())) {
    24. int c = hits.get(p.getUniqueId());
    25. hits.put(p.getUniqueId(), c + 1);
    26. } else {
    27. hits.put(p.getUniqueId(), 1);
    28. }
    29. }
    30.  
    31. public void resetHits(Player p){
    32. if (hits.containsKey(p.getUniqueId())){
    33. hits.remove(p.getUniqueId());
    34. }
    35. }
    36.  
    37. HashMap<UUID, Integer> hits = new HashMap<>();
    38.  
    39. public void spawnPlayers(final World w){
    40. int counter = 0;
    41.  
    42. for (Player players : Bukkit.getOnlinePlayers()) {
    43. if (players.getWorld().equals(w)) {
    44. final Player p1 = (Player) players.getWorld().spawnEntity(players.getLocation().add(0, 2, 0), EntityType.PLAYER);
    45. p1.setCustomName("FFChecker" + counter);
    46. counter++;
    47. }
    48. }
    49.  
    50. for (Player players : Bukkit.getOnlinePlayers()){
    51. if (players.getWorld().equals(w)) {
    52. for (Entity e : w.getEntities()) {
    53. if (e.getType() == EntityType.PLAYER) {
    54. Player ep = (Player) e;
    55. if (ep.getCustomName().contains("FFChecker")) {
    56. players.hidePlayer(ep);
    57. }
    58. }
    59. }
    60. }
    61. }
    62.  
    63. new BukkitRunnable(){
    64. @Override
    65. public void run() {
    66. for (Entity e : w.getEntities()){
    67. if (e.getType() == EntityType.PLAYER){
    68. Player p = (Player) e;
    69. if (p.getCustomName().contains("FFChecker")){
    70. e.remove();
    71. }
    72. }
    73. }
    74. }
    75. }.runTaskLater(Main.plugin, 10);
    76. }
    77. @EventHandler
    78. public void onHit(EntityDamageByEntityEvent e){
    79. if (e.getEntity() instanceof Player){
    80. if (((Player) e.getEntity()).getCustomName().equalsIgnoreCase("FFChecker")){
    81. if (e.getDamager() instanceof Player){
    82. Player p = (Player) e.getDamager();
    83. addHit(p);
    84.  
    85. if (getHits(p) > 10){
    86. for (Player players : Bukkit.getOnlinePlayers()){
    87. if (players.hasPermission("plugin.notify")){
    88. players.sendMessage("§c[FF] §ePlayer " + p.getName() + " may be using force-field hacks.");
    89. }
    90. }
    91. resetHits(p);
    92. }
    93. }
    94. }
    95. }
    96. }
    97. }
    98.  


    To use it, you would just run the method "spawnPlayers" with the world argument for the world your players are in.

    Note, this is not tested, it probably won't work at all, knowing me, I probably messed something small up

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

Share This Page