Fix game sign / portal exception

This commit is contained in:
Daniel Saukel 2016-06-22 13:56:41 +02:00
parent b23efdb3a1
commit 3e118f688e
11 changed files with 82 additions and 26 deletions

View File

@ -94,7 +94,7 @@ public class Announcer {
if (multiFloor) {
dungeonName = identifier;
Dungeon dungeon = plugin.getDungeons().getDungeon(identifier);
Dungeon dungeon = plugin.getDungeons().getByName(identifier);
if (dungeon != null) {
mapName = dungeon.getConfig().getStartFloor();
}
@ -135,7 +135,7 @@ public class Announcer {
if (multiFloor) {
dungeonName = identifier;
Dungeon dungeon = plugin.getDungeons().getDungeon(identifier);
Dungeon dungeon = plugin.getDungeons().getByName(identifier);
if (dungeon != null) {
mapName = dungeon.getConfig().getStartFloor();
}

View File

@ -75,7 +75,7 @@ public class ListCommand extends BRCommand {
if (args.length >= 2) {
if (args[1].equalsIgnoreCase("dungeons") || args[1].equalsIgnoreCase("d")) {
if (args.length >= 3) {
Dungeon dungeon = plugin.getDungeons().getDungeon(args[2]);
Dungeon dungeon = plugin.getDungeons().getByName(args[2]);
if (dungeon != null) {
MessageUtil.sendPluginTag(sender, plugin);
MessageUtil.sendCenteredMessage(sender, "&4&l[ &6" + dungeon.getName() + " &4&l]");

View File

@ -70,7 +70,7 @@ public class PlayCommand extends BRCommand {
identifier = args[2];
mapName = identifier;
if (args[1].equalsIgnoreCase("dungeon") || args[1].equalsIgnoreCase("d")) {
Dungeon dungeon = plugin.getDungeons().getDungeon(args[2]);
Dungeon dungeon = plugin.getDungeons().getByName(args[2]);
if (dungeon != null) {
multiFloor = true;
mapName = dungeon.getConfig().getStartFloor();
@ -102,7 +102,7 @@ public class PlayCommand extends BRCommand {
} else {
dGroup.setDungeonName(identifier);
Dungeon dungeon = plugin.getDungeons().getDungeon(identifier);
Dungeon dungeon = plugin.getDungeons().getByName(identifier);
if (dungeon != null) {
DungeonConfig config = dungeon.getConfig();

View File

@ -56,7 +56,7 @@ public enum DMessages implements Messages {
ERROR_COOLDOWN("Error_Cooldown", "&4You can only enter this dungeon every &6&v1&4 hours!"),
ERROR_DISPENSER("Error_Dispenser", "&4You cannot access this dispenser!"),
ERROR_DROP("Error_Drop", "&4You cannot drop safe items"),
ERROR_DUNGEON_NOT_EXIST("Error_DungeonNotExist", "&4Dungeon &6&v1&4 does not exist!"),
ERROR_DUNGEON_NOT_EXIST("Error_DungeonNotExist", "&4This dungeon does not exist."),
ERROR_ENDERCHEST("Error_Enderchest", "&4You cannot use an enderchest while in a dungeon!"),
ERROR_IN_GROUP("Error_InGroup", "&4The player &6&v1&4 is already member of a group."),
ERROR_JOIN_GROUP("Error_JoinGroup", "&4You have to join a group first!"),
@ -139,7 +139,7 @@ public enum DMessages implements Messages {
PLAYER_CHECKPOINT_REACHED("Player_CheckpointReached", "&6Checkpoint reached!"),
PLAYER_DEATH("Player_Death", "&6You died, lives left: &2&v1"),
PLAYER_DEATH_KICK("Player_DeathKick", "&2&v1&6 died and lost his last life."),
PLAYER_FINISHED_DUNGEON("Player_FinishedDungeon", "&6You successfully finished the Dungeon!"),
PLAYER_FINISHED_DUNGEON("Player_FinishedDungeon", "&6You successfully finished the dungeon!"),
PLAYER_INVITED("Player_Invited", "&4&v1&6 invited you to the group &4&v2&6."),
PLAYER_UNINVITED("Player_Uninvited", "&4&v1&6 took back your invitation to the group &4&v2&6."),
PLAYER_JOIN_GROUP("Player_JoinGroup", "&6You successfully joined the group!"),
@ -150,7 +150,7 @@ public enum DMessages implements Messages {
PLAYER_LIVES_REMOVED("Player_LivesRemoved", "&6You lost &4&v1&6 lives!"),
PLAYER_LOOT_ADDED("Player_LootAdded", "&4&v1&6 have been added to your reward inventory!"),
PLAYER_NEW_CAPTAIN("Player_NewCaptain", "&6You are now the new captain of your group."),
PLAYER_OFFLINE("Player_Offline", "&Player &4&v1&6 went offline. In &4&v2&6 seconds he will autmatically be kicked from the Dungeon!"),
PLAYER_OFFLINE("Player_Offline", "&Player &4&v1&6 went offline. In &4&v2&6 seconds he will autmatically be kicked from the dungeon!"),
PLAYER_OFFLINE_NEVER("Player_OfflineNever", "&6The player &4&v1&6 went offline. He will &4not&6 be kicked from the dungeon automatically!"),
PLAYER_PORTAL_ABORT("Player_PortalAbort", "&6Portal creation cancelled!"),
PLAYER_PORTAL_INTRODUCTION("Player_PortalIntroduction", "&6Click the two edges of the portal with the wooden sword!"),

View File

@ -40,21 +40,14 @@ public class Dungeons {
}
}
/**
* @return the dungeons
*/
public List<Dungeon> getDungeons() {
return dungeons;
}
/**
* @param name
* the name of the Dungeon
* @return the Dungeon that has the name
*/
public Dungeon getDungeon(String name) {
public Dungeon getByName(String name) {
for (Dungeon dungeon : dungeons) {
if (dungeon.getName().equals(name)) {
if (dungeon.getName().equalsIgnoreCase(name)) {
return dungeon;
}
}
@ -62,6 +55,13 @@ public class Dungeons {
return null;
}
/**
* @return the dungeons
*/
public List<Dungeon> getDungeons() {
return dungeons;
}
/**
* @param name
* the name of the Dungeon

View File

@ -185,13 +185,13 @@ public class DPortal extends GlobalProtection {
}
}
if (target == null) {
if (target == null && dGroup.getMapName() != null) {
target = new GameWorld(dGroup.getMapName());
dGroup.setGameWorld(target);
}
if (target == null) {
MessageUtil.sendMessage(player, DMessages.ERROR_DUNGEON_NOT_EXIST.getMessage(DGroup.getByPlayer(player).getMapName()));
MessageUtil.sendMessage(player, DMessages.ERROR_DUNGEON_NOT_EXIST.getMessage());
return;
}

View File

@ -63,7 +63,7 @@ public class GameSign extends GlobalProtection {
this.setMultiFloor(multiFloor);
if (multiFloor) {
dungeonName = identifier;
Dungeon dungeon = plugin.getDungeons().getDungeon(identifier);
Dungeon dungeon = plugin.getDungeons().getByName(identifier);
if (dungeon != null) {
mapName = dungeon.getConfig().getStartFloor();
} else {
@ -511,6 +511,8 @@ public class GameSign extends GlobalProtection {
if (topSign.getLine(0).equals(NEW_GAME)) {
Game game = new Game(dGroup);
dGroup.setDungeonName(gameSign.dungeonName);
dGroup.setMapName(gameSign.mapName);
gameSign.games[column] = game;
gameSign.update();

View File

@ -62,7 +62,7 @@ public class GroupSign extends GlobalProtection {
this.setMultiFloor(multiFloor);
if (multiFloor) {
dungeonName = identifier;
Dungeon dungeon = plugin.getDungeons().getDungeon(identifier);
Dungeon dungeon = plugin.getDungeons().getByName(identifier);
if (dungeon != null) {
mapName = dungeon.getConfig().getStartFloor();
} else {

View File

@ -22,7 +22,6 @@ import io.github.dre2n.dungeonsxl.config.DMessages;
import io.github.dre2n.dungeonsxl.config.MainConfig;
import io.github.dre2n.dungeonsxl.event.dgroup.DGroupCreateEvent;
import io.github.dre2n.dungeonsxl.event.dplayer.DPlayerDeathEvent;
import io.github.dre2n.dungeonsxl.event.dplayer.DPlayerKickEvent;
import io.github.dre2n.dungeonsxl.game.Game;
import io.github.dre2n.dungeonsxl.global.DPortal;
import io.github.dre2n.dungeonsxl.global.GameSign;

View File

@ -34,6 +34,7 @@ import io.github.dre2n.dungeonsxl.requirement.Requirement;
import io.github.dre2n.dungeonsxl.reward.Reward;
import io.github.dre2n.dungeonsxl.task.TimeIsRunningTask;
import io.github.dre2n.dungeonsxl.world.GameWorld;
import io.github.dre2n.dungeonsxl.world.Worlds;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
@ -107,7 +108,7 @@ public class DGroup {
}
}
dungeon = plugin.getDungeons().getDungeon(identifier);
dungeon = plugin.getDungeons().getByName(identifier);
if (multiFloor && dungeon != null) {
dungeonName = dungeon.getName();
mapName = dungeon.getConfig().getStartFloor();
@ -376,7 +377,7 @@ public class DGroup {
* the name of the dungeon
*/
public void setDungeon(String name) {
dungeon = plugin.getDungeons().getDungeon(name);
dungeon = plugin.getDungeons().getByName(name);
if (dungeon != null) {
dungeonName = dungeon.getName();
mapName = dungeon.getConfig().getStartFloor();
@ -396,12 +397,16 @@ public class DGroup {
}
/**
* Will fail if there is no dungeon with this name.
*
* @param dungeonName
* the dungeonName to set
*/
public void setDungeonName(String dungeonName) {
if (plugin.getDungeons().getByName(name) != null) {
this.dungeonName = dungeonName;
}
}
/**
* @return if the group is playing
@ -411,12 +416,16 @@ public class DGroup {
}
/**
* Will fail if there is no resource world with this name.
*
* @param name
* the name to set
*/
public void setMapName(String name) {
if (Worlds.exists(name)) {
mapName = name;
}
}
/**
* @return the unplayedFloors

View File

@ -0,0 +1,46 @@
/*
* Copyright (C) 2012-2016 Frank Baumann
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package io.github.dre2n.dungeonsxl.world;
import java.io.File;
import java.util.Set;
/**
* @author Daniel Saukel
*/
public class Worlds {
/*private Set<ResourceWorld> resourceWorlds;
public Worlds(File folder) {
for (File file : folder.listFiles()) {
resourceWorlds.add(new ResourceWorld());
}
}*/
@Deprecated
public static boolean exists(String name) {
for (File world : io.github.dre2n.dungeonsxl.DungeonsXL.MAPS.listFiles()) {
if (world.isDirectory() && world.getName().equalsIgnoreCase(name)) {
return true;
}
}
return false;
}
}