mirror of
https://github.com/AppleDash/SaneEconomy.git
synced 2024-06-28 23:44:51 +02:00
Add in-game command to reload the database and fix /ecoadmin permission.
This commit is contained in:
parent
1f980b9fc8
commit
841d6e937d
|
@ -1,5 +1,5 @@
|
||||||
group 'org.appledash'
|
group 'org.appledash'
|
||||||
version '0.3.0-SNAPSHOT'
|
version '0.3.1-SNAPSHOT'
|
||||||
|
|
||||||
apply plugin: 'java'
|
apply plugin: 'java'
|
||||||
|
|
||||||
|
|
|
@ -4,6 +4,7 @@ import org.appledash.saneeconomy.command.SaneEconomyCommand;
|
||||||
import org.appledash.saneeconomy.command.type.BalanceCommand;
|
import org.appledash.saneeconomy.command.type.BalanceCommand;
|
||||||
import org.appledash.saneeconomy.command.type.EconomyAdminCommand;
|
import org.appledash.saneeconomy.command.type.EconomyAdminCommand;
|
||||||
import org.appledash.saneeconomy.command.type.PayCommand;
|
import org.appledash.saneeconomy.command.type.PayCommand;
|
||||||
|
import org.appledash.saneeconomy.command.type.SaneEcoCommand;
|
||||||
import org.appledash.saneeconomy.economy.Currency;
|
import org.appledash.saneeconomy.economy.Currency;
|
||||||
import org.appledash.saneeconomy.economy.EconomyManager;
|
import org.appledash.saneeconomy.economy.EconomyManager;
|
||||||
import org.appledash.saneeconomy.economy.backend.EconomyStorageBackend;
|
import org.appledash.saneeconomy.economy.backend.EconomyStorageBackend;
|
||||||
|
@ -29,6 +30,7 @@ public class SaneEconomy extends JavaPlugin {
|
||||||
put("balance", new BalanceCommand());
|
put("balance", new BalanceCommand());
|
||||||
put("ecoadmin", new EconomyAdminCommand());
|
put("ecoadmin", new EconomyAdminCommand());
|
||||||
put("pay", new PayCommand());
|
put("pay", new PayCommand());
|
||||||
|
put("saneeconomy", new SaneEcoCommand());
|
||||||
}};
|
}};
|
||||||
|
|
||||||
public SaneEconomy() {
|
public SaneEconomy() {
|
||||||
|
@ -99,14 +101,15 @@ public class SaneEconomy extends JavaPlugin {
|
||||||
}
|
}
|
||||||
|
|
||||||
getLogger().info("Connection successful!");
|
getLogger().info("Connection successful!");
|
||||||
getLogger().info("Performing initial data load...");
|
|
||||||
mySQLBackend.reloadData();
|
|
||||||
getLogger().info("Data loaded!");
|
|
||||||
} else {
|
} else {
|
||||||
getLogger().severe("Unknown storage backend " + backendType + "!");
|
getLogger().severe("Unknown storage backend " + backendType + "!");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getLogger().info("Performing initial data load...");
|
||||||
|
backend.reloadDatabase();
|
||||||
|
getLogger().info("Data loaded!");
|
||||||
|
|
||||||
economyManager = new EconomyManager(currency, backend);
|
economyManager = new EconomyManager(currency, backend);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -20,7 +20,7 @@ import org.bukkit.entity.Player;
|
||||||
public class EconomyAdminCommand extends SaneEconomyCommand {
|
public class EconomyAdminCommand extends SaneEconomyCommand {
|
||||||
@Override
|
@Override
|
||||||
public String getPermission() {
|
public String getPermission() {
|
||||||
return "saneeconomy.admin";
|
return "saneeconomy.ecoadmin";
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -0,0 +1,41 @@
|
||||||
|
package org.appledash.saneeconomy.command.type;
|
||||||
|
|
||||||
|
import org.appledash.saneeconomy.SaneEconomy;
|
||||||
|
import org.appledash.saneeconomy.command.SaneEconomyCommand;
|
||||||
|
import org.appledash.saneeconomy.command.exception.CommandException;
|
||||||
|
import org.appledash.saneeconomy.command.exception.type.usage.InvalidUsageException;
|
||||||
|
import org.appledash.saneeconomy.utils.MessageUtils;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by AppleDash on 6/14/2016.
|
||||||
|
* Blackjack is still best pony.
|
||||||
|
*/
|
||||||
|
public class SaneEcoCommand extends SaneEconomyCommand {
|
||||||
|
@Override
|
||||||
|
public String getPermission() {
|
||||||
|
return "saneeconomy.admin";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String[] getUsage() {
|
||||||
|
return new String[] {
|
||||||
|
"/<command> reload-database"
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onCommand(CommandSender sender, String[] args) throws CommandException {
|
||||||
|
if (args.length != 1) {
|
||||||
|
throw new InvalidUsageException();
|
||||||
|
}
|
||||||
|
|
||||||
|
String subCommand = args[0];
|
||||||
|
|
||||||
|
if (subCommand.equalsIgnoreCase("reload-database")) {
|
||||||
|
MessageUtils.sendMessage(sender, "Reloading database...");
|
||||||
|
SaneEconomy.getInstance().getEconomyManager().getBackend().reloadDatabase();
|
||||||
|
MessageUtils.sendMessage(sender, "Database reloaded.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -137,4 +137,8 @@ public class EconomyManager {
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public EconomyStorageBackend getBackend() {
|
||||||
|
return backend;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,4 +45,9 @@ public interface EconomyStorageBackend {
|
||||||
* @return Player's new balance
|
* @return Player's new balance
|
||||||
*/
|
*/
|
||||||
double subtractBalance(Player player, double amount);
|
double subtractBalance(Player player, double amount);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reload this backend's database from disk.
|
||||||
|
*/
|
||||||
|
void reloadDatabase();
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,10 +21,10 @@ public class EconomyStorageBackendFlatfile implements EconomyStorageBackend {
|
||||||
|
|
||||||
public EconomyStorageBackendFlatfile(File file) {
|
public EconomyStorageBackendFlatfile(File file) {
|
||||||
this.file = file;
|
this.file = file;
|
||||||
loadDatabase();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void loadDatabase() {
|
@Override
|
||||||
|
public void reloadDatabase() {
|
||||||
if (!file.exists()) {
|
if (!file.exists()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -61,7 +61,8 @@ public class EconomyStorageBackendMySQL implements EconomyStorageBackend {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void reloadData() {
|
@Override
|
||||||
|
public void reloadDatabase() {
|
||||||
Connection conn = openConnection();
|
Connection conn = openConnection();
|
||||||
try {
|
try {
|
||||||
PreparedStatement ps = conn.prepareStatement("SELECT * FROM `player_balances`");
|
PreparedStatement ps = conn.prepareStatement("SELECT * FROM `player_balances`");
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
name: SaneEconomy
|
name: SaneEconomy
|
||||||
main: org.appledash.saneeconomy.SaneEconomy
|
main: org.appledash.saneeconomy.SaneEconomy
|
||||||
version: 0.3.0
|
version: 0.3.1
|
||||||
commands:
|
commands:
|
||||||
balance:
|
balance:
|
||||||
aliases: [bal]
|
aliases: [bal]
|
||||||
|
@ -17,3 +17,8 @@ commands:
|
||||||
description: Give some of your money to another player.
|
description: Give some of your money to another player.
|
||||||
usage: /<command> <player> <amount>
|
usage: /<command> <player> <amount>
|
||||||
permission: saneeconomy.pay
|
permission: saneeconomy.pay
|
||||||
|
saneeconomy:
|
||||||
|
aliases: [saneeco]
|
||||||
|
description: Various admin commands for SaneEconomy.
|
||||||
|
usage: /command reload-database
|
||||||
|
pernission: saneeconomy.admin
|
||||||
|
|
Loading…
Reference in New Issue
Block a user