Skip to content

Instantly share code, notes, and snippets.

@IanPedroV
Last active February 16, 2016 19:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save IanPedroV/075c970e363fe598520c to your computer and use it in GitHub Desktop.
Save IanPedroV/075c970e363fe598520c to your computer and use it in GitHub Desktop.
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