Code error?

Discussion in 'Plugin Development' started by GaaTavares, Jun 8, 2013.

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

    GaaTavares

    I'm editing a plugin, and i found a error, i deleted the MoveLog end; but i getted more errors, see:

    (NO DELETION)

    MoveCheck.java >
    Error: MoveLog end; ( duplicate local variable )
    Code:java
    1.  
    2. package kookaburra.minecraft.plugins.nohax;
    3.  
    4. import java.util.ArrayList;
    5. import java.util.Hashtable;
    6. import java.util.Set;
    7.  
    8. import kookaburra.minecraft.plugins.nohax.MoveCheck.Jump;
    9. import kookaburra.minecraft.plugins.nohax.alerts.Alert;
    10. import kookaburra.minecraft.plugins.nohax.alerts.AlertLevel;
    11. import kookaburra.minecraft.plugins.nohax.alerts.AlertType;
    12. import org.bukkit.Location;
    13. import org.bukkit.Material;
    14. import org.bukkit.Server;
    15. import org.bukkit.block.Block;
    16. import org.bukkit.entity.Player;
    17. import org.bukkit.util.Vector;
    18.  
    19. public class MoveCheck
    20. implements Runnable
    21. {
    22. public static Hashtable<Player, Location> LastLocation;
    23. public static Hashtable<Player, ArrayList<MoveLog>> Moves;
    24. public static Hashtable<Player, Long> InvalidateExpires;
    25. public static MoveCheck Instance;
    26. public static int CheckCounter = 0;
    27. public static Player LastHacker;
    28. public static Server server;
    29.  
    30. public static void AddMove(Player player, Location to)
    31. {
    32. if ((Permissions.CanFly(player)) && (Permissions.CanSpeed(player))) {
    33. return;
    34. }
    35. Long expires = (Long)InvalidateExpires.get(player);
    36.  
    37. if ((expires != null) && (expires.longValue() > System.currentTimeMillis()))
    38. {
    39. return;
    40. }
    41.  
    42. if (!Moves.containsKey(player))
    43. {
    44. Moves.put(player, new ArrayList());
    45. }
    46.  
    47. synchronized ((ArrayList)Moves.get(player))
    48. {
    49. MoveCheck tmp97_94 = Instance; tmp97_94.getClass(); ((ArrayList)Moves.get(player)).add(MoveLog(player, to));
    50. }
    51. }
    52.  
    53. private static Object MoveLog(Player player, Location to) {
    54. return null;
    55. }
    56.  
    57. public static void Invalidate(Player player, long time)
    58. {
    59. if (Moves.containsKey(player))
    60. {
    61. ((ArrayList)Moves.get(player)).clear();
    62. }
    63.  
    64. time += System.currentTimeMillis();
    65. Long expires = (Long)InvalidateExpires.get(player);
    66.  
    67. if ((expires == null) || (expires.longValue() < time))
    68. InvalidateExpires.put(player, Long.valueOf(time));
    69. }
    70.  
    71. public static void Clear(Player player)
    72. {
    73. if (Moves.containsKey(player)) {
    74. Moves.remove(player);
    75. }
    76. if (LastLocation.containsKey(player))
    77. LastLocation.remove(player);
    78. }
    79.  
    80. public MoveCheck(Server server)
    81. {
    82. server = server;
    83.  
    84. LastLocation = new Hashtable();
    85. Moves = new Hashtable();
    86. InvalidateExpires = new Hashtable();
    87.  
    88. Instance = this;
    89. }
    90.  
    91. public void run()
    92. {
    93. for (Player player : server.getOnlinePlayers())
    94. {
    95. if (player.isOp())
    96. {
    97. if (!Moves.containsKey(player))
    98. continue;
    99. ((ArrayList)Moves.get(player)).clear();
    100. }
    101. else if ((!Moves.containsKey(player)) || (!LastLocation.containsKey(player)))
    102. {
    103. LastLocation.put(player, player.getLocation().clone());
    104. }
    105. else
    106. {
    107. try {
    108. synchronized ((ArrayList)Moves.get(player))
    109. {
    110. ArrayList<Jump> jumps = GetJumps((ArrayList)Moves.get(player));
    111.  
    112. for (Jump jump : jumps)
    113. {
    114. if ((!jump.isOnGround) && (!Permissions.CanFly(player)))
    115. {
    116. if (jump.height > 5.0D)
    117. {
    118. Alert.Add(player, AlertType.Flying, AlertLevel.Definitely);
    119. }
    120. else if (((jump.height >= 1.3D) && (!jump.isOnFire)) || (jump.height >= 2.0D))
    121. {
    122. Alert.Add(player, AlertType.Flying, AlertLevel.Probably);
    123. }
    124.  
    125. }
    126.  
    127. if (Permissions.CanSpeed(player))
    128. continue;
    129. if (((jump.horizontalSpeed > 11.0D) && (jump.time > 0.5D)) || ((jump.horizontalSpeed > 9.0D) && (jump.time > 1.5D)))
    130. {
    131. Alert.Add(player, AlertType.Speeding, AlertLevel.Probably);
    132. } else {
    133. if ((jump.horizontalSpeed <= 13.0D) || (jump.time <= 0.5D))
    134. continue;
    135. Alert.Add(player, AlertType.Speeding, AlertLevel.Definitely);
    136. }
    137.  
    138. }
    139.  
    140. ((ArrayList)Moves.get(player)).clear();
    141. }
    142.  
    143. LastLocation.put(player, player.getLocation());
    144. }
    145. catch (Exception e)
    146. {
    147. e.printStackTrace();
    148. }
    149. }
    150. }
    151. if (Moves.keySet().size() > Util.server.getMaxPlayers() * 3)
    152. {
    153. Moves.clear();
    154. Moves = new Hashtable();
    155. }
    156. }
    157.  
    158. public String GetLocationString(Location l)
    159. {
    160. return "(" + l.getX() + ", " + l.getY() + ", " + l.getZ() + ")";
    161. }
    162.  
    163. @SuppressWarnings("unchecked")
    164. public static ArrayList<Jump> GetJumps(ArrayList<MoveLog> moves) {
    165. int inc = 1;
    166.  
    167. ArrayList jumps = new ArrayList();
    168.  
    169. while (inc < moves.size())
    170. {
    171. if (((MoveLog)moves.get(inc)).isInVehicle) {
    172. return new ArrayList();
    173. }
    174.  
    175. int startInc = inc;
    176.  
    177. while ((inc < moves.size()) && (!((MoveLog)moves.get(inc)).isAir)) inc++;
    178.  
    179. if (inc > startInc + 5)
    180. {
    181. MoveCheck tmp79_76 = Instance; tmp79_76.getClass(); Jump jump = new Jump((MoveLog)moves.get(startInc), (MoveLog)moves.get((inc + startInc - 1) / 2), (MoveLog)moves.get(inc - 1));
    182. jump.isOnGround = true;
    183. jumps.add(jump);
    184. MoveLog end;
    185. }
    186.  
    187. if (inc >= moves.size())
    188. {
    189. break;
    190. }
    191. MoveLog start = (MoveLog)moves.get(inc - 1);
    192.  
    193. while ((inc < moves.size()) && (((MoveLog)moves.get(inc)).isAir) && (((MoveLog)moves.get(inc)).location.getY() > ((MoveLog)moves.get(inc - 1)).location.getY())) inc++;
    194.  
    195. if (inc >= moves.size())
    196. {
    197. MoveCheck tmp235_232 = Instance; tmp235_232.getClass(); jumps.add(new Jump(start, (MoveLog)moves.get(inc - 1), (MoveLog)moves.get(inc - 1)));
    198. break;
    199. }
    200.  
    201. MoveLog apex = (MoveLog)moves.get(inc - 1);
    202. boolean isFloating = false;
    203. boolean isOnFire = false;
    204. int floatCount = 0;
    205.  
    206. while ((inc < moves.size()) && (((MoveLog)moves.get(inc)).isAir))
    207. {
    208. if (((MoveLog)moves.get(inc - 1)).location.getY() <= ((MoveLog)moves.get(inc)).location.getY())
    209. {
    210. floatCount++;
    211.  
    212. if (floatCount > 3)
    213. isFloating = true;
    214. }
    215. else
    216. {
    217. floatCount = 0;
    218. }
    219.  
    220. if (((MoveLog)moves.get(inc)).isOnFire) {
    221. isOnFire = true;
    222. }
    223. inc++;
    224. }
    225. MoveLog end;
    226. MoveLog end; <----------------- ERROR HERE
    227. if (inc >= moves.size())
    228. end = (MoveLog)moves.get(moves.size() - 1);
    229. else
    230. end = (MoveLog)moves.get(inc);
    231. MoveCheck tmp433_430 = Instance; tmp433_430.getClass(); Jump jump = new Jump(start, apex, end);
    232. jump.isFloating = isFloating;
    233. jump.isOnFire = isOnFire;
    234. jumps.add(jump);
    235. }
    236.  
    237. return jumps;
    238. }
    239.  
    240. public class Jump
    241. {
    242. public MoveCheck.MoveLog start;
    243. public MoveCheck.MoveLog apex;
    244. public MoveCheck.MoveLog end;
    245. public double height;
    246. public double fallDistance;
    247. public double length;
    248. public double time;
    249. public double jumpTime;
    250. public double fallTime;
    251. public double verticalSpeed;
    252. public double jumpSpeed;
    253. public double fallSpeed;
    254. public double horizontalSpeed;
    255. public boolean isFloating = false;
    256. public boolean isOnGround = false;
    257. public boolean isOnFire = false;
    258.  
    259. public Jump(MoveCheck.MoveLog start, MoveCheck.MoveLog apex, MoveCheck.MoveLog end)
    260. {
    261. this.start = start;
    262. this.apex = apex;
    263. this.end = end;
    264.  
    265. if ((start.location.getY() == apex.location.getY()) && (apex.location.getY() == end.location.getY()) && (!start.isAir) && (!apex.isAir) && (!end.isAir)) {
    266. this.isOnGround = true;
    267. }
    268. this.height = (apex.location.getY() - start.location.getY());
    269. this.fallDistance = (apex.location.getY() - end.location.getY());
    270. this.length = (GetHorzDistance(start.location, apex.location) + GetHorzDistance(apex.location, end.location));
    271.  
    272. this.time = ((end.time - start.time) / 1000.0D);
    273. this.jumpTime = ((apex.time - start.time) / 1000.0D);
    274. this.fallTime = ((end.time - apex.time) / 1000.0D);
    275.  
    276. this.jumpSpeed = (this.height / this.jumpTime);
    277. this.fallSpeed = (this.fallDistance / this.fallTime);
    278. this.verticalSpeed = ((this.height + this.fallDistance) / this.time);
    279.  
    280. this.horizontalSpeed = (this.length / this.time);
    281. }
    282.  
    283. private double GetHorzDistance(Location a, Location b)
    284. {
    285. double x = Math.abs(a.getX() - b.getX());
    286. double z = Math.abs(a.getZ() - b.getZ());
    287.  
    288. return Math.sqrt(x * x + z * z); } }
    289. public class MoveLog { public Player player;
    290. public long time;
    291. public Location location;
    292. public Vector velocity;
    293. public boolean isSprinting;
    294. public boolean isSneaking;
    295. public boolean isAir;
    296. public boolean isOnFire;
    297. public boolean isInVehicle;
    298.  
    299. public MoveLog(Player p, Location l) { this.player = p;
    300. this.location = l.clone();
    301. this.time = System.currentTimeMillis();
    302. this.velocity = p.getVelocity();
    303. this.isSprinting = p.isSprinting();
    304. this.isSneaking = p.isSneaking();
    305. this.isInVehicle = p.isInsideVehicle();
    306. this.isOnFire = (p.getFireTicks() > 0);
    307.  
    308. if (Math.abs(this.velocity.getX()) < 0.001D)
    309. this.velocity.setX(0);
    310. if (Math.abs(this.velocity.getY()) < 0.001D)
    311. this.velocity.setY(0);
    312. if (Math.abs(this.velocity.getZ()) < 0.001D) {
    313. this.velocity.setZ(0);
    314. }
    315. this.isAir = isBlockAir(this.location);
    316. }
    317.  
    318. public double Speed(MoveLog other)
    319. {
    320. if (other == null) {
    321. return 0.0D;
    322. }
    323. long time = Math.abs(this.time - other.time);
    324. double distance = this.location.distance(other.location);
    325.  
    326. return distance / time;
    327. }
    328.  
    329. private boolean isMaterialAir(Material type)
    330. {
    331. return (type == Material.AIR) || (type == Material.TORCH) || (type == Material.REDSTONE_TORCH_OFF) || (type == Material.REDSTONE_TORCH_ON);
    332. }
    333.  
    334. private boolean isBlockAir(Location location)
    335. {
    336. Location l = location.clone();
    337. double x = l.getX();
    338. double y = l.getY();
    339. double z = l.getZ();
    340.  
    341. y = Math.floor(y) - 0.001D;
    342.  
    343. Material type = new Location(l.getWorld(), x, y, z).getBlock().getType();
    344.  
    345. if (!isMaterialAir(type)) {
    346. return false;
    347. }
    348. boolean xup = false;
    349. boolean xdwn = false;
    350. boolean zup = false;
    351. boolean zdwn = false;
    352.  
    353. if ((int)x != (int)(x + 0.32D))
    354. {
    355. xup = true;
    356. type = new Location(l.getWorld(), x + 0.32D, y, z).getBlock().getType();
    357.  
    358. if (!isMaterialAir(type)) {
    359. return false;
    360. }
    361. }
    362. if ((int)x != (int)(x - 0.32D))
    363. {
    364. xdwn = true;
    365. type = new Location(l.getWorld(), x - 0.32D, y, z).getBlock().getType();
    366.  
    367. if (!isMaterialAir(type)) {
    368. return false;
    369. }
    370. }
    371. if ((int)z != (int)(z + 0.32D))
    372. {
    373. zup = true;
    374. type = new Location(l.getWorld(), x, y, z + 0.32D).getBlock().getType();
    375.  
    376. if (!isMaterialAir(type)) {
    377. return false;
    378. }
    379. }
    380. if ((int)z != (int)(z - 0.32D))
    381. {
    382. zdwn = true;
    383. type = new Location(l.getWorld(), x, y, z - 0.32D).getBlock().getType();
    384.  
    385. if (!isMaterialAir(type)) {
    386. return false;
    387. }
    388. }
    389. if ((xup) && (zup))
    390. {
    391. type = new Location(l.getWorld(), x + 0.32D, y, z + 0.32D).getBlock().getType();
    392.  
    393. if (!isMaterialAir(type)) {
    394. return false;
    395. }
    396. }
    397. if ((xup) && (zdwn))
    398. {
    399. type = new Location(l.getWorld(), x + 0.32D, y, z - 0.32D).getBlock().getType();
    400.  
    401. if (!isMaterialAir(type)) {
    402. return false;
    403. }
    404. }
    405. if ((xdwn) && (zup))
    406. {
    407. type = new Location(l.getWorld(), x - 0.32D, y, z + 0.32D).getBlock().getType();
    408.  
    409. if (!isMaterialAir(type)) {
    410. return false;
    411. }
    412. }
    413. if ((xdwn) && (zdwn))
    414. {
    415. type = new Location(l.getWorld(), x - 0.32D, y, z - 0.32D).getBlock().getType();
    416.  
    417. if (!isMaterialAir(type)) {
    418. return false;
    419. }
    420. }
    421. return true;
    422. }
    423. }
    424. }
    425.  
    426. [syntax/]
    427.  
    428.  
    429. Main/kNoHax.jar
    430.  
    431. [syntax=java]
    432. package kookaburra.minecraft.plugins.nohax;
    433.  
    434. import kookaburra.minecraft.plugins.nohax.forcefield.ForcefieldListener;
    435. import org.bukkit.ChatColor;
    436. import org.bukkit.command.Command;
    437. import org.bukkit.command.CommandSender;
    438. import org.bukkit.plugin.PluginDescriptionFile;
    439. import org.bukkit.plugin.PluginManager;
    440. import org.bukkit.plugin.java.JavaPlugin;
    441.  
    442. public class kNoHax extends JavaPlugin
    443. {
    444. public void onDisable()
    445. {
    446. PluginDescriptionFile pdfFile = getDescription();
    447.  
    448. Util.Initialize(this);
    449.  
    450. System.out.println(pdfFile.getName() + " version " + pdfFile.getVersion() + " is disabled!");
    451. }
    452.  
    453. public void onLoad()
    454. {
    455. super.onLoad();
    456. }
    457.  
    458. public void onEnable() {
    459. PluginManager pm = getServer().getPluginManager();
    460.  
    461. pm.registerEvents(new EventListener(), this);
    462. pm.registerEvents(new ForcefieldListener(), this);
    463.  
    464. PluginDescriptionFile pdfFile = getDescription();
    465.  
    466. Util.Initialize(this);
    467.  
    468. System.out.println(pdfFile.getName() + " version " + pdfFile.getVersion() + " is enabled!");
    469. }
    470.  
    471. public boolean onCommand(CommandSender sender, Command command, String label, String[] args)
    472. {
    473. if (label.equalsIgnoreCase("lag"))
    474. {
    475. double tps = Lag.getTPS();
    476. double lag = Math.round((1.0D - tps / 20.0D) * 100.0D);
    477.  
    478. sender.sendMessage(ChatColor.GOLD + "Server running at " + tps + " tps");
    479. sender.sendMessage(ChatColor.GOLD + "Lag is approx " + lag + "%");
    480. return true;
    481. }
    482.  
    483. return false;
    484. }
    485. }
    486. [syntax/][/syntax]
     
  2. Offline

    Pink__Slime

    GaaTavares
    Could you please post the stack trace.
     
  3. Offline

    GaaTavares


    What?put the Main? i dont speak english pretty good sorry
    OBS: How i can put java codes?
     
  4. Offline

    Pink__Slime

    GaaTavares
    Java codes are in [ syntax=java][ /syntax] tags.
    A stack trace is the error you get in console.
     
  5. Offline

    GaaTavares

    @Pink_Slime

    Oh sorry, i get this "flood error" on console:

    Task #2 for kNoHax 1.4 generated an exepction: java.lang.NullPointerException
    at kookaburra.minecraft.plugins.nohax.MoveCheck.run(MoveCheck.java:92)
     
Thread Status:
Not open for further replies.

Share This Page