Added island banks.

This commit is contained in:
Brianna O'Keefe 2019-02-07 17:02:39 -05:00
parent d7efe4bdda
commit 6381e7b138
13 changed files with 246 additions and 51 deletions

View File

@ -20,7 +20,7 @@
<repositories> <repositories>
<repository> <repository>
<id>private</id> <id>private</id>
<url>http://repo.songoda.com/repository/private</url> <url>http://repo.songoda.com/artifactory/private/</url>
</repository> </repository>
</repositories> </repositories>
<dependencies> <dependencies>
@ -41,7 +41,7 @@
</dependency> </dependency>
<dependency> <dependency>
<groupId>net.nifheim.beelzebu</groupId> <groupId>net.nifheim.beelzebu</groupId>
<artifactId>coins</artifactId> <artifactId>Coins</artifactId>
<version>2.3.2</version> <version>2.3.2</version>
</dependency> </dependency>
<dependency> <dependency>

View File

@ -253,6 +253,7 @@ public class SkyBlock extends JavaPlugin {
FileConfiguration configLoad = config.getFileConfiguration(); FileConfiguration configLoad = config.getFileConfiguration();
configLoad.set("Stackables", null); configLoad.set("Stackables", null);
if (stackableManager.getStacks() == null) return;
for (Stackable stackable : stackableManager.getStacks().values()) { for (Stackable stackable : stackableManager.getStacks().values()) {
if (island != stackable.getIsland()) continue; if (island != stackable.getIsland()) continue;
ConfigurationSection section = configLoad.createSection("Stackables." + stackable.getUuid().toString()); ConfigurationSection section = configLoad.createSection("Stackables." + stackable.getUuid().toString());

View File

@ -108,6 +108,8 @@ public class CommandManager implements CommandExecutor, TabCompleter {
configLoad.getString("Command.Island.Weather.Info.Message")))); configLoad.getString("Command.Island.Weather.Info.Message"))));
subCommands.add(new UnlockCommand(skyblock).setInfo(ChatColor.translateAlternateColorCodes('&', subCommands.add(new UnlockCommand(skyblock).setInfo(ChatColor.translateAlternateColorCodes('&',
configLoad.getString("Command.Island.Unlock.Info.Message")))); configLoad.getString("Command.Island.Unlock.Info.Message"))));
subCommands.add(new BankCommand(skyblock).setInfo(ChatColor.translateAlternateColorCodes('&',
configLoad.getString("Command.Island.Bank.Info.Message"))));
// subCommands.add(new // subCommands.add(new
// RollbackCommand(skyblock).setInfo(ChatColor.translateAlternateColorCodes('&', // RollbackCommand(skyblock).setInfo(ChatColor.translateAlternateColorCodes('&',
// configLoad.getString("Command.Island.Rollback.Info.Message")))); // configLoad.getString("Command.Island.Rollback.Info.Message"))));

View File

