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;
|
|
|
|
|
2016-06-20 18:05:03 +02:00
|
|
|
import io.github.dre2n.commons.util.NumberUtil;
|
2016-03-01 22:08:07 +01:00
|
|
|
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;
|
2016-06-20 18:20:50 +02:00
|
|
|
import io.github.dre2n.dungeonsxl.player.DGroup;
|
2016-03-01 22:08:07 +01:00
|
|
|
import io.github.dre2n.dungeonsxl.trigger.InteractTrigger;
|
2016-06-20 14:34:02 +02:00
|
|
|
import io.github.dre2n.dungeonsxl.util.ProgressBar;
|
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;
|
2016-06-20 14:34:02 +02:00
|
|
|
import org.bukkit.scheduler.BukkitRunnable;
|
2016-03-01 22:08:07 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @author Frank Baumann, Milan Albrecht, Daniel Saukel
|
|
|
|
*/
|
|
|
|
public class ReadySign extends DSign {
|
|
|
|
|
|
|
|
private DSignType type = DSignTypeDefault.READY;
|
|
|
|
|
|
|
|
private GameType gameType;
|
2016-06-20 14:34:02 +02:00
|
|
|
private double autoStart = -1;
|
2016-06-20 18:20:50 +02:00
|
|
|
private boolean triggered = false;
|
2016-03-01 22:08:07 +01:00
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2016-06-20 14:34:02 +02:00
|
|
|
/**
|
|
|
|
* @return the time until the game starts automatically; -1 for no auto start
|
|
|
|
*/
|
|
|
|
public double getTimeToAutoStart() {
|
|
|
|
return autoStart;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param time
|
|
|
|
* the time in seconds until the game starts automatically; -1 for no auto start
|
|
|
|
*/
|
|
|
|
public void setTimeToAutoStart(double time) {
|
|
|
|
autoStart = time;
|
|
|
|
}
|
|
|
|
|
2016-03-01 22:08:07 +01:00
|
|
|
@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;
|
|
|
|
}
|
|
|
|
|
2016-06-20 14:34:02 +02:00
|
|
|
if (!lines[2].isEmpty()) {
|
|
|
|
autoStart = NumberUtil.parseDouble(lines[2], -1);
|
|
|
|
}
|
|
|
|
|
2016-03-01 22:08:07 +01:00
|
|
|
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-06-20 14:34:02 +02:00
|
|
|
|
2016-06-20 18:20:50 +02:00
|
|
|
if (!triggered && autoStart >= 0) {
|
|
|
|
triggered = true;
|
|
|
|
|
2016-06-20 14:34:02 +02:00
|
|
|
new BukkitRunnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
onTrigger();
|
|
|
|
}
|
|
|
|
}.runTaskLater(plugin, (long) (autoStart * 20));
|
|
|
|
|
2016-06-20 18:20:50 +02:00
|
|
|
if (!DGroup.getByPlayer(player).isPlaying()) {
|
|
|
|
ProgressBar.sendProgressBar(getGame().getPlayers(), (int) Math.ceil(autoStart));
|
|
|
|
}
|
2016-06-20 14:34:02 +02:00
|
|
|
}
|
|
|
|
|
2016-03-01 22:08:07 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onTrigger() {
|
2016-06-20 14:34:02 +02:00
|
|
|
for (Player player : Game.getByGameWorld(getGameWorld()).getPlayers()) {
|
|
|
|
ready(DGamePlayer.getByPlayer(player));
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|