DungeonsXL/src/main/java/io/github/dre2n/dungeonsxl/sign/ReadySign.java

133 lines
3.9 KiB
Java
Raw Normal View History

2016-03-01 22:08:07 +01:00
/*
* 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.sign;
import io.github.dre2n.commons.util.messageutil.MessageUtil;
2016-04-29 01:24:59 +02:00
import io.github.dre2n.dungeonsxl.config.DMessages;
2016-04-24 00:02:04 +02:00
import io.github.dre2n.dungeonsxl.game.Game;
2016-03-01 22:08:07 +01:00
import io.github.dre2n.dungeonsxl.game.GameType;
import io.github.dre2n.dungeonsxl.game.GameTypeDefault;
2016-05-05 14:13:28 +02:00
import io.github.dre2n.dungeonsxl.player.DGamePlayer;
import io.github.dre2n.dungeonsxl.player.DGroup;
2016-03-01 22:08:07 +01:00
import io.github.dre2n.dungeonsxl.trigger.InteractTrigger;
2016-04-29 01:24:59 +02:00
import io.github.dre2n.dungeonsxl.world.GameWorld;
2016-03-01 22:08:07 +01:00
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.block.Sign;
import org.bukkit.entity.Player;
/**
* @author Frank Baumann, Milan Albrecht, Daniel Saukel
*/
public class ReadySign extends DSign {
private DSignType type = DSignTypeDefault.READY;
private GameType gameType;
2016-05-17 01:21:05 +02:00
public ReadySign(Sign sign, String[] lines, GameWorld gameWorld) {
super(sign, lines, gameWorld);
2016-03-01 22:08:07 +01:00
}
/**
* @return the gameType
*/
public GameType getGameType() {
return gameType;
}
/**
* @param gameType
* the gameType to set
*/
public void setGameType(GameType gameType) {
this.gameType = gameType;
}
@Override
public boolean check() {
return true;
}
@Override
public void onInit() {
2016-05-16 20:55:05 +02:00
if (plugin.getGameTypes().getBySign(this) != null) {
gameType = plugin.getGameTypes().getBySign(this);
2016-03-01 22:08:07 +01:00
} else {
gameType = GameTypeDefault.DEFAULT;
}
if (!getTriggers().isEmpty()) {
getSign().getBlock().setType(Material.AIR);
return;
}
InteractTrigger trigger = InteractTrigger.getOrCreate(0, getSign().getBlock(), getGameWorld());
if (trigger != null) {
trigger.addListener(this);
addTrigger(trigger);
}
getSign().setLine(0, ChatColor.DARK_BLUE + "############");
getSign().setLine(1, ChatColor.DARK_GREEN + "Ready");
getSign().setLine(2, ChatColor.DARK_RED + gameType.getSignName());
getSign().setLine(3, ChatColor.DARK_BLUE + "############");
getSign().update();
}
@Override
public boolean onPlayerTrigger(Player player) {
2016-05-05 14:13:28 +02:00
ready(DGamePlayer.getByPlayer(player));
2016-03-01 22:08:07 +01:00
return true;
}
@Override
public void onTrigger() {
2016-04-24 00:02:04 +02:00
for (DGroup dGroup : Game.getByGameWorld(getGameWorld()).getDGroups()) {
for (Player player : dGroup.getPlayers()) {
2016-05-05 14:13:28 +02:00
ready(DGamePlayer.getByPlayer(player));
2016-04-24 00:02:04 +02:00
}
2016-03-01 22:08:07 +01:00
}
}
2016-05-05 14:13:28 +02:00
private void ready(DGamePlayer dPlayer) {
2016-03-01 22:08:07 +01:00
if (dPlayer == null) {
return;
}
if (dPlayer.isReady()) {
return;
}
if (getGameWorld().getSignClass().isEmpty() || dPlayer.getDClass() != null) {
2016-04-24 00:02:04 +02:00
GameType forced = getGameWorld().getConfig().getForcedGameType();
dPlayer.ready(forced == null ? gameType : forced);
2016-05-21 23:03:03 +02:00
}
2016-03-01 22:08:07 +01:00
2016-05-21 23:03:03 +02:00
if (dPlayer.isReady()) {
MessageUtil.sendMessage(dPlayer.getPlayer(), plugin.getMessageConfig().getMessage(dPlayer.isReady() ? DMessages.PLAYER_READY : DMessages.ERROR_READY));
2016-03-01 22:08:07 +01:00
}
}
@Override
public DSignType getType() {
return type;
}
}