mirror of
https://github.com/zoriya/PluginSDG.git
synced 2025-12-06 06:46:09 +00:00
Unstable gui, need implementing of the getGamesMap method. Added gui supporting game creation, game removal
This commit is contained in:
6
pom.xml
6
pom.xml
@@ -48,5 +48,11 @@
|
||||
<artifactId>worldedit-bukkit</artifactId>
|
||||
<version>7.1.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.jetbrains</groupId>
|
||||
<artifactId>annotations</artifactId>
|
||||
<version>RELEASE</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
@@ -114,6 +114,10 @@ public class GameManager extends JavaPlugin
|
||||
public void deleteGame(MiniGame game)
|
||||
{
|
||||
this._games.remove(game);
|
||||
for(Player player : game.getPlayerList())
|
||||
{
|
||||
this.removePlayer(player);
|
||||
}
|
||||
}
|
||||
|
||||
//! @brief Return a list of game whose GameType match a given type
|
||||
@@ -166,7 +170,7 @@ public class GameManager extends JavaPlugin
|
||||
Operations.complete(operation);
|
||||
clipboard.setOrigin(BlockVector3.at(nextGameLocation.getX(), nextGameLocation.getY(), nextGameLocation.getZ()));
|
||||
nextGameLocation.add(new Vector(200, 0, 0));
|
||||
return new GameMap(clipboard, world);
|
||||
return new GameMap(clipboard, world, name);
|
||||
}
|
||||
}
|
||||
catch (IOException | WorldEditException e)
|
||||
@@ -217,8 +221,16 @@ public class GameManager extends JavaPlugin
|
||||
_playerInGame.remove(player);
|
||||
}
|
||||
|
||||
|
||||
public MiniGame GetPlayerGame(Player player)
|
||||
{
|
||||
return _playerInGame.get(player);
|
||||
}
|
||||
|
||||
//TODO: implement getGamesMap returning the list of maps for a given GameType
|
||||
public GameMap[] getGamesMap(GameType type)
|
||||
{
|
||||
return new GameMap[0];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -14,11 +14,13 @@ public class GameMap
|
||||
public Location lobbyLocation;
|
||||
|
||||
public ArrayList<Location> spawnLocations;
|
||||
private String _mapName;
|
||||
|
||||
public GameMap() { }
|
||||
|
||||
public GameMap(Clipboard clipboard, World world)
|
||||
public GameMap(Clipboard clipboard, World world, String mapName)
|
||||
{
|
||||
this._mapName = mapName;
|
||||
BlockVector3 o = clipboard.getOrigin();
|
||||
this.lobbyLocation = new Location(world, o.getX(), o.getY(), o.getZ());
|
||||
for (BlockVector3 b : clipboard.getRegion())
|
||||
|
||||
@@ -14,11 +14,10 @@ public abstract class MiniGame
|
||||
protected int _maxPlayer = 4;
|
||||
protected boolean enforceMaxPlayer = true;
|
||||
|
||||
|
||||
public MiniGame(GameManager manager, String mapName, String name)
|
||||
{
|
||||
this._manager = manager;
|
||||
this._map = this._manager.generateMap(mapName);;
|
||||
this._map = this._manager.generateMap(mapName);
|
||||
this._players = new ArrayList<>();
|
||||
this.name = name;
|
||||
}
|
||||
@@ -44,7 +43,7 @@ public abstract class MiniGame
|
||||
//! @return True if the player has joined the game, false otherwise.
|
||||
public boolean join(Player player)
|
||||
{
|
||||
if (this.getMaxPlayers() < this.getCurrentPlayers() + 1)
|
||||
if (this.getMaxPlayers() > this.getCurrentPlayers() + 1)
|
||||
return false;
|
||||
this._players.add(player);
|
||||
player.teleport(this._map.lobbyLocation);
|
||||
@@ -56,7 +55,7 @@ public abstract class MiniGame
|
||||
//! @brief Can a player join this game
|
||||
public boolean isJoinable()
|
||||
{
|
||||
return this.getMaxPlayers() < this.getCurrentPlayers() + 1;
|
||||
return this.getMaxPlayers() > this.getCurrentPlayers() + 1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,8 +1,11 @@
|
||||
package moe.sdg.PluginSDG.gui;
|
||||
|
||||
import moe.sdg.PluginSDG.GameMap;
|
||||
import moe.sdg.PluginSDG.MiniGame;
|
||||
import moe.sdg.PluginSDG.enums.GameType;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
@@ -14,6 +17,14 @@ import java.util.ArrayList;
|
||||
|
||||
public class GameSelectorGui extends GuiInventory implements Listener
|
||||
{
|
||||
private String _guiMode = "default";
|
||||
|
||||
private final int gameDisplayEndSlot = 27;
|
||||
private final int gameDisplayStartSlot = 0;
|
||||
|
||||
//this is horrible we store potential map name and type in hope that we will eventually use it
|
||||
private String _map;
|
||||
private GameType _type;
|
||||
|
||||
public GameSelectorGui(GuiController invManager , String invTitle, Player player)
|
||||
{
|
||||
@@ -24,11 +35,14 @@ public class GameSelectorGui extends GuiInventory implements Listener
|
||||
protected void initializeItems()
|
||||
{
|
||||
ArrayList<MiniGame> gameList = this._guiController.getGameController().getGames();
|
||||
for(int i = 0; i < gameList.size() && i <27; i++)
|
||||
this._guiMode = "default";
|
||||
|
||||
blankMenu();
|
||||
|
||||
for(int i = gameDisplayStartSlot; i < gameList.size() && i < gameDisplayEndSlot; i++)
|
||||
{
|
||||
MiniGame game = (gameList.get(i));
|
||||
MiniGame playerGame = _guiController.getGameController().GetPlayerGame(this.player);
|
||||
|
||||
player.sendMessage("game name" + game.getName());
|
||||
if(game.isJoinable())
|
||||
this.inv.setItem(i, createGuiItem(Material.WHITE_WOOL, game.getName(), game.toString()));
|
||||
else
|
||||
@@ -37,47 +51,53 @@ public class GameSelectorGui extends GuiInventory implements Listener
|
||||
|
||||
this.inv.setItem(37, createGuiItem(Material.EMERALD_BLOCK, "Create a new game"));
|
||||
this.inv.setItem(43, createGuiItem(Material.REDSTONE_BLOCK, "Delete game"));
|
||||
|
||||
|
||||
}
|
||||
|
||||
//! @brief Empty the top part of the menu
|
||||
private void blankMenu()
|
||||
{
|
||||
for(int i = gameDisplayStartSlot; i < gameDisplayEndSlot; i++ )
|
||||
{
|
||||
this.inv.setItem(i, createGuiItem(Material.AIR,"a","a"));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
@EventHandler
|
||||
public void onInventoryClick(InventoryClickEvent event)
|
||||
{
|
||||
event.getWhoClicked().sendMessage("event");
|
||||
if (event.getInventory() != inv) return;
|
||||
|
||||
event.setCancelled(true);
|
||||
|
||||
final ItemStack clickedItem = event.getCurrentItem();
|
||||
|
||||
// verify current item is not null
|
||||
if (clickedItem == null || clickedItem.getType() == Material.AIR) return;
|
||||
|
||||
player.playSound(player.getLocation(), Sound.UI_BUTTON_CLICK, 10, 29);
|
||||
|
||||
switch (clickedItem.getType())
|
||||
{
|
||||
case REDSTONE_BLOCK:
|
||||
break;
|
||||
case WHITE_WOOL:
|
||||
case RED_WOOL:
|
||||
if(_guiMode.equals("delete")) deleteGame(event);
|
||||
break;
|
||||
case EMERALD_BLOCK:
|
||||
case GREEN_STAINED_GLASS_PANE:
|
||||
case MAP:
|
||||
createGame(event);
|
||||
break;
|
||||
case RED_WOOL:
|
||||
// deleteGame(event);
|
||||
case REDSTONE_BLOCK:
|
||||
case BONE_BLOCK:
|
||||
switchDeleteMode();
|
||||
break;
|
||||
}
|
||||
|
||||
final Player player = (Player) event.getWhoClicked();
|
||||
|
||||
// Using slots click is a best option for your inventory click's
|
||||
player.sendMessage("You clicked at slot " + event.getRawSlot());
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onInventoryClick(final InventoryDragEvent event)
|
||||
{
|
||||
event.getWhoClicked().sendMessage("event");
|
||||
if (event.getInventory() == inv) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
@@ -87,16 +107,98 @@ public class GameSelectorGui extends GuiInventory implements Listener
|
||||
{
|
||||
//TODO: add menu for selecting map and menu for selecting game type
|
||||
int i = 1;
|
||||
String name = event.getWhoClicked().getName();
|
||||
while ( _guiController.getGameController().getGameByName(name) != null)
|
||||
name = event.getWhoClicked().getName() + "#" + i++;
|
||||
this._guiController.getGameController().createGame(GameType.DeathMatch, "", name);
|
||||
|
||||
switch(_guiMode)
|
||||
{
|
||||
case "default":
|
||||
showGameModeList();
|
||||
break;
|
||||
case "mapSelect":
|
||||
_type = GameType.valueOf(event.getCurrentItem().getItemMeta().getDisplayName());
|
||||
showMapList();
|
||||
break;
|
||||
case "createGame":
|
||||
this._map = event.getCurrentItem().getItemMeta().getDisplayName();
|
||||
String name = event.getWhoClicked().getName();
|
||||
while ( _guiController.getGameController().getGameByName(name) != null)
|
||||
name = event.getWhoClicked().getName() + "#" + i++;
|
||||
|
||||
this._guiController.getGameController().createGame(GameType.DeathMatch, this._map, name);
|
||||
initializeItems();
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void deleteGame(InventoryClickEvent event)
|
||||
private void showGameModeList()
|
||||
{
|
||||
MiniGame game = (this._guiController.getGameController().getGames().get(event.getSlot())); // map inventory pos to pos in array
|
||||
game.destroy();
|
||||
blankMenu();
|
||||
for (GameType type : GameType.values())
|
||||
{
|
||||
if(type == GameType.None);
|
||||
// NOTE : Adding color to type.name will break the menu TOO BAD!
|
||||
inv.addItem( createGuiItem(Material.GREEN_STAINED_GLASS_PANE, type.name()));
|
||||
}
|
||||
_guiMode = "modeSelect";
|
||||
}
|
||||
|
||||
private void showMapList()
|
||||
{
|
||||
// NOTE : delete this once map list is properly implemented
|
||||
inv.addItem( createGuiItem(Material.MAP, "mapName"));
|
||||
|
||||
for (GameMap map : _guiController.getGameController().getGamesMap(this._type))
|
||||
{
|
||||
inv.addItem( createGuiItem(Material.MAP, this._type.name()));
|
||||
}
|
||||
_guiMode = "createGame";
|
||||
}
|
||||
|
||||
|
||||
//! @brief switch between deleting game on click and normal mode
|
||||
private void switchDeleteMode()
|
||||
{
|
||||
if(_guiMode.equals("delete"))
|
||||
{
|
||||
this.initializeItems();
|
||||
}
|
||||
else if(_guiMode.equals("default"))
|
||||
{
|
||||
this.initializeItems();
|
||||
this._guiMode = "delete";
|
||||
this.inv.setItem(43, createGuiItem(Material.BONE_BLOCK, "Delete game"));
|
||||
}
|
||||
}
|
||||
|
||||
//! @brief delete a game that was clicked on
|
||||
private void deleteGame(InventoryClickEvent event)
|
||||
{
|
||||
MiniGame game = mapInventoryToGameList(event.getRawSlot(), event);
|
||||
if(game != null)
|
||||
{
|
||||
game.destroy();
|
||||
} else {
|
||||
event.getWhoClicked().sendMessage(ChatColor.RED +"game does not exist");
|
||||
}
|
||||
this.initializeItems();
|
||||
|
||||
}
|
||||
|
||||
private void joinGame()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
//! @brief return a game from an inventory position. Return null if the slot position does not map to anything
|
||||
private MiniGame mapInventoryToGameList(int slotNumber, InventoryClickEvent event)
|
||||
{
|
||||
Player player = (Player) event.getWhoClicked();
|
||||
if(slotNumber < this._guiController.getGameController().getGames().size() && slotNumber >= gameDisplayStartSlot)
|
||||
{
|
||||
return this._guiController.getGameController().getGames().get(slotNumber); // map inventory pos to pos in array
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -40,6 +40,7 @@ public abstract class GuiInventory implements Listener
|
||||
final ItemMeta meta = item.getItemMeta();
|
||||
|
||||
// Set the name of the item
|
||||
if(meta == null) return item;
|
||||
meta.setDisplayName(name);
|
||||
|
||||
// Set the lore of the item
|
||||
|
||||
Reference in New Issue
Block a user