2020-03-13 23:48:49 +01:00
|
|
|
/*
|
2022-01-08 23:02:57 +01:00
|
|
|
* Copyright (C) 2012-2022 Frank Baumann
|
2020-03-13 23:48:49 +01:00
|
|
|
*
|
|
|
|
* 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 de.erethon.dungeonsxl.sign.button;
|
|
|
|
|
|
|
|
import de.erethon.dungeonsxl.api.DungeonsAPI;
|
|
|
|
import de.erethon.dungeonsxl.api.dungeon.GameRule;
|
|
|
|
import de.erethon.dungeonsxl.api.sign.Button;
|
|
|
|
import de.erethon.dungeonsxl.api.world.InstanceWorld;
|
2022-04-03 18:09:12 +02:00
|
|
|
import de.erethon.bedrock.misc.NumberUtil;
|
2020-03-13 23:48:49 +01:00
|
|
|
import org.bukkit.block.Sign;
|
2020-03-18 19:37:41 +01:00
|
|
|
import org.bukkit.entity.Player;
|
2020-03-13 23:48:49 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @author Daniel Saukel
|
|
|
|
*/
|
|
|
|
public abstract class MessageSign extends Button {
|
|
|
|
|
2020-03-18 19:37:41 +01:00
|
|
|
protected String text = "UNKNOWN MESSAGE";
|
2020-03-13 23:48:49 +01:00
|
|
|
|
|
|
|
public MessageSign(DungeonsAPI api, Sign sign, String[] lines, InstanceWorld instance) {
|
|
|
|
super(api, sign, lines, instance);
|
|
|
|
}
|
|
|
|
|
|
|
|
public String getText() {
|
|
|
|
return text;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setText(String text) {
|
|
|
|
this.text = text;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean isOnDungeonInit() {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean isProtected() {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean isSetToAir() {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean validate() {
|
|
|
|
return !getLine(1).isEmpty();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void initialize() {
|
|
|
|
String text = getGameWorld().getDungeon().getRules().getState(GameRule.MESSAGES).get(NumberUtil.parseInt(getLine(1)));
|
|
|
|
if (text != null) {
|
|
|
|
this.text = text;
|
2020-03-18 19:37:41 +01:00
|
|
|
} else {
|
|
|
|
markAsErroneous("Unknown message, ID: " + getLine(1));
|
2020-03-13 23:48:49 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-18 19:37:41 +01:00
|
|
|
@Override
|
|
|
|
public boolean push(Player player) {
|
2020-06-22 19:56:08 +02:00
|
|
|
sendMessage(player);
|
2020-03-18 19:37:41 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void push() {
|
|
|
|
for (Player player : getGameWorld().getWorld().getPlayers()) {
|
|
|
|
sendMessage(player);
|
|
|
|
}
|
|
|
|
getGameWorld().removeDungeonSign(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
public abstract void sendMessage(Player player);
|
|
|
|
|
2020-03-13 23:48:49 +01:00
|
|
|
}
|