#154: Resource pack signs

This commit is contained in:
Daniel Saukel 2016-09-11 22:20:52 +02:00
parent cd8af05227
commit 65cb1ebd16
3 changed files with 122 additions and 1 deletions

View File

@ -45,7 +45,7 @@ public class MainConfig extends BRConfig {
NEVER NEVER
} }
public static final int CONFIG_VERSION = 12; public static final int CONFIG_VERSION = 13;
private String language = "english"; private String language = "english";
private boolean enableEconomy = false; private boolean enableEconomy = false;
@ -79,6 +79,7 @@ public class MainConfig extends BRConfig {
/* Misc */ /* Misc */
private boolean sendFloorTitle = true; private boolean sendFloorTitle = true;
private Map<String, Object> externalMobProviders = new HashMap<>(); private Map<String, Object> externalMobProviders = new HashMap<>();
private Map<String, Object> resourcePacks = new HashMap<>();
/* Performance */ /* Performance */
private int maxInstances = 10; private int maxInstances = 10;
@ -249,6 +250,13 @@ public class MainConfig extends BRConfig {
return externalMobProviders; return externalMobProviders;
} }
/**
* @return the resource pack index
*/
public Map<String, Object> getResourcePacks() {
return resourcePacks;
}
/** /**
* @return the maximum amount of worlds to instantiate at once * @return the maximum amount of worlds to instantiate at once
*/ */
@ -422,6 +430,10 @@ public class MainConfig extends BRConfig {
config.createSection("externalMobProviders"); config.createSection("externalMobProviders");
} }
if (!config.contains("resourcePacks")) {
config.createSection("resourcePacks");
}
if (!config.contains("maxInstances")) { if (!config.contains("maxInstances")) {
config.set("maxInstances", maxInstances); config.set("maxInstances", maxInstances);
} }
@ -514,6 +526,10 @@ public class MainConfig extends BRConfig {
externalMobProviders = config.getConfigurationSection("externalMobProviders").getValues(false); externalMobProviders = config.getConfigurationSection("externalMobProviders").getValues(false);
} }
if (config.contains("resourcePacks")) {
resourcePacks = config.getConfigurationSection("resourcePacks").getValues(false);
}
if (config.contains("maxInstances")) { if (config.contains("maxInstances")) {
maxInstances = config.getInt("maxInstances"); maxInstances = config.getInt("maxInstances");
} }

View File

@ -52,6 +52,7 @@ public enum DSignTypeDefault implements DSignType {
PROTECTION("Protection", "protection", false, false, ProtectionSign.class), PROTECTION("Protection", "protection", false, false, ProtectionSign.class),
READY("Ready", "ready", true, true, ReadySign.class), READY("Ready", "ready", true, true, ReadySign.class),
REDSTONE("Redstone", "redstone", false, false, RedstoneSign.class), REDSTONE("Redstone", "redstone", false, false, RedstoneSign.class),
RESOURCE_PACK("ResourcePack", "resourcepack", true, true, ResourcePackSign.class),
SCRIPT("Script", "script", false, false, ScriptSign.class), SCRIPT("Script", "script", false, false, ScriptSign.class),
SOUND_MESSAGE("SoundMSG", "soundmsg", false, false, SoundMessageSign.class), SOUND_MESSAGE("SoundMSG", "soundmsg", false, false, SoundMessageSign.class),
START("Start", "start", true, false, StartSign.class), START("Start", "start", true, false, StartSign.class),

View File

@ -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 <http://www.gnu.org/licenses/>.
*/
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;
}
}