Solved [URGENT] [HELP] A lotta things Not Working

Discussion in 'Plugin Development' started by TheEpicButterStudios, Oct 21, 2013.

Thread Status:
Not open for further replies.
  1. I'm nervous about posting my full code.
    DON'T COPY-PASTE THIS INTO ONE OF YOUR PLUGINS!
    Code:java
    1. package me.TheEpicButterStudios.InstaTnT;
    2. import java.util.ArrayList;
    3. import org.bukkit.ChatColor;
    4. import org.bukkit.Location;
    5. import org.bukkit.Material;
    6. import org.bukkit.command.Command;
    7. import org.bukkit.command.CommandSender;
    8. import org.bukkit.entity.Entity;
    9. import org.bukkit.entity.Player;
    10. import org.bukkit.entity.TNTPrimed;
    11. import org.bukkit.event.EventHandler;
    12. import org.bukkit.event.EventPriority;
    13. import org.bukkit.event.Listener;
    14. import org.bukkit.plugin.java.JavaPlugin;
    15.  
    16. //InstaTnT code by TheEpicButterStudios
    17. //Distributed on [url]http://dev.bukkit.org/bukkit-plugins/instatnt/[/url]
    18. //under the GNU General Public License, version 3.
    19. //All code by TheEpicButterStudios, cannot be edited and
    20. //redistributed. Should only be downloaded from BukkitDev.
    21. // This is a comment =D
    22. public class InstaTnT extends JavaPlugin implements Listener
    23. {
    24. /*
    25. * @author TheEpicButterStudios
    26. */
    27. @EventHandler(priority=EventPriority.HIGH)
    28. public void tntPlace(Listener event)
    29. {
    30. getServer().getPluginManager().registerEvents(event, this);
    31. if(((Location) event).getBlock().getType() == Material.TNT) {
    32. ((Location) event).getBlock().setType(Material.AIR);
    33. Entity tnt = ((Player) event).getPlayer().getWorld().spawn(((Location) event).getBlock().getLocation(), TNTPrimed.class);
    34. ((TNTPrimed)tnt).setFuseTicks(0);
    35. }
    36. }
    37.  
    38.  
    39.  
    40.  
    41.  
    42.  
    43.  
    44.  
    45.  
    46. public final ArrayList<Player> InstaTnTUsers = new ArrayList<Player>();
    47.  
    48. public void OnEnable()
    49. {
    50. getLogger().info("[InstaTnT] has been enabled!");
    51. getLogger().info("[InstaTnT] by TheEpicButterStudios!");
    52. getLogger().info("Running version rd-100001913");
    53. getLogger().warning("You shouldn't be running this build!");
    54. }
    55.  
    56. public void OnDisable()
    57. {
    58. getLogger().info("[InstaTnT] Has Been Disabled.");
    59. getLogger().info("[InstaTnT] Good Night!");
    60. }
    61.  
    62. public boolean OnCommand(CommandSender sender, Command cmd, String commandLabel, String args[]) {
    63. if(player.hasPermission("instatnt.explode")); {
    64. if(commandLabel.equalsIgnoreCase("InstaBoom")){
    65. toggleInstaTnT(sender);
    66.  
    67. } else ((Player) sender).sendMessage(ChatColor.RED + "You do not have access to that command.");
    68. return false;
    69. }
    70.  
    71.  
    72. }
    73. private void toggleInstaTnT(CommandSender sender)
    74. {
    75.  
    76. if(!enabled((Player)sender) )
    77. {
    78. InstaTnTUsers.add((Player) sender);
    79. ((Player) sender).sendMessage(ChatColor.YELLOW + "[InstaTnT] Enabled for YOU!");
    80. }
    81. else
    82. {
    83.  
    84. InstaTnTUsers.remove((Player)sender);
    85. ((Player) sender).sendMessage(ChatColor.RED + "[InstaTnT] Disabled. See Ya!");
    86. }
    87. }
    88. public boolean enabled(Player player)
    89. {
    90. return InstaTnTUsers.contains(player);
    91. }
    92. public static Player player;
    93.  
    94. }

    Help appreciated. Thanks!
     
  2. Offline

    thecrystalflame

    um would you mind being a bit more specific with what you need help with? is the plugin not loading, is it throwing errors at certain points? if so what points. etc etc
     
  3. thecrystalflame
    Problems:
    * Not logging to console
    * Command not working
    * Block replace not working
     
  4. Offline

    The_Doctor_123

    Because we're totally going to steal your code and release it? It's 94 lines and doesn't even work.. Be confident nobody will steal it.
     
    Blah1 likes this.
  5. Offline

    JRL1004

    Why are you registering events inside of an event instead of in onEnable()?
    Code:java
    1.  
    2. @EventHandler(priority=EventPriority.HIGH)
    3. public void tntPlace(Listener event)
    4. {
    5. getServer().getPluginManager().registerEvents(event, this);
    6. //Other things
    7. }
    8.  

    Also, don't store players in an ArrayList. It is smarter to store the players names (Strings) in an ArrayList so that if the player logs off the GC can unload them.
    Code:java
    1. if(player.hasPermission("instatnt.explode")); {
    2. if(commandLabel.equalsIgnoreCase("InstaBoom")){
    3. toggleInstaTnT(sender);

    You are also checking to see if the player has permission to use a command before checking to make sure it is the correct command.
     
  6. Offline

    xTrollxDudex

    Most of us can create this plugin: with less lines, cleaner code, and it will actually work in less than 10 minutes.

    Not to be offending or anything, but you may want to learn a bit more about bukkit and java before, erm, throwing together code.
     
    Blah1 likes this.
  7. Offline

    Sour

    Also, the license you say your code is under and the statements your saying are sorta conflicting. The GPL license is all about open source and the ability to edit and make changes. You might want to read what a license entails before slapping it onto your code. http://www.gnu.org/copyleft/gpl.html
     
    Minecrell and The_Doctor_123 like this.
  8. Offline

    The_Doctor_123

    Sour
    Haha, didn't even read what license he put at the top. So technically, we can copy his code and release it! Oh, wait, that's right.. it needs to be scrapped and redone.. Seriously, I didn't read his code until now, it makes absolutely no sense at all.
     
  9. Offline

    DAZ3DNDC0NFUS3D

    half of which are annotations, blank lines, or imports
     
  10. Offline

    Datdenkikniet

    A Listener event? Casting events to locations? Where did you get that from.
     
  11. Offline

    Dread9Nought

    You should probably @Override onEnable and onDisable for your plugin to enable first lol
     
  12. Offline

    CaptainBern Retired Staff

    TheEpicButterStudios You're doing OnEnable and OnDisable, this will not work. You have to use onEnable and onDisable. (Yes it is case-sensitive)

    TheEpicButterStudios Well I couldn't resis and wrote a snippet that should work:
    Code:java
    1. package me.TheEpicButterStudios.InstaTnT;
    2.  
    3. import java.util.ArrayList;
    4. import org.bukkit.ChatColor;
    5. import org.bukkit.Location;
    6. import org.bukkit.Material;
    7. import org.bukkit.command.Command;
    8. import org.bukkit.command.CommandSender;
    9. import org.bukkit.entity.Entity;
    10. import org.bukkit.entity.Player;
    11. import org.bukkit.entity.TNTPrimed;
    12. import org.bukkit.event.EventHandler;
    13. import org.bukkit.event.EventPriority;
    14. import org.bukkit.event.Listener;
    15. import org.bukkit.plugin.java.JavaPlugin;
    16. import org.bukkit.event;
    17.  
    18. public class InstaTnT extends JavaPlugin implements Listener{
    19.  
    20. public List<String> instaTnTers = new ArrayList<String>();
    21.  
    22. public void onDisable(){
    23. instaTnTers.clear();
    24. }
    25.  
    26. public void onEnable(){
    27. getServer().getPluginManager().registerEvents(this, this);
    28. }
    29.  
    30. @EventHandler
    31. public void onBlockPlace(BlockPlaceEvent event){
    32. if(instaTnTers.conatins(event.getPlayer().getName())){
    33. if(event.getBlock().getType().equals(Material.TNT)){
    34. event.getPlayer().getWorld().spawnEntity(event.getBlock().getLocation(), EntityType.PRIMED_TNT);
    35. }
    36. }
    37. }
    38.  
    39. public boolean onCommand(CommandSender sender, Command command, String label, String[] args){
    40. if(sender instanceof Player){
    41. Player player = (Player) sender;
    42. if(player.hasPermission("instatnt.explode")){ //I would rather use something like instatnt.use but okay...
    43. if(instaTnTers.contains(player.getName()){
    44. instaTnTers.remove(player.getName());
    45. player.sendMessage(ChatColor.RED + "Insta TNT disabled!");
    46. }else{
    47. instaTnTers.add(player.getName());
    48. player.sendMessage(ChatColor.GREEN + "Insta TNT enabled!");
    49. }
    50. }else{
    51. player.sendMessage(ChatColor.RED + "You don't have permission to use this command!");
    52. }
    53. }else{
    54. sender.sendMessage(ChatColor.RED + "You do not have access to that command!");
    55. }
    56. }
    57. }

    It's written in Notepad++ so imports may be wrong. Also, I didn't check for the label but I'm sure you know how to do that yourself.
    I wrote this code for educational purposes. If you're planning on just copy-pasting your way trough it then you won't learn anything. You may consider this code as an example of how it should be done. Please for the sake of everything thats holy, learn how to make plugins first before just pushing some code together. As about the "Don"t copy this inside your own plugins!" part, there are over 100 insta-tnt plugins out there, so I'm sure no one will, but let your rule also count for this code. Don't just copy it, learn from it.
    - CaptainBern

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 5, 2016
  13. CaptainBern Thanks!
    Why does everyone else have to be so NEGATIVE...
    I will admit, I am a beginner...
     
  14. Offline

    CaptainBern Retired Staff

  15. Offline

    The_Doctor_123

    TheEpicButterStudios
    I need to make a text file containing a few paragraphs about what I'm about to say right now, as I say it a million times a day to people.

    Learn Java before getting into 3rd party APIs(as said in my signature). It is well worth it.
     
Thread Status:
Not open for further replies.

Share This Page