Merge branch 'main' of https://github.com/Lucanius69/BedWars
This commit is contained in:
commit
5e63d85468
@ -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;
|
||||
|
@ -154,7 +154,9 @@ public class ArenaCommand implements CommandExecutor {
|
||||
new GenerateCommand().executeAs(sender, cmd, label, args);
|
||||
|
||||
break;
|
||||
|
||||
case "generator":
|
||||
new GeneratorCommand().executeAs(sender, cmd, label, args);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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<String> getTabCompletions(CommandSender sender, Command cmd, String label, String[] args) {
|
||||
List<String> tabCompletions = new ArrayList<String>();
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
@ -7,6 +7,7 @@ import lombok.Setter;
|
||||
import rip.tilly.bedwars.generators.Generator;
|
||||
import rip.tilly.bedwars.utils.CustomLocation;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Getter
|
||||
@ -38,10 +39,6 @@ public class Arena {
|
||||
private int deadZone;
|
||||
private int buildMax;
|
||||
|
||||
// private List<Generator> playerGenerators;
|
||||
// private List<Generator> diamondGenerators;
|
||||
// private List<Generator> emeraldGenerators;
|
||||
|
||||
private boolean enabled;
|
||||
|
||||
public CopiedArena getAvailableArena() {
|
||||
|
@ -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<CustomLocation> generators = new ArrayList<>();
|
||||
}
|
||||
|
@ -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 {
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -52,6 +52,8 @@ public class ArenaManager {
|
||||
int deadZone = section.getInt(name + ".deadZone");
|
||||
int buildMax = section.getInt(name + ".buildMax");
|
||||
|
||||
List<String> generators = section.getStringList(name + ".generators");
|
||||
|
||||
CustomLocation spawnA = CustomLocation.stringToLocation(a);
|
||||
CustomLocation spawnB = CustomLocation.stringToLocation(b);
|
||||
CustomLocation locMin = CustomLocation.stringToLocation(min);
|
||||
@ -61,6 +63,11 @@ public class ArenaManager {
|
||||
CustomLocation locTeamBmin = CustomLocation.stringToLocation(teamBmin);
|
||||
CustomLocation locTeamBmax = CustomLocation.stringToLocation(teamBmax);
|
||||
|
||||
List<CustomLocation> generatorLocations = new ArrayList<>();
|
||||
for (String location : generators) {
|
||||
generatorLocations.add(CustomLocation.stringToLocation(location));
|
||||
}
|
||||
|
||||
List<CopiedArena> copiedArenas = new ArrayList<>();
|
||||
ConfigurationSection copiedSection = section.getConfigurationSection(name + ".copiedArenas");
|
||||
if (copiedSection != null) {
|
||||
@ -74,6 +81,8 @@ public class ArenaManager {
|
||||
String copyTeamBmin = copiedSection.getString(copy + ".teamBmin");
|
||||
String copyTeamBmax = copiedSection.getString(copy + ".teamBmax");
|
||||
|
||||
List<String> copyGenerators = copiedSection.getStringList(copy + ".generators");
|
||||
|
||||
CustomLocation copySpawnA = CustomLocation.stringToLocation(copyA);
|
||||
CustomLocation copySpawnB = CustomLocation.stringToLocation(copyB);
|
||||
CustomLocation copyLocMin = CustomLocation.stringToLocation(copyMin);
|
||||
@ -83,6 +92,11 @@ public class ArenaManager {
|
||||
CustomLocation copyLocTeamBmin = CustomLocation.stringToLocation(copyTeamBmin);
|
||||
CustomLocation copyLocTeamBmax = CustomLocation.stringToLocation(copyTeamBmax);
|
||||
|
||||
List<CustomLocation> copyGeneratorLocations = new ArrayList<>();
|
||||
for (String location : copyGenerators) {
|
||||
copyGeneratorLocations.add(CustomLocation.stringToLocation(location));
|
||||
}
|
||||
|
||||
CopiedArena copiedArena = new CopiedArena(
|
||||
copySpawnA,
|
||||
copySpawnB,
|
||||
@ -91,7 +105,8 @@ public class ArenaManager {
|
||||
copyLocTeamAmin,
|
||||
copyLocTeamAmax,
|
||||
copyLocTeamBmin,
|
||||
copyLocTeamBmax
|
||||
copyLocTeamBmax,
|
||||
copyGeneratorLocations
|
||||
);
|
||||
|
||||
this.plugin.getChunkClearingManager().copyArena(copiedArena);
|
||||
@ -118,6 +133,7 @@ public class ArenaManager {
|
||||
locTeamBmax,
|
||||
deadZone,
|
||||
buildMax,
|
||||
generatorLocations,
|
||||
enabled
|
||||
);
|
||||
|
||||
@ -161,6 +177,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);
|
||||
|
||||
@ -187,6 +205,8 @@ public class ArenaManager {
|
||||
fileConfig.set(copyRoot + ".teamBmin", copyTeamBmin);
|
||||
fileConfig.set(copyRoot + ".teamBmax", copyTeamBmax);
|
||||
|
||||
fileConfig.set(copyRoot + ".generators", this.fromLocations(copiedArena.getGenerators()));
|
||||
|
||||
i++;
|
||||
}
|
||||
}
|
||||
@ -241,4 +261,13 @@ public class ArenaManager {
|
||||
public void setArenaGameUUIDs(CopiedArena copiedArena, UUID uuid) {
|
||||
this.arenaGameUUIDs.put(copiedArena, uuid);
|
||||
}
|
||||
|
||||
public List<String> fromLocations(List<CustomLocation> locations) {
|
||||
List<String> toReturn = new ArrayList<>();
|
||||
for (CustomLocation location : locations) {
|
||||
toReturn.add(CustomLocation.locationToString(location));
|
||||
}
|
||||
|
||||
return toReturn;
|
||||
}
|
||||
}
|
||||
|
94
src/main/java/rip/tilly/bedwars/menus/shop/ShopButton.java
Normal file
94
src/main/java/rip/tilly/bedwars/menus/shop/ShopButton.java
Normal file
@ -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<String> 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<String> 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);
|
||||
}
|
||||
}
|
||||
}
|
20
src/main/java/rip/tilly/bedwars/menus/shop/ShopType.java
Normal file
20
src/main/java/rip/tilly/bedwars/menus/shop/ShopType.java
Normal file
@ -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;
|
||||
}
|
@ -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;
|
||||
}
|
@ -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<Integer, Button> getButtons(Player player) {
|
||||
Map<Integer, Button> buttons = new HashMap<>();
|
||||
|
||||
|
||||
}
|
||||
}
|
@ -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<CustomLocation> 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);
|
||||
|
@ -1,4 +1,4 @@
|
||||
package rip.tilly.bedwars.menusystem;
|
||||
package rip.tilly.bedwars.utils.menusystem;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
@ -1,4 +1,4 @@
|
||||
package rip.tilly.bedwars.menusystem;
|
||||
package rip.tilly.bedwars.utils.menusystem;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
@ -1,4 +1,4 @@
|
||||
package rip.tilly.bedwars.menusystem;
|
||||
package rip.tilly.bedwars.utils.menusystem;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
Loading…
Reference in New Issue
Block a user