Add consoleColorsEnabled configuration option

This commit is contained in:
Olof Larsson 2017-07-02 17:20:51 +02:00
parent 0e4c5d7ee4
commit d74690ec7c
9 changed files with 35 additions and 17 deletions

View File

@ -46,6 +46,7 @@ public class MassiveCoreMConf extends Entity<MassiveCoreMConf>
public boolean versionSynchronizationEnabled = true; public boolean versionSynchronizationEnabled = true;
public int tabCompletionLimit = 100; public int tabCompletionLimit = 100;
public boolean recipientChatEventEnabled = true; public boolean recipientChatEventEnabled = true;
public boolean consoleColorsEnabled = true;
// -------------------------------------------- // // -------------------------------------------- //
// PERMISSIONS FORMATS // PERMISSIONS FORMATS
@ -142,9 +143,7 @@ public class MassiveCoreMConf extends Entity<MassiveCoreMConf>
// DEVELOPER // DEVELOPER
// -------------------------------------------- // // -------------------------------------------- //
public boolean debugWriters = false; public boolean debugEnabled = false;
public boolean debugActives = false;
public boolean testsEnabled = false;
// -------------------------------------------- // // -------------------------------------------- //
// SPONSOR // SPONSOR

View File

@ -3,6 +3,7 @@ package com.massivecraft.massivecore;
import com.massivecraft.massivecore.collections.MassiveList; import com.massivecraft.massivecore.collections.MassiveList;
import com.massivecraft.massivecore.command.MassiveCommand; import com.massivecraft.massivecore.command.MassiveCommand;
import com.massivecraft.massivecore.mixin.Mixin; import com.massivecraft.massivecore.mixin.Mixin;
import com.massivecraft.massivecore.mixin.MixinMessage;
import com.massivecraft.massivecore.predicate.Predicate; import com.massivecraft.massivecore.predicate.Predicate;
import com.massivecraft.massivecore.predicate.PredicateAnd; import com.massivecraft.massivecore.predicate.PredicateAnd;
import com.massivecraft.massivecore.predicate.PredicateIsClassSingleton; import com.massivecraft.massivecore.predicate.PredicateIsClassSingleton;
@ -216,7 +217,7 @@ public abstract class MassivePlugin extends JavaPlugin implements Listener, Name
// can only happen after others have been initialised. // can only happen after others have been initialised.
public void activateOne(Object object) public void activateOne(Object object)
{ {
boolean debug = MassiveCoreMConf.get() != null && MassiveCoreMConf.get().debugActives; boolean debug = MassiveCoreMConf.get() != null && MassiveCoreMConf.get().debugEnabled;
// Try collection // Try collection
if (object instanceof Iterable) if (object instanceof Iterable)
@ -460,14 +461,15 @@ public abstract class MassivePlugin extends JavaPlugin implements Listener, Name
public void log(Level level, Object... msg) public void log(Level level, Object... msg)
{ {
String imploded = Txt.implode(msg, " "); String imploded = Txt.implode(msg, " ");
ConsoleCommandSender sender = Bukkit.getConsoleSender(); ConsoleCommandSender console = Bukkit.getConsoleSender();
if (level == Level.INFO && sender != null) if (level == Level.INFO && console != null)
{ {
Bukkit.getConsoleSender().sendMessage(this.logPrefixColored + imploded); MixinMessage.get().messageOne(console, this.logPrefixColored + imploded);
} }
else else
{ {
Logger.getLogger("Minecraft").log(level, this.logPrefixPlain + imploded); Logger.getLogger("Minecraft").log(level, this.logPrefixPlain + imploded);
} }
} }
} }

View File

@ -9,6 +9,7 @@ import com.massivecraft.massivecore.event.EventMassiveCoreAfterPlayerRespawn;
import com.massivecraft.massivecore.event.EventMassiveCoreAfterPlayerTeleport; import com.massivecraft.massivecore.event.EventMassiveCoreAfterPlayerTeleport;
import com.massivecraft.massivecore.event.EventMassiveCorePermissionDeniedFormat; import com.massivecraft.massivecore.event.EventMassiveCorePermissionDeniedFormat;
import com.massivecraft.massivecore.event.EventMassiveCorePlayerToRecipientChat; import com.massivecraft.massivecore.event.EventMassiveCorePlayerToRecipientChat;
import com.massivecraft.massivecore.mixin.MixinMessage;
import com.massivecraft.massivecore.mixin.MixinVisibility; import com.massivecraft.massivecore.mixin.MixinVisibility;
import com.massivecraft.massivecore.predicate.Predicate; import com.massivecraft.massivecore.predicate.Predicate;
import com.massivecraft.massivecore.predicate.PredicateStartsWithIgnoreCase; import com.massivecraft.massivecore.predicate.PredicateStartsWithIgnoreCase;
@ -78,7 +79,7 @@ public class EngineMassiveCoreMain extends Engine
// Format and send with the format and message from this recipient's own event. // Format and send with the format and message from this recipient's own event.
String recipientMessage = String.format(recipientEvent.getFormat(), sender.getDisplayName(), recipientEvent.getMessage()); String recipientMessage = String.format(recipientEvent.getFormat(), sender.getDisplayName(), recipientEvent.getMessage());
recipient.sendMessage(recipientMessage); MixinMessage.get().messageOne(recipient, recipientMessage);
} }
// For the console // For the console

