Load and trigger signs correctly in games

This commit is contained in:
Daniel Saukel 2020-03-18 16:13:58 +01:00
parent 293dc75f0e
commit 51cccb3afb
3 changed files with 32 additions and 12 deletions

View File

@ -61,6 +61,7 @@ import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.block.Sign;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Hanging;
import org.bukkit.entity.Player;
@ -164,6 +165,20 @@ public class DGameWorld extends DInstanceWorld implements GameWorld {
classes = enabled;
}
@Override
public DungeonSign createDungeonSign(Sign sign, String[] lines) {
DungeonSign dSign = super.createDungeonSign(sign, lines);
if (dSign.isOnDungeonInit()) {
dSign.initialize();
}
if (!dSign.isErroneous() && dSign.isSetToAir()) {
dSign.setToAir();
}
return dSign;
}
/**
* @return the placeableBlocks
*/
@ -369,10 +384,18 @@ public class DGameWorld extends DInstanceWorld implements GameWorld {
isPlaying = true;
for (DungeonSign sign : getDungeonSigns()) {
if (sign != null) {
if (!sign.isOnDungeonInit()) {
sign.initialize();
if (sign == null || sign.isOnDungeonInit()) {
continue;
}
sign.initialize();
if (sign.isErroneous()) {
continue;
}
if (sign.isSetToAir()) {
sign.setToAir();
}
if (!sign.hasTriggers()) {
sign.trigger(null);
}
}
@ -383,12 +406,6 @@ public class DGameWorld extends DInstanceWorld implements GameWorld {
for (Trigger trigger : getTriggers(TriggerTypeDefault.FORTUNE)) {
((FortuneTrigger) trigger).onTrigger();
}
for (DungeonSign sign : getDungeonSigns()) {
if (sign != null && !sign.isErroneous() && !sign.hasTriggers()) {
sign.trigger(null);
}
}
}
/**

View File

@ -118,6 +118,7 @@ public abstract class DInstanceWorld implements InstanceWorld {
DungeonSign dSign = (DungeonSign) constructor.newInstance(plugin, sign, lines, this);
signs.put(sign.getBlock(), dSign);
return dSign;
} catch (NoSuchMethodException | SecurityException | InstantiationException | IllegalAccessException
| IllegalArgumentException | InvocationTargetException exception) {
MessageUtil.log(plugin, "&4Could not create a dungeon sign of the type \"" + type

View File

@ -26,6 +26,7 @@ import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.util.Collection;
import org.bukkit.block.Block;
import org.bukkit.block.BlockState;
import org.bukkit.block.Sign;
/**
@ -73,8 +74,9 @@ public class SignData {
int z = os.readInt();
Block block = instance.getWorld().getBlockAt(x, y, z);
if (block.getState() instanceof Sign) {
Sign sign = (Sign) block.getState();
BlockState state = block.getState();
if (state instanceof Sign) {
Sign sign = (Sign) state;
String[] lines = sign.getLines();
instance.createDungeonSign(sign, lines);