Merge pull request #157 from DRE2N/resourcepacks

Per dungeon resourcepacks
This commit is contained in:
Daniel Saukel 2016-09-13 18:52:26 +02:00 committed by GitHub
commit ef0e4be52a
10 changed files with 215 additions and 2 deletions

View File

@ -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.

View File

@ -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,

View File

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

View File

@ -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"),

View File

@ -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<String, Object> externalMobProviders = new HashMap<>();
private Map<String, Object> 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<String, Object> 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");
}

View File

@ -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),

View File

@ -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),

View File

@ -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 <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 || 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;
}
}

11
pom.xml
View File

@ -45,7 +45,7 @@
<dependency>
<groupId>io.github.dre2n</groupId>
<artifactId>caliburn</artifactId>
<version>0.2</version>
<version>0.2.1</version>
</dependency>
<dependency>
<groupId>io.github.dre2n</groupId>
@ -74,6 +74,11 @@
<version>2.6.9</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.inventivetalent.resourcepackapi</groupId>
<artifactId>api</artifactId>
<version>2.2.1</version>
</dependency>
</dependencies>
<repositories>
<repository>
@ -92,6 +97,10 @@
<id>betonquest-repo</id>
<url>http://betonquest.betoncraft.pl/mvn</url>
</repository>
<repository>
<id>inventive-repo</id>
<url>http://repo.inventivetalent.org/content/groups/public/</url>
</repository>
<repository>
<id>dre2n-repo</id>
<url>http://feuerstern.bplaced.net/repo/</url>

View File

@ -29,6 +29,10 @@
<pattern>io.github.dre2n.commons</pattern>
<shadedPattern>io.github.dre2n.dungeonsxl.util.commons</shadedPattern>
</relocation>
<relocation>
<pattern>org.inventivetalent.rpapi</pattern>
<shadedPattern>io.github.dre2n.dungeonsxl.util.resourcepackapi</shadedPattern>
</relocation>
</relocations>
<artifactSet>
<includes>
@ -36,6 +40,7 @@
<include>io.github.dre2n:caliburn</include>
<include>io.github.dre2n:debukkit</include>
<include>io.github.dre2n:dungeonsxl-*</include>
<include>org.inventivetalent.resourcepackapi:api</include>
</includes>
</artifactSet>
</configuration>