mirror of
https://github.com/DRE2N/DungeonsXL.git
synced 2025-02-17 21:02:12 +01:00
Multi group dungeons
This commit is contained in:
parent
aa8b952c7c
commit
92b10ec50a
@ -91,12 +91,7 @@ public class CreateCommand extends BRCommand {
|
||||
plugin.getLogger().info(messageConfig.getMessage(Messages.LOG_WORLD_GENERATION_FINISHED));
|
||||
|
||||
// Tp Player
|
||||
if (editWorld.getLobby() == null) {
|
||||
new DPlayer(player, editWorld.getWorld(), editWorld.getWorld().getSpawnLocation(), true);
|
||||
|
||||
} else {
|
||||
new DPlayer(player, editWorld.getWorld(), editWorld.getLobby(), true);
|
||||
}
|
||||
new DPlayer(player, editWorld.getWorld(), true);
|
||||
|
||||
} else {
|
||||
MessageUtil.sendMessage(player, messageConfig.getMessage(Messages.ERROR_NAME_TO_LONG));
|
||||
|
@ -72,12 +72,7 @@ public class EditCommand extends BRCommand {
|
||||
return;
|
||||
}
|
||||
|
||||
if (editWorld.getLobby() == null) {
|
||||
new DPlayer(player, editWorld.getWorld(), editWorld.getWorld().getSpawnLocation(), true);
|
||||
|
||||
} else {
|
||||
new DPlayer(player, editWorld.getWorld(), editWorld.getLobby(), true);
|
||||
}
|
||||
new DPlayer(player, editWorld.getWorld(), true);
|
||||
|
||||
}
|
||||
|
||||
|
@ -71,7 +71,7 @@ public class GameCommand extends BRCommand {
|
||||
groups += (group == game.getDGroups().get(0) ? "" : "&b, &e") + group.getName();
|
||||
}
|
||||
MessageUtil.sendMessage(sender, "&bGroups: &e" + groups);
|
||||
MessageUtil.sendMessage(sender, "&bGame type: &e" + game.getType());
|
||||
MessageUtil.sendMessage(sender, "&bGame type: &e" + (game.getType() == null ? "Not started yet" : game.getType()));
|
||||
MessageUtil.sendMessage(sender, "&bDungeon: &e" + (dGroup.getDungeonName() == null ? "N/A" : dGroup.getDungeonName()));
|
||||
MessageUtil.sendMessage(sender, "&bMap: &e" + (dGroup.getMapName() == null ? "N/A" : dGroup.getMapName()));
|
||||
}
|
||||
|
@ -166,12 +166,12 @@ public class PlayCommand extends BRCommand {
|
||||
|
||||
if (dGroup.getGameWorld().getLocLobby() == null) {
|
||||
for (Player groupPlayer : dGroup.getPlayers()) {
|
||||
new DPlayer(groupPlayer, dGroup.getGameWorld().getWorld(), dGroup.getGameWorld().getWorld().getSpawnLocation(), false);
|
||||
new DPlayer(groupPlayer, dGroup.getGameWorld());
|
||||
}
|
||||
|
||||
} else {
|
||||
for (Player groupPlayer : dGroup.getPlayers()) {
|
||||
new DPlayer(groupPlayer, dGroup.getGameWorld().getWorld(), dGroup.getGameWorld().getLocLobby(), false);
|
||||
new DPlayer(groupPlayer, dGroup.getGameWorld());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -57,7 +57,7 @@ public class EditWorld {
|
||||
private int id;
|
||||
private Location lobby;
|
||||
private CopyOnWriteArrayList<String> invitedPlayers = new CopyOnWriteArrayList<>();
|
||||
private CopyOnWriteArrayList<Block> sign = new CopyOnWriteArrayList<>();
|
||||
private CopyOnWriteArrayList<Block> signs = new CopyOnWriteArrayList<>();
|
||||
|
||||
public EditWorld() {
|
||||
plugin.getEditWorlds().add(this);
|
||||
@ -188,18 +188,18 @@ public class EditWorld {
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the sign
|
||||
* @return the signs
|
||||
*/
|
||||
public CopyOnWriteArrayList<Block> getSign() {
|
||||
return sign;
|
||||
public CopyOnWriteArrayList<Block> getSigns() {
|
||||
return signs;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param sign
|
||||
* the sign to set
|
||||
*/
|
||||
public void setSign(CopyOnWriteArrayList<Block> sign) {
|
||||
this.sign = sign;
|
||||
public void setSigns(CopyOnWriteArrayList<Block> signs) {
|
||||
this.signs = signs;
|
||||
}
|
||||
|
||||
public void generate() {
|
||||
@ -231,8 +231,8 @@ public class EditWorld {
|
||||
|
||||
try {
|
||||
ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream(new File(plugin.getDataFolder(), "/maps/" + mapName + "/DXLData.data")));
|
||||
out.writeInt(sign.size());
|
||||
for (Block sign : this.sign) {
|
||||
out.writeInt(signs.size());
|
||||
for (Block sign : signs) {
|
||||
out.writeInt(sign.getX());
|
||||
out.writeInt(sign.getY());
|
||||
out.writeInt(sign.getZ());
|
||||
@ -368,7 +368,7 @@ public class EditWorld {
|
||||
int z = os.readInt();
|
||||
Block block = editWorld.world.getBlockAt(x, y, z);
|
||||
editWorld.checkSign(block);
|
||||
editWorld.sign.add(block);
|
||||
editWorld.signs.add(block);
|
||||
}
|
||||
os.close();
|
||||
|
||||
|
@ -19,6 +19,7 @@ package io.github.dre2n.dungeonsxl.game;
|
||||
import io.github.dre2n.dungeonsxl.DungeonsXL;
|
||||
import io.github.dre2n.dungeonsxl.player.DGroup;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@ -30,16 +31,28 @@ public class Game {
|
||||
protected static DungeonsXL plugin = DungeonsXL.getInstance();
|
||||
|
||||
private List<DGroup> dGroups = new ArrayList<>();
|
||||
private boolean started;
|
||||
private GameType type;
|
||||
private GameWorld world;
|
||||
|
||||
public Game(DGroup dGroup) {
|
||||
this.dGroups.add(dGroup);
|
||||
this.type = GameTypeDefault.DEFAULT;
|
||||
dGroups.add(dGroup);
|
||||
started = false;
|
||||
|
||||
plugin.getGames().add(this);
|
||||
}
|
||||
|
||||
public Game(DGroup dGroup, GameType type) {
|
||||
this.dGroups.add(dGroup);
|
||||
public Game(DGroup dGroup, GameType type, GameWorld world) {
|
||||
this(new ArrayList<>(Arrays.asList(dGroup)), type, world);
|
||||
}
|
||||
|
||||
public Game(List<DGroup> dGroups, GameType type, GameWorld world) {
|
||||
this.dGroups = dGroups;
|
||||
this.type = type;
|
||||
this.world = world;
|
||||
this.started = true;
|
||||
|
||||
plugin.getGames().add(this);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -65,6 +78,21 @@ public class Game {
|
||||
dGroups.remove(dGroup);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return if the Game has started yet
|
||||
*/
|
||||
public boolean hasStarted() {
|
||||
return started;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param started
|
||||
* set if the Game has started yet
|
||||
*/
|
||||
public void setStarted(boolean started) {
|
||||
this.started = started;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the type
|
||||
*/
|
||||
@ -80,6 +108,21 @@ public class Game {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the GameWorld connected to the Game
|
||||
*/
|
||||
public GameWorld getWorld() {
|
||||
return world;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param gameWorld
|
||||
* the GameWorld to connect to the Game
|
||||
*/
|
||||
public void setWorld(GameWorld world) {
|
||||
this.world = world;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return if the DGroup list is empty
|
||||
*/
|
||||
@ -104,7 +147,7 @@ public class Game {
|
||||
|
||||
public static Game getByGameWorld(GameWorld gameWorld) {
|
||||
for (Game game : plugin.getGames()) {
|
||||
if (game.getDGroups().get(0).getGameWorld().equals(gameWorld)) {
|
||||
if (game.getWorld().equals(gameWorld)) {
|
||||
return game;
|
||||
}
|
||||
}
|
||||
|
@ -39,6 +39,7 @@ import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.io.ObjectInputStream;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Chunk;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
@ -62,8 +63,6 @@ public class GameWorld {
|
||||
protected static DungeonsXL plugin = DungeonsXL.getInstance();
|
||||
|
||||
// Variables
|
||||
private Game game;
|
||||
|
||||
private boolean tutorial;
|
||||
|
||||
private CopyOnWriteArrayList<GamePlaceableBlock> placeableBlocks = new CopyOnWriteArrayList<>();
|
||||
@ -105,18 +104,17 @@ public class GameWorld {
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the game
|
||||
* @return
|
||||
* the Game connected to the GameWorld
|
||||
*/
|
||||
public Game getGame() {
|
||||
return game;
|
||||
}
|
||||
for (Game game : plugin.getGames()) {
|
||||
if (game.getWorld() == this) {
|
||||
return game;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param game
|
||||
* the game to set
|
||||
*/
|
||||
public void setGame(Game game) {
|
||||
this.game = game;
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -341,6 +339,10 @@ public class GameWorld {
|
||||
* @return the worldConfig
|
||||
*/
|
||||
public WorldConfig getConfig() {
|
||||
if (worldConfig == null) {
|
||||
return plugin.getDefaultConfig();
|
||||
}
|
||||
|
||||
return worldConfig;
|
||||
}
|
||||
|
||||
@ -374,7 +376,7 @@ public class GameWorld {
|
||||
}
|
||||
|
||||
public void startGame() {
|
||||
GameWorldStartGameEvent event = new GameWorldStartGameEvent(this, game);
|
||||
GameWorldStartGameEvent event = new GameWorldStartGameEvent(this, getGame());
|
||||
|
||||
if (event.isCancelled()) {
|
||||
return;
|
||||
@ -472,39 +474,42 @@ public class GameWorld {
|
||||
// Secure Objects
|
||||
gameWorld.secureObjects = gameWorld.worldConfig.getSecureObjects();
|
||||
|
||||
// World
|
||||
FileUtil.copyDirectory(file, new File("DXL_Game_" + gameWorld.id), DungeonsXL.EXCLUDED_FILES);
|
||||
if (Bukkit.getWorld("DXL_Game_" + gameWorld.id) == null) {
|
||||
|
||||
// Id File
|
||||
File idFile = new File("DXL_Game_" + gameWorld.id + "/.id_" + name);
|
||||
try {
|
||||
idFile.createNewFile();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
// World
|
||||
FileUtil.copyDirectory(file, new File("DXL_Game_" + gameWorld.id), DungeonsXL.EXCLUDED_FILES);
|
||||
|
||||
gameWorld.world = plugin.getServer().createWorld(WorldCreator.name("DXL_Game_" + gameWorld.id));
|
||||
|
||||
ObjectInputStream os;
|
||||
try {
|
||||
os = new ObjectInputStream(new FileInputStream(new File(plugin.getDataFolder() + "/maps/" + gameWorld.mapName + "/DXLData.data")));
|
||||
|
||||
int length = os.readInt();
|
||||
for (int i = 0; i < length; i++) {
|
||||
int x = os.readInt();
|
||||
int y = os.readInt();
|
||||
int z = os.readInt();
|
||||
Block block = gameWorld.world.getBlockAt(x, y, z);
|
||||
gameWorld.checkSign(block);
|
||||
// Id File
|
||||
File idFile = new File("DXL_Game_" + gameWorld.id + "/.id_" + name);
|
||||
try {
|
||||
idFile.createNewFile();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
os.close();
|
||||
gameWorld.world = plugin.getServer().createWorld(WorldCreator.name("DXL_Game_" + gameWorld.id));
|
||||
|
||||
} catch (FileNotFoundException exception) {
|
||||
plugin.getLogger().info("Could not find any sign data for the world \"" + name + "\"!");
|
||||
ObjectInputStream os;
|
||||
try {
|
||||
os = new ObjectInputStream(new FileInputStream(new File(plugin.getDataFolder() + "/maps/" + gameWorld.mapName + "/DXLData.data")));
|
||||
|
||||
} catch (IOException exception) {
|
||||
exception.printStackTrace();
|
||||
int length = os.readInt();
|
||||
for (int i = 0; i < length; i++) {
|
||||
int x = os.readInt();
|
||||
int y = os.readInt();
|
||||
int z = os.readInt();
|
||||
Block block = gameWorld.world.getBlockAt(x, y, z);
|
||||
gameWorld.checkSign(block);
|
||||
}
|
||||
|
||||
os.close();
|
||||
|
||||
} catch (FileNotFoundException exception) {
|
||||
plugin.getLogger().info("Could not find any sign data for the world \"" + name + "\"!");
|
||||
|
||||
} catch (IOException exception) {
|
||||
exception.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
return gameWorld;
|
||||
|
@ -20,6 +20,7 @@ import io.github.dre2n.commons.util.BlockUtil;
|
||||
import io.github.dre2n.commons.util.messageutil.MessageUtil;
|
||||
import io.github.dre2n.dungeonsxl.DungeonsXL;
|
||||
import io.github.dre2n.dungeonsxl.config.MessageConfig.Messages;
|
||||
import io.github.dre2n.dungeonsxl.game.Game;
|
||||
import io.github.dre2n.dungeonsxl.game.GameWorld;
|
||||
import io.github.dre2n.dungeonsxl.player.DGroup;
|
||||
import io.github.dre2n.dungeonsxl.player.DPlayer;
|
||||
@ -162,28 +163,48 @@ public class DPortal extends GlobalProtection {
|
||||
* the player to teleport into his dungeon
|
||||
*/
|
||||
public void teleport(Player player) {
|
||||
DGroup dgroup = DGroup.getByPlayer(player);
|
||||
DGroup dGroup = DGroup.getByPlayer(player);
|
||||
|
||||
if (dgroup == null) {
|
||||
if (dGroup == null) {
|
||||
MessageUtil.sendMessage(player, plugin.getMessageConfig().getMessage(Messages.ERROR_JOIN_GROUP));
|
||||
return;
|
||||
}
|
||||
|
||||
if (dgroup.getGameWorld() == null) {
|
||||
dgroup.setGameWorld(GameWorld.load(DGroup.getByPlayer(player).getMapName()));
|
||||
GameWorld target = dGroup.getGameWorld();
|
||||
Game game = Game.getByDGroup(dGroup);
|
||||
|
||||
if (target == null && game != null) {
|
||||
target = game.getWorld();
|
||||
}
|
||||
|
||||
if (dgroup.getGameWorld() == null) {
|
||||
if (target == null) {
|
||||
if (game != null) {
|
||||
for (DGroup otherTeam : game.getDGroups()) {
|
||||
if (otherTeam.getGameWorld() != null) {
|
||||
target = otherTeam.getGameWorld();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (target == null) {
|
||||
target = GameWorld.load(dGroup.getMapName());
|
||||
dGroup.setGameWorld(target);
|
||||
}
|
||||
|
||||
if (target == null) {
|
||||
MessageUtil.sendMessage(player, plugin.getMessageConfig().getMessage(Messages.ERROR_DUNGEON_NOT_EXIST, DGroup.getByPlayer(player).getMapName()));
|
||||
return;
|
||||
}
|
||||
|
||||
if (dgroup.getGameWorld().getLocLobby() == null) {
|
||||
new DPlayer(player, dgroup.getGameWorld().getWorld(), dgroup.getGameWorld().getWorld().getSpawnLocation(), false);
|
||||
|
||||
} else {
|
||||
new DPlayer(player, dgroup.getGameWorld().getWorld(), dgroup.getGameWorld().getLocLobby(), false);
|
||||
if (game != null) {
|
||||
game.setWorld(target);
|
||||
}
|
||||
|
||||
dGroup.setGameWorld(target);
|
||||
|
||||
new DPlayer(player, target);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -276,6 +297,10 @@ public class DPortal extends GlobalProtection {
|
||||
public static DPortal getByBlock(Block block) {
|
||||
for (GlobalProtection protection : protections.getProtections(DPortal.class)) {
|
||||
DPortal portal = (DPortal) protection;
|
||||
if (portal.getBlock1() == null || portal.getBlock2() == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
int x1 = portal.block1.getX(), y1 = portal.block1.getY(), z1 = portal.block1.getZ();
|
||||
int x2 = portal.block2.getX(), y2 = portal.block2.getY(), z2 = portal.block2.getZ();
|
||||
int x3 = block.getX(), y3 = block.getY(), z3 = block.getZ();
|
||||
|
@ -511,7 +511,8 @@ public class GameSign extends GlobalProtection {
|
||||
Sign topSign = (Sign) topBlock.getState();
|
||||
|
||||
if (topSign.getLine(0).equals(NEW_GAME)) {
|
||||
gameSign.games[column] = new Game(dGroup);
|
||||
Game game = new Game(dGroup);
|
||||
gameSign.games[column] = game;
|
||||
gameSign.update();
|
||||
|
||||
} else if (topSign.getLine(0).equals(JOIN_GAME)) {
|
||||
|
@ -89,18 +89,20 @@ public class BlockListener implements Listener {
|
||||
return;
|
||||
}
|
||||
|
||||
// Editworld Signs
|
||||
// EditWorld Signs
|
||||
EditWorld editWorld = EditWorld.getByWorld(block.getWorld());
|
||||
if (editWorld != null) {
|
||||
editWorld.getSign().remove(event.getBlock());
|
||||
editWorld.getSigns().remove(event.getBlock());
|
||||
return;
|
||||
}
|
||||
|
||||
// Deny GameWorld Blocks
|
||||
// Deny GameWorld block breaking
|
||||
GameWorld gameWorld = GameWorld.getByWorld(block.getWorld());
|
||||
if (gameWorld != null) {
|
||||
for (DSign dSign : gameWorld.getDSigns()) {
|
||||
if (dSign.getSign().equals(block)) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@ -112,6 +114,9 @@ public class BlockListener implements Listener {
|
||||
} else if (!gameType.canBuild()) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
||||
} else {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -220,7 +225,7 @@ public class BlockListener implements Listener {
|
||||
|
||||
if (dsign.check()) {
|
||||
editWorld.checkSign(block);
|
||||
editWorld.getSign().add(block);
|
||||
editWorld.getSigns().add(block);
|
||||
MessageUtil.sendMessage(player, plugin.getMessageConfig().getMessage(Messages.PLAYER_SIGN_CREATED));
|
||||
|
||||
} else {
|
||||
|
@ -127,6 +127,10 @@ public class EntityListener implements Listener {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!game.hasStarted()) {
|
||||
return;
|
||||
}
|
||||
|
||||
WorldConfig config = gameWorld.getConfig();
|
||||
GameType type = game.getType();
|
||||
|
||||
|
@ -81,7 +81,7 @@ public class PlayerListener implements Listener {
|
||||
@EventHandler(priority = EventPriority.HIGH)
|
||||
public void onDeath(PlayerDeathEvent event) {
|
||||
Player player = event.getEntity();
|
||||
final DPlayer dPlayer = DPlayer.getByPlayer(player);
|
||||
DPlayer dPlayer = DPlayer.getByPlayer(player);
|
||||
|
||||
GameWorld gameWorld = GameWorld.getByWorld(player.getLocation().getWorld());
|
||||
if (gameWorld == null) {
|
||||
@ -132,8 +132,7 @@ public class PlayerListener implements Listener {
|
||||
MessageUtil.broadcastMessage(messageConfig.getMessage(Messages.PLAYER_DEATH_KICK, player.getName()));
|
||||
dPlayer.leave();
|
||||
if (gameWorld.getConfig().getKeepInventoryOnEscape()) {
|
||||
/*new org.bukkit.scheduler.BukkitRunnable() {public void run(){*/
|
||||
dPlayer.applyRespawnInventory();/*}}.runTaskLater(plugin, 1);*/
|
||||
dPlayer.applyRespawnInventory();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -406,13 +405,8 @@ public class PlayerListener implements Listener {
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGH)
|
||||
public void onPortal(PlayerPortalEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
Location location = event.getFrom();
|
||||
DPortal dPortal = DPortal.getByLocation(location);
|
||||
|
||||
if (dPortal != null) {
|
||||
if (DPortal.getByLocation(event.getFrom()) != null) {
|
||||
event.setCancelled(true);
|
||||
dPortal.teleport(player);
|
||||
}
|
||||
}
|
||||
|
||||
@ -557,9 +551,7 @@ public class PlayerListener implements Listener {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (dGroup.getGameWorld().getLocLobby() != null) {
|
||||
new DPlayer(player, dGroup.getGameWorld().getWorld(), dGroup.getGameWorld().getLocLobby(), false);
|
||||
}
|
||||
new DPlayer(player, dGroup.getGameWorld());
|
||||
}
|
||||
}
|
||||
|
||||
@ -648,11 +640,14 @@ public class PlayerListener implements Listener {
|
||||
Player player = event.getPlayer();
|
||||
DLootInventory inventory = DLootInventory.getByPlayer(player);
|
||||
|
||||
if (inventory == null) {
|
||||
DPortal dPortal = DPortal.getByLocation(player.getEyeLocation());
|
||||
//TODO: Fix chat spam
|
||||
if (dPortal != null) {
|
||||
dPortal.teleport(player);
|
||||
return;
|
||||
}
|
||||
|
||||
if (player.getLocation().getBlock().getType() == Material.PORTAL) {
|
||||
if (inventory == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -76,43 +76,11 @@ public class DGroup {
|
||||
}
|
||||
|
||||
public DGroup(Player player, String identifier, boolean multiFloor) {
|
||||
plugin.getDGroups().add(this);
|
||||
name = "Group_" + plugin.getDGroups().size();
|
||||
|
||||
captain = player;
|
||||
players.add(player);
|
||||
|
||||
Dungeon dungeon = plugin.getDungeons().getDungeon(identifier);
|
||||
if (multiFloor && dungeon != null) {
|
||||
dungeonName = identifier;
|
||||
mapName = dungeon.getConfig().getStartFloor();
|
||||
unplayedFloors = dungeon.getConfig().getFloors();
|
||||
|
||||
} else {
|
||||
mapName = identifier;
|
||||
}
|
||||
playing = false;
|
||||
floorCount = 0;
|
||||
this("Group_" + plugin.getDGroups().size(), player, identifier, multiFloor);
|
||||
}
|
||||
|
||||
public DGroup(String name, Player player, String identifier, boolean multiFloor) {
|
||||
plugin.getDGroups().add(this);
|
||||
this.name = name;
|
||||
|
||||
captain = player;
|
||||
players.add(player);
|
||||
|
||||
Dungeon dungeon = plugin.getDungeons().getDungeon(identifier);
|
||||
if (multiFloor && dungeon != null) {
|
||||
dungeonName = identifier;
|
||||
mapName = dungeon.getConfig().getStartFloor();
|
||||
unplayedFloors = dungeon.getConfig().getFloors();
|
||||
|
||||
} else {
|
||||
mapName = identifier;
|
||||
}
|
||||
playing = false;
|
||||
floorCount = 0;
|
||||
this(name, player, new CopyOnWriteArrayList<>(Arrays.asList(player)), identifier, multiFloor);
|
||||
}
|
||||
|
||||
public DGroup(String name, Player captain, List<Player> players, String identifier, boolean multiFloor) {
|
||||
@ -462,7 +430,7 @@ public class DGroup {
|
||||
*/
|
||||
public void delete() {
|
||||
plugin.getDGroups().remove(this);
|
||||
if (Game.getByDGroup(this) != null){
|
||||
if (Game.getByDGroup(this) != null) {
|
||||
Game.getByDGroup(this).removeDGroup(this);
|
||||
}
|
||||
GameSign.updatePerGame(Game.getByDGroup(this));
|
||||
@ -491,8 +459,6 @@ public class DGroup {
|
||||
}
|
||||
}
|
||||
|
||||
gameWorld.setGame(game);
|
||||
|
||||
DGroupStartFloorEvent event = new DGroupStartFloorEvent(this, gameWorld);
|
||||
|
||||
if (event.isCancelled()) {
|
||||
@ -500,7 +466,13 @@ public class DGroup {
|
||||
}
|
||||
|
||||
playing = true;
|
||||
gameWorld.startGame();
|
||||
|
||||
if (gameWorld != null) {
|
||||
if (!gameWorld.isPlaying()) {
|
||||
gameWorld.startGame();
|
||||
}
|
||||
}
|
||||
|
||||
floorCount++;
|
||||
|
||||
for (Player player : getPlayers()) {
|
||||
|
@ -92,12 +92,17 @@ public class DPlayer extends DGlobalPlayer {
|
||||
private int initialLives = -1;
|
||||
private int lives;
|
||||
|
||||
public DPlayer(Player player, World world, Location teleport, boolean editing) {
|
||||
public DPlayer(Player player, GameWorld gameWorld) {
|
||||
this(player, gameWorld.getWorld(), false);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public DPlayer(Player player, World world, boolean editing) {
|
||||
super(player);
|
||||
|
||||
this.world = world;
|
||||
|
||||
double health = ((Damageable) player).getHealth();
|
||||
double health = player.getHealth();
|
||||
|
||||
if (!Version.andHigher(Version.MC1_9).contains(CompatibilityHandler.getInstance().getVersion())) {
|
||||
savePlayer = new DSavePlayer(player.getName(), player.getUniqueId(), player.getLocation(), player.getInventory().getContents(), player.getInventory().getArmorContents(), null, player.getLevel(),
|
||||
@ -109,9 +114,11 @@ public class DPlayer extends DGlobalPlayer {
|
||||
}
|
||||
this.editing = editing;
|
||||
|
||||
Location teleport;
|
||||
if (this.editing) {
|
||||
this.getPlayer().setGameMode(GameMode.CREATIVE);
|
||||
clearPlayerData();
|
||||
teleport = EditWorld.getByWorld(world).getLobby();
|
||||
|
||||
} else {
|
||||
WorldConfig worldConfig = GameWorld.getByWorld(world).getConfig();
|
||||
@ -124,9 +131,15 @@ public class DPlayer extends DGlobalPlayer {
|
||||
}
|
||||
initialLives = worldConfig.getInitialLives();
|
||||
lives = initialLives;
|
||||
teleport = GameWorld.getByWorld(world).getLocLobby();
|
||||
}
|
||||
|
||||
PlayerUtil.secureTeleport(this.getPlayer(), teleport);
|
||||
if (teleport == null) {
|
||||
PlayerUtil.secureTeleport(player, world.getSpawnLocation());
|
||||
|
||||
} else {
|
||||
PlayerUtil.secureTeleport(player, teleport);
|
||||
}
|
||||
}
|
||||
|
||||
public void clearPlayerData() {
|
||||
@ -496,12 +509,10 @@ public class DPlayer extends DGlobalPlayer {
|
||||
|
||||
// Belohnung
|
||||
if (gameWorld.getGame() != null) {
|
||||
if (gameWorld.getGame().getType().hasRewards()) {
|
||||
if (finished) {
|
||||
if (gameWorld.getGame() != null) {
|
||||
for (Reward reward : gameWorld.getConfig().getRewards()) {
|
||||
reward.giveTo(getPlayer());
|
||||
}
|
||||
if (finished) {
|
||||
if (gameWorld.getGame().getType().hasRewards()) {
|
||||
for (Reward reward : gameWorld.getConfig().getRewards()) {
|
||||
reward.giveTo(getPlayer());
|
||||
}
|
||||
|
||||
addTreasure();
|
||||
@ -576,20 +587,7 @@ public class DPlayer extends DGlobalPlayer {
|
||||
}
|
||||
|
||||
public void ready() {
|
||||
ready = true;
|
||||
|
||||
DGroup dGroup = DGroup.getByPlayer(getPlayer());
|
||||
|
||||
if (dGroup == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!dGroup.isPlaying()) {
|
||||
dGroup.startGame(new Game(dGroup));
|
||||
|
||||
} else {
|
||||
respawn();
|
||||
}
|
||||
ready(GameTypeDefault.DEFAULT);
|
||||
}
|
||||
|
||||
public void ready(GameType gameType) {
|
||||
@ -601,11 +599,21 @@ public class DPlayer extends DGlobalPlayer {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!dGroup.isPlaying()) {
|
||||
dGroup.startGame(new Game(dGroup, gameType));
|
||||
Game game = Game.getByGameWorld(dGroup.getGameWorld());
|
||||
if (game == null) {
|
||||
game = new Game(dGroup, gameType, dGroup.getGameWorld());
|
||||
|
||||
} else {
|
||||
respawn();
|
||||
game.setType(gameType);
|
||||
}
|
||||
|
||||
for (DGroup gameGroup : game.getDGroups()) {
|
||||
if (!gameGroup.isPlaying()) {
|
||||
gameGroup.startGame(game);
|
||||
|
||||
} else {
|
||||
respawn();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -42,7 +42,7 @@ public class InteractSign extends DSign {
|
||||
@Override
|
||||
public boolean check() {
|
||||
Set<Integer> used = new HashSet<>();
|
||||
for (Block block : EditWorld.getByWorld(getSign().getLocation().getWorld()).getSign()) {
|
||||
for (Block block : EditWorld.getByWorld(getSign().getLocation().getWorld()).getSigns()) {
|
||||
if (block == null) {
|
||||
continue;
|
||||
}
|
||||
|
@ -18,9 +18,11 @@ package io.github.dre2n.dungeonsxl.sign;
|
||||
|
||||
import io.github.dre2n.commons.util.messageutil.MessageUtil;
|
||||
import io.github.dre2n.dungeonsxl.config.MessageConfig.Messages;
|
||||
import io.github.dre2n.dungeonsxl.game.Game;
|
||||
import io.github.dre2n.dungeonsxl.game.GameType;
|
||||
import io.github.dre2n.dungeonsxl.game.GameTypeDefault;
|
||||
import io.github.dre2n.dungeonsxl.game.GameWorld;
|
||||
import io.github.dre2n.dungeonsxl.player.DGroup;
|
||||
import io.github.dre2n.dungeonsxl.player.DPlayer;
|
||||
import io.github.dre2n.dungeonsxl.trigger.InteractTrigger;
|
||||
import org.bukkit.ChatColor;
|
||||
@ -96,8 +98,10 @@ public class ReadySign extends DSign {
|
||||
|
||||
@Override
|
||||
public void onTrigger() {
|
||||
for (DPlayer dPlayer : plugin.getDPlayers().getDPlayers()) {
|
||||
ready(dPlayer);
|
||||
for (DGroup dGroup : Game.getByGameWorld(getGameWorld()).getDGroups()) {
|
||||
for (Player player : dGroup.getPlayers()) {
|
||||
ready(DPlayer.getByPlayer(player));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -111,7 +115,8 @@ public class ReadySign extends DSign {
|
||||
}
|
||||
|
||||
if (getGameWorld().getSignClass().isEmpty() || dPlayer.getDClass() != null) {
|
||||
dPlayer.ready(gameType);
|
||||
GameType forced = getGameWorld().getConfig().getForcedGameType();
|
||||
dPlayer.ready(forced == null ? gameType : forced);
|
||||
MessageUtil.sendMessage(dPlayer.getPlayer(), plugin.getMessageConfig().getMessage(Messages.PLAYER_READY));
|
||||
|
||||
} else {
|
||||
|
@ -45,7 +45,7 @@ public class TriggerSign extends DSign {
|
||||
@Override
|
||||
public boolean check() {
|
||||
Set<Integer> used = new HashSet<>();
|
||||
for (Block block : EditWorld.getByWorld(getSign().getLocation().getWorld()).getSign()) {
|
||||
for (Block block : EditWorld.getByWorld(getSign().getLocation().getWorld()).getSigns()) {
|
||||
if (block == null) {
|
||||
continue;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user