1.17.x Skulls and Signs not updating

Discussion in 'Spigot Plugin Development' started by xIrinaShaykx, Jun 16, 2021.

  1. Code (Java):
    package de.irina.cookieclicker.utils;

    import de.irina.cookieclicker.CookieClicker;
    import org.bukkit.*;
    import org.bukkit.block.*;
    import org.bukkit.inventory.meta.SkullMeta;

    import java.sql.ResultSet;
    import java.sql.SQLException;
    import java.util.ArrayList;
    import java.util.HashMap;
    import java.util.List;
    import java.util.UUID;

    public class Ranking {

        static HashMap<Integer, String> rang = new HashMap<Integer, String>();

        public static void set(){
            ResultSet rs = MySQL.query("SELECT uuid FROM cookieclicker ORDER BY cookies DESC LIMIT 3");
            int in = 0;
            try{
                while(rs.next()){
                    in++;
                    rang.put(in, rs.getString("uuid"));
                }
            } catch(SQLException e){
                e.printStackTrace();
            }


            String world1 = CookieClicker.getInstance().cfg.getString("Locations.1.world");
            double x1 = CookieClicker.getInstance().cfg.getDouble("Locations.1.x");
            double y1 = CookieClicker.getInstance().cfg.getDouble("Locations.1.y");
            double z1 = CookieClicker.getInstance().cfg.getDouble("Locations.1.z");

            String world2 = CookieClicker.getInstance().cfg.getString("Locations.2.world");
            double x2 = CookieClicker.getInstance().cfg.getDouble("Locations.2.x");
            double y2 = CookieClicker.getInstance().cfg.getDouble("Locations.2.y");
            double z2 = CookieClicker.getInstance().cfg.getDouble("Locations.2.z");

            String world3 = CookieClicker.getInstance().cfg.getString("Locations.3.world");
            double x3 = CookieClicker.getInstance().cfg.getDouble("Locations.3.y");
            double y3 = CookieClicker.getInstance().cfg.getDouble("Locations.3.y");
            double z3 = CookieClicker.getInstance().cfg.getDouble("Locations.3.z");

            Location loc = new Location(Bukkit.getWorld(world1), x1, y1, z1);
            Location loc2 = new Location(Bukkit.getWorld(world2), x2, y2, z2);
            Location loc3 = new Location(Bukkit.getWorld(world3), x3, y3, z3);
            List<Location> LOC = new ArrayList<Location>();
            LOC.add(loc);
            LOC.add(loc2);
            LOC.add(loc3);

            for(int i = 0; i < LOC.size(); i++){
                int id = i+1;;
                LOC.get(i).getBlock().setType(Material.PLAYER_HEAD);
                Skull s = (Skull) LOC.get(i).getBlock().getState();
                OfflinePlayer name = Bukkit.getOfflinePlayer(UUID.fromString(rang.get(id)));
                s.setOwningPlayer(name);
                s.update(true);

                Location newloc = new Location(LOC.get(i).getWorld(), LOC.get(i).getX(), LOC.get(i).getY() - 1, LOC.get(i).getZ());
                if(newloc.getBlock().getState() instanceof Sign){
                    BlockState b = newloc.getBlock().getState();
                    Sign S = (Sign) b;
                    S.setLine(0, "Platz #" + id);
                    S.setLine(1, name.getName());
                    S.setLine(2, "");
                    S.setLine(3, Cookies.getCookies(rang.get(id)) + " Cookies");
                    S.update();
                }
            }

        }
    }
     
    It does not update the Skull and it doesnt update the Sign below it..

    Pls i need help Im frustrated
     
  2. When are youy calling this method and where from? Are you sure the code is actually being executed?
     
  3. Im calling this in the onEnable() part it sets 2 Skulls one Steve Skull and one Alex Skull but when I print the rangs out in the console after they got putted in it gives me 3 places
     
  4. I think your chunks aren't loaded, if you are calling this in your onEnable(), so try update after server restart.
     
  5. But the Thing is the Chunk are loaded its near the Spawnpoint the Statswall Structure