View File

@ -105,7 +105,7 @@ public abstract class WriterAbstract<OA, OB, CA, CB, FA, FB, D> extends Engine
public void reportSuccess(boolean success, String name, Throwable t) public void reportSuccess(boolean success, String name, Throwable t)
{ {
if ( ! MassiveCoreMConf.get().debugWriters) return; if ( ! MassiveCoreMConf.get().debugEnabled) return;
// Create // Create
List<String> messages = new MassiveList<>(); List<String> messages = new MassiveList<>();

View File

@ -171,8 +171,8 @@ public class MixinMessage extends Mixin
{ {
if (message instanceof String) if (message instanceof String)
{ {
String string = (String)message; String plain = (String)message;
sendee.sendMessage(string); NmsChat.get().sendChatPlain(sendee, plain);
} }
else if (message instanceof Mson) else if (message instanceof Mson)
{ {

View File

@ -1,10 +1,13 @@
package com.massivecraft.massivecore.nms; package com.massivecraft.massivecore.nms;
import com.massivecraft.massivecore.MassiveCoreMConf;
import com.massivecraft.massivecore.mixin.Mixin; import com.massivecraft.massivecore.mixin.Mixin;
import com.massivecraft.massivecore.mson.Mson; import com.massivecraft.massivecore.mson.Mson;
import com.massivecraft.massivecore.util.IdUtil; import com.massivecraft.massivecore.util.IdUtil;
import com.massivecraft.massivecore.util.Txt; import com.massivecraft.massivecore.util.Txt;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.command.ConsoleCommandSender;
import org.json.simple.JSONObject; import org.json.simple.JSONObject;
public class NmsChat extends Mixin public class NmsChat extends Mixin
@ -36,8 +39,20 @@ public class NmsChat extends Mixin
CommandSender sendee = IdUtil.getSender(sendeeObject); CommandSender sendee = IdUtil.getSender(sendeeObject);
if (sendee == null) return; if (sendee == null) return;
String message = mson.toPlain(true); String plain = mson.toPlain(true);
sendee.sendMessage(message); sendChatPlain(sendee, plain);
}
public void sendChatPlain(Object sendeeObject, String plain) {
CommandSender sendee = IdUtil.getSender(sendeeObject);
if (sendee == null) return;
MassiveCoreMConf mconf = MassiveCoreMConf.get();
if (mconf != null && !mconf.consoleColorsEnabled && sendee instanceof ConsoleCommandSender) {
plain = ChatColor.stripColor(plain);
}
sendee.sendMessage(plain);
} }
// -------------------------------------------- // // -------------------------------------------- //

View File

@ -119,8 +119,8 @@ public abstract class NmsChatAbstract extends NmsChat
} }
else else
{ {
String message = mson.toPlain(true); String plain = mson.toPlain(true);
sendee.sendMessage(message); this.sendChatPlain(sendee, plain);
} }
} }

View File

@ -29,7 +29,7 @@ public abstract class Test extends Engine
@Override @Override
public void setActiveInner(boolean active) public void setActiveInner(boolean active)
{ {
if (!MassiveCoreMConf.get().testsEnabled) return; if (!MassiveCoreMConf.get().debugEnabled) return;
this.test(); this.test();

View File

@ -4,6 +4,7 @@ import com.massivecraft.massivecore.Identified;
import com.massivecraft.massivecore.Lang; import com.massivecraft.massivecore.Lang;
import com.massivecraft.massivecore.MassiveCore; import com.massivecraft.massivecore.MassiveCore;
import com.massivecraft.massivecore.event.EventMassiveCorePermissionDeniedFormat; import com.massivecraft.massivecore.event.EventMassiveCorePermissionDeniedFormat;
import com.massivecraft.massivecore.mixin.MixinMessage;
import com.massivecraft.massivecore.nms.NmsPermissions; import com.massivecraft.massivecore.nms.NmsPermissions;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
@ -390,7 +391,7 @@ public class PermissionUtil
{ {
CommandSender sender = (CommandSender)permissible; CommandSender sender = (CommandSender)permissible;
String message = getPermissionDeniedMessage(permission); String message = getPermissionDeniedMessage(permission);
sender.sendMessage(message); MixinMessage.get().messageOne(sender, message);
} }
return false; return false;