Skip to content

Commit

Permalink
Works now without vault too
Browse files Browse the repository at this point in the history
  • Loading branch information
aleksilassila committed Oct 24, 2020
1 parent 4f3a029 commit 1889db2
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 43 deletions.
2 changes: 1 addition & 1 deletion Islands.iml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" exported="" name="spigot-1.16.2" level="project" />
<orderEntry type="library" name="Vault" level="project" />
<orderEntry type="library" name="spigot" level="project" />
<orderEntry type="library" name="WorldEdit" level="project" />
<orderEntry type="library" name="IF-0.7.2" level="project" />
<orderEntry type="library" name="Vault" level="project" />
</component>
</module>
6 changes: 3 additions & 3 deletions src/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ groupLimits: # Requires vault to work, all limits can

islandSizes: # Island sizing. You can add or remove as many sizes as you want.
BIG: 80 # NORMAL is the fallback size. At least 1 size has to be defined.
NORMAL: 64
SMALL: 32
NORMAL: 64 # For now due to bukkit api, the default sizes here can be disabled only by
SMALL: 32 # setting their size as 0.

islandCost:
islandPrices: # If vault has been enabled, you can set island creation prices here
BIG: 5000
NORMAL: 3000
SMALL: 1000
Expand Down
20 changes: 13 additions & 7 deletions src/me/aleksilassila/islands/GUIs/CreateGUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import me.aleksilassila.islands.Islands;
import me.aleksilassila.islands.utils.BiomeMaterials;
import me.aleksilassila.islands.utils.Messages;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Biome;
Expand Down Expand Up @@ -83,11 +82,13 @@ private Gui getSizeGui(Biome biome) {
Gui gui = createPaginatedGUI(2, Messages.get("gui.create.SIZE_TITLE"), availableSizePanes("island " + subcommand + " " + biome.name()));
gui.setOnTopClick(inventoryClickEvent -> inventoryClickEvent.setCancelled(true));

StaticPane balance = new StaticPane(0, 1, 1, 1);
if (plugin.econ != null) {
StaticPane balance = new StaticPane(0, 1, 1, 1);

balance.addItem(new GuiItem(createGuiItem(Material.EMERALD, Messages.get("gui.create.BALANCE"), true, Messages.get("gui.create.BALANCE_LORE", plugin.econ.getBalance(player)))), 0, 0); // FIXME test without vault
balance.addItem(new GuiItem(createGuiItem(Material.EMERALD, Messages.get("gui.create.BALANCE"), true, Messages.get("gui.create.BALANCE_LORE", plugin.econ.getBalance(player)))), 0, 0); // FIXME test without vault

gui.addPane(balance);
gui.addPane(balance);
}

return gui;
}
Expand All @@ -107,12 +108,17 @@ private List<StaticPane> availableSizePanes(String createCommand) {
int islandSize = plugin.definedIslandSizes.get(key);
if (!player.hasPermission(plugin.getCreatePermission(islandSize))) continue;

double cost = plugin.islandCosts.getOrDefault(islandSize, 0.0) + recreateCost;
double cost = 0.0;

if (plugin.econ != null) {
cost = plugin.islandPrices.getOrDefault(islandSize, 0.0) + recreateCost;

if (oldCost != null) {
cost = Math.max(cost - oldCost, 0);
if (oldCost != null) {
cost = Math.max(cost - oldCost, 0);
}
}


pane.addItem(
new GuiItem(
createGuiItem(
Expand Down
10 changes: 5 additions & 5 deletions src/me/aleksilassila/islands/Islands.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public class Islands extends JavaPlugin {
public Set<Player> playersWithNoFall = new HashSet<>();
public HashMap<String, ConfirmItem> confirmations;
public Map<String, Long> teleportCooldowns;
public Map<Integer, Double> islandCosts;
public Map<Integer, Double> islandPrices;

public Map<String, Integer> definedIslandSizes;
public Map<Integer, List<Shape>> definedIslandShapes;
Expand Down Expand Up @@ -306,12 +306,12 @@ private boolean setupEconomy() {
}

econ = rsp.getProvider();
islandCosts = new HashMap<>();
islandPrices = new HashMap<>();

for (String size : Objects.requireNonNull(getConfig().getConfigurationSection("islandSizes")).getKeys(false)) {
if (getConfig().getDouble("islandCost." + size) > 0) {
getLogger().info("Added cost: " + getConfig().getInt("islandSizes." + size) + " for " + getConfig().getDouble("islandCost." + size));
islandCosts.put(getConfig().getInt("islandSizes." + size), getConfig().getDouble("islandCost." + size));
if (getConfig().getDouble("islandPrices." + size) > 0) {
getLogger().info("Added cost: " + getConfig().getInt("islandSizes." + size) + " for " + getConfig().getDouble("islandPrices." + size));
islandPrices.put(getConfig().getInt("islandSizes." + size), getConfig().getDouble("islandPrices." + size));
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
package me.aleksilassila.islands.commands.subcommands;

import com.mojang.brigadier.Message;
import me.aleksilassila.islands.GUIs.CreateGUI;
import me.aleksilassila.islands.IslandLayout;
import me.aleksilassila.islands.Islands;
import me.aleksilassila.islands.commands.IslandManagmentCommands;
import me.aleksilassila.islands.commands.Subcommand;
import me.aleksilassila.islands.utils.Messages;
import me.aleksilassila.islands.utils.Permissions;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.block.Biome;
import org.bukkit.configuration.ConfigurationSection;
Expand Down Expand Up @@ -50,15 +48,6 @@ public void onCommand(Player player, String[] args, boolean confirmed) {
if (args.length < 1) {
new CreateGUI(plugin, player, "create").open();

// player.sendMessage(Messages.help.CREATE);
//
// for (Biome biome : availableLocations.keySet()) {
// if (availableLocations.get(biome).size() > 0) {
// player.sendMessage(ChatColor.GOLD + biome.toString() + ChatColor.GREEN + " has " + ChatColor.GOLD
// + availableLocations.get(biome).size() + ChatColor.GREEN + " island variations available.");
// }
// }

return;
}

Expand Down Expand Up @@ -89,7 +78,7 @@ public void onCommand(Player player, String[] args, boolean confirmed) {
return;
}

if (!hasFunds(player, islandSize)) {
if (plugin.econ != null && !hasFunds(player, islandSize)) {
player.sendMessage(Messages.get("error.INSUFFICIENT_FUNDS"));
return;
}
Expand All @@ -114,22 +103,22 @@ public void onCommand(Player player, String[] args, boolean confirmed) {
return;
}

pay(player, islandSize);
if (plugin.econ != null) pay(player, islandSize);
player.sendTitle(Messages.get("success.ISLAND_GEN_TITLE"), Messages.get("success.ISLAND_GEN_SUBTITLE"), 10, 20 * 7, 10);
}

private boolean hasFunds(Player player, int islandSize) {
if (plugin.econ == null) return true;

double cost = plugin.islandCosts.getOrDefault(islandSize, 0.0);
double cost = plugin.islandPrices.getOrDefault(islandSize, 0.0);

return plugin.econ.has(player, cost);
}

private void pay(Player player, int islandSize) {
if (plugin.econ == null) return;

double cost = plugin.islandCosts.getOrDefault(islandSize, 0.0);
double cost = plugin.islandPrices.getOrDefault(islandSize, 0.0);

if (cost > 0) {
plugin.econ.withdrawPlayer(player, cost);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,27 +65,31 @@ public void onCommand(Player player, String[] args, boolean confirmed) {
if (args.length < 1) {
CreateGUI gui = new CreateGUI(plugin, player, "recreate");

if (plugin.getConfig().getBoolean("economy.recreateSum")) {
double oldCost = plugin.islandCosts.getOrDefault(plugin.getIslandsConfig().getInt(islandId + ".size"), 0.0);
if (plugin.econ != null && plugin.getConfig().getBoolean("economy.recreateSum")) {
double oldCost = plugin.islandPrices.getOrDefault(plugin.getIslandsConfig().getInt(islandId + ".size"), 0.0);
gui.setOldCost(oldCost);
}

gui.open();
return;
}

double cost = plugin.islandCosts.getOrDefault(islandSize, 0.0);
cost += plugin.getConfig().getDouble("economy.recreateCost");
double cost = 0.0;

if (plugin.getConfig().getBoolean("economy.recreateSum")) {
double oldCost = plugin.islandCosts.getOrDefault(plugin.getIslandsConfig().getInt(islandId + ".size"), 0.0);
if (plugin.econ != null) {
cost = plugin.islandPrices.getOrDefault(islandSize, 0.0);
cost += plugin.getConfig().getDouble("economy.recreateCost");

cost = Math.max(cost - oldCost, 0);
}
if (plugin.getConfig().getBoolean("economy.recreateSum")) {
double oldCost = plugin.islandPrices.getOrDefault(plugin.getIslandsConfig().getInt(islandId + ".size"), 0.0);

if (!hasFunds(player, islandSize, cost)) {
player.sendMessage(Messages.get("error.INSUFFICIENT_FUNDS"));
return;
cost = Math.max(cost - oldCost, 0);
}

if (!hasFunds(player, islandSize, cost)) {
player.sendMessage(Messages.get("error.INSUFFICIENT_FUNDS"));
return;
}
}

targetBiome = utils.getTargetBiome(args[0]);
Expand Down Expand Up @@ -113,7 +117,7 @@ public void onCommand(Player player, String[] args, boolean confirmed) {
return;
}

pay(player, islandSize, cost);
if (plugin.econ != null) pay(player, islandSize, cost);

player.sendTitle(Messages.get("success.ISLAND_GEN_TITLE"), Messages.get("success.ISLAND_GEN_SUBTITLE"), 10, 20 * 7, 10);
} catch (IllegalArgumentException e) {
Expand Down

0 comments on commit 1889db2

Please sign in to comment.