Solved Floor Selection Problem

Discussion in 'Plugin Development' started by MrGriefer_, Jul 4, 2017.

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

    MrGriefer_

    Hello everyone,

    I'm working on a mini game plugin called Red Alert just like Volcano in Hpixel Party Games 1, basically the floor turns from white to yellow and then yellow to orange, etc...
    I tried creating a timer (scheduleSyncRepeatingTask) that will select a random block from a Map<Location, Material> but it doesn't seem to work.
    Here is my code:
    PHP:
        private int randomBlockTimer;
        private 
    void randomBlockSelect() {
            
    this.randomBlockTimer Bukkit.getScheduler().scheduleSyncRepeatingTask(RedAlert.instance, new Runnable() {
                public 
    void run() {
                    if (!
    locations.isEmpty()) {
                        
    Random random = new Random();
                        List<
    Locationkeys = new ArrayList<Location>(locations.keySet());
                        
    Location loc keys.get(random.nextInt(keys.size()));
                        
    blockChange(loc);
                    }
                }
            }, 
    10L);
        }
    locations is Map<Location, Material>.

    EDIT: Before I run that code, I first store every block in the selected floor region to that map list. Here is my code:
    PHP:
        public void loadFloor(World world) {
            
    int minX getMinimumLocation().getBlockX();
            
    int minY getMinimumLocation().getBlockY();
            
    int minZ getMinimumLocation().getBlockZ();
          
            
    int maxX getMaximumLocation().getBlockX();
            
    int maxY getMaximumLocation().getBlockY();
            
    int maxZ getMaximumLocation().getBlockZ();
          
            for (
    int x minX<= maxXx++) {
                for (
    int y minY<= maxYy++) {
                    for (
    int z minZ<= maxZz++) {
                        
    Location loc = new Location(worldxyz);
                        
    this.locations.put(loc.getBlock().getLocation(), loc.getBlock().getType());
                    }
                }
            }
        }
     
  2. Offline

    Sethburster

    Have you attempted to debug the code? What part of it isn't working? Does it actually get the Location?Do you check if keys is empty? Is it the blockChange method causing the problem. Try adding some output statements every line and see how your code is flowing. See if its ever actually getting to blockChange(loc) and what the value of Loc is at that point.
     
  3. Offline

    MrGriefer_

    I debug my code, found out the problem thanks man for the help.
     
Thread Status:
Not open for further replies.

Share This Page