uhhh
This commit is contained in:
parent
ff6c6cf8ec
commit
a7e07a123b
@ -8,10 +8,10 @@ import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import rip.tilly.bedwars.listeners.GameStartListener;
|
||||
import rip.tilly.bedwars.listeners.InteractListener;
|
||||
import rip.tilly.bedwars.listeners.PlayerDataListener;
|
||||
import rip.tilly.bedwars.listeners.RandomListeners;
|
||||
import rip.tilly.bedwars.listeners.game.GameEndListener;
|
||||
import rip.tilly.bedwars.listeners.game.GameStartListener;
|
||||
import rip.tilly.bedwars.listeners.*;
|
||||
import rip.tilly.bedwars.listeners.game.WorldListener;
|
||||
import rip.tilly.bedwars.managers.CommandManager;
|
||||
import rip.tilly.bedwars.managers.GameManager;
|
||||
import rip.tilly.bedwars.managers.PlayerDataManager;
|
||||
@ -22,6 +22,7 @@ import rip.tilly.bedwars.managers.arena.chunk.ChunkManager;
|
||||
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.providers.scoreboard.ScoreboardProvider;
|
||||
import rip.tilly.bedwars.utils.CC;
|
||||
@ -53,8 +54,9 @@ public final class BedWars extends JavaPlugin {
|
||||
private CommandManager commandManager;
|
||||
private GameManager gameManager;
|
||||
private PartyManager partyManager;
|
||||
private QueueManager queueManager;
|
||||
|
||||
private HashMap<Player, PlayerMenuUtil> playerMenuUtilMap = new HashMap<Player, PlayerMenuUtil>();
|
||||
private final HashMap<Player, PlayerMenuUtil> playerMenuUtilMap = new HashMap<Player, PlayerMenuUtil>();
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
@ -119,11 +121,13 @@ public final class BedWars extends JavaPlugin {
|
||||
this.commandManager = new CommandManager();
|
||||
this.gameManager = new GameManager();
|
||||
this.partyManager = new PartyManager();
|
||||
this.queueManager = new QueueManager();
|
||||
}
|
||||
|
||||
private void loadListeners() {
|
||||
Arrays.asList(
|
||||
new PlayerDataListener(), new RandomListeners(), new InteractListener(), new GameStartListener()
|
||||
new PlayerDataListener(), new RandomListeners(), new InteractListener(), new ButtonListener(),
|
||||
new GameStartListener(), new GameEndListener(), new WorldListener()
|
||||
).forEach(listener -> this.getServer().getPluginManager().registerEvents(listener, this));
|
||||
}
|
||||
|
||||
|
@ -5,7 +5,7 @@ import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import rip.tilly.bedwars.BedWars;
|
||||
import rip.tilly.bedwars.commands.BaseCommand;
|
||||
import rip.tilly.bedwars.player.PlayerData;
|
||||
import rip.tilly.bedwars.playerdata.PlayerData;
|
||||
import rip.tilly.bedwars.utils.CC;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
@ -5,7 +5,7 @@ import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import rip.tilly.bedwars.BedWars;
|
||||
import rip.tilly.bedwars.commands.BaseCommand;
|
||||
import rip.tilly.bedwars.player.PlayerData;
|
||||
import rip.tilly.bedwars.playerdata.PlayerData;
|
||||
import rip.tilly.bedwars.utils.CC;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
@ -5,7 +5,7 @@ import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import rip.tilly.bedwars.BedWars;
|
||||
import rip.tilly.bedwars.commands.BaseCommand;
|
||||
import rip.tilly.bedwars.player.PlayerData;
|
||||
import rip.tilly.bedwars.playerdata.PlayerData;
|
||||
import rip.tilly.bedwars.utils.CC;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
@ -6,6 +6,7 @@ import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import rip.tilly.bedwars.BedWars;
|
||||
import rip.tilly.bedwars.commands.BaseCommand;
|
||||
import rip.tilly.bedwars.utils.CC;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@ -19,8 +20,8 @@ public class AcceptCommand extends BaseCommand {
|
||||
Player player = (Player) sender;
|
||||
|
||||
Player target = Bukkit.getPlayer(args[1]);
|
||||
|
||||
if (target == null) {
|
||||
player.sendMessage(CC.translate("&cThat player is not online!"));
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -5,6 +5,8 @@ import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import rip.tilly.bedwars.BedWars;
|
||||
import rip.tilly.bedwars.commands.BaseCommand;
|
||||
import rip.tilly.bedwars.playerdata.PlayerState;
|
||||
import rip.tilly.bedwars.utils.CC;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@ -17,6 +19,11 @@ public class LeaveCommand extends BaseCommand {
|
||||
public void executeAs(CommandSender sender, Command cmd, String label, String[] args) {
|
||||
Player player = (Player) sender;
|
||||
|
||||
if (this.main.getPlayerDataManager().getPlayerData(player.getUniqueId()).getPlayerState() != PlayerState.SPAWN) {
|
||||
player.sendMessage(CC.translate("&cYou can't use this while not in the spawn!"));
|
||||
return;
|
||||
}
|
||||
|
||||
this.main.getPartyManager().leaveParty(player);
|
||||
}
|
||||
|
||||
|
@ -6,6 +6,8 @@ import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import rip.tilly.bedwars.BedWars;
|
||||
import rip.tilly.bedwars.commands.BaseCommand;
|
||||
import rip.tilly.bedwars.managers.party.Party;
|
||||
import rip.tilly.bedwars.utils.CC;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@ -16,9 +18,28 @@ public class RemoveCommand extends BaseCommand {
|
||||
|
||||
@Override
|
||||
public void executeAs(CommandSender sender, Command cmd, String label, String[] args) {
|
||||
Player player = (Player) sender;
|
||||
Player target = Bukkit.getPlayer(args[1]);
|
||||
|
||||
Party party = this.main.getPartyManager().getParty(player.getUniqueId());
|
||||
if (party == null) {
|
||||
player.sendMessage(CC.translate("&cYou are not in a party!"));
|
||||
return;
|
||||
}
|
||||
|
||||
if (party.getLeader() != player.getUniqueId()) {
|
||||
player.performCommand("party info");
|
||||
return;
|
||||
}
|
||||
|
||||
if (target == null) {
|
||||
player.sendMessage(CC.translate("&cPlayer not found!"));
|
||||
return;
|
||||
}
|
||||
|
||||
Party targetParty = this.main.getPartyManager().getParty(target.getUniqueId());
|
||||
if (targetParty == null || targetParty.getLeader() != party.getLeader()) {
|
||||
player.sendMessage(CC.translate("&cThat player is not in your party!"));
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -5,7 +5,7 @@ import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import rip.tilly.bedwars.BedWars;
|
||||
import rip.tilly.bedwars.commands.BaseCommand;
|
||||
import rip.tilly.bedwars.player.PlayerData;
|
||||
import rip.tilly.bedwars.playerdata.PlayerData;
|
||||
import rip.tilly.bedwars.utils.CC;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
@ -5,7 +5,7 @@ import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import rip.tilly.bedwars.BedWars;
|
||||
import rip.tilly.bedwars.commands.BaseCommand;
|
||||
import rip.tilly.bedwars.player.PlayerData;
|
||||
import rip.tilly.bedwars.playerdata.PlayerData;
|
||||
import rip.tilly.bedwars.utils.CC;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
@ -5,7 +5,7 @@ import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import rip.tilly.bedwars.BedWars;
|
||||
import rip.tilly.bedwars.commands.BaseCommand;
|
||||
import rip.tilly.bedwars.player.PlayerData;
|
||||
import rip.tilly.bedwars.playerdata.PlayerData;
|
||||
import rip.tilly.bedwars.utils.CC;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
@ -1,4 +1,4 @@
|
||||
package rip.tilly.bedwars.game.events;
|
||||
package rip.tilly.bedwars.events;
|
||||
|
||||
import lombok.Getter;
|
||||
import rip.tilly.bedwars.game.Game;
|
@ -1,4 +1,4 @@
|
||||
package rip.tilly.bedwars.game.events;
|
||||
package rip.tilly.bedwars.events;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.RequiredArgsConstructor;
|
@ -1,4 +1,4 @@
|
||||
package rip.tilly.bedwars.game.events;
|
||||
package rip.tilly.bedwars.events;
|
||||
|
||||
import rip.tilly.bedwars.game.Game;
|
||||
|
28
src/main/java/rip/tilly/bedwars/events/PlayerKillEvent.java
Normal file
28
src/main/java/rip/tilly/bedwars/events/PlayerKillEvent.java
Normal file
@ -0,0 +1,28 @@
|
||||
package rip.tilly.bedwars.events;
|
||||
|
||||
import lombok.Getter;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
||||
@Getter
|
||||
public class PlayerKillEvent extends Event {
|
||||
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
|
||||
private final Player player;
|
||||
private final Player killer;
|
||||
|
||||
public PlayerKillEvent(Player player, Player killer) {
|
||||
this.player = player;
|
||||
this.killer = killer;
|
||||
}
|
||||
|
||||
public HandlerList getHandlers() {
|
||||
return handlers;
|
||||
}
|
||||
|
||||
public static HandlerList getHandlerList() {
|
||||
return handlers;
|
||||
}
|
||||
}
|
@ -4,8 +4,11 @@ import io.netty.util.internal.ConcurrentSet;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.github.paperspigot.Title;
|
||||
import rip.tilly.bedwars.BedWars;
|
||||
import rip.tilly.bedwars.game.arena.Arena;
|
||||
@ -13,15 +16,9 @@ import rip.tilly.bedwars.game.arena.CopiedArena;
|
||||
import rip.tilly.bedwars.utils.CC;
|
||||
import rip.tilly.bedwars.utils.TimeUtils;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.*;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
/**
|
||||
* Created by Lucanius
|
||||
* Project: BedWars
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
public class Game {
|
||||
@ -29,9 +26,13 @@ public class Game {
|
||||
private final BedWars plugin = BedWars.getInstance();
|
||||
|
||||
private final Set<Entity> entitiesToRemove = new ConcurrentSet<>();
|
||||
private final Set<Location> placedBlocksLocations = new ConcurrentSet<>();
|
||||
private final Set<UUID> spectators = new ConcurrentSet<>();
|
||||
private final Set<Integer> runnables = new HashSet<>();
|
||||
|
||||
private final List<GameTeam> teams;
|
||||
private final Arena arena;
|
||||
private final GameType gameType;
|
||||
|
||||
private final UUID gameId = UUID.randomUUID();
|
||||
|
||||
@ -39,9 +40,11 @@ public class Game {
|
||||
private GameState gameState = GameState.STARTING;
|
||||
private int countdown = 6;
|
||||
private int durationTimer;
|
||||
private int winningTeamId;
|
||||
|
||||
public Game(Arena arena, GameTeam... teams) {
|
||||
public Game(Arena arena, GameType gameType, GameTeam... teams) {
|
||||
this.arena = arena;
|
||||
this.gameType = gameType;
|
||||
this.teams = Arrays.asList(teams);
|
||||
}
|
||||
|
||||
@ -66,7 +69,7 @@ public class Game {
|
||||
}
|
||||
|
||||
public void broadcastTitle(String message, String subMessage) {
|
||||
Title title = new Title(message, subMessage, 5, 20, 5);
|
||||
Title title = new Title(CC.translate(message), CC.translate(subMessage), 5, 20, 5);
|
||||
this.teams.forEach(team -> team.playingPlayers().forEach(player -> player.sendTitle(title)));
|
||||
}
|
||||
|
||||
@ -78,6 +81,13 @@ public class Game {
|
||||
this.teams.forEach(team -> team.playingPlayers().forEach(player -> player.playSound(player.getLocation(), sound, 10, 1)));
|
||||
}
|
||||
|
||||
public void broadcastWithSound(String message, Sound sound) {
|
||||
this.teams.forEach(team -> team.playingPlayers().forEach(player -> {
|
||||
player.sendMessage(CC.translate(message));
|
||||
player.playSound(player.getLocation(), sound, 10, 1);
|
||||
}));
|
||||
}
|
||||
|
||||
public int decrementCountdown() {
|
||||
return --this.countdown;
|
||||
}
|
||||
@ -90,6 +100,30 @@ public class Game {
|
||||
return (this.teams.get(0).getAllPlayers().size() >= 2 || this.teams.get(1).getAllPlayers().size() >= 2);
|
||||
}
|
||||
|
||||
public void addSpectator(UUID uuid) {
|
||||
this.spectators.add(uuid);
|
||||
}
|
||||
|
||||
public void removeSpectator(UUID uuid) {
|
||||
this.spectators.remove(uuid);
|
||||
}
|
||||
|
||||
public Stream<Player> spectatorPlayers() {
|
||||
return this.spectators.stream().map(this.plugin.getServer()::getPlayer).filter(Objects::nonNull);
|
||||
}
|
||||
|
||||
public void addRunnable(int id) {
|
||||
this.runnables.add(id);
|
||||
}
|
||||
|
||||
public void addPlacedBlock(Block block) {
|
||||
this.placedBlocksLocations.add(block.getLocation());
|
||||
}
|
||||
|
||||
public void removePlacedBlock(Block block) {
|
||||
this.placedBlocksLocations.remove(block.getLocation());
|
||||
}
|
||||
|
||||
public boolean isPlaceable(Location location, Game game) {
|
||||
double minX = game.getCopiedArena().getMin().getX();
|
||||
double minZ = game.getCopiedArena().getMin().getZ();
|
||||
@ -160,4 +194,19 @@ public class Game {
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isBreakable(Block block) {
|
||||
if (placedBlocksLocations.contains(block.getLocation())) {
|
||||
return true;
|
||||
}
|
||||
|
||||
Material material = block.getType();
|
||||
switch (material) {
|
||||
case BED:
|
||||
case BED_BLOCK:
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -4,7 +4,7 @@ import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.bukkit.entity.Player;
|
||||
import rip.tilly.bedwars.BedWars;
|
||||
import rip.tilly.bedwars.player.PlayerTeam;
|
||||
import rip.tilly.bedwars.playerdata.PlayerTeam;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@ -12,10 +12,6 @@ import java.util.Objects;
|
||||
import java.util.UUID;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
/**
|
||||
* Created by Lucanius
|
||||
* Project: BedWars
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
public class GameTeam {
|
||||
@ -29,6 +25,8 @@ public class GameTeam {
|
||||
private final int id;
|
||||
private final PlayerTeam playerTeam;
|
||||
|
||||
private boolean hasBed = true;
|
||||
|
||||
public GameTeam(UUID leader, List<UUID> allPlayers, int id, PlayerTeam playerTeam) {
|
||||
this.leader = leader;
|
||||
this.allPlayers = allPlayers;
|
||||
@ -49,4 +47,8 @@ public class GameTeam {
|
||||
public Stream<Player> playingPlayers() {
|
||||
return this.playingPlayers.stream().map(this.plugin.getServer()::getPlayer).filter(Objects::nonNull);
|
||||
}
|
||||
|
||||
public void destroyBed() {
|
||||
this.hasBed = false;
|
||||
}
|
||||
}
|
||||
|
32
src/main/java/rip/tilly/bedwars/game/GameType.java
Normal file
32
src/main/java/rip/tilly/bedwars/game/GameType.java
Normal file
@ -0,0 +1,32 @@
|
||||
package rip.tilly.bedwars.game;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.bukkit.Material;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
@Getter
|
||||
@RequiredArgsConstructor
|
||||
public enum GameType {
|
||||
|
||||
V1(10, "1v1", Arrays.asList(" ", "&9You have to start somewhere,", "&9so why not start here?"),
|
||||
Material.WOOD_SWORD,
|
||||
0, 2),
|
||||
V2(12, "2v2", Arrays.asList(" ", "&9Adapt, overcome and conquer,", "&9you are advancing rapidly."),
|
||||
Material.STONE_SWORD,
|
||||
0, 4),
|
||||
V3(14, "3v3", Arrays.asList(" ", "&9How crazy is this, it seems", "&9like it was just yesterday", "&9since you started."),
|
||||
Material.IRON_SWORD,
|
||||
0, 6),
|
||||
V4(16, "4v4", Arrays.asList(" ", "&9You are now a master of BedWars,", "&9you are now capable of going", "&9up against the undefeated PvP Bot", "&7(Coming soon...)"),
|
||||
Material.DIAMOND_SWORD, 0, 8);
|
||||
|
||||
private final int slot;
|
||||
private final String name;
|
||||
private final List<String> lore;
|
||||
private final Material material;
|
||||
private final int data;
|
||||
private final int queueAmount;
|
||||
}
|
@ -12,10 +12,6 @@ import java.util.List;
|
||||
@Setter
|
||||
@AllArgsConstructor
|
||||
@RequiredArgsConstructor
|
||||
/**
|
||||
* Created by Lucanius
|
||||
* Project: BedWars
|
||||
*/
|
||||
public class Arena {
|
||||
|
||||
private final String name;
|
||||
|
@ -10,10 +10,6 @@ import rip.tilly.bedwars.utils.CustomLocation;
|
||||
@Setter
|
||||
@AllArgsConstructor
|
||||
@RequiredArgsConstructor
|
||||
/**
|
||||
* Created by Lucanius
|
||||
* Project: BedWars
|
||||
*/
|
||||
public class CopiedArena {
|
||||
|
||||
private CustomLocation a;
|
||||
|
@ -0,0 +1,74 @@
|
||||
package rip.tilly.bedwars.listeners;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.inventory.ClickType;
|
||||
import org.bukkit.event.inventory.InventoryAction;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.event.inventory.InventoryCloseEvent;
|
||||
import rip.tilly.bedwars.BedWars;
|
||||
import rip.tilly.bedwars.utils.menu.Button;
|
||||
import rip.tilly.bedwars.utils.menu.Menu;
|
||||
|
||||
public class ButtonListener implements Listener {
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
public void onButtonPress(InventoryClickEvent event) {
|
||||
Player player = (Player) event.getWhoClicked();
|
||||
Menu openMenu = Menu.currentlyOpenedMenus.get(player.getName());
|
||||
if (openMenu != null) {
|
||||
if (event.getSlot() != event.getRawSlot()) {
|
||||
if ((event.getClick() == ClickType.SHIFT_LEFT || event.getClick() == ClickType.SHIFT_RIGHT)) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (openMenu.getButtons().containsKey(event.getSlot())) {
|
||||
Button button = openMenu.getButtons().get(event.getSlot());
|
||||
boolean cancel = button.shouldCancel(player, event.getSlot(), event.getClick());
|
||||
if (!cancel && (event.getClick() == ClickType.SHIFT_LEFT || event.getClick() == ClickType.SHIFT_RIGHT)) {
|
||||
event.setCancelled(true);
|
||||
if (event.getCurrentItem() != null) {
|
||||
player.getInventory().addItem(event.getCurrentItem());
|
||||
}
|
||||
} else {
|
||||
event.setCancelled(cancel);
|
||||
}
|
||||
|
||||
button.clicked(player, event.getSlot(), event.getClick(), event.getHotbarButton());
|
||||
|
||||
if (Menu.currentlyOpenedMenus.containsKey(player.getName())) {
|
||||
Menu newMenu = Menu.currentlyOpenedMenus.get(player.getName());
|
||||
if (newMenu == openMenu && openMenu.isUpdateAfterClick()) {
|
||||
openMenu.setClosedByMenu(true);
|
||||
newMenu.openMenu(player);
|
||||
}
|
||||
} else if (button.shouldUpdate(player, event.getSlot(), event.getClick())) {
|
||||
openMenu.setClosedByMenu(true);
|
||||
openMenu.openMenu(player);
|
||||
}
|
||||
if (event.isCancelled()) {
|
||||
Bukkit.getScheduler().runTaskLater(BedWars.getInstance(), player::updateInventory, 1L);
|
||||
}
|
||||
} else {
|
||||
if ((event.getClick() == ClickType.SHIFT_LEFT || event.getClick() == ClickType.SHIFT_RIGHT || event.getAction().equals(InventoryAction.MOVE_TO_OTHER_INVENTORY) || event.getAction().equals(InventoryAction.HOTBAR_MOVE_AND_READD) || event.getAction().equals(InventoryAction.HOTBAR_SWAP))) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGH)
|
||||
public void onInventoryClose(InventoryCloseEvent event) {
|
||||
Player player = (Player) event.getPlayer();
|
||||
Menu openMenu = Menu.currentlyOpenedMenus.get(player.getName());
|
||||
if (openMenu != null) {
|
||||
openMenu.onClose(player);
|
||||
Menu.currentlyOpenedMenus.remove(player.getName());
|
||||
}
|
||||
}
|
||||
}
|
@ -1,17 +0,0 @@
|
||||
package rip.tilly.bedwars.listeners;
|
||||
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import rip.tilly.bedwars.BedWars;
|
||||
import rip.tilly.bedwars.game.Game;
|
||||
import rip.tilly.bedwars.game.events.GameStartEvent;
|
||||
|
||||
public class GameStartListener implements Listener {
|
||||
|
||||
private BedWars main = BedWars.getInstance();
|
||||
|
||||
@EventHandler
|
||||
public void onGameStart(GameStartEvent event) {
|
||||
Game game = event.getGame();
|
||||
}
|
||||
}
|
@ -11,20 +11,21 @@ import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.material.TrapDoor;
|
||||
import rip.tilly.bedwars.BedWars;
|
||||
import rip.tilly.bedwars.managers.hotbar.impl.HotbarItem;
|
||||
import rip.tilly.bedwars.menusystem.menu.PlayAGameMenu;
|
||||
import rip.tilly.bedwars.player.PlayerData;
|
||||
import rip.tilly.bedwars.player.PlayerState;
|
||||
import rip.tilly.bedwars.menus.queue.QueueMenu;
|
||||
import rip.tilly.bedwars.playerdata.PlayerData;
|
||||
import rip.tilly.bedwars.playerdata.PlayerState;
|
||||
|
||||
/**
|
||||
* Created by Lucanius
|
||||
* Project: BedWars
|
||||
*/
|
||||
public class InteractListener implements Listener {
|
||||
|
||||
private final BedWars plugin = BedWars.getInstance();
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerInteract(PlayerInteractEvent event) {
|
||||
if (event.getAction() == Action.PHYSICAL && event.getClickedBlock().getType() == Material.SOIL) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
if ((event.getAction() != Action.RIGHT_CLICK_BLOCK && event.getAction() != Action.RIGHT_CLICK_AIR)) {
|
||||
return;
|
||||
}
|
||||
@ -74,7 +75,7 @@ public class InteractListener implements Listener {
|
||||
case SPAWN:
|
||||
switch (hotbarItem.getActionType()) {
|
||||
case QUEUE_MENU:
|
||||
new PlayAGameMenu(this.plugin.getPlayerMenuUtil(player)).open();
|
||||
new QueueMenu().openMenu(player);
|
||||
|
||||
break;
|
||||
case SETTINGS_MENU:
|
||||
@ -95,7 +96,7 @@ public class InteractListener implements Listener {
|
||||
// open party games menu
|
||||
break;
|
||||
case PARTY_INFO:
|
||||
player.chat("/party info");
|
||||
player.performCommand("party info");
|
||||
|
||||
break;
|
||||
case PARTY_LEAVE:
|
||||
@ -107,7 +108,7 @@ public class InteractListener implements Listener {
|
||||
case QUEUE:
|
||||
switch (hotbarItem.getActionType()) {
|
||||
case LEAVE_QUEUE:
|
||||
// leave queue
|
||||
this.plugin.getQueueManager().removePlayerFromQueue(player);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
@ -7,12 +7,8 @@ import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.*;
|
||||
import rip.tilly.bedwars.BedWars;
|
||||
import rip.tilly.bedwars.player.PlayerData;
|
||||
import rip.tilly.bedwars.playerdata.PlayerData;
|
||||
|
||||
/**
|
||||
* Created by Lucanius
|
||||
* Project: BedWars
|
||||
*/
|
||||
public class PlayerDataListener implements Listener {
|
||||
|
||||
private final BedWars plugin = BedWars.getInstance();
|
||||
@ -59,13 +55,13 @@ public class PlayerDataListener implements Listener {
|
||||
|
||||
switch (playerData.getPlayerState()) {
|
||||
case PLAYING:
|
||||
this.plugin.getGameManager().removePlayerFromGame(player, playerData);
|
||||
this.plugin.getGameManager().removePlayerFromGame(player, playerData, false);
|
||||
break;
|
||||
case QUEUE:
|
||||
// remove from queue
|
||||
this.plugin.getQueueManager().removePlayerFromQueue(player);
|
||||
break;
|
||||
case SPECTATING:
|
||||
// remove spectator
|
||||
this.plugin.getGameManager().removeSpectator(player);
|
||||
break;
|
||||
}
|
||||
|
||||
@ -82,13 +78,13 @@ public class PlayerDataListener implements Listener {
|
||||
|
||||
switch (playerData.getPlayerState()) {
|
||||
case PLAYING:
|
||||
this.plugin.getGameManager().removePlayerFromGame(player, playerData);
|
||||
this.plugin.getGameManager().removePlayerFromGame(player, playerData, false);
|
||||
break;
|
||||
case QUEUE:
|
||||
// remove from queue
|
||||
this.plugin.getQueueManager().removePlayerFromQueue(player);
|
||||
break;
|
||||
case SPECTATING:
|
||||
// remove spectator
|
||||
this.plugin.getGameManager().removeSpectator(player);
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -2,13 +2,15 @@ package rip.tilly.bedwars.listeners;
|
||||
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.block.BlockFadeEvent;
|
||||
import org.bukkit.event.block.*;
|
||||
import org.bukkit.event.entity.FoodLevelChangeEvent;
|
||||
import org.bukkit.event.hanging.HangingBreakEvent;
|
||||
import org.bukkit.event.player.PlayerDropItemEvent;
|
||||
import org.bukkit.event.player.PlayerToggleFlightEvent;
|
||||
import org.bukkit.event.weather.WeatherChangeEvent;
|
||||
import rip.tilly.bedwars.BedWars;
|
||||
import rip.tilly.bedwars.player.PlayerData;
|
||||
import rip.tilly.bedwars.player.PlayerState;
|
||||
import rip.tilly.bedwars.playerdata.PlayerData;
|
||||
import rip.tilly.bedwars.playerdata.PlayerState;
|
||||
|
||||
public class RandomListeners implements Listener {
|
||||
|
||||
@ -29,11 +31,52 @@ public class RandomListeners implements Listener {
|
||||
|
||||
@EventHandler
|
||||
public void onWeatherChange(WeatherChangeEvent event) {
|
||||
event.setCancelled(true);
|
||||
if (event.toWeatherState()) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onBlockFade(BlockFadeEvent event) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onBlockForm(BlockFormEvent event) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onLeavesDecay(LeavesDecayEvent event) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onHangingBreak(HangingBreakEvent event) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onBlockBurn(BlockBurnEvent event) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onBlockSpread(BlockSpreadEvent event) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onBlockIgnite(BlockIgniteEvent event) {
|
||||
if (event.getCause() == BlockIgniteEvent.IgniteCause.LIGHTNING) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerToggleFlight(PlayerToggleFlightEvent event) {
|
||||
if (this.plugin.getPlayerDataManager().getPlayerData(event.getPlayer().getUniqueId()).getPlayerState() == PlayerState.RESPAWNING) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,52 @@
|
||||
package rip.tilly.bedwars.listeners.game;
|
||||
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.github.paperspigot.Title;
|
||||
import rip.tilly.bedwars.BedWars;
|
||||
import rip.tilly.bedwars.events.GameEndEvent;
|
||||
import rip.tilly.bedwars.game.Game;
|
||||
import rip.tilly.bedwars.game.GameState;
|
||||
import rip.tilly.bedwars.game.GameTeam;
|
||||
import rip.tilly.bedwars.playerdata.PlayerData;
|
||||
import rip.tilly.bedwars.utils.CC;
|
||||
import rip.tilly.bedwars.utils.PlayerUtil;
|
||||
|
||||
public class GameEndListener implements Listener {
|
||||
|
||||
private final BedWars plugin = BedWars.getInstance();
|
||||
|
||||
@EventHandler
|
||||
public void onGameEnd(GameEndEvent event) {
|
||||
Game game = event.getGame();
|
||||
game.setGameState(GameState.ENDING);
|
||||
game.setCountdown(3);
|
||||
|
||||
GameTeam winningTeam = event.getWinningTeam();
|
||||
GameTeam losingTeam = event.getLosingTeam();
|
||||
|
||||
game.setWinningTeamId(winningTeam.getId());
|
||||
|
||||
game.getTeams().forEach(team -> team.allPlayers().forEach(player -> {
|
||||
PlayerUtil.clearPlayer(player);
|
||||
|
||||
PlayerData playerData = this.plugin.getPlayerDataManager().getPlayerData(player.getUniqueId());
|
||||
playerData.setLastDamager(null);
|
||||
playerData.setGameKills(0);
|
||||
|
||||
String winnerTitle = CC.translate("&aVICTORY!");
|
||||
String losingTitle = CC.translate("&aDEFEAT!");
|
||||
String subTitle = CC.translate(winningTeam.getPlayerTeam().getChatColor() + winningTeam.getPlayerTeam().getName() + " &fhas won the game!");
|
||||
|
||||
if (winningTeam.getAllPlayers().contains(player.getUniqueId())) {
|
||||
player.sendTitle(new Title(winnerTitle, subTitle, 5, 20, 5));
|
||||
playerData.setWins(playerData.getWins() + 1);
|
||||
} else if (losingTeam.getAllPlayers().contains(player.getUniqueId())) {
|
||||
player.sendTitle(new Title(losingTitle, subTitle, 5, 20, 5));
|
||||
playerData.setLosses(playerData.getLosses() + 1);
|
||||
}
|
||||
|
||||
playerData.setGamesPlayed(playerData.getGamesPlayed() + 1);
|
||||
}));
|
||||
}
|
||||
}
|
@ -0,0 +1,76 @@
|
||||
package rip.tilly.bedwars.listeners.game;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import rip.tilly.bedwars.BedWars;
|
||||
import rip.tilly.bedwars.events.GameStartEvent;
|
||||
import rip.tilly.bedwars.game.Game;
|
||||
import rip.tilly.bedwars.game.GameType;
|
||||
import rip.tilly.bedwars.playerdata.PlayerData;
|
||||
import rip.tilly.bedwars.runnables.GameRunnable;
|
||||
import rip.tilly.bedwars.utils.CC;
|
||||
import rip.tilly.bedwars.utils.CustomLocation;
|
||||
import rip.tilly.bedwars.utils.PlayerUtil;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
public class GameStartListener implements Listener {
|
||||
|
||||
private BedWars plugin = BedWars.getInstance();
|
||||
|
||||
@EventHandler
|
||||
public void onGameStart(GameStartEvent event) {
|
||||
Game game = event.getGame();
|
||||
GameType gameType = game.getGameType();
|
||||
|
||||
if (game.getArena().getAvailableArenas().size() > 0) {
|
||||
game.setCopiedArena(game.getArena().getAvailableArena());
|
||||
this.plugin.getArenaManager().setArenaGameUUIDs(game.getCopiedArena(), game.getGameId());
|
||||
} else {
|
||||
game.broadcast(CC.translate("&cThere are no available arenas at this moment!"));
|
||||
this.plugin.getGameManager().removeGame(game);
|
||||
return;
|
||||
}
|
||||
|
||||
Set<Player> gamePlayers = new HashSet<>();
|
||||
game.getTeams().forEach(team -> team.playingPlayers().forEach(player -> {
|
||||
gamePlayers.add(player);
|
||||
this.plugin.getGameManager().removeGameRequests(player.getUniqueId());
|
||||
|
||||
PlayerUtil.clearPlayer(player);
|
||||
|
||||
PlayerData playerData = this.plugin.getPlayerDataManager().getPlayerData(player.getUniqueId());
|
||||
playerData.setCurrentGameId(game.getGameId());
|
||||
playerData.setTeamId(team.getId());
|
||||
playerData.setPlayerTeam(team.getPlayerTeam());
|
||||
|
||||
CustomLocation locationA = game.getCopiedArena().getA();
|
||||
CustomLocation locationB = game.getCopiedArena().getB();
|
||||
|
||||
player.teleport(team.getId() == 1 ? locationA.toBukkitLocation() : locationB.toBukkitLocation());
|
||||
|
||||
player.getInventory().setArmorContents(this.plugin.getGameManager().getGameArmor(playerData));
|
||||
for (ItemStack stack : this.plugin.getGameManager().getGameItems()) {
|
||||
player.getInventory().addItem(stack);
|
||||
}
|
||||
}));
|
||||
|
||||
for (Player player : gamePlayers) {
|
||||
for (Player online : this.plugin.getServer().getOnlinePlayers()) {
|
||||
online.hidePlayer(player);
|
||||
player.hidePlayer(online);
|
||||
}
|
||||
}
|
||||
|
||||
for (Player player : gamePlayers) {
|
||||
for (Player other : gamePlayers) {
|
||||
player.showPlayer(other);
|
||||
}
|
||||
}
|
||||
|
||||
new GameRunnable(game).runTaskTimer(this.plugin, 20, 20);
|
||||
}
|
||||
}
|
@ -0,0 +1,64 @@
|
||||
package rip.tilly.bedwars.listeners.game;
|
||||
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerMoveEvent;
|
||||
import rip.tilly.bedwars.BedWars;
|
||||
import rip.tilly.bedwars.game.Game;
|
||||
import rip.tilly.bedwars.game.GameState;
|
||||
import rip.tilly.bedwars.events.PlayerKillEvent;
|
||||
import rip.tilly.bedwars.playerdata.PlayerData;
|
||||
import rip.tilly.bedwars.playerdata.PlayerState;
|
||||
|
||||
public class MovementListener implements Listener {
|
||||
|
||||
private final BedWars plugin = BedWars.getInstance();
|
||||
|
||||
private boolean isInGame(PlayerData playerData) {
|
||||
return playerData.getPlayerState() == PlayerState.PLAYING;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerMove(PlayerMoveEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
if (player.getGameMode() == GameMode.CREATIVE && player.isOp()) {
|
||||
return;
|
||||
}
|
||||
|
||||
PlayerData playerData = this.plugin.getPlayerDataManager().getPlayerData(player.getUniqueId());
|
||||
if (playerData == null) {
|
||||
this.plugin.getLogger().warning(player.getName() + "'s player data is null");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!this.isInGame(playerData)) {
|
||||
return;
|
||||
}
|
||||
|
||||
Game game = this.plugin.getGameManager().getGame(player.getUniqueId());
|
||||
if (game == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
Location to = event.getTo();
|
||||
Location from = event.getFrom();
|
||||
if (to.getX() != from.getX() || to.getZ() != from.getZ()) {
|
||||
if (game.getGameState() == GameState.STARTING) {
|
||||
player.teleport(from);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (from.getBlockY() <= game.getArena().getDeadZone() && game.getGameState() != GameState.ENDING) {
|
||||
Player killer = playerData.getLastDamager();
|
||||
if (killer != null) {
|
||||
this.plugin.getServer().getPluginManager().callEvent(new PlayerKillEvent(player, killer));
|
||||
} else {
|
||||
this.plugin.getServer().getPluginManager().callEvent(new PlayerKillEvent(player, null));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,46 @@
|
||||
package rip.tilly.bedwars.listeners.game;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import rip.tilly.bedwars.BedWars;
|
||||
import rip.tilly.bedwars.events.PlayerKillEvent;
|
||||
import rip.tilly.bedwars.game.Game;
|
||||
import rip.tilly.bedwars.game.GameTeam;
|
||||
import rip.tilly.bedwars.playerdata.PlayerData;
|
||||
import rip.tilly.bedwars.runnables.RespawnRunnable;
|
||||
|
||||
public class PlayerKillListener implements Listener {
|
||||
|
||||
private final BedWars plugin = BedWars.getInstance();
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerKill(PlayerKillEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
Player killer = event.getKiller();
|
||||
|
||||
PlayerData playerData = this.plugin.getPlayerDataManager().getPlayerData(player.getUniqueId());
|
||||
if (playerData == null) {
|
||||
this.plugin.getLogger().warning(player.getName() + "'s player data is null");
|
||||
return;
|
||||
}
|
||||
|
||||
Game game = this.plugin.getGameManager().getGame(player.getUniqueId());
|
||||
if (game == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
GameTeam playerTeam = game.getTeams().get(playerData.getTeamId());
|
||||
if (playerTeam.isHasBed()) {
|
||||
if (killer != null) {
|
||||
PlayerData killerData = this.plugin.getPlayerDataManager().getPlayerData(killer.getUniqueId());
|
||||
game.broadcast(playerData.getPlayerTeam().getChatColor() + player.getName() + " &ewas killed by " + killerData.getPlayerTeam().getChatColor() + killer.getName() + "&e!");
|
||||
} else {
|
||||
game.broadcast(playerData.getPlayerTeam().getChatColor() + player.getName() + " &efell into the void!");
|
||||
}
|
||||
new RespawnRunnable(this.plugin, player, playerData, game, playerTeam, 6, 6).runTaskTimer(this.plugin, 20, 20);
|
||||
} else {
|
||||
this.plugin.getGameManager().removePlayerFromGame(player, playerData, true);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,131 @@
|
||||
package rip.tilly.bedwars.listeners.game;
|
||||
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.block.BlockBreakEvent;
|
||||
import org.bukkit.event.block.BlockPlaceEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import rip.tilly.bedwars.BedWars;
|
||||
import rip.tilly.bedwars.game.Game;
|
||||
import rip.tilly.bedwars.game.GameState;
|
||||
import rip.tilly.bedwars.game.GameTeam;
|
||||
import rip.tilly.bedwars.playerdata.PlayerData;
|
||||
import rip.tilly.bedwars.playerdata.PlayerState;
|
||||
|
||||
public class WorldListener implements Listener {
|
||||
|
||||
private final BedWars plugin = BedWars.getInstance();
|
||||
|
||||
private boolean isInGame(PlayerData playerData) {
|
||||
return playerData.getPlayerState() == PlayerState.PLAYING;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onBlockBreak(BlockBreakEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
if (player.getGameMode() == GameMode.CREATIVE && player.isOp()) {
|
||||
return;
|
||||
}
|
||||
|
||||
PlayerData playerData = this.plugin.getPlayerDataManager().getPlayerData(player.getUniqueId());
|
||||
if (playerData == null) {
|
||||
this.plugin.getLogger().warning(player.getName() + "'s player data is null");
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!this.isInGame(playerData)) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
Game game = this.plugin.getGameManager().getGame(player.getUniqueId());
|
||||
if (game == null) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (game.getGameState() != GameState.FIGHTING) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
Block block = event.getBlock();
|
||||
if (!game.isBreakable(block)) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (block.getType() == Material.BED_BLOCK) {
|
||||
GameTeam playerTeam = game.getTeams().get(playerData.getTeamId());
|
||||
if ((playerTeam.getId() == 1 ? game.getCopiedArena().getA().toBukkitLocation() : game.getCopiedArena().getB().toBukkitLocation()).distance(block.getLocation()) < 20) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
GameTeam opposingTeam = playerData.getTeamId() == 0 ? game.getTeams().get(1) : game.getTeams().get(0);
|
||||
opposingTeam.destroyBed();
|
||||
game.broadcastWithSound(playerTeam.getPlayerTeam().getChatColor() + player.getName() + " &ehas destroyed " + opposingTeam.getPlayerTeam().getChatColor() + opposingTeam.getPlayerTeam().getName() + "'s &ebed!", Sound.ENDERDRAGON_GROWL);
|
||||
game.broadcastSound(Sound.ENDERDRAGON_GROWL);
|
||||
return;
|
||||
}
|
||||
|
||||
player.getInventory().addItem(block.getDrops().toArray(new ItemStack[0]));
|
||||
game.removePlacedBlock(block);
|
||||
block.setType(Material.AIR);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onBlockPlace(BlockPlaceEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
if (player.getGameMode() == GameMode.CREATIVE && player.isOp()) {
|
||||
return;
|
||||
}
|
||||
|
||||
PlayerData playerData = this.plugin.getPlayerDataManager().getPlayerData(player.getUniqueId());
|
||||
if (playerData == null) {
|
||||
this.plugin.getLogger().warning(player.getName() + "'s player data is null");
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!this.isInGame(playerData)) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
Game game = this.plugin.getGameManager().getGame(player.getUniqueId());
|
||||
if (game == null) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (game.getGameState() != GameState.FIGHTING) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
Block block = event.getBlock();
|
||||
if (block.getLocation().getBlockY() >= game.getArena().getBuildMax()) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!game.isPlaceable(block.getLocation(), game)) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (game.isInside(block.getLocation(), game)) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
game.addPlacedBlock(block);
|
||||
}
|
||||
}
|
@ -1,43 +1,56 @@
|
||||
package rip.tilly.bedwars.managers;
|
||||
|
||||
import lombok.Getter;
|
||||
import org.bukkit.Color;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Item;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.potion.PotionEffect;
|
||||
import org.bukkit.potion.PotionEffectType;
|
||||
import rip.tilly.bedwars.BedWars;
|
||||
import rip.tilly.bedwars.game.Game;
|
||||
import rip.tilly.bedwars.game.GameRequest;
|
||||
import rip.tilly.bedwars.game.GameTeam;
|
||||
import rip.tilly.bedwars.game.*;
|
||||
import rip.tilly.bedwars.game.arena.Arena;
|
||||
import rip.tilly.bedwars.game.events.GameEndEvent;
|
||||
import rip.tilly.bedwars.game.events.GameStartEvent;
|
||||
import rip.tilly.bedwars.player.PlayerData;
|
||||
import rip.tilly.bedwars.events.GameEndEvent;
|
||||
import rip.tilly.bedwars.events.GameStartEvent;
|
||||
import rip.tilly.bedwars.managers.hotbar.impl.HotbarItem;
|
||||
import rip.tilly.bedwars.playerdata.PlayerData;
|
||||
import rip.tilly.bedwars.playerdata.PlayerState;
|
||||
import rip.tilly.bedwars.utils.ItemBuilder;
|
||||
import rip.tilly.bedwars.utils.PlayerUtil;
|
||||
import rip.tilly.bedwars.utils.TtlHashMap;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* Created by Lucanius
|
||||
* Project: BedWars
|
||||
*/
|
||||
public class GameManager {
|
||||
|
||||
private final BedWars plugin = BedWars.getInstance();
|
||||
|
||||
private final Map<UUID, Set<GameRequest>> gameRequests = new TtlHashMap<>(TimeUnit.SECONDS, 30);
|
||||
private final Map<UUID, UUID> spectators = new ConcurrentHashMap<>();
|
||||
@Getter private final Map<UUID, Game> games = new ConcurrentHashMap<>();
|
||||
|
||||
public int getFighters() {
|
||||
public int getPlaying() {
|
||||
int i = 0;
|
||||
for (Game game : this.games.values()) {
|
||||
for (GameTeam team : game.getTeams()) {
|
||||
i += team.getPlayingPlayers().size();
|
||||
}
|
||||
}
|
||||
return i;
|
||||
}
|
||||
|
||||
public int getPlayingByType(GameType gameType) {
|
||||
int i = 0;
|
||||
for (Game game : this.games.values()) {
|
||||
if (game.getGameType() == gameType) {
|
||||
for (GameTeam teams : game.getTeams()) {
|
||||
i += teams.getPlayingPlayers().size();
|
||||
}
|
||||
}
|
||||
}
|
||||
return i;
|
||||
}
|
||||
|
||||
@ -80,9 +93,29 @@ public class GameManager {
|
||||
this.games.remove(game.getGameId());
|
||||
}
|
||||
|
||||
public void removePlayerFromGame(Player player, PlayerData playerData) {
|
||||
public void addDroppedItem(Game game, Item item) {
|
||||
game.addEntityToRemove(item);
|
||||
game.addRunnable(this.plugin.getServer().getScheduler().runTaskLater(this.plugin, () -> {
|
||||
game.removeEntityToRemove(item);
|
||||
item.remove();
|
||||
}, 100L).getTaskId());
|
||||
}
|
||||
|
||||
public void addDroppedItems(Game game, Set<Item> items) {
|
||||
for (Item item : items) {
|
||||
game.addEntityToRemove(item);
|
||||
}
|
||||
game.addRunnable(this.plugin.getServer().getScheduler().runTaskLater(this.plugin, () -> {
|
||||
for (Item item : items) {
|
||||
game.removeEntityToRemove(item);
|
||||
item.remove();
|
||||
}
|
||||
}, 100L).getTaskId());
|
||||
}
|
||||
|
||||
public void removePlayerFromGame(Player player, PlayerData playerData, boolean spectatorDeath) {
|
||||
Game game = this.games.get(playerData.getCurrentGameId());
|
||||
Player killer = player.getKiller();
|
||||
Player killer = playerData.getLastDamager();
|
||||
|
||||
if (player.isOnline() && killer != null) {
|
||||
killer.hidePlayer(player);
|
||||
@ -93,15 +126,109 @@ public class GameManager {
|
||||
|
||||
if (killer != null) {
|
||||
game.broadcast(losingTeam.getPlayerTeam().getChatColor() + player.getName() + " &ehas been killed by " + winningTeam.getPlayerTeam().getChatColor() + killer.getName() + "&e! &b&lFINAL KILL!");
|
||||
PlayerData killerData = this.plugin.getPlayerDataManager().getPlayerData(killer.getUniqueId());
|
||||
killerData.setKills(killerData.getKills() + 1);
|
||||
} else {
|
||||
game.broadcast(losingTeam.getPlayerTeam().getChatColor() + player.getName() + " &ehas died! &b&lFINAL KILL!");
|
||||
}
|
||||
|
||||
losingTeam.killPlayer(player.getUniqueId());
|
||||
int remaining = losingTeam.getPlayingPlayers().size();
|
||||
playerData.setDeaths(playerData.getDeaths() + 1);
|
||||
|
||||
losingTeam.killPlayer(player.getUniqueId());
|
||||
|
||||
if (spectatorDeath) {
|
||||
this.addSpectatorDeath(player, playerData, game);
|
||||
}
|
||||
|
||||
int remaining = losingTeam.getPlayingPlayers().size();
|
||||
if (remaining == 0) {
|
||||
this.plugin.getServer().getPluginManager().callEvent(new GameEndEvent(game, winningTeam, losingTeam));
|
||||
}
|
||||
}
|
||||
|
||||
private void addSpectatorDeath(Player player, PlayerData playerData, Game game) {
|
||||
this.spectators.put(player.getUniqueId(), game.getGameId());
|
||||
playerData.setPlayerState(PlayerState.SPECTATING);
|
||||
PlayerUtil.clearPlayer(player);
|
||||
game.addSpectator(player.getUniqueId());
|
||||
game.addRunnable(this.plugin.getServer().getScheduler().scheduleSyncDelayedTask(this.plugin, () -> {
|
||||
game.getTeams().forEach(team -> team.playingPlayers().forEach(member -> member.hidePlayer(player)));
|
||||
game.spectatorPlayers().forEach(spectator -> spectator.hidePlayer(player));
|
||||
player.getActivePotionEffects().stream().map(PotionEffect::getType).forEach(player::removePotionEffect);
|
||||
player.setWalkSpeed(0.2F);
|
||||
player.setFlySpeed(0.4F);
|
||||
player.setAllowFlight(true);
|
||||
}, 20L));
|
||||
|
||||
player.setWalkSpeed(0.0F);
|
||||
player.addPotionEffect(new PotionEffect(PotionEffectType.JUMP, 10000, -5));
|
||||
|
||||
this.plugin.getHotbarManager().getSpectatorItems().stream().filter(HotbarItem::isEnabled).forEach(item -> player.getInventory().setItem(item.getSlot(), item.getItemStack()));
|
||||
player.updateInventory();
|
||||
}
|
||||
|
||||
public void addSpectator(Player player, PlayerData playerData, Player target, Game targetGame) {
|
||||
this.spectators.put(player.getUniqueId(), targetGame.getGameId());
|
||||
|
||||
if (targetGame.getGameState() != GameState.ENDING) {
|
||||
targetGame.broadcast("&d" + player.getName() + " &eis now spectating!");
|
||||
}
|
||||
|
||||
targetGame.addSpectator(player.getUniqueId());
|
||||
playerData.setPlayerState(PlayerState.SPECTATING);
|
||||
|
||||
player.teleport(target);
|
||||
player.setAllowFlight(true);
|
||||
player.setFlying(true);
|
||||
|
||||
player.getInventory().clear();
|
||||
this.plugin.getHotbarManager().getSpectatorItems().stream().filter(HotbarItem::isEnabled).forEach(item -> player.getInventory().setItem(item.getSlot(), item.getItemStack()));
|
||||
player.updateInventory();
|
||||
|
||||
this.plugin.getServer().getOnlinePlayers().forEach(online -> {
|
||||
online.hidePlayer(player);
|
||||
player.hidePlayer(online);
|
||||
});
|
||||
|
||||
targetGame.getTeams().forEach(team -> team.playingPlayers().forEach(player::showPlayer));
|
||||
}
|
||||
|
||||
public void removeSpectator(Player player) {
|
||||
Game game = this.games.get(this.spectators.get(player.getUniqueId()));
|
||||
game.removeSpectator(player.getUniqueId());
|
||||
|
||||
if (game.getGameState() != GameState.ENDING) {
|
||||
game.broadcast("&d" + player.getName() + " &eis no longer spectating!");
|
||||
}
|
||||
|
||||
this.spectators.remove(player.getUniqueId());
|
||||
this.plugin.getPlayerDataManager().resetPlayer(player, true);
|
||||
}
|
||||
|
||||
public List<ItemStack> getGameItems() {
|
||||
List<ItemStack> allItems = new ArrayList<>();
|
||||
|
||||
ItemStack sword = new ItemBuilder(Material.WOOD_SWORD).build();
|
||||
allItems.add(sword);
|
||||
|
||||
return allItems;
|
||||
}
|
||||
|
||||
public ItemStack[] getGameArmor(PlayerData playerData) {
|
||||
Color color = playerData.getPlayerTeam().getColor();
|
||||
|
||||
return new ItemStack[] {
|
||||
new ItemBuilder(Material.LEATHER_BOOTS).color(color).build(),
|
||||
new ItemBuilder(Material.LEATHER_LEGGINGS).color(color).build(),
|
||||
new ItemBuilder(Material.LEATHER_CHESTPLATE).color(color).build(),
|
||||
new ItemBuilder(Material.LEATHER_HELMET).color(color).build()
|
||||
};
|
||||
}
|
||||
|
||||
public void clearBlocks(Game game) {
|
||||
game.getPlacedBlocksLocations().forEach(location -> {
|
||||
location.getBlock().setType(Material.AIR);
|
||||
game.removePlacedBlock(location.getBlock());
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -8,8 +8,8 @@ import org.bson.Document;
|
||||
import org.bukkit.entity.Player;
|
||||
import rip.tilly.bedwars.BedWars;
|
||||
import rip.tilly.bedwars.managers.hotbar.impl.HotbarItem;
|
||||
import rip.tilly.bedwars.player.PlayerData;
|
||||
import rip.tilly.bedwars.player.PlayerState;
|
||||
import rip.tilly.bedwars.playerdata.PlayerData;
|
||||
import rip.tilly.bedwars.playerdata.PlayerState;
|
||||
import rip.tilly.bedwars.utils.PlayerUtil;
|
||||
|
||||
import java.util.Collection;
|
||||
@ -17,10 +17,6 @@ import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* Created by Lucanius
|
||||
* Project: BedWars
|
||||
*/
|
||||
public class PlayerDataManager {
|
||||
|
||||
@Getter private final Map<UUID, PlayerData> players = new HashMap<>();
|
||||
|
@ -8,10 +8,6 @@ import rip.tilly.bedwars.BedWars;
|
||||
import rip.tilly.bedwars.utils.CC;
|
||||
import rip.tilly.bedwars.utils.CustomLocation;
|
||||
|
||||
/**
|
||||
* Created by Lucanius
|
||||
* Project: BedWars
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
public class SpawnManager {
|
||||
|
@ -14,10 +14,6 @@ import rip.tilly.bedwars.utils.config.file.Config;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
|
||||
/**
|
||||
* Created by Lucanius
|
||||
* Project: BedWars
|
||||
*/
|
||||
public class ArenaManager {
|
||||
|
||||
private final BedWars plugin = BedWars.getInstance();
|
||||
|
@ -7,10 +7,6 @@ import rip.tilly.bedwars.game.arena.Arena;
|
||||
import rip.tilly.bedwars.game.arena.CopiedArena;
|
||||
import rip.tilly.bedwars.utils.CustomLocation;
|
||||
|
||||
/**
|
||||
* Created by Lucanius
|
||||
* Project: BedWars
|
||||
*/
|
||||
public class ChunkManager {
|
||||
|
||||
private final BedWars plugin = BedWars.getInstance();
|
||||
|
@ -9,10 +9,6 @@ import rip.tilly.bedwars.utils.ItemUtil;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by Lucanius
|
||||
* Project: BedWars
|
||||
*/
|
||||
@Getter
|
||||
public class HotbarManager {
|
||||
|
||||
|
@ -1,9 +1,5 @@
|
||||
package rip.tilly.bedwars.managers.hotbar.impl;
|
||||
|
||||
/**
|
||||
* Created by Lucanius
|
||||
* Project: BedWars
|
||||
*/
|
||||
public enum ActionType {
|
||||
|
||||
QUEUE_MENU,
|
||||
|
@ -7,10 +7,6 @@ import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by Lucanius
|
||||
* Project: BedWars
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
public class HotbarItem {
|
||||
|
@ -16,10 +16,6 @@ import rip.tilly.bedwars.utils.config.file.Config;
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
/**
|
||||
* Created by Lucanius
|
||||
* Project: BedWars
|
||||
*/
|
||||
@Getter
|
||||
public class MongoManager {
|
||||
|
||||
|
@ -5,8 +5,7 @@ import lombok.Setter;
|
||||
import org.bukkit.entity.Player;
|
||||
import rip.tilly.bedwars.BedWars;
|
||||
import rip.tilly.bedwars.game.GameTeam;
|
||||
import rip.tilly.bedwars.player.PlayerTeam;
|
||||
import sun.misc.UUDecoder;
|
||||
import rip.tilly.bedwars.playerdata.PlayerTeam;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
|
@ -4,8 +4,8 @@ import lombok.Getter;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import rip.tilly.bedwars.BedWars;
|
||||
import rip.tilly.bedwars.player.PlayerData;
|
||||
import rip.tilly.bedwars.player.PlayerState;
|
||||
import rip.tilly.bedwars.playerdata.PlayerData;
|
||||
import rip.tilly.bedwars.playerdata.PlayerState;
|
||||
import rip.tilly.bedwars.utils.CC;
|
||||
import rip.tilly.bedwars.utils.Clickable;
|
||||
import rip.tilly.bedwars.utils.TtlHashMap;
|
||||
@ -75,6 +75,11 @@ public class PartyManager {
|
||||
}
|
||||
|
||||
public void createParty(Player player) {
|
||||
if (this.getParty(player.getUniqueId()) != null) {
|
||||
player.sendMessage(CC.translate("&cYou are already in a party!"));
|
||||
return;
|
||||
}
|
||||
|
||||
Party party = new Party(player.getUniqueId());
|
||||
this.parties.put(player.getUniqueId(), party);
|
||||
this.plugin.getPlayerDataManager().resetPlayer(player, false);
|
||||
@ -101,6 +106,14 @@ public class PartyManager {
|
||||
|
||||
public void joinParty(UUID leader, Player player) {
|
||||
Party party = this.getParty(leader);
|
||||
if (party == null) {
|
||||
player.sendMessage(CC.translate("&cThis party doesn't exist!"));
|
||||
return;
|
||||
}
|
||||
if (!this.hasPartyInvite(player.getUniqueId(), leader)) {
|
||||
player.sendMessage(CC.translate("&cYou have no pending invites!"));
|
||||
return;
|
||||
}
|
||||
this.partyLeaders.put(player.getUniqueId(), leader);
|
||||
party.addMember(player.getUniqueId());
|
||||
this.plugin.getPlayerDataManager().resetPlayer(player, false);
|
||||
@ -110,6 +123,7 @@ public class PartyManager {
|
||||
public void leaveParty(Player player) {
|
||||
Party party = this.getParty(player.getUniqueId());
|
||||
if (party == null) {
|
||||
player.sendMessage(CC.translate("&cYou are not in a party!"));
|
||||
return;
|
||||
}
|
||||
|
||||
@ -124,7 +138,7 @@ public class PartyManager {
|
||||
|
||||
switch (playerData.getPlayerState()) {
|
||||
case PLAYING:
|
||||
this.plugin.getGameManager().removePlayerFromGame(player, playerData);
|
||||
this.plugin.getGameManager().removePlayerFromGame(player, playerData, false);
|
||||
break;
|
||||
case SPECTATING:
|
||||
// this.plugin.getGameManager().removeSpectator(player);
|
||||
|
@ -0,0 +1,12 @@
|
||||
package rip.tilly.bedwars.managers.queue;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import rip.tilly.bedwars.game.GameType;
|
||||
|
||||
@Getter
|
||||
@RequiredArgsConstructor
|
||||
public class QueueEntry {
|
||||
|
||||
private final GameType gameType;
|
||||
}
|
148
src/main/java/rip/tilly/bedwars/managers/queue/QueueManager.java
Normal file
148
src/main/java/rip/tilly/bedwars/managers/queue/QueueManager.java
Normal file
@ -0,0 +1,148 @@
|
||||
package rip.tilly.bedwars.managers.queue;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import rip.tilly.bedwars.BedWars;
|
||||
import rip.tilly.bedwars.game.Game;
|
||||
import rip.tilly.bedwars.game.GameTeam;
|
||||
import rip.tilly.bedwars.game.GameType;
|
||||
import rip.tilly.bedwars.game.arena.Arena;
|
||||
import rip.tilly.bedwars.managers.hotbar.impl.HotbarItem;
|
||||
import rip.tilly.bedwars.playerdata.PlayerData;
|
||||
import rip.tilly.bedwars.playerdata.PlayerState;
|
||||
import rip.tilly.bedwars.playerdata.PlayerTeam;
|
||||
import rip.tilly.bedwars.utils.CC;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
public class QueueManager {
|
||||
|
||||
private final BedWars plugin = BedWars.getInstance();
|
||||
private final Map<UUID, QueueEntry> queued = new ConcurrentHashMap<>();
|
||||
private final Map<UUID, Long> queueTime = new HashMap<>();
|
||||
|
||||
public QueueManager() {
|
||||
this.plugin.getServer().getScheduler().runTaskTimer(this.plugin, () -> this.queued.forEach((key, value) -> {
|
||||
this.findMatch(this.plugin.getServer().getPlayer(key), value.getGameType());
|
||||
}), 20, 20);
|
||||
}
|
||||
|
||||
public void addPlayerToQueue(Player player, PlayerData playerData, GameType gameType) {
|
||||
playerData.setPlayerState(PlayerState.QUEUE);
|
||||
|
||||
QueueEntry queueEntry = new QueueEntry(gameType);
|
||||
this.queued.put(playerData.getUniqueId(), queueEntry);
|
||||
this.giveQueueItems(player);
|
||||
|
||||
player.sendMessage(" ");
|
||||
player.sendMessage(CC.translate("&d&l" + gameType.getName() + " Queue"));
|
||||
player.sendMessage(CC.translate("&7&oSearching for a game..."));
|
||||
player.sendMessage(" ");
|
||||
|
||||
this.queueTime.put(player.getUniqueId(), System.currentTimeMillis());
|
||||
}
|
||||
|
||||
public void removePlayerFromQueue(Player player) {
|
||||
if (player == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
QueueEntry entry = this.queued.get(player.getUniqueId());
|
||||
if (entry == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.plugin.getPlayerDataManager().resetPlayer(player, false);
|
||||
this.queued.remove(player.getUniqueId());
|
||||
|
||||
player.sendMessage(CC.translate("&cYou have left the queue!"));
|
||||
}
|
||||
|
||||
private void findMatch(Player player, GameType gameType) {
|
||||
if (player == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
PlayerData playerData = this.plugin.getPlayerDataManager().getPlayerData(player.getUniqueId());
|
||||
if (playerData == null) {
|
||||
this.plugin.getLogger().warning(player.getName() + "'s player data is null");
|
||||
return;
|
||||
}
|
||||
|
||||
for (UUID opponent : this.queued.keySet()) {
|
||||
if (opponent == player.getUniqueId()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
QueueEntry queueEntry = this.queued.get(opponent);
|
||||
if (queueEntry.getGameType() != gameType) {
|
||||
continue;
|
||||
}
|
||||
|
||||
Player opponentPlayer = Bukkit.getPlayer(opponent);
|
||||
|
||||
List<UUID> playersA = new ArrayList<>();
|
||||
List<UUID> playersB = new ArrayList<>();
|
||||
|
||||
playersA.add(player.getUniqueId());
|
||||
playersB.add(opponent);
|
||||
|
||||
GameTeam teamA = new GameTeam(player.getUniqueId(), playersA, 0, PlayerTeam.RED);
|
||||
GameTeam teamB = new GameTeam(player.getUniqueId(), playersB, 1, PlayerTeam.LIME);
|
||||
|
||||
Arena arena = this.plugin.getArenaManager().getRandomArena();
|
||||
|
||||
if (this.getQueueSizeByType(gameType) >= gameType.getQueueAmount()) {
|
||||
|
||||
player.sendMessage(" ");
|
||||
player.sendMessage(CC.translate("&aGame found!"));
|
||||
player.sendMessage(CC.translate("&7⚫ &fOpponent: &d" + opponentPlayer.getName()));
|
||||
//player.sendMessage(CC.translate("&7⚫ &fArena: &d" + arena.getName()));
|
||||
player.sendMessage(CC.translate("&7⚫ &fGame: &d" + gameType.getName()));
|
||||
player.sendMessage(" ");
|
||||
|
||||
opponentPlayer.sendMessage(" ");
|
||||
opponentPlayer.sendMessage(CC.translate("&aGame found!"));
|
||||
opponentPlayer.sendMessage(CC.translate("&7⚫ &fOpponent: &d" + player.getName()));
|
||||
//opponentPlayer.sendMessage(CC.translate("&7⚫ &fArena: &d" + arena.getName()));
|
||||
opponentPlayer.sendMessage(CC.translate("&7⚫ &fGame: &d" + gameType.getName()));
|
||||
opponentPlayer.sendMessage(" ");
|
||||
|
||||
Game game = new Game(arena, gameType, teamA, teamB);
|
||||
this.plugin.getGameManager().createGame(game);
|
||||
|
||||
this.queued.remove(player.getUniqueId());
|
||||
this.queued.remove(opponentPlayer.getUniqueId());
|
||||
|
||||
this.queueTime.remove(player.getUniqueId());
|
||||
this.queueTime.remove(opponentPlayer.getUniqueId());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void giveQueueItems(Player player) {
|
||||
player.closeInventory();
|
||||
player.getInventory().clear();
|
||||
|
||||
this.plugin.getHotbarManager().getQueueItems().stream().filter(HotbarItem::isEnabled).forEach(item -> player.getInventory().setItem(item.getSlot(), item.getItemStack()));
|
||||
|
||||
player.updateInventory();
|
||||
}
|
||||
|
||||
public QueueEntry getQueueEntry(UUID uuid) {
|
||||
return this.queued.get(uuid);
|
||||
}
|
||||
|
||||
public long getPlayerQueueTime(UUID uuid) {
|
||||
return this.queueTime.get(uuid);
|
||||
}
|
||||
|
||||
public int getQueueSizeByType(GameType type) {
|
||||
return (int) this.queued.entrySet().stream().filter(entry -> entry.getValue().getGameType() == type).count();
|
||||
}
|
||||
|
||||
public int getAllQueueSize() {
|
||||
return this.queued.entrySet().size();
|
||||
}
|
||||
}
|
4
src/main/java/rip/tilly/bedwars/menus/e.java
Normal file
4
src/main/java/rip/tilly/bedwars/menus/e.java
Normal file
@ -0,0 +1,4 @@
|
||||
package rip.tilly.bedwars.menus;
|
||||
|
||||
public class e {
|
||||
}
|
80
src/main/java/rip/tilly/bedwars/menus/queue/QueueMenu.java
Normal file
80
src/main/java/rip/tilly/bedwars/menus/queue/QueueMenu.java
Normal file
@ -0,0 +1,80 @@
|
||||
package rip.tilly.bedwars.menus.queue;
|
||||
|
||||
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.game.GameType;
|
||||
import rip.tilly.bedwars.utils.CC;
|
||||
import rip.tilly.bedwars.utils.ItemBuilder;
|
||||
import rip.tilly.bedwars.utils.menu.Button;
|
||||
import rip.tilly.bedwars.utils.menu.Menu;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class QueueMenu extends Menu {
|
||||
|
||||
@Override
|
||||
public boolean isUpdateAfterClick() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTitle(Player player) {
|
||||
return CC.translate("&eSelect a game to play...");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<Integer, Button> getButtons(Player player) {
|
||||
Map<Integer, Button> buttons = new HashMap<>();
|
||||
|
||||
for (GameType type : GameType.values()) {
|
||||
buttons.put(type.getSlot(), new QueueButton("&d&l" + type.getName(), type.getLore(), type, type.getMaterial(), type.getData()));
|
||||
}
|
||||
|
||||
fillEmptySlots(buttons, new ItemBuilder(Material.STAINED_GLASS_PANE).durability(7).name(" ").build());
|
||||
|
||||
return buttons;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSize() {
|
||||
return 3 * 9;
|
||||
}
|
||||
|
||||
@AllArgsConstructor
|
||||
private class QueueButton extends Button {
|
||||
|
||||
private final String name;
|
||||
private final List<String> lore;
|
||||
private final GameType gameType;
|
||||
private final Material material;
|
||||
private final int data;
|
||||
|
||||
@Override
|
||||
public ItemStack getButtonItem(Player player) {
|
||||
List<String> loreList = new ArrayList<>(lore);
|
||||
loreList.add(" ");
|
||||
loreList.add("&fPlaying: &b" + BedWars.getInstance().getGameManager().getPlayingByType(gameType));
|
||||
|
||||
return new ItemBuilder(material)
|
||||
.name(name)
|
||||
.durability(data)
|
||||
.amount(BedWars.getInstance().getGameManager().getPlayingByType(gameType) > 0 ? BedWars.getInstance().getGameManager().getPlayingByType(gameType) : 1)
|
||||
.lore(loreList)
|
||||
.hideFlags()
|
||||
.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clicked(Player player, int slot, ClickType clickType, int hotbarButton) {
|
||||
BedWars.getInstance().getQueueManager().addPlayerToQueue(player, BedWars.getInstance().getPlayerDataManager().getPlayerData(player.getUniqueId()), gameType);
|
||||
playNeutral(player);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,12 +0,0 @@
|
||||
package rip.tilly.bedwars.player;
|
||||
|
||||
/**
|
||||
* Created by Lucanius
|
||||
* Project: BedWars
|
||||
*/
|
||||
public enum PlayerState {
|
||||
SPAWN,
|
||||
QUEUE,
|
||||
PLAYING,
|
||||
SPECTATING
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
package rip.tilly.bedwars.player;
|
||||
package rip.tilly.bedwars.playerdata;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
@ -8,10 +8,6 @@ import rip.tilly.bedwars.managers.PlayerDataManager;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* Created by Lucanius
|
||||
* Project: BedWars
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
public class PlayerData {
|
||||
@ -38,6 +34,7 @@ public class PlayerData {
|
||||
private int gamesPlayed;
|
||||
|
||||
private Player lastDamager;
|
||||
private int gameKills;
|
||||
|
||||
public PlayerData(UUID uniqueId) {
|
||||
this.uniqueId = uniqueId;
|
@ -1,4 +1,4 @@
|
||||
package rip.tilly.bedwars.player;
|
||||
package rip.tilly.bedwars.playerdata;
|
||||
|
||||
import lombok.Data;
|
||||
|
@ -0,0 +1,9 @@
|
||||
package rip.tilly.bedwars.playerdata;
|
||||
|
||||
public enum PlayerState {
|
||||
SPAWN,
|
||||
QUEUE,
|
||||
PLAYING,
|
||||
RESPAWNING,
|
||||
SPECTATING
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
package rip.tilly.bedwars.player;
|
||||
package rip.tilly.bedwars.playerdata;
|
||||
|
||||
import lombok.Getter;
|
||||
import org.bukkit.ChatColor;
|
||||
@ -6,10 +6,6 @@ import org.bukkit.Color;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* Created by Lucanius
|
||||
* Project: BedWars
|
||||
*/
|
||||
@Getter
|
||||
public enum PlayerTeam {
|
||||
|
@ -2,10 +2,13 @@ package rip.tilly.bedwars.providers.scoreboard;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import rip.tilly.bedwars.managers.party.Party;
|
||||
import rip.tilly.bedwars.managers.queue.QueueEntry;
|
||||
import rip.tilly.bedwars.playerdata.PlayerState;
|
||||
import rip.tilly.bedwars.utils.TimeUtils;
|
||||
import rip.tilly.bedwars.utils.assemble.AssembleAdapter;
|
||||
import org.bukkit.entity.Player;
|
||||
import rip.tilly.bedwars.BedWars;
|
||||
import rip.tilly.bedwars.player.PlayerData;
|
||||
import rip.tilly.bedwars.playerdata.PlayerData;
|
||||
import rip.tilly.bedwars.utils.CC;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@ -30,6 +33,7 @@ public class ScoreboardProvider implements AssembleAdapter {
|
||||
|
||||
switch (playerData.getPlayerState()) {
|
||||
case SPAWN:
|
||||
case QUEUE:
|
||||
return this.spawnScoreboard(playerData);
|
||||
case PLAYING:
|
||||
return null;
|
||||
@ -43,10 +47,8 @@ public class ScoreboardProvider implements AssembleAdapter {
|
||||
private List<String> spawnScoreboard(PlayerData playerData) {
|
||||
List<String> lines = new ArrayList<String>();
|
||||
|
||||
boolean inParty = this.main.getPartyManager().getParty(playerData.getUniqueId()) != null;
|
||||
|
||||
lines.add(CC.scoreboardBar);
|
||||
|
||||
boolean inParty = this.main.getPartyManager().getParty(playerData.getUniqueId()) != null;
|
||||
if (inParty) {
|
||||
Party party = this.main.getPartyManager().getParty(playerData.getUniqueId());
|
||||
lines.add("&9Party Leader: &d" + Bukkit.getPlayer(party.getLeader()).getName());
|
||||
@ -55,34 +57,40 @@ public class ScoreboardProvider implements AssembleAdapter {
|
||||
}
|
||||
|
||||
lines.add("&fOnline: &d" + this.main.getServer().getOnlinePlayers().size());
|
||||
lines.add("&fPlaying: &d" + this.main.getGameManager().getFighters());
|
||||
lines.add(" ");
|
||||
lines.add("&fPlaying: &d" + this.main.getGameManager().getPlaying());
|
||||
|
||||
if (true) {
|
||||
lines.add("&fLevel: &d" + playerData.getLevel());
|
||||
|
||||
String finishedProgress = "";
|
||||
|
||||
int notFinishedProgress = 10;
|
||||
|
||||
for (int i = 0; i < playerData.getXp() * 100; i++) {
|
||||
if (i % 10 == 0) {
|
||||
finishedProgress += "⬛";
|
||||
|
||||
notFinishedProgress--;
|
||||
}
|
||||
if (playerData.getPlayerState() == PlayerState.QUEUE) {
|
||||
QueueEntry queueEntry = this.main.getQueueManager().getQueueEntry(playerData.getUniqueId());
|
||||
if (queueEntry != null) {
|
||||
long queueTime = System.currentTimeMillis() - (this.main.getQueueManager().getPlayerQueueTime(playerData.getUniqueId()));
|
||||
String formattedQueueTime = TimeUtils.formatIntoMMSS(Math.round(queueTime / 1000L));
|
||||
lines.add(CC.scoreboardBar);
|
||||
lines.add("&e" + queueEntry.getGameType().getName() + " Queue");
|
||||
lines.add("&fTime: &d" + formattedQueueTime);
|
||||
}
|
||||
|
||||
String leftOverProgress = "";
|
||||
|
||||
for (int i = 1; i <= notFinishedProgress; i++) {
|
||||
leftOverProgress += "⬛";
|
||||
}
|
||||
|
||||
lines.add("&8" + finishedProgress + "&7" + leftOverProgress + " &7(" + ((int) (playerData.getXp() * 100)) + "%&7)");
|
||||
lines.add(" ");
|
||||
}
|
||||
|
||||
lines.add(" ");
|
||||
|
||||
lines.add("&fLevel: &d" + playerData.getLevel());
|
||||
String finishedProgress = "";
|
||||
int notFinishedProgress = 10;
|
||||
for (int i = 0; i < playerData.getXp() * 100; i++) {
|
||||
if (i % 10 == 0) {
|
||||
finishedProgress += "⬛";
|
||||
|
||||
notFinishedProgress--;
|
||||
}
|
||||
}
|
||||
|
||||
String leftOverProgress = "";
|
||||
for (int i = 1; i <= notFinishedProgress; i++) {
|
||||
leftOverProgress += "⬛";
|
||||
}
|
||||
|
||||
lines.add("&8" + finishedProgress + "&7" + leftOverProgress + " &7(" + ((int) (playerData.getXp() * 100)) + "%&7)");
|
||||
|
||||
lines.add(" ");
|
||||
lines.add("&dtilly.rip");
|
||||
lines.add(CC.scoreboardBar);
|
||||
|
||||
|
49
src/main/java/rip/tilly/bedwars/runnables/GameRunnable.java
Normal file
49
src/main/java/rip/tilly/bedwars/runnables/GameRunnable.java
Normal file
@ -0,0 +1,49 @@
|
||||
package rip.tilly.bedwars.runnables;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
import rip.tilly.bedwars.BedWars;
|
||||
import rip.tilly.bedwars.game.Game;
|
||||
import rip.tilly.bedwars.game.GameState;
|
||||
|
||||
@RequiredArgsConstructor
|
||||
public class GameRunnable extends BukkitRunnable {
|
||||
|
||||
private final BedWars plugin = BedWars.getInstance();
|
||||
private final Game game;
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
switch (this.game.getGameState()) {
|
||||
case STARTING:
|
||||
if (this.game.decrementCountdown() == 0) {
|
||||
this.game.setGameState(GameState.FIGHTING);
|
||||
this.game.broadcastWithSound("&aThe match has started, good luck!", Sound.FIREWORK_BLAST);
|
||||
} else {
|
||||
this.game.broadcastWithSound("&eStarting match in &d" + this.game.getCountdown() + " &eseconds...", Sound.NOTE_PLING);
|
||||
this.game.broadcastTitle("&d&lStarting Match In...", "&e" + this.game.getCountdown());
|
||||
}
|
||||
break;
|
||||
case FIGHTING:
|
||||
this.game.incrementDuration();
|
||||
break;
|
||||
case ENDING:
|
||||
if (this.game.decrementCountdown() == 0) {
|
||||
this.game.getEntitiesToRemove().forEach(Entity::remove);
|
||||
this.game.getRunnables().forEach(runnable -> this.plugin.getServer().getScheduler().cancelTask(runnable));
|
||||
this.game.getTeams().forEach(team -> team.playingPlayers().forEach(player -> this.plugin.getPlayerDataManager().resetPlayer(player, true)));
|
||||
this.game.spectatorPlayers().forEach(this.plugin.getGameManager()::removeSpectator);
|
||||
|
||||
this.plugin.getChunkClearingManager().resetArena(this.game.getCopiedArena());
|
||||
this.game.getArena().addAvailableArena(this.game.getCopiedArena());
|
||||
this.plugin.getArenaManager().removeArenaGameUUID(this.game.getCopiedArena());
|
||||
|
||||
this.plugin.getGameManager().removeGame(this.game);
|
||||
this.cancel();
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,85 @@
|
||||
package rip.tilly.bedwars.runnables;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
import org.bukkit.util.Vector;
|
||||
import org.github.paperspigot.Title;
|
||||
import rip.tilly.bedwars.BedWars;
|
||||
import rip.tilly.bedwars.game.Game;
|
||||
import rip.tilly.bedwars.game.GameTeam;
|
||||
import rip.tilly.bedwars.playerdata.PlayerData;
|
||||
import rip.tilly.bedwars.playerdata.PlayerState;
|
||||
import rip.tilly.bedwars.utils.CC;
|
||||
|
||||
@AllArgsConstructor
|
||||
public class RespawnRunnable extends BukkitRunnable {
|
||||
|
||||
private final BedWars plugin;
|
||||
private final Player player;
|
||||
private final PlayerData playerData;
|
||||
private final Game game;
|
||||
private final GameTeam gameTeam;
|
||||
private final int startingTime;
|
||||
private int respawnTime;
|
||||
|
||||
private boolean isInGame(PlayerData playerData) {
|
||||
return playerData.getPlayerState() == PlayerState.PLAYING;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
if (!this.isInGame(this.playerData)) {
|
||||
cancel();
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.respawnTime <= 1) {
|
||||
this.playerData.setPlayerState(PlayerState.PLAYING);
|
||||
this.game.getTeams().forEach(team -> team.playingPlayers().forEach(gamePlayer -> gamePlayer.showPlayer(this.player)));
|
||||
this.player.teleport(this.gameTeam.getId() == 1 ? this.game.getCopiedArena().getA().toBukkitLocation() : this.game.getCopiedArena().getB().toBukkitLocation());
|
||||
|
||||
this.player.sendTitle(new Title(CC.translate("&aRespawning..."), "", 1, 20, 0));
|
||||
this.player.sendMessage(CC.translate("&aYou have respawned!"));
|
||||
this.player.playSound(this.player.getLocation(), Sound.ORB_PICKUP, 10F, 1F);
|
||||
|
||||
for (ItemStack stack : this.plugin.getGameManager().getGameItems()) {
|
||||
this.player.getInventory().addItem(stack);
|
||||
}
|
||||
|
||||
this.game.getTeams().forEach(team -> team.playingPlayers().filter(player1 -> !this.player.equals(player1))
|
||||
.forEach(matchplayer -> matchplayer.sendMessage(CC.translate(this.gameTeam.getPlayerTeam().getChatColor() + this.player.getName() + " &ehas respawned!"))));
|
||||
|
||||
this.player.setHealth(this.player.getMaxHealth());
|
||||
this.player.setFoodLevel(20);
|
||||
this.playerData.setLastDamager(null);
|
||||
|
||||
cancel();
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.respawnTime == this.startingTime) {
|
||||
this.playerData.setPlayerState(PlayerState.RESPAWNING);
|
||||
this.game.getTeams().forEach(team -> team.playingPlayers().forEach(gamePlayer -> gamePlayer.hidePlayer(this.player)));
|
||||
|
||||
this.player.getInventory().clear();
|
||||
this. player.updateInventory();
|
||||
|
||||
this.player.setHealth(this.player.getMaxHealth());
|
||||
this.player.setFoodLevel(20);
|
||||
|
||||
this. player.setVelocity(this.player.getVelocity().add(new Vector(0, 0.25, 0)));
|
||||
this.player.setAllowFlight(true);
|
||||
this.player.setFlying(true);
|
||||
this.player.setVelocity(this.player.getVelocity().add(new Vector(0, 0.15, 0)));
|
||||
this. player.setAllowFlight(true);
|
||||
this. player.setFlying(true);
|
||||
}
|
||||
|
||||
this.respawnTime--;
|
||||
this.player.sendTitle(new Title(CC.translate("&e" + this.respawnTime), " ", 5, 20, 5));
|
||||
this.player.playSound(this.player.getLocation(), Sound.NOTE_PLING, 0.7F, 1.0F);
|
||||
}
|
||||
}
|
@ -5,10 +5,6 @@ import org.bukkit.ChatColor;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by Lucanius
|
||||
* Project: BedWars
|
||||
*/
|
||||
public class CC {
|
||||
|
||||
public static final String scoreboardBar = ChatColor.GRAY.toString() + ChatColor.STRIKETHROUGH + "----------------------";
|
||||
|
@ -128,7 +128,7 @@ public class ItemBuilder implements Listener {
|
||||
|
||||
public ItemBuilder hideFlags() {
|
||||
final ItemMeta meta = is.getItemMeta();
|
||||
meta.addItemFlags(ItemFlag.HIDE_POTION_EFFECTS, ItemFlag.HIDE_UNBREAKABLE, ItemFlag.HIDE_ATTRIBUTES);
|
||||
meta.addItemFlags(ItemFlag.HIDE_POTION_EFFECTS, ItemFlag.HIDE_UNBREAKABLE, ItemFlag.HIDE_ATTRIBUTES, ItemFlag.HIDE_ENCHANTS);
|
||||
is.setItemMeta(meta);
|
||||
|
||||
return this;
|
||||
|
52
src/main/java/rip/tilly/bedwars/utils/menu/Button.java
Normal file
52
src/main/java/rip/tilly/bedwars/utils/menu/Button.java
Normal file
@ -0,0 +1,52 @@
|
||||
package rip.tilly.bedwars.utils.menu;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.inventory.ClickType;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
public abstract class Button {
|
||||
|
||||
public static Button placeholder(final Material material, final byte data, String... title) {
|
||||
return (new Button() {
|
||||
public ItemStack getButtonItem(Player player) {
|
||||
ItemStack it = new ItemStack(material, 1, data);
|
||||
ItemMeta meta = it.getItemMeta();
|
||||
|
||||
meta.setDisplayName(StringUtils.join(title));
|
||||
it.setItemMeta(meta);
|
||||
|
||||
return it;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static void playFail(Player player) {
|
||||
player.playSound(player.getLocation(), Sound.DIG_GRASS, 20F, 0.1F);
|
||||
}
|
||||
|
||||
public static void playSuccess(Player player) {
|
||||
player.playSound(player.getLocation(), Sound.NOTE_PIANO, 20F, 15F);
|
||||
}
|
||||
|
||||
public static void playNeutral(Player player) {
|
||||
player.playSound(player.getLocation(), Sound.CLICK, 20F, 1F);
|
||||
}
|
||||
|
||||
public abstract ItemStack getButtonItem(Player player);
|
||||
|
||||
public void clicked(Player player, int slot, ClickType clickType, int hotbarButton) {
|
||||
|
||||
}
|
||||
|
||||
public boolean shouldCancel(Player player, int slot, ClickType clickType) {
|
||||
return (true);
|
||||
}
|
||||
|
||||
public boolean shouldUpdate(Player player, int slot, ClickType clickType) {
|
||||
return (false);
|
||||
}
|
||||
}
|
150
src/main/java/rip/tilly/bedwars/utils/menu/Menu.java
Normal file
150
src/main/java/rip/tilly/bedwars/utils/menu/Menu.java
Normal file
@ -0,0 +1,150 @@
|
||||
package rip.tilly.bedwars.utils.menu;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
import rip.tilly.bedwars.BedWars;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@Getter @Setter
|
||||
public abstract class Menu {
|
||||
|
||||
public static Map<String, Menu> currentlyOpenedMenus = new HashMap<>();
|
||||
@Getter private Map<Integer, Button> buttons = new HashMap<>();
|
||||
|
||||
private boolean autoUpdate = false;
|
||||
private boolean updateAfterClick = true;
|
||||
private boolean closedByMenu = false;
|
||||
private boolean placeholder = false;
|
||||
|
||||
private Button placeholderButton = Button.placeholder(Material.STAINED_GLASS_PANE, (byte) 7, " ");
|
||||
private BukkitTask task;
|
||||
|
||||
private ItemStack createItemStack(Player player, Button button) {
|
||||
ItemStack item = button.getButtonItem(player);
|
||||
if (item.getType() != Material.SKULL) {
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
if (meta != null && meta.hasDisplayName()) {
|
||||
meta.setDisplayName(meta.getDisplayName() + "§b§c§d§e");
|
||||
}
|
||||
item.setItemMeta(meta);
|
||||
}
|
||||
|
||||
return item;
|
||||
}
|
||||
|
||||
public void openMenu(final Player player) {
|
||||
this.buttons = this.getButtons(player);
|
||||
|
||||
Menu previousMenu = Menu.currentlyOpenedMenus.get(player.getName());
|
||||
Inventory inventory = null;
|
||||
int size = this.getSize() == -1 ? this.size(this.buttons) : this.getSize();
|
||||
boolean update = false;
|
||||
String title = this.getTitle(player);
|
||||
|
||||
if (title.length() > 32) {
|
||||
title = title.substring(0, 32);
|
||||
}
|
||||
|
||||
if (player.getOpenInventory() != null) {
|
||||
if (previousMenu == null) {
|
||||
player.closeInventory();
|
||||
} else {
|
||||
int previousSize = player.getOpenInventory().getTopInventory().getSize();
|
||||
|
||||
if (previousSize == size && player.getOpenInventory().getTopInventory().getTitle().equals(title)) {
|
||||
inventory = player.getOpenInventory().getTopInventory();
|
||||
update = true;
|
||||
} else {
|
||||
previousMenu.setClosedByMenu(true);
|
||||
player.closeInventory();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (inventory == null) {
|
||||
inventory = Bukkit.createInventory(player, size, title);
|
||||
}
|
||||
|
||||
inventory.setContents(new ItemStack[inventory.getSize()]);
|
||||
|
||||
currentlyOpenedMenus.put(player.getName(), this);
|
||||
|
||||
for (Map.Entry<Integer, Button> buttonEntry : this.buttons.entrySet()) {
|
||||
inventory.setItem(buttonEntry.getKey(), createItemStack(player, buttonEntry.getValue()));
|
||||
}
|
||||
|
||||
if (this.isPlaceholder()) {
|
||||
for (int index = 0; index < size; index++) {
|
||||
if (this.buttons.get(index) == null) {
|
||||
this.buttons.put(index, this.placeholderButton);
|
||||
inventory.setItem(index, this.placeholderButton.getButtonItem(player));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (update) {
|
||||
player.updateInventory();
|
||||
} else {
|
||||
player.openInventory(inventory);
|
||||
}
|
||||
|
||||
this.setClosedByMenu(false);
|
||||
if (autoUpdate && task == null) {
|
||||
task = BedWars.getInstance().getServer().getScheduler().runTaskTimer(BedWars.getInstance(), () -> this.openMenu(player), 0, 20L);
|
||||
}
|
||||
}
|
||||
|
||||
public int size(Map<Integer, Button> buttons) {
|
||||
int highest = 0;
|
||||
|
||||
for (int buttonValue : buttons.keySet()) {
|
||||
if (buttonValue > highest) {
|
||||
highest = buttonValue;
|
||||
}
|
||||
}
|
||||
|
||||
return (int) (Math.ceil((highest + 1) / 9D) * 9D);
|
||||
}
|
||||
|
||||
public int getSlot(int x, int y) {
|
||||
return ((9 * y) + x);
|
||||
}
|
||||
|
||||
public int getSize() {
|
||||
return -1;
|
||||
}
|
||||
|
||||
public abstract String getTitle(Player player);
|
||||
|
||||
public abstract Map<Integer, Button> getButtons(Player player);
|
||||
|
||||
public void onClose(Player player) {
|
||||
if (task != null) {
|
||||
task.cancel();
|
||||
}
|
||||
}
|
||||
|
||||
public void fillEmptySlots(Map<Integer, Button> buttons, ItemStack itemStack) {
|
||||
int bound = getSize();
|
||||
|
||||
for (int slot = 0; slot < bound; slot++) {
|
||||
if (buttons.get(slot) == null) {
|
||||
buttons.put(slot, new Button() {
|
||||
@Override
|
||||
public ItemStack getButtonItem(Player player) {
|
||||
return itemStack;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user