From eb05d587f466787edaacd4b53b46a646f97f56e5 Mon Sep 17 00:00:00 2001 From: Olof Larsson Date: Sun, 6 Nov 2016 19:42:28 +0100 Subject: [PATCH] Initial MixinLog experiments. --- src/com/massivecraft/massivecore/Log.java | 103 ++++++++++++++++++ .../massivecraft/massivecore/MassiveCore.java | 1 + .../event/EventMassiveCoreLog.java | 32 ++++++ .../massivecore/mixin/MixinLog.java | 26 +++++ 4 files changed, 162 insertions(+) create mode 100644 src/com/massivecraft/massivecore/Log.java create mode 100644 src/com/massivecraft/massivecore/event/EventMassiveCoreLog.java create mode 100644 src/com/massivecraft/massivecore/mixin/MixinLog.java diff --git a/src/com/massivecraft/massivecore/Log.java b/src/com/massivecraft/massivecore/Log.java new file mode 100644 index 00000000..0a59a317 --- /dev/null +++ b/src/com/massivecraft/massivecore/Log.java @@ -0,0 +1,103 @@ +package com.massivecraft.massivecore; + +import com.massivecraft.massivecore.collections.MassiveMap; +import com.massivecraft.massivecore.event.EventMassiveCoreLog; +import com.massivecraft.massivecore.mixin.MixinLog; +import org.bukkit.entity.Player; +import org.bukkit.plugin.Plugin; + +import java.util.Map; +import java.util.logging.Level; + +public class Log +{ + // -------------------------------------------- // + // CONSTANTS + // -------------------------------------------- // + + public static final String FIELD_TIMESTAMP = "timestamp"; + public static final String FIELD_PLUGIN = "plugin"; + public static final String FIELD_PLAYER = "player"; + public static final String FIELD_LEVEL = "level"; + public static final String FIELD_CATEGORY = "category"; + public static final String FIELD_MESSAGE = "message"; + + // -------------------------------------------- // + // FIELDS + // -------------------------------------------- // + + private Map fields = new MassiveMap<>(); + public Map getFields() { return this.fields; } + + // -------------------------------------------- // + // CONSTRUCT + // -------------------------------------------- // + + public Log() + { + this + .timestamp(System.currentTimeMillis()) + ; + } + + // -------------------------------------------- // + // ACCESS > RAW + // -------------------------------------------- // + + public Log set(String key, Object value) + { + if (value != null) + { + this.getFields().put(key, value); + } + else + { + this.getFields().remove(key); + } + + return this; + } + + public T get(String key) + { + return (T) this.getFields().get(key); + } + + // -------------------------------------------- // + // ACCESS > SUGAR + // -------------------------------------------- // + + public Log timestamp(Long timestamp) { return this.set(FIELD_TIMESTAMP, timestamp); } + public Long timestamp() { return this.get(FIELD_TIMESTAMP); } + + public Log plugin(Plugin plugin) { return this.set(FIELD_PLUGIN, plugin); } + public Plugin plugin() { return this.get(FIELD_PLUGIN); } + + public Log player(Player player) { return this.set(FIELD_PLAYER, player); } + public Player player() { return this.get(FIELD_PLAYER); } + + public Log level(Level level) { return this.set(FIELD_LEVEL, level); } + public Level level() { return this.get(FIELD_LEVEL); } + + public Log category(String category) { return this.set(FIELD_CATEGORY, category); } + public String category() { return this.get(FIELD_CATEGORY); } + + public Log message(String message) { return this.set(FIELD_MESSAGE, message); } + public String message() { return this.get(FIELD_MESSAGE); } + + // -------------------------------------------- // + // SEND + // -------------------------------------------- // + + public void send() + { + // Run Event + EventMassiveCoreLog event = new EventMassiveCoreLog(this); + event.run(); + if (event.isCancelled()) return; + + // Send Through Mixin + MixinLog.get().send(this); + } + +} diff --git a/src/com/massivecraft/massivecore/MassiveCore.java b/src/com/massivecraft/massivecore/MassiveCore.java index 6f461f2e..37188be0 100644 --- a/src/com/massivecraft/massivecore/MassiveCore.java +++ b/src/com/massivecraft/massivecore/MassiveCore.java @@ -300,6 +300,7 @@ public class MassiveCore extends MassivePlugin MixinGamemode.class, MixinInventory.class, MixinKick.class, + MixinLog.class, MixinMassiveCraftPremium.class, MixinMessage.class, MixinModification.class, diff --git a/src/com/massivecraft/massivecore/event/EventMassiveCoreLog.java b/src/com/massivecraft/massivecore/event/EventMassiveCoreLog.java new file mode 100644 index 00000000..20eb2128 --- /dev/null +++ b/src/com/massivecraft/massivecore/event/EventMassiveCoreLog.java @@ -0,0 +1,32 @@ +package com.massivecraft.massivecore.event; + +import com.massivecraft.massivecore.Log; +import org.bukkit.event.HandlerList; + +public class EventMassiveCoreLog extends EventMassiveCore +{ + // -------------------------------------------- // + // REQUIRED EVENT CODE + // -------------------------------------------- // + + private static final HandlerList handlers = new HandlerList(); + @Override public HandlerList getHandlers() { return handlers; } + public static HandlerList getHandlerList() { return handlers; } + + // -------------------------------------------- // + // FIELD + // -------------------------------------------- // + + private final Log log; + public Log getLog() { return this.log; } + + // -------------------------------------------- // + // CONSTRUCT + // -------------------------------------------- // + + public EventMassiveCoreLog(Log log) + { + this.log = log; + } + +} diff --git a/src/com/massivecraft/massivecore/mixin/MixinLog.java b/src/com/massivecraft/massivecore/mixin/MixinLog.java new file mode 100644 index 00000000..a893416e --- /dev/null +++ b/src/com/massivecraft/massivecore/mixin/MixinLog.java @@ -0,0 +1,26 @@ +package com.massivecraft.massivecore.mixin; + +import com.massivecraft.massivecore.Log; +import com.massivecraft.massivecore.event.EventMassiveCorePlayerLeave; +import org.bukkit.event.player.PlayerJoinEvent; + +public class MixinLog extends Mixin +{ + // -------------------------------------------- // + // INSTANCE & CONSTRUCT + // -------------------------------------------- // + + private static MixinLog d = new MixinLog(); + private static MixinLog i = d; + public static MixinLog get() { return i; } + + // -------------------------------------------- // + // SEND + // -------------------------------------------- // + + public void send(Log log) + { + + } + +}