mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2025-06-28 11:44:42 +02:00
Console Colour Support
This commit is contained in:
@ -0,0 +1,88 @@
|
||||
package com.intellectualcrafters.plot;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
|
||||
/**
|
||||
* Created by Citymonstret on 2014-09-22.
|
||||
*/
|
||||
public class ConsoleColors {
|
||||
|
||||
public static final String ANSI_RESET = "\u001B[0m";
|
||||
public static final String ANSI_BLACK = "\u001B[30m";
|
||||
public static final String ANSI_RED = "\u001B[31m";
|
||||
public static final String ANSI_GREEN = "\u001B[32m";
|
||||
public static final String ANSI_YELLOW = "\u001B[33m";
|
||||
public static final String ANSI_BLUE = "\u001B[34m";
|
||||
public static final String ANSI_PURPLE = "\u001B[35m";
|
||||
public static final String ANSI_CYAN = "\u001B[36m";
|
||||
public static final String ANSI_WHITE = "\u001B[37m";
|
||||
public static final String ANSI_BOLD = "\033[1m";
|
||||
public static final String ANSI_UNDERLINE = "\033[0m";
|
||||
public static final String ANSI_ITALIC = "\033[3m]";
|
||||
|
||||
public static String fromString(String input) {
|
||||
input = input
|
||||
.replaceAll("&0", fromChatColor(ChatColor.BLACK))
|
||||
.replaceAll("&1", fromChatColor(ChatColor.DARK_BLUE))
|
||||
.replaceAll("&2", fromChatColor(ChatColor.DARK_GREEN))
|
||||
.replaceAll("&3", fromChatColor(ChatColor.DARK_AQUA))
|
||||
.replaceAll("&4", fromChatColor(ChatColor.DARK_RED))
|
||||
.replaceAll("&5", fromChatColor(ChatColor.DARK_PURPLE))
|
||||
.replaceAll("&6", fromChatColor(ChatColor.GOLD))
|
||||
.replaceAll("&7", fromChatColor(ChatColor.GRAY))
|
||||
.replaceAll("&8", fromChatColor(ChatColor.DARK_GRAY))
|
||||
.replaceAll("&9", fromChatColor(ChatColor.BLUE))
|
||||
.replaceAll("&a", fromChatColor(ChatColor.GREEN))
|
||||
.replaceAll("&b", fromChatColor(ChatColor.AQUA))
|
||||
.replaceAll("&c", fromChatColor(ChatColor.RED))
|
||||
.replaceAll("&d", fromChatColor(ChatColor.LIGHT_PURPLE))
|
||||
.replaceAll("&e", fromChatColor(ChatColor.YELLOW))
|
||||
.replaceAll("&f", fromChatColor(ChatColor.WHITE))
|
||||
.replaceAll("&k", fromChatColor(ChatColor.MAGIC))
|
||||
.replaceAll("&l", fromChatColor(ChatColor.BOLD))
|
||||
.replaceAll("&m", fromChatColor(ChatColor.STRIKETHROUGH))
|
||||
.replaceAll("&n", fromChatColor(ChatColor.UNDERLINE))
|
||||
.replaceAll("&o", fromChatColor(ChatColor.ITALIC))
|
||||
.replaceAll("&r", fromChatColor(ChatColor.RESET))
|
||||
;
|
||||
return input + ANSI_RESET;
|
||||
}
|
||||
|
||||
public static String fromChatColor(ChatColor color) {
|
||||
switch(color) {
|
||||
case RESET:
|
||||
return ANSI_RESET;
|
||||
case GRAY:
|
||||
case DARK_GRAY:
|
||||
return ANSI_WHITE;
|
||||
case BLACK:
|
||||
return ANSI_BLACK;
|
||||
case DARK_RED:
|
||||
case RED:
|
||||
return ANSI_RED;
|
||||
case GOLD:
|
||||
case YELLOW:
|
||||
return ANSI_YELLOW;
|
||||
case DARK_GREEN:
|
||||
case GREEN:
|
||||
return ANSI_GREEN;
|
||||
case AQUA:
|
||||
case DARK_AQUA:
|
||||
return ANSI_CYAN;
|
||||
case LIGHT_PURPLE:
|
||||
case DARK_PURPLE:
|
||||
return ANSI_PURPLE;
|
||||
case BLUE:
|
||||
case DARK_BLUE:
|
||||
return ANSI_BLUE;
|
||||
case UNDERLINE:
|
||||
return ANSI_UNDERLINE;
|
||||
case ITALIC:
|
||||
return ANSI_ITALIC;
|
||||
case BOLD:
|
||||
return ANSI_BOLD;
|
||||
default:
|
||||
return "";
|
||||
}
|
||||
}
|
||||
}
|
@ -248,6 +248,27 @@ public class PlotMain extends JavaPlugin {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void setupLogger() {
|
||||
File log = new File(getMain().getDataFolder() + File.separator + "logs" + File.separator + "plots.log");
|
||||
if (!log.exists()) {
|
||||
try {
|
||||
if (!new File(getMain().getDataFolder() + File.separator + "logs").mkdirs()) {
|
||||
sendConsoleSenderMessage(C.PREFIX.s() + "&cFailed to create logs folder. Do it manually.");
|
||||
}
|
||||
if (log.createNewFile()) {
|
||||
FileWriter writer = new FileWriter(log);
|
||||
writer.write("Created at: " + new Date().toString() + "\n\n\n");
|
||||
writer.close();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
Logger.setup(log);
|
||||
Logger.add(LogLevel.GENERAL, "Logger enabled");
|
||||
}
|
||||
/**
|
||||
* On Load.
|
||||
* TODO: Load updates async
|
||||
@ -255,26 +276,8 @@ public class PlotMain extends JavaPlugin {
|
||||
@Override
|
||||
@SuppressWarnings("deprecation")
|
||||
public void onEnable() {
|
||||
{
|
||||
File log = new File(getMain().getDataFolder() + File.separator + "logs" + File.separator + "plots.log");
|
||||
if (!log.exists()) {
|
||||
try {
|
||||
if (!new File(getMain().getDataFolder() + File.separator + "logs").mkdirs()) {
|
||||
sendConsoleSenderMessage(C.PREFIX.s() + "&cFailed to create logs folder. Do it manually.");
|
||||
}
|
||||
if (log.createNewFile()) {
|
||||
FileWriter writer = new FileWriter(log);
|
||||
writer.write("Created at: " + new Date().toString() + "\n\n\n");
|
||||
writer.close();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
setupLogger();
|
||||
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
Logger.setup(log);
|
||||
Logger.add(LogLevel.GENERAL, "Logger enabled");
|
||||
}
|
||||
configs();
|
||||
|
||||
// TODO make this configurable
|
||||
@ -388,10 +391,15 @@ public class PlotMain extends JavaPlugin {
|
||||
100L, 1L);
|
||||
|
||||
if(Web.ENABLED) {
|
||||
sendConsoleSenderMessage("This is not yet implemented...");
|
||||
sendConsoleSenderMessage(C.PREFIX.s() + "This is not yet implemented...");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void options(boolean verbose) {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Get MySQL Connection
|
||||
*
|
||||
@ -432,7 +440,11 @@ public class PlotMain extends JavaPlugin {
|
||||
* @param string message
|
||||
*/
|
||||
public static void sendConsoleSenderMessage(String string) {
|
||||
getMain().getServer().getConsoleSender().sendMessage(ChatColor.translateAlternateColorCodes('&', string));
|
||||
if(getMain().getServer().getConsoleSender() == null) {
|
||||
System.out.println(ChatColor.stripColor(ConsoleColors.fromString(string)));
|
||||
} else {
|
||||
getMain().getServer().getConsoleSender().sendMessage(ChatColor.translateAlternateColorCodes('&', string));
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean teleportPlayer(Player player, Location from, Plot plot) {
|
||||
@ -589,7 +601,7 @@ public class PlotMain extends JavaPlugin {
|
||||
World world = Bukkit.getWorld(w);
|
||||
try {
|
||||
if(world.getLoadedChunks().length < 1) {
|
||||
return;
|
||||
continue;
|
||||
}
|
||||
for (Chunk chunk : world.getLoadedChunks()) {
|
||||
for (Entity entity : chunk.getEntities()){
|
||||
|
Reference in New Issue
Block a user