Skip to content

Commit

Permalink
Added a command to toggle money
Browse files Browse the repository at this point in the history
  • Loading branch information
Lorenzo0111 committed Oct 27, 2021
1 parent e329711 commit 02d2ac3
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 12 deletions.
12 changes: 12 additions & 0 deletions src/main/java/me/lorenzo0111/debugeconomy/DebugEconomy.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
package me.lorenzo0111.debugeconomy;

import me.lorenzo0111.debugeconomy.command.DebugEconomyCommand;
import me.lorenzo0111.debugeconomy.manager.EconomyManager;
import org.bukkit.Bukkit;
import org.bukkit.plugin.ServicePriority;
import org.bukkit.plugin.java.JavaPlugin;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.UUID;

public final class DebugEconomy extends JavaPlugin {
private final List<UUID> noMoney = new ArrayList<>();

@Override
public void onEnable() {
Expand All @@ -24,10 +30,16 @@ public void onEnable() {

Bukkit.getServicesManager().register(EconomyManager.class,new EconomyManager(this), this, ServicePriority.Low);
this.getLogger().info("Hooked with Vault.");

Objects.requireNonNull(this.getCommand("debugeconomy")).setExecutor(new DebugEconomyCommand(this));
}

@Override
public void onDisable() {
// Plugin shutdown logic
}

public List<UUID> getNoMoney() {
return noMoney;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package me.lorenzo0111.debugeconomy.command;

import me.lorenzo0111.debugeconomy.DebugEconomy;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabExecutor;
import org.bukkit.entity.Player;

import java.util.Collections;
import java.util.List;

public class DebugEconomyCommand implements TabExecutor {
private final DebugEconomy plugin;

public DebugEconomyCommand(DebugEconomy plugin) {
this.plugin = plugin;
}

@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if (!(sender instanceof Player)) return true;
Player player = (Player) sender;

if (plugin.getNoMoney().contains(player.getUniqueId())) {
plugin.getNoMoney().remove(player.getUniqueId());
sender.sendMessage(ChatColor.GREEN + "Now vault will see that you have sufficient money.");
return true;
}

plugin.getNoMoney().add(player.getUniqueId());
sender.sendMessage(ChatColor.RED + "Now vault will see that you don't have sufficient money.");
return true;
}

@Override
public List<String> onTabComplete(CommandSender sender, Command command, String alias, String[] args) {
return Collections.singletonList("toggle");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import me.lorenzo0111.debugeconomy.DebugEconomy;
import net.milkbowl.vault.economy.Economy;
import net.milkbowl.vault.economy.EconomyResponse;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;

import java.util.ArrayList;
Expand Down Expand Up @@ -72,63 +73,71 @@ public boolean hasAccount(OfflinePlayer player, String worldName) {

@Override
public double getBalance(String playerName) {
return Integer.MAX_VALUE;
return getBalance(Bukkit.getOfflinePlayer(playerName));
}

@Override
public double getBalance(OfflinePlayer player) {
return Integer.MAX_VALUE;
return plugin.getNoMoney().contains(player.getUniqueId()) ? 0.0 : Integer.MAX_VALUE;
}

@Override
public double getBalance(String playerName, String world) {
return Integer.MAX_VALUE;
return getBalance(Bukkit.getOfflinePlayer(playerName));
}

@Override
public double getBalance(OfflinePlayer player, String world) {
return Integer.MAX_VALUE;
return getBalance(player);
}

@Override
public boolean has(String playerName, double amount) {
return true;
return getBalance(playerName) > 1;
}

@Override
public boolean has(OfflinePlayer player, double amount) {
return true;
return getBalance(player) > 1;
}

@Override
public boolean has(String playerName, String worldName, double amount) {
return true;
return getBalance(playerName) > 1;
}

@Override
public boolean has(OfflinePlayer player, String worldName, double amount) {
return true;
return getBalance(player) > 1;
}

@Override
public EconomyResponse withdrawPlayer(String playerName, double amount) {
return new EconomyResponse(amount, getBalance(playerName), EconomyResponse.ResponseType.SUCCESS, null);
return has(playerName,amount) ?
new EconomyResponse(amount, getBalance(playerName), EconomyResponse.ResponseType.SUCCESS, null)
: new EconomyResponse(amount, getBalance(playerName), EconomyResponse.ResponseType.FAILURE, null);
}

@Override
public EconomyResponse withdrawPlayer(OfflinePlayer player, double amount) {
return new EconomyResponse(amount, getBalance(player), EconomyResponse.ResponseType.SUCCESS, null);
return has(player,amount) ?
new EconomyResponse(amount, getBalance(player), EconomyResponse.ResponseType.SUCCESS, null)
: new EconomyResponse(amount, getBalance(player), EconomyResponse.ResponseType.FAILURE, null);

}

@Override
public EconomyResponse withdrawPlayer(String playerName, String worldName, double amount) {
return new EconomyResponse(amount, getBalance(playerName), EconomyResponse.ResponseType.SUCCESS, null);
return has(playerName,amount) ?
new EconomyResponse(amount, getBalance(playerName), EconomyResponse.ResponseType.SUCCESS, null)
: new EconomyResponse(amount, getBalance(playerName), EconomyResponse.ResponseType.FAILURE, null);
}

@Override
public EconomyResponse withdrawPlayer(OfflinePlayer player, String worldName, double amount) {
return new EconomyResponse(amount, getBalance(player), EconomyResponse.ResponseType.SUCCESS, null);
return has(player,amount) ?
new EconomyResponse(amount, getBalance(player), EconomyResponse.ResponseType.SUCCESS, null)
: new EconomyResponse(amount, getBalance(player), EconomyResponse.ResponseType.FAILURE, null);
}

@Override
Expand Down
5 changes: 5 additions & 0 deletions src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,8 @@ main: me.lorenzo0111.debugeconomy.DebugEconomy
api-version: 1.13
depend: [Vault]
authors: [Lorenzo0111]
commands:
debugeconomy:
aliases: [de,eco]
permission: economy.debug
permission-message: You need the economy.debug permission to use this command.

0 comments on commit 02d2ac3

Please sign in to comment.