@ -0,0 +1,143 @@
package me.goodandevil.skyblock.command.commands;
import me.goodandevil.skyblock.SkyBlock;
import me.goodandevil.skyblock.command.CommandManager.Type;
import me.goodandevil.skyblock.command.SubCommand;
import me.goodandevil.skyblock.config.FileManager;
import me.goodandevil.skyblock.config.FileManager.Config;
import me.goodandevil.skyblock.economy.EconomyManager;
import me.goodandevil.skyblock.island.Island;
import me.goodandevil.skyblock.island.IslandManager;
import me.goodandevil.skyblock.island.IslandRole;
import me.goodandevil.skyblock.message.MessageManager;
import me.goodandevil.skyblock.sound.SoundManager;
import me.goodandevil.skyblock.utils.version.Sounds;
import org.apache.commons.lang.WordUtils;
import org.bukkit.command.ConsoleCommandSender;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.entity.Player;
import java.io.File;
public class BankCommand extends SubCommand {
private final SkyBlock skyblock;
private String info;
public BankCommand(SkyBlock skyblock) {
this.skyblock = skyblock;
}
@Override
public void onCommandByPlayer(Player player, String[] args) {
MessageManager messageManager = skyblock.getMessageManager();
EconomyManager economyManager = skyblock.getEconomyManager();
IslandManager islandManager = skyblock.getIslandManager();
SoundManager soundManager = skyblock.getSoundManager();
FileManager fileManager = skyblock.getFileManager();
Config config = fileManager.getConfig(new File(skyblock.getDataFolder(), "language.yml"));
FileConfiguration configLoad = config.getFileConfiguration();
if (args.length == 0) {
messageManager.sendMessage(player, configLoad.getString("Command.Island.Bank.Invalid.Message"));
soundManager.playSound(player, Sounds.ANVIL_LAND.bukkitSound(), 1.0F, 1.0F);
return;
}
String action = WordUtils.capitalize(args[0].toLowerCase());
Island island = islandManager.getIslandAtLocation(player.getLocation());
if (island == null) {
messageManager.sendMessage(player, configLoad.getString("Command.Island.Bank.Unknown.Message"));
soundManager.playSound(player, Sounds.ANVIL_LAND.bukkitSound(), 1.0F, 1.0F);
return;
}
if (!island.hasRole(IslandRole.Operator, player.getUniqueId())
&& !island.hasRole(IslandRole.Owner, player.getUniqueId())
&& !island.hasRole(IslandRole.Member, player.getUniqueId())) {
messageManager.sendMessage(player, configLoad.getString("Command.Island.Bank.Perm.Message"));
soundManager.playSound(player, Sounds.ANVIL_LAND.bukkitSound(), 1.0F, 1.0F);
return;
}
double balance = island.getBankBalance();
switch (action) {
case "Balance":
case "Bal":
messageManager.sendMessage(player, configLoad.getString("Command.Island.Bank.Balance.Message").replace(
"%balance%", String.valueOf(balance)));
return;
case "Deposit": {
double amt = Long.parseLong(args[1]);
if (!economyManager.hasBalance(player, amt)) {
messageManager.sendMessage(player, configLoad.getString("Command.Island.Bank.Short.Message"));
soundManager.playSound(player, Sounds.ANVIL_LAND.bukkitSound(), 1.0F, 1.0F);
return;
}
economyManager.withdraw(player, amt);
island.addToBank(amt);
messageManager.sendMessage(player, configLoad.getString("Command.Island.Bank.Deposit.Message").replace(
"%amount%", String.valueOf(amt)));
return;
}
case "Withdraw": {
double amt = Long.parseLong(args[1]);
if (amt > balance) {
messageManager.sendMessage(player, configLoad.getString("Command.Island.Bank.Short2.Message"));
return;
}
economyManager.deposit(player, amt);
island.removeFromBank(amt);
messageManager.sendMessage(player, configLoad.getString("Command.Island.Bank.Withdraw.Message").replace(
"%amount%", String.valueOf(amt)));
return;
}
}
messageManager.sendMessage(player, configLoad.getString("Command.Island.Bank.Invalid.Message"));
soundManager.playSound(player, Sounds.ANVIL_LAND.bukkitSound(), 1.0F, 1.0F);
}
@Override
public void onCommandByConsole(ConsoleCommandSender sender, String[] args) {
sender.sendMessage("SkyBlock | Error: You must be a player to perform that command.");
}
@Override
public String getName() {
return "bank";
}
@Override
public String getInfo() {
return info;
}
@Override
public SubCommand setInfo(String info) {
this.info = info;
return this;
}
@Override
public String[] getAliases() {
return new String[0];
}
@Override
public String[] getArguments() {
return new String[0];
}
@Override
public Type getType() {
return Type.Default;
}
}

View File

