Add "/quake list" command
Add TableGenerator.java in Utils (From FisheyLP) Use TableGenerator to format list command output Add number of seconds in "Starting" status Use this status in lobby signs and list command Fix arena config file lookup: load only .yml files Don't start empty arena
This commit is contained in:
parent
d0a438507e
commit
e43495d70f
@ -423,5 +423,11 @@ public abstract class Arena {
|
||||
return null;
|
||||
}
|
||||
|
||||
public String getStatus() {
|
||||
return this._etat <= this._pregame ? (this.getplayers() == this._maxplayer ? ChatColor.DARK_PURPLE + "[FULL]" :
|
||||
(this._VIP ? ChatColor.AQUA + "[VIP]" :
|
||||
(this._etat <= this._starting ? ChatColor.GOLD + "[Starting in " + this._etat + "s]" :
|
||||
ChatColor.GREEN + "[Join]"))) : ChatColor.RED + "[In Game]";
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
package com.Geekpower14.Quake.Arena;
|
||||
|
||||
import com.Geekpower14.Quake.Quake;
|
||||
import com.Geekpower14.Quake.Utils.TableGenerator;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
@ -8,6 +9,7 @@ import java.util.HashMap;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class ArenaManager {
|
||||
@ -26,8 +28,12 @@ public class ArenaManager {
|
||||
}
|
||||
ArrayList<String> Maps = new ArrayList<>();
|
||||
for(File f: folder.listFiles()) {
|
||||
String name = f.getName().replaceAll(".yml", "");
|
||||
Maps.add(name);
|
||||
if(f.getName().endsWith(".yml")) {
|
||||
String name = f.getName().replaceAll(".yml", "");
|
||||
Maps.add(name);
|
||||
|
||||
_plugin.getLogger().info("Loading: [" + f.getName() + "]");
|
||||
}
|
||||
}
|
||||
if(Maps.isEmpty())
|
||||
return;
|
||||
@ -50,7 +56,7 @@ public class ArenaManager {
|
||||
if (Type2.equalsIgnoreCase("Solo")) {
|
||||
arena = new SArena(_plugin, name, _ARENAS.size());
|
||||
_ARENAS.put(name, arena);
|
||||
} else if(Type2.equalsIgnoreCase("Team")) {
|
||||
} else if(Type2.equalsIgnoreCase("Team")) {
|
||||
arena = new TArena(_plugin, name, _ARENAS.size());
|
||||
_ARENAS.put(name, arena);
|
||||
}
|
||||
@ -169,4 +175,31 @@ public class ArenaManager {
|
||||
aren.updateScore();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void listArenas(Player player) {
|
||||
String type, status;
|
||||
|
||||
if(_ARENAS.size() < 1) {
|
||||
player.sendMessage("No Arena!");
|
||||
}
|
||||
else {
|
||||
player.sendMessage(ChatColor.LIGHT_PURPLE +"Arena List:");
|
||||
TableGenerator tg = new TableGenerator(TableGenerator.Alignment.RIGHT, TableGenerator.Alignment.LEFT, TableGenerator.Alignment.LEFT, TableGenerator.Alignment.RIGHT);
|
||||
|
||||
for(Arena aren : _ARENAS.values()) {
|
||||
if(aren instanceof SArena) {
|
||||
type="Solo";
|
||||
} else {
|
||||
type="Team";
|
||||
}
|
||||
|
||||
tg.addRow( ChatColor.RED + Integer.toString(aren._ID) + ChatColor.WHITE, ChatColor.GREEN + type , aren._name + ChatColor.WHITE, aren.getStatus());
|
||||
|
||||
}
|
||||
|
||||
for (String line : tg.generate(TableGenerator.Receiver.CLIENT, true, true)) {
|
||||
player.sendMessage(line);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -41,7 +41,7 @@ public class SArena extends Arena {
|
||||
@Override
|
||||
public Boolean loadConfig() {
|
||||
File fichier_config = new File(_plugin.getDataFolder(), "/arenas/" + _name + ".yml");
|
||||
YamlConfiguration config = YamlConfiguration.loadConfiguration((File)fichier_config);
|
||||
YamlConfiguration config = YamlConfiguration.loadConfiguration((File)fichier_config);
|
||||
if (config.contains("Nombre")) {
|
||||
int nombre = config.getInt("Nombre");
|
||||
for (int i = 0; i < nombre; i++) {
|
||||
@ -278,20 +278,25 @@ public class SArena extends Arena {
|
||||
|
||||
@Override
|
||||
public void start() {
|
||||
_etat = _ingame;
|
||||
if (_objective != null) {
|
||||
_objective.unregister();
|
||||
}
|
||||
_objective = _board.registerNewObjective(_name, "dummy");
|
||||
_objective.setDisplaySlot(DisplaySlot.SIDEBAR);
|
||||
_objective.setDisplayName("Score");
|
||||
for(APlayer play : _players.values()) {
|
||||
Player player = play.getPlayer();
|
||||
cleaner(player);
|
||||
giveStuff(player);
|
||||
tp(player);
|
||||
updateScore();
|
||||
giveEffect(player);
|
||||
if( _players.values().size() == 0) {
|
||||
_plugin.getLogger().info("Don't start empty Arena: Stop it!");
|
||||
stop();
|
||||
} else {
|
||||
_etat = _ingame;
|
||||
if (_objective != null) {
|
||||
_objective.unregister();
|
||||
}
|
||||
_objective = _board.registerNewObjective(_name, "dummy");
|
||||
_objective.setDisplaySlot(DisplaySlot.SIDEBAR);
|
||||
_objective.setDisplayName("Score");
|
||||
for(APlayer play : _players.values()) {
|
||||
Player player = play.getPlayer();
|
||||
cleaner(player);
|
||||
giveStuff(player);
|
||||
tp(player);
|
||||
updateScore();
|
||||
giveEffect(player);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -346,4 +351,4 @@ public class SArena extends Arena {
|
||||
return loc;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -20,22 +20,23 @@ public class MyCommandExecutor implements CommandExecutor {
|
||||
}
|
||||
|
||||
private void loadCommands() {
|
||||
_commands.put("leave", new LeaveCommand(_plugin));
|
||||
_commands.put("addspawn", new AddSpawnCommand(_plugin));
|
||||
_commands.put("addlobby", new AddLobbyCommand(_plugin));
|
||||
_commands.put("create", new CreateCommand(_plugin));
|
||||
_commands.put("setlobbyspawn", new SetLobbySpawnCommand(_plugin));
|
||||
_commands.put("join", new JoinCommand(_plugin));
|
||||
_commands.put("removelobby", new RemoveLobbyCommand(_plugin));
|
||||
_commands.put("removespawn", new RemoveSpawnCommand(_plugin));
|
||||
_commands.put("remove", new RemoveCommand(_plugin));
|
||||
_commands.put("save", new SaveCommand(_plugin));
|
||||
_commands.put("list", new ListCommand(_plugin));
|
||||
_commands.put("addspawn", new AddSpawnCommand(_plugin));
|
||||
_commands.put("removespawn", new RemoveSpawnCommand(_plugin));
|
||||
_commands.put("setmap", new SetMapCommand(_plugin));
|
||||
_commands.put("setmin", new SetMinCommand(_plugin));
|
||||
_commands.put("setmax", new SetMaxCommand(_plugin));
|
||||
_commands.put("addlobby", new AddLobbyCommand(_plugin));
|
||||
_commands.put("setlobbyspawn", new SetLobbySpawnCommand(_plugin));
|
||||
_commands.put("removelobby", new RemoveLobbyCommand(_plugin));
|
||||
_commands.put("join", new JoinCommand(_plugin));
|
||||
_commands.put("leave", new LeaveCommand(_plugin));
|
||||
_commands.put("start", new StartCommand(_plugin));
|
||||
_commands.put("stop", new StopCommand(_plugin));
|
||||
_commands.put("shop", new ShopCommand(_plugin));
|
||||
_commands.put("remove", new RemoveCommand(_plugin));
|
||||
_commands.put("kill", new UtilsCommand(_plugin, "kill"));
|
||||
_commands.put("add", new UtilsCommand(_plugin, "add"));
|
||||
_commands.put("lol", new UtilsCommand(_plugin, "lol"));
|
||||
@ -54,8 +55,8 @@ public class MyCommandExecutor implements CommandExecutor {
|
||||
player = (Player)sender;
|
||||
if(cmd.getName().equalsIgnoreCase("quake")) {
|
||||
if(args == null || args.length < 1) {
|
||||
player.sendMessage(ChatColor.YELLOW + "Plugin By Geekpower14");
|
||||
player.sendMessage(ChatColor.YELLOW + "Reloaded by Bl4ckSkull666 ( wwww.Survival-Piraten.de )");
|
||||
player.sendMessage(ChatColor.YELLOW + "Plugin By Geekpower14u / Bl4ckSkull666");
|
||||
player.sendMessage(ChatColor.YELLOW + "Updated bt AlkorZ3 ( Obsidia.Rx3.net )");
|
||||
player.sendMessage(ChatColor.YELLOW + "Version: " + _plugin.getDescription().getVersion());
|
||||
return true;
|
||||
}
|
||||
|
@ -232,7 +232,10 @@ public class LobbyManager {
|
||||
Block block = bloc.getBlock();
|
||||
if (block.getState() instanceof Sign) {
|
||||
Sign sign = (Sign)block.getState();
|
||||
String ligne0 = arena._etat <= arena._pregame ? (arena.getplayers() == arena._maxplayer ? ChatColor.DARK_PURPLE + "[FULL]" : (arena._VIP ? ChatColor.AQUA + "[VIP]" : (arena._etat <= arena._starting ? ChatColor.GOLD + "[Starting]" : ChatColor.GREEN + "[Join]"))) : ChatColor.RED + "[InGame]";
|
||||
/*
|
||||
String ligne0 = arena._etat <= arena._pregame ? (arena.getplayers() == arena._maxplayer ? ChatColor.DARK_PURPLE + "[FULL]" : (arena._VIP ? ChatColor.AQUA + "[VIP]" : (arena._etat <= arena._starting ? ChatColor.GOLD + "[Starting]" : ChatColor.GREEN + "[Join]"))) : ChatColor.RED + "[InGame]";
|
||||
*/
|
||||
String ligne0 = arena.getStatus();
|
||||
String tmp = "";
|
||||
if (arena instanceof SArena) {
|
||||
tmp = "S-";
|
||||
|
@ -38,7 +38,7 @@ import org.bukkit.scoreboard.Scoreboard;
|
||||
public class Quake
|
||||
extends JavaPlugin {
|
||||
public static boolean _debug = false;
|
||||
public static String _version = "3.4.0";
|
||||
public static String _version = "3.5.0";
|
||||
public static Version _ver = new Version(_version);
|
||||
public ArenaManager _am = null;
|
||||
public LobbyManager _lobby = null;
|
||||
|
240
src/com/Geekpower14/Quake/Utils/TableGenerator.java
Normal file
240
src/com/Geekpower14/Quake/Utils/TableGenerator.java
Normal file
@ -0,0 +1,240 @@
|
||||
package com.Geekpower14.Quake.Utils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
// Copyright by FisheyLP, Version 1.3 (12.08.16)
|
||||
// https://github.com/FisheyLP/TableGenerator
|
||||
|
||||
public class TableGenerator {
|
||||
|
||||
private static String delimiter = " | ";
|
||||
private static List<Character> char7 = Arrays.asList('°', '~', '@');
|
||||
private static List<Character> char5 = Arrays.asList('"', '{', '}', '(', ')', '*', 'f', 'k', '<', '>');
|
||||
private static List<Character> char4 = Arrays.asList('I', 't', ' ', '[', ']', '€');
|
||||
private static List<Character> char3 = Arrays.asList('l', '`', '³', '\'');
|
||||
private static List<Character> char2 = Arrays.asList(',', '.', '!', 'i', '´', ':', ';', '|');
|
||||
private static char char1 = '\u17f2';
|
||||
private static Pattern regex = Pattern.compile(char1+"(?:§r)?(\\s*)"
|
||||
+ "(?:§r§8)?"+char1+"(?:§r)?(\\s*)"
|
||||
+ "(?:§r§8)?"+char1+"(?:§r)?(\\s*)"
|
||||
+ "(?:§r§8)?"+char1);
|
||||
private static String colors = "[&§][0-9a-fA-Fk-oK-OrR]";
|
||||
private Alignment[] alignments;
|
||||
private List<Row> table = new ArrayList<>();
|
||||
private int columns;
|
||||
|
||||
public TableGenerator(Alignment... alignments) {
|
||||
if (alignments == null || alignments.length < 1)
|
||||
throw new IllegalArgumentException("Must atleast provide 1 alignment.");
|
||||
|
||||
this.columns = alignments.length;
|
||||
this.alignments = alignments;
|
||||
}
|
||||
|
||||
public List<String> generate(Receiver receiver, boolean ignoreColors,
|
||||
boolean coloredDistances) {
|
||||
if (receiver == null) {
|
||||
throw new IllegalArgumentException("Receiver must not be null.");
|
||||
}
|
||||
|
||||
Integer[] columWidths = new Integer[columns];
|
||||
|
||||
for (Row r : table) {
|
||||
for (int i = 0; i < columns; i++) {
|
||||
String text = r.texts.get(i);
|
||||
int length;
|
||||
|
||||
if (ignoreColors)
|
||||
length = getCustomLength(text.replaceAll(colors, ""),
|
||||
receiver);
|
||||
else length = getCustomLength(text, receiver);
|
||||
|
||||
if (columWidths[i] == null) {
|
||||
columWidths[i] = length;
|
||||
}
|
||||
|
||||
else if (length > columWidths[i]) {
|
||||
columWidths[i] = length;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
List<String> lines = new ArrayList<String>();
|
||||
|
||||
for (Row r : table) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
if (r.empty) {
|
||||
lines.add("");
|
||||
continue;
|
||||
}
|
||||
|
||||
for (int i = 0; i < columns; i++) {
|
||||
Alignment agn = alignments[i];
|
||||
String text = r.texts.get(i);
|
||||
int length;
|
||||
|
||||
if (ignoreColors)
|
||||
length = getCustomLength(text.replaceAll(colors, ""),
|
||||
receiver);
|
||||
else length = getCustomLength(text,
|
||||
receiver);
|
||||
|
||||
int empty = columWidths[i] - length;
|
||||
int spacesAmount = empty;
|
||||
if (receiver == Receiver.CLIENT)
|
||||
spacesAmount = (int) Math.floor(empty / 4d);
|
||||
int char1Amount = 0;
|
||||
if (receiver == Receiver.CLIENT)
|
||||
char1Amount = empty - 4 * spacesAmount;
|
||||
|
||||
String spaces = concatChars(' ', spacesAmount);
|
||||
String char1s = concatChars(char1, char1Amount);
|
||||
|
||||
if (coloredDistances)
|
||||
char1s = "§r§8" + char1s + "§r";
|
||||
|
||||
if (agn == Alignment.LEFT) {
|
||||
sb.append(text);
|
||||
if (i < columns - 1)
|
||||
sb.append(char1s).append(spaces);
|
||||
}
|
||||
if (agn == Alignment.RIGHT) {
|
||||
sb.append(spaces).append(char1s).append(text);
|
||||
}
|
||||
if (agn == Alignment.CENTER) {
|
||||
int leftAmount = empty / 2;
|
||||
int rightAmount = empty - leftAmount;
|
||||
|
||||
int spacesLeftAmount = leftAmount;
|
||||
int spacesRightAmount = rightAmount;
|
||||
if (receiver == Receiver.CLIENT) {
|
||||
spacesLeftAmount = (int) Math.floor(spacesLeftAmount / 4d);
|
||||
spacesRightAmount = (int) Math.floor(spacesRightAmount / 4d);
|
||||
}
|
||||
|
||||
int char1LeftAmount = 0;
|
||||
int char1RightAmount = 0;
|
||||
if (receiver == Receiver.CLIENT) {
|
||||
char1LeftAmount = leftAmount - 4 * spacesLeftAmount;
|
||||
char1RightAmount = rightAmount - 4 * spacesRightAmount;
|
||||
}
|
||||
|
||||
String spacesLeft = concatChars(' ', spacesLeftAmount);
|
||||
String spacesRight = concatChars(' ', spacesRightAmount);
|
||||
String char1Left = concatChars(char1, char1LeftAmount);
|
||||
String char1Right = concatChars(char1, char1RightAmount);
|
||||
|
||||
if (coloredDistances) {
|
||||
char1Left = "§r§8" + char1Left + "§r";
|
||||
char1Right = "§r§8" + char1Right + "§r";
|
||||
}
|
||||
|
||||
sb.append(spacesLeft).append(char1Left).append(text);
|
||||
if (i < columns - 1)
|
||||
sb.append(char1Right).append(spacesRight);
|
||||
}
|
||||
|
||||
if (i < columns - 1) sb.append("§r" + delimiter);
|
||||
}
|
||||
|
||||
String line = sb.toString();
|
||||
if (receiver == Receiver.CLIENT) {
|
||||
for (int i = 0; i < 2; i++) {
|
||||
Matcher matcher = regex.matcher(line);
|
||||
line = matcher.replaceAll("$1$2$3 ").replace("§r§8§r", "§r")
|
||||
.replaceAll("§r(\\s*)§r", "§r$1");
|
||||
}
|
||||
}
|
||||
lines.add(line);
|
||||
}
|
||||
return lines;
|
||||
}
|
||||
|
||||
protected static int getCustomLength(String text, Receiver receiver) {
|
||||
if (text == null) {
|
||||
throw new IllegalArgumentException("Text must not be null.");
|
||||
}
|
||||
if (receiver == null) {
|
||||
throw new IllegalArgumentException("Receiver must not be null.");
|
||||
}
|
||||
if (receiver == Receiver.CONSOLE) return text.length();
|
||||
|
||||
int length = 0;
|
||||
for (char c : text.toCharArray())
|
||||
length += getCustomCharLength(c);
|
||||
|
||||
return length;
|
||||
}
|
||||
|
||||
protected static int getCustomCharLength(char c) {
|
||||
if (char1 == c) return 1;
|
||||
if (char2.contains(c)) return 2;
|
||||
if (char3.contains(c)) return 3;
|
||||
if (char4.contains(c)) return 4;
|
||||
if (char5.contains(c)) return 5;
|
||||
if (char7.contains(c)) return 7;
|
||||
|
||||
return 6;
|
||||
}
|
||||
|
||||
protected String concatChars(char c, int length) {
|
||||
String s = "";
|
||||
if (length < 1) return s;
|
||||
|
||||
for (int i = 0; i < length; i++)
|
||||
s += Character.toString(c);
|
||||
return s;
|
||||
}
|
||||
|
||||
public void addRow(String... texts) {
|
||||
if (texts == null) {
|
||||
throw new IllegalArgumentException("Texts must not be null.");
|
||||
}
|
||||
if (texts != null && texts.length > columns) {
|
||||
throw new IllegalArgumentException("Too big for the table.");
|
||||
}
|
||||
|
||||
Row r = new Row(texts);
|
||||
|
||||
table.add(r);
|
||||
}
|
||||
|
||||
private class Row {
|
||||
|
||||
public List<String> texts = new ArrayList<>();
|
||||
public boolean empty = true;
|
||||
|
||||
public Row(String... texts) {
|
||||
if (texts == null) {
|
||||
for (int i = 0; i < columns; i++)
|
||||
this.texts.add("");
|
||||
return;
|
||||
}
|
||||
|
||||
for (String text : texts) {
|
||||
if (text != null && !text.isEmpty()) empty = false;
|
||||
|
||||
this.texts.add(text);
|
||||
}
|
||||
|
||||
for (int i = 0; i < columns; i++) {
|
||||
if (i >= texts.length) this.texts.add("");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public enum Receiver {
|
||||
|
||||
CONSOLE, CLIENT
|
||||
}
|
||||
|
||||
public enum Alignment {
|
||||
|
||||
CENTER, LEFT, RIGHT
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user