Just implement logging

This commit is contained in:
Sam 2017-05-11 23:07:46 +01:00 committed by cnr
parent 7658046d62
commit 5c968890d3
5 changed files with 67 additions and 21 deletions

View File

@ -1,5 +1,6 @@
package mineplex.gemhunters.loot.rewards;
import mineplex.gemhunters.util.SlackRewardBot;
import org.bukkit.inventory.ItemStack;
import mineplex.core.Managers;
@ -32,15 +33,7 @@ public class LootChestReward extends LootItemReward
@Override
public void onSuccessful()
{
_inventory.addItemToInventory(new Callback<Boolean>()
{
@Override
public void run(Boolean success)
{
//DebugModule.getInstance().d("Success= " + success);
}
}, _player, _chestName + " Chest", _amount);
_inventory.addItemToInventory(success -> SlackRewardBot.logReward(_player, this, success ? "Success" : "Failure"), _player, _chestName + " Chest", _amount);
}
@Override

View File

@ -1,5 +1,9 @@
package mineplex.gemhunters.loot.rewards;
import com.sun.org.apache.xpath.internal.operations.Bool;
import mineplex.core.common.util.Callback;
import mineplex.core.server.util.TransactionResponse;
import mineplex.gemhunters.util.SlackRewardBot;
import org.bukkit.inventory.ItemStack;
import mineplex.core.Managers;
@ -35,13 +39,11 @@ public class LootGadgetReward extends LootItemReward
if (donor.ownsUnknownSalesPackage(_gadget))
{
//DebugModule.getInstance().d("Shard duplicate");
_donation.rewardCurrencyUntilSuccess(GlobalCurrency.TREASURE_SHARD, _player, "Earned", (int) (500 + 1000 * Math.random()));
_donation.rewardCurrencyUntilSuccess(GlobalCurrency.TREASURE_SHARD, _player, "Earned", (int) (500 + 1000 * Math.random()), success -> SlackRewardBot.logReward(_player, this, (success ? "Success" : "Failure") + " (Shard Dupe)"));
}
else
{
//DebugModule.getInstance().d("Adding gadget");
_donation.purchaseUnknownSalesPackage(_player, _gadget, GlobalCurrency.TREASURE_SHARD, 0, true, null);
_donation.purchaseUnknownSalesPackage(_player, _gadget, GlobalCurrency.TREASURE_SHARD, 0, true, transaction -> SlackRewardBot.logReward(_player, this, transaction == TransactionResponse.Success ? "Success" : "Failure"));
}
}

View File

@ -2,6 +2,7 @@ package mineplex.gemhunters.loot.rewards;
import java.util.concurrent.TimeUnit;
import mineplex.gemhunters.util.SlackRewardBot;
import org.bukkit.inventory.ItemStack;
import mineplex.core.Managers;
@ -70,11 +71,11 @@ public class LootRankReward extends LootItemReward
if (newRank == null)
{
_player.sendMessage(F.main("Loot", "Since you already have eternal ( You are lucky :) ). So instead you can have " + CONSOLATION_PRICE + " shards."));
_donation.rewardCurrencyUntilSuccess(GlobalCurrency.TREASURE_SHARD, _player, "Earned", CONSOLATION_PRICE);
_donation.rewardCurrencyUntilSuccess(GlobalCurrency.TREASURE_SHARD, _player, "Earned", CONSOLATION_PRICE, success -> SlackRewardBot.logReward(_player, this, (success ? "Success" : "Failure") + " (Shard Dupe)"));
return;
}
_clientManager.SaveRank(_player.getName(), _player.getUniqueId(), newRank, true);
_clientManager.SaveRank(callback -> SlackRewardBot.logReward(_player, this, callback.Name), _player.getName(), _player.getUniqueId(), newRank, true);
}
@Override

View File

@ -1,5 +1,6 @@
package mineplex.gemhunters.loot.rewards;
import mineplex.gemhunters.util.SlackRewardBot;
import org.bukkit.inventory.ItemStack;
import mineplex.core.Managers;
@ -30,7 +31,7 @@ public class LootShardReward extends LootItemReward
@Override
public void onSuccessful()
{
_donation.rewardCurrencyUntilSuccess(GlobalCurrency.TREASURE_SHARD, _player, "Earned", _amount);
_donation.rewardCurrencyUntilSuccess(GlobalCurrency.TREASURE_SHARD, _player, "Earned", _amount, success -> SlackRewardBot.logReward(_player, this, success ? "Success" : "Failure"));
}
@Override

View File

@ -0,0 +1,49 @@
package mineplex.gemhunters.util;
import mineplex.core.Managers;
import mineplex.core.common.util.UtilServer;
import mineplex.core.monitor.LagMeter;
import mineplex.core.slack.SlackAPI;
import mineplex.core.slack.SlackMessage;
import mineplex.core.slack.SlackTeam;
import mineplex.gemhunters.loot.rewards.LootItemReward;
import org.bukkit.entity.Player;
import java.net.MalformedURLException;
import java.net.URL;
import java.text.DecimalFormat;
public class SlackRewardBot
{
private static final DecimalFormat FORMAT = new DecimalFormat("0.0");
private static final String SLACK_CHANNEL_NAME = "#gem-hunters-logging";
private static final String SLACK_USERNAME = "Gem Hunters";
private static final String SLACK_ICON = "http://moppletop.github.io/mineplex/chest-image.png";
private static LagMeter _lag;
public static void logReward(Player player, LootItemReward reward, String status)
{
if (_lag == null)
{
_lag = Managers.get(LagMeter.class);
}
try
{
SlackAPI.getInstance().sendMessage(SlackTeam.DEVELOPER, SLACK_CHANNEL_NAME, new SlackMessage(SLACK_USERNAME, new URL(SLACK_ICON),
"Rewarding a " + reward.getClass().getSimpleName() +
"\nName: " + reward.getItemStack().getItemMeta().getDisplayName() +
"\nPlayer: " + player.getName() +
"\nStatus: *" + status + "*" +
"\nServer: " + UtilServer.getServerName() +
"\nTPS: " + FORMAT.format(_lag.getTicksPerSecond())),
true);
}
catch (MalformedURLException e)
{
}
}
}