* Fixed some possible java exception causes.

This commit is contained in:
LevelX2 2015-06-27 09:32:50 +02:00
parent b668209f7d
commit c774e95335
5 changed files with 173 additions and 167 deletions

View file

@ -43,6 +43,7 @@ import mage.game.Table;
import mage.game.tournament.TournamentPlayer;
import mage.interfaces.callback.ClientCallback;
import mage.players.net.UserData;
import mage.players.net.UserGroup;
import mage.server.draft.DraftSession;
import mage.server.game.GameManager;
import mage.server.game.GameSessionPlayer;
@ -53,7 +54,6 @@ import mage.server.util.SystemUtil;
import mage.view.TableClientMessage;
import org.apache.log4j.Logger;
/**
*
* @author BetaSteward_at_googlemail.com
@ -63,6 +63,7 @@ public class User {
private static final Logger logger = Logger.getLogger(User.class);
public enum UserState {
Created, Connected, Disconnected, Reconnected, Expired;
}
@ -103,6 +104,8 @@ public class User {
this.watchedGames = new ArrayList<>();
this.tablesToDelete = new ArrayList<>();
this.sessionId = "";
// default these to avaiod NPE -> will be updated from client short after
this.userData = new UserData(UserGroup.PLAYER, 0, false, false, false, null, "world.png", false);
}
public String getName() {
@ -276,6 +279,7 @@ public class User {
}
logger.trace(new StringBuilder("isExpired: User ").append(userName).append(" lastActivity: ").append(lastActivity).append(" expired: ").append(expired).toString());
return false; /*userState == UserState.Disconnected && */
}
private void reconnect() {

View file

@ -25,7 +25,6 @@
* authors and should not be interpreted as representing official policies, either expressed
* or implied, of BetaSteward_at_googlemail.com.
*/
package mage.server.game;
import java.io.Serializable;
@ -100,8 +99,7 @@ public class GamesRoomImpl extends RoomImpl implements GamesRoom, Serializable {
for (Table table : allTables) {
if (table.getState() != TableState.FINISHED) {
tableList.add(new TableView(table));
}
else if (matchList.size() < 50) {
} else if (matchList.size() < 50) {
if (table.isTournament()) {
matchList.add(new MatchView(table));
} else {
@ -222,6 +220,7 @@ public class GamesRoomImpl extends RoomImpl implements GamesRoom, Serializable {
* @author LevelX2
*/
class TableListSorter implements Comparator<Table> {
@Override
public int compare(Table one, Table two) {
if (!one.getState().equals(TableState.SIDEBOARDING) && !one.getState().equals(TableState.DUELING)) {
@ -259,6 +258,7 @@ class TableListSorter implements Comparator<Table> {
}
class UserNameSorter implements Comparator<UsersView> {
@Override
public int compare(UsersView one, UsersView two) {
return one.getUserName().compareToIgnoreCase(two.getUserName());

View file

@ -25,9 +25,9 @@
* authors and should not be interpreted as representing official policies, either expressed
* or implied, of BetaSteward_at_googlemail.com.
*/
package mage.abilities.effects;
import java.util.List;
import java.util.UUID;
import mage.abilities.Ability;
import mage.constants.Duration;
@ -42,7 +42,6 @@ import mage.game.stack.StackObject;
import mage.players.Player;
import mage.target.TargetPermanent;
/**
*
* @author BetaSteward_at_googlemail.com
@ -81,9 +80,11 @@ public class PlaneswalkerRedirectionEffect extends RedirectionEffect {
if (numPlaneswalkers > 0 && player.chooseUse(outcome, "Redirect damage to planeswalker?", game)) {
redirectTarget = new TargetPermanent(filter);
if (numPlaneswalkers == 1) {
redirectTarget.add(game.getBattlefield().getAllActivePermanents(filter, target.getId(), game).get(0).getId(), game);
List<Permanent> planeswalker = game.getBattlefield().getAllActivePermanents(filter, target.getId(), game);
if (!planeswalker.isEmpty()) {
redirectTarget.add(planeswalker.get(0).getId(), game);
}
else {
} else {
player.choose(Outcome.Damage, redirectTarget, null, game);
}
if (!game.isSimulation()) {

View file

@ -25,7 +25,6 @@
* authors and should not be interpreted as representing official policies, either expressed
* or implied, of BetaSteward_at_googlemail.com.
*/
package mage.game;
import java.util.HashMap;
@ -108,7 +107,6 @@ public abstract class GameCommanderImpl extends GameImpl {
}
}
//20130711
/*903.8. The Commander variant uses an alternate mulligan rule.
* Each time a player takes a mulligan, rather than shuffling his or her entire hand of cards into his or her library, that player exiles any number of cards from his or her hand face down.
@ -145,7 +143,8 @@ public abstract class GameCommanderImpl extends GameImpl {
usedFreeMulligans.put(player.getId(), used + 1);
}
} else {
deduction = 0;{
deduction = 0;
{
}
usedFreeMulligans.put(player.getId(), 1);
@ -188,6 +187,9 @@ public abstract class GameCommanderImpl extends GameImpl {
protected boolean checkStateBasedActions() {
for (Player player : getPlayers().values()) {
CommanderInfoWatcher damageWatcher = (CommanderInfoWatcher) getState().getWatchers().get("CommanderCombatDamageWatcher", player.getCommanderId());
if (damageWatcher == null) {
continue;
}
for (Map.Entry<UUID, Integer> entrySet : damageWatcher.getDamageToPlayer().entrySet()) {
if (entrySet.getValue() > 20) {
Player opponent = getPlayer(entrySet.getKey());

View file

@ -48,10 +48,9 @@ import mage.watchers.Watcher;
*
* @author Plopman
*/
public class CommanderInfoWatcher extends Watcher {
public Map<UUID, Integer> damageToPlayer = new HashMap<>();
public final Map<UUID, Integer> damageToPlayer = new HashMap<>();
public boolean checkCommanderDamage;
public CommanderInfoWatcher(UUID commander, boolean checkCommanderDamage) {
@ -60,7 +59,6 @@ public class CommanderInfoWatcher extends Watcher {
this.checkCommanderDamage = checkCommanderDamage;
}
public CommanderInfoWatcher(final CommanderInfoWatcher watcher) {
super(watcher);
this.damageToPlayer.putAll(watcher.damageToPlayer);
@ -88,8 +86,9 @@ public class CommanderInfoWatcher extends Watcher {
Player player = game.getPlayer(playerUUID);
MageObject commander = game.getObject(sourceId);
if (player != null && commander != null) {
if (!game.isSimulation())
if (!game.isSimulation()) {
game.informPlayers(commander.getLogName() + " did " + damage + " combat damage to " + player.getLogName() + " during the game.");
}
this.addCardInfoToCommander(game);
}
}