[Sothatsit's Useful Snippets] - Block Letters, MobBarAPI, AutoRespawn + More!

Discussion in 'Resources' started by SoThatsIt, Feb 1, 2014.

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

    SoThatsIt

    Just set it to a blank string ""
     
  2. Offline

    97WaterPolo

    SoThatsIt
    I tried, using
    Code:java
    1. public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args)
    2. {
    3. Player player = (Player)sender;
    4. if (cmd.getName().equalsIgnoreCase("siglerevent") && (sender.hasPermission("SiglerEvent.use")))
    5. {
    6. player.sendMessage(OmerrgUtils.rainbowChatColor("Hallo"));
    7. try
    8. {
    9. MobBarAPI.getInstance().setStatus(player, "", 100, false);
    10. player.sendMessage("asd");
    11. }
    12. catch (Exception e)
    13. {
    14. // TODO Auto-generated catch block
    15. e.printStackTrace();
    16. }
    17. }else
    18. {
    19. player.sendMessage(red + "You do not have permission to use that command!");
    20. }
    21. return false;
    22.  
    23. }


    I am just trying to remove the bar entirely on command.
     
  3. Offline

    DarkBladee12

    SoThatsIt Just made a little class which allows you to serialize an inventory to a single string without having to use NMS code or reflection. It can be found here.
     
    SoThatsIt likes this.
  4. Offline

    jusjus112

    SoThatsIt
    I have an problem with the BossBarAPI, i have the api on playerjoinevent, it workd fine.
    But when an player dies, it is gone, and if the player joined again, it is gone!
     
  5. Offline

    SoThatsIt

    After a player teleports, dies or relogs you have to re-send the boss bar

    Awesome, ill add that now :D

    dont see why that wouldnt work, note that sometimes it takes a couple of seconds for the client to update the mob bar.
     
  6. Offline

    97WaterPolo

    SoThatsIt
    Is there another way to cancel it? Still isn't working for me :L
     
  7. Offline

    SoThatsIt

    well, i guess you could teleport the player away and back again, but that should work :F
     
  8. Offline

    97WaterPolo

  9. Offline

    calebbfmv

    You know, I was feeling special when I worked on a Dynamic Words (like the letters), but now, I don't.....
     
    SoThatsIt likes this.
  10. Offline

    jusjus112

    SoThatsIt
    And how do i resend the bar?
    I have tried this, but doesnt work:
    Code:java
    1. import org.bukkit.ChatColor;
    2. import org.bukkit.entity.Player;
    3. import org.bukkit.event.EventHandler;
    4. import org.bukkit.event.Listener;
    5. import org.bukkit.event.entity.PlayerDeathEvent;
    6. import org.bukkit.event.player.PlayerJoinEvent;
    7.  
    8. public class bossbar implements Listener {
    9.  
    10. @EventHandler
    11. public void onPlayerJoin(PlayerJoinEvent e) {
    12. Player p = e.getPlayer();
    13.  
    14. try {
    15. MobBarAPI.getInstance().setStatus(p, ChatColor.GOLD + "" + ChatColor.BOLD + "Welcome to " + ChatColor.RESET + "" + ChatColor.BOLD + ChatColor.AQUA + "Theme" + ChatColor.DARK_AQUA + "Park " + ChatColor.GOLD + "" + ChatColor.BOLD + p.getName(), 100, false);
    16. } catch (Exception e1) {
    17. // TODO Auto-generated catch block
    18. e1.printStackTrace();
    19. }
    20. }
    21.  
    22. @EventHandler
    23. public void onPlayerDeath(PlayerDeathEvent e) {
    24. Player p = e.getEntity();
    25.  
    26. try {
    27. MobBarAPI.getInstance().setStatus(p, ChatColor.GOLD + "" + ChatColor.BOLD + "Welcome to " + ChatColor.RESET + "" + ChatColor.BOLD + ChatColor.AQUA + "Theme" + ChatColor.DARK_AQUA + "Park " + ChatColor.GOLD + "" + ChatColor.BOLD + p.getName(), 100, false);
    28. } catch (Exception e1) {
    29. // TODO Auto-generated catch block
    30. e1.printStackTrace();
    31. }
    32. }
    33.  
    34.  
    35.  
    36. }
    37.  
     
  11. Offline

    SoThatsIt

    add the setting of a players status in a bukkit scheduler for like 4 ticks after the player joins/dies and use playerRespawnEvent not playerDeathEvent
     
  12. Offline

    CrazyGuy3000

    Code:java
    1. getServer().getScheduler().scheduleSyncRepeatingTask(this, new Runnable(){
    2. @Override
    3. public void run() {
    4. String floatingtext = ""+floatingint+"";
    5. Location numbers = new Location(Bukkit.getWorld("world"), -720.34303, 32.168, 296.17959);
    6.  
    7. Bukkit.broadcastMessage(""+floatingint+"");
    8.  
    9. Letter.drawString(""+floatingtext+"", Material.STAINED_CLAY, (byte) 9, numbers, Direction.NORTH);
    10.  
    11. if(floatingint != 0){
    12. floatingint --;
    13. }
    14.  
    15.  
    16. }
    17. }, 20L, 20L);


    Im using this, and Im trying to get it to show the INT that I converted from a string, it works well but it overwrites on top of the previous number each time rather than cleaning itself up, I have played with code and I can't get it to delete itself afterwards... Could you show a Letter.java with a way this is possible? thanks :)
     
  13. Offline

    SoThatsIt

    You'll need to save the last number you used, or in your case floatingint + 1, and use Letter.drawString(""+(floatingint + 1), Material.AIR, (byte) 0, numbers, Direction.NORTH);

    You need to do this before you draw your next number.

    Basicly, what im doing there is re-drawing the last text that you drew but with air blocks so it removes it
     
  14. Offline

    CrazyGuy3000

    SoThatsIt
    oh thanks, didn't think of this!

    Edit:
    SoThatsIt
    got it working, kinda. I had to run it off 2 seperate aSync's due to the String is counted as a mass string if you define it twice, The text does remove its old number but it flashes due to there being a single tick gap.

    Code:java
    1. getServer().getScheduler().scheduleSyncRepeatingTask(this, new Runnable(){
    2.  
    3. @Override
    4.  
    5. public void run() {
    6.  
    7. Location numbers = new Location(Bukkit.getWorld("world"), -720.34303, 32.168, 296.17959);
    8.  
    9. Letter.drawString(""+(floatingint + 1)+"", Material.AIR, (byte) 9, numbers, Direction.NORTH);
    10.  
    11. }
    12.  
    13. }, 21L, 21L);
    14.  
    15. getServer().getScheduler().scheduleSyncRepeatingTask(this, new Runnable(){
    16.  
    17. @Override
    18.  
    19. public void run() {
    20.  
    21. Location numbers = new Location(Bukkit.getWorld("world"), -720.34303, 32.168, 296.17959);
    22.  
    23.  
    24.  
    25.  
    26.  
    27. Letter.drawString(""+floatingint+"", Material.STAINED_CLAY, (byte) 9, numbers, Direction.NORTH);
    28.  
    29.  
    30.  
    31.  
    32.  
    33. if(floatingint != 0){
    34.  
    35. floatingint --;
    36.  
    37. Bukkit.broadcastMessage(""+floatingint+"");
    38.  
    39. }
    40.  
    41.  
    42.  
    43. }
    44.  
    45. }, 20L, 20L);


    Ideas?
     
  15. Offline

    SoThatsIt

    why are you using 2 different schedulers? all you need is one :p, then just before you set the new number remove the old one. And because we know that the old number is just the current number plus 1 we can just use floatingint + 1.

    Code:java
    1. getServer().getScheduler().scheduleSyncRepeatingTask(this , new Runnable()
    2. {
    3.  
    4. @Override
    5. public void run()
    6. {
    7. Location numbers = new Location(Bukkit.getWorld("world"), -720.34303, 32.168, 296.17959);
    8.  
    9. Letter.drawString("" + ( floatingint + 1 ) , Material.AIR , (byte) 0 , numbers , Direction.NORTH);
    10.  
    11. Letter.drawString("" + floatingint , Material.STAINED_CLAY , (byte) 9 , numbers , Direction.NORTH);
    12.  
    13. if ( floatingint != 0 )
    14. {
    15.  
    16. floatingint--;
    17.  
    18. Bukkit.broadcastMessage("" + floatingint + "");
    19.  
    20. }
    21. }
    22.  
    23. } , 20L , 20L);
     
  16. Offline

    CrazyGuy3000


    Used the exact code, http://i.imgur.com/14wqjxN.png
    you define it twice but the letter.drawString goes all into a single line

    ** TESTED BY MAKING THE AIR INTO SPONGE **
     
  17. Offline

    jesus997

    Hi, I have a problem. Use your class (Auto Respawn) to make my users automatically revive. But in console I get this error:

    Code:
    2014-02-22 23:29:44 [SEVERE] java.lang.NoSuchFieldException: minecraftServer
    2014-02-22 23:29:44 [SEVERE] at java.lang.Class.getDeclaredField(Class.java:1899)
    2014-02-22 23:29:44 [SEVERE] at me.jesus997.CPVP.GameListener$2.run(GameListener.java:163)
    2014-02-22 23:29:44 [SEVERE] at org.bukkit.craftbukkit.v1_6_R2.scheduler.CraftTask.run(CraftTask.java:53)
    2014-02-22 23:29:44 [SEVERE] at org.bukkit.craftbukkit.v1_6_R2.scheduler.CraftScheduler.mainThreadHeartbeat(CraftScheduler.java:345)
    2014-02-22 23:29:44 [SEVERE] at net.minecraft.server.v1_6_R2.MinecraftServer.t(MinecraftServer.java:522)
    2014-02-22 23:29:44 [SEVERE] at net.minecraft.server.v1_6_R2.DedicatedServer.t(DedicatedServer.java:226)
    2014-02-22 23:29:44 [SEVERE] at net.minecraft.server.v1_6_R2.MinecraftServer.s(MinecraftServer.java:486)
    2014-02-22 23:29:44 [SEVERE] at net.minecraft.server.v1_6_R2.MinecraftServer.run(MinecraftServer.java:419)
    
    Line 163 is this:

    Code:java
    1. Field minecraftServer = con.getClass().getDeclaredField("minecraftServer");


    The full code is this:

    Code:java
    1. // AutoRespawn by Sothatsit
    2. @EventHandler
    3. public void onPlayerDeath2(final PlayerDeathEvent e)
    4. {
    5. new BukkitRunnable()
    6. {
    7. @Override
    8. public void run()
    9. {
    10. try
    11. {
    12. Object nmsPlayer = e.getEntity().getClass().getMethod("getHandle").invoke(e.getEntity());
    13. Object con = nmsPlayer.getClass().getDeclaredField("playerConnection").get(nmsPlayer);
    14.  
    15. Class< ? > EntityPlayer = Class.forName(nmsPlayer.getClass().getPackage().getName() + ".EntityPlayer");
    16.  
    17. Field minecraftServer = con.getClass().getDeclaredField("minecraftServer");
    18. minecraftServer.setAccessible(true);
    19. Object mcserver = minecraftServer.get(con);
    20.  
    21. Object playerlist = mcserver.getClass().getDeclaredMethod("getPlayerList").invoke(mcserver);
    22. Method moveToWorld = playerlist.getClass().getMethod("moveToWorld" , EntityPlayer , int.class , boolean.class);
    23. moveToWorld.invoke(playerlist , nmsPlayer , 0 , false);
    24. }
    25. catch (Exception ex)
    26. {
    27. ex.printStackTrace();
    28. }
    29. }
    30. }.runTaskLater(plugin , 2);
    31. }


    You can help?, thanks!
     
  18. Offline

    SoThatsIt

    The Auto-Respawn class only works in 1.7 sorry
     
  19. Offline

    jesus997

    @SoThatsIt But I've tried it on a test server and works even if I still the same version (1.6.2). I do not understand why it does not work in online.
     
  20. Offline

    SoThatsIt

    well, the reason is in 1.7 they added a field called "minecraftServer" to the PlayerConneciton class which is not there in 1.6, so any versions which have this field in the PlayerConnection class will work and it turns out the version you are using does not.
     
  21. Offline

    jesus997

    It's very rare, I'm sure I ran the 1.6.2 R0.1, just thank you very much!. Another thing, do you know any way to call PacketPlayOutWorldEvent in 1.6.2?, I'm pretty sure you can not, but I thought I was someone with more experience tell me.
     
  22. Offline

    SoThatsIt

    All the packets changed in 1.7, PacketPlayOutWorldEvent has changed from the packet Packet61WorldEvent.

    so, in 1.6 you would need to use Packet61WorldEvent instead of PacketPlayOutWorldEvent

    you can find more about the changes that happened to packets here
    http://forums.bukkit.org/threads/info-1-7-x-protocol-changes-find-the-new-packet-names-here.201574/
     
  23. Offline

    CrazyGuy3000

    SoThatsIt Any luck with the fiasco i'm having?
     
  24. Offline

    SoThatsIt

    well, you are obviously using it wrong but im not exactly sure how.
     
  25. Offline

    Captain Dory

    Nice snippets. I'm trying out MobBarAPI, but the bar isn't showing up. My code:
    PHP:
    private static Plugin plugin;
        private 
    Scoreboard board;
        private 
    Objective Alive;
       
        public 
    void onEnable() {
     
            
    plugin this;
           
            
    Bukkit.getScoreboardManager().getNewScoreboard();
            
    Alive board.registerNewObjective("test""dummy");
            
    Alive.setDisplaySlot(DisplaySlot.SIDEBAR);
            
    Alive.setDisplayName("Alive");
            for (
    Player p Bukkit.getOnlinePlayers()) {
               
                
    int count 2;
                
    Score score Alive.getScore(p);
                
    score.setScore(count);
                
    count++;
                
    p.setScoreboard(board);
               
            }
           
        }
       
        
    MobBarAPI mbapi MobBarAPI.getInstance();
        
    void setStatus() {
           
            for (
    Player p Bukkit.getOnlinePlayers()) {
               
                try {
                   
                    
    p.sendMessage("welcome");
                   
                    
    mbapi.setStatus(p"Rebels VS Forgotten"50true);
                   
                } catch (
    Exception e) {
                   
                    
    p.sendMessage("Could not set up MobBarAPI");
                   
                    
    e.printStackTrace();
                   
                }
           
            }
           
        }
     
        public 
    void onDisable() {
     
            
    plugin null;
           
            
    saveConfig();
     
        }
       
        public 
    boolean onCommand(CommandSender sCommand cmdString labelString [] args) {
           
            if (
    cmd.getName().equals("team1p")) {
               
                
    s.sendMessage("Hi");
               
            }
           
            return 
    false;
           
        }
     
        public static 
    void registerEvents(org.bukkit.plugin.Plugin pluginListener... listeners) {
           
            for (
    Listener listener listeners) {
               
                
    Bukkit.getServer().getPluginManager().registerEvents(listenerplugin);
               
            }
           
        }
       
        public static 
    Plugin getPlugin() {
           
            return 
    plugin;
           
        }
    Any help appreciated, thaanks :)
     
  26. Offline

    SoThatsIt

    You'll have to send them the mob bar when they log in
     
  27. Offline

    Captain Dory

    Thanks! Got it working :) This is really cool. By the way, can mob bars display any sort of string, or are there limitations?
     
  28. Offline

    SoThatsIt

    its limited to 128 characters but other than that should be able to display any text that you can send to a player in a message :)
     
  29. Offline

    Captain Dory

    Ok thanks :)
     
  30. Offline

    somebody7136

    SoThatsIt
    I'm new-ish to coding, so how would I use your Letter system? Interested in making multi line text for lobbies.

    Thanks!
     
Thread Status:
Not open for further replies.

Share This Page