mirror of
https://github.com/trainerlord/WorldSystem.git
synced 2024-12-03 13:33:22 +01:00
Started implementation for #15
This commit is contained in:
parent
1dcc6f4108
commit
ea9c7c5b5e
17
pom.xml
17
pom.xml
@ -80,6 +80,12 @@
|
|||||||
<url>http://nexus.myplayplanet.net/repository/public/</url>
|
<url>http://nexus.myplayplanet.net/repository/public/</url>
|
||||||
</repository>
|
</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 -->
|
<!-- Mojang repo for GameProfileBuilder -->
|
||||||
<repository>
|
<repository>
|
||||||
<id>mojang</id>
|
<id>mojang</id>
|
||||||
@ -115,9 +121,7 @@
|
|||||||
</dependency>
|
</dependency>
|
||||||
-->
|
-->
|
||||||
|
|
||||||
|
<dependency>
|
||||||
<!-- Download FAWE and change to path to your path if you want to use it -->
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.sk98q.worldedit</groupId>
|
<groupId>com.sk98q.worldedit</groupId>
|
||||||
<artifactId>FastAsnycWorldEdit</artifactId>
|
<artifactId>FastAsnycWorldEdit</artifactId>
|
||||||
<scope>system</scope>
|
<scope>system</scope>
|
||||||
@ -138,5 +142,12 @@
|
|||||||
<version>2.0.0-SNAPSHOT</version>
|
<version>2.0.0-SNAPSHOT</version>
|
||||||
<scope>compile</scope>
|
<scope>compile</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>net.milkbowl.vault</groupId>
|
||||||
|
<artifactId>VaultAPI</artifactId>
|
||||||
|
<version>1.6</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</project>
|
</project>
|
@ -8,6 +8,7 @@ import de.butzlabben.world.config.PluginConfig;
|
|||||||
import de.butzlabben.world.config.WorldConfig;
|
import de.butzlabben.world.config.WorldConfig;
|
||||||
import de.butzlabben.world.gui.WorldChooseGUI;
|
import de.butzlabben.world.gui.WorldChooseGUI;
|
||||||
import de.butzlabben.world.gui.WorldSystemGUI;
|
import de.butzlabben.world.gui.WorldSystemGUI;
|
||||||
|
import de.butzlabben.world.util.MoneyUtil;
|
||||||
import de.butzlabben.world.wrapper.SystemWorld;
|
import de.butzlabben.world.wrapper.SystemWorld;
|
||||||
import de.butzlabben.world.wrapper.WorldPlayer;
|
import de.butzlabben.world.wrapper.WorldPlayer;
|
||||||
import de.butzlabben.world.wrapper.WorldTemplate;
|
import de.butzlabben.world.wrapper.WorldTemplate;
|
||||||
@ -94,6 +95,15 @@ public class WSCommand {
|
|||||||
p.sendMessage(MessageConfig.getNoPermission());
|
p.sendMessage(MessageConfig.getNoPermission());
|
||||||
return;
|
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);
|
create(p, template);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -181,6 +181,7 @@ public class SettingsConfig {
|
|||||||
borderSizes.put(s, cfg.getLong("worldborder.ranks." + s));
|
borderSizes.put(s, cfg.getLong("worldborder.ranks." + s));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return the commands specified in settings.yml on /ws get
|
* @return the commands specified in settings.yml on /ws get
|
||||||
*/
|
*/
|
||||||
|
59
src/main/java/de/butzlabben/world/util/MoneyUtil.java
Normal file
59
src/main/java/de/butzlabben/world/util/MoneyUtil.java
Normal 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() {
|
||||||
|
}
|
||||||
|
}
|
@ -13,10 +13,12 @@ public class WorldTemplate {
|
|||||||
private final String permission;
|
private final String permission;
|
||||||
private final OrcItem icon;
|
private final OrcItem icon;
|
||||||
private final int slot;
|
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.name = name;
|
||||||
this.permission = permission;
|
this.permission = permission;
|
||||||
|
this.cost = cost;
|
||||||
|
|
||||||
this.icon = GuiConfig.getItem("worldchoose." + name);
|
this.icon = GuiConfig.getItem("worldchoose." + name);
|
||||||
this.slot = GuiConfig.getSlot("worldchoose." + name);
|
this.slot = GuiConfig.getSlot("worldchoose." + name);
|
||||||
@ -31,6 +33,10 @@ public class WorldTemplate {
|
|||||||
return slot;
|
return slot;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getCost() {
|
||||||
|
return cost;
|
||||||
|
}
|
||||||
|
|
||||||
public OrcItem getIcon() {
|
public OrcItem getIcon() {
|
||||||
return icon;
|
return icon;
|
||||||
}
|
}
|
||||||
|
@ -27,7 +27,13 @@ public class WorldTemplateProvider {
|
|||||||
String permission = null;
|
String permission = null;
|
||||||
if (section.isString(key + ".permission"))
|
if (section.isString(key + ".permission"))
|
||||||
permission = section.getString(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));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -29,6 +29,9 @@ worldtemplates:
|
|||||||
# Only players with this exact permission can use and see this template
|
# Only players with this exact permission can use and see this template
|
||||||
# ws.* will not work with this
|
# ws.* will not work with this
|
||||||
permission: ws.template.another_template
|
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
|
# If a confirm is needed before auto-update
|
||||||
need_confirm: true
|
need_confirm: true
|
||||||
|
Loading…
Reference in New Issue
Block a user