Skip to content

Commit

Permalink
Feature Adds
Browse files Browse the repository at this point in the history
- Added Metrics
- Added Reload on TradeShop Reload
  • Loading branch information
KillerOfPie committed Aug 28, 2021
1 parent bf33dce commit 807fb84
Show file tree
Hide file tree
Showing 9 changed files with 131 additions and 52 deletions.
32 changes: 32 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -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
9 changes: 8 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@

<groupId>org.shanerx</groupId>
<artifactId>tradeshop-log</artifactId>
<version>0.0.1-DEV</version>
<version>0.0.2-DEV</version>
<name>TradeShop-LOG</name>
<url>https://tradeshop.github.io/</url>
<description>Add-On plugin for Tradeshop that adds basic logging of transactions. This will later be integrated into TradeShop itself.</description>
Expand Down Expand Up @@ -123,6 +123,13 @@
<scope>provided</scope>
</dependency>

<dependency>
<groupId>org.bstats</groupId>
<artifactId>bstats-bukkit</artifactId>
<version>2.2.1</version>
<scope>compile</scope>
</dependency>

<dependency>
<groupId>com.github.Tradeshop</groupId>
<artifactId>TradeShop</artifactId>
Expand Down
13 changes: 13 additions & 0 deletions src/main/java/org/shanerx/tradeshoplog/TradeShopLOG.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -36,6 +37,9 @@ public class TradeShopLOG extends JavaPlugin {

private TransactionLogger transactionLogger;

private final int bStatsPluginID = 12596;
private Metrics metrics;

@Override
public void onEnable() {

Expand All @@ -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() {
Expand Down
7 changes: 6 additions & 1 deletion src/main/java/org/shanerx/tradeshoplog/enumys/Setting.java
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;


Expand All @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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!"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<ShopItemStack> 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()));
Expand Down
24 changes: 0 additions & 24 deletions tradeshop-log.iml

This file was deleted.

2 changes: 1 addition & 1 deletion version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.0.1-DEV
0.0.2-DEV

0 comments on commit 807fb84

Please sign in to comment.