Plugin only works with server

Discussion in 'Plugin Development' started by koolkat, Apr 5, 2014.

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

    koolkat

    I have created a plugin for only a server. Is there a way I can put into the code so if the server ip matches, the plugin will run, if not disabled the plugin.
     
  2. koolkat Try it like this in the onEnable section:
    Code:java
    1. if (!this.getServer().getIp().equals("your ip here")){
    2.  
    3. PluginManager pm = this.getServer().getPluginManager();
    4.  
    5. pm.disablePlugin(this);
    6.  
    7. }
     
  3. Offline

    koolkat

    Lionhard

    I use this in the beginning, will this mess up with that code?

    Code:java
    1. public void onEnable(){
    2. getServer().getPluginManager().registerEvents(new PlayerManager(), this);
     
  4. koolkat Uhm, what's that? Is that your own class or something?

    EDIT: You can use both, that's no problem. ;)

    EDIT 2:
    This way, try it out if it works:

    Code:java
    1. public void onEnable(){
    2.  
    3. getServer().getPluginManager().registerEvents(new PlayerManager(), this);
    4.  
    5. if (!this.getServer().getIp().equals("your ip here")){
    6.  
    7. PluginManager pm = this.getServer().getPluginManager();
    8.  
    9. pm.disablePlugin(this);
    10.  
    11. }
    12.  
    13. }
     
  5. Offline

    koolkat

    Lionhard

    Would I put the reset of my code from onEnable inside the if statement or outside of it?
     
  6. Offline

    GotRice

    koolkat Once that code is activated, your whole plugin would be disabled, so it should be outside
     
  7. Offline

    RawCode

    you shoud understand simple fact - anyone with just a bit of skill can ommit such check in less then a minute.
     
  8. koolkat Noo, that if statement just looks if the server ip is NOT your IP and if it is NOT your IP it disables the plugin. Nothing else goes into the statement anymore.

    GotRice What do you mean? That is exactly what he wants, at the time the plugin gets enabled it checks if the server ip is not his IP and if it is not his IP he disables the plugin.

    EDIT: Sorry GotRice just read your comment again and understood what you meant. :oops:
     
  9. Offline

    GotRice

    Lionhard yea I telling him that, that bit of code would disable his plugin... So his plugin's code should be outside of that statement.

    Edit: Just saw Lionhard's edit. disregard of this post.
     
    Lionhard likes this.
  10. Offline

    koolkat

  11. koolkat can you please post the whole error code? :D It seems that is has problems with PlayerManager, please post the code from the Player Manager and the whole error code.
     
  12. Offline

    koolkat

  13. koolkat Can you also show me the whole main class, or the line 54 + the player manager? :D (use pastebin)

    EDIT:Try this, too.
    Code:java
    1. public void onEnable(){
    2.  
    3. if (!this.getServer().getIp().equals("your ip here")){
    4.  
    5. PluginManager pm = this.getServer().getPluginManager();
    6.  
    7. pm.disablePlugin(this);
    8.  
    9. } else {
    10.  
    11. getServer().getPluginManager().registerEvents(new PlayerManager(), this);
    12.  
    13. }
     
  14. Offline

    koolkat

    Lionhard

    Still doesn't work

    [01:01:56] [Server thread/ERROR]: Error occurred while enabling Pluginv1.4.0 (Is it up to date?)
    org.bukkit.plugin.IllegalPluginAccessException: Plugin attempted to register task while disabled
    at org.bukkit.craftbukkit.v1_7_R2.scheduler.CraftScheduler.validate(CraftScheduler.java:394) ~[bukkit.jar:git-Spigot-1360]
    at org.bukkit.craftbukkit.v1_7_R2.scheduler.CraftScheduler.runTaskTimerAsynchronously(CraftScheduler.java:137) ~[bukkit.jar:git-Spigot-1360]
    at org.bukkit.craftbukkit.v1_7_R2.scheduler.CraftScheduler.scheduleAsyncRepeatingTask(CraftScheduler.java:133) ~[bukkit.jar:git-Spigot-1360]
    at com.player.stuff.Plugin.onEnable(Plugin.java:73) ~[?:?]
    at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:250) ~[bukkit.jar:git-Spigot-1360]
    at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:324) [bukkit.jar:git-Spigot-1360]
    at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:405) [bukkit.jar:git-Spigot-1360]
    at org.bukkit.craftbukkit.v1_7_R2.CraftServer.loadPlugin(CraftServer.java:463) [bukkit.jar:git-Spigot-1360]
    at org.bukkit.craftbukkit.v1_7_R2.CraftServer.enablePlugins(CraftServer.java:381) [bukkit.jar:git-Spigot-1360]
    at net.minecraft.server.v1_7_R2.MinecraftServer.n(MinecraftServer.java:351) [bukkit.jar:git-Spigot-1360]
    at net.minecraft.server.v1_7_R2.MinecraftServer.g(MinecraftServer.java:326) [bukkit.jar:git-Spigot-1360]
    at net.minecraft.server.v1_7_R2.MinecraftServer.a(MinecraftServer.java:282) [bukkit.jar:git-Spigot-1360]
    at net.minecraft.server.v1_7_R2.DedicatedServer.init(DedicatedServer.java:186) [bukkit.jar:git-Spigot-1360]
    at net.minecraft.server.v1_7_R2.MinecraftServer.run(MinecraftServer.java:440) [bukkit.jar:git-Spigot-1360]
    at net.minecraft.server.v1_7_R2.ThreadServerApplication.run(SourceFile:618) [bukkit.jar:git-Spigot-1360]
     
  15. koolkat again, send me the WHOLE main class and the PlayerManager class.
     
  16. Offline

    RawCode

    [bukkit.jar:git-Spigot-1360]

    Spigont not supported here
     
  17. Offline

    koolkat

    RawCode

    What does that mean? Bukkit.jar is just the name I put for spigot.jar

    Lionhard
    Okay I removed the plugin manager stuff to test if it even works. It does, but when I put my ip in, it says that it is enabled. But the ! in the if statement says if the ip doesn't match, do this. So my question is, why doesn't my ip match the one that I use. This ip is the one I connect to in minecraft multiplayer.
    The code
    Code:java
    1. if (!this.getServer().getIp().equals("ip")){
    2. //PluginManager pm = this.getServer().getPluginManager();
    3. //pm.disablePlugin(this);
    4. PluginDescriptionFile pdfFile = this.getDescription();
    5. logger.info("[" + pdfFile.getName() + "]" + " Version " + pdfFile.getVersion() + " 11111111111111111111111111111111111111111111111111111111");
    6. }


    In console, it shows the message

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

    Jade

    Locked. Unofficial builds are not supported here.
     
Thread Status:
Not open for further replies.

Share This Page