Console.java

mudlibs/tinylib/src/net/sourceforge/pain/tinylib/Console.java · 1.3 KB

From the archive pain_0_45.tgz

Download the archive   « Back to the archive contents

package net.sourceforge.pain.tinylib;


import net.sourceforge.pain.*;
import net.sourceforge.pain.network.console.*;
import net.sourceforge.pain.tinylib.data.type.*;

import java.util.*;

/**
 * mudlib specific console extention
 */ 
public final class Console extends BasicConsole {

    private static final HashMap consoleByPlayerId = new HashMap();

    private Object playerId;

    protected Console(ConsoleAdapter adapter) {
        super(adapter);
    }

    public Player getPlayer() {
        return (Player) (playerId == null ? null : Codebase.getDB().getObject(playerId));
    }

    public void setPlayer(Player newPlayer) {
        if (playerId != null && newPlayer != null) {
            throw new RuntimeException("Owner redefinition not supported!");
        }
        if (playerId == null && newPlayer == null) {
            throw new RuntimeException("BUG, newPlayer is null!");
        }
        if (newPlayer == null) {
            consoleByPlayerId.remove(playerId);
            playerId = null;
        } else {
            playerId = newPlayer.getOid();
            consoleByPlayerId.put(newPlayer.getOid(), this);
        }
    }


    public static Console getConsoleByOwner(Player player) {
        return (Console) consoleByPlayerId.get(player.getOid());
    }
}

Site Stats

Snippets: 1791
Codebases: 571