Noob compilation question

Discussion in 'Plugin Development' started by The_Punkster, May 18, 2014.

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

    The_Punkster

    So I'm not plugin maker but I've been trying to modify an old plugin to change something to my liking.

    I have the .java file and it's been edited, but I can't figure out how to convert it to a .class to be used.

    I've tried the javac way, but that just gives me errors about symbols.

    Here's the code:
    Code:java
    1. package com.ownedcraft;
    2.  
    3. import java.util.HashMap;
    4. import java.util.Map.Entry;
    5.  
    6. import org.bukkit.Bukkit;
    7. import org.bukkit.ChatColor;
    8. import org.bukkit.Material;
    9. import org.bukkit.entity.Player;
    10. import org.bukkit.event.EventHandler;
    11. import org.bukkit.event.Listener;
    12. import org.bukkit.event.block.Action;
    13. import org.bukkit.event.player.PlayerInteractEvent;
    14. import org.bukkit.event.player.PlayerMoveEvent;
    15. import org.bukkit.event.player.PlayerQuitEvent;
    16.  
    17. public class CPListener implements Listener{
    18.  
    19. private Main plugin;
    20.  
    21. private HashMap<Player,Player> compassTargets;
    22.  
    23. public CPListener(Main instance){
    24. plugin = instance;
    25. plugin.getServer().getPluginManager().registerEvents(this, plugin);
    26. compassTargets = new HashMap<Player,Player>();
    27. }
    28.  
    29. @EventHandler
    30. public void onLeave(PlayerQuitEvent e){
    31. for (Entry<Player,Player> entry: compassTargets.entrySet()){
    32. if (entry.getKey() == e.getPlayer()){
    33. compassTargets.remove(entry.getKey());
    34. }
    35. if (entry.getValue() == e.getPlayer()){
    36. entry.getKey().sendMessage(ChatColor.RED+"Your target has left the game, your compass is no longer tracking anyone.");
    37. compassTargets.remove(entry.getKey());
    38. }
    39. }
    40. }
    41.  
    42. @EventHandler
    43. public void onPlayerInteract(PlayerInteractEvent e){
    44. Player ply = e.getPlayer();
    45. Player targ = null;
    46. if (( (e.getAction().equals(Action.RIGHT_CLICK_AIR) || e.getAction().equals(Action.RIGHT_CLICK_BLOCK)) && ply.getItemInHand().getType().equals(Material.COMPASS))){
    47.  
    48. if (!ply.hasPermission("comptrack.track")) return;
    49.  
    50. // Find the closest player to this player
    51.  
    52. for (Player player: Bukkit.getOnlinePlayers()){
    53. if (ply.getWorld() != player.getWorld()) continue;
    54. if (ply == player) continue;
    55. if ( (targ == null) || ply.getLocation().distance(player.getLocation()) < targ.getLocation().distance(ply.getLocation())){
    56. if (player.getLocation().distance(ply.getLocation()) <= 1) continue;
    57. targ = player;
    58. }
    59. }
    60.  
    61. if (targ == null){
    62. ply.sendMessage(ChatColor.RED+"Couldn't find a target!");
    63. return;
    64. }
    65.  
    66. // Add set the compass location of this player, if a target was found
    67.  
    68. ply.sendMessage(ChatColor.GRAY+"Targeting "+ChatColor.GREEN+targ.getName()+"!");
    69. compassTargets.put(ply,targ);
    70. }
    71. else if ( (e.getAction().equals(Action.LEFT_CLICK_AIR) || e.getAction().equals(Action.LEFT_CLICK_BLOCK)) && ply.getItemInHand().getType().equals(Material.COMPASS) ){
    72.  
    73. if (!ply.hasPermission("comptrack.dist")) return;
    74.  
    75. if (compassTargets.get(ply) != null){
    76. ply.sendMessage(ChatColor.GREEN+"Your target is "+ply.getLocation().distance(compassTargets.get(ply).getLocation())+" blocks away.");
    77. }
    78. else {
    79. ply.sendMessage(ChatColor.RED+"Your compass isn't tracking anyone!");
    80. }
    81. }
    82.  
    83. }
    84.  
    85. @EventHandler
    86. public void onMove(PlayerMoveEvent e){
    87.  
    88. if (compassTargets.get(e.getPlayer()) != null){
    89. e.getPlayer().setCompassTarget(compassTargets.get(e.getPlayer()).getLocation());
    90. }
    91.  
    92. for (Player ply: Bukkit.getOnlinePlayers()){
    93.  
    94. Player compassTarget = compassTargets.get(ply);
    95.  
    96. if (compassTarget == e.getPlayer()){
    97. if (ply.getWorld() == e.getPlayer().getWorld()){
    98. if (ply.getLocation().distance(e.getPlayer().getLocation()) <= 1){
    99. ply.sendMessage(ChatColor.GREEN+"Your target is close.");
    100. compassTargets.remove(ply);
    101. }
    102. ply.setCompassTarget(e.getPlayer().getLocation());
    103. }
    104. else {
    105. ply.sendMessage(ChatColor.RED+"Your target has changed world, and is no longer available.");
    106. compassTargets.remove(ply);
    107. }
    108. }
    109. }
    110.  
    111. }
    112.  
    113. }
    114.  




    It's from an old plugin called CompassTracker.
     
  2. Offline

    blobic123

    The_Punkster
    To compile it you may need all of the source files, plugin.yml and config.yml in an application environment from which you can compile (I recommend eclipse). In there you need to reference the Bukkit API and JavaDocs then do what you want to edit.
     
  3. Offline

    The_Punkster

    blobic123

    Ahhh, that's what I was thinking it was, normal cmd javac won't get the minecraft stoof.

    Thank-you, gonna try learning to make plugins soon :D
     
  4. Offline

    RawCode

    use eclipce
    try again
     
  5. Offline

    Iroh Retired Staff

    Locked.
    We do not support modifying existing plugins.
     
Thread Status:
Not open for further replies.

Share This Page