On Server Tick event?

Discussion in 'Plugin Development' started by ImPhantom, Mar 1, 2014.

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

    ImPhantom

    Sorry to be hogging all of this section but i am creating an Economy on scoreboard feature to add in my plugin with vault and shit. But i want the players balance to update like when he gets paid or he buys something. Could i do that by updating the scoreboard on Server Tick?

    Code:
    Code:java
    1. @EventHandler
    2. public void start(PlayerJoinEvent e) {
    3. ScoreboardManager manager = Bukkit.getScoreboardManager();
    4. Scoreboard board = manager.getNewScoreboard();
    5.  
    6. Objective objective = board.registerNewObjective("test", "dummy");
    7. Team team = board.registerNewTeam("Server Info");
    8.  
    9. team.setDisplayName("diss playy nammmee");
    10.  
    11. objective.setDisplaySlot(DisplaySlot.SIDEBAR);
    12. objective.setDisplayName("Test");
    13.  
    14.  
    15. Score score = objective.getScore(Bukkit.getOfflinePlayer("Balance:"));
    16.  
    17. for(Player p : Bukkit.getOnlinePlayers()){
    18. score.setScore((int) Phant0m.econ.getBalance(p.getName()));
    19. p.setScoreboard(board);
    20. }
    21. }
     
  2. Offline

    ShadowLAX

    ImPhantom Updating the scoreboard on every server tick for a lot of players would be very CPU demanding. Instead, update the player's scoreboard when there balance changes.
     
  3. Offline

    ImPhantom


    ShadowLAX

    What Event would that be though?
     
  4. Offline

    ShadowLAX

    ImPhantom You will have to make a custom event if you are not using a dependency of another economy plugin that has a balance change event of some sort.
     
  5. Offline

    Creepapa

    i use GameTickEvent

    onEnable

    Code:java
    1. private GameTickEvent gametickevent = new GameTickEvent();
    2.  
    3. private void registerGameTickEvent(){
    4. Bukkit.getScheduler().runTaskTimer(this, new Runnable(){
    5. @Override
    6. public void run(){
    7. Bukkit.getPluginManager().callEvent(gametickevent);
    8. }
    9. }, 1, 1);
    10. }


    Event

    Code:java
    1. public class GameTickEvent extends Event{
    2. private static final HandlerList handlers = new HandlerList();
    3.  
    4. @Override
    5. public HandlerList getHandlers(){
    6. return GameTickEvent.handlers;
    7. }
    8.  
    9. public static HandlerList getHandlerList(){
    10. return GameTickEvent.handlers;
    11. }
    12. }
     
Thread Status:
Not open for further replies.

Share This Page