Teams friendlyfire doesnt work

Discussion in 'Spigot Plugin Development' started by HockeyFreak062, Aug 4, 2018.

  1. Hey! Im trying to make some teams. Then set the Friendly fire to false so they cant hit each other And set the Collision option to NEVER so they cant push each other. But this doesnt work. Here is my code
    Code (Java):

    public class CreateTeams implements Listener {

        public void onJoin(PlayerJoinEvent event) {
            ScoreboardManager man = Bukkit.getScoreboardManager();
            Scoreboard board = man.getNewScoreboard();

            Player p = event.getPlayer();

            Team maylind = board.registerNewTeam("Maylind");
            Team wayllan = board.registerNewTeam("wayllan");
            Team erardol = board.registerNewTeam("Erardol");
            Team gwalenn = board.registerNewTeam("Gwalenn");


            maylind.setOption(Option.COLLISION_RULE, OptionStatus.NEVER);
            wayllan.setOption(Option.COLLISION_RULE, OptionStatus.NEVER);
            erardol.setOption(Option.COLLISION_RULE, OptionStatus.NEVER);
            gwalenn.setOption(Option.COLLISION_RULE, OptionStatus.NEVER);

            maylind.setOption(Option.DEATH_MESSAGE_VISIBILITY, OptionStatus.NEVER);
            wayllan.setOption(Option.DEATH_MESSAGE_VISIBILITY, OptionStatus.NEVER);
            erardol.setOption(Option.DEATH_MESSAGE_VISIBILITY, OptionStatus.NEVER);
            gwalenn.setOption(Option.DEATH_MESSAGE_VISIBILITY, OptionStatus.NEVER);

            if (Main.dataConfig.getConfig().getString(p.getUniqueId() + ".Kingdom").equalsIgnoreCase("Kingdom1")) {
            } else if (Main.dataConfig.getConfig().getString(p.getUniqueId() + ".Kingdom").equalsIgnoreCase("Kingdom2")) {
            } else if (Main.dataConfig.getConfig().getString(p.getUniqueId() + ".Kingdom").equalsIgnoreCase("Kingdom3")) {
            } else if (Main.dataConfig.getConfig().getString(p.getUniqueId() + ".Kingdom").equalsIgnoreCase("Kingdom4")) {


    No errors shown in the console btw
  2. Everytime a player joins you create a new scoreboard and new teams. Store the scoreboard and teams else where and only create them in the onEnable().

    Currently no one who joins is in the same team. They all join their own individual one man team
    • Agree Agree x 1
  3. Try setting the Scoreboard for everybody:
    Code (Java):
    for(Player player : Bukkit.getOnlinePlayers()){
    Tell me how this goes :)
  4. I now create them in the onEnable() but how can i access them in other classes?
  5. In your class constructor with your events pass in the main class
    Code (Text):
    private mainClass main:

    public myClass(mainClass main){
        this.main = main;
    Then in the main class where you register events put new myClass(this) instead of myClass()
  6. I dont know where you are talking about sorry I' m not that great of a dev.
  7. What he's saying is basic Java knowledge, so at this point, you may need to take some time to study Constructors and Arguments in java before continuing. To put it simply, he's saying you need to pass your main plugin class (the one that extends JavaPlugin) to your class which implements Listener. You'd do this by adding a Constructor to that class which accepts an argument of the type of your main plugin class. By doing that, then you can access members from your main plugin class in your event listener class.
    Code (Java):
    public class MainPlugin extends JavaPlugin {
        public Scoreboard myScoreboard;
        /* Some other stuff */
    This is an example of what your main plugin class may look like.

    Code (Java):
    public class CreateTeams implements Listener {
        private MainPlugin plugin;
        public CreateTeams(MainPlugin plugin) { this.plugin = plugin; } // This is a constructor!
        private void SomeMethod() { Scoreboard s = plugin.myScoreboard; } // Now you can access a shared scoreboard object.
        /* Listeners and such down here */
    After this, anywhere in your CreateTeams class, you can reference your main plugin class through the variable 'plugin'.

    So in short, study up. It'll help create plugins tremendously if you understand a few simple concepts of Java!
    • Informative Informative x 1
  8. Thanks I will defenitly do that thnx for the links!