Hi Guys, I have 2 class files in my plugin and i need to know how to make the connect the 2 class files Heres the main class: Code: package com.plugin.checkinv; import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.event.Listener; public class CheckInv extends JavaPlugin{ public void onEnable() { this.getServer().getPluginManager().registerEvents((Listener) new CheckInv(), this); getLogger().info("CheckInv has been enabled!"); } public void onDisable() { getLogger().info("CheckInv has been disabled!"); } } And Secondary Calss: Code: package com.plugin.checkinv; import org.bukkit.Material; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.inventory.PlayerInventory; import org.bukkit.plugin.java.JavaPlugin; public class CheckInvMain extends JavaPlugin implements Listener{ @EventHandler(priority = EventPriority.HIGHEST) public void onPlayerJoin(PlayerJoinEvent evt) { Player player = evt.getPlayer(); PlayerInventory inventory = player.getInventory(); if (inventory.contains(Material.BEDROCK)) { inventory.remove(Material.BEDROCK); player.sendMessage("Why do you have bedrock???"); } } And plugin.yml: Code: name: CheckInv main: com.plugin.checkinv.CheckInv version: 1.0.7 What other code do i have to put in? Thx in advance!
change: this.getServer().getPluginManager().registerEvents((Listener) new CheckInv(), this); to: this.getServer().getPluginManager().registerEvents(this, this); changeublic class CheckInv extends JavaPlugin{ toublic class CheckInv extends JavaPlugin implements Listener{ and simply copy your code : @EventHandler(priority = EventPriority.HIGHEST) public void onPlayerJoin(PlayerJoinEvent evt) { Player player = evt.getPlayer(); PlayerInventory inventory = player.getInventory(); if (inventory.contains(Material.BEDROCK)) { inventory.remove(Material.BEDROCK); player.sendMessage("Why do you have bedrock???"); } } over to your main class file
ok i guess... Any way to make it tho? Since i will be developing larger plugins in the future. EDIT by Moderator: merged posts, please use the edit button instead of double posting.
Yes he did. So he didn't answer your question. I suggest changing your main class CheckInv to this (Main contain bugs just typing this off top my head *Easy to fix ones*) Code: package com.plugin.checkinv; import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.event.Listener; public class CheckInv extends JavaPlugin{ @SuppressWarnings("unused") private CheckInvMain Checkinvmain = null; public void onEnable() { getLogger().info("CheckInv has been enabled!"); Checkinvmain = CheckInvMain(this); } public void onDisable() { getLogger().info("CheckInv has been disabled!"); } } I made it call the CheckInvMain if you notice i removed the registar events I moved it into CheckInvMain Better that way (In my eyes) May not be but someone may correct me they may not. Now for the second class Code: package com.plugin.checkinv; import org.bukkit.Material; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.inventory.PlayerInventory; import org.bukkit.plugin.java.JavaPlugin; public class CheckInvMain implements Listener{ public CheckInv plugin; public CheckInvMain (CheckInv plugin) { this.plugin = plugin; plugin.getServer().getPluginManager().registerEvents(this, plugin); } @EventHandler(priority = EventPriority.HIGHEST) public void onPlayerJoin(PlayerJoinEvent evt) { Player player = evt.getPlayer(); PlayerInventory inventory = player.getInventory(); if (inventory.contains(Material.BEDROCK)) { inventory.remove(Material.BEDROCK); player.sendMessage("Why do you have bedrock???"); } } Here what i have done is made the "public CheckInv plugin;" This just calls the CheckInv then i also added a constructor which in there registars the events. Hope this helped any questions just ask.