Skip to content

Commit

Permalink
move Debug to core
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Aug 28, 2022
1 parent a23fe75 commit 58cc6e1
Show file tree
Hide file tree
Showing 28 changed files with 233 additions and 902 deletions.
13 changes: 7 additions & 6 deletions plugin/src/main/java/com/denizenscript/denizen/Denizen.java
Expand Up @@ -25,6 +25,7 @@
import com.denizenscript.denizen.utilities.command.manager.Injector;
import com.denizenscript.denizen.utilities.command.manager.messaging.Messaging;
import com.denizenscript.denizen.utilities.debugging.BStatsMetricsLite;
import com.denizenscript.denizen.utilities.debugging.DebugSubmit;
import com.denizenscript.denizen.utilities.debugging.StatsRecord;
import com.denizenscript.denizencore.utilities.debugging.Debug;
import com.denizenscript.denizen.utilities.depends.Depends;
Expand Down Expand Up @@ -130,23 +131,23 @@ public void onEnable() {
PlayerFlagHandler.dataFolder.mkdir();
}
String javaVersion = System.getProperty("java.version");
getLogger().info("Running on java version: " + javaVersion);
Debug.log("Running on java version: " + javaVersion);
if (javaVersion.startsWith("8") || javaVersion.startsWith("1.8")) {
getLogger().info("Running on fully supported Java 8. Updating to Java 17+ is recommended.");
Debug.log("Running on fully supported Java 8. Updating to Java 17+ is recommended.");
}
else if (javaVersion.startsWith("9") || javaVersion.startsWith("1.9") || javaVersion.startsWith("10") || javaVersion.startsWith("1.10")
|| javaVersion.startsWith("11")
|| javaVersion.startsWith("12") || javaVersion.startsWith("13") || javaVersion.startsWith("14") || javaVersion.startsWith("15")) {
getLogger().warning("Running unreliable Java version. Old Minecraft is built for Java 8, modern Minecraft is built for Java 17. Other Java versions are not guaranteed to function properly.");
}
else if (javaVersion.startsWith("16")) {
getLogger().info("Running on fully supported Java 16.");
Debug.log("Running on fully supported Java 16.");
}
else if (javaVersion.startsWith("17")) {
getLogger().info("Running on fully supported Java 17.");
Debug.log("Running on fully supported Java 17.");
}
else {
getLogger().info("Running on unrecognized (future?) Java version. May or may not work.");
Debug.log("Running on unrecognized (future?) Java version. May or may not work.");
}
if (!NMSHandler.initialize(this)) {
getLogger().warning("-------------------------------------");
Expand Down Expand Up @@ -218,6 +219,7 @@ else if (javaVersion.startsWith("17")) {
Debug.echoError(e);
}
try {
DebugSubmit.init();
// If Citizens is enabled, Create the NPC Helper
if (Depends.citizens != null) {
npcHelper = new DenizenNPCHelper();
Expand Down Expand Up @@ -410,7 +412,6 @@ else if (javaVersion.startsWith("17")) {
Bukkit.shutdown();
}
Bukkit.getScheduler().scheduleSyncRepeatingTask(Denizen.this, () -> {
com.denizenscript.denizen.utilities.debugging.Debug.onTick();
DenizenCore.tick(50); // Sadly, minecraft has no delta timing, so a tick is always 50ms.
}, 1, 1);
InventoryTag.setupInventoryTracker();
Expand Down
@@ -1,6 +1,5 @@
package com.denizenscript.denizen.events.entity;

import com.denizenscript.denizen.nms.NMSHandler;
import com.denizenscript.denizen.objects.EntityTag;
import com.denizenscript.denizen.objects.ItemTag;
import com.denizenscript.denizen.utilities.implementation.BukkitScriptEntryData;
Expand Down
Expand Up @@ -8,6 +8,7 @@
import com.denizenscript.denizencore.objects.core.ElementTag;
import com.denizenscript.denizencore.objects.core.JavaReflectedObjectTag;
import com.denizenscript.denizencore.scripts.ScriptEntryData;
import com.denizenscript.denizencore.utilities.debugging.DebugInternals;
import org.bukkit.entity.Player;

public class PlayerReceivesPacketScriptEvent extends BukkitScriptEvent {
Expand Down Expand Up @@ -83,7 +84,7 @@ public ScriptEntryData getScriptEntryData() {

public static boolean fireFor(Player player, Object packet) {
instance.player = new PlayerTag(player);
instance.className = new ElementTag(packet.getClass().getSimpleName());
instance.className = new ElementTag(DebugInternals.getClassNameOpti(packet.getClass()));
instance.packet = packet;
return instance.fire().cancelled;
}
Expand Down
Expand Up @@ -8,6 +8,7 @@
import com.denizenscript.denizencore.objects.core.ElementTag;
import com.denizenscript.denizencore.objects.core.JavaReflectedObjectTag;
import com.denizenscript.denizencore.scripts.ScriptEntryData;
import com.denizenscript.denizencore.utilities.debugging.DebugInternals;
import org.bukkit.entity.Player;

public class PlayerSendPacketScriptEvent extends BukkitScriptEvent {
Expand Down Expand Up @@ -83,7 +84,7 @@ public ScriptEntryData getScriptEntryData() {

public static boolean fireFor(Player player, Object packet) {
instance.player = new PlayerTag(player);
instance.className = new ElementTag(packet.getClass().getSimpleName());
instance.className = new ElementTag(DebugInternals.getClassNameOpti(packet.getClass()));
instance.packet = packet;
return instance.fire().cancelled;
}
Expand Down
Expand Up @@ -7,7 +7,6 @@
import com.denizenscript.denizen.utilities.entity.FakeEntity;
import com.denizenscript.denizencore.objects.Mechanism;
import org.bukkit.*;
import org.bukkit.attribute.Attribute;
import org.bukkit.boss.BossBar;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
Expand Down
Expand Up @@ -2906,7 +2906,7 @@ public static <R extends ObjectTag> void registerSpawnedOnlyTag(Class<R> returnT
tagProcessor.registerTag(returnType, name, (attribute, object) -> {
if (!object.isSpawnedOrValidForTag()) {
if (!attribute.hasAlternative()) {
com.denizenscript.denizen.utilities.debugging.Debug.echoError("Entity is not spawned, but tag '" + attribute.getAttributeWithoutParam(1) + "' requires the entity be spawned, for entity: " + object.debuggable());
Debug.echoError("Entity is not spawned, but tag '" + attribute.getAttributeWithoutParam(1) + "' requires the entity be spawned, for entity: " + object.debuggable());
}
return null;
}
Expand Down Expand Up @@ -3963,7 +3963,7 @@ else if (getBukkitEntity() instanceof Creeper) {
NMSHandler.playerHelper.setAttackCooldown((Player) getLivingEntity(), Math.round(NMSHandler.playerHelper.getMaxAttackCooldownTicks((Player) getLivingEntity()) * mechanism.getValue().asFloat()));
}
else {
com.denizenscript.denizen.utilities.debugging.Debug.echoError("Invalid percentage! \"" + percent + "\" is not between 0 and 1!");
Debug.echoError("Invalid percentage! \"" + percent + "\" is not between 0 and 1!");
}
}

Expand Down
Expand Up @@ -2,7 +2,7 @@

import com.denizenscript.denizen.objects.*;
import com.denizenscript.denizen.utilities.Settings;
import com.denizenscript.denizencore.utilities.debugging.Debug;
import com.denizenscript.denizencore.DenizenCore;
import com.denizenscript.denizencore.objects.core.ElementTag;
import com.denizenscript.denizencore.objects.Mechanism;
import com.denizenscript.denizencore.objects.core.ListTag;
Expand Down Expand Up @@ -95,7 +95,7 @@ public static void registerTags() {
output.append(val.replaceAll("\\w+@", ""));
}
else {
output.append(ChatColor.stripColor(com.denizenscript.denizen.utilities.debugging.Debug.cleanTextForDebugOutput(object.debuggable())));
output.append(ChatColor.stripColor(DenizenCore.implementation.applyDebugColors(object.debuggable())));
}
}
if (i == list.size() - 2) {
Expand Down
Expand Up @@ -9,6 +9,7 @@
import com.denizenscript.denizencore.scripts.ScriptEntry;
import com.denizenscript.denizencore.scripts.containers.ScriptContainer;
import com.denizenscript.denizencore.utilities.YamlConfiguration;
import com.denizenscript.denizencore.utilities.debugging.DebugInternals;
import com.denizenscript.denizencore.utilities.text.StringHolder;

import java.util.*;
Expand Down Expand Up @@ -231,7 +232,7 @@ public Map<String, String> getIdMapFor(Class<? extends AbstractTrigger> trigger,
}
}
catch (Exception ex) {
Debug.echoError("Warning: improperly defined " + trigger.getSimpleName() + " trigger for script '" + getName() + "' (basic formatting error?)!");
Debug.echoError("Warning: improperly defined " + DebugInternals.getClassNameOpti(trigger) + " trigger for script '" + getName() + "' (basic formatting error?)!");
Debug.echoError(ex);
}
return idMap;
Expand Down
Expand Up @@ -90,7 +90,7 @@ public void run(ReplaceableTagEvent event) {

public static HashSet<String> deprecatedServerUtilTags = new HashSet<>(Arrays.asList("current_time_millis", "real_time_since_start",
"delta_time_since_start", "current_tick", "available_processors", "ram_usage", "ram_free", "ram_max", "ram_allocated", "disk_usage",
"disk_total", "disk_free", "started_time", "has_file", "list_files", "notes", "last_reload", "scripts", "sql_connections", "java_version"));
"disk_total", "disk_free", "started_time", "has_file", "list_files", "notes", "last_reload", "scripts", "sql_connections", "java_version", "stack_trace"));

public void serverTag(ReplaceableTagEvent event) {
if (!event.matches("server") || event.replaced()) {
Expand Down Expand Up @@ -1338,6 +1338,14 @@ else if (value.startsWith("e@")) {
// @description
// Deprecated in favor of <@link tag util.last_reload>
// -->

// <--[tag]
// @attribute <server.stack_trace>
// @returns ElementTag
// @deprecated use util.stack_trace
// @description
// Deprecated in favor of <@link tag util.stack_trace>
// -->
if (deprecatedServerUtilTags.contains(attribute.getAttributeWithoutParam(1))) {
event.setReplacedObject(UtilTagBase.instance.getObjectAttribute(attribute));
return;
Expand Down Expand Up @@ -2328,20 +2336,6 @@ else if (attribute.startsWith("generate_loot_table") && attribute.hasParam()) {
event.setReplacedObject(result.getObjectAttribute(attribute.fulfill(1)));
}

// <--[tag]
// @attribute <server.stack_trace>
// @returns ElementTag
// @description
// Generates and shows a stack trace for the current context.
// This tag is strictly for internal debugging reasons.
// WARNING: Different Java versions generate different stack trace formats and details.
// WARNING: Java internally limits stack trace generation in a variety of ways. This tag cannot be relied on to output anything.
// -->
else if (attribute.startsWith("stack_trace")) {
String trace = com.denizenscript.denizen.utilities.debugging.Debug.getFullExceptionMessage(new RuntimeException("TRACE"), false);
event.setReplacedObject(new ElementTag(trace).getObjectAttribute(attribute.fulfill(1)));
}

// <--[tag]
// @attribute <server.area_notes_debug>
// @returns MapTag
Expand Down
Expand Up @@ -10,6 +10,7 @@
import com.denizenscript.denizencore.objects.core.ElementTag;
import com.denizenscript.denizencore.objects.notable.NoteManager;
import com.denizenscript.denizencore.utilities.CoreUtilities;
import com.denizenscript.denizencore.utilities.debugging.DebugInternals;
import net.citizensnpcs.api.npc.NPC;
import org.bukkit.*;
import org.bukkit.block.Biome;
Expand Down Expand Up @@ -92,7 +93,7 @@ public static void registerMainObjects() {
if (CoreConfiguration.debugVerbose) {
StringBuilder debug = new StringBuilder(256);
for (ObjectType<?> objectType : ObjectFetcher.objectsByPrefix.values()) {
debug.append(objectType.clazz.getSimpleName()).append(" as ").append(objectType.prefix).append(", ");
debug.append(DebugInternals.getClassNameOpti(objectType.clazz)).append(" as ").append(objectType.prefix).append(", ");
}
Debug.echoApproval("Loaded core object types: [" + debug.substring(0, debug.length() - 2) + "]");
}
Expand Down
Expand Up @@ -19,6 +19,7 @@ public class Settings {
public static void refillCache() {
FileConfiguration config = Denizen.getInstance().getConfig();
// Core
CoreConfiguration.debugRecordingAllowed = true;
CoreConfiguration.defaultDebugMode = config.getBoolean("Debug.Show", true);
CoreConfiguration.shouldShowDebug = CoreConfiguration.defaultDebugMode;
CoreConfiguration.debugExtraInfo = config.getBoolean("Debug.Extra info", false);
Expand Down Expand Up @@ -55,6 +56,10 @@ public static void refillCache() {
CoreConfiguration.allowReflectionSet = config.getBoolean("Reflection.Allow set command", false);
CoreConfiguration.allowReflectionSetPrivate = config.getBoolean("Reflection.Allow set private fields", false);
CoreConfiguration.allowReflectionSetFinal = config.getBoolean("Reflection.Allow set final fields", false);
CoreConfiguration.debugLimitPerTick = config.getInt("Debug.Limit per tick", 5000);
CoreConfiguration.debugTrimLength = config.getInt("Debug.Trim length limit", 1024);
CoreConfiguration.debugPrefix = config.getString("Debug.Prefix", "");
CoreConfiguration.debugLineLength = config.getInt("Debug.Line length", 300);
String scriptEncoding = config.getString("Scripts.Encoding", "default");
if (scriptEncoding.equalsIgnoreCase("default")) {
CoreConfiguration.scriptEncoding = null;
Expand All @@ -75,12 +80,8 @@ public static void refillCache() {
cache_showExHelp = config.getBoolean("Debug.Ex command help", true);
cache_showExDebug = config.getBoolean("Debug.Ex command debug", true);
cache_getAlternateScriptPath = config.getString("Scripts location.Alternative folder path", "plugins/Denizen");
cache_consoleWidth = config.getInt("Debug.Line length", 128);
cache_trimLength = config.getInt("Debug.Trim length limit", 1024);
cache_canRecordStats = config.getBoolean("Debug.Stats", true);
cache_defaultDebugMode = config.getBoolean("Debug.Container default", true);
cache_debugLimitPerTick = config.getInt("Debug.Limit per tick", 5000);
cache_debugPrefix = config.getString("Debug.Prefix", "");
cache_warnOnAsyncPackets = config.getBoolean("Debug.Warn on async packets", false);
cache_interactQueueSpeed = config.getString("Scripts.Interact.Queue speed", "0.5s");
cache_healthTraitEnabledByDefault = config.getBoolean("Traits.Health.Enabled", false);
Expand Down Expand Up @@ -150,11 +151,9 @@ public static void refillCache() {
public static String cache_getAlternateScriptPath, cache_healthTraitRespawnDelay,
cache_engageTimeoutInSeconds, cache_chatMultipleTargetsFormat, cache_chatNoTargetFormat,
cache_chatToTargetFormat, cache_chatWithTargetToBystandersFormat, cache_chatWithTargetsToBystandersFormat,
cache_chatToNpcFormat, cache_chatToNpcOverheardFormat, cache_interactQueueSpeed, cache_limitPath,
cache_debugPrefix;
cache_chatToNpcFormat, cache_chatToNpcOverheardFormat, cache_interactQueueSpeed, cache_limitPath;

public static int cache_consoleWidth = 128, cache_trimLength = 1024, cache_blockTagsMaxBlocks,
cache_chatHistoryMaxMessages, cache_debugLimitPerTick;
public static int cache_blockTagsMaxBlocks, cache_chatHistoryMaxMessages;

public static double cache_chatBystandersRange, cache_chatToNpcOverhearingRange;

Expand All @@ -172,14 +171,6 @@ public static boolean overrideHelp() {
return cache_overrideHelp;
}

public static int consoleWidth() {
return cache_consoleWidth;
}

public static int trimLength() {
return cache_trimLength;
}

public static boolean showExHelp() {
return cache_showExHelp;
}
Expand All @@ -192,14 +183,6 @@ public static boolean canRecordStats() {
return cache_canRecordStats;
}

public static int debugLimitPerTick() {
return cache_debugLimitPerTick;
}

public static String debugPrefix() {
return cache_debugPrefix;
}

public static String interactQueueSpeed() {
return cache_interactQueueSpeed;
}
Expand Down
Expand Up @@ -19,7 +19,6 @@
import org.bukkit.block.data.type.Door;
import org.bukkit.block.data.type.Stairs;
import org.bukkit.block.data.type.Chest;
import org.bukkit.block.data.Bisected;

import java.lang.reflect.Method;
import java.util.HashMap;
Expand Down

0 comments on commit 58cc6e1

Please sign in to comment.