diff --git a/src/main/java/rip/tilly/bedwars/BedWars.java b/src/main/java/rip/tilly/bedwars/BedWars.java index f104d50..c7583af 100644 --- a/src/main/java/rip/tilly/bedwars/BedWars.java +++ b/src/main/java/rip/tilly/bedwars/BedWars.java @@ -22,7 +22,7 @@ import rip.tilly.bedwars.managers.hotbar.HotbarManager; import rip.tilly.bedwars.managers.mongo.MongoManager; import rip.tilly.bedwars.managers.party.PartyManager; import rip.tilly.bedwars.managers.queue.QueueManager; -import rip.tilly.bedwars.menusystem.PlayerMenuUtil; +import rip.tilly.bedwars.utils.menusystem.PlayerMenuUtil; import rip.tilly.bedwars.providers.placeholderapi.PlaceholderAPIProvider; import rip.tilly.bedwars.providers.scoreboard.ScoreboardProvider; import rip.tilly.bedwars.utils.CC; diff --git a/src/main/java/rip/tilly/bedwars/commands/arena/ArenaCommand.java b/src/main/java/rip/tilly/bedwars/commands/arena/ArenaCommand.java index f621adc..4e83e5e 100644 --- a/src/main/java/rip/tilly/bedwars/commands/arena/ArenaCommand.java +++ b/src/main/java/rip/tilly/bedwars/commands/arena/ArenaCommand.java @@ -139,7 +139,8 @@ public class ArenaCommand implements CommandExecutor { new GenerateCommand().executeAs(sender, cmd, label, args); break; - + case "generator": + new GeneratorCommand().executeAs(sender, cmd, label, args); } } diff --git a/src/main/java/rip/tilly/bedwars/commands/arena/GeneratorCommand.java b/src/main/java/rip/tilly/bedwars/commands/arena/GeneratorCommand.java new file mode 100644 index 0000000..f6fe466 --- /dev/null +++ b/src/main/java/rip/tilly/bedwars/commands/arena/GeneratorCommand.java @@ -0,0 +1,48 @@ +package rip.tilly.bedwars.commands.arena; + +import org.bukkit.ChatColor; +import org.bukkit.Location; +import org.bukkit.command.Command; +import org.bukkit.command.CommandSender; +import org.bukkit.configuration.file.FileConfiguration; +import org.bukkit.entity.Player; +import rip.tilly.bedwars.BedWars; +import rip.tilly.bedwars.commands.BaseCommand; +import rip.tilly.bedwars.game.arena.Arena; +import rip.tilly.bedwars.utils.CC; + +import java.util.ArrayList; +import java.util.List; + +public class GeneratorCommand extends BaseCommand { + + private BedWars main = BedWars.getInstance(); + + @Override + public void executeAs(CommandSender sender, Command cmd, String label, String[] args) { + Player player = (Player) sender; + + Arena arena = this.main.getArenaManager().getArena(args[1]); + + if (arena != null) { + Location location = player.getLocation(); + player.sendMessage(ChatColor.GREEN + "Successfully set the generator point #" + this.main.getArenaManager().getArena(arena.getName()).getGenerators().size() + "."); + this.saveStringsGenerators(arena); + } else { + player.sendMessage(CC.translate("&cThis arena does not already exist")); + } + } + + @Override + public List getTabCompletions(CommandSender sender, Command cmd, String label, String[] args) { + List tabCompletions = new ArrayList(); + + return tabCompletions; + } + + private void saveStringsGenerators(Arena arena) { + FileConfiguration config = this.main.getArenasConfig().getConfig(); + config.set("arenas." + arena.getName() + ".generators", this.main.getArenaManager().fromLocations(arena.getGenerators())); + this.main.getArenasConfig().save(); + } +} diff --git a/src/main/java/rip/tilly/bedwars/game/arena/Arena.java b/src/main/java/rip/tilly/bedwars/game/arena/Arena.java index c45c390..6e7d9db 100644 --- a/src/main/java/rip/tilly/bedwars/game/arena/Arena.java +++ b/src/main/java/rip/tilly/bedwars/game/arena/Arena.java @@ -6,6 +6,7 @@ import lombok.RequiredArgsConstructor; import lombok.Setter; import rip.tilly.bedwars.utils.CustomLocation; +import java.util.ArrayList; import java.util.List; @Getter @@ -37,6 +38,8 @@ public class Arena { private int deadZone; private int buildMax; + private List generators = new ArrayList<>(); + private boolean enabled; public CopiedArena getAvailableArena() { diff --git a/src/main/java/rip/tilly/bedwars/game/arena/CopiedArena.java b/src/main/java/rip/tilly/bedwars/game/arena/CopiedArena.java index 7a929e3..52857dd 100644 --- a/src/main/java/rip/tilly/bedwars/game/arena/CopiedArena.java +++ b/src/main/java/rip/tilly/bedwars/game/arena/CopiedArena.java @@ -6,6 +6,9 @@ import lombok.RequiredArgsConstructor; import lombok.Setter; import rip.tilly.bedwars.utils.CustomLocation; +import java.util.ArrayList; +import java.util.List; + @Getter @Setter @AllArgsConstructor @@ -23,4 +26,6 @@ public class CopiedArena { private CustomLocation teamBmin; private CustomLocation teamBmax; + + private List generators = new ArrayList<>(); } diff --git a/src/main/java/rip/tilly/bedwars/listeners/MenuListener.java b/src/main/java/rip/tilly/bedwars/listeners/MenuListener.java index a4abf1a..0f72b40 100644 --- a/src/main/java/rip/tilly/bedwars/listeners/MenuListener.java +++ b/src/main/java/rip/tilly/bedwars/listeners/MenuListener.java @@ -4,7 +4,7 @@ import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.inventory.InventoryClickEvent; import org.bukkit.inventory.InventoryHolder; -import rip.tilly.bedwars.menusystem.Menu; +import rip.tilly.bedwars.utils.menusystem.Menu; public class MenuListener implements Listener { diff --git a/src/main/java/rip/tilly/bedwars/listeners/game/DamageListener.java b/src/main/java/rip/tilly/bedwars/listeners/game/DamageListener.java index ded6acd..76790d9 100644 --- a/src/main/java/rip/tilly/bedwars/listeners/game/DamageListener.java +++ b/src/main/java/rip/tilly/bedwars/listeners/game/DamageListener.java @@ -29,16 +29,17 @@ public class DamageListener implements Listener { Player player = (Player) event.getEntity(); PlayerData playerData = this.plugin.getPlayerDataManager().getPlayerData(player.getUniqueId()); EntityDamageEvent.DamageCause cause = event.getCause(); - Game game = this.plugin.getGameManager().getGame(player.getUniqueId()); switch (playerData.getPlayerState()) { case PLAYING: + Game game = this.plugin.getGameManager().getGame(player.getUniqueId()); if (game.getGameState() != GameState.FIGHTING) { event.setCancelled(true); } break; case RESPAWNING: + Game respawnGame = this.plugin.getGameManager().getGame(player.getUniqueId()); if (cause == EntityDamageEvent.DamageCause.VOID) { - Location gameLocation = playerData.getTeamId() == 1 ? game.getCopiedArena().getA().toBukkitLocation() : game.getCopiedArena().getB().toBukkitLocation(); + Location gameLocation = playerData.getTeamId() == 1 ? respawnGame.getCopiedArena().getA().toBukkitLocation() : respawnGame.getCopiedArena().getB().toBukkitLocation(); player.teleport(gameLocation); } event.setCancelled(true); @@ -86,7 +87,11 @@ public class DamageListener implements Listener { PlayerData playerData = this.plugin.getPlayerDataManager().getPlayerData(player.getUniqueId()); PlayerData damagerData = this.plugin.getPlayerDataManager().getPlayerData(damager.getUniqueId()); - if (playerData.getPlayerState() != PlayerState.PLAYING || damagerData.getPlayerState() != PlayerState.PLAYING) { + if (playerData.getPlayerState() != PlayerState.PLAYING) { + event.setCancelled(true); + return; + } + if (damagerData.getPlayerState() != PlayerState.PLAYING) { event.setCancelled(true); return; } diff --git a/src/main/java/rip/tilly/bedwars/managers/arena/ArenaManager.java b/src/main/java/rip/tilly/bedwars/managers/arena/ArenaManager.java index 9480289..b4ec525 100644 --- a/src/main/java/rip/tilly/bedwars/managers/arena/ArenaManager.java +++ b/src/main/java/rip/tilly/bedwars/managers/arena/ArenaManager.java @@ -51,6 +51,8 @@ public class ArenaManager { int deadZone = section.getInt(name + ".deadZone"); int buildMax = section.getInt(name + ".buildMax"); + List generators = section.getStringList(name + ".generators"); + CustomLocation spawnA = CustomLocation.stringToLocation(a); CustomLocation spawnB = CustomLocation.stringToLocation(b); CustomLocation locMin = CustomLocation.stringToLocation(min); @@ -60,6 +62,11 @@ public class ArenaManager { CustomLocation locTeamBmin = CustomLocation.stringToLocation(teamBmin); CustomLocation locTeamBmax = CustomLocation.stringToLocation(teamBmax); + List generatorLocations = new ArrayList<>(); + for (String location : generators) { + generatorLocations.add(CustomLocation.stringToLocation(location)); + } + List copiedArenas = new ArrayList<>(); ConfigurationSection copiedSection = section.getConfigurationSection(name + ".copiedArenas"); if (copiedSection != null) { @@ -73,6 +80,8 @@ public class ArenaManager { String copyTeamBmin = copiedSection.getString(copy + ".teamBmin"); String copyTeamBmax = copiedSection.getString(copy + ".teamBmax"); + List copyGenerators = copiedSection.getStringList(copy + ".generators"); + CustomLocation copySpawnA = CustomLocation.stringToLocation(copyA); CustomLocation copySpawnB = CustomLocation.stringToLocation(copyB); CustomLocation copyLocMin = CustomLocation.stringToLocation(copyMin); @@ -82,6 +91,11 @@ public class ArenaManager { CustomLocation copyLocTeamBmin = CustomLocation.stringToLocation(copyTeamBmin); CustomLocation copyLocTeamBmax = CustomLocation.stringToLocation(copyTeamBmax); + List copyGeneratorLocations = new ArrayList<>(); + for (String location : copyGenerators) { + copyGeneratorLocations.add(CustomLocation.stringToLocation(location)); + } + CopiedArena copiedArena = new CopiedArena( copySpawnA, copySpawnB, @@ -90,7 +104,8 @@ public class ArenaManager { copyLocTeamAmin, copyLocTeamAmax, copyLocTeamBmin, - copyLocTeamBmax + copyLocTeamBmax, + copyGeneratorLocations ); this.plugin.getChunkClearingManager().copyArena(copiedArena); @@ -117,6 +132,7 @@ public class ArenaManager { locTeamBmax, deadZone, buildMax, + generatorLocations, enabled ); @@ -160,6 +176,8 @@ public class ArenaManager { fileConfig.set(root + ".deadZone", deadZone); fileConfig.set(root + ".buildMax", buildMax); + fileConfig.set(root + ".generators", this.fromLocations(arena.getGenerators())); + fileConfig.set(root + ".enabled", arena.isEnabled()); fileConfig.set(root + ".copiedArenas", null); @@ -186,6 +204,8 @@ public class ArenaManager { fileConfig.set(copyRoot + ".teamBmin", copyTeamBmin); fileConfig.set(copyRoot + ".teamBmax", copyTeamBmax); + fileConfig.set(copyRoot + ".generators", this.fromLocations(copiedArena.getGenerators())); + i++; } } @@ -240,4 +260,13 @@ public class ArenaManager { public void setArenaGameUUIDs(CopiedArena copiedArena, UUID uuid) { this.arenaGameUUIDs.put(copiedArena, uuid); } + + public List fromLocations(List locations) { + List toReturn = new ArrayList<>(); + for (CustomLocation location : locations) { + toReturn.add(CustomLocation.locationToString(location)); + } + + return toReturn; + } } diff --git a/src/main/java/rip/tilly/bedwars/menus/shop/ShopButton.java b/src/main/java/rip/tilly/bedwars/menus/shop/ShopButton.java new file mode 100644 index 0000000..82a2e93 --- /dev/null +++ b/src/main/java/rip/tilly/bedwars/menus/shop/ShopButton.java @@ -0,0 +1,94 @@ +package rip.tilly.bedwars.menus.shop; + +import lombok.AllArgsConstructor; +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.event.inventory.ClickType; +import org.bukkit.inventory.ItemStack; +import rip.tilly.bedwars.BedWars; +import rip.tilly.bedwars.playerdata.PlayerData; +import rip.tilly.bedwars.utils.CC; +import rip.tilly.bedwars.utils.ItemBuilder; +import rip.tilly.bedwars.utils.menu.Button; + +import java.util.ArrayList; +import java.util.List; + +@AllArgsConstructor +public class ShopButton extends Button { + + private final String name; + private final List lore; + private final Material material; + private final int data; + private final int amount; + private final Material costType; + private final String costTypeName; + private final int cost; + private final boolean color; + private final int costItems; + + @Override + public ItemStack getButtonItem(Player player) { + List loreList = new ArrayList<>(); + + loreList.add(" "); + loreList.addAll(lore); + +// int costItems = 0; +// for (ItemStack contents : player.getInventory().getContents()) { +// if (contents != null) { +// if (contents.getType() == costType) { +// costItems += contents.getAmount(); +// } +// } +// } + + loreList.add(" "); + loreList.add(costItems >= cost ? "&aClick to purchase!" : "&cYou don't have enough " + costTypeName + "!"); + + PlayerData playerData = BedWars.getInstance().getPlayerDataManager().getPlayerData(player.getUniqueId()); + if (color) { + return new ItemBuilder(material).name(name).lore(loreList).amount(amount).durability(playerData.getPlayerTeam().getColorData()).hideFlags().build(); + } else { + return new ItemBuilder(material).name(name).lore(loreList).amount(amount).durability(data).hideFlags().build(); + } + } + + @Override + public void clicked(Player player, int slot, ClickType clickType, int hotbarButton) { + +// int costItems = 0; +// for (ItemStack contents : player.getInventory().getContents()) { +// if (contents != null) { +// if (contents.getType() == costType) { +// costItems += contents.getAmount(); +// } +// } +// } + + PlayerData playerData = BedWars.getInstance().getPlayerDataManager().getPlayerData(player.getUniqueId()); + if (costItems >= cost) { + for (ItemStack contents : player.getInventory().getContents()) { + if (contents != null) { + if (contents.getType() == costType) { + if (contents.getAmount() == cost) { + player.getInventory().removeItem(contents); + } else { + contents.setAmount(contents.getAmount() - cost); + } + } + } + } + if (color) { + player.getInventory().addItem(new ItemBuilder(material).amount(amount).durability(playerData.getPlayerTeam().getColorData()).hideFlags().build()); + } else { + player.getInventory().addItem(new ItemBuilder(material).amount(amount).durability(data).hideFlags().build()); + } + playNeutral(player); + } else { + player.sendMessage(CC.translate("&cYou don't have enough " + costTypeName + "!")); + playFail(player); + } + } +} diff --git a/src/main/java/rip/tilly/bedwars/menus/shop/ShopType.java b/src/main/java/rip/tilly/bedwars/menus/shop/ShopType.java new file mode 100644 index 0000000..392332c --- /dev/null +++ b/src/main/java/rip/tilly/bedwars/menus/shop/ShopType.java @@ -0,0 +1,20 @@ +package rip.tilly.bedwars.menus.shop; + +import lombok.RequiredArgsConstructor; +import org.bukkit.Material; + +@RequiredArgsConstructor +public enum ShopType { + + QUICK("Quick Buy"), + BLOCKS("Blocks"), + ARMOR("Armor"), + TOOLS("Tools"), + WEAPONS("Weapons"), + RANGED("Ranged"), + POTIONS("Potions"), + UTILITY("Utility"); + + private final String name; + private final Material material; +} diff --git a/src/main/java/rip/tilly/bedwars/menus/shop/ShopTypeButton.java b/src/main/java/rip/tilly/bedwars/menus/shop/ShopTypeButton.java new file mode 100644 index 0000000..1fb3d2d --- /dev/null +++ b/src/main/java/rip/tilly/bedwars/menus/shop/ShopTypeButton.java @@ -0,0 +1,10 @@ +package rip.tilly.bedwars.menus.shop; + +import lombok.AllArgsConstructor; +import rip.tilly.bedwars.utils.menu.Button; + +@AllArgsConstructor +public class ShopTypeButton extends Button { + + private final ShopType shopType; +} diff --git a/src/main/java/rip/tilly/bedwars/menus/shop/blocks/BlocksMenu.java b/src/main/java/rip/tilly/bedwars/menus/shop/blocks/BlocksMenu.java new file mode 100644 index 0000000..25f987b --- /dev/null +++ b/src/main/java/rip/tilly/bedwars/menus/shop/blocks/BlocksMenu.java @@ -0,0 +1,29 @@ +package rip.tilly.bedwars.menus.shop.blocks; + +import org.bukkit.entity.Player; +import rip.tilly.bedwars.utils.CC; +import rip.tilly.bedwars.utils.menu.Button; +import rip.tilly.bedwars.utils.menu.Menu; + +import java.util.HashMap; +import java.util.Map; + +public class BlocksMenu extends Menu { + + @Override + public boolean isUpdateAfterClick() { + return true; + } + + @Override + public String getTitle(Player player) { + return CC.translate("&eBlocks"); + } + + @Override + public Map getButtons(Player player) { + Map buttons = new HashMap<>(); + + + } +} diff --git a/src/main/java/rip/tilly/bedwars/runnables/ArenaCommandRunnable.java b/src/main/java/rip/tilly/bedwars/runnables/ArenaCommandRunnable.java index 7cddb15..832b6e9 100644 --- a/src/main/java/rip/tilly/bedwars/runnables/ArenaCommandRunnable.java +++ b/src/main/java/rip/tilly/bedwars/runnables/ArenaCommandRunnable.java @@ -10,6 +10,9 @@ import rip.tilly.bedwars.game.arena.Arena; import rip.tilly.bedwars.game.arena.CopiedArena; import rip.tilly.bedwars.utils.CustomLocation; +import java.util.ArrayList; +import java.util.List; + @Getter @AllArgsConstructor public class ArenaCommandRunnable implements Runnable { @@ -58,7 +61,13 @@ public class ArenaCommandRunnable implements Runnable { CustomLocation teamBmin = new CustomLocation(bMinX, arena.getTeamBmin().getY(), bMinZ, arena.getTeamBmin().getYaw(), arena.getTeamBmin().getPitch()); CustomLocation teamBmax = new CustomLocation(bMaxX, arena.getTeamBmax().getY(), bMaxZ, arena.getTeamBmax().getYaw(), arena.getTeamBmax().getPitch()); - CopiedArena copiedArena = new CopiedArena(a, b, min, max, teamAmin, teamAmax, teamBmin, teamBmax); + List generators = new ArrayList<>(); + for (CustomLocation generator : arena.getGenerators()) { + CustomLocation newGenerator = new CustomLocation((generator.getX() + this.getOffsetX()), generator.getY(), (generator.getZ() + this.getOffsetZ()), generator.getYaw(), generator.getPitch()); + generators.add(newGenerator); + } + + CopiedArena copiedArena = new CopiedArena(a, b, min, max, teamAmin, teamAmax, teamBmin, teamBmax, generators); arena.addCopiedArena(copiedArena); arena.addAvailableArena(copiedArena); diff --git a/src/main/java/rip/tilly/bedwars/menusystem/Menu.java b/src/main/java/rip/tilly/bedwars/utils/menusystem/Menu.java similarity index 97% rename from src/main/java/rip/tilly/bedwars/menusystem/Menu.java rename to src/main/java/rip/tilly/bedwars/utils/menusystem/Menu.java index 6115bd9..722984a 100644 --- a/src/main/java/rip/tilly/bedwars/menusystem/Menu.java +++ b/src/main/java/rip/tilly/bedwars/utils/menusystem/Menu.java @@ -1,4 +1,4 @@ -package rip.tilly.bedwars.menusystem; +package rip.tilly.bedwars.utils.menusystem; import org.bukkit.Bukkit; import org.bukkit.Material; diff --git a/src/main/java/rip/tilly/bedwars/menusystem/PaginatedMenu.java b/src/main/java/rip/tilly/bedwars/utils/menusystem/PaginatedMenu.java similarity index 96% rename from src/main/java/rip/tilly/bedwars/menusystem/PaginatedMenu.java rename to src/main/java/rip/tilly/bedwars/utils/menusystem/PaginatedMenu.java index 9af95c0..17cbf26 100644 --- a/src/main/java/rip/tilly/bedwars/menusystem/PaginatedMenu.java +++ b/src/main/java/rip/tilly/bedwars/utils/menusystem/PaginatedMenu.java @@ -1,4 +1,4 @@ -package rip.tilly.bedwars.menusystem; +package rip.tilly.bedwars.utils.menusystem; import org.bukkit.ChatColor; import org.bukkit.Material; diff --git a/src/main/java/rip/tilly/bedwars/menusystem/PlayerMenuUtil.java b/src/main/java/rip/tilly/bedwars/utils/menusystem/PlayerMenuUtil.java similarity index 87% rename from src/main/java/rip/tilly/bedwars/menusystem/PlayerMenuUtil.java rename to src/main/java/rip/tilly/bedwars/utils/menusystem/PlayerMenuUtil.java index eaff142..7ab2bf0 100644 --- a/src/main/java/rip/tilly/bedwars/menusystem/PlayerMenuUtil.java +++ b/src/main/java/rip/tilly/bedwars/utils/menusystem/PlayerMenuUtil.java @@ -1,4 +1,4 @@ -package rip.tilly.bedwars.menusystem; +package rip.tilly.bedwars.utils.menusystem; import org.bukkit.entity.Player;