FFA plugin.

Discussion in 'Plugin Development' started by digitox, Mar 19, 2017.

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

    digitox

    Hi,


    I have made a FFA plugin. But i want it to be a SkyFFA. like you'r having ff. in the sky. But when you get kicked out. i Just says {Player} got killed by void. I want to set a Y heigth (to set the Y height you do /setHegth). When you set this the If a Player is getting under that Y cordinate, you will get killed by the person that was last hitting you. If you could help me whit how to set the command. and How to make the Coordinate Event?!

    Then i need help whit my ScoreBoard. i don't know what is wrong but i don't work.

    Code:
    package me.digitox.ffa.Utilities;
    
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.entity.PlayerDeathEvent;
    import org.bukkit.event.player.PlayerJoinEvent;
    import org.bukkit.event.player.PlayerLevelChangeEvent;
    import org.bukkit.event.player.PlayerQuitEvent;
    import org.bukkit.event.player.PlayerRespawnEvent;
    import org.bukkit.scoreboard.DisplaySlot;
    import org.bukkit.scoreboard.Objective;
    import org.bukkit.scoreboard.Score;
    import org.bukkit.scoreboard.Scoreboard;
    import org.bukkit.scoreboard.ScoreboardManager;
    
    import me.digitox.ffa.Main;
    
    public class SB implements Listener{
       
        @EventHandler
        public void on(PlayerJoinEvent e) {
            for(Player all : Bukkit.getOnlinePlayers()) {
                updateSB(all);
            }
        }
       
        @EventHandler
        public void on(PlayerQuitEvent e) {
            for(Player all : Bukkit.getOnlinePlayers()) {
                updateSB(all);
            }
        }
       
    
        @EventHandler
        public void on(PlayerRespawnEvent e) {
            Player p = e.getPlayer();
            updateSB(p);
        }
       
    
        @EventHandler
        public void on(PlayerLevelChangeEvent e) {
            Player p = e.getPlayer();
            updateSB(p);
           
        }
       
    
        @EventHandler
        public void on(PlayerDeathEvent e) {
            Player p = (Player) e.getEntity();
            Player k = p.getKiller();
            updateSB(p);
            updateSB(k);
        }
    
       
       
        public static void updateSB(Player p) {
            ScoreboardManager manager = Bukkit.getScoreboardManager();
            Scoreboard board = manager.getNewScoreboard();
           
            int kills = Main.getInstance().getConfig().getInt("Stats." + p.getName() + ".Kills");
            int deaths = Main.getInstance().getConfig().getInt("Stats." + p.getName() + ".Deaths");
            double kdr = kills/deaths;
            String out = String.format("%.1f", Double.valueOf(kdr));
           
            Objective o = board.registerNewObjective("test", "dummy");
            o.setDisplaySlot(DisplaySlot.SIDEBAR);
           
            o.setDisplayName(ChatColor.translateAlternateColorCodes('&', "&8---§7[" + "&3&lFFA &9&lStats " + "§7]&8---"));
           
            Score s1 = o.getScore("            ");
            s1.setScore(7);
           
            Score name = o.getScore(ChatColor.YELLOW + "Name: " + ChatColor.WHITE + p.getName());
            name.setScore(6);
           
            Score k = o.getScore(ChatColor.YELLOW + "Kills: " + ChatColor.WHITE + kills);
            k.setScore(5);
           
            Score d = o.getScore(ChatColor.YELLOW + "Deaths: " + ChatColor.WHITE + deaths);
            d.setScore(4);
           
            Score s = o.getScore(ChatColor.YELLOW + "Streak: " + ChatColor.WHITE + p.getLevel());
            s.setScore(3);
           
            Score kd = o.getScore(ChatColor.YELLOW + "Kills: " + ChatColor.WHITE + out);
            kd.setScore(2);
           
            Score s2 = o.getScore("            ");
            s2.setScore(1);
           
            p.setScoreboard(board);
        }
    
    }
    
     
  2. Offline

    clmcd42

    You can use the PlayerMoveEvent to check if the player is below a certain Y coordinate.

    Not sure about the scoreboard, what about it doesn't work?
     
  3. Offline

    digitox

    I think i have coded it right. but when i Start the server there is no ScoreBoard?

    @clmcd42 But how do i set like the player gets the kill if a player is under the Y coordinate, and how do i set the Y coordinate?
     
  4. Offline

    clmcd42

    You'll need to store who hit the player most recently somewhere. You can access that information by using the EntityDamageByEntityEvent like so:

    Code:
        @EventHandler
        public void onEntityDamageByEntity(EntityDamageByEntityEvent e) {
            if(e.getEntity() instanceof Player && e.getDamager() instanceof Player) {
                //You can look into including other DamageCauses if you need to for your plugin
                Player attacked = (Player) e.getEntity();
                Player attacker = (Player) e.getDamager();
                //Find a way to record somewhere that the attacked player was last hit by the attacker.
            }
        }
    Then, utilize the PlayerMoveEvent to determine when a player goes below whatever Y level you want, kill them when they do, and increment the kill count of the player who last attacked them by one.

    I don't have experience with scoreboards, so I'm not really sure how to help you there. A few more pieces of advice, however; be very careful when casting an Entity to a Player. It is good practice to use an "if(entity instanceof Player)" before you do it, just to be sure you are actually dealing with a Player. What if the player is joining for the first time and is not yet in the config? Also, watch out when you are calculating your KDR. What if the players have zero deaths? Then you would be dividing by zero. Just a few things I noticed when glancing through your code, I hope I helped.
     
    Last edited: Mar 19, 2017
  5. Offline

    digitox

    @clmcd42 ok. But i'm new to coding whit PlayerMoveEvent, can you help me a little there?
    And I'm new to onEntityDamageBuEntity.
     
  6. Offline

    Drkmaster83

    It's the same concept as the other event-based programming you're doing. The names are even self-explanatory. "When a player moves - i.e. PlayerMoveEvent", "When an entity is damaged by another entity - i.e. EntityDamageByEntityEvent"... Read up on PlayerMoveEvent and EntityDamageByEntityEvent, then make a collegiate try, show us what you've attempted, tell us what's wrong, and then we'll go from there.
     
  7. Offline

    digitox

    @Drkmaster83 can you help me whit the ScorBoard?


    i don't know how to do it. i have tried so many things.
    plis help me.

    bump.
    I really need help.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Mar 23, 2017
Thread Status:
Not open for further replies.

Share This Page