Hey, So I've recently been trying to make my first ever plugin for a private server, the plugin basically makes the player teleport back to their spawn if they fall below y60 and should add a point to their score however I can't for the life of me figure out how to add the score every time the fall. can anyone help? here is the code: Code: @EventHandler public void join(PlayerJoinEvent event){ Player player = event.getPlayer(); ScoreboardManager m = Bukkit.getScoreboardManager(); Scoreboard b = m.getNewScoreboard(); Objective o = b.registerNewObjective(ChatColor.BLUE + "Blue", "dummy"); o.setDisplaySlot(DisplaySlot.SIDEBAR); o.setDisplayName(ChatColor.GOLD + "Score"); Score Blue = o.getScore(ChatColor.BLUE + "Blue Team: "); Score Red = o.getScore(ChatColor.RED + "Red Team: "); Blue.setScore(0); Red.setScore(0); player.setScoreboard(b); } @EventHandler public void onMove(PlayerMoveEvent event) { Player player = event.getPlayer(); Location loc = player.getLocation(); int y = loc.getBlockY(); if(y <= 60){ if(player.getName().equalsIgnoreCase("Roploplayz")){ Location Roplolocation = new Location(Bukkit.getWorld("world") , 3.5, 65, -4.5, 0, 0); player.teleport(Roplolocation); PlayerInventory inventory = player.getInventory(); inventory.clear(); ItemStack Blocks = new ItemStack(Material.DIAMOND_BLOCK, 64); player.getInventory().setItem(3, Blocks); ItemStack KnockbackS = new ItemStack(Material.STICK); KnockbackS.addUnsafeEnchantment(Enchantment.KNOCKBACK, 1); player.getInventory().setItem(0, KnockbackS); //change Blue Score } if(player.getName().equalsIgnoreCase("WhatsDeathLike")){ Location Deathlocation = new Location(Bukkit.getWorld("world") , 3.5, 65, -29.5, 0, 0); player.teleport(Deathlocation); PlayerInventory inventory = player.getInventory(); inventory.clear(); ItemStack Blocks = new ItemStack(Material.DIAMOND_BLOCK, 64); player.getInventory().setItem(1, Blocks); ItemStack KnockbackS = new ItemStack(Material.STICK); KnockbackS.addUnsafeEnchantment(Enchantment.KNOCKBACK, 1); player.getInventory().setItem(0, KnockbackS); //change Red Score } } }
scoreboard.getScore(ChatColor.BLUE + "Blue Team: ").setScore(newValue); scorebaord.getScore(ChatColor.RED + "Red Team: ").setScore(newValue); I think this is how the scoreboards work. Can't fully remember as I haven't used the API for it in quite a while.
PlayerMoveEvent happens when a player moves their mouse in addition to when they move, therefore it is called many times per second. Using PlayerMoveEvent is not an efficient way to achieve your goal from a performance viewpoint. Better to use a repeating task that checks the player's position every second or so. Then do what Mathias told you.
It Worked, Thanks so much! Okay, thanks for the suggestion ill get right on it Hey by any chance do you guys know how to make the scoreboard then update every time a player gains score? EDIT by Moderator: merged posts, please use the edit button instead of double posting.