mirror of
https://github.com/DRE2N/DungeonsXL.git
synced 2024-11-02 17:00:19 +01:00
Direct play join signs. Resolves #451
This commit is contained in:
parent
9c50677054
commit
7688d55766
@ -45,8 +45,8 @@ public class GameSign extends JoinSign {
|
||||
|
||||
private Game game;
|
||||
|
||||
public GameSign(DungeonsXL plugin, int id, Block startSign, String identifier, int maxGroupsPerGame) {
|
||||
super(plugin, id, startSign, identifier, maxGroupsPerGame);
|
||||
public GameSign(DungeonsXL plugin, int id, Block startSign, String identifier, int maxGroupsPerGame, int startIfElementsAtLeast) {
|
||||
super(plugin, id, startSign, identifier, maxGroupsPerGame, startIfElementsAtLeast);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -76,11 +76,17 @@ public class GameSign extends JoinSign {
|
||||
Sign sign = (Sign) startSign.getState();
|
||||
|
||||
if (game == null || game.getDGroups().isEmpty()) {
|
||||
loadedWorld = false;
|
||||
sign.setLine(0, DMessage.SIGN_GLOBAL_NEW_GAME.getMessage());
|
||||
sign.update();
|
||||
return;
|
||||
}
|
||||
|
||||
if (game.getDGroups().size() >= startIfElementsAtLeast && startIfElementsAtLeast != -1) {
|
||||
loadedWorld = true;
|
||||
game.getDGroups().forEach(g -> g.teleport());
|
||||
}
|
||||
|
||||
if (game.getDGroups().get(0).isPlaying()) {
|
||||
sign.setLine(0, DMessage.SIGN_GLOBAL_IS_PLAYING.getMessage());
|
||||
|
||||
@ -122,6 +128,7 @@ public class GameSign extends JoinSign {
|
||||
config.set(preString + ".dungeon", dungeon.getName());
|
||||
}
|
||||
config.set(preString + ".maxGroupsPerGame", maxElements);
|
||||
config.set(preString + ".startIfElementsAtLeast", startIfElementsAtLeast);
|
||||
}
|
||||
|
||||
public void onPlayerInteract(Block block, Player player) {
|
||||
@ -209,12 +216,17 @@ public class GameSign extends JoinSign {
|
||||
}
|
||||
|
||||
String identifier = event.getLine(2);
|
||||
int maxGroupsPerGame = NumberUtil.parseInt(event.getLine(3), 1);
|
||||
String[] data = event.getLine(3).split(",");
|
||||
int maxGroupsPerGame = NumberUtil.parseInt(data[0], 1);
|
||||
int startIfElementsAtLeast = -1;
|
||||
if (data.length > 1) {
|
||||
startIfElementsAtLeast = NumberUtil.parseInt(data[1], -1);
|
||||
}
|
||||
|
||||
return tryToCreate(plugin, event.getBlock(), identifier, maxGroupsPerGame);
|
||||
return tryToCreate(plugin, event.getBlock(), identifier, maxGroupsPerGame, startIfElementsAtLeast);
|
||||
}
|
||||
|
||||
public static GameSign tryToCreate(DungeonsXL plugin, Block startSign, String identifier, int maxGroupsPerGame) {
|
||||
public static GameSign tryToCreate(DungeonsXL plugin, Block startSign, String identifier, int maxGroupsPerGame, int startIfElementsAtLeast) {
|
||||
World world = startSign.getWorld();
|
||||
BlockFace facing = ((Attachable) startSign.getState().getData()).getAttachedFace().getOppositeFace();
|
||||
int x = startSign.getX(), y = startSign.getY(), z = startSign.getZ();
|
||||
@ -231,7 +243,7 @@ public class GameSign extends JoinSign {
|
||||
|
||||
verticalSigns--;
|
||||
}
|
||||
GameSign sign = new GameSign(plugin, plugin.getGlobalProtectionCache().generateId(GameSign.class, world), startSign, identifier, maxGroupsPerGame);
|
||||
GameSign sign = new GameSign(plugin, plugin.getGlobalProtectionCache().generateId(GameSign.class, world), startSign, identifier, maxGroupsPerGame, startIfElementsAtLeast);
|
||||
|
||||
LWCUtil.removeProtection(startSign);
|
||||
|
||||
|
@ -185,9 +185,10 @@ public class GlobalProtectionCache {
|
||||
if (data.contains(preString)) {
|
||||
String mapName = data.getString(preString + ".dungeon");
|
||||
int maxGroupsPerGame = data.getInt(preString + ".maxGroupsPerGame");
|
||||
int startIfElementsAtLeast = data.getInt(preString + ".startIfElementsAtLeast");
|
||||
Block startSign = world.getBlockAt(data.getInt(preString + ".x"), data.getInt(preString + ".y"), data.getInt(preString + ".z"));
|
||||
|
||||
new GameSign(plugin, id, startSign, mapName, maxGroupsPerGame);
|
||||
new GameSign(plugin, id, startSign, mapName, maxGroupsPerGame, startIfElementsAtLeast);
|
||||
}
|
||||
|
||||
} while (data.contains(preString));
|
||||
@ -205,9 +206,10 @@ public class GlobalProtectionCache {
|
||||
String mapName = data.getString(preString + ".dungeon");
|
||||
String groupName = data.getString(preString + ".groupName");
|
||||
int maxPlayersPerGroup = data.getInt(preString + ".maxPlayersPerGroup");
|
||||
int startIfElementsAtLeast = data.getInt(preString + ".startIfElementsAtLeast");
|
||||
Block startSign = world.getBlockAt(data.getInt(preString + ".x"), data.getInt(preString + ".y"), data.getInt(preString + ".z"));
|
||||
|
||||
new GroupSign(plugin, id, startSign, mapName, maxPlayersPerGroup, groupName);
|
||||
new GroupSign(plugin, id, startSign, mapName, maxPlayersPerGroup, startIfElementsAtLeast, groupName);
|
||||
}
|
||||
} while (data.contains(preString));
|
||||
}
|
||||
|
@ -45,8 +45,8 @@ public class GroupSign extends JoinSign {
|
||||
private String groupName;
|
||||
private DGroup group;
|
||||
|
||||
public GroupSign(DungeonsXL plugin, int id, Block startSign, String identifier, int maxPlayersPerGroup, String groupName) {
|
||||
super(plugin, id, startSign, identifier, maxPlayersPerGroup);
|
||||
public GroupSign(DungeonsXL plugin, int id, Block startSign, String identifier, int maxPlayersPerGroup, int startIfElementsAtLeast, String groupName) {
|
||||
super(plugin, id, startSign, identifier, maxPlayersPerGroup, startIfElementsAtLeast);
|
||||
this.groupName = groupName;
|
||||
}
|
||||
|
||||
@ -77,11 +77,17 @@ public class GroupSign extends JoinSign {
|
||||
Sign sign = (Sign) startSign.getState();
|
||||
|
||||
if (group == null) {
|
||||
loadedWorld = false;
|
||||
sign.setLine(0, DMessage.SIGN_GLOBAL_NEW_GROUP.getMessage());
|
||||
sign.update();
|
||||
return;
|
||||
}
|
||||
|
||||
if (group.getPlayers().size() >= startIfElementsAtLeast && startIfElementsAtLeast != -1 && !loadedWorld) {
|
||||
loadedWorld = true;
|
||||
group.teleport();
|
||||
}
|
||||
|
||||
if (group.isPlaying()) {
|
||||
sign.setLine(0, DMessage.SIGN_GLOBAL_IS_PLAYING.getMessage());
|
||||
|
||||
@ -124,6 +130,7 @@ public class GroupSign extends JoinSign {
|
||||
}
|
||||
config.set(preString + ".groupName", groupName);
|
||||
config.set(preString + ".maxPlayersPerGroup", maxElements);
|
||||
config.set(preString + ".startIfElementsAtLeast", startIfElementsAtLeast);
|
||||
}
|
||||
|
||||
public void onPlayerInteract(Block block, Player player) {
|
||||
@ -193,17 +200,21 @@ public class GroupSign extends JoinSign {
|
||||
String[] data = event.getLine(3).split(",");
|
||||
int maxPlayersPerGroup = 1;
|
||||
String groupName = null;
|
||||
int startIfElementsAtLeast = -1;
|
||||
if (data.length >= 1) {
|
||||
maxPlayersPerGroup = NumberUtil.parseInt(data[0], 1);
|
||||
}
|
||||
if (data.length == 2) {
|
||||
if (data.length >= 2) {
|
||||
groupName = data[1];
|
||||
}
|
||||
if (data.length == 3) {
|
||||
startIfElementsAtLeast = NumberUtil.parseInt(data[2], -1);
|
||||
}
|
||||
|
||||
return tryToCreate(plugin, event.getBlock(), identifier, maxPlayersPerGroup, groupName);
|
||||
return tryToCreate(plugin, event.getBlock(), identifier, maxPlayersPerGroup, startIfElementsAtLeast, groupName);
|
||||
}
|
||||
|
||||
public static GroupSign tryToCreate(DungeonsXL plugin, Block startSign, String identifier, int maxPlayersPerGroup, String groupName) {
|
||||
public static GroupSign tryToCreate(DungeonsXL plugin, Block startSign, String identifier, int maxPlayersPerGroup, int startIfElementsAtLeast, String groupName) {
|
||||
World world = startSign.getWorld();
|
||||
BlockFace facing = ((Attachable) startSign.getState().getData()).getAttachedFace().getOppositeFace();
|
||||
int x = startSign.getX(), y = startSign.getY(), z = startSign.getZ();
|
||||
@ -220,7 +231,8 @@ public class GroupSign extends JoinSign {
|
||||
|
||||
verticalSigns--;
|
||||
}
|
||||
GroupSign sign = new GroupSign(plugin, plugin.getGlobalProtectionCache().generateId(GroupSign.class, world), startSign, identifier, maxPlayersPerGroup, groupName);
|
||||
GroupSign sign = new GroupSign(plugin, plugin.getGlobalProtectionCache().generateId(GroupSign.class, world), startSign, identifier, maxPlayersPerGroup,
|
||||
startIfElementsAtLeast, groupName);
|
||||
|
||||
LWCUtil.removeProtection(startSign);
|
||||
|
||||
|
@ -33,11 +33,13 @@ public class JoinSign extends GlobalProtection {
|
||||
|
||||
protected Dungeon dungeon;
|
||||
protected int maxElements;
|
||||
protected int startIfElementsAtLeast = -1;
|
||||
protected Block startSign;
|
||||
protected int verticalSigns;
|
||||
protected Set<Block> blocks;
|
||||
protected boolean loadedWorld;
|
||||
|
||||
protected JoinSign(DungeonsXL plugin, int id, Block startSign, String identifier, int maxElements) {
|
||||
protected JoinSign(DungeonsXL plugin, int id, Block startSign, String identifier, int maxElements, int startIfElementsAtLeast) {
|
||||
super(plugin, startSign.getWorld(), id);
|
||||
|
||||
this.startSign = startSign;
|
||||
@ -52,6 +54,9 @@ public class JoinSign extends GlobalProtection {
|
||||
verticalSigns = (int) Math.ceil((float) (1 + maxElements) / 4);
|
||||
|
||||
this.maxElements = maxElements;
|
||||
if (startIfElementsAtLeast > 0 && startIfElementsAtLeast <= maxElements) {
|
||||
this.startIfElementsAtLeast = startIfElementsAtLeast;
|
||||
}
|
||||
|
||||
update();
|
||||
}
|
||||
@ -78,10 +83,33 @@ public class JoinSign extends GlobalProtection {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param maxElements the maximum element count per sign
|
||||
* @param amount the maximum element count per sign
|
||||
*/
|
||||
public void setMaxElements(int maxElements) {
|
||||
this.maxElements = maxElements;
|
||||
public void setMaxElements(int amount) {
|
||||
maxElements = amount;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the minimum amount of elements required to start the dungeon countdown
|
||||
*
|
||||
* @return the minimum amount of elements required to start the dungeon countdown;<br>
|
||||
* -1 if the dungeon is not instantiated only through the sign.
|
||||
*/
|
||||
public int getStartIfElementsAtLeastAmount() {
|
||||
return startIfElementsAtLeast;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the minimum amount of elements required to start the dungeon countdown
|
||||
*
|
||||
* @param amount the amount to set
|
||||
*/
|
||||
public void setStartIfElementsAtLeastAmount(int amount) {
|
||||
if ((amount > 0 || amount == -1) && amount < maxElements) {
|
||||
startIfElementsAtLeast = amount;
|
||||
} else {
|
||||
throw new IllegalArgumentException("startIfElementsAtLeastAmount is < 0 or < maxElements");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -44,6 +44,7 @@ import java.util.Random;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
|
||||
@ -609,6 +610,65 @@ public class DGroup {
|
||||
}
|
||||
|
||||
/* Actions */
|
||||
public boolean teleport() {
|
||||
if (dungeon == null || dungeon.getMap() == null) {
|
||||
sendMessage(DMessage.ERROR_DUNGEON_NOT_EXIST.getMessage());
|
||||
return false;
|
||||
}
|
||||
|
||||
DGameWorld target = dungeon.getMap().instantiateAsGameWorld(false);
|
||||
Game game = Game.getByDGroup(this);
|
||||
|
||||
if (target == null && game != null) {
|
||||
target = game.getWorld();
|
||||
}
|
||||
|
||||
if (target == null) {
|
||||
if (game != null) {
|
||||
for (DGroup otherTeam : game.getDGroups()) {
|
||||
if (otherTeam.getGameWorld() != null) {
|
||||
target = otherTeam.getGameWorld();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (target == null && dungeon != null) {
|
||||
DResourceWorld resource = dungeon.getMap();
|
||||
if (resource != null) {
|
||||
target = resource.instantiateAsGameWorld(false);
|
||||
if (target == null) {
|
||||
sendMessage(DMessage.ERROR_TOO_MANY_INSTANCES.getMessage());
|
||||
return false;
|
||||
}
|
||||
gameWorld = target;
|
||||
}
|
||||
}
|
||||
|
||||
if (target == null) {
|
||||
sendMessage(DMessage.ERROR_DUNGEON_NOT_EXIST.getMessage());
|
||||
return false;
|
||||
}
|
||||
|
||||
if (game == null) {
|
||||
game = new Game(plugin, this, target);
|
||||
|
||||
} else {
|
||||
game.setWorld(target);
|
||||
gameWorld = target;
|
||||
}
|
||||
|
||||
for (OfflinePlayer offline : players.getOfflinePlayers()) {
|
||||
if (!offline.isOnline()) {
|
||||
players.remove(offline);
|
||||
}
|
||||
Player player = offline.getPlayer();
|
||||
new DGamePlayer(plugin, player, target);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* The group finishs the dungeon.
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user