Fix group signs not loading correctly

...and minor further fixes.
This commit is contained in:
Daniel Saukel 2015-12-27 14:07:30 +01:00
parent a018664102
commit 0cc9a28f4d
4 changed files with 150 additions and 95 deletions

View File

@ -95,6 +95,7 @@ public class DPortal {
if (dgroup.getGameWorld() == null) {
MessageUtil.sendMessage(player, plugin.getDMessages().get("Error_DungeonNotExist", DGroup.get(player).getMapName()));
return;
}
if (dgroup.getGameWorld().getLocLobby() == null) {

View File

@ -43,7 +43,7 @@ public class GroupSign {
this.startSign = startSign;
dGroups = new DGroup[maxGroups];
this.multiFloor = multiFloor;
this.setMultiFloor(multiFloor);
if (multiFloor) {
dungeonName = identifier;
Dungeon dungeon = plugin.getDungeons().getDungeon(identifier);
@ -81,6 +81,36 @@ public class GroupSign {
this.dungeonName = dungeonName;
}
/**
* @return the mapName
*/
public String getMapName() {
return mapName;
}
/**
* @param mapName
* the mapName to set
*/
public void setMapName(String mapName) {
this.mapName = mapName;
}
/**
* @return the multiFloor
*/
public boolean isMultiFloor() {
return multiFloor;
}
/**
* @param multiFloor
* the multiFloor to set
*/
public void setMultiFloor(boolean multiFloor) {
this.multiFloor = multiFloor;
}
public void update() {
int i = 0;
for (DGroup dGroup : dGroups) {
@ -347,17 +377,20 @@ public class GroupSign {
}
if ( !GameWorld.canPlayDungeon(groupSign.mapName, player)) {
File file = new File(DungeonsXL.getPlugin().getDataFolder() + "/maps/" + groupSign.mapName, "config.yml");
File file = new File(plugin.getDataFolder() + "/maps/" + groupSign.mapName, "config.yml");
if (file != null) {
WorldConfig confReader = new WorldConfig(file);
if (confReader != null) {
MessageUtil.sendMessage(player, DungeonsXL.getPlugin().getDMessages().get("Error_Cooldown", "" + confReader.getTimeToNextPlay()));
}
MessageUtil.sendMessage(player, plugin.getDMessages().get("Error_Cooldown", "" + confReader.getTimeToNextPlay()));
}
}
return true;
}
if ( !GameWorld.checkRequirements(groupSign.mapName, player)) {
MessageUtil.sendMessage(player, DungeonsXL.getPlugin().getDMessages().get("Error_Requirements"));
MessageUtil.sendMessage(player, plugin.getDMessages().get("Error_Requirements"));
return true;
}
int sx1 = groupSign.startSign.getX(), sy1 = groupSign.startSign.getY(), sz1 = groupSign.startSign.getZ();
@ -379,7 +412,12 @@ public class GroupSign {
Sign topSign = (Sign) topBlock.getState();
if (topSign.getLine(0).equals(strNewGrp)) {
if (DGroup.get(player) == null) {
groupSign.dGroups[column] = new DGroup(player, groupSign.mapName, groupSign.multiFloor);
if (groupSign.isMultiFloor()) {
groupSign.dGroups[column] = new DGroup(player, groupSign.dungeonName, groupSign.isMultiFloor());
} else {
groupSign.dGroups[column] = new DGroup(player, groupSign.mapName, groupSign.isMultiFloor());
}
groupSign.update();
}
@ -451,7 +489,7 @@ public class GroupSign {
configFile.set(preString + ".z", groupSign.startSign.getZ());
// Etc.
if (groupSign.multiFloor) {
if (groupSign.isMultiFloor()) {
configFile.set(preString + ".dungeon", groupSign.dungeonName);
} else {
@ -460,7 +498,7 @@ public class GroupSign {
configFile.set(preString + ".maxGroups", groupSign.dGroups.length);
configFile.set(preString + ".maxPlayersPerGroup", groupSign.maxPlayersPerGroup);
configFile.set(preString + ".multiFloor", groupSign.multiFloor);
configFile.set(preString + ".multiFloor", groupSign.isMultiFloor());
}
}
@ -480,8 +518,8 @@ public class GroupSign {
int maxGroups = configFile.getInt(preString + ".maxGroups");
int maxPlayersPerGroup = configFile.getInt(preString + ".maxPlayersPerGroup");
boolean multiFloor = false;
if (configFile.contains("multiFloor")) {
multiFloor = configFile.getBoolean("multiFloor");
if (configFile.contains(preString + ".multiFloor")) {
multiFloor = configFile.getBoolean(preString + ".multiFloor");
}
Block startSign = world.getBlockAt(configFile.getInt(preString + ".x"), configFile.getInt(preString + ".y"), configFile.getInt(preString + ".z"));

View File

@ -32,12 +32,14 @@ public class BlockListener implements Listener {
@EventHandler(priority = EventPriority.HIGH)
public void onBlockPhysics(BlockPhysicsEvent event) {
if (event.getBlock().getType() == Material.PORTAL) {
if (event.getBlock().getType() != Material.PORTAL) {
return;
}
if (DPortal.get(event.getBlock()) != null) {
event.setCancelled(true);
}
}
}
@EventHandler(priority = EventPriority.HIGH)
public void onBlockBreak(BlockBreakEvent event) {
@ -72,14 +74,14 @@ public class BlockListener implements Listener {
}
// Editworld Signs
EditWorld eworld = EditWorld.get(block.getWorld());
if (eworld != null) {
eworld.getSign().remove(event.getBlock());
EditWorld editWorld = EditWorld.get(block.getWorld());
if (editWorld != null) {
editWorld.getSign().remove(event.getBlock());
}
// Deny GameWorld Blocks
GameWorld gworld = GameWorld.get(block.getWorld());
if (gworld != null) {
GameWorld gameWorld = GameWorld.get(block.getWorld());
if (gameWorld != null) {
event.setCancelled(true);
}
@ -90,9 +92,14 @@ public class BlockListener implements Listener {
Block block = event.getBlock();
// Deny GameWorld Blocks
GameWorld gworld = GameWorld.get(block.getWorld());
if (gworld != null) {
if ( !GamePlaceableBlock.canBuildHere(block, block.getFace(event.getBlockAgainst()), event.getItemInHand().getType(), gworld)) {
GameWorld gameWorld = GameWorld.get(block.getWorld());
if (gameWorld == null) {
return;
}
if (GamePlaceableBlock.canBuildHere(block, block.getFace(event.getBlockAgainst()), event.getItemInHand().getType(), gameWorld)) {
return;
}
// Workaround for a bug that would allow 3-Block-high jumping
Location loc = event.getPlayer().getLocation();
@ -108,20 +115,24 @@ public class BlockListener implements Listener {
}
event.setCancelled(true);
}
}
}
@EventHandler(priority = EventPriority.NORMAL)
public void onSignChange(SignChangeEvent event) {
Player player = event.getPlayer();
Block block = event.getBlock();
String[] lines = event.getLines();
EditWorld eworld = EditWorld.get(player.getWorld());
EditWorld editWorld = EditWorld.get(player.getWorld());
// Group Signs
if (eworld == null) {
if (player.isOp() || player.hasPermission("dxl.sign")) {
if (lines[0].equalsIgnoreCase("[DXL]")) {
if (editWorld == null) {
if ( !player.hasPermission("dxl.sign")) {
return;
}
if ( !lines[0].equalsIgnoreCase("[DXL]")) {
return;
}
if (lines[1].equalsIgnoreCase("Group")) {
String dungeonName = lines[2];
@ -135,21 +146,23 @@ public class BlockListener implements Listener {
multiFloor = true;
}
}
if (maxGroups > 0 && maxPlayersPerGroup > 0) {
if (GroupSign.tryToCreate(event.getBlock(), dungeonName, maxGroups, maxPlayersPerGroup, multiFloor) != null) {
event.setCancelled(true);
}
}
}
} else if (lines[1].equalsIgnoreCase("Leave")) {
if (block.getState() instanceof Sign) {
Sign sign = (Sign) block.getState();
new LeaveSign(sign);
}
event.setCancelled(true);
}
}
}
} else { // Editworld Signs
Sign sign = (Sign) block.getState();
if (sign != null) {
@ -160,21 +173,22 @@ public class BlockListener implements Listener {
DSign dsign = DSign.create(sign, null);
if (dsign != null) {
if (player.isOp() || player.hasPermission(dsign.getType().getBuildPermission())) {
if (dsign == null) {
return;
}
if ( !player.hasPermission(dsign.getType().getBuildPermission())) {
MessageUtil.sendMessage(player, DungeonsXL.getPlugin().getDMessages().get("Error_NoPermissions"));
}
if (dsign.check()) {
eworld.checkSign(block);
eworld.getSign().add(block);
editWorld.checkSign(block);
editWorld.getSign().add(block);
MessageUtil.sendMessage(player, DungeonsXL.getPlugin().getDMessages().get("Player_SignCreated"));
} else {
MessageUtil.sendMessage(player, DungeonsXL.getPlugin().getDMessages().get("Error_SignWrongFormat"));
}
} else {
MessageUtil.sendMessage(player, DungeonsXL.getPlugin().getDMessages().get("Error_NoPermissions"));
}
}
}
}
}
@ -183,19 +197,21 @@ public class BlockListener implements Listener {
public void onBlockSpread(BlockSpreadEvent event) {
Block block = event.getBlock();
// Block the Spread off Vines
if (block.getType() == Material.VINE) {
if (block.getType() != Material.VINE) {
return;
}
// Check GameWorlds
GameWorld gworld = GameWorld.get(event.getBlock().getWorld());
if (gworld != null) {
GameWorld gameWorld = GameWorld.get(event.getBlock().getWorld());
if (gameWorld != null) {
event.setCancelled(true);
}
// Check EditWorlds
EditWorld eworld = EditWorld.get(event.getBlock().getWorld());
if (eworld != null) {
EditWorld editWorld = EditWorld.get(event.getBlock().getWorld());
if (editWorld != null) {
event.setCancelled(true);
}
}
}
@ -213,9 +229,9 @@ public class BlockListener implements Listener {
@Override
public void run() {
for (GameWorld gworld : DungeonsXL.getPlugin().getGameWorlds()) {
if (block.getWorld() == gworld.getWorld()) {
RedstoneTrigger.updateAll(gworld);
for (GameWorld gameWorld : DungeonsXL.getPlugin().getGameWorlds()) {
if (block.getWorld() == gameWorld.getWorld()) {
RedstoneTrigger.updateAll(gameWorld);
}
}
}

View File

@ -30,12 +30,12 @@ public class DGroup {
plugin.getDGroups().add(this);
this.players.add(player);
if (multiFloor) {
Dungeon dungeon = plugin.getDungeons().getDungeon(identifier);
if (multiFloor && dungeon != null) {
this.dungeonName = identifier;
this.mapName = plugin.getDungeons().getDungeon(dungeonName).getConfig().getStartFloor();
System.out.println("This one?");
this.unplayedFloors = plugin.getDungeons().getDungeon(dungeonName).getConfig().getFloors();
System.out.println("If this shows p,");
this.mapName = dungeon.getConfig().getStartFloor();
this.unplayedFloors = dungeon.getConfig().getFloors();
} else {
this.mapName = identifier;