-
-
Save IanPedroV/075c970e363fe598520c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package br.com.vidacraft.utilities; | |
import java.util.ArrayList; | |
import java.util.List; | |
import org.bukkit.Bukkit; | |
import org.bukkit.ChatColor; | |
import org.bukkit.Location; | |
import org.bukkit.Material; | |
import org.bukkit.World; | |
import org.bukkit.block.Block; | |
import org.bukkit.block.Sign; | |
import br.com.vidacraft.core.Arena; | |
import br.com.vidacraft.core.ArenaManager; | |
import br.com.vidacraft.core.ArenaState; | |
import br.com.vidacraft.utilities.coboid.Cuboid; | |
import br.com.vidacraft.utilities.tasks.Task; | |
public class SignUpdater { | |
static List<Location> signsLocs = new ArrayList<>(); | |
public static void signUpdate() { | |
getSigns(); | |
for (Location loc : signsLocs) { | |
signUpdater(loc); | |
} | |
} | |
public static void signUpdater(Location bLocation) { | |
World w = bLocation.getWorld(); | |
Block b = w.getBlockAt(bLocation); | |
new Task(Task.REPEATING, 3 * 20) { | |
public void update() { | |
if (b.getTypeId() == Material.SIGN_POST.getId() || b.getTypeId() == Material.WALL_SIGN.getId()) { | |
Sign sign = (Sign) b.getState(); | |
Arena a = ArenaManager.getManager().getArena(sign.getLine(2)); | |
for (int i = 0; i < ArenaManager.getManager().getArenasQuantity(); i++) { | |
sign.setLine(0, "------------"); | |
} | |
if (a.getGameState() == ArenaState.WAITING) { | |
sign.setLine(1, colorize("&2[Aguardando]")); | |
} | |
if (a.getGameState() == ArenaState.STARTING) { | |
sign.setLine(1, "[Iniciando]"); | |
} | |
if (sign.getLine(1) == "RUNNING") { | |
sign.setLine(1, "[No Jogo]"); | |
} | |
if (sign.getLine(1) == "RESTARTING") { | |
sign.setLine(1, "[Reiniciando]"); | |
} | |
sign.setLine(2, a.getName()); | |
sign.setLine(3, String.valueOf(a.getPlayers().size() + "/" + a.getMaximumPlayers())); | |
sign.update(); | |
} | |
} | |
}; | |
} | |
public static void getSigns() { | |
Location loc1 = new Location(Bukkit.getWorld("swlobby"), -665, 12, -2140); | |
Location loc2 = new Location(Bukkit.getWorld("swlobby"), -664, 8, -2148); | |
Cuboid cuboid = new Cuboid(loc1, loc2); | |
for (Block block : cuboid.getBlocks()) { | |
Location loc = block.getLocation(); | |
World w = loc.getWorld(); | |
Block b = w.getBlockAt(loc); | |
if (b.getTypeId() == Material.SIGN_POST.getId() || b.getTypeId() == Material.WALL_SIGN.getId()) { | |
signsLocs.add(block.getLocation()); | |
} | |
} | |
} | |
private static String colorize(String input) { | |
return ChatColor.translateAlternateColorCodes('&', input); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment