diff --git a/README.md b/README.md index 60865bf5..b78fc0b7 100644 --- a/README.md +++ b/README.md @@ -33,6 +33,7 @@ DungeonsXL also provides custom game mechanics to make these worlds interesting. * Different game types allow you to use your maps dynamically for different purposes. [Read more...](../../wiki/game-types) * Announcements sothat users can join the next match easily. [Read more...](../../wiki/announcements) * Great performance due to a custom, asynchronous world loading and creation method and several other performance tweaks +* Per dungeon resource packs * ...and many more! @@ -72,6 +73,9 @@ Maven automatically fetches all dependencies and builds DungeonsXL; just run _bu #### Caliburn API [Caliburn](https://github.com/DRE2N/CaliburnAPI) is an API to read custom items and mobs from config files. DungeonsXL contains Caliburn Beta 0.2.1. +#### ResourcePackAPI +inventivetalent's [ResourcePackAPI](https://www.spigotmc.org/resources/api-resourcepackapi-1-7-1-8-1-9-1-10.2397/) is an API to set the resourcepack of a player. DungeonsXL contains ResourcePackAPI 2.2.1. + ### Java Make sure that your server uses Java 7 or higher. diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/command/DCommands.java b/core/src/main/java/io/github/dre2n/dungeonsxl/command/DCommands.java index c1d97e11..05e41a3a 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/command/DCommands.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/command/DCommands.java @@ -48,6 +48,7 @@ public class DCommands extends BRCommands { public static PlayCommand PLAY = new PlayCommand(); public static PortalCommand PORTAL = new PortalCommand(); public static ReloadCommand RELOAD = new ReloadCommand(); + public static ResourcePackCommand RESOURCE_PACK = new ResourcePackCommand(); public static RewardsCommand REWARDS = new RewardsCommand(); public static SaveCommand SAVE = new SaveCommand(); public static StatusCommand STATUS = new StatusCommand(); @@ -78,6 +79,7 @@ public class DCommands extends BRCommands { PLAY, PORTAL, RELOAD, + RESOURCE_PACK, REWARDS, SAVE, STATUS, diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/command/ResourcePackCommand.java b/core/src/main/java/io/github/dre2n/dungeonsxl/command/ResourcePackCommand.java new file mode 100644 index 00000000..6caf1a9c --- /dev/null +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/command/ResourcePackCommand.java @@ -0,0 +1,63 @@ +/* + * 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.command; + +import io.github.dre2n.commons.command.BRCommand; +import io.github.dre2n.commons.util.messageutil.MessageUtil; +import io.github.dre2n.dungeonsxl.DungeonsXL; +import io.github.dre2n.dungeonsxl.config.DMessages; +import io.github.dre2n.dungeonsxl.player.DPermissions; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; +import org.inventivetalent.rpapi.ResourcePackAPI; + +/** + * @author Daniel Saukel + */ +public class ResourcePackCommand extends BRCommand { + + DungeonsXL plugin = DungeonsXL.getInstance(); + + public ResourcePackCommand() { + setCommand("resourcepack"); + setMinArgs(1); + setMaxArgs(1); + setHelp(DMessages.HELP_CMD_RESOURCE_PACK.getMessage()); + setPermission(DPermissions.RESOURCE_PACK.getNode()); + setPlayerCommand(true); + } + + @Override + public void onExecute(String[] args, CommandSender sender) { + Player player = (Player) sender; + + if (args[1].equalsIgnoreCase("reset")) { + // Placeholder to reset to default + ResourcePackAPI.setResourcepack(player, "http://google.com"); + return; + } + + String url = (String) plugin.getMainConfig().getResourcePacks().get(args[1]); + if (url == null) { + MessageUtil.sendMessage(sender, DMessages.ERROR_NO_SUCH_RESOURCE_PACK.getMessage(args[1])); + return; + } + + ResourcePackAPI.setResourcepack(player, url); + } + +} diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/config/DMessages.java b/core/src/main/java/io/github/dre2n/dungeonsxl/config/DMessages.java index a6764fb5..ebe2078c 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/config/DMessages.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/config/DMessages.java @@ -85,6 +85,7 @@ public enum DMessages implements Messages { ERROR_NO_SUCH_GROUP("Error_NoSuchGroup", "&4The group &6&v1&4 does not exist!"), ERROR_NO_SUCH_MAP("Error_NoSuchMap", "&4The world &6&v1&4 does not exist!"), ERROR_NO_SUCH_PLAYER("Error_NoSuchPlayer", "&4The player &6&v1&4 does not exist!"), + ERROR_NO_SUCH_RESOURCE_PACK("Error_NoSuchResourcePack", "&4The resource pack &6&v1 &4is not registered in the main configuration file!"), ERROR_NO_SUCH_SHOP("Error_NoSuchShop", "&4Shop &v1 &4not found..."), ERROR_NOT_CAPTAIN("Error_NotCaptain", "&4You are not the captain of your group!"), ERROR_NOT_IN_DUNGEON("Error_NotInDungeon", "&4You are not in a dungeon!"), @@ -130,6 +131,7 @@ public enum DMessages implements Messages { HELP_CMD_PORTAL("Help_Cmd_Portal", "/dxl portal ([material=portal])- Creates a portal that leads into a dungeon"), HELP_CMD_RELOAD("Help_Cmd_Reload", "/dxl reload - Reloads the plugin"), HELP_CMD_REWARDS("Help_Cmd_Rewards", "/dxl rewards - Gives all left item rewards to the player"), + HELP_CMD_RESOURCE_PACK("Help_Cmd_ResourcePack", "/dxl resourcepack [ID] - Downloads a resourcepack registered in the main configuration file; use 'reset' to reset"), HELP_CMD_SAVE("Help_Cmd_Save", "/dxl save - Saves the current dungeon"), HELP_CMD_STATUS("Help_Cmd_Status", "/dxl status - Shows the technical status of DungeonsXL"), HELP_CMD_SETTINGS("Help_Cmd_Settings", "/dxl settings ([edit|global|player])- Opens the settings menu"), 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/player/DPermissions.java b/core/src/main/java/io/github/dre2n/dungeonsxl/player/DPermissions.java index a5955413..3f345d4a 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/player/DPermissions.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/player/DPermissions.java @@ -59,6 +59,7 @@ public enum DPermissions { PLAY("play", OP), PORTAL("portal", OP), RELOAD("reload", OP), + RESOURCE_PACK("resourcepack", OP), REWARDS("rewards", TRUE), SAVE("save", OP), STATUS("status", OP), 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..e16436fe --- /dev/null +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/sign/ResourcePackSign.java @@ -0,0 +1,110 @@ +/* + * 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 || lines[1].equalsIgnoreCase("reset"); + } + + @Override + public void onInit() { + Object url = null; + if (lines[1].equalsIgnoreCase("reset")) { + // Placeholder to reset to default + url = "http://google.com"; + } else { + 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; + } + +} diff --git a/pom.xml b/pom.xml index 6b9b62e3..5b3a2ba7 100644 --- a/pom.xml +++ b/pom.xml @@ -45,7 +45,7 @@ io.github.dre2n caliburn - 0.2 + 0.2.1 io.github.dre2n @@ -74,6 +74,11 @@ 2.6.9 provided + + org.inventivetalent.resourcepackapi + api + 2.2.1 + @@ -92,6 +97,10 @@ betonquest-repo http://betonquest.betoncraft.pl/mvn + + inventive-repo + http://repo.inventivetalent.org/content/groups/public/ + dre2n-repo http://feuerstern.bplaced.net/repo/ diff --git a/shade/pom.xml b/shade/pom.xml index 23b07e46..f2dad90d 100644 --- a/shade/pom.xml +++ b/shade/pom.xml @@ -29,6 +29,10 @@ io.github.dre2n.commons io.github.dre2n.dungeonsxl.util.commons + + org.inventivetalent.rpapi + io.github.dre2n.dungeonsxl.util.resourcepackapi + @@ -36,6 +40,7 @@ io.github.dre2n:caliburn io.github.dre2n:debukkit io.github.dre2n:dungeonsxl-* + org.inventivetalent.resourcepackapi:api