From 65cb1ebd16ece8ae0f5b890b34070248f8ee95f4 Mon Sep 17 00:00:00 2001 From: Daniel Saukel Date: Sun, 11 Sep 2016 22:20:52 +0200 Subject: [PATCH] #154: Resource pack signs --- .../dre2n/dungeonsxl/config/MainConfig.java | 18 ++- .../dungeonsxl/sign/DSignTypeDefault.java | 1 + .../dungeonsxl/sign/ResourcePackSign.java | 104 ++++++++++++++++++ 3 files changed, 122 insertions(+), 1 deletion(-) create mode 100644 core/src/main/java/io/github/dre2n/dungeonsxl/sign/ResourcePackSign.java diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/config/MainConfig.java b/core/src/main/java/io/github/dre2n/dungeonsxl/config/MainConfig.java index 57883c00..e80f8efb 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/config/MainConfig.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/config/MainConfig.java @@ -45,7 +45,7 @@ public class MainConfig extends BRConfig { NEVER } - public static final int CONFIG_VERSION = 12; + public static final int CONFIG_VERSION = 13; private String language = "english"; private boolean enableEconomy = false; @@ -79,6 +79,7 @@ public class MainConfig extends BRConfig { /* Misc */ private boolean sendFloorTitle = true; private Map externalMobProviders = new HashMap<>(); + private Map resourcePacks = new HashMap<>(); /* Performance */ private int maxInstances = 10; @@ -249,6 +250,13 @@ public class MainConfig extends BRConfig { return externalMobProviders; } + /** + * @return the resource pack index + */ + public Map getResourcePacks() { + return resourcePacks; + } + /** * @return the maximum amount of worlds to instantiate at once */ @@ -422,6 +430,10 @@ public class MainConfig extends BRConfig { config.createSection("externalMobProviders"); } + if (!config.contains("resourcePacks")) { + config.createSection("resourcePacks"); + } + if (!config.contains("maxInstances")) { config.set("maxInstances", maxInstances); } @@ -514,6 +526,10 @@ public class MainConfig extends BRConfig { externalMobProviders = config.getConfigurationSection("externalMobProviders").getValues(false); } + if (config.contains("resourcePacks")) { + resourcePacks = config.getConfigurationSection("resourcePacks").getValues(false); + } + if (config.contains("maxInstances")) { maxInstances = config.getInt("maxInstances"); } diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/sign/DSignTypeDefault.java b/core/src/main/java/io/github/dre2n/dungeonsxl/sign/DSignTypeDefault.java index 8910f494..9134c3e4 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/sign/DSignTypeDefault.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/sign/DSignTypeDefault.java @@ -52,6 +52,7 @@ public enum DSignTypeDefault implements DSignType { PROTECTION("Protection", "protection", false, false, ProtectionSign.class), READY("Ready", "ready", true, true, ReadySign.class), REDSTONE("Redstone", "redstone", false, false, RedstoneSign.class), + RESOURCE_PACK("ResourcePack", "resourcepack", true, true, ResourcePackSign.class), SCRIPT("Script", "script", false, false, ScriptSign.class), SOUND_MESSAGE("SoundMSG", "soundmsg", false, false, SoundMessageSign.class), START("Start", "start", true, false, StartSign.class), diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/sign/ResourcePackSign.java b/core/src/main/java/io/github/dre2n/dungeonsxl/sign/ResourcePackSign.java new file mode 100644 index 00000000..c99c1973 --- /dev/null +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/sign/ResourcePackSign.java @@ -0,0 +1,104 @@ +/* + * 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 . + */ +package io.github.dre2n.dungeonsxl.sign; + +import io.github.dre2n.dungeonsxl.trigger.InteractTrigger; +import io.github.dre2n.dungeonsxl.world.DGameWorld; +import org.bukkit.ChatColor; +import org.bukkit.Material; +import org.bukkit.block.Sign; +import org.bukkit.entity.Player; +import org.inventivetalent.rpapi.ResourcePackAPI; + +/** + * @author Daniel Saukel + */ +public class ResourcePackSign extends DSign { + + private DSignType type = DSignTypeDefault.RESOURCE_PACK; + + private String resourcePack; + + public ResourcePackSign(Sign sign, String[] lines, DGameWorld gameWorld) { + super(sign, lines, gameWorld); + } + + /* Getters and setters */ + @Override + public DSignType getType() { + return type; + } + + /** + * @return the external mob + */ + public String getResourcePack() { + return resourcePack; + } + + /** + * @param resourcePack + * the resource pack to set + */ + public void setExternalMob(String resourcePack) { + this.resourcePack = resourcePack; + } + + /* Actions */ + @Override + public boolean check() { + return plugin.getMainConfig().getResourcePacks().get(lines[1]) != null; + } + + @Override + public void onInit() { + Object url = plugin.getMainConfig().getResourcePacks().get(lines[1]); + + if (url instanceof String) { + resourcePack = (String) url; + + } else { + markAsErroneous(); + return; + } + + 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); + } + + String name = lines[1]; + getSign().setLine(0, ChatColor.DARK_BLUE + "############"); + getSign().setLine(1, ChatColor.DARK_GREEN + "Download"); + getSign().setLine(2, ChatColor.DARK_GREEN + name); + getSign().setLine(3, ChatColor.DARK_BLUE + "############"); + getSign().update(); + } + + @Override + public boolean onPlayerTrigger(Player player) { + ResourcePackAPI.setResourcepack(player, resourcePack); + return true; + } + +}