Skip to content

Commit

Permalink
Fix extras maximums loading late and fix tokenmanager
Browse files Browse the repository at this point in the history
  • Loading branch information
Trophonix committed Dec 27, 2018
1 parent 9678942 commit 6570950
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
6 changes: 5 additions & 1 deletion src/main/java/com/trophonix/tradeplus/extras/Extra.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public abstract class Extra {
final ItemStack theirIcon;
final double taxPercent;
public double value1 = 0, value2 = 0;
double min;
double max1;
double max2;
long lastUpdatedMax = System.currentTimeMillis();
Expand All @@ -27,7 +28,10 @@ public abstract class Extra {
ConfigurationSection section = pl.getConfig().getConfigurationSection("extras." + name);
this.player1 = player1;
this.player2 = player2;
this.increment = section.getDouble("increment");
this.increment = section.getDouble("increment", 1D);
this.min = section.getDouble("minimum", 1D);
this.max1 = getMax(player1);
this.max2 = getMax(player2);
this.increment1 = increment;
this.increment2 = increment;
ItemFactory factory = new ItemFactory(section.getString("material", "PAPER"), Material.PAPER)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,30 @@

import com.trophonix.tradeplus.TradePlus;
import com.trophonix.tradeplus.util.ItemFactory;
import me.realized.tokenmanager.api.TokenManager;
import org.bukkit.Bukkit;
import me.realized.tokenmanager.TokenManagerPlugin;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;

public class TokenManagerExtra extends Extra {

private TokenManager tokenManager;


public TokenManagerExtra(Player player1, Player player2, TradePlus pl) {
super("tokenmanager", player1, player2, pl);
tokenManager = (TokenManager) Bukkit.getPluginManager().getPlugin("TokenManager");
}

@Override
public double getMax(Player player) {
return tokenManager.getTokens(player).orElse(0);
return TokenManagerPlugin.getInstance().getTokens(player).orElse(0);
}

@Override
public void onTradeEnd() {
if (value1 > 0) {
tokenManager.removeTokens(player1.getUniqueId().toString(), (long)value1);
tokenManager.addTokens(player2.getUniqueId().toString(), (long)value1);
TokenManagerPlugin.getInstance().removeTokens(player1.getUniqueId().toString(), (long)value1);
TokenManagerPlugin.getInstance().addTokens(player2.getUniqueId().toString(), (long)value1);
}
if (value2 > 0) {
tokenManager.removeTokens(player2.getUniqueId().toString(), (long)value2);
tokenManager.addTokens(player1.getUniqueId().toString(), (long)value1);
TokenManagerPlugin.getInstance().removeTokens(player2.getUniqueId().toString(), (long)value2);
TokenManagerPlugin.getInstance().addTokens(player1.getUniqueId().toString(), (long)value1);
}
}

Expand Down

0 comments on commit 6570950

Please sign in to comment.