Finish sign scripts. Closes #48

This commit is contained in:
Daniel Saukel 2016-05-17 01:21:05 +02:00
parent 569ddf5a8a
commit 0791008ea4
25 changed files with 67 additions and 57 deletions

View File

@ -36,8 +36,8 @@ public class BlockSign extends DSign {
private byte offBlockData = 0x0;
private byte onBlockData = 0x0;
public BlockSign(Sign sign, GameWorld gameWorld) {
super(sign, gameWorld);
public BlockSign(Sign sign, String[] lines, GameWorld gameWorld) {
super(sign, lines, gameWorld);
}
@Override

View File

@ -36,8 +36,8 @@ public class CheckpointSign extends DSign {
private boolean initialized;
private CopyOnWriteArrayList<DGamePlayer> done = new CopyOnWriteArrayList<>();
public CheckpointSign(Sign sign, GameWorld gameWorld) {
super(sign, gameWorld);
public CheckpointSign(Sign sign, String[] lines, GameWorld gameWorld) {
super(sign, lines, gameWorld);
}
@Override

View File

@ -33,8 +33,8 @@ public class ChestSign extends DSign {
private double moneyReward;
private int levelReward;
public ChestSign(Sign sign, GameWorld gameWorld) {
super(sign, gameWorld);
public ChestSign(Sign sign, String[] lines, GameWorld gameWorld) {
super(sign, lines, gameWorld);
}
@Override

View File

@ -29,8 +29,8 @@ public class ChunkUpdaterSign extends DSign {
private DSignType type = DSignTypeDefault.CHUNK_UPDATER;
public ChunkUpdaterSign(Sign sign, GameWorld gameWorld) {
super(sign, gameWorld);
public ChunkUpdaterSign(Sign sign, String[] lines, GameWorld gameWorld) {
super(sign, lines, gameWorld);
}
@Override

View File

@ -31,8 +31,8 @@ public class ClassesSign extends DSign {
private DClass dClass;
public ClassesSign(Sign sign, GameWorld gameWorld) {
super(sign, gameWorld);
public ClassesSign(Sign sign, String[] lines, GameWorld gameWorld) {
super(sign, lines, gameWorld);
dClass = plugin.getDClasses().getByName(sign.getLine(1));
}

View File

@ -44,8 +44,8 @@ public class CommandSign extends DSign {
private String executor;
private boolean initialized;
public CommandSign(Sign sign, GameWorld gameWorld) {
super(sign, gameWorld);
public CommandSign(Sign sign, String[] lines, GameWorld gameWorld) {
super(sign, lines, gameWorld);
}
@Override

View File

@ -40,8 +40,8 @@ public class DMobSign extends DSign implements MobSign {
private boolean active;
private BukkitTask task;
public DMobSign(Sign sign, GameWorld gameWorld) {
super(sign, gameWorld);
public DMobSign(Sign sign, String[] lines, GameWorld gameWorld) {
super(sign, lines, gameWorld);
}
@Override

View File

@ -43,9 +43,9 @@ public abstract class DSign {
// List of Triggers
private Set<Trigger> triggers = new HashSet<>();
public DSign(Sign sign, GameWorld gameWorld) {
public DSign(Sign sign, String[] lines, GameWorld gameWorld) {
this.sign = sign;
this.lines = sign.getLines();
this.lines = lines;
this.gameWorld = gameWorld;
// Check Trigger
@ -53,7 +53,7 @@ public abstract class DSign {
return;
}
String line3 = sign.getLine(3).replaceAll("\\s", "");
String line3 = lines[3].replaceAll("\\s", "");
String[] triggerTypes = line3.split(",");
for (String triggerString : triggerTypes) {
@ -198,8 +198,8 @@ public abstract class DSign {
}
try {
Constructor<? extends DSign> constructor = type.getHandler().getConstructor(Sign.class, GameWorld.class);
dSign = constructor.newInstance(sign, gameWorld);
Constructor<? extends DSign> constructor = type.getHandler().getConstructor(Sign.class, String[].class, GameWorld.class);
dSign = constructor.newInstance(sign, lines, gameWorld);
} catch (NoSuchMethodException | SecurityException | InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException exception) {
MessageUtil.log("An error occurred while accessing the handler class of the sign " + type.getName() + ": " + exception.getClass().getSimpleName());

View File

@ -31,8 +31,8 @@ public class EndSign extends DSign {
private DSignType type = DSignTypeDefault.END;
public EndSign(Sign sign, GameWorld gameWorld) {
super(sign, gameWorld);
public EndSign(Sign sign, String[] lines, GameWorld gameWorld) {
super(sign, lines, gameWorld);
}
@Override

View File

@ -52,8 +52,8 @@ public class ExternalMobSign extends DSign implements MobSign {
private LivingEntity externalMob;
private List<Entity> externalMobs = new ArrayList<>();
public ExternalMobSign(Sign sign, GameWorld gameWorld) {
super(sign, gameWorld);
public ExternalMobSign(Sign sign, String[] lines, GameWorld gameWorld) {
super(sign, lines, gameWorld);
}
@Override

View File

@ -33,8 +33,8 @@ public class FloorSign extends DSign {
private String floor;
public FloorSign(Sign sign, GameWorld gameWorld) {
super(sign, gameWorld);
public FloorSign(Sign sign, String[] lines, GameWorld gameWorld) {
super(sign, lines, gameWorld);
}
@Override

View File

@ -35,8 +35,8 @@ public class InteractSign extends DSign {
private DSignType type = DSignTypeDefault.INTERACT;
public InteractSign(Sign sign, GameWorld gameWorld) {
super(sign, gameWorld);
public InteractSign(Sign sign, String[] lines, GameWorld gameWorld) {
super(sign, lines, gameWorld);
}
@Override

View File

@ -32,8 +32,8 @@ public class LeaveSign extends DSign {
private DSignType type = DSignTypeDefault.LEAVE;
public LeaveSign(Sign sign, GameWorld gameWorld) {
super(sign, gameWorld);
public LeaveSign(Sign sign, String[] lines, GameWorld gameWorld) {
super(sign, lines, gameWorld);
}
@Override

View File

@ -27,8 +27,8 @@ public class LobbySign extends DSign {
private DSignType type = DSignTypeDefault.LOBBY;
public LobbySign(Sign sign, GameWorld gameWorld) {
super(sign, gameWorld);
public LobbySign(Sign sign, String[] lines, GameWorld gameWorld) {
super(sign, lines, gameWorld);
}
@Override

View File

@ -36,8 +36,8 @@ public class MessageSign extends DSign {
private boolean initialized;
private CopyOnWriteArrayList<Player> done = new CopyOnWriteArrayList<>();
public MessageSign(Sign sign, GameWorld gameWorld) {
super(sign, gameWorld);
public MessageSign(Sign sign, String[] lines, GameWorld gameWorld) {
super(sign, lines, gameWorld);
}
@Override

View File

@ -28,8 +28,8 @@ public class PlaceSign extends DSign {
private DSignType type = DSignTypeDefault.PLACE;
public PlaceSign(Sign sign, GameWorld gameWorld) {
super(sign, gameWorld);
public PlaceSign(Sign sign, String[] lines, GameWorld gameWorld) {
super(sign, lines, gameWorld);
}
@Override

View File

@ -39,8 +39,8 @@ public class ReadySign extends DSign {
private GameType gameType;
public ReadySign(Sign sign, GameWorld gameWorld) {
super(sign, gameWorld);
public ReadySign(Sign sign, String[] lines, GameWorld gameWorld) {
super(sign, lines, gameWorld);
}
/**

View File

@ -42,8 +42,8 @@ public class RedstoneSign extends DSign {
private int repeat = 1;
private int repeatsToDo = 1;
public RedstoneSign(Sign sign, GameWorld gameWorld) {
super(sign, gameWorld);
public RedstoneSign(Sign sign, String[] lines, GameWorld gameWorld) {
super(sign, lines, gameWorld);
}
/**

View File

@ -17,6 +17,7 @@
package io.github.dre2n.dungeonsxl.sign;
import io.github.dre2n.dungeonsxl.world.GameWorld;
import org.bukkit.Material;
import org.bukkit.block.Sign;
/**
@ -28,8 +29,9 @@ public class ScriptSign extends DSign {
private String name;
public ScriptSign(Sign sign, GameWorld gameWorld) {
super(sign, gameWorld);
public ScriptSign(Sign sign, String[] lines, GameWorld gameWorld) {
super(sign, lines, gameWorld);
name = lines[1];
}
/**
@ -48,10 +50,18 @@ public class ScriptSign extends DSign {
public void onInit() {
SignScript script = plugin.getSignScripts().getByName(name);
for (String[] lines : script.getSigns()) {
getGameWorld().getDSigns().add(DSign.create(getSign(), lines, getGameWorld()));
DSign dSign = DSign.create(getSign(), lines, getGameWorld());
getGameWorld().getDSigns().add(dSign);
dSign.onInit();
if (!dSign.hasTriggers()) {
dSign.onTrigger();
}
}
getSign().getBlock().setType(Material.AIR);
}
@Override
public DSignType getType() {
return type;

View File

@ -33,7 +33,7 @@ public class SignScript {
private String name;
private List<String[]> signs = new ArrayList<>();
private List<String[]> signs;
/**
* @param file
@ -51,13 +51,13 @@ public class SignScript {
*/
public SignScript(String name, FileConfiguration config) {
this.name = name;
signs = new ArrayList<>(config.getKeys(false).size());
int i = 0;
for (String key : config.getKeys(false)) {
int index = NumberUtil.parseInt(key);
String[] lines = config.getStringList(key).toArray(signs.get(i));
signs.set(index, lines);
i++;
String[] lines = new String[]{};
lines = config.getStringList(key).toArray(lines);
signs.add(index, lines);
}
}

View File

@ -35,8 +35,8 @@ public class SoundMessageSign extends DSign {
private String msg;
private CopyOnWriteArrayList<Player> done = new CopyOnWriteArrayList<>();
public SoundMessageSign(Sign sign, GameWorld gameWorld) {
super(sign, gameWorld);
public SoundMessageSign(Sign sign, String[] lines, GameWorld gameWorld) {
super(sign, lines, gameWorld);
}
@Override

View File

@ -27,8 +27,8 @@ public class StartSign extends DSign {
private DSignType type = DSignTypeDefault.START;
public StartSign(Sign sign, GameWorld gameWorld) {
super(sign, gameWorld);
public StartSign(Sign sign, String[] lines, GameWorld gameWorld) {
super(sign, lines, gameWorld);
}
@Override

View File

@ -38,8 +38,8 @@ public class TriggerSign extends DSign {
private int triggerId;
private boolean initialized;
public TriggerSign(Sign sign, GameWorld gameWorld) {
super(sign, gameWorld);
public TriggerSign(Sign sign, String[] lines, GameWorld gameWorld) {
super(sign, lines, gameWorld);
}
@Override

View File

@ -34,8 +34,8 @@ public class WaveSign extends DSign {
private double mobCountIncreaseRate;
private boolean teleport;
public WaveSign(Sign sign, GameWorld gameWorld) {
super(sign, gameWorld);
public WaveSign(Sign sign, String[] lines, GameWorld gameWorld) {
super(sign, lines, gameWorld);
}
/**

View File

@ -27,8 +27,8 @@ public class CustomSign extends DSign {
private DSignType type = DSignTypeCustom.CUSTOM;
public CustomSign(Sign sign, GameWorld gameWorld) {
super(sign, gameWorld);
public CustomSign(Sign sign, String[] lines, GameWorld gameWorld) {
super(sign, lines, gameWorld);
}
@Override