├── config.yml ├── .gitignore ├── src └── com │ └── scarabcoder │ └── gameapi │ ├── util │ ├── ScarabUtil.java │ ├── LocationUtil.java │ └── ScoreboardUtil.java │ ├── event │ ├── npc │ │ └── NPCInteractEvent.java │ ├── PlayerLeaveAreaEvent.java │ ├── PlayerEnterAreaEvent.java │ ├── gui │ │ ├── InventoryButtonClickEvent.java │ │ └── InventoryGUIEvent.java │ ├── GameEndEvent.java │ ├── GameStartEvent.java │ ├── PlayerLeaveGameEvent.java │ ├── PlayerJoinGameEvent.java │ ├── AreaEvent.java │ ├── AutoTeamCompensationEvent.java │ ├── PlayerKillPlayerEvent.java │ └── PlayerDamagePlayerEvent.java │ ├── enums │ ├── GamePlayerType.java │ ├── GameStatus.java │ ├── PlayerJoinLimitAction.java │ ├── TeamSpreadType.java │ └── DefaultFontInfo.java │ ├── npc │ ├── NPC.java │ └── NPCManager.java │ ├── manager │ ├── TeamManager.java │ ├── GameManager.java │ ├── PlayerManager.java │ └── ArenaManager.java │ ├── listener │ ├── PlayerQuitListener.java │ ├── PlayerJoinListener.java │ ├── ServerPingListener.java │ ├── InventoryListener.java │ ├── PlayerMovementListener.java │ ├── PlayerPvPListener.java │ └── SettingsListener.java │ ├── gui │ ├── GUIManager.java │ └── InventoryGUI.java │ ├── GameAPI.java │ └── game │ ├── Team.java │ ├── GamePlayer.java │ ├── Area.java │ ├── Arena.java │ ├── GameSettings.java │ ├── ArenaSettings.java │ └── Game.java ├── plugin.yml └── README.md /config.yml: -------------------------------------------------------------------------------- 1 | debug: false 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | bin/ 2 | .settings/ 3 | .classpath 4 | .project 5 | -------------------------------------------------------------------------------- /src/com/scarabcoder/gameapi/util/ScarabUtil.java: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/scarabcoder/GameAPI/HEAD/src/com/scarabcoder/gameapi/util/ScarabUtil.java -------------------------------------------------------------------------------- /src/com/scarabcoder/gameapi/event/npc/NPCInteractEvent.java: -------------------------------------------------------------------------------- 1 | package com.scarabcoder.gameapi.event.npc; 2 | 3 | public class NPCInteractEvent { 4 | 5 | } 6 | -------------------------------------------------------------------------------- /src/com/scarabcoder/gameapi/enums/GamePlayerType.java: -------------------------------------------------------------------------------- 1 | package com.scarabcoder.gameapi.enums; 2 | 3 | public enum GamePlayerType { 4 | SPECTATOR, PLAYER 5 | } 6 | -------------------------------------------------------------------------------- /src/com/scarabcoder/gameapi/enums/GameStatus.java: -------------------------------------------------------------------------------- 1 | package com.scarabcoder.gameapi.enums; 2 | 3 | public enum GameStatus { 4 | WAITING, INGAME, RESTARTING 5 | } 6 | -------------------------------------------------------------------------------- /src/com/scarabcoder/gameapi/enums/PlayerJoinLimitAction.java: -------------------------------------------------------------------------------- 1 | package com.scarabcoder.gameapi.enums; 2 | 3 | public enum PlayerJoinLimitAction { 4 | KICK, LOBBY, SPECTATOR, DISALLOW 5 | } 6 | -------------------------------------------------------------------------------- /plugin.yml: -------------------------------------------------------------------------------- 1 | name: GameAPI 2 | version: 0.1.0 Beta 3 | author: Nicholas Harris (ScarabCoder) 4 | description: An API for developers to use when developing minigames. 5 | main: com.scarabcoder.gameapi.GameAPI 6 | -------------------------------------------------------------------------------- /src/com/scarabcoder/gameapi/npc/NPC.java: -------------------------------------------------------------------------------- 1 | package com.scarabcoder.gameapi.npc; 2 | 3 | public class NPC { 4 | 5 | public NPC(Animals entity){ 6 | this.entity = entity; 7 | this.allowAIMovement = false; 8 | this.invincible = true; 9 | } 10 | 11 | public Entity getEntity(){ 12 | return this.entity; 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /src/com/scarabcoder/gameapi/enums/TeamSpreadType.java: -------------------------------------------------------------------------------- 1 | package com.scarabcoder.gameapi.enums; 2 | 3 | public enum TeamSpreadType { 4 | /** 5 | * Will select random team if both teams are even, otherwise the team with less players. 6 | */ 7 | EVEN, 8 | /** 9 | * Will fill first team, then when full second team, and so on. 10 | */ 11 | FIRST_AVAILABLE 12 | } 13 | -------------------------------------------------------------------------------- /src/com/scarabcoder/gameapi/event/PlayerLeaveAreaEvent.java: -------------------------------------------------------------------------------- 1 | package com.scarabcoder.gameapi.event; 2 | 3 | import com.scarabcoder.gameapi.game.Area; 4 | import com.scarabcoder.gameapi.game.GamePlayer; 5 | 6 | public class PlayerLeaveAreaEvent extends AreaEvent { 7 | 8 | public PlayerLeaveAreaEvent(GamePlayer player, Area area) { 9 | super(player, area); 10 | } 11 | 12 | } 13 | -------------------------------------------------------------------------------- /src/com/scarabcoder/gameapi/event/PlayerEnterAreaEvent.java: -------------------------------------------------------------------------------- 1 | package com.scarabcoder.gameapi.event; 2 | 3 | import com.scarabcoder.gameapi.game.Area; 4 | import com.scarabcoder.gameapi.game.GamePlayer; 5 | 6 | public class PlayerEnterAreaEvent extends AreaEvent { 7 | 8 | public PlayerEnterAreaEvent(GamePlayer player, Area area) { 9 | super(player, area); 10 | } 11 | 12 | 13 | 14 | 15 | } 16 | -------------------------------------------------------------------------------- /src/com/scarabcoder/gameapi/npc/NPCManager.java: -------------------------------------------------------------------------------- 1 | package com.scarabcoder.gameapi.npc; 2 | 3 | public class NPCManager { 4 | 5 | /*private static HashMap npcs = new HashMap(); 6 | 7 | 8 | 9 | public static boolean isNPC(Entity entity){ 10 | return npcs.get(entity.getUniqueId()) != null; 11 | } 12 | 13 | public static void storeNPC(NPC npc){ 14 | npcs.put(npc.getEntity().getUniqueId(), npc); 15 | } 16 | 17 | public static NPC getNPC(Entity entity){ 18 | return npcs.get(entity.getUniqueId()); 19 | }*/ 20 | 21 | } 22 | -------------------------------------------------------------------------------- /src/com/scarabcoder/gameapi/util/LocationUtil.java: -------------------------------------------------------------------------------- 1 | package com.scarabcoder.gameapi.util; 2 | 3 | import org.bukkit.Location; 4 | 5 | public class LocationUtil { 6 | 7 | public static boolean isInArea(Location l, Location l1, Location l2){ 8 | 9 | double x1 = Math.min(l1.getX(), l2.getX()); 10 | double y1 = Math.min(l1.getY(), l2.getY()); 11 | double z1 = Math.min(l1.getZ(), l2.getZ()); 12 | 13 | double x2 = Math.max(l1.getX(), l2.getX()); 14 | double y2 = Math.max(l1.getY(), l2.getY()); 15 | double z2 = Math.max(l1.getZ(), l2.getZ()); 16 | 17 | if(l.getX() >= x1 && l.getX() <= x2 && 18 | l.getY() >= y1 && l.getY() <= y2 && 19 | l.getZ() >= z1 && l.getZ() <= z2){ 20 | return true; 21 | } 22 | 23 | 24 | 25 | return false; 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /src/com/scarabcoder/gameapi/event/gui/InventoryButtonClickEvent.java: -------------------------------------------------------------------------------- 1 | package com.scarabcoder.gameapi.event.gui; 2 | 3 | import org.bukkit.inventory.ItemStack; 4 | 5 | import com.scarabcoder.gameapi.game.GamePlayer; 6 | import com.scarabcoder.gameapi.gui.InventoryGUI; 7 | 8 | public class InventoryButtonClickEvent extends InventoryGUIEvent { 9 | 10 | private String buttonID; 11 | private ItemStack stack; 12 | 13 | 14 | public InventoryButtonClickEvent(InventoryGUI gui, GamePlayer player, String buttonID, ItemStack stack) { 15 | super(gui, player); 16 | this.buttonID = buttonID; 17 | this.stack = stack; 18 | } 19 | 20 | public ItemStack getItemStack(){ 21 | return this.stack; 22 | } 23 | 24 | public String getButtonID(){ 25 | return this.buttonID; 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /src/com/scarabcoder/gameapi/manager/TeamManager.java: -------------------------------------------------------------------------------- 1 | package com.scarabcoder.gameapi.manager; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | import com.scarabcoder.gameapi.game.Team; 7 | 8 | public class TeamManager { 9 | 10 | private List teams = new ArrayList(); 11 | 12 | public TeamManager(){ 13 | 14 | } 15 | 16 | public void registerTeam(Team team){ 17 | this.teams.add(team); 18 | } 19 | 20 | public void registerTeams(Team...teams ){ 21 | for(Team team : teams){ 22 | this.teams.add(team); 23 | } 24 | } 25 | public Team getTeam(String name){ 26 | for(Team team : teams){ 27 | if(team.getName().equals(name)) return team; 28 | } 29 | return null; 30 | } 31 | 32 | public List getTeams(){ 33 | return this.teams; 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /src/com/scarabcoder/gameapi/listener/PlayerQuitListener.java: -------------------------------------------------------------------------------- 1 | package com.scarabcoder.gameapi.listener; 2 | 3 | import org.bukkit.event.EventHandler; 4 | import org.bukkit.event.Listener; 5 | import org.bukkit.event.player.PlayerQuitEvent; 6 | 7 | import com.scarabcoder.gameapi.game.GamePlayer; 8 | import com.scarabcoder.gameapi.manager.PlayerManager; 9 | 10 | public class PlayerQuitListener implements Listener { 11 | 12 | @EventHandler 13 | public void playerQuit(PlayerQuitEvent e){ 14 | GamePlayer player = PlayerManager.getGamePlayer(e.getPlayer()); 15 | if(player.getGame() != null){ 16 | if(player.getGame().getGameSettings().shouldDisableVanillaJoinLeaveMessages()){ 17 | e.setQuitMessage(""); 18 | } 19 | if(player.getGame().getGameSettings().shouldLeavePlayerOnDisconnect()){ 20 | player.getGame().removePlayer(player); 21 | } 22 | } 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /src/com/scarabcoder/gameapi/event/gui/InventoryGUIEvent.java: -------------------------------------------------------------------------------- 1 | package com.scarabcoder.gameapi.event.gui; 2 | 3 | import org.bukkit.event.Event; 4 | import org.bukkit.event.HandlerList; 5 | 6 | import com.scarabcoder.gameapi.game.GamePlayer; 7 | import com.scarabcoder.gameapi.gui.InventoryGUI; 8 | 9 | public class InventoryGUIEvent extends Event { 10 | 11 | private static HandlerList handlers = new HandlerList(); 12 | private InventoryGUI gui; 13 | private GamePlayer player; 14 | 15 | public InventoryGUIEvent(InventoryGUI gui, GamePlayer player){ 16 | this.gui = gui; 17 | this.player = player; 18 | } 19 | 20 | public InventoryGUI getInventoryGUI(){ 21 | return this.gui; 22 | } 23 | 24 | public GamePlayer getPlayer(){ 25 | return this.player; 26 | } 27 | 28 | @Override 29 | public HandlerList getHandlers() { 30 | return handlers; 31 | } 32 | 33 | public static HandlerList getHandlerList(){ 34 | return handlers; 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /src/com/scarabcoder/gameapi/util/ScoreboardUtil.java: -------------------------------------------------------------------------------- 1 | package com.scarabcoder.gameapi.util; 2 | 3 | import java.util.Arrays; 4 | import java.util.List; 5 | 6 | import org.bukkit.Bukkit; 7 | import org.bukkit.scoreboard.DisplaySlot; 8 | import org.bukkit.scoreboard.Objective; 9 | import org.bukkit.scoreboard.Scoreboard; 10 | 11 | public class ScoreboardUtil { 12 | 13 | public static Scoreboard createScoreboard(String title, String...strings){ 14 | return createScoreboard(title, Arrays.asList(strings)); 15 | } 16 | 17 | public static Scoreboard createScoreboard(String title, List strings){ 18 | Scoreboard s = Bukkit.getScoreboardManager().getNewScoreboard(); 19 | Objective obj = s.registerNewObjective(title, "dummy"); 20 | obj.setDisplaySlot(DisplaySlot.SIDEBAR); 21 | obj.setDisplayName(title); 22 | for(int x = strings.size() - 1; x != -1; x--){ 23 | obj.getScore(strings.get(x)).setScore(strings.size() - x); 24 | } 25 | return s; 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /src/com/scarabcoder/gameapi/gui/GUIManager.java: -------------------------------------------------------------------------------- 1 | package com.scarabcoder.gameapi.gui; 2 | 3 | import java.util.HashMap; 4 | import java.util.UUID; 5 | 6 | import org.bukkit.inventory.Inventory; 7 | 8 | public class GUIManager { 9 | 10 | private static HashMap guis = new HashMap(); 11 | 12 | protected static void registerGUI(InventoryGUI gui){ 13 | guis.put(gui.getID(), gui); 14 | } 15 | 16 | public static InventoryGUI getGUI(String id){ 17 | return guis.get(UUID.fromString(id)); 18 | } 19 | 20 | public static InventoryGUI getGUI(UUID id){ 21 | return guis.get(id); 22 | } 23 | 24 | public static InventoryGUI getGUI(Inventory inv){ 25 | for(UUID guiID : guis.keySet()){ 26 | InventoryGUI gui = guis.get(guiID); 27 | if(gui.getInventory().equals(inv)){ 28 | return gui; 29 | } 30 | } 31 | return null; 32 | } 33 | 34 | public static boolean isGUI(Inventory inv){ 35 | return getGUI(inv) != null; 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /src/com/scarabcoder/gameapi/manager/GameManager.java: -------------------------------------------------------------------------------- 1 | package com.scarabcoder.gameapi.manager; 2 | 3 | import java.util.ArrayList; 4 | import java.util.HashMap; 5 | import java.util.Iterator; 6 | import java.util.List; 7 | 8 | import com.scarabcoder.gameapi.GameAPI; 9 | import com.scarabcoder.gameapi.game.Game; 10 | 11 | public class GameManager { 12 | 13 | private static HashMap games = new HashMap(); 14 | 15 | public static void registerGame(Game game){ 16 | games.put(game.getID(), game); 17 | GameAPI.logInfo(game.getRegisteringPlugin().getName() + " registered game " + game.getID() + "."); 18 | 19 | } 20 | 21 | public static List getGames(){ 22 | List games = new ArrayList(); 23 | Iterator gIt = GameManager.games.values().iterator(); 24 | while(gIt.hasNext()){ 25 | games.add(gIt.next()); 26 | } 27 | return games; 28 | } 29 | 30 | public static Game getGame(String ID){ 31 | return games.get(ID); 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /src/com/scarabcoder/gameapi/manager/PlayerManager.java: -------------------------------------------------------------------------------- 1 | package com.scarabcoder.gameapi.manager; 2 | 3 | import java.util.HashMap; 4 | import java.util.UUID; 5 | 6 | import org.bukkit.OfflinePlayer; 7 | 8 | import com.scarabcoder.gameapi.game.GamePlayer; 9 | 10 | public class PlayerManager { 11 | 12 | private static HashMap playerMap = new HashMap(); 13 | 14 | /** 15 | * Get the GamePlayer given a Bukkit Player. GamePlayers are initiated once per server session, and are saved whether or not a player is online. 16 | * @param player 17 | * @return GamePlayer, should never be null 18 | */ 19 | public static GamePlayer getGamePlayer(OfflinePlayer player){ 20 | GamePlayer pl = null; 21 | if(playerMap.containsKey(player.getUniqueId())){ 22 | pl = playerMap.get(player.getUniqueId()); 23 | }else{ 24 | GamePlayer gpl = new GamePlayer(player); 25 | playerMap.put(player.getUniqueId(), gpl); 26 | pl = gpl; 27 | } 28 | return pl; 29 | } 30 | 31 | 32 | } 33 | -------------------------------------------------------------------------------- /src/com/scarabcoder/gameapi/event/GameEndEvent.java: -------------------------------------------------------------------------------- 1 | package com.scarabcoder.gameapi.event; 2 | 3 | import org.bukkit.event.Event; 4 | import org.bukkit.event.HandlerList; 5 | import org.bukkit.plugin.RegisteredListener; 6 | 7 | import com.scarabcoder.gameapi.game.Game; 8 | 9 | public class GameEndEvent extends Event { 10 | 11 | private static final HandlerList handlers = new HandlerList(); 12 | private Game game; 13 | 14 | public GameEndEvent(Game game){ 15 | this.game = game; 16 | } 17 | 18 | /** 19 | * Get the game this event refers to. 20 | * @return Game 21 | */ 22 | public Game getGame(){ 23 | return game; 24 | } 25 | 26 | @Override 27 | public HandlerList getHandlers() { 28 | for(RegisteredListener listener : handlers.getRegisteredListeners()){ 29 | if(!listener.getPlugin().equals(game.getRegisteringPlugin())){ 30 | handlers.unregister(listener); 31 | } 32 | } 33 | return handlers; 34 | } 35 | 36 | public static HandlerList getHandlerList(){ 37 | return handlers; 38 | } 39 | 40 | 41 | } 42 | -------------------------------------------------------------------------------- /src/com/scarabcoder/gameapi/event/GameStartEvent.java: -------------------------------------------------------------------------------- 1 | package com.scarabcoder.gameapi.event; 2 | 3 | import org.bukkit.event.Event; 4 | import org.bukkit.event.HandlerList; 5 | import org.bukkit.plugin.RegisteredListener; 6 | 7 | import com.scarabcoder.gameapi.game.Game; 8 | 9 | public class GameStartEvent extends Event { 10 | 11 | private static final HandlerList handlers = new HandlerList(); 12 | private Game game; 13 | 14 | public GameStartEvent(Game game){ 15 | this.game = game; 16 | } 17 | 18 | /** 19 | * Get the game this event refers to. 20 | * @return Game 21 | */ 22 | public Game getGame(){ 23 | return this.game; 24 | } 25 | 26 | @Override 27 | public HandlerList getHandlers() { 28 | for(RegisteredListener listener : handlers.getRegisteredListeners()){ 29 | if(!listener.getPlugin().equals(game.getRegisteringPlugin())){ 30 | handlers.unregister(listener); 31 | } 32 | } 33 | return handlers; 34 | } 35 | 36 | public static HandlerList getHandlerList(){ 37 | return handlers; 38 | } 39 | 40 | } 41 | -------------------------------------------------------------------------------- /src/com/scarabcoder/gameapi/listener/PlayerJoinListener.java: -------------------------------------------------------------------------------- 1 | package com.scarabcoder.gameapi.listener; 2 | 3 | import org.bukkit.event.EventHandler; 4 | import org.bukkit.event.Listener; 5 | import org.bukkit.event.player.PlayerJoinEvent; 6 | 7 | import com.scarabcoder.gameapi.game.Game; 8 | import com.scarabcoder.gameapi.game.GamePlayer; 9 | import com.scarabcoder.gameapi.manager.GameManager; 10 | import com.scarabcoder.gameapi.manager.PlayerManager; 11 | 12 | public class PlayerJoinListener implements Listener{ 13 | 14 | @EventHandler 15 | public void playerJoin(PlayerJoinEvent e){ 16 | GamePlayer player = PlayerManager.getGamePlayer(e.getPlayer()); 17 | player.setPlayer(e.getPlayer()); 18 | 19 | for(Game game : GameManager.getGames()){ 20 | 21 | 22 | if(game.getGameSettings().usesBungee()){ 23 | 24 | game.addPlayer(player); 25 | 26 | break; 27 | } 28 | } 29 | if(player.getGame().getGameSettings().shouldDisableVanillaJoinLeaveMessages()){ 30 | e.setJoinMessage(""); 31 | } 32 | 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /src/com/scarabcoder/gameapi/listener/ServerPingListener.java: -------------------------------------------------------------------------------- 1 | package com.scarabcoder.gameapi.listener; 2 | 3 | import org.apache.commons.lang3.StringUtils; 4 | import org.bukkit.event.EventHandler; 5 | import org.bukkit.event.Listener; 6 | import org.bukkit.event.server.ServerListPingEvent; 7 | 8 | import com.scarabcoder.gameapi.game.Game; 9 | import com.scarabcoder.gameapi.manager.GameManager; 10 | 11 | public class ServerPingListener implements Listener { 12 | 13 | @EventHandler 14 | public void onServerListPing(ServerListPingEvent e){ 15 | boolean motdSet = false; 16 | boolean playerCountSet = false; 17 | for(Game g : GameManager.getGames()){ 18 | if(g.getGameSettings().doesSetMOTD() && !motdSet){ 19 | e.setMotd(StringUtils.capitalize(StringUtils.lowerCase(g.getGameStatus().toString()))); 20 | motdSet = true; 21 | } 22 | if(g.getGameSettings().doesSetListPlayerCount() && !playerCountSet){ 23 | e.setMaxPlayers(g.getGameSettings().getMaximumPlayers()); 24 | playerCountSet = true; 25 | } 26 | 27 | } 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /src/com/scarabcoder/gameapi/event/PlayerLeaveGameEvent.java: -------------------------------------------------------------------------------- 1 | package com.scarabcoder.gameapi.event; 2 | 3 | import org.bukkit.event.Event; 4 | import org.bukkit.event.HandlerList; 5 | import org.bukkit.plugin.RegisteredListener; 6 | 7 | import com.scarabcoder.gameapi.game.Game; 8 | import com.scarabcoder.gameapi.game.GamePlayer; 9 | 10 | public class PlayerLeaveGameEvent extends Event { 11 | private static final HandlerList handlers = new HandlerList(); 12 | 13 | private GamePlayer player; 14 | private Game game; 15 | 16 | public PlayerLeaveGameEvent(GamePlayer player, Game game){ 17 | this.player = player; 18 | this.game = game; 19 | } 20 | 21 | public GamePlayer getPlayer(){ 22 | return this.player; 23 | } 24 | 25 | public Game getGame(){ 26 | return this.game; 27 | } 28 | 29 | @Override 30 | public HandlerList getHandlers() { 31 | for(RegisteredListener listener : handlers.getRegisteredListeners()){ 32 | if(!listener.getPlugin().equals(game.getRegisteringPlugin())){ 33 | handlers.unregister(listener); 34 | } 35 | } 36 | return handlers; 37 | } 38 | 39 | public static HandlerList getHandlerList(){ 40 | return handlers; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/com/scarabcoder/gameapi/listener/InventoryListener.java: -------------------------------------------------------------------------------- 1 | package com.scarabcoder.gameapi.listener; 2 | 3 | import org.bukkit.Bukkit; 4 | import org.bukkit.OfflinePlayer; 5 | import org.bukkit.event.EventHandler; 6 | import org.bukkit.event.Listener; 7 | import org.bukkit.event.inventory.InventoryClickEvent; 8 | 9 | import com.scarabcoder.gameapi.event.gui.InventoryButtonClickEvent; 10 | import com.scarabcoder.gameapi.game.GamePlayer; 11 | import com.scarabcoder.gameapi.gui.GUIManager; 12 | import com.scarabcoder.gameapi.gui.InventoryGUI; 13 | import com.scarabcoder.gameapi.manager.PlayerManager; 14 | 15 | public class InventoryListener implements Listener { 16 | 17 | @EventHandler 18 | public void onInventoryClick(InventoryClickEvent e){ 19 | if(GUIManager.isGUI(e.getClickedInventory())){ 20 | InventoryGUI gui = GUIManager.getGUI(e.getClickedInventory()); 21 | if(gui.isButton(e.getSlot())){ 22 | GamePlayer p = PlayerManager.getGamePlayer((OfflinePlayer) e.getWhoClicked()); 23 | InventoryButtonClickEvent ev = new InventoryButtonClickEvent(gui, p, gui.getButtonID(e.getSlot()), e.getCurrentItem()); 24 | Bukkit.getPluginManager().callEvent(ev); 25 | } 26 | } 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /src/com/scarabcoder/gameapi/event/PlayerJoinGameEvent.java: -------------------------------------------------------------------------------- 1 | package com.scarabcoder.gameapi.event; 2 | 3 | import org.bukkit.event.Event; 4 | import org.bukkit.event.HandlerList; 5 | 6 | import com.scarabcoder.gameapi.enums.GamePlayerType; 7 | import com.scarabcoder.gameapi.game.Game; 8 | import com.scarabcoder.gameapi.game.GamePlayer; 9 | 10 | public class PlayerJoinGameEvent extends Event { 11 | 12 | private static final HandlerList handlers = new HandlerList(); 13 | 14 | private GamePlayer player; 15 | private Game game; 16 | private GamePlayerType type; 17 | 18 | public PlayerJoinGameEvent(GamePlayer player, Game game){ 19 | this.player = player; 20 | this.game = game; 21 | this.type = GamePlayerType.PLAYER; 22 | } 23 | 24 | public void setGamePlayerType(GamePlayerType type){ 25 | this.type = type; 26 | } 27 | 28 | public GamePlayerType getGamePlayerType(){ 29 | return this.type; 30 | } 31 | 32 | public GamePlayer getPlayer(){ 33 | return this.player; 34 | } 35 | 36 | public Game getGame(){ 37 | return this.game; 38 | } 39 | 40 | public HandlerList getHandlers() { 41 | 42 | 43 | return handlers; 44 | } 45 | 46 | public static HandlerList getHandlerList(){ 47 | return handlers; 48 | } 49 | 50 | } 51 | -------------------------------------------------------------------------------- /src/com/scarabcoder/gameapi/event/AreaEvent.java: -------------------------------------------------------------------------------- 1 | package com.scarabcoder.gameapi.event; 2 | 3 | import org.bukkit.event.Cancellable; 4 | import org.bukkit.event.Event; 5 | import org.bukkit.event.HandlerList; 6 | import org.bukkit.plugin.RegisteredListener; 7 | 8 | import com.scarabcoder.gameapi.game.Area; 9 | import com.scarabcoder.gameapi.game.GamePlayer; 10 | 11 | public class AreaEvent extends Event implements Cancellable { 12 | 13 | private boolean cancelled = false; 14 | private static final HandlerList handlers = new HandlerList(); 15 | private GamePlayer player; 16 | private Area area; 17 | 18 | 19 | public AreaEvent(GamePlayer player, Area area){ 20 | this.player = player; 21 | this.area = area; 22 | } 23 | 24 | public GamePlayer getPlayer(){ 25 | return this.player; 26 | } 27 | 28 | public Area getArea(){ 29 | return this.area; 30 | } 31 | 32 | @Override 33 | public boolean isCancelled() { 34 | return cancelled; 35 | } 36 | 37 | @Override 38 | public void setCancelled(boolean cancelled) { 39 | this.cancelled = cancelled; 40 | } 41 | 42 | @Override 43 | public HandlerList getHandlers() { 44 | for(RegisteredListener listener : handlers.getRegisteredListeners()){ 45 | if(!listener.getPlugin().equals(player.getGame().getRegisteringPlugin())){ 46 | handlers.unregister(listener); 47 | } 48 | } 49 | return handlers; 50 | } 51 | public static HandlerList getHandlerList(){ 52 | return handlers; 53 | } 54 | 55 | } 56 | -------------------------------------------------------------------------------- /src/com/scarabcoder/gameapi/event/AutoTeamCompensationEvent.java: -------------------------------------------------------------------------------- 1 | package com.scarabcoder.gameapi.event; 2 | 3 | import org.bukkit.event.Cancellable; 4 | import org.bukkit.event.Event; 5 | import org.bukkit.event.HandlerList; 6 | 7 | import com.scarabcoder.gameapi.game.Game; 8 | import com.scarabcoder.gameapi.game.GamePlayer; 9 | import com.scarabcoder.gameapi.game.Team; 10 | 11 | public class AutoTeamCompensationEvent extends Event implements Cancellable{ 12 | 13 | public static final HandlerList handlers = new HandlerList(); 14 | private boolean cancelled = false; 15 | 16 | private Team from; 17 | private Team to; 18 | private Game game; 19 | private GamePlayer player; 20 | 21 | public AutoTeamCompensationEvent(Team from, Team to, GamePlayer player, Game game){ 22 | this.from = from; 23 | this.to = to; 24 | this.player = player; 25 | this.game = game; 26 | } 27 | 28 | public Team getFrom(){ 29 | return this.from; 30 | } 31 | 32 | public Team getTo(){ 33 | return this.to; 34 | } 35 | 36 | public GamePlayer getPlayer(){ 37 | return this.player; 38 | } 39 | 40 | public Game getGame(){ 41 | return this.game; 42 | } 43 | 44 | @Override 45 | public HandlerList getHandlers() { 46 | return handlers; 47 | } 48 | 49 | public static HandlerList getHandlerList(){ 50 | return handlers; 51 | } 52 | 53 | @Override 54 | public boolean isCancelled() { 55 | return cancelled; 56 | } 57 | 58 | @Override 59 | public void setCancelled(boolean cancel) { 60 | this.cancelled = cancel; 61 | } 62 | 63 | } 64 | -------------------------------------------------------------------------------- /src/com/scarabcoder/gameapi/gui/InventoryGUI.java: -------------------------------------------------------------------------------- 1 | package com.scarabcoder.gameapi.gui; 2 | 3 | import java.util.HashMap; 4 | import java.util.UUID; 5 | 6 | import org.bukkit.Bukkit; 7 | import org.bukkit.inventory.Inventory; 8 | import org.bukkit.inventory.ItemStack; 9 | 10 | import com.scarabcoder.gameapi.game.GamePlayer; 11 | 12 | public class InventoryGUI { 13 | 14 | private int rowAmount = 0; 15 | private Inventory inventory; 16 | private UUID id; 17 | private HashMap btns = new HashMap(); 18 | 19 | public InventoryGUI(String title){ 20 | this.id = UUID.randomUUID(); 21 | GUIManager.registerGUI(this); 22 | if(this.rowAmount == 0) this.rowAmount = 6; 23 | this.inventory = Bukkit.createInventory(null, rowAmount * 9, title); 24 | 25 | } 26 | 27 | public void open(GamePlayer player){ 28 | if(player.isOnline()){ 29 | player.getOnlinePlayer().openInventory(this.inventory); 30 | } 31 | } 32 | 33 | public void setButton(String id, int slot, ItemStack button){ 34 | this.inventory.setItem(slot, button); 35 | this.btns.put(slot, id); 36 | } 37 | 38 | public InventoryGUI(int rowAmount, String title){ 39 | this(title); 40 | this.rowAmount = rowAmount; 41 | } 42 | 43 | public UUID getID(){ 44 | return this.id; 45 | } 46 | 47 | public Inventory getInventory(){ 48 | return this.inventory; 49 | } 50 | 51 | public String getButtonID(int slot){ 52 | return btns.get(slot); 53 | } 54 | 55 | public boolean isButton(int slot){ 56 | return getButtonID(slot) != null; 57 | } 58 | 59 | } 60 | -------------------------------------------------------------------------------- /src/com/scarabcoder/gameapi/event/PlayerKillPlayerEvent.java: -------------------------------------------------------------------------------- 1 | package com.scarabcoder.gameapi.event; 2 | 3 | import org.bukkit.event.Cancellable; 4 | import org.bukkit.event.Event; 5 | import org.bukkit.event.HandlerList; 6 | import org.bukkit.plugin.RegisteredListener; 7 | 8 | import com.scarabcoder.gameapi.game.Game; 9 | import com.scarabcoder.gameapi.game.GamePlayer; 10 | 11 | public class PlayerKillPlayerEvent extends Event implements Cancellable{ 12 | 13 | private boolean cancelled = false; 14 | 15 | private static final HandlerList handlers = new HandlerList(); 16 | 17 | private GamePlayer killer; 18 | private GamePlayer killed; 19 | private Game game; 20 | 21 | public PlayerKillPlayerEvent(GamePlayer killer, GamePlayer killed, Game game){ 22 | this.killer = killer; 23 | this.killed = killed; 24 | this.game = game; 25 | } 26 | 27 | public GamePlayer getKiller(){ 28 | return this.killer; 29 | } 30 | 31 | public GamePlayer getKilled(){ 32 | return this.killed; 33 | } 34 | 35 | public Game getGame(){ 36 | return this.game; 37 | } 38 | 39 | @Override 40 | public boolean isCancelled() { 41 | return cancelled; 42 | } 43 | 44 | @Override 45 | public void setCancelled(boolean cancel) { 46 | this.cancelled = cancel; 47 | } 48 | 49 | @Override 50 | public HandlerList getHandlers() { 51 | for(RegisteredListener listener : handlers.getRegisteredListeners()){ 52 | if(!listener.getPlugin().equals(game.getRegisteringPlugin())){ 53 | handlers.unregister(listener); 54 | } 55 | } 56 | return handlers; 57 | } 58 | 59 | public static HandlerList getHandlerList(){ 60 | return handlers; 61 | } 62 | 63 | } 64 | -------------------------------------------------------------------------------- /src/com/scarabcoder/gameapi/event/PlayerDamagePlayerEvent.java: -------------------------------------------------------------------------------- 1 | package com.scarabcoder.gameapi.event; 2 | 3 | import org.bukkit.event.Cancellable; 4 | import org.bukkit.event.Event; 5 | import org.bukkit.event.HandlerList; 6 | import org.bukkit.plugin.RegisteredListener; 7 | 8 | import com.scarabcoder.gameapi.game.Game; 9 | import com.scarabcoder.gameapi.game.GamePlayer; 10 | 11 | public class PlayerDamagePlayerEvent extends Event implements Cancellable { 12 | 13 | private boolean cancelled = false; 14 | private static final HandlerList handlers = new HandlerList(); 15 | 16 | private GamePlayer damager; 17 | private GamePlayer damaged; 18 | private Game game; 19 | 20 | public PlayerDamagePlayerEvent(GamePlayer damager, GamePlayer damaged, Game game){ 21 | this.damaged = damaged; 22 | this.damager = damager; 23 | this.game = game; 24 | } 25 | 26 | public GamePlayer getDamager(){ 27 | return this.damager; 28 | } 29 | 30 | public GamePlayer getDamaged(){ 31 | return this.damaged; 32 | } 33 | 34 | public Game getGame(){ 35 | return this.game; 36 | } 37 | 38 | @Override 39 | public boolean isCancelled() { 40 | return cancelled; 41 | } 42 | 43 | @Override 44 | public void setCancelled(boolean cancel) { 45 | this.cancelled = cancel; 46 | } 47 | 48 | @Override 49 | public HandlerList getHandlers() { 50 | for(RegisteredListener listener : handlers.getRegisteredListeners()){ 51 | if(!listener.getPlugin().equals(game.getRegisteringPlugin())){ 52 | handlers.unregister(listener); 53 | } 54 | } 55 | return handlers; 56 | } 57 | 58 | public static HandlerList getHandlerList(){ 59 | return handlers; 60 | } 61 | 62 | 63 | 64 | } 65 | -------------------------------------------------------------------------------- /src/com/scarabcoder/gameapi/listener/PlayerMovementListener.java: -------------------------------------------------------------------------------- 1 | package com.scarabcoder.gameapi.listener; 2 | 3 | import org.bukkit.Bukkit; 4 | import org.bukkit.Location; 5 | import org.bukkit.event.EventHandler; 6 | import org.bukkit.event.Listener; 7 | import org.bukkit.event.player.PlayerMoveEvent; 8 | 9 | import com.scarabcoder.gameapi.event.AreaEvent; 10 | import com.scarabcoder.gameapi.event.PlayerEnterAreaEvent; 11 | import com.scarabcoder.gameapi.event.PlayerLeaveAreaEvent; 12 | import com.scarabcoder.gameapi.game.Area; 13 | import com.scarabcoder.gameapi.game.GamePlayer; 14 | import com.scarabcoder.gameapi.manager.PlayerManager; 15 | import com.scarabcoder.gameapi.util.LocationUtil; 16 | 17 | public class PlayerMovementListener implements Listener { 18 | 19 | @EventHandler 20 | public void onPlayerMove(PlayerMoveEvent e){ 21 | GamePlayer player = PlayerManager.getGamePlayer(e.getPlayer()); 22 | if(player.isInGame()){ 23 | for(Area area : player.getGame().getAreas()){ 24 | Location f = e.getFrom(); 25 | Location t = e.getTo(); 26 | Location l1 = area.getLocation1(); 27 | Location l2 = area.getLocation2(); 28 | boolean fromIsIn = false; 29 | boolean toIsIn = false; 30 | if(LocationUtil.isInArea(f, l1, l2)){ 31 | fromIsIn = true; 32 | } 33 | if(LocationUtil.isInArea(t, l1, l2)){ 34 | toIsIn = true; 35 | } 36 | AreaEvent ev = null; 37 | if(fromIsIn && !toIsIn){ 38 | ev = new PlayerLeaveAreaEvent(player, area); 39 | }else if(!fromIsIn && toIsIn){ 40 | ev = new PlayerEnterAreaEvent(player, area); 41 | } 42 | if(ev != null){ 43 | Bukkit.getPluginManager().callEvent(ev); 44 | e.setCancelled(ev.isCancelled()); 45 | } 46 | } 47 | } 48 | } 49 | 50 | } 51 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # This API is abandoned 2 | If it wasn't already obvious from the inactivity for 4+ years, this project is abandoned for now. I may remake it in Kotlin, along with some other projects, so stay tuned. 3 | 4 | # Latest: Release 0.1.0 5 | ## Beta: indev 0.1.0 6 | 7 | GameAPI is a plugin-library used for Spigot plugins. Simply put, you no longer have to code common things in minigames like teams or arena management. It allows the developer to concentrate on the minigame itself, with some extra utilities not included in the Spigot API. 8 | 9 | ## Example 10 | Create and configure a game. 11 | ```Java 12 | Arena myGameArena = new Arena("myworld"); //Set the arena, with a string parameter for the world name 13 | myGameArena.setLobbySpawn(arena.getWorld().getSpawnLocation)); //Set the lobby spawn, for pre-game waiting. 14 | 15 | Game myGame = new Game("MyGame", myGameArena, MyPlugin.getPlugin()); //Create the game object 16 | myGame.setPrefix("[" + ChatColor.AQUA + "My Game" + ChatColor.RESET + "]"); //Set the prefix used in messages 17 | 18 | ArenaSettings mySettings = myGameArena.getArenaSettings(); //Get arena settings 19 | mySettings.setCanDestroy(false); //Don't allow block breaking 20 | mySettings.setCanBuild(false); //Don't allow block placing 21 | mySettings.setAllowItemDrop(false); //Don't allow players to drop items 22 | ``` 23 | 24 | The above is all it takes to start a game. What takes 8 lines of code in the onEnable() event here normally takes 150+ lines and multiple files without the library. 25 | One of the most powerful features (excluding team management) of GameAPI are the ArenaSettings. Instead of listening for blockDestroy/Build/ItemDrop events and cancelling, you can simply set the settings for the game arena. The boring task of listening for many events is now achieved with a few single lines. 26 | 27 | ArenaSettings are the tip of the iceberg, however. If you wanted to set properties for for only a single area, you can define Areas with their own set of utility events and ArenaSettings. 28 | 29 | For more on how to get started with the GameAPI library, check out the GitHub wiki. 30 | -------------------------------------------------------------------------------- /src/com/scarabcoder/gameapi/listener/PlayerPvPListener.java: -------------------------------------------------------------------------------- 1 | package com.scarabcoder.gameapi.listener; 2 | 3 | import org.bukkit.Bukkit; 4 | import org.bukkit.OfflinePlayer; 5 | import org.bukkit.entity.Arrow; 6 | import org.bukkit.entity.Player; 7 | import org.bukkit.event.EventHandler; 8 | import org.bukkit.event.Listener; 9 | import org.bukkit.event.entity.EntityDamageByEntityEvent; 10 | 11 | import com.scarabcoder.gameapi.event.PlayerDamagePlayerEvent; 12 | import com.scarabcoder.gameapi.event.PlayerKillPlayerEvent; 13 | import com.scarabcoder.gameapi.game.GamePlayer; 14 | import com.scarabcoder.gameapi.manager.PlayerManager; 15 | 16 | public class PlayerPvPListener implements Listener { 17 | 18 | 19 | @EventHandler 20 | public void playerDamagePlayer(EntityDamageByEntityEvent e){ 21 | GamePlayer player = null; 22 | GamePlayer damager = null; 23 | if(e.getEntity() instanceof Player && (e.getDamager() instanceof Arrow || e.getDamager() instanceof Player)){ 24 | player = PlayerManager.getGamePlayer((Player) e.getEntity()); 25 | if(e.getDamager() instanceof Arrow){ 26 | Arrow arrow = (Arrow) e.getDamager(); 27 | if(arrow.getShooter() instanceof Player){ 28 | damager = PlayerManager.getGamePlayer((OfflinePlayer) arrow.getShooter()); 29 | } 30 | }else{ 31 | damager = PlayerManager.getGamePlayer((Player) e.getDamager()); 32 | } 33 | } 34 | if(player != null && damager != null){ 35 | if(player.isInGame() && damager.isInGame()){ 36 | if( 37 | !e.isCancelled() && 38 | player.getGame().equals(damager.getGame())){ 39 | if((player.getOnlinePlayer().getHealth() - e.getFinalDamage() <= 0)){ 40 | PlayerKillPlayerEvent ev = new PlayerKillPlayerEvent(damager, player, damager.getGame()); 41 | Bukkit.getPluginManager().callEvent(ev); 42 | if(!ev.isCancelled()){ 43 | damager.getGame().increaseKills(damager, 1); 44 | }else{ 45 | e.setCancelled(true); 46 | } 47 | }else{ 48 | PlayerDamagePlayerEvent ev = new PlayerDamagePlayerEvent(damager, player, damager.getGame()); 49 | Bukkit.getPluginManager().callEvent(ev); 50 | e.setCancelled(ev.isCancelled()); 51 | } 52 | } 53 | } 54 | } 55 | } 56 | 57 | } 58 | -------------------------------------------------------------------------------- /src/com/scarabcoder/gameapi/GameAPI.java: -------------------------------------------------------------------------------- 1 | package com.scarabcoder.gameapi; 2 | 3 | import java.io.File; 4 | 5 | import org.bukkit.Bukkit; 6 | import org.bukkit.plugin.Plugin; 7 | import org.bukkit.plugin.java.JavaPlugin; 8 | 9 | import com.scarabcoder.gameapi.listener.InventoryListener; 10 | import com.scarabcoder.gameapi.listener.PlayerJoinListener; 11 | import com.scarabcoder.gameapi.listener.PlayerMovementListener; 12 | import com.scarabcoder.gameapi.listener.PlayerPvPListener; 13 | import com.scarabcoder.gameapi.listener.PlayerQuitListener; 14 | import com.scarabcoder.gameapi.listener.ServerPingListener; 15 | import com.scarabcoder.gameapi.listener.SettingsListener; 16 | 17 | public class GameAPI extends JavaPlugin { 18 | 19 | private static Plugin plugin; 20 | 21 | private static File gameWorlds; 22 | 23 | private static boolean debug; 24 | 25 | @Override 26 | public void onEnable(){ 27 | Bukkit.getPluginManager().registerEvents(new PlayerMovementListener(), this); 28 | Bukkit.getPluginManager().registerEvents(new SettingsListener(), this); 29 | Bukkit.getPluginManager().registerEvents(new PlayerPvPListener(), this); 30 | Bukkit.getPluginManager().registerEvents(new PlayerQuitListener(), this); 31 | Bukkit.getPluginManager().registerEvents(new InventoryListener(), this); 32 | Bukkit.getPluginManager().registerEvents(new PlayerJoinListener(), this); 33 | Bukkit.getPluginManager().registerEvents(new ServerPingListener(), this); 34 | getServer().getMessenger().registerOutgoingPluginChannel(this, "BungeeCord"); 35 | plugin = this; 36 | 37 | gameWorlds = new File("GameWorlds"); 38 | 39 | if(!gameWorlds.exists()){ 40 | gameWorlds.mkdir(); 41 | } 42 | if(!this.getDataFolder().exists()){ 43 | this.getDataFolder().mkdir(); 44 | } 45 | 46 | this.saveDefaultConfig(); 47 | debug = this.getConfig().getBoolean("debug"); 48 | 49 | } 50 | 51 | /** 52 | * Get whether or not the API is in debug mode, as set in the config.yml. 53 | * @return boolean debug mode. 54 | */ 55 | public static boolean debugMode(){ 56 | return debug; 57 | } 58 | 59 | public static File getGameWorldsFolder(){ 60 | return gameWorlds; 61 | } 62 | 63 | public static Plugin getPlugin(){ 64 | return plugin; 65 | 66 | 67 | } 68 | 69 | public static void logInfo(String msg){ 70 | System.out.println("[GameAPI] [INFO] " + msg); 71 | } 72 | 73 | public static void sendDebugMessage(String message, Plugin plugin){ 74 | if(GameAPI.debugMode()) System.out.println("[GameAPI]" + (plugin.getName().equals("GameAPI") ? "" : " [" + plugin.getName() + "]") + " [DEBUG] " + message); 75 | } 76 | 77 | 78 | } 79 | -------------------------------------------------------------------------------- /src/com/scarabcoder/gameapi/enums/DefaultFontInfo.java: -------------------------------------------------------------------------------- 1 | package com.scarabcoder.gameapi.enums; 2 | 3 | //Source: SirSpoodles on Spigot 4 | public enum DefaultFontInfo{ 5 | 6 | A('A', 5), 7 | a('a', 5), 8 | B('B', 5), 9 | b('b', 5), 10 | C('C', 5), 11 | c('c', 5), 12 | D('D', 5), 13 | d('d', 5), 14 | E('E', 5), 15 | e('e', 5), 16 | F('F', 5), 17 | f('f', 4), 18 | G('G', 5), 19 | g('g', 5), 20 | H('H', 5), 21 | h('h', 5), 22 | I('I', 3), 23 | i('i', 1), 24 | J('J', 5), 25 | j('j', 5), 26 | K('K', 5), 27 | k('k', 4), 28 | L('L', 5), 29 | l('l', 1), 30 | M('M', 5), 31 | m('m', 5), 32 | N('N', 5), 33 | n('n', 5), 34 | O('O', 5), 35 | o('o', 5), 36 | P('P', 5), 37 | p('p', 5), 38 | Q('Q', 5), 39 | q('q', 5), 40 | R('R', 5), 41 | r('r', 5), 42 | S('S', 5), 43 | s('s', 5), 44 | T('T', 5), 45 | t('t', 4), 46 | U('U', 5), 47 | u('u', 5), 48 | V('V', 5), 49 | v('v', 5), 50 | W('W', 5), 51 | w('w', 5), 52 | X('X', 5), 53 | x('x', 5), 54 | Y('Y', 5), 55 | y('y', 5), 56 | Z('Z', 5), 57 | z('z', 5), 58 | NUM_1('1', 5), 59 | NUM_2('2', 5), 60 | NUM_3('3', 5), 61 | NUM_4('4', 5), 62 | NUM_5('5', 5), 63 | NUM_6('6', 5), 64 | NUM_7('7', 5), 65 | NUM_8('8', 5), 66 | NUM_9('9', 5), 67 | NUM_0('0', 5), 68 | EXCLAMATION_POINT('!', 1), 69 | AT_SYMBOL('@', 6), 70 | NUM_SIGN('#', 5), 71 | DOLLAR_SIGN('$', 5), 72 | PERCENT('%', 5), 73 | UP_ARROW('^', 5), 74 | AMPERSAND('&', 5), 75 | ASTERISK('*', 5), 76 | LEFT_PARENTHESIS('(', 4), 77 | RIGHT_PERENTHESIS(')', 4), 78 | MINUS('-', 5), 79 | UNDERSCORE('_', 5), 80 | PLUS_SIGN('+', 5), 81 | EQUALS_SIGN('=', 5), 82 | LEFT_CURL_BRACE('{', 4), 83 | RIGHT_CURL_BRACE('}', 4), 84 | LEFT_BRACKET('[', 3), 85 | RIGHT_BRACKET(']', 3), 86 | COLON(':', 1), 87 | SEMI_COLON(';', 1), 88 | DOUBLE_QUOTE('"', 3), 89 | SINGLE_QUOTE('\'', 1), 90 | LEFT_ARROW('<', 4), 91 | RIGHT_ARROW('>', 4), 92 | QUESTION_MARK('?', 5), 93 | SLASH('/', 5), 94 | BACK_SLASH('\\', 5), 95 | LINE('|', 1), 96 | TILDE('~', 5), 97 | TICK('`', 2), 98 | PERIOD('.', 1), 99 | COMMA(',', 1), 100 | SPACE(' ', 3), 101 | DEFAULT('a', 4); 102 | 103 | private char character; 104 | private int length; 105 | 106 | DefaultFontInfo(char character, int length) { 107 | this.character = character; 108 | this.length = length; 109 | } 110 | 111 | public char getCharacter(){ 112 | return this.character; 113 | } 114 | 115 | public int getLength(){ 116 | return this.length; 117 | } 118 | 119 | public int getBoldLength(){ 120 | if(this == DefaultFontInfo.SPACE) return this.getLength(); 121 | return this.length + 1; 122 | } 123 | 124 | public static DefaultFontInfo getDefaultFontInfo(char c){ 125 | for(DefaultFontInfo dFI : DefaultFontInfo.values()){ 126 | if(dFI.getCharacter() == c) return dFI; 127 | } 128 | return DefaultFontInfo.DEFAULT; 129 | } 130 | } 131 | -------------------------------------------------------------------------------- /src/com/scarabcoder/gameapi/game/Team.java: -------------------------------------------------------------------------------- 1 | package com.scarabcoder.gameapi.game; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | import org.bukkit.ChatColor; 7 | import org.bukkit.Color; 8 | import org.bukkit.Location; 9 | 10 | import com.scarabcoder.gameapi.enums.GamePlayerType; 11 | 12 | public class Team { 13 | 14 | private List players = new ArrayList(); 15 | 16 | private boolean allowTeamDamage = false; 17 | private String name; 18 | private Color color; 19 | private ChatColor chatColor; 20 | private List teamSpawns; 21 | 22 | 23 | public Team(Color dyeColor, ChatColor chatColor, String name){ 24 | this.color = dyeColor; 25 | this.name = name; 26 | this.chatColor = chatColor; 27 | this.teamSpawns = new ArrayList(); 28 | 29 | } 30 | 31 | public List getPlayersByMode(GamePlayerType type){ 32 | List ps = new ArrayList(); 33 | for(GamePlayer p : this.players){ 34 | if(p.getGame().getGamePlayerType(p).equals(type)){ 35 | ps.add(p); 36 | } 37 | } 38 | return ps; 39 | } 40 | 41 | public void sendMessage(String msg){ 42 | for(GamePlayer player : this.getPlayers()){ 43 | if(player.isOnline()){ 44 | player.getOnlinePlayer().sendMessage("[" + this.getChatColor() + name + ChatColor.RESET + "] " + msg); 45 | } 46 | } 47 | } 48 | 49 | public List getTeamSpawns(){ 50 | return this.teamSpawns; 51 | } 52 | 53 | public void addTeamSpawn(Location location){ 54 | this.teamSpawns.add(location); 55 | } 56 | 57 | public Color getColor(){ 58 | return this.color; 59 | } 60 | 61 | public ChatColor getChatColor(){ 62 | return this.chatColor; 63 | } 64 | 65 | public String getName(){ 66 | return this.name; 67 | } 68 | 69 | /** 70 | * Whether or not players can damage each other. 71 | * @return boolean 72 | */ 73 | public boolean allowTeamDamage(){ 74 | return allowTeamDamage; 75 | } 76 | 77 | /** 78 | * Whether or not players can damage each other 79 | * @param allow 80 | */ 81 | public void setAllowTeamDamage(boolean allow){ 82 | this.allowTeamDamage = allow; 83 | } 84 | 85 | 86 | /** 87 | * Add a player to the team. Players can be on multiple teams, though it isn't recommended. 88 | * @param p The GamePlayer to be added. 89 | */ 90 | public void addPlayer(GamePlayer p){ 91 | players.add(p); 92 | p.setTeam(this); 93 | } 94 | 95 | /** 96 | * Removes the player from the team. 97 | * @param p Player to remove. 98 | */ 99 | public void removePlayer(GamePlayer p){ 100 | p.setTeam(null); 101 | players.remove(p); 102 | } 103 | 104 | /** 105 | * Get a list of players on the team. 106 | * @return List of players on the team. 107 | */ 108 | public List getPlayers(){ 109 | return players; 110 | } 111 | 112 | } 113 | -------------------------------------------------------------------------------- /src/com/scarabcoder/gameapi/manager/ArenaManager.java: -------------------------------------------------------------------------------- 1 | package com.scarabcoder.gameapi.manager; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | import org.bukkit.Location; 7 | 8 | import com.scarabcoder.gameapi.game.Area; 9 | import com.scarabcoder.gameapi.game.ArenaSettings; 10 | import com.scarabcoder.gameapi.game.Game; 11 | import com.scarabcoder.gameapi.game.GamePlayer; 12 | 13 | public class ArenaManager { 14 | 15 | /** 16 | * Get a list of active settings for a position. 17 | * If two ArenaSetting's priorities conflict, the first one that the computer finds is chosen. 18 | * @param player GamePlayer 19 | * @return ArenaSettings object for the location, or null if no settings apply. 20 | */ 21 | public static ArenaSettings getActiveSettings(Location location){ 22 | 23 | int topPriority = -1; 24 | ArenaSettings settings = null; 25 | 26 | for(ArenaSettings setting : ArenaManager.getArenaSettingsByLocation(location)){ 27 | if(setting.getPriority() > topPriority){ 28 | settings = setting; 29 | topPriority = setting.getPriority(); 30 | } 31 | } 32 | 33 | return settings; 34 | 35 | } 36 | 37 | /** 38 | * Get a list of active settings for a player. 39 | * If two ArenaSetting's priorities conflict, the first one that the computer finds is chosen. 40 | * @param player GamePlayer 41 | * @return ArenaSettings object with active settings, or null if the player is not in a game. 42 | */ 43 | public static ArenaSettings getActiveSettings(GamePlayer player){ 44 | if(!player.isInGame()) return null; 45 | if(player.getAreas().size() == 0) return player.getGame().getArena().getArenaSettings(); 46 | 47 | ArenaSettings settings = null; 48 | int topPriority = -1; 49 | 50 | for(Area area : player.getAreas()){ 51 | if(area.useSettings()){ 52 | if(area.getSettings().getPriority() > topPriority){ 53 | settings = area.getSettings(); 54 | topPriority = area.getSettings().getPriority(); 55 | } 56 | } 57 | } 58 | 59 | return (settings == null ? player.getGame().getArena().getArenaSettings() : settings); 60 | 61 | } 62 | 63 | /** 64 | * Get a list of ArenaSettings that apply to a location. This is cross-game! 65 | * @param location Bukkit Location. 66 | * @return List 67 | */ 68 | public static List getArenaSettingsByLocation(Location location){ 69 | List settings = new ArrayList(); 70 | for(Game game : GameManager.getGames()){ 71 | if(game.getArena().getWorld().getName().equals(location.getWorld().getName())) settings.add(game.getArena().getArenaSettings()); 72 | for(Area area : game.getAreas()){ 73 | if(area.useSettings()){ 74 | Location l1 = area.getLocation1(); 75 | Location l2 = area.getLocation2(); 76 | if( 77 | location.getX() > l1.getX() && location.getX() < l2.getX() && 78 | location.getY() > l1.getY() && location.getY() < l2.getY() && 79 | location.getZ() > l1.getZ() && location.getZ() < l2.getZ() 80 | ){ 81 | settings.add(area.getSettings()); 82 | } 83 | } 84 | } 85 | } 86 | return settings; 87 | } 88 | 89 | } 90 | -------------------------------------------------------------------------------- /src/com/scarabcoder/gameapi/game/GamePlayer.java: -------------------------------------------------------------------------------- 1 | package com.scarabcoder.gameapi.game; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | import org.bukkit.OfflinePlayer; 7 | import org.bukkit.entity.Player; 8 | 9 | import com.scarabcoder.gameapi.util.LocationUtil; 10 | 11 | public class GamePlayer { 12 | 13 | private OfflinePlayer player; 14 | 15 | private Team team; 16 | 17 | private Game game; 18 | 19 | public GamePlayer(OfflinePlayer player){ 20 | this.player = player; 21 | } 22 | 23 | 24 | public void setPlayer(OfflinePlayer player){ 25 | this.player = player; 26 | } 27 | 28 | /** 29 | * Set the game this player is in. 30 | * Used by the internal API, bad things might happen if you set this yourself! 31 | * @param game Game to be set. 32 | */ 33 | protected void setGame(Game game){ 34 | this.game = game; 35 | } 36 | 37 | 38 | /** 39 | * Get the Bukkit (offline) player. 40 | * For the online player, use getOnlinePlayer(). Make sure you check if the player is online with isOnline()! 41 | * @return OfflinePlayer 42 | */ 43 | public OfflinePlayer getPlayer(){ 44 | return player; 45 | } 46 | 47 | /** 48 | * Get the online Bukkit Player. 49 | * @return Player if online, null if otherwise. 50 | */ 51 | public Player getOnlinePlayer(){ 52 | return player.getPlayer(); 53 | } 54 | 55 | /** 56 | * Checks whether or not the player is online. 57 | * @return boolean online 58 | */ 59 | public boolean isOnline(){ 60 | return getOnlinePlayer() != null; 61 | } 62 | 63 | /** 64 | * Set the team this player is in. This is an internal API method, bad things might happen if you set this yourself! 65 | * @param team Team to be set. 66 | */ 67 | protected void setTeam(Team team){ 68 | Team oldTeam = this.team; 69 | this.team = team; 70 | if(oldTeam != null){ 71 | oldTeam.removePlayer(this); 72 | } 73 | } 74 | 75 | /** 76 | * Get the team this player is in. If the player is not in a team, returns null. 77 | * @return Team object or null. 78 | */ 79 | public Team getTeam(){ 80 | return team; 81 | } 82 | 83 | /** 84 | * Get the game the player is in. 85 | * @return Game object if the player is in a game, null otherwise (see GamePlayer.isInGame()) 86 | */ 87 | public Game getGame(){ 88 | return game; 89 | } 90 | 91 | /** 92 | * Returns whether or not the player is in a game. 93 | * @return true if in a game, false otherwise. 94 | */ 95 | public boolean isInGame(){ 96 | return this.game != null; 97 | } 98 | 99 | /** 100 | * Get the list of areas this player is in. 101 | * @return List of areas. Only null if the player is not in a game, or is offline. 102 | */ 103 | public List getAreas(){ 104 | if(!this.isInGame()) return null; 105 | if(!this.isOnline()) return null; 106 | List areas = new ArrayList(); 107 | for(Area area : this.getGame().getAreas()){ 108 | if(LocationUtil.isInArea(this.getOnlinePlayer().getLocation(), area.getLocation1(), area.getLocation2())) 109 | areas.add(area); 110 | 111 | } 112 | return areas; 113 | } 114 | 115 | } 116 | -------------------------------------------------------------------------------- /src/com/scarabcoder/gameapi/game/Area.java: -------------------------------------------------------------------------------- 1 | package com.scarabcoder.gameapi.game; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | import org.bukkit.Location; 7 | 8 | public class Area { 9 | 10 | private Location loc1; 11 | 12 | private ArenaSettings settings; 13 | 14 | private Location loc2; 15 | 16 | private String name; 17 | 18 | private boolean useSettings; 19 | 20 | /** 21 | * Define an area to make checking for certain events easier. 22 | * You can also define areas to have their own settings (Area.getSettings()). 23 | * Area settings will not take effect unless useSettings() is set to true. 24 | * Loc1 and loc2 will be re-written so that loc1 is always the "lowest" position, and loc2 to be the "highest" 25 | * 26 | * @param loc1 First corner of the area 27 | * @param loc2 Second corner of the area 28 | * @param name The name for this area 29 | */ 30 | public Area(Location loc1, Location loc2, String name){ 31 | 32 | double x1 = Math.min(loc1.getX(), loc2.getX()); 33 | double y1 = Math.min(loc1.getY(), loc2.getY()); 34 | double z1 = Math.min(loc1.getZ(), loc2.getZ()); 35 | 36 | double x2 = Math.max(loc1.getX(), loc2.getX()); 37 | double y2 = Math.max(loc1.getY(), loc2.getY()); 38 | double z2 = Math.max(loc1.getZ(), loc2.getZ()); 39 | 40 | this.loc1 = new Location(loc1.getWorld(), x1, y1, z1); 41 | this.loc2 = new Location(loc2.getWorld(), x2, y2, z2); 42 | this.name = name; 43 | this.settings = new ArenaSettings(); 44 | this.useSettings = false; 45 | } 46 | 47 | public Location getCenter(){ 48 | return getCenter(true); 49 | } 50 | 51 | public Location getCenter(boolean withY){ 52 | double x = loc1.getX() + 0.5 + (loc2.getX() - loc1.getX()) / 2; 53 | double y = (withY ? loc1.getY() + (loc2.getY() - loc1.getY()) / 2 : loc1.getY()); 54 | double z = loc1.getZ() + 0.5 + (loc2.getZ() - loc1.getZ()) / 2; 55 | return new Location(loc1.getWorld(), x, y, z); 56 | } 57 | 58 | public boolean useSettings(){ 59 | return this.useSettings; 60 | } 61 | 62 | public void useSettings(boolean use){ 63 | this.useSettings = use; 64 | } 65 | 66 | /** 67 | * Checks whether or not a player is in the area. 68 | * @return True if player is in area, false otherwise. 69 | */ 70 | public boolean isPlayerInArea(){ 71 | return false; 72 | } 73 | 74 | /** 75 | * Returns a list of players in the area. 76 | * @return List players. 77 | */ 78 | public List getPlayersInArea(){ 79 | return new ArrayList(); 80 | } 81 | 82 | /** 83 | * Get the settings for this area. 84 | * @return ArenaSettings for this area. 85 | */ 86 | public ArenaSettings getSettings(){ 87 | return settings; 88 | } 89 | 90 | /** 91 | * Get the first (corner) location of this area. 92 | * @return Location object. 93 | */ 94 | public Location getLocation1(){ 95 | return loc1; 96 | } 97 | 98 | /** 99 | * Get the second (corner) location of this area. 100 | * @return Location object. 101 | */ 102 | public Location getLocation2(){ 103 | return loc2; 104 | } 105 | 106 | /** 107 | * Get the set name for this area. 108 | * @return String name. 109 | */ 110 | public String getName(){ 111 | return name; 112 | } 113 | 114 | } 115 | -------------------------------------------------------------------------------- /src/com/scarabcoder/gameapi/game/Arena.java: -------------------------------------------------------------------------------- 1 | package com.scarabcoder.gameapi.game; 2 | 3 | import java.io.File; 4 | import java.io.IOException; 5 | 6 | import org.apache.commons.io.FileUtils; 7 | import org.bukkit.Bukkit; 8 | import org.bukkit.Location; 9 | import org.bukkit.World; 10 | import org.bukkit.WorldCreator; 11 | import org.bukkit.WorldType; 12 | import org.bukkit.entity.Player; 13 | 14 | import com.scarabcoder.gameapi.GameAPI; 15 | 16 | public class Arena { 17 | 18 | private String id; 19 | 20 | private ArenaSettings settings; 21 | 22 | private Location spectatorSpawn; 23 | 24 | private Location lobbySpawn; 25 | 26 | private World world; 27 | 28 | /** 29 | * Arena object, used in Game to define Arena world. 30 | * If the world exists as a folder in the server directory but isn't loaded, it will be loaded. If it doesn't exist as a folder and isn't laoded, one will be created. 31 | * @param id Unique Arena ID. Also used for world name. 32 | */ 33 | public Arena(String id){ 34 | this.settings = new ArenaSettings(); 35 | this.id = id; 36 | if(Bukkit.getWorld(id) == null){ 37 | Bukkit.createWorld(new WorldCreator(id)); 38 | } 39 | this.world = Bukkit.getWorld(id); 40 | this.saveDefault(); 41 | } 42 | 43 | public String getName(){ 44 | return this.id; 45 | } 46 | 47 | /** 48 | * Get the global ArenaSettings for this arena. 49 | * @return ArenaSettings 50 | */ 51 | public ArenaSettings getArenaSettings(){ 52 | return this.settings; 53 | } 54 | 55 | /** 56 | * Get the Bukkit world for this arena. 57 | * @return World Bukkit world. 58 | */ 59 | public World getWorld(){ 60 | return world; 61 | } 62 | 63 | /** 64 | * Get the spectator spawnpoint. 65 | * @return Location spawnpoint. 66 | */ 67 | public Location getSpectatorSpawn(){ 68 | return spectatorSpawn; 69 | } 70 | 71 | /** 72 | * Get the lobby spawnpoint. 73 | * @return Location lobby spawnpoint. 74 | */ 75 | public Location getLobbySpawn(){ 76 | return lobbySpawn; 77 | } 78 | 79 | /** 80 | * Set the spawn used for spectators spawning. 81 | * 82 | */ 83 | public void setSpectatorSpawn(Location spectatorSpawn){ 84 | this.spectatorSpawn = spectatorSpawn; 85 | } 86 | 87 | /** 88 | * Set the spawn used when the game status is waiting. 89 | */ 90 | public void setLobbySpawn(Location lobbySpawn){ 91 | this.lobbySpawn = lobbySpawn; 92 | } 93 | 94 | /** 95 | * Saves current world as the default, used when resetting the world. 96 | */ 97 | public void saveDefault(){ 98 | GameAPI.sendDebugMessage("Saving default world for " + this.getWorld().getName() + "...", GameAPI.getPlugin()); 99 | File worldFolder = world.getWorldFolder(); 100 | try { 101 | File dest = new File(GameAPI.getGameWorldsFolder(), this.world.getName()); 102 | if(dest.exists()){ 103 | GameAPI.sendDebugMessage("Deleting existing default world " + this.getWorld().getName() + "...", GameAPI.getPlugin()); 104 | FileUtils.deleteDirectory(dest); 105 | } 106 | GameAPI.sendDebugMessage("Copying world " + this.getWorld().getName() + " to defaults folder...", GameAPI.getPlugin()); 107 | FileUtils.copyDirectory(worldFolder, new File(GameAPI.getGameWorldsFolder(), this.world.getName())); 108 | 109 | } catch (IOException e) { 110 | e.printStackTrace(); 111 | } 112 | } 113 | /** 114 | * Resets the world to saved default. 115 | * Players should NOT be in the world. As a precaution against world corruption, any players in the world are kicked from the server. 116 | */ 117 | public void resetWorld(){ 118 | GameAPI.sendDebugMessage("Resetting arena world " + this.getWorld().getName() + "!", GameAPI.getPlugin()); 119 | File worldFolder = world.getWorldFolder(); 120 | String worldName = world.getName(); 121 | for(Player player : this.getWorld().getPlayers()){ 122 | player.kickPlayer("World resetting..."); 123 | } 124 | GameAPI.sendDebugMessage("Unloading world " + worldName + "...", GameAPI.getPlugin()); 125 | Bukkit.unloadWorld(worldName, true); 126 | Bukkit.getScheduler().scheduleSyncDelayedTask(GameAPI.getPlugin(), new Runnable(){ 127 | 128 | @Override 129 | public void run() { 130 | try { 131 | GameAPI.sendDebugMessage("Deleting world " + worldName + "...", GameAPI.getPlugin()); 132 | FileUtils.deleteDirectory(worldFolder); 133 | GameAPI.sendDebugMessage("Copying default world from GameWorlds/" + worldName + "...", GameAPI.getPlugin()); 134 | FileUtils.copyDirectory(new File(GameAPI.getGameWorldsFolder(), worldName), new File(GameAPI.getGameWorldsFolder().getParentFile(), worldName)); 135 | GameAPI.sendDebugMessage("Loading world " + worldName + " on server...", GameAPI.getPlugin()); 136 | WorldCreator creator = new WorldCreator(worldName); 137 | creator.generatorSettings("3;minecraft:air;127;"); 138 | creator.type(WorldType.FLAT); 139 | world = Bukkit.createWorld(creator); 140 | } catch (IOException e) { 141 | e.printStackTrace(); 142 | } 143 | } 144 | 145 | }, 20); 146 | 147 | 148 | } 149 | 150 | 151 | } 152 | -------------------------------------------------------------------------------- /src/com/scarabcoder/gameapi/game/GameSettings.java: -------------------------------------------------------------------------------- 1 | package com.scarabcoder.gameapi.game; 2 | 3 | import org.bukkit.GameMode; 4 | import org.bukkit.Location; 5 | 6 | import com.scarabcoder.gameapi.enums.PlayerJoinLimitAction; 7 | import com.scarabcoder.gameapi.enums.TeamSpreadType; 8 | 9 | public class GameSettings { 10 | 11 | private int minPlayers; 12 | private int maxPlayers; 13 | private int countdownTimer; 14 | private boolean setMOTD; 15 | private boolean setListPlayerCount; 16 | private boolean enableBungee; 17 | private Location lobbySpawn; 18 | private String lobbyServer; 19 | private PlayerJoinLimitAction limitAction; 20 | private boolean shouldLeavePlayerOnDisconnect; 21 | private boolean useTeams; 22 | private TeamSpreadType spreadType; 23 | private GameMode mode; 24 | private GameMode spectatorMode; 25 | private boolean teleportPlayersOnGameStart; 26 | private boolean automaticCountdown; 27 | private int foodLevel; 28 | private double healthLevel; 29 | private int minTeamSize; 30 | private int maxTeamSize; 31 | private boolean autoTeamCompensation; 32 | private boolean disableVanillaJoinLeaveMessages; 33 | private boolean displayVanillaDeathMessages; 34 | private boolean resetWorlds; 35 | 36 | public GameSettings(){ 37 | loadDefaults(); 38 | } 39 | 40 | /** 41 | * Reset defaults. 42 | */ 43 | public void loadDefaults(){ 44 | this.minPlayers = 2; 45 | this.maxPlayers = 8; 46 | this.countdownTimer = 60; 47 | this.setMOTD = false; 48 | this.setListPlayerCount = false; 49 | this.limitAction = PlayerJoinLimitAction.DISALLOW; 50 | this.shouldLeavePlayerOnDisconnect = true; 51 | this.useTeams = false; 52 | this.spreadType = TeamSpreadType.EVEN; 53 | this.mode = GameMode.SURVIVAL; 54 | this.spectatorMode = GameMode.SPECTATOR; 55 | this.setTeleportPlayersOnGameStart(true); 56 | this.setAutomaticCountdown(true); 57 | this.foodLevel = 20; 58 | this.healthLevel = 20.0d; 59 | this.minTeamSize = 1; 60 | this.maxTeamSize = 4; 61 | this.autoTeamCompensation = false; 62 | this.disableVanillaJoinLeaveMessages = true; 63 | this.enableBungee = false; 64 | this.displayVanillaDeathMessages = true; 65 | this.resetWorlds = false; 66 | } 67 | 68 | public boolean shouldResetWorlds(){ 69 | return this.resetWorlds; 70 | } 71 | 72 | public void setResetWorlds(boolean reset){ 73 | this.resetWorlds = reset; 74 | } 75 | 76 | public boolean shouldDisableVanillaDeathMessages(){ 77 | return this.displayVanillaDeathMessages; 78 | } 79 | 80 | public void setDisableVanillaDeathMessages(boolean display){ 81 | this.displayVanillaDeathMessages = display; 82 | } 83 | 84 | /** 85 | * Get whether or not teams should automatically be re-arranged if the team spread type is set to EVEN. 86 | * Auto compensation occurs when during the PlayerLeaveGameEvent. 87 | * Default: false 88 | * @return 89 | */ 90 | public boolean getAutomaticTeamSizeCompensationEnabled(){ 91 | return this.autoTeamCompensation; 92 | } 93 | 94 | /** 95 | * Whether or not the vanilla "x joined the game/x left the game" messages should be disabled. 96 | * Default: true 97 | * @return 98 | */ 99 | public boolean shouldDisableVanillaJoinLeaveMessages(){ 100 | return this.disableVanillaJoinLeaveMessages; 101 | } 102 | 103 | /** 104 | * Set whether or not the vanilla "x joined the game/x left the game" messages should be disabled. 105 | * Default: true 106 | * @return 107 | */ 108 | public void shouldDisableVanillaJoinLeaveMessages(boolean disable){ 109 | this.disableVanillaJoinLeaveMessages = disable; 110 | } 111 | 112 | /** 113 | * Set whether or not teams should automatically be re-arranged if the team spread type is set to EVEN. 114 | * Auto compensation occurs when during the PlayerLeaveGameEvent. 115 | * Default: false 116 | * @return 117 | */ 118 | public void setAutomaticTeamSizeCompensationEnabled(boolean enable){ 119 | this.autoTeamCompensation = enable; 120 | } 121 | 122 | /** 123 | * Get the minimum team size. Only used if teams are enabled. 124 | * @return Minimum team size. 125 | */ 126 | public int getMinimumTeamSize(){ 127 | return this.minTeamSize; 128 | } 129 | 130 | /** 131 | * Set the minimum team size. Only used if teams are enabled. 132 | * @param minSize Minimum team size. 133 | */ 134 | public void setMinimumTeamSize(int minSize){ 135 | this.minTeamSize = minSize; 136 | } 137 | 138 | /** 139 | * Get the maximum team size. Only used if teams are enabled. 140 | * @return Maximum team size. 141 | */ 142 | public int getMaximumTeamSize(){ 143 | return this.maxTeamSize; 144 | } 145 | 146 | /** 147 | * Set the maximum team size. Only used if teams are enabled. 148 | * @param maxSize Maximum team size. 149 | */ 150 | public void setMaximumTeamSize(int maxSize){ 151 | this.maxTeamSize = maxSize; 152 | } 153 | 154 | /** 155 | * Get whether or not the countdown should start when the minimum players required are filled. 156 | * @return 157 | */ 158 | public boolean getAutomaticCountdown() { 159 | return automaticCountdown; 160 | } 161 | 162 | /** 163 | * Set whether or not the countdown should start when the minimum players required are filled. 164 | * @param automaticCountdown 165 | */ 166 | public void setAutomaticCountdown(boolean automaticCountdown) { 167 | this.automaticCountdown = automaticCountdown; 168 | } 169 | 170 | /** 171 | * Whether or not players should be teleported to team spawns or game spawns on game start. 172 | * @return 173 | */ 174 | public boolean shouldTeleportPlayersOnGameStart() { 175 | return teleportPlayersOnGameStart; 176 | } 177 | 178 | /** 179 | * Set whether or not players should be teleported to team spawns or game spawns on game start. 180 | * @param teleportPlayersOnGameStart 181 | */ 182 | public void setTeleportPlayersOnGameStart(boolean teleportPlayersOnGameStart) { 183 | this.teleportPlayersOnGameStart = teleportPlayersOnGameStart; 184 | } 185 | 186 | /** 187 | * Get the Minecraft GameMode that players should be in while playing the game. 188 | * @return 189 | */ 190 | public GameMode getMode() { 191 | return mode; 192 | } 193 | 194 | 195 | /** 196 | * Set the Minecraft GameMode that players should be in while playing the game. 197 | * @param mode 198 | */ 199 | public void setMode(GameMode mode) { 200 | this.mode = mode; 201 | } 202 | 203 | /** 204 | * Get the Minecraft GameMode that spectators should be in while playing the game. 205 | * @return 206 | */ 207 | public GameMode getSpectatorMode() { 208 | return spectatorMode; 209 | } 210 | 211 | /** 212 | * Set the Minecraft GameMode that spectators should be in while playing the game. 213 | * @param spectatorMode 214 | */ 215 | public void setSpectatorMode(GameMode spectatorMode) { 216 | this.spectatorMode = spectatorMode; 217 | } 218 | 219 | /** 220 | * Get the team spread type. See TeamSpreadType.EVEN and TeamSpreadType.FIRST_AVAILABLE for more info. 221 | * @return Team spread type. 222 | */ 223 | public TeamSpreadType getTeamSpreadType(){ 224 | return this.spreadType; 225 | } 226 | 227 | /** 228 | * Set the team spread type. See TeamSpreadType.EVEN and TeamSpreadType.FIRST_AVAILABLE for more info. 229 | * @param type 230 | */ 231 | public void setTeamSpreadType(TeamSpreadType type){ 232 | this.spreadType = type; 233 | } 234 | 235 | /** 236 | * Whether or not teams are enabled. If enabled, players will automatically be added to an available team, sorted via the set TeamSpreadType. 237 | * @return boolean 238 | */ 239 | public boolean shouldUseTeams(){ 240 | return this.useTeams; 241 | } 242 | 243 | /** 244 | * Set whether or not teams are enabled. If enabled, players will automatically be added to an available team, sorted via the set TeamSpreadType. 245 | * @param should 246 | */ 247 | public void shouldUseTeams(boolean should){ 248 | this.useTeams = should; 249 | } 250 | 251 | /** 252 | * Whether or not the player should be removed from the game when they disconnect from the server. 253 | * @return 254 | */ 255 | public boolean shouldLeavePlayerOnDisconnect(){ 256 | return this.shouldLeavePlayerOnDisconnect; 257 | } 258 | 259 | /** 260 | * Set whether or not the player should be removed from the game when they disconnect from the server. 261 | * @param should 262 | */ 263 | public void shouldLeavePlayerOnDisconnect(boolean should){ 264 | this.shouldLeavePlayerOnDisconnect = should; 265 | } 266 | 267 | /** 268 | * Get whether or not the game uses Bungee servers. 269 | * @return Bungee enabled 270 | */ 271 | public boolean usesBungee(){ 272 | return this.enableBungee; 273 | } 274 | 275 | /** 276 | * Set whether or not the game should use Bungee servers. 277 | * @param bungee boolean. 278 | */ 279 | public void setUsesBungee(boolean bungee){ 280 | this.enableBungee = bungee; 281 | } 282 | 283 | /** 284 | * Set the lobby location. Only used if bungee mode is disabled. 285 | * @param location 286 | */ 287 | public void setLobbyLocation(Location location){ 288 | this.lobbySpawn = location; 289 | } 290 | 291 | /** 292 | * Set the lobby server that the player should be sent to on game end/leave. Only used if bungee mode is enabled. 293 | * @param server 294 | */ 295 | public void setLobbyServer(String server){ 296 | this.lobbyServer = server; 297 | } 298 | 299 | public Location getLobbyLocation(){ 300 | return this.lobbySpawn; 301 | } 302 | 303 | public String getLobbyServer(){ 304 | return this.lobbyServer; 305 | } 306 | 307 | /** 308 | * Get whether or not the Game should set the MOTD (Message Of The Day) to the GameStatus. 309 | * Default: false 310 | * @return doesSetMOTD 311 | */ 312 | public boolean doesSetMOTD(){ 313 | return setMOTD; 314 | } 315 | 316 | /** 317 | * Set whether or not the Game should set the MOTD (Message Of The Day) for the server to the GameStatus. 318 | * Default: false 319 | * @param motd 320 | */ 321 | public void setMOTD(boolean motd){ 322 | this.setMOTD = motd; 323 | } 324 | 325 | /** 326 | * Whether or not the game should set the max players allowed for the server to the the Maximum Players. 327 | * @return boolean 328 | */ 329 | public boolean doesSetListPlayerCount(){ 330 | return this.setListPlayerCount; 331 | } 332 | 333 | /** 334 | * Set whether or not the game should set hte max players allowed for the server to the maximum players. 335 | * @param should set. 336 | */ 337 | public void shouldSetListPlayerCount(boolean should){ 338 | this.setListPlayerCount = should; 339 | } 340 | 341 | /** 342 | * Get the minimum players required the start this game. 343 | * @return int number of players 344 | */ 345 | public int getMinimumPlayers(){ 346 | return this.minPlayers; 347 | } 348 | 349 | /** 350 | * Get the maximum amount of players that can join a game. 351 | * You can define what happens when a player attempts to join when the limit is filled with GameSettings.getLimitedPlayerJoinAction(). 352 | * @return int max players. 353 | */ 354 | public int getMaximumPlayers(){ 355 | return maxPlayers; 356 | } 357 | 358 | public PlayerJoinLimitAction getLimitedPlayerJoinAction(){ 359 | return this.limitAction ; 360 | } 361 | 362 | 363 | 364 | /** 365 | * When the minimum player count is met, it will start the countdown timer. 366 | * 367 | * @return countdown time in seconds. 368 | */ 369 | public int getCountdownTime(){ 370 | return countdownTimer; 371 | } 372 | 373 | /** 374 | * Get the minimum players required the start this game. 375 | * @param min minimum amount of players. 376 | */ 377 | public void setMinimumPlayers(int min){ 378 | this.minPlayers = min; 379 | } 380 | 381 | /** 382 | * Get the maximum amount of players that can join a game. 383 | * You can define what happens when a player attempts to join when the limit is filled with GameSettings.setLimitedPlayerJoinAction(). 384 | * @param max 385 | */ 386 | public void setMaximumPlayers(int max){ 387 | this.maxPlayers = max; 388 | } 389 | 390 | 391 | /** 392 | * When the minimum player count is met, it will start the countdown timer. 393 | * @param seconds 394 | */ 395 | public void setCountdownTime(int seconds){ 396 | this.countdownTimer = seconds; 397 | } 398 | 399 | public int getFoodLevel() { 400 | return foodLevel; 401 | } 402 | 403 | public void setFoodLevel(int foodLevel) { 404 | this.foodLevel = foodLevel; 405 | } 406 | 407 | public double getHealthLevel() { 408 | return healthLevel; 409 | } 410 | 411 | public void setHealthLevel(double healthLevel) { 412 | this.healthLevel = healthLevel; 413 | } 414 | 415 | } 416 | -------------------------------------------------------------------------------- /src/com/scarabcoder/gameapi/game/ArenaSettings.java: -------------------------------------------------------------------------------- 1 | package com.scarabcoder.gameapi.game; 2 | 3 | public class ArenaSettings { 4 | 5 | private boolean canBuild; 6 | private boolean canDestroy; 7 | private boolean canPvP; 8 | private boolean allowMobDamage; 9 | private boolean allowItemFrameDamage; 10 | private boolean allowPaintingDamage; 11 | private boolean allowExpDrop; 12 | private boolean allowItemDrop; 13 | private boolean allowMobSpawn; 14 | private boolean allowCreeperExplosion; 15 | private boolean allowOtherExplosion; 16 | private boolean allowEndermanGrief; 17 | private boolean allowEnderpearl; 18 | private boolean allowEnderDragonDestroy; 19 | private boolean allowGhastFireballExplosion; 20 | private boolean allowPlayerSleep; 21 | private boolean allowTNTExplosion; 22 | private boolean allowFlintAndSteel; 23 | private boolean allowFireSpread; 24 | private boolean allowLavaFire; 25 | private boolean allowLightning; 26 | private boolean allowChestAccess; 27 | private boolean allowPistons; 28 | private boolean allowWaterFlow; 29 | private boolean allowLavaFlow; 30 | private boolean allowPlayerInteract; 31 | private boolean allowVehiclePlacement; 32 | private boolean allowVehicleDestroy; 33 | private boolean allowSnowCollection; 34 | private boolean allowSnowMelt; 35 | private boolean allowIceForm; 36 | private boolean allowMushroomGrowth; 37 | private boolean allowLeafDecay; 38 | private boolean allowGrassGrowth; 39 | private boolean allowMyceliumSpread; 40 | private boolean allowVineGrowth; 41 | private boolean allowPlayerInvincibility; 42 | private boolean allowFoodLevelChange; 43 | private boolean keepInventory; 44 | private boolean allowDurabilityChange; 45 | private boolean allowBlockDrop; 46 | private boolean allowTimeChange; 47 | private boolean allowWeatherChange; 48 | private boolean allowInventoryChange; 49 | private boolean allowChat; 50 | 51 | private int priority; 52 | 53 | /** 54 | * ArenaSettings can be used for blocking certain events easier, without having to listen for each one. 55 | * For example, most minigames don't allow block breaking. Instead of cancelling an event, you can use: 56 | * ArenaSettings.setCanBuild(false). 57 | * Also sets a default priority of 0 for Areas or -1 for Arenas (see ArenaSettings.getPriority() for more on how this works). 58 | */ 59 | public ArenaSettings(){ 60 | this.loadDefaults(); 61 | 62 | } 63 | 64 | /** 65 | * ArenaSettings can be used for blocking certain events easier, without having to listen for each one. 66 | * For example, most minigames don't allow block breaking. Instead of cancelling an event, you can use: 67 | * ArenaSettings.setCanBuild(false). 68 | * @param priority Priority to be set. 69 | */ 70 | public ArenaSettings(int priority){ 71 | this.priority = 0; 72 | this.loadDefaults(); 73 | } 74 | 75 | /** 76 | * Get the priority these settings take. Higher number = higher priority. 77 | * Default: 0 for Areas, -1 for Arenas. 78 | * @return This ArenaSettings' priority. 79 | */ 80 | public int getPriority(){ 81 | return this.priority; 82 | } 83 | 84 | /** 85 | * Set the priority these settings take. Higher number = higher priority 86 | * Default: 0 for Areas, -1 for Arenas. 87 | * @param priority The ArenaSettings' priority to be set. 88 | */ 89 | public void setPriority(int priority){ 90 | this.priority = priority; 91 | } 92 | 93 | 94 | /** 95 | * Resets all settings to their default, except priority level. 96 | */ 97 | public void loadDefaults(){ 98 | this.allowChestAccess = true; 99 | this.allowCreeperExplosion = true; 100 | this.allowEnderDragonDestroy = true; 101 | this.allowEndermanGrief = true; 102 | this.allowEnderpearl = true; 103 | this.allowExpDrop = true; 104 | this.allowFireSpread = true; 105 | this.allowFlintAndSteel = true; 106 | this.allowGhastFireballExplosion = true; 107 | this.allowGrassGrowth = true; 108 | this.allowIceForm = true; 109 | this.allowItemDrop = true; 110 | this.allowItemFrameDamage = true; 111 | this.allowLavaFire = true; 112 | this.allowLavaFlow = true; 113 | this.allowLeafDecay = true; 114 | this.allowLightning = true; 115 | this.allowMobDamage = true; 116 | this.allowMobSpawn = true; 117 | this.allowMushroomGrowth = true; 118 | this.allowMyceliumSpread = true; 119 | this.allowOtherExplosion = true; 120 | this.allowPaintingDamage = true; 121 | this.allowPistons = true; 122 | this.allowPlayerInteract = true; 123 | this.allowPlayerInvincibility = false; 124 | this.allowPlayerSleep = true; 125 | this.allowSnowCollection = true; 126 | this.allowSnowMelt = true; 127 | this.allowTNTExplosion = true; 128 | this.allowVehicleDestroy = true; 129 | this.allowVehiclePlacement = true; 130 | this.allowVineGrowth = true; 131 | this.allowWaterFlow = true; 132 | this.canBuild = true; 133 | this.canDestroy = true; 134 | this.canPvP = true; 135 | this.allowFoodLevelChange = true; 136 | this.keepInventory = false; 137 | this.allowDurabilityChange = true; 138 | this.allowBlockDrop = true; 139 | this.allowTimeChange = true; 140 | this.allowWeatherChange = true; 141 | this.setAllowInventoryChange(true); 142 | this.allowChat = true; 143 | } 144 | 145 | 146 | public boolean allowChat(){ 147 | return this.allowChat; 148 | } 149 | 150 | public void allowChat(boolean allow){ 151 | this.allowChat = allow; 152 | } 153 | 154 | public boolean getAllowBlockDrop(){ 155 | return this.allowBlockDrop; 156 | } 157 | 158 | public void setAllowBlockDrop(boolean allow){ 159 | this.allowBlockDrop = allow; 160 | } 161 | 162 | public boolean isCanBuild() { 163 | return canBuild; 164 | } 165 | 166 | public void setCanBuild(boolean canBuild) { 167 | this.canBuild = canBuild; 168 | } 169 | 170 | public boolean isCanDestroy() { 171 | return canDestroy; 172 | } 173 | 174 | public void setCanDestroy(boolean canDestroy) { 175 | this.canDestroy = canDestroy; 176 | } 177 | 178 | public boolean isCanPvP() { 179 | return canPvP; 180 | } 181 | 182 | public void setCanPvP(boolean canPvP) { 183 | this.canPvP = canPvP; 184 | } 185 | 186 | public boolean canMobDamage() { 187 | return allowMobDamage; 188 | } 189 | 190 | public void setAllowMobDamage(boolean allowMobDamage) { 191 | this.allowMobDamage = allowMobDamage; 192 | } 193 | 194 | public boolean canItemFrameDamage() { 195 | return allowItemFrameDamage; 196 | } 197 | 198 | public void setAllowItemFrameDamage(boolean allowItemFrameDamage) { 199 | this.allowItemFrameDamage = allowItemFrameDamage; 200 | } 201 | 202 | public boolean canPaintingDamage() { 203 | return allowPaintingDamage; 204 | } 205 | 206 | public void setAllowPaintingDamage(boolean allowPaintingDamage) { 207 | this.allowPaintingDamage = allowPaintingDamage; 208 | } 209 | 210 | public boolean canExpDrop() { 211 | return allowExpDrop; 212 | } 213 | 214 | public void setAllowExpDrop(boolean allowExpDrop) { 215 | this.allowExpDrop = allowExpDrop; 216 | } 217 | 218 | public boolean canItemDrop() { 219 | return allowItemDrop; 220 | } 221 | 222 | public void setAllowItemDrop(boolean allowItemDrop) { 223 | this.allowItemDrop = allowItemDrop; 224 | } 225 | 226 | public boolean canMobSpawn() { 227 | return allowMobSpawn; 228 | } 229 | 230 | public void setAllowMobSpawn(boolean allowMobSpawn) { 231 | this.allowMobSpawn = allowMobSpawn; 232 | } 233 | 234 | public boolean canCreeperExplosion() { 235 | return allowCreeperExplosion; 236 | } 237 | 238 | public void setAllowCreeperExplosion(boolean allowCreeperExplosion) { 239 | this.allowCreeperExplosion = allowCreeperExplosion; 240 | } 241 | 242 | public boolean canOtherExplosion() { 243 | return allowOtherExplosion; 244 | } 245 | 246 | public void setAllowOtherExplosion(boolean allowOtherExplosion) { 247 | this.allowOtherExplosion = allowOtherExplosion; 248 | } 249 | 250 | public boolean canEndermanGrief() { 251 | return allowEndermanGrief; 252 | } 253 | 254 | public void setAllowEndermanGrief(boolean allowEndermanGrief) { 255 | this.allowEndermanGrief = allowEndermanGrief; 256 | } 257 | 258 | public boolean canEnderpearl() { 259 | return allowEnderpearl; 260 | } 261 | 262 | public void setAllowEnderpearl(boolean allowEndepearl) { 263 | this.allowEnderpearl = allowEndepearl; 264 | } 265 | 266 | public boolean canEnderDragonDestroy() { 267 | return allowEnderDragonDestroy; 268 | } 269 | 270 | public void setAllowEnderDragonDestroy(boolean allowEnderDragonDestroy) { 271 | this.allowEnderDragonDestroy = allowEnderDragonDestroy; 272 | } 273 | 274 | public boolean canGhastFireballExplosion() { 275 | return allowGhastFireballExplosion; 276 | } 277 | 278 | public void setAllowGhastFireballExplosion(boolean allowGhastFireballExplosion) { 279 | this.allowGhastFireballExplosion = allowGhastFireballExplosion; 280 | } 281 | 282 | public boolean canPlayerSleep() { 283 | return allowPlayerSleep; 284 | } 285 | 286 | public void setAllowPlayerSleep(boolean allowPlayerSleep) { 287 | this.allowPlayerSleep = allowPlayerSleep; 288 | } 289 | 290 | public boolean canTNTExplosion() { 291 | return allowTNTExplosion; 292 | } 293 | 294 | public void setAllowTNTExplosion(boolean allowTNTExplosion) { 295 | this.allowTNTExplosion = allowTNTExplosion; 296 | } 297 | 298 | public boolean canFlintAndSteel() { 299 | return allowFlintAndSteel; 300 | } 301 | 302 | public void setAllowFlintAndSteel(boolean allowFlintAndSteel) { 303 | this.allowFlintAndSteel = allowFlintAndSteel; 304 | } 305 | 306 | public boolean canFireSpread() { 307 | return allowFireSpread; 308 | } 309 | 310 | public void setAllowFireSpread(boolean allowFireSpread) { 311 | this.allowFireSpread = allowFireSpread; 312 | } 313 | 314 | public boolean canLavaFire() { 315 | return allowLavaFire; 316 | } 317 | 318 | public void setAllowLavaFire(boolean allowLavaFire) { 319 | this.allowLavaFire = allowLavaFire; 320 | } 321 | 322 | public boolean canLightning() { 323 | return allowLightning; 324 | } 325 | 326 | public void setAllowLightning(boolean allowLightning) { 327 | this.allowLightning = allowLightning; 328 | } 329 | 330 | public boolean canChestAccess() { 331 | return allowChestAccess; 332 | } 333 | 334 | public void setAllowChestAccess(boolean allowChestAccess) { 335 | this.allowChestAccess = allowChestAccess; 336 | } 337 | 338 | public boolean canPistons() { 339 | return allowPistons; 340 | } 341 | 342 | public void setAllowPistons(boolean allowPistons) { 343 | this.allowPistons = allowPistons; 344 | } 345 | 346 | public boolean canWaterFlow() { 347 | return allowWaterFlow; 348 | } 349 | 350 | public void setAllowWaterFlow(boolean allowWaterFlow) { 351 | this.allowWaterFlow = allowWaterFlow; 352 | } 353 | 354 | public boolean canLavaFlow() { 355 | return allowLavaFlow; 356 | } 357 | 358 | public void setAllowLavaFlow(boolean allowLavaFlow) { 359 | this.allowLavaFlow = allowLavaFlow; 360 | } 361 | 362 | public boolean canPlayerInteract() { 363 | return allowPlayerInteract; 364 | } 365 | 366 | public void setAllowPlayerInteract(boolean allowPlayerInteract) { 367 | this.allowPlayerInteract = allowPlayerInteract; 368 | } 369 | 370 | public boolean canVehiclePlacement() { 371 | return allowVehiclePlacement; 372 | } 373 | 374 | public void setAllowVehiclePlacement(boolean allowVehiclePlacement) { 375 | this.allowVehiclePlacement = allowVehiclePlacement; 376 | } 377 | 378 | public boolean canVehicleDestroy() { 379 | return allowVehicleDestroy; 380 | } 381 | 382 | public void setAllowVehicleDestroy(boolean allowVehicleDestroy) { 383 | this.allowVehicleDestroy = allowVehicleDestroy; 384 | } 385 | 386 | public boolean canSnowCollection() { 387 | return allowSnowCollection; 388 | } 389 | 390 | public void setAllowSnowCollection(boolean allowSnowCollection) { 391 | this.allowSnowCollection = allowSnowCollection; 392 | } 393 | 394 | public boolean canSnowMelt() { 395 | return allowSnowMelt; 396 | } 397 | 398 | public void setAllowSnowMelt(boolean allowSnowMelt) { 399 | this.allowSnowMelt = allowSnowMelt; 400 | } 401 | 402 | public boolean canIceForm() { 403 | return allowIceForm; 404 | } 405 | 406 | public void setAllowIceForm(boolean allowIceForm) { 407 | this.allowIceForm = allowIceForm; 408 | } 409 | 410 | public boolean canMushroomGrowth() { 411 | return allowMushroomGrowth; 412 | } 413 | 414 | public void setAllowMushroomGrowth(boolean allowMushroomGrowth) { 415 | this.allowMushroomGrowth = allowMushroomGrowth; 416 | } 417 | 418 | public boolean canLeafDecay() { 419 | return allowLeafDecay; 420 | } 421 | 422 | public void setAllowLeafDecay(boolean allowLeafDecay) { 423 | this.allowLeafDecay = allowLeafDecay; 424 | } 425 | 426 | public boolean canGrassGrowth() { 427 | return allowGrassGrowth; 428 | } 429 | 430 | public void setAllowGrassGrowth(boolean allowGrassGrowth) { 431 | this.allowGrassGrowth = allowGrassGrowth; 432 | } 433 | 434 | public boolean canMyceliumSpread() { 435 | return allowMyceliumSpread; 436 | } 437 | 438 | public void setAllowMyceliumSpread(boolean allowMyceliumSpread) { 439 | this.allowMyceliumSpread = allowMyceliumSpread; 440 | } 441 | 442 | public boolean canVineGrowth() { 443 | return allowVineGrowth; 444 | } 445 | 446 | public void setAllowVineGrowth(boolean allowVineGrowth) { 447 | this.allowVineGrowth = allowVineGrowth; 448 | } 449 | 450 | public boolean canPlayerInvincibility() { 451 | return allowPlayerInvincibility; 452 | } 453 | 454 | public void setAllowPlayerInvincibility(boolean allowPlayerInvincibility) { 455 | this.allowPlayerInvincibility = allowPlayerInvincibility; 456 | } 457 | 458 | public boolean isAllowFoodLevelChange() { 459 | return allowFoodLevelChange; 460 | } 461 | 462 | public void setAllowFoodLevelChange(boolean allowFoodLevelChange) { 463 | this.allowFoodLevelChange = allowFoodLevelChange; 464 | } 465 | 466 | public boolean isKeepInventory() { 467 | return keepInventory; 468 | } 469 | 470 | public void setKeepInventory(boolean keepInventory) { 471 | this.keepInventory = keepInventory; 472 | } 473 | 474 | public boolean isAllowDurabilityChange() { 475 | return allowDurabilityChange; 476 | } 477 | 478 | public void setAllowDurabilityChange(boolean allowDurabilityChange) { 479 | this.allowDurabilityChange = allowDurabilityChange; 480 | } 481 | 482 | public boolean isAllowTimeChange() { 483 | return allowTimeChange; 484 | } 485 | 486 | public void setAllowTimeChange(boolean allowTimeChange) { 487 | this.allowTimeChange = allowTimeChange; 488 | } 489 | 490 | public boolean isAllowWeatherChange() { 491 | return allowWeatherChange; 492 | } 493 | 494 | public void setAllowWeatherChange(boolean allowWeatherChange) { 495 | this.allowWeatherChange = allowWeatherChange; 496 | } 497 | 498 | public boolean isAllowInventoryChange() { 499 | return allowInventoryChange; 500 | } 501 | 502 | public void setAllowInventoryChange(boolean allowInventoryChange) { 503 | this.allowInventoryChange = allowInventoryChange; 504 | } 505 | 506 | } 507 | -------------------------------------------------------------------------------- /src/com/scarabcoder/gameapi/listener/SettingsListener.java: -------------------------------------------------------------------------------- 1 | package com.scarabcoder.gameapi.listener; 2 | 3 | import java.util.Random; 4 | 5 | import org.bukkit.Material; 6 | import org.bukkit.OfflinePlayer; 7 | import org.bukkit.entity.EntityType; 8 | import org.bukkit.entity.Player; 9 | import org.bukkit.event.EventHandler; 10 | import org.bukkit.event.EventPriority; 11 | import org.bukkit.event.Listener; 12 | import org.bukkit.event.block.Action; 13 | import org.bukkit.event.block.BlockBreakEvent; 14 | import org.bukkit.event.block.BlockFadeEvent; 15 | import org.bukkit.event.block.BlockFormEvent; 16 | import org.bukkit.event.block.BlockFromToEvent; 17 | import org.bukkit.event.block.BlockIgniteEvent; 18 | import org.bukkit.event.block.BlockPistonExtendEvent; 19 | import org.bukkit.event.block.BlockPistonRetractEvent; 20 | import org.bukkit.event.block.BlockPlaceEvent; 21 | import org.bukkit.event.block.BlockSpreadEvent; 22 | import org.bukkit.event.block.LeavesDecayEvent; 23 | import org.bukkit.event.entity.CreatureSpawnEvent; 24 | import org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason; 25 | import org.bukkit.event.entity.EntityChangeBlockEvent; 26 | import org.bukkit.event.entity.EntityDamageByEntityEvent; 27 | import org.bukkit.event.entity.EntityDamageEvent; 28 | import org.bukkit.event.entity.EntityDeathEvent; 29 | import org.bukkit.event.entity.EntityExplodeEvent; 30 | import org.bukkit.event.entity.FoodLevelChangeEvent; 31 | import org.bukkit.event.entity.PlayerDeathEvent; 32 | import org.bukkit.event.entity.ProjectileLaunchEvent; 33 | import org.bukkit.event.inventory.InventoryClickEvent; 34 | import org.bukkit.event.player.AsyncPlayerChatEvent; 35 | import org.bukkit.event.player.PlayerBedEnterEvent; 36 | import org.bukkit.event.player.PlayerDropItemEvent; 37 | import org.bukkit.event.player.PlayerInteractEvent; 38 | import org.bukkit.event.player.PlayerItemDamageEvent; 39 | import org.bukkit.event.player.PlayerRespawnEvent; 40 | import org.bukkit.event.vehicle.VehicleDestroyEvent; 41 | import org.bukkit.event.weather.LightningStrikeEvent; 42 | import org.bukkit.event.weather.WeatherChangeEvent; 43 | 44 | import com.scarabcoder.gameapi.game.ArenaSettings; 45 | import com.scarabcoder.gameapi.game.Game; 46 | import com.scarabcoder.gameapi.game.GamePlayer; 47 | import com.scarabcoder.gameapi.manager.ArenaManager; 48 | import com.scarabcoder.gameapi.manager.PlayerManager; 49 | import com.scarabcoder.gameapi.util.ScarabUtil; 50 | 51 | public class SettingsListener implements Listener{ 52 | 53 | 54 | @EventHandler(priority = EventPriority.LOWEST) 55 | public void playerInteract(PlayerInteractEvent e){ 56 | GamePlayer p = PlayerManager.getGamePlayer(e.getPlayer()); 57 | ArenaSettings settings = ArenaManager.getActiveSettings(p); 58 | if(settings != null){ 59 | if(p.isInGame()){ 60 | if(!settings.canPlayerInteract()){ 61 | e.setCancelled(true); 62 | return; 63 | } 64 | if(e.getAction().equals(Action.RIGHT_CLICK_BLOCK)){ 65 | //CHEST ACCESS 66 | if(e.getClickedBlock().getType().equals(Material.CHEST) || e.getClickedBlock().getType().equals(Material.TRAPPED_CHEST)){ 67 | if(!settings.canChestAccess()){ 68 | e.setCancelled(true); 69 | } 70 | } 71 | //FLINT & STEEL 72 | if(e.getItem() != null){ 73 | if(e.getItem().getType().equals(Material.FLINT_AND_STEEL)){ 74 | if(!settings.canFlintAndSteel()) e.setCancelled(true); 75 | } 76 | } 77 | } 78 | } 79 | } 80 | } 81 | 82 | @EventHandler 83 | public void onChat(AsyncPlayerChatEvent e){ 84 | GamePlayer player = PlayerManager.getGamePlayer(e.getPlayer()); 85 | ArenaSettings settings = ArenaManager.getActiveSettings(player); 86 | if(settings != null){ 87 | if(!settings.allowChat()) e.setCancelled(true); 88 | } 89 | } 90 | 91 | @EventHandler 92 | public void onWeatherChange(WeatherChangeEvent e){ 93 | ArenaSettings settings = ArenaManager.getActiveSettings(e.getWorld().getSpawnLocation()); 94 | if(settings != null){ 95 | if(!settings.isAllowWeatherChange()) e.setCancelled(true); 96 | } 97 | } 98 | 99 | @EventHandler(priority = EventPriority.LOWEST) 100 | public void explosionEvent(EntityExplodeEvent e){ 101 | ArenaSettings settings = ArenaManager.getActiveSettings(e.getLocation()); 102 | if(settings != null){ 103 | if(e.getEntityType().equals(EntityType.CREEPER)){ 104 | if(!settings.canCreeperExplosion()){ 105 | e.setCancelled(true); 106 | } 107 | }else if(e.getEntityType().equals(EntityType.FIREBALL)){ 108 | if(!settings.canGhastFireballExplosion()) e.setCancelled(true); 109 | }else if(e.getEntityType().equals(EntityType.PRIMED_TNT)){ 110 | if(!settings.canTNTExplosion()) e.setCancelled(true); 111 | }else{ 112 | if(!settings.canOtherExplosion()) e.setCancelled(true); 113 | } 114 | } 115 | } 116 | 117 | @EventHandler(priority = EventPriority.LOWEST) 118 | public void enderpearlEvent(ProjectileLaunchEvent e){ 119 | if(e.getEntity().getShooter() != null){ 120 | if(e.getEntity().getShooter() instanceof Player){ 121 | GamePlayer player = PlayerManager.getGamePlayer((Player) e.getEntity().getShooter()); 122 | ArenaSettings settings = ArenaManager.getActiveSettings(player); 123 | if(settings != null){ 124 | if(!ArenaManager.getActiveSettings(player).canEnderpearl()){ 125 | e.setCancelled(true); 126 | } 127 | } 128 | } 129 | } 130 | } 131 | 132 | @EventHandler(priority = EventPriority.LOWEST) 133 | public void entityGrief(EntityChangeBlockEvent e){ 134 | ArenaSettings settings = ArenaManager.getActiveSettings(e.getBlock().getLocation()); 135 | if(settings != null){ 136 | //EnderDragon 137 | if(!settings.canEnderDragonDestroy() && e.getEntityType().equals(EntityType.ENDER_DRAGON)) e.setCancelled(true); 138 | //Enderman 139 | if(!settings.canEndermanGrief() && e.getEntityType().equals(EntityType.ENDERMAN)) e.setCancelled(true); 140 | 141 | } 142 | } 143 | 144 | @EventHandler(priority = EventPriority.LOWEST) 145 | public void expDrop(EntityDeathEvent e){ 146 | ArenaSettings settings = ArenaManager.getActiveSettings(e.getEntity().getLocation()); 147 | if(settings != null){ 148 | if(!settings.canExpDrop()){ 149 | e.setDroppedExp(0); 150 | } 151 | } 152 | } 153 | 154 | @EventHandler(priority = EventPriority.LOWEST) 155 | public void blockSpread(BlockSpreadEvent e){ 156 | 157 | ArenaSettings settings = ArenaManager.getActiveSettings(e.getBlock().getLocation()); 158 | if(settings != null){ 159 | if(e.getNewState().getType().equals(Material.FIRE)){ 160 | if(!settings.canFireSpread()){ 161 | e.setCancelled(true); 162 | } 163 | } else if(e.getNewState().getType().equals(Material.GRASS)){ 164 | if(!settings.canGrassGrowth()) e.setCancelled(true); 165 | } else if(e.getNewState().getType().equals(Material.BROWN_MUSHROOM) || e.getNewState().getType().equals(Material.RED_MUSHROOM)){ 166 | if(!settings.canMushroomGrowth()) e.setCancelled(true); 167 | } else if(e.getNewState().getType().equals(Material.MYCEL)){ 168 | if(!settings.canMyceliumSpread()) e.setCancelled(true); 169 | } else if(e.getNewState().getType().equals(Material.VINE)){ 170 | if(!settings.canVineGrowth()) e.setCancelled(true); 171 | } 172 | } 173 | } 174 | 175 | @EventHandler(priority = EventPriority.LOWEST) 176 | public void blockForm(BlockFormEvent e){ 177 | ArenaSettings settings = ArenaManager.getActiveSettings(e.getBlock().getLocation()); 178 | if(settings != null){ 179 | if(e.getNewState().equals(Material.ICE)){ 180 | if(!settings.canIceForm()) e.setCancelled(true); 181 | 182 | }else if(e.getNewState().equals(Material.SNOW)){ 183 | if(!settings.canSnowCollection()) e.setCancelled(true); 184 | } 185 | } 186 | } 187 | 188 | @EventHandler(priority = EventPriority.LOWEST) 189 | public void itemDrop(PlayerDropItemEvent e){ 190 | ArenaSettings settings = ArenaManager.getActiveSettings(PlayerManager.getGamePlayer(e.getPlayer())); 191 | if(settings != null){ 192 | if(!settings.canItemDrop()) e.setCancelled(true); 193 | } 194 | } 195 | 196 | @EventHandler(priority = EventPriority.LOWEST) 197 | public void entityDamage(EntityDamageEvent e){ 198 | ArenaSettings settings = ArenaManager.getActiveSettings(e.getEntity().getLocation()); 199 | if(settings != null){ 200 | if(e.getEntity().getType().equals(EntityType.ITEM_FRAME)){ 201 | if(!settings.canItemFrameDamage()) e.setCancelled(true); 202 | }else if(e.getEntity().getType().equals(EntityType.PAINTING)){ 203 | if(!settings.canPaintingDamage()) e.setCancelled(true); 204 | }else if(e.getEntity().getType().equals(EntityType.PLAYER)){ 205 | GamePlayer player = PlayerManager.getGamePlayer((Player) e.getEntity()); 206 | ArenaSettings pSettings = ArenaManager.getActiveSettings(player); 207 | if(pSettings != null){ 208 | if(pSettings.canPlayerInvincibility()) e.setCancelled(true); 209 | } 210 | } 211 | } 212 | } 213 | 214 | @EventHandler(priority = EventPriority.LOWEST) 215 | public void igniteEvent(BlockIgniteEvent e){ 216 | ArenaSettings settings = ArenaManager.getActiveSettings(e.getBlock().getLocation()); 217 | if(settings != null){ 218 | if(e.getIgnitingBlock().getType().equals(Material.STATIONARY_LAVA) || e.getIgnitingBlock().getType().equals(Material.LAVA)){ 219 | if(!settings.canLavaFire()) e.setCancelled(true); 220 | } 221 | } 222 | } 223 | 224 | 225 | @EventHandler(priority = EventPriority.LOWEST) 226 | public void fluidFlow(BlockFromToEvent e){ 227 | ArenaSettings settings = ArenaManager.getActiveSettings(e.getBlock().getLocation()); 228 | if(settings != null){ 229 | if(e.getBlock().getType().equals(Material.LAVA)){ 230 | if(!settings.canLavaFlow()) e.setCancelled(true); 231 | }else if(e.getBlock().getType().equals(Material.WATER)){ 232 | if(!settings.canWaterFlow()) e.setCancelled(true); 233 | } 234 | } 235 | } 236 | 237 | @EventHandler(priority = EventPriority.LOWEST) 238 | public void leafDecay(LeavesDecayEvent e){ 239 | ArenaSettings settings = ArenaManager.getActiveSettings(e.getBlock().getLocation()); 240 | if(settings != null){ 241 | if(!settings.canLeafDecay()) e.setCancelled(true); 242 | } 243 | } 244 | 245 | @EventHandler(priority = EventPriority.LOWEST) 246 | public void lightningStrike(LightningStrikeEvent e){ 247 | ArenaSettings settings = ArenaManager.getActiveSettings(e.getLightning().getLocation()); 248 | if(settings != null){ 249 | if(!settings.canLightning()) e.setCancelled(true); 250 | } 251 | } 252 | 253 | @EventHandler(priority = EventPriority.LOWEST) 254 | public void allowMobSpawn(CreatureSpawnEvent e){ 255 | ArenaSettings settings = ArenaManager.getActiveSettings(e.getEntity().getLocation()); 256 | if(settings != null){ 257 | if(!settings.canMobSpawn() && e.getSpawnReason().equals(SpawnReason.NATURAL)) e.setCancelled(true); 258 | } 259 | } 260 | 261 | @EventHandler(priority = EventPriority.LOWEST) 262 | public void pistonExtend(BlockPistonExtendEvent e){ 263 | ArenaSettings settings = ArenaManager.getActiveSettings(e.getBlock().getLocation()); 264 | if(settings != null){ 265 | if(!settings.canPistons()) e.setCancelled(true); 266 | } 267 | } 268 | 269 | 270 | @EventHandler(priority = EventPriority.LOWEST) 271 | public void pistonRetract(BlockPistonRetractEvent e){ 272 | ArenaSettings settings = ArenaManager.getActiveSettings(e.getBlock().getLocation()); 273 | if(settings != null){ 274 | if(!settings.canPistons()) e.setCancelled(true); 275 | } 276 | } 277 | 278 | @EventHandler(priority = EventPriority.LOWEST) 279 | public void playerEnterBed(PlayerBedEnterEvent e){ 280 | ArenaSettings settings = ArenaManager.getActiveSettings(PlayerManager.getGamePlayer(e.getPlayer())); 281 | if(settings != null){ 282 | if(!settings.canPlayerSleep()) e.setCancelled(true); 283 | } 284 | } 285 | 286 | @EventHandler(priority = EventPriority.LOWEST) 287 | public void blockMelt(BlockFadeEvent e){ 288 | ArenaSettings settings = ArenaManager.getActiveSettings(e.getBlock().getLocation()); 289 | if(settings != null){ 290 | if(e.getBlock().getType().equals(Material.SNOW)){ 291 | if(!settings.canSnowMelt()) e.setCancelled(true); 292 | } 293 | } 294 | } 295 | 296 | @EventHandler(priority = EventPriority.LOWEST) 297 | public void vehicleDestroy(VehicleDestroyEvent e){ 298 | ArenaSettings settings = ArenaManager.getActiveSettings(e.getVehicle().getLocation()); 299 | if(settings != null){ 300 | if(!settings.canVehicleDestroy()) e.setCancelled(true); 301 | } 302 | } 303 | 304 | 305 | @EventHandler(priority = EventPriority.LOWEST) 306 | public void blockPlace(BlockPlaceEvent e){ 307 | ArenaSettings settings = ArenaManager.getActiveSettings(PlayerManager.getGamePlayer(e.getPlayer())); 308 | if(settings != null){ 309 | if(!settings.isCanBuild()) e.setCancelled(true); 310 | } 311 | } 312 | 313 | @EventHandler(priority = EventPriority.LOWEST) 314 | public void blockBreak(BlockBreakEvent e){ 315 | ArenaSettings settings = ArenaManager.getActiveSettings(PlayerManager.getGamePlayer(e.getPlayer())); 316 | if(settings != null){ 317 | if(!settings.isCanDestroy()){ 318 | e.setCancelled(true); 319 | }else if(!settings.getAllowBlockDrop()){ 320 | e.setCancelled(true); 321 | e.getBlock().setType(Material.AIR); 322 | } 323 | 324 | } 325 | } 326 | 327 | @EventHandler(priority = EventPriority.LOWEST) 328 | public void onFoodchange(FoodLevelChangeEvent e){ 329 | GamePlayer player = PlayerManager.getGamePlayer((Player)e.getEntity()); 330 | ArenaSettings settings = ArenaManager.getActiveSettings(player); 331 | if(settings != null){ 332 | if(!settings.isAllowFoodLevelChange()){ 333 | e.setCancelled(true); 334 | } 335 | } 336 | } 337 | 338 | @EventHandler(priority = EventPriority.LOWEST) 339 | public void playerDeath(PlayerDeathEvent e){ 340 | GamePlayer player = PlayerManager.getGamePlayer(e.getEntity()); 341 | ArenaSettings settings = ArenaManager.getActiveSettings(player); 342 | if(settings != null){ 343 | if(settings.isKeepInventory()){ 344 | e.setKeepInventory(true); 345 | } 346 | if(player.getGame().getGameSettings().shouldDisableVanillaDeathMessages()) e.setDeathMessage(""); 347 | } 348 | } 349 | 350 | @EventHandler(priority = EventPriority.LOWEST) 351 | public void onItemDurabilityChange(PlayerItemDamageEvent e){ 352 | GamePlayer player = PlayerManager.getGamePlayer(e.getPlayer()); 353 | ArenaSettings settings = ArenaManager.getActiveSettings(player); 354 | if(settings != null){ 355 | e.setCancelled(!settings.isAllowDurabilityChange()); 356 | } 357 | } 358 | 359 | @EventHandler 360 | public void onInventoryClick(InventoryClickEvent e){ 361 | GamePlayer player = PlayerManager.getGamePlayer((OfflinePlayer) e.getWhoClicked()); 362 | ArenaSettings settings = ArenaManager.getActiveSettings(player); 363 | if(settings != null){ 364 | if(!settings.isAllowInventoryChange()) e.setCancelled(true); 365 | } 366 | } 367 | 368 | 369 | @EventHandler(priority = EventPriority.LOWEST) 370 | public void playerRespawn(PlayerRespawnEvent e){ 371 | GamePlayer player = PlayerManager.getGamePlayer(e.getPlayer()); 372 | if(player.isOnline() && player.isInGame()){ 373 | Game game = player.getGame(); 374 | if(game.getGameSettings().shouldUseTeams()){ 375 | if(player.getTeam() != null){ 376 | e.setRespawnLocation((player.getTeam().getTeamSpawns().get(new Random().nextInt(player.getTeam().getTeamSpawns().size())))); 377 | } 378 | } 379 | 380 | return; 381 | } 382 | } 383 | 384 | @EventHandler(priority = EventPriority.LOWEST) 385 | public void playerDamagePlayer(EntityDamageByEntityEvent e){ 386 | if(ScarabUtil.isPlayerDamager(e) && e.getEntity() instanceof Player){ 387 | GamePlayer player = PlayerManager.getGamePlayer((Player) e.getEntity()); 388 | GamePlayer damager = ScarabUtil.getDamager(e); 389 | if(damager.isInGame()){ 390 | ArenaSettings settings = ArenaManager.getActiveSettings(damager); 391 | if(settings != null){ 392 | if(!settings.isCanPvP()){ 393 | e.setCancelled(true); 394 | }else{ 395 | if(player.isInGame()){ 396 | if(player.getGame().getID().equals(damager.getGame().getID())){ 397 | if(player.getTeam() != null && damager.getTeam() != null){ 398 | if(player.getTeam().getName().equals(damager.getTeam().getName()) && !player.getTeam().allowTeamDamage()) e.setCancelled(true); 399 | } 400 | } 401 | } 402 | } 403 | 404 | } 405 | } 406 | 407 | } 408 | } 409 | 410 | 411 | 412 | } 413 | -------------------------------------------------------------------------------- /src/com/scarabcoder/gameapi/game/Game.java: -------------------------------------------------------------------------------- 1 | package com.scarabcoder.gameapi.game; 2 | 3 | import java.util.ArrayList; 4 | import java.util.Collections; 5 | import java.util.HashMap; 6 | import java.util.List; 7 | import java.util.Random; 8 | import java.util.concurrent.CopyOnWriteArrayList; 9 | 10 | import org.bukkit.Bukkit; 11 | import org.bukkit.Location; 12 | import org.bukkit.plugin.Plugin; 13 | import org.bukkit.plugin.messaging.ChannelNotRegisteredException; 14 | 15 | import com.google.common.io.ByteArrayDataOutput; 16 | import com.google.common.io.ByteStreams; 17 | import com.scarabcoder.gameapi.GameAPI; 18 | import com.scarabcoder.gameapi.enums.GamePlayerType; 19 | import com.scarabcoder.gameapi.enums.GameStatus; 20 | import com.scarabcoder.gameapi.enums.TeamSpreadType; 21 | import com.scarabcoder.gameapi.event.AutoTeamCompensationEvent; 22 | import com.scarabcoder.gameapi.event.GameEndEvent; 23 | import com.scarabcoder.gameapi.event.GameStartEvent; 24 | import com.scarabcoder.gameapi.event.PlayerJoinGameEvent; 25 | import com.scarabcoder.gameapi.event.PlayerLeaveGameEvent; 26 | import com.scarabcoder.gameapi.manager.PlayerManager; 27 | import com.scarabcoder.gameapi.manager.TeamManager; 28 | import com.scarabcoder.gameapi.util.ScarabUtil; 29 | 30 | import net.md_5.bungee.api.ChatColor; 31 | 32 | public class Game { 33 | 34 | private String id; 35 | 36 | private HashMap playerModes = new HashMap(); 37 | 38 | private GameStatus status; 39 | 40 | private Arena arena; 41 | 42 | private GameSettings settings; 43 | 44 | private TeamManager teamManager; 45 | 46 | private PlayerManager playerManager; 47 | 48 | private String messagePrefix; 49 | 50 | private Plugin plugin; 51 | 52 | private List areas; 53 | 54 | private List players; 55 | 56 | private HashMap kills = new HashMap(); 57 | 58 | private List spawns; 59 | 60 | private boolean countingDown; 61 | 62 | private int currentCountdown; 63 | 64 | private Runnable loop; 65 | 66 | public Game(String id, Arena arena, GameStatus status, Plugin plugin){ 67 | this.id = id; 68 | this.arena = arena; 69 | this.plugin = plugin; 70 | this.teamManager = new TeamManager(); 71 | this.playerManager = new PlayerManager(); 72 | this.messagePrefix = ""; 73 | this.status = status; 74 | this.areas = new ArrayList(); 75 | this.players = new ArrayList(); 76 | this.settings = new GameSettings(); 77 | this.currentCountdown = 0; 78 | this.spawns = new ArrayList(); 79 | this.loop = new Runnable(){ 80 | 81 | @Override 82 | public void run() { 83 | 84 | }}; 85 | final Game game = this; 86 | Bukkit.getScheduler().scheduleSyncRepeatingTask(GameAPI.getPlugin(), new Runnable(){ 87 | @Override 88 | public void run() { 89 | if(game.getGameSettings().getAutomaticCountdown() && !game.isCountingDown() && game.getGameStatus().equals(GameStatus.WAITING)){ 90 | if(game.isMinimumPlayersFilled()){ 91 | game.setCountingDown(true); 92 | game.increaseCountdown(); 93 | game.sendMessage(ChatColor.GREEN + "Game starts in " + ChatColor.DARK_GREEN + game.getGameSettings().getCountdownTime() + ChatColor.GREEN + " seconds!"); 94 | } 95 | } 96 | if(game.isCountingDown()){ 97 | if(game.getCurrentCountdown() < game.getGameSettings().getCountdownTime()){ 98 | GameAPI.sendDebugMessage(game.getCurrentCountdown() % 10d + "", GameAPI.getPlugin()); 99 | if(game.getCurrentCountdown() % 10 == 0){ 100 | game.sendMessage(ChatColor.GREEN + "Game starts in " + ChatColor.DARK_GREEN + (game.getGameSettings().getCountdownTime() - game.getCurrentCountdown()) + ChatColor.GREEN + " seconds!"); 101 | }else if(game.getGameSettings().getCountdownTime() - game.getCurrentCountdown() <= 5){ 102 | game.sendMessage(ChatColor.GREEN + "Game starts in " + ChatColor.DARK_GREEN + (game.getGameSettings().getCountdownTime() - game.getCurrentCountdown()) + ChatColor.GREEN + " seconds!"); 103 | } 104 | game.increaseCountdown(); 105 | }else{ 106 | if(game.isMinimumPlayersFilled()){ 107 | game.startGame(); 108 | game.resetCurrentCountdown(); 109 | game.setCountingDown(false); 110 | }else{ 111 | game.sendMessage(ChatColor.RED + "Not enough players to start game."); 112 | game.resetCurrentCountdown(); 113 | game.setCountingDown(false); 114 | } 115 | } 116 | } 117 | game.getRunnable().run(); 118 | } 119 | 120 | }, 0L, 20L); 121 | } 122 | 123 | public int getKills(GamePlayer p){ 124 | return this.kills.get(p); 125 | } 126 | 127 | public void increaseKills(GamePlayer p, int amount){ 128 | this.kills.put(p, this.getKills(p) + amount); 129 | } 130 | 131 | public boolean isMinimumPlayersFilled(){ 132 | return this.getPlayers().size() >= this.getGameSettings().getMinimumPlayers(); 133 | } 134 | 135 | public void setPlayerMode(GamePlayerType type, GamePlayer player){ 136 | switch(type){ 137 | case PLAYER: 138 | if(player.isOnline()){ 139 | player.getOnlinePlayer().setGameMode(this.getGameSettings().getMode()); 140 | } 141 | break; 142 | case SPECTATOR: 143 | if(player.isOnline()){ 144 | player.getOnlinePlayer().setGameMode(this.getGameSettings().getSpectatorMode()); 145 | } 146 | break; 147 | default: 148 | break; 149 | 150 | } 151 | this.playerModes.put(player, type); 152 | } 153 | 154 | public GamePlayerType getGamePlayerType(GamePlayer player){ 155 | return this.playerModes.get(player); 156 | } 157 | 158 | public List getGamePlayerByMode(GamePlayerType type){ 159 | List players = new ArrayList(); 160 | for(GamePlayer player : this.getPlayers()){ 161 | if(this.getGamePlayerType(player).equals(type)){ 162 | players.add(player); 163 | } 164 | } 165 | return players; 166 | } 167 | 168 | public boolean isCountingDown() { 169 | return countingDown; 170 | } 171 | 172 | 173 | 174 | public void setCountingDown(boolean countingDown) { 175 | this.countingDown = countingDown; 176 | } 177 | 178 | 179 | 180 | /** 181 | * Add a game spawn. These are only used when teams are disabled, for use in place of team spawns. 182 | * @param location 183 | */ 184 | public void addSpawn(Location location){ 185 | this.spawns.add(location); 186 | } 187 | 188 | /** 189 | * Get all game spawns. These are only used when teams are disabled, for use in place of team spawns. 190 | * @param location 191 | */ 192 | public List getSpawns(){ 193 | return this.spawns; 194 | } 195 | 196 | /** 197 | * Utility variable. Get the current countdown, can be used to start off the game when there are enough players. 198 | * Starts at 0 and increases, subtract from GameSettings.getCountdownTime(). 199 | * @return Current countdown time variable. 200 | */ 201 | public int getCurrentCountdown(){ 202 | return this.currentCountdown; 203 | } 204 | 205 | /** 206 | * Utility variable. Get the current countdown, can be used to start off the game when there are enough players. 207 | * Starts at 0 and increases, subtract from GameSettings.getCountdownTime(). 208 | * Resets to 0. 209 | * @return Current countdown time variable. 210 | */ 211 | public int resetCurrentCountdown(){ 212 | this.currentCountdown = 0; 213 | return this.currentCountdown; 214 | } 215 | 216 | /** 217 | * Utility variable. Get the current countdown, can be used to start off the game when there are enough players. 218 | * Starts at 0 and increases, subtract from GameSettings.getCountdownTime(). 219 | * Increases countdown by 1. 220 | * @return Current countdown time variable. 221 | */ 222 | public int increaseCountdown(){ 223 | this.currentCountdown++; 224 | return this.currentCountdown; 225 | } 226 | 227 | /** 228 | * Add the area to the game. 229 | * @param area 230 | */ 231 | public void registerArea(Area area){ 232 | this.areas.add(area); 233 | } 234 | 235 | public void registerAreas(Area...areas){ 236 | for(Area area : areas){ 237 | this.registerArea(area); 238 | } 239 | } 240 | 241 | public Area getArea(String name){ 242 | for(Area area : this.areas){ 243 | if(area.getName().equals(name)) return area; 244 | } 245 | return null; 246 | } 247 | 248 | /** 249 | * Get the plugin that registered this minigame. 250 | * @return Bukkit Plugin 251 | */ 252 | public Plugin getRegisteringPlugin(){ 253 | return this.plugin; 254 | } 255 | 256 | /** 257 | * Set the current game status. 258 | * @param status 259 | */ 260 | public void setGameStatus(GameStatus status){ 261 | this.status = status; 262 | } 263 | 264 | /** 265 | * Start the game. Doesn't do much other then teleporting team members to their spawn and setting the game status. 266 | */ 267 | public void startGame(){ 268 | this.setGameStatus(GameStatus.INGAME); 269 | GameStartEvent ev = new GameStartEvent(this); 270 | if(this.getGameSettings().shouldTeleportPlayersOnGameStart()){ 271 | if(this.getGameSettings().shouldUseTeams()){ 272 | for(Team team : this.getTeamManager().getTeams()){ 273 | for(GamePlayer player : team.getPlayers()){ 274 | if(player.isOnline()){ 275 | Random rand = new Random(); 276 | player.getOnlinePlayer().teleport(team.getTeamSpawns().get(rand.nextInt(team.getTeamSpawns().size()))); 277 | } 278 | } 279 | } 280 | }else{ 281 | for(GamePlayer player : this.getPlayers()){ 282 | if(player.isOnline()){ 283 | player.getOnlinePlayer().teleport(this.getSpawns().get(new Random().nextInt(this.getSpawns().size()))); 284 | } 285 | } 286 | } 287 | } 288 | Bukkit.getPluginManager().callEvent(ev); 289 | } 290 | 291 | /** 292 | * End the game, kicking all players and resetting the arena. 293 | */ 294 | public void endGame(){ 295 | this.setGameStatus(GameStatus.RESTARTING); 296 | GameEndEvent ev = new GameEndEvent(this); 297 | Bukkit.getPluginManager().callEvent(ev); 298 | List players = new CopyOnWriteArrayList(this.getPlayers()); 299 | this.playerModes = new HashMap(); 300 | for(GamePlayer pl : players){ 301 | this.removePlayer(pl); 302 | } 303 | this.setGameStatus(GameStatus.WAITING); 304 | if(this.getGameSettings().shouldResetWorlds()){ 305 | final Game game = this; 306 | Bukkit.getScheduler().scheduleSyncDelayedTask(GameAPI.getPlugin(), new Runnable(){ 307 | 308 | @Override 309 | public void run() { 310 | game.arena.resetWorld(); 311 | } 312 | 313 | }, 5L); 314 | } 315 | } 316 | 317 | /** 318 | * Add a player to a randomly selected team. Team selection mode is defined by GameSettings.getTeamSpreadType(). 319 | * 320 | * @return If teams are disabled, all teams are full, or there aren't any registered teams, returns null. Otherwise, the Team that the player was added to. 321 | */ 322 | public Team addToTeam(GamePlayer player){ 323 | List teams = this.getTeamManager().getTeams(); 324 | if(!this.getGameSettings().shouldUseTeams()) return null; 325 | if(teams.size() == 0) return null; 326 | switch(this.getGameSettings().getTeamSpreadType()){ 327 | case EVEN: 328 | int lowest = this.getGameSettings().getMaximumTeamSize(); 329 | Team lowestTeam = null; 330 | for(Team team : teams){ 331 | if(team.getPlayers().size() <= lowest){ 332 | lowest = team.getPlayers().size(); 333 | lowestTeam = team; 334 | } 335 | } 336 | lowestTeam.addPlayer(player); 337 | return lowestTeam; 338 | case FIRST_AVAILABLE: 339 | for(Team team : teams){ 340 | if(team.getPlayers().size() < this.getGameSettings().getMaximumTeamSize()){ 341 | team.addPlayer(player); 342 | return team; 343 | } 344 | } 345 | return null; 346 | default: 347 | return null; 348 | 349 | } 350 | } 351 | 352 | public List getPlayersSortedByKills(){ 353 | List pls = this.players; 354 | Collections.sort(pls, (p1, p2) -> this.getKills(p1) > this.getKills(p2) ? 0 : 1); 355 | return pls; 356 | } 357 | 358 | /** 359 | * Add a player to the game. You must handle teleporting. Teams are not set here, use addToTeam(GamePlayer, [Team]). 360 | * Player will not be added if already part of the game. The GameMode set in GameSettings.getGameMode() will be applied here. 361 | * @param player 362 | */ 363 | public void addPlayer(GamePlayer player){ 364 | if(!this.players.contains(player)){ 365 | this.kills.put(player, 0); 366 | PlayerJoinGameEvent ev = new PlayerJoinGameEvent(player, this); 367 | this.players.add(player); 368 | player.setGame(this); 369 | if(player.isOnline()){ 370 | player.getOnlinePlayer().setGameMode(this.getGameSettings().getMode()); 371 | player.getOnlinePlayer().setFoodLevel(this.getGameSettings().getFoodLevel()); 372 | player.getOnlinePlayer().setHealth(this.getGameSettings().getHealthLevel()); 373 | if(this.getArena().getLobbySpawn() != null){ 374 | player.getOnlinePlayer().teleport(this.getArena().getLobbySpawn()); 375 | } 376 | } 377 | Bukkit.getPluginManager().callEvent(ev); 378 | this.setPlayerMode(ev.getGamePlayerType(), player); 379 | 380 | } 381 | } 382 | 383 | /** 384 | * Removes the player from the game, and sends them to the lobby set in GameSettings. 385 | * 386 | * @param player 387 | */ 388 | public void removePlayer(GamePlayer player){ 389 | if(player.isOnline()){ 390 | this.players.remove(player); 391 | if(this.getGameSettings().usesBungee()){ 392 | 393 | ByteArrayDataOutput out = ByteStreams.newDataOutput(); 394 | out.writeUTF("Connect"); 395 | out.writeUTF(this.getGameSettings().getLobbyServer()); 396 | 397 | try{ 398 | player.getOnlinePlayer().sendPluginMessage(GameAPI.getPlugin(), "BungeeCord", out.toByteArray()); 399 | } catch(ChannelNotRegisteredException e){ 400 | player.getOnlinePlayer().kickPlayer("Hub server not found, kicking instead."); 401 | } 402 | }else{ 403 | player.getOnlinePlayer().teleport(this.getGameSettings().getLobbyLocation()); 404 | } 405 | } 406 | if(player.getTeam() != null && this.getGameSettings().shouldUseTeams()){ 407 | Team team = player.getTeam(); 408 | player.getTeam().removePlayer(player); 409 | if(this.getTeamManager().getTeams().size() > 1 && 410 | this.getGameSettings().getAutomaticTeamSizeCompensationEnabled() && 411 | this.getGameSettings().getTeamSpreadType().equals(TeamSpreadType.EVEN)){ 412 | Team highestTeam = null; 413 | for(Team t : this.getTeamManager().getTeams()){ 414 | if(team.getPlayers().size() - 1 < t.getPlayers().size() && t.getPlayers().size() > 0){ 415 | if(highestTeam != null){ 416 | if(t.getPlayers().size() > highestTeam.getPlayers().size()){ 417 | highestTeam = t;; 418 | } 419 | }else{ 420 | highestTeam = t; 421 | } 422 | } 423 | } 424 | if(highestTeam != null){ 425 | AutoTeamCompensationEvent ev = new AutoTeamCompensationEvent(highestTeam, team, highestTeam.getPlayers().get(0), this); 426 | Bukkit.getPluginManager().callEvent(ev); 427 | if(!ev.isCancelled()) 428 | highestTeam.getPlayers().get(0).setTeam(team); 429 | 430 | } 431 | } 432 | } 433 | 434 | player.setGame(null); 435 | PlayerLeaveGameEvent ev = new PlayerLeaveGameEvent(player, this); 436 | Bukkit.getPluginManager().callEvent(ev); 437 | 438 | } 439 | 440 | /** 441 | * Set what happens every second in the game. 442 | * @param runnable Runnable object. 443 | */ 444 | public void setLoopRunnable(Runnable runnable){ 445 | this.loop = runnable; 446 | } 447 | 448 | /** 449 | * Get what happens every second in the game. 450 | * @return Runnable 451 | */ 452 | public Runnable getRunnable(){ 453 | return this.loop; 454 | } 455 | 456 | 457 | /** 458 | * Send a game message. Messages are prefixed with the set message prefix (set/getMessagePrefix()) 459 | * If you want to send without a prefix, use sendMessage(message, boolean usePrefix) 460 | * @param message Message to be sent. 461 | */ 462 | public void sendMessage(String message){ 463 | this.sendMessage(message, true); 464 | } 465 | 466 | /** 467 | * Send a game message. Messages are prefixed with the set message prefix (set/getMessagePrefix()) 468 | * If you want to send without a prefix, use sendMessage(message, boolean usePrefix) 469 | * @param message Message to be sent. 470 | */ 471 | public void sendMessage(String message, boolean usePrefix){ 472 | for(GamePlayer player : this.getPlayers()){ 473 | if(player.isOnline()){ 474 | player.getOnlinePlayer().sendMessage((usePrefix ? messagePrefix + " " : "") + message); 475 | } 476 | } 477 | } 478 | 479 | public void sendMessage(String message, boolean usePrefix, boolean centered){ 480 | if(centered) message = ScarabUtil.getCenteredMessage(message); 481 | sendMessage(message, usePrefix); 482 | } 483 | 484 | /** 485 | * Set the message prefix. For example, "[Survival Games]" 486 | * @param prefix Prefix to set. 487 | */ 488 | public void setMessagePrefix(String prefix){ 489 | this.messagePrefix = prefix; 490 | } 491 | 492 | /** 493 | * Get the message prefix. 494 | * @return String message prefix. 495 | */ 496 | public String getMessagePrefix(){ 497 | return this.messagePrefix; 498 | } 499 | 500 | /** 501 | * Get the unique ID for this game. 502 | * @return String name 503 | */ 504 | public String getID(){ 505 | return id; 506 | } 507 | 508 | /** 509 | * Get the current game's status 510 | * @return GameStatus 511 | */ 512 | public GameStatus getGameStatus(){ 513 | return this.status; 514 | } 515 | 516 | 517 | /** 518 | * Get the game settings, used for things like minimum and maximum player count. 519 | * @return 520 | */ 521 | public GameSettings getGameSettings(){ 522 | return this.settings; 523 | } 524 | 525 | /** 526 | * Get the Team Manager for this Game, used for creating/managing teams. 527 | * @return Team Manager 528 | */ 529 | public TeamManager getTeamManager(){ 530 | return this.teamManager; 531 | } 532 | 533 | /** 534 | * Get the Player Manager for this Game. 535 | * @return Player Manager 536 | */ 537 | public PlayerManager getPlayerManager(){ 538 | return this.playerManager; 539 | } 540 | 541 | /** 542 | * Get all the GamePlayers in this game. 543 | * @return List 544 | */ 545 | public List getPlayers(){ 546 | return this.players; 547 | } 548 | 549 | /** 550 | * Get all the areas registered to this Game. 551 | * @return List 552 | */ 553 | public List getAreas(){ 554 | return areas; 555 | } 556 | 557 | /** 558 | * Get the global arena object for this game. 559 | * @return Arena 560 | */ 561 | public Arena getArena(){ 562 | return this.arena; 563 | } 564 | 565 | } 566 | --------------------------------------------------------------------------------