Started implementation for #15

This commit is contained in:
Butzlabben 2019-02-26 23:17:32 +01:00
parent 1dcc6f4108
commit ea9c7c5b5e
7 changed files with 101 additions and 5 deletions

17
pom.xml
View File

@ -79,6 +79,12 @@
<id>pp-public</id>
<url>http://nexus.myplayplanet.net/repository/public/</url>
</repository>
<!-- Repo for Vault support-->
<repository>
<id>vault-repo</id>
<url>http://nexus.hc.to/content/repositories/pub_releases</url>
</repository>
<!-- Mojang repo for GameProfileBuilder -->
<repository>
@ -115,9 +121,7 @@
</dependency>
-->
<!-- Download FAWE and change to path to your path if you want to use it -->
<dependency>
<dependency>
<groupId>com.sk98q.worldedit</groupId>
<artifactId>FastAsnycWorldEdit</artifactId>
<scope>system</scope>
@ -138,5 +142,12 @@
<version>2.0.0-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>net.milkbowl.vault</groupId>
<artifactId>VaultAPI</artifactId>
<version>1.6</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>

View File

@ -8,6 +8,7 @@ import de.butzlabben.world.config.PluginConfig;
import de.butzlabben.world.config.WorldConfig;
import de.butzlabben.world.gui.WorldChooseGUI;
import de.butzlabben.world.gui.WorldSystemGUI;
import de.butzlabben.world.util.MoneyUtil;
import de.butzlabben.world.wrapper.SystemWorld;
import de.butzlabben.world.wrapper.WorldPlayer;
import de.butzlabben.world.wrapper.WorldTemplate;
@ -94,6 +95,15 @@ public class WSCommand {
p.sendMessage(MessageConfig.getNoPermission());
return;
}
// Implementation check for #15
if (template.getCost() > 0) {
if (!MoneyUtil.hasMoney(p.getUniqueId(), template.getCost())) {
// TODO send not enough money message
return;
}
MoneyUtil.removeMoney(p.getUniqueId(), template.getCost());
}
create(p, template);
return;
}

View File

@ -181,6 +181,7 @@ public class SettingsConfig {
borderSizes.put(s, cfg.getLong("worldborder.ranks." + s));
}
}
/**
* @return the commands specified in settings.yml on /ws get
*/

View File

@ -0,0 +1,59 @@
package de.butzlabben.world.util;
import com.google.common.base.Preconditions;
import de.butzlabben.world.config.PluginConfig;
import net.milkbowl.vault.economy.Economy;
import net.milkbowl.vault.economy.EconomyResponse;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.plugin.RegisteredServiceProvider;
import java.util.UUID;
/**
* Little util class for dealing with money with vault
* Used for #15
*/
public class MoneyUtil {
private static Object economy = null;
static {
if (Bukkit.getPluginManager().getPlugin("Vault") != null) {
try {
RegisteredServiceProvider<Economy> service = Bukkit.getServicesManager().getRegistration(Economy.class);
if (service != null)
economy = service.getProvider();
} catch (Exception e) {
}
}
if (economy == null)
Bukkit.getConsoleSender().sendMessage(PluginConfig.getPrefix() + "Couldn't find a Vault Economy extension");
}
public static void removeMoney(UUID uuid, int money) {
Preconditions.checkNotNull(uuid);
Preconditions.checkNotNull(economy);
Preconditions.checkArgument(money > 0, "Money must not be negative");
OfflinePlayer op = Bukkit.getOfflinePlayer(uuid);
Economy economy = (Economy) MoneyUtil.economy;
EconomyResponse response = economy.withdrawPlayer(op, money);
if (!response.transactionSuccess()) {
Bukkit.getConsoleSender().sendMessage(PluginConfig.getPrefix() + "§cTransaction failure for removing " + money + " from " + op.getName());
Bukkit.getConsoleSender().sendMessage(PluginConfig.getPrefix() + "§cError message: " + response.errorMessage);
}
}
public static boolean hasMoney(UUID uuid, int money) {
Preconditions.checkNotNull(uuid);
Preconditions.checkNotNull(economy);
Preconditions.checkArgument(money > 0, "Money must not be negative");
OfflinePlayer op = Bukkit.getOfflinePlayer(uuid);
Economy economy = (Economy) MoneyUtil.economy;
return economy.getBalance(op) >= money;
}
private MoneyUtil() {
}
}

View File

@ -13,10 +13,12 @@ public class WorldTemplate {
private final String permission;
private final OrcItem icon;
private final int slot;
private final int cost;
public WorldTemplate(String name, String permission) {
public WorldTemplate(String name, String permission, int cost) {
this.name = name;
this.permission = permission;
this.cost = cost;
this.icon = GuiConfig.getItem("worldchoose." + name);
this.slot = GuiConfig.getSlot("worldchoose." + name);
@ -31,6 +33,10 @@ public class WorldTemplate {
return slot;
}
public int getCost() {
return cost;
}
public OrcItem getIcon() {
return icon;
}

View File

@ -27,7 +27,13 @@ public class WorldTemplateProvider {
String permission = null;
if (section.isString(key + ".permission"))
permission = section.getString(key + ".permission");
templates.put(name, new WorldTemplate(name, permission));
int cost = -1;
// Get money for #15 if needed
if (section.isInt(key + ".cost"))
cost = section.getInt(key + ".cost");
templates.put(name, new WorldTemplate(name, permission, cost));
}
}

View File

@ -29,6 +29,9 @@ worldtemplates:
# Only players with this exact permission can use and see this template
# ws.* will not work with this
permission: ws.template.another_template
# If this config option is given, 100 is needed to create a world
# This amount will then with withdrawn from the player
cost: 100
# If a confirm is needed before auto-update
need_confirm: true