@ -58,6 +58,7 @@ public class UnlockCommand extends SubCommand {
if (island == null) { if (island == null) {
messageManager.sendMessage(player, configLoad.getString("Command.Island.Unlock.Owner.Message")); messageManager.sendMessage(player, configLoad.getString("Command.Island.Unlock.Owner.Message"));
soundManager.playSound(player, Sounds.ANVIL_LAND.bukkitSound(), 1.0F, 1.0F); soundManager.playSound(player, Sounds.ANVIL_LAND.bukkitSound(), 1.0F, 1.0F);
return;
} }
Config islandData = fileManager Config islandData = fileManager

View File

@ -60,6 +60,16 @@ public class EconomyManager {
Bukkit.getServer().getPluginManager().callEvent(new PlayerWithdrawMoneyEvent(player, money)); Bukkit.getServer().getPluginManager().callEvent(new PlayerWithdrawMoneyEvent(player, money));
} }
public void deposit(Player player, double money) {
if (economy != null) {
economy.depositPlayer(player, money);
} else if (economyPlugin == EconomyPlugin.Coins) {
CoinsAPI.addCoins(player.getUniqueId(), money);
}
Bukkit.getServer().getPluginManager().callEvent(new PlayerWithdrawMoneyEvent(player, money));
}
public boolean isEconomy() { public boolean isEconomy() {
if (Bukkit.getServer().getPluginManager().getPlugin("Vault") == null if (Bukkit.getServer().getPluginManager().getPlugin("Vault") == null
&& Bukkit.getServer().getPluginManager().getPlugin("Coins") == null) { && Bukkit.getServer().getPluginManager().getPlugin("Coins") == null) {

View File

@ -5,7 +5,6 @@ import me.goodandevil.skyblock.config.FileManager.Config;
import me.goodandevil.skyblock.utils.version.Materials; import me.goodandevil.skyblock.utils.version.Materials;
import me.goodandevil.skyblock.utils.version.NMSUtil; import me.goodandevil.skyblock.utils.version.NMSUtil;
import me.goodandevil.skyblock.utils.version.Sounds; import me.goodandevil.skyblock.utils.version.Sounds;
import org.bukkit.Bukkit;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.block.BlockFace; import org.bukkit.block.BlockFace;
@ -233,31 +232,27 @@ public class GeneratorManager {
public void generateBlock(Generator generator, Block block) { public void generateBlock(Generator generator, Block block) {
block.setType(Material.AIR); block.setType(Material.AIR);
Bukkit.getServer().getScheduler().runTaskAsynchronously(skyblock, () -> {
Materials materials = getRandomMaterials(generator); Materials materials = getRandomMaterials(generator);
if (materials == null) return; if (materials == null) return;
Bukkit.getScheduler().runTask(skyblock, () -> { skyblock.getSoundManager().playSound(block.getLocation(), Sounds.FIZZ.bukkitSound(),
skyblock.getSoundManager().playSound(block.getLocation(), Sounds.FIZZ.bukkitSound(), 1.0F, 10.0F);
1.0F, 10.0F);
if (NMSUtil.getVersionNumber() > 12) { if (NMSUtil.getVersionNumber() > 12) {
block.setType(materials.parseMaterial()); block.setType(materials.parseMaterial());
} else { } else {
ItemStack is = materials.parseItem(); ItemStack is = materials.parseItem();
block.setType(is.getType()); block.setType(is.getType());
try { try {
block.getClass().getMethod("setData", byte.class).invoke(block, block.getClass().getMethod("setData", byte.class).invoke(block,
(byte) is.getDurability()); (byte) is.getDurability());
} catch (IllegalAccessException | IllegalArgumentException } catch (IllegalAccessException | IllegalArgumentException
| InvocationTargetException | NoSuchMethodException | SecurityException e) { | InvocationTargetException | NoSuchMethodException | SecurityException e) {
e.printStackTrace(); e.printStackTrace();
} }
} }
});
});
} }
public Materials getRandomMaterials(Generator generator) { public Materials getRandomMaterials(Generator generator) {

View File

@ -3,6 +3,7 @@ package me.goodandevil.skyblock.hologram;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import me.goodandevil.skyblock.utils.version.NMSUtil;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.entity.ArmorStand; import org.bukkit.entity.ArmorStand;
@ -27,7 +28,10 @@ public class Hologram {
public void addLine(String text) { public void addLine(String text) {
ArmorStand as = (ArmorStand) location.getWorld().spawnEntity( ArmorStand as = (ArmorStand) location.getWorld().spawnEntity(
location.clone().add(0.0D, getHeight() + getHeightIncrement(), 0.0D), EntityType.ARMOR_STAND); location.clone().add(0.0D, getHeight() + getHeightIncrement(), 0.0D), EntityType.ARMOR_STAND);
int NMSVersion = NMSUtil.getVersionNumber();
as.setVisible(false); as.setVisible(false);
if (NMSVersion > 8)
as.setMarker(false);
as.setGravity(false); as.setGravity(false);
as.setCustomName(ChatColor.translateAlternateColorCodes('&', text)); as.setCustomName(ChatColor.translateAlternateColorCodes('&', text));
as.setCustomNameVisible(true); as.setCustomNameVisible(true);

View File

@ -609,6 +609,32 @@ public class Island {
return null; return null;
} }
public double getBankBalance() {
return skyblock.getFileManager().getConfig(
new File(new File(skyblock.getDataFolder().toString() + "/island-data"), uuid.toString() + ".yml"))
.getFileConfiguration().getDouble("Bank.Balance");
}
public void addToBank(double value) {
value = value + getBankBalance();
skyblock.getFileManager().getConfig(
new File(new File(skyblock.getDataFolder().toString() + "/island-data"), uuid.toString() + ".yml"))
.getFileConfiguration().set("Bank.Balance", value);
}
public void removeFromBank(double value) {
value = getBankBalance() - value;
skyblock.getFileManager().getConfig(
new File(new File(skyblock.getDataFolder().toString() + "/island-data"), uuid.toString() + ".yml"))
.getFileConfiguration().set("Bank.Balance", value);
}
public boolean isOpen() {
return skyblock.getFileManager().getConfig(
new File(new File(skyblock.getDataFolder().toString() + "/island-data"), uuid.toString() + ".yml"))
.getFileConfiguration().getBoolean("Visitor.Open");
}
public void setOpen(boolean open) { public void setOpen(boolean open) {
IslandOpenEvent islandOpenEvent = new IslandOpenEvent(getAPIWrapper(), open); IslandOpenEvent islandOpenEvent = new IslandOpenEvent(getAPIWrapper(), open);
Bukkit.getServer().getPluginManager().callEvent(islandOpenEvent); Bukkit.getServer().getPluginManager().callEvent(islandOpenEvent);
@ -621,12 +647,6 @@ public class Island {
} }
} }
public boolean isOpen() {
return skyblock.getFileManager().getConfig(
new File(new File(skyblock.getDataFolder().toString() + "/island-data"), uuid.toString() + ".yml"))
.getFileConfiguration().getBoolean("Visitor.Open");
}
public List<String> getMessage(IslandMessage message) { public List<String> getMessage(IslandMessage message) {
List<String> islandMessage = new ArrayList<>(); List<String> islandMessage = new ArrayList<>();

View File

@ -1148,27 +1148,19 @@ public class IslandManager {
|| island.hasRole(IslandRole.Operator, player.getUniqueId())) { || island.hasRole(IslandRole.Operator, player.getUniqueId())) {
if (player.hasPermission("fabledskyblock.fly") || player.hasPermission("fabledskyblock.fly") if (player.hasPermission("fabledskyblock.fly") || player.hasPermission("fabledskyblock.fly")
|| player.hasPermission("fabledskyblock.*")) { || player.hasPermission("fabledskyblock.*")) {
Bukkit.getServer().getScheduler().runTask(skyblock, new Runnable() { Bukkit.getServer().getScheduler().runTask(skyblock, () -> {
@Override player.setAllowFlight(true);
public void run() { player.setFlying(true);
player.setAllowFlight(true);
player.setFlying(true);
}
});
}
} else {
if (player.hasPermission("fabledskyblock.fly") || player.hasPermission("fabledskyblock.*")) {
Bukkit.getServer().getScheduler().runTask(skyblock, new Runnable() {
@Override
public void run() {
player.setAllowFlight(true);
player.setFlying(true);
}
}); });
} }
return;
} }
if (player.hasPermission("fabledskyblock.fly") || player.hasPermission("fabledskyblock.*")) {
Bukkit.getServer().getScheduler().runTask(skyblock, () -> {
player.setAllowFlight(true);
player.setFlying(true);
});
}
} }
public void removeUpgrades(Player player, boolean bypassIsland) { public void removeUpgrades(Player player, boolean bypassIsland) {

View File

@ -293,9 +293,12 @@ public class Block implements Listener {
if (!LocationUtil.isLocationAtLocationRadius(block.getLocation(), if (!LocationUtil.isLocationAtLocationRadius(block.getLocation(),
island.getLocation(world, IslandEnvironment.Island), island.getRadius() - 2.0D)) { island.getLocation(world, IslandEnvironment.Island), island.getRadius() - 2.0D)) {
event.setCancelled(true); event.setCancelled(true);
} else if (skyblock.getStackableManager() != null } else if (skyblock.getStackableManager() != null) {
&& skyblock.getStackableManager().isStacked(block.getLocation())) { if (skyblock.getStackableManager().isStacked(block.getLocation())) {
event.setCancelled(true); event.setCancelled(true);
return;
}
} else if (LocationUtil.isLocationLocation(block.getLocation(), } else if (LocationUtil.isLocationLocation(block.getLocation(),
island.getLocation(world, IslandEnvironment.Main) island.getLocation(world, IslandEnvironment.Main)
.clone() .clone()
@ -341,6 +344,8 @@ public class Block implements Listener {
Material material = event.getBlock().getType(); Material material = event.getBlock().getType();
if (material != Material.WATER && material != Material.LAVA) return; if (material != Material.WATER && material != Material.LAVA) return;
if (event.getNewState().getType() != Material.COBBLESTONE) return;
if (generatorManager != null && generatorManager.getGenerators().size() > 0) { if (generatorManager != null && generatorManager.getGenerators().size() > 0) {
Island island = islandManager.getIslandAtLocation(event.getBlock().getLocation()); Island island = islandManager.getIslandAtLocation(event.getBlock().getLocation());
IslandWorld world = worldManager.getIslandWorld(event.getBlock().getWorld()); IslandWorld world = worldManager.getIslandWorld(event.getBlock().getWorld());
@ -360,6 +365,7 @@ public class Block implements Listener {
} }
} }
event.setCancelled(true);
generatorManager.generateBlock(generator, block); generatorManager.generateBlock(generator, block);
return; return;
} }

View File

@ -102,6 +102,7 @@ public class Move implements Listener {
if (island != null) { if (island != null) {
islandManager.removeUpgrades(player, false);
if (islandManager.isLocationAtIsland(island, to)) { if (islandManager.isLocationAtIsland(island, to)) {
Config config = fileManager.getConfig(new File(skyblock.getDataFolder(), "config.yml")); Config config = fileManager.getConfig(new File(skyblock.getDataFolder(), "config.yml"));
FileConfiguration configLoad = config.getFileConfiguration(); FileConfiguration configLoad = config.getFileConfiguration();
@ -122,6 +123,7 @@ public class Move implements Listener {
if (configLoad.getBoolean("Island.World." + world.name() + ".Liquid.Enable")) { if (configLoad.getBoolean("Island.World." + world.name() + ".Liquid.Enable")) {
if (to.getY() <= configLoad.getInt("Island.World." + world.name() + ".Liquid.Height")) { if (to.getY() <= configLoad.getInt("Island.World." + world.name() + ".Liquid.Height")) {
if (!configLoad.getBoolean("Island.Liquid.Teleport.Enable")) return;
if (keepItemsOnDeath) { if (keepItemsOnDeath) {
player.setFallDistance(0.0F); player.setFallDistance(0.0F);

View File

@ -16,6 +16,25 @@ Command:
Message: "&bSkyBlock &8| &cError&8: &ePlease provide a numerical value." Message: "&bSkyBlock &8| &cError&8: &ePlease provide a numerical value."
Page: Page:
Message: "&bSkyBlock &8| &cError&8: &eThere are not that many pages." Message: "&bSkyBlock &8| &cError&8: &eThere are not that many pages."
Bank:
Info:
Message: "&f&oAllows you to access your islands bank."
Unknown:
Message: "&bSkyBlock &8| &cError&8: &eYou are not currently on an island."
Perm:
Message: "&bSkyBlock &8| &cError&8: &eYou do not have permission to access this islands bank."
Balance:
Message: "&bSkyBlock &8| &aInfo&8: &eYour islands balance is '&7$%balance%&e'."
Deposit:
Message: "&bSkyBlock &8| &aInfo&8: &eYou successfully deposited '&7$%amount%&e'."
Withdraw:
Message: "&bSkyBlock &8| &aInfo&8: &eYou successfully withdrew '&7$%amount%&e'."
Short:
Message: "&bSkyBlock &8| &cError&8: &eYou don't have enough money to do that."
Short2:
Message: "&bSkyBlock &8| &cError&8: &eThere is not enough money to withdraw."
Invalid:
Message: "&bSkyBlock &8| &cError&8: &eInvalid: /island bank [<Deposit|Withdraw|Balance>]"
Unlock: Unlock:
Owner: Owner:
Message: "&bSkyBlock &8| &cError&8: &eYou are not an Island owner." Message: "&bSkyBlock &8| &cError&8: &eYou are not an Island owner."