diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..eb7cc58
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,32 @@
+# Compiled binaries
+/target/
+*.class
+/bin/
+
+# Package files
+*.jar
+*.war
+*.ear
+*.zip
+*.tar.gz
+*.rar
+
+# Redundant Gradle files
+/.gradle/
+/build/
+
+# IntelliJ IDEA project files
+/.idea/
+*.iml
+
+# Eclipse project files
+/.settings/
+.classpath
+.project
+
+# Redundant Maven files
+dependency-reduced-pom.xml
+
+# Temporary and log files
+**/temp.**
+*.log
\ No newline at end of file
diff --git a/pom.xml b/pom.xml
index c730091..01e0999 100644
--- a/pom.xml
+++ b/pom.xml
@@ -31,7 +31,7 @@
org.shanerx
tradeshop-log
- 0.0.1-DEV
+ 0.0.2-DEV
TradeShop-LOG
https://tradeshop.github.io/
Add-On plugin for Tradeshop that adds basic logging of transactions. This will later be integrated into TradeShop itself.
@@ -123,6 +123,13 @@
provided
+
+ org.bstats
+ bstats-bukkit
+ 2.2.1
+ compile
+
+
com.github.Tradeshop
TradeShop
diff --git a/src/main/java/org/shanerx/tradeshoplog/TradeShopLOG.java b/src/main/java/org/shanerx/tradeshoplog/TradeShopLOG.java
index a22e1e3..77e355d 100644
--- a/src/main/java/org/shanerx/tradeshoplog/TradeShopLOG.java
+++ b/src/main/java/org/shanerx/tradeshoplog/TradeShopLOG.java
@@ -25,6 +25,7 @@
package org.shanerx.tradeshoplog;
+import org.bstats.bukkit.Metrics;
import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.java.JavaPlugin;
import org.shanerx.tradeshop.utils.Updater;
@@ -36,6 +37,9 @@ public class TradeShopLOG extends JavaPlugin {
private TransactionLogger transactionLogger;
+ private final int bStatsPluginID = 12596;
+ private Metrics metrics;
+
@Override
public void onEnable() {
@@ -46,11 +50,20 @@ public void onEnable() {
PluginManager pm = getServer().getPluginManager();
pm.registerEvents(new SuccessfulTradeEventListener(this), this);
+ pm.registerEvents(new TradeShopReloadEventListener(), this);
if (Setting.CHECK_UPDATES.getBoolean()) {
new Thread(() -> getUpdater().checkCurrentVersion()).start();
}
+ if (Setting.ALLOW_METRICS.getBoolean()) {
+ metrics = new Metrics(this, bStatsPluginID);
+ getLogger().info("Metrics successfully initialized!");
+
+ } else {
+ getLogger().warning("Metrics are disabled! Please consider enabling them to support the authors!");
+ }
+
}
public Updater getUpdater() {
diff --git a/src/main/java/org/shanerx/tradeshoplog/enumys/Setting.java b/src/main/java/org/shanerx/tradeshoplog/enumys/Setting.java
index 6d062d6..bdcf07f 100644
--- a/src/main/java/org/shanerx/tradeshoplog/enumys/Setting.java
+++ b/src/main/java/org/shanerx/tradeshoplog/enumys/Setting.java
@@ -45,13 +45,18 @@ public enum Setting {
CONFIG_VERSION(SettingSectionKeys.NONE, "config-version", 1.0, "", "\n"),
+ // Language Options
+ MESSAGE_PREFIX(SettingSectionKeys.LANGUAGE_OPTIONS, "message-prefix", "&a[&eTradeShop-LOG&a] ", "The prefix the displays before all plugin messages", "\n"),
+
+ // System Options
ENABLE_DEBUG(SettingSectionKeys.SYSTEM_OPTIONS, "enable-debug", 0, "What debug code should be run. this will add significant amounts of spam to the console/log, generally not used unless requested by Devs (must be a whole number)"),
CHECK_UPDATES(SettingSectionKeys.SYSTEM_OPTIONS, "check-updates", true, "Should we check for updates when the server starts"),
OUTPUT_TYPE(SettingSectionKeys.SYSTEM_OPTIONS, "output-type", "TSV", "How should the output file be formatted\n # Options: `TSV` - Tab Separated Value file"),
LOG_TIME_SEPARATION(SettingSectionKeys.SYSTEM_OPTIONS, "log-time-separation", "H", "How often should we create new log files.\n # Options: `M` - Month, `d` - Day, `H` - Hour, `m` - Minute, `s` - Second"),
TRANSACTION_LOG_FORMAT(SettingSectionKeys.SYSTEM_OPTIONS, "transaction-log-format", "%Date_@_%Time_@_%ShopType_@_%Owner_@_%TradingPlayer_@_%World_@_%X_@_%Y_@_%Z_@_%CostList_@_%ProductList"
, "How should the output entries be formatted, each value must be seperated by `_@_`\n # Changes to this may cause formatting errors in the current output log, please remove old output logs once you have changed this." +
- "\n # Values: \n # %Date \n # %Time \n # %ShopType \n # %Owner \n # %TradingPlayer \n # %ShopLocation \n # %World \n # %X \n # %Y \n # %Z \n # %CostList \n # %ProductList");
+ "\n # Values: \n # %Date \n # %Time \n # %ShopType \n # %Owner \n # %TradingPlayer \n # %ShopLocation \n # %World \n # %X \n # %Y \n # %Z \n # %CostList \n # %ProductList"),
+ ALLOW_METRICS(SettingSectionKeys.SYSTEM_OPTIONS, "allow-metrics", true, "Allow us to connect anonymous metrics so we can see how our plugin is being used to better develop it");
private static TradeShopLOG plugin = (TradeShopLOG) Bukkit.getPluginManager().getPlugin("TradeShop-LOG");
diff --git a/src/main/java/org/shanerx/tradeshoplog/listeners/SuccessfulTradeEventListener.java b/src/main/java/org/shanerx/tradeshoplog/listeners/SuccessfulTradeEventListener.java
index 79b7f53..d738984 100644
--- a/src/main/java/org/shanerx/tradeshoplog/listeners/SuccessfulTradeEventListener.java
+++ b/src/main/java/org/shanerx/tradeshoplog/listeners/SuccessfulTradeEventListener.java
@@ -28,7 +28,7 @@
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
-import org.shanerx.tradeshop.framework.events.SuccessfulTradeEvent;
+import org.shanerx.tradeshop.framework.events.PlayerSuccessfulTradeEvent;
import org.shanerx.tradeshoplog.TradeShopLOG;
@@ -41,7 +41,7 @@ public SuccessfulTradeEventListener(TradeShopLOG tradeShopARM) {
}
@EventHandler(priority = EventPriority.MONITOR)
- public void onSuccessfulTrade(SuccessfulTradeEvent event) {
+ public void onSuccessfulTrade(PlayerSuccessfulTradeEvent event) {
if(!event.isCancelled()) {
tradeShopLOG.getTransactionLogger().logTransaction(event);
}
diff --git a/src/main/java/org/shanerx/tradeshoplog/listeners/TradeShopReloadEventListener.java b/src/main/java/org/shanerx/tradeshoplog/listeners/TradeShopReloadEventListener.java
new file mode 100644
index 0000000..f5ba732
--- /dev/null
+++ b/src/main/java/org/shanerx/tradeshoplog/listeners/TradeShopReloadEventListener.java
@@ -0,0 +1,45 @@
+/*
+ *
+ * Copyright (c) 2016-2019
+ * SparklingComet @ http://shanerx.org
+ * KillerOfPie @ http://killerofpie.github.io
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * NOTICE: All modifications made by others to the source code belong
+ * to the respective contributor. No contributor should be held liable for
+ * any damages of any kind, whether be material or moral, which were
+ * caused by their contribution(s) to the project. See the full License for more information.
+ *
+ */
+
+package org.shanerx.tradeshoplog.listeners;
+
+import org.bukkit.event.EventHandler;
+import org.bukkit.event.EventPriority;
+import org.bukkit.event.Listener;
+import org.shanerx.tradeshop.framework.events.TradeShopReloadEvent;
+import org.shanerx.tradeshop.utils.Utils;
+import org.shanerx.tradeshoplog.enumys.Setting;
+
+
+public class TradeShopReloadEventListener implements Listener {
+
+ public TradeShopReloadEventListener() {}
+
+ @EventHandler(priority = EventPriority.MONITOR)
+ public void onTradeShopReload(TradeShopReloadEvent event) {
+ Setting.reload();
+ event.sender.sendMessage(new Utils().colorize(Setting.MESSAGE_PREFIX.getString() + "&6The configuration files have been reloaded!"));
+ }
+}
diff --git a/src/main/java/org/shanerx/tradeshoplog/utils/logging/TransactionLogger.java b/src/main/java/org/shanerx/tradeshoplog/utils/logging/TransactionLogger.java
index c79c264..6b34212 100644
--- a/src/main/java/org/shanerx/tradeshoplog/utils/logging/TransactionLogger.java
+++ b/src/main/java/org/shanerx/tradeshoplog/utils/logging/TransactionLogger.java
@@ -4,7 +4,7 @@
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonObject;
-import org.shanerx.tradeshop.framework.events.SuccessfulTradeEvent;
+import org.shanerx.tradeshop.framework.events.PlayerSuccessfulTradeEvent;
import org.shanerx.tradeshop.objects.Shop;
import org.shanerx.tradeshop.objects.ShopItemStack;
import org.shanerx.tradeshoplog.TradeShopLOG;
@@ -55,34 +55,35 @@ private PrintWriter buildWriter() {
return null;
}
- public void logTransaction(SuccessfulTradeEvent event) {
+ public void logTransaction(PlayerSuccessfulTradeEvent event) {
PrintWriter printWriter = buildWriter();
- assert printWriter != null;
- Shop shop = event.getShop();
- String localFormat = Setting.TRANSACTION_LOG_FORMAT.getString().replaceAll("_@_", loggerOutputType.getDelimiter());
+ if(printWriter != null) {
+ Shop shop = event.getShop();
+ String localFormat = Setting.TRANSACTION_LOG_FORMAT.getString().replaceAll("_@_", loggerOutputType.getDelimiter());
- if(newFile) {
- printWriter.println(localFormat.replaceAll("%", ""));
- newFile = false;
+ if (newFile) {
+ printWriter.println(localFormat.replaceAll("%", ""));
+ newFile = false;
+ }
+ printWriter.println(localFormat
+ .replaceAll("%Date", getTransactionDate())
+ .replaceAll("%Time", getTransactionTime())
+ .replaceAll("%ShopType", shop.getShopType().toString())
+ .replaceAll("%Owner", shop.getOwner().getName())
+ .replaceAll("%TradingPlayer", event.getPlayer().getName())
+ .replaceAll("%ShopLocation", shop.getShopLocationAsSL().toString())
+ .replaceAll("%World", shop.getShopLocationAsSL().getWorldName())
+ .replaceAll("%X", shop.getShopLocationAsSL().getX() + "")
+ .replaceAll("%Y", shop.getShopLocationAsSL().getY() + "")
+ .replaceAll("%Z", shop.getShopLocationAsSL().getZ() + "")
+ .replaceAll("%CostList", "\"" + getItemListAsString(event.getCost()) + "\"")
+ .replaceAll("%ProductList", "\"" + getItemListAsString(event.getProduct())) + "\"");
+ printWriter.close();
}
- printWriter.println(localFormat
- .replaceAll("%Date", getTransactionDate())
- .replaceAll("%Time", getTransactionTime())
- .replaceAll("%ShopType", shop.getShopType().toString())
- .replaceAll("%Owner", shop.getOwner().getName())
- .replaceAll("%TradingPlayer", event.getPlayer().getName())
- .replaceAll("%ShopLocation", shop.getShopLocationAsSL().toString())
- .replaceAll("%World", shop.getShopLocationAsSL().getWorldName())
- .replaceAll("%X", shop.getShopLocationAsSL().getX() + "")
- .replaceAll("%Y", shop.getShopLocationAsSL().getY() + "")
- .replaceAll("%Z", shop.getShopLocationAsSL().getZ() + "")
- .replaceAll("%CostList", "\"" + getItemListAsString(event.getCost()) + "\"")
- .replaceAll("%ProductList", "\"" + getItemListAsString(event.getProduct())) + "\"");
- printWriter.close();
}
private String getItemListAsString(List itemList) {
- final Gson gson = new GsonBuilder().serializeNulls().create();
+ final Gson gson = new GsonBuilder().create();
JsonObject jsonObj = new JsonObject();
for (int i = 0; i < itemList.size(); i++) {
jsonObj.add(i + "", gson.toJsonTree(itemList.get(i).getItemStack()));
diff --git a/tradeshop-log.iml b/tradeshop-log.iml
deleted file mode 100644
index 0f389a8..0000000
--- a/tradeshop-log.iml
+++ /dev/null
@@ -1,24 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/version.txt b/version.txt
index 99e70be..4a57655 100644
--- a/version.txt
+++ b/version.txt
@@ -1 +1 @@
-0.0.1-DEV
\ No newline at end of file
+0.0.2-DEV
\ No newline at end of file