Added script signs (untested)

This commit is contained in:
Daniel Saukel 2016-05-16 20:55:05 +02:00
parent 9e6ea22b39
commit 569ddf5a8a
21 changed files with 289 additions and 29 deletions

View File

@ -44,6 +44,7 @@ import io.github.dre2n.dungeonsxl.requirement.RequirementTypes;
import io.github.dre2n.dungeonsxl.reward.DLootInventory;
import io.github.dre2n.dungeonsxl.reward.RewardTypes;
import io.github.dre2n.dungeonsxl.sign.DSignTypes;
import io.github.dre2n.dungeonsxl.sign.SignScripts;
import io.github.dre2n.dungeonsxl.task.AnnouncerTask;
import io.github.dre2n.dungeonsxl.task.LazyUpdateTask;
import io.github.dre2n.dungeonsxl.task.SecureModeTask;
@ -73,6 +74,7 @@ public class DungeonsXL extends BRPlugin {
public static File ANNOUNCERS;
public static File CLASSES;
public static File MOBS;
public static File SIGNS;
private DataConfig dataConfig;
private MainConfig mainConfig;
@ -91,6 +93,7 @@ public class DungeonsXL extends BRPlugin {
private Announcers announcers;
private DClasses dClasses;
private DMobTypes dMobTypes;
private SignScripts signScripts;
private BukkitTask announcerTask;
private BukkitTask worldUnloadTask;
@ -150,6 +153,7 @@ public class DungeonsXL extends BRPlugin {
loadAnnouncers(ANNOUNCERS);
loadDClasses(CLASSES);
loadDMobTypes(MOBS);
loadSignScripts(SIGNS);
manager.registerEvents(new EntityListener(), this);
manager.registerEvents(new GUIListener(), this);
@ -242,6 +246,11 @@ public class DungeonsXL extends BRPlugin {
if (!MOBS.exists()) {
MOBS.mkdir();
}
SIGNS = new File(SCRIPTS, "signs");
if (!SIGNS.exists()) {
SIGNS.mkdir();
}
}
// Save and load
@ -543,6 +552,20 @@ public class DungeonsXL extends BRPlugin {
dMobTypes = new DMobTypes(file);
}
/**
* @return the loaded instance of SignScripts
*/
public SignScripts getSignScripts() {
return signScripts;
}
/**
* load / reload a new instance of SignScripts
*/
public void loadSignScripts(File file) {
signScripts = new SignScripts(file);
}
/**
* @return the worldUnloadTask
*/

View File

@ -32,9 +32,9 @@ import org.bukkit.plugin.PluginManager;
* @author Frank Baumann, Daniel Saukel
*/
public class ReloadCommand extends BRCommand {
DungeonsXL plugin = DungeonsXL.getInstance();
public ReloadCommand() {
setCommand("reload");
setMinArgs(0);
@ -44,11 +44,11 @@ public class ReloadCommand extends BRCommand {
setPlayerCommand(true);
setConsoleCommand(true);
}
@Override
public void onExecute(String[] args, CommandSender sender) {
PluginManager plugins = Bukkit.getServer().getPluginManager();
int maps = new File(plugin.getDataFolder() + "/maps").listFiles().length;
int dungeons = new File(plugin.getDataFolder() + "/dungeons").listFiles().length;
int loaded = plugin.getEditWorlds().size() + plugin.getGameWorlds().size();
@ -85,11 +85,12 @@ public class ReloadCommand extends BRCommand {
plugin.loadAnnouncers(DungeonsXL.ANNOUNCERS);
plugin.loadDClasses(DungeonsXL.CLASSES);
plugin.loadDMobTypes(DungeonsXL.MOBS);
plugin.loadSignScripts(DungeonsXL.SIGNS);
MessageUtil.sendPluginTag(sender, plugin);
MessageUtil.sendCenteredMessage(sender, DMessages.CMD_RELOAD_DONE.getMessage());
MessageUtil.sendCenteredMessage(sender, DMessages.CMD_MAIN_LOADED.getMessage(String.valueOf(maps), String.valueOf(dungeons), String.valueOf(loaded), String.valueOf(players)));
MessageUtil.sendCenteredMessage(sender, DMessages.CMD_MAIN_COMPATIBILITY.getMessage(String.valueOf(internals), vault, mythicMobs));
}
}

View File

@ -17,6 +17,7 @@
package io.github.dre2n.dungeonsxl.game;
import io.github.dre2n.commons.util.messageutil.MessageUtil;
import io.github.dre2n.dungeonsxl.sign.DSign;
import java.util.ArrayList;
import java.util.List;
import org.bukkit.block.Sign;
@ -60,7 +61,7 @@ public class GameTypes {
/**
* @return the game type which has the enum value sign text in the second line of the sign
*/
public GameType getBySign(Sign sign) {
public GameType getBySign(DSign sign) {
String[] lines = sign.getLines();
for (GameType type : types) {

View File

@ -47,7 +47,6 @@ public class BlockSign extends DSign {
@Override
public void onInit() {
String lines[] = getSign().getLines();
if (!lines[1].isEmpty()) {
String line1[] = lines[1].split(",");
Material offBlock = Material.matchMaterial(line1[0]);

View File

@ -44,7 +44,6 @@ public class ChestSign extends DSign {
@Override
public void onInit() {
String[] lines = getSign().getLines();
if (!lines[1].isEmpty()) {
String[] attributes = lines[1].split(",");
if (attributes.length >= 1) {

View File

@ -40,7 +40,6 @@ public class ChunkUpdaterSign extends DSign {
@Override
public void onInit() {
String lines[] = getSign().getLines();
Chunk chunk = getGameWorld().getWorld().getChunkAt(getSign().getBlock());
if (!lines[1].isEmpty()) {

View File

@ -55,7 +55,6 @@ public class ClassesSign extends DSign {
/* Actions */
@Override
public boolean check() {
String[] lines = getSign().getLines();
return plugin.getDClasses().getByName(lines[1]) != null;
}

View File

@ -50,7 +50,6 @@ public class CommandSign extends DSign {
@Override
public boolean check() {
String lines[] = getSign().getLines();
if (lines[1].isEmpty() || lines[2].isEmpty()) {
return false;
}
@ -70,7 +69,6 @@ public class CommandSign extends DSign {
@Override
public void onInit() {
String[] lines = getSign().getLines();
String[] attributes = lines[2].split(",");
command = lines[1];

View File

@ -131,7 +131,6 @@ public class DMobSign extends DSign implements MobSign {
@Override
public boolean check() {
String lines[] = getSign().getLines();
if (lines[1].isEmpty() || lines[2].isEmpty()) {
return false;
}
@ -151,7 +150,6 @@ public class DMobSign extends DSign implements MobSign {
@Override
public void onInit() {
String lines[] = getSign().getLines();
if (!lines[1].isEmpty() && !lines[2].isEmpty()) {
String mob = lines[1];
if (mob != null) {

View File

@ -37,13 +37,15 @@ public abstract class DSign {
static DungeonsXL plugin = DungeonsXL.getInstance();
private Sign sign;
protected String[] lines;
private GameWorld gameWorld;
// List of Triggers
private Set<Trigger> triggers = new HashSet<>();
public DSign(Sign sign, GameWorld gameWorld) {
this.setSign(sign);
this.sign = sign;
this.lines = sign.getLines();
this.gameWorld = gameWorld;
// Check Trigger
@ -88,6 +90,21 @@ public abstract class DSign {
this.sign = sign;
}
/**
* @return the sign lines
*/
public String[] getLines() {
return lines;
}
/**
* @param lines
* the sign lines to set
*/
public void setLines(String[] lines) {
this.lines = lines;
}
/**
* @return the gameWorld
*/
@ -169,7 +186,10 @@ public abstract class DSign {
}
public static DSign create(Sign sign, GameWorld gameWorld) {
String[] lines = sign.getLines();
return create(sign, sign.getLines(), gameWorld);
}
public static DSign create(Sign sign, String[] lines, GameWorld gameWorld) {
DSign dSign = null;
for (DSignType type : plugin.getDSigns().getDSigns()) {

View File

@ -42,6 +42,7 @@ public enum DSignTypeDefault implements DSignType {
PLACE("Place", "place", false, PlaceSign.class),
READY("Ready", "ready", true, ReadySign.class),
REDSTONE("Redstone", "redstone", false, RedstoneSign.class),
SCRIPT("Script", "script", false, ScriptSign.class),
SOUND_MESSAGE("SoundMSG", "soundmsg", false, SoundMessageSign.class),
START("Start", "start", true, StartSign.class),
TRIGGER("Trigger", "trigger", true, TriggerSign.class),

View File

@ -196,7 +196,6 @@ public class ExternalMobSign extends DSign implements MobSign {
@Override
public boolean check() {
String lines[] = getSign().getLines();
if (lines[1].isEmpty() || lines[2].isEmpty()) {
return false;
}
@ -216,8 +215,6 @@ public class ExternalMobSign extends DSign implements MobSign {
@Override
public void onInit() {
String lines[] = getSign().getLines();
String mob = lines[1];
if (mob != null) {
String[] attributes = lines[2].split(",");

View File

@ -44,7 +44,6 @@ public class FloorSign extends DSign {
@Override
public void onInit() {
String[] lines = getSign().getLines();
if (!lines[1].isEmpty()) {
floor = lines[1];
}

View File

@ -51,8 +51,6 @@ public class MessageSign extends DSign {
@Override
public void onInit() {
String lines[] = getSign().getLines();
if (!lines[1].isEmpty()) {
String msg = getGame().getRules().getMsg(NumberUtil.parseInt(lines[1]), true);
if (msg != null) {

View File

@ -39,7 +39,6 @@ public class PlaceSign extends DSign {
@Override
public void onInit() {
String lines[] = getSign().getLines();
getGameWorld().getPlaceableBlocks().add(new GamePlaceableBlock(getSign().getBlock(), lines[1], lines[2]));
getSign().getBlock().setType(Material.AIR);
}

View File

@ -65,8 +65,8 @@ public class ReadySign extends DSign {
@Override
public void onInit() {
if (plugin.getGameTypes().getBySign(getSign()) != null) {
gameType = plugin.getGameTypes().getBySign(getSign());
if (plugin.getGameTypes().getBySign(this) != null) {
gameType = plugin.getGameTypes().getBySign(this);
} else {
gameType = GameTypeDefault.DEFAULT;

View File

@ -0,0 +1,60 @@
/*
* 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.dungeonsxl.world.GameWorld;
import org.bukkit.block.Sign;
/**
* @author Daniel Saukel
*/
public class ScriptSign extends DSign {
private DSignType type = DSignTypeDefault.SCRIPT;
private String name;
public ScriptSign(Sign sign, GameWorld gameWorld) {
super(sign, gameWorld);
}
/**
* @return the name of the script
*/
public String getName() {
return name;
}
@Override
public boolean check() {
return plugin.getSignScripts().getByName(lines[1]) != null;
}
@Override
public void onInit() {
SignScript script = plugin.getSignScripts().getByName(name);
for (String[] lines : script.getSigns()) {
getGameWorld().getDSigns().add(DSign.create(getSign(), lines, getGameWorld()));
}
}
@Override
public DSignType getType() {
return type;
}
}

View File

@ -0,0 +1,97 @@
/*
* 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.NumberUtil;
import io.github.dre2n.dungeonsxl.DungeonsXL;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
/**
* @author Daniel Saukel
*/
public class SignScript {
DungeonsXL plugin = DungeonsXL.getInstance();
private String name;
private List<String[]> signs = new ArrayList<>();
/**
* @param file
* the script file
*/
public SignScript(File file) {
this(file.getName().substring(0, file.getName().length() - 4), YamlConfiguration.loadConfiguration(file));
}
/**
* @param name
* the name of the Announcer
* @param config
* the config that stores the information
*/
public SignScript(String name, FileConfiguration config) {
this.name = name;
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++;
}
}
/**
* @return the name of the announcer
*/
public String getName() {
return name;
}
/**
* @return the signs
*/
public List<String[]> getSigns() {
return signs;
}
/**
* @param index
* the index number
* @return the lines of the sign
*/
public String[] getLines(int index) {
return signs.get(index);
}
/**
* @param index
* the index number
* @param lines
* the lines to set
*/
public void setLines(int index, String[] lines) {
signs.set(index, lines);
}
}

View File

@ -0,0 +1,75 @@
/*
* 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.FileUtil;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
/**
* @author Daniel Saukel
*/
public class SignScripts {
private List<SignScript> scripts = new ArrayList<>();
public SignScripts(File file) {
if (file.isDirectory()) {
for (File script : FileUtil.getFilesForFolder(file)) {
scripts.add(new SignScript(script));
}
}
}
/**
* @return the script that has the name
*/
public SignScript getByName(String name) {
for (SignScript script : scripts) {
if (script.getName().equalsIgnoreCase(name)) {
return script;
}
}
return null;
}
/**
* @return the scripts
*/
public List<SignScript> getScripts() {
return scripts;
}
/**
* @param script
* the SignScript to add
*/
public void addScript(SignScript script) {
scripts.add(script);
}
/**
* @param script
* the SignScript to remove
*/
public void removeScript(SignScript script) {
scripts.remove(script);
}
}

View File

@ -50,8 +50,6 @@ public class SoundMessageSign extends DSign {
@Override
public void onInit() {
String lines[] = getSign().getLines();
if (!lines[1].isEmpty()) {
String msg = getGame().getRules().getMsg(NumberUtil.parseInt(lines[1]), true);
if (msg != null) {

View File

@ -75,7 +75,6 @@ public class WaveSign extends DSign {
@Override
public void onInit() {
String[] lines = getSign().getLines();
if (!lines[1].isEmpty()) {
mobCountIncreaseRate = NumberUtil.parseDouble(lines[1], 2);
}