mirror of
https://github.com/DRE2N/DungeonsXL.git
synced 2025-02-26 17:21:40 +01:00
Add /dxl rewards command
This commit is contained in:
parent
1a7dbfd434
commit
11f20b4656
@ -48,6 +48,7 @@ public class DCommands extends BRCommands {
|
|||||||
public static PlayCommand PLAY = new PlayCommand();
|
public static PlayCommand PLAY = new PlayCommand();
|
||||||
public static PortalCommand PORTAL = new PortalCommand();
|
public static PortalCommand PORTAL = new PortalCommand();
|
||||||
public static ReloadCommand RELOAD = new ReloadCommand();
|
public static ReloadCommand RELOAD = new ReloadCommand();
|
||||||
|
public static RewardsCommand REWARDS = new RewardsCommand();
|
||||||
public static SaveCommand SAVE = new SaveCommand();
|
public static SaveCommand SAVE = new SaveCommand();
|
||||||
public static StatusCommand STATUS = new StatusCommand();
|
public static StatusCommand STATUS = new StatusCommand();
|
||||||
public static TestCommand TEST = new TestCommand();
|
public static TestCommand TEST = new TestCommand();
|
||||||
@ -77,6 +78,7 @@ public class DCommands extends BRCommands {
|
|||||||
PLAY,
|
PLAY,
|
||||||
PORTAL,
|
PORTAL,
|
||||||
RELOAD,
|
RELOAD,
|
||||||
|
REWARDS,
|
||||||
SAVE,
|
SAVE,
|
||||||
STATUS,
|
STATUS,
|
||||||
TEST,
|
TEST,
|
||||||
|
@ -0,0 +1,66 @@
|
|||||||
|
/*
|
||||||
|
* 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.DGlobalPlayer;
|
||||||
|
import io.github.dre2n.dungeonsxl.player.DPermissions;
|
||||||
|
import io.github.dre2n.dungeonsxl.reward.DLootInventory;
|
||||||
|
import java.util.List;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Daniel Saukel
|
||||||
|
*/
|
||||||
|
public class RewardsCommand extends BRCommand {
|
||||||
|
|
||||||
|
DungeonsXL plugin = DungeonsXL.getInstance();
|
||||||
|
|
||||||
|
public RewardsCommand() {
|
||||||
|
setCommand("rewards");
|
||||||
|
setMinArgs(0);
|
||||||
|
setMaxArgs(0);
|
||||||
|
setHelp(DMessages.HELP_CMD_REWARDS.getMessage());
|
||||||
|
setPermission(DPermissions.REWARDS.getNode());
|
||||||
|
setPlayerCommand(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onExecute(String[] args, CommandSender sender) {
|
||||||
|
Player player = (Player) sender;
|
||||||
|
DGlobalPlayer dGlobalPlayer = plugin.getDPlayers().getByPlayer(player);
|
||||||
|
|
||||||
|
if (!dGlobalPlayer.hasRewardItemsLeft()) {
|
||||||
|
MessageUtil.sendMessage(player, DMessages.ERROR_NO_REWARDS_LEFT.getMessage());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
List<ItemStack> rewardItems = dGlobalPlayer.getRewardItems();
|
||||||
|
List<ItemStack> rewards = rewardItems.subList(0, rewardItems.size() > 54 ? 53 : rewardItems.size());
|
||||||
|
new DLootInventory(player, rewards.toArray(new ItemStack[54]));
|
||||||
|
rewardItems.removeAll(rewards);
|
||||||
|
if (rewardItems.isEmpty()) {
|
||||||
|
dGlobalPlayer.setRewardItems(null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -78,6 +78,7 @@ public enum DMessages implements Messages {
|
|||||||
ERROR_NO_PERMISSIONS("Error_NoPermissions", "&4You have no permission to do this!"),
|
ERROR_NO_PERMISSIONS("Error_NoPermissions", "&4You have no permission to do this!"),
|
||||||
ERROR_NO_PLAYER_COMMAND("Error_NoPlayerCommand", "&6/dxl &v1&4 cannot be executed as player!"),
|
ERROR_NO_PLAYER_COMMAND("Error_NoPlayerCommand", "&6/dxl &v1&4 cannot be executed as player!"),
|
||||||
ERROR_NO_PROTECTED_BLOCK("Error_NoDXLBlock", "&4This is not a block protected by DungeonsXL!"),
|
ERROR_NO_PROTECTED_BLOCK("Error_NoDXLBlock", "&4This is not a block protected by DungeonsXL!"),
|
||||||
|
ERROR_NO_REWARDS_LEFT("Error_NoRewardsLeft", "&4You do not have any item rewards left."),
|
||||||
ERROR_NO_SUCH_GROUP("Error_NoSuchGroup", "&4The group &6&v1&4 does not exist!"),
|
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_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_PLAYER("Error_NoSuchPlayer", "&4The player &6&v1&4 does not exist!"),
|
||||||
@ -92,6 +93,7 @@ public enum DMessages implements Messages {
|
|||||||
ERROR_REQUIREMENTS("Error_Requirements", "&4You don't fulfill the requirements for this dungeon!"),
|
ERROR_REQUIREMENTS("Error_Requirements", "&4You don't fulfill the requirements for this dungeon!"),
|
||||||
ERROR_SIGN_WRONG_FORMAT("Error_SignWrongFormat", "&4The sign is not written correctly!"),
|
ERROR_SIGN_WRONG_FORMAT("Error_SignWrongFormat", "&4The sign is not written correctly!"),
|
||||||
ERROR_TOO_MANY_INSTANCES("Error_TooManyInstances", "&4There are currently too many maps instantiated. Try it again in a few minutes!"),
|
ERROR_TOO_MANY_INSTANCES("Error_TooManyInstances", "&4There are currently too many maps instantiated. Try it again in a few minutes!"),
|
||||||
|
ERROR_TOO_MANY_REWARDS("Error_TooManyRewards", "&6You won too many rewards to show all of them in one inventory. Use &4/dxl rewards &6to receive the other ones."),
|
||||||
ERROR_TOO_MANY_TUTORIALS("Error_TooManyTutorials", "&4There are currently too many tutorials running. Try it again in a few minutes!"),
|
ERROR_TOO_MANY_TUTORIALS("Error_TooManyTutorials", "&4There are currently too many tutorials running. Try it again in a few minutes!"),
|
||||||
ERROR_TUTORIAL_NOT_EXIST("Error_TutorialNotExist", "&4Tutorial dungeon does not exist!"),
|
ERROR_TUTORIAL_NOT_EXIST("Error_TutorialNotExist", "&4Tutorial dungeon does not exist!"),
|
||||||
HELP_CMD_BREAK("Help_Cmd_Break", "/dxl break - Break a block protected by DungeonsXL"),
|
HELP_CMD_BREAK("Help_Cmd_Break", "/dxl break - Break a block protected by DungeonsXL"),
|
||||||
@ -123,6 +125,7 @@ public enum DMessages implements Messages {
|
|||||||
HELP_CMD_PLAY("Help_Cmd_Play", "/dxl play ([dungeon|map]) [name] - Allows the player to play a dungeon without a portal"),
|
HELP_CMD_PLAY("Help_Cmd_Play", "/dxl play ([dungeon|map]) [name] - Allows the player to play a dungeon without a portal"),
|
||||||
HELP_CMD_PORTAL("Help_Cmd_Portal", "/dxl portal ([material=portal])- Creates a portal that leads into a dungeon"),
|
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_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_SAVE("Help_Cmd_Save", "/dxl save - Saves the current dungeon"),
|
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_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"),
|
HELP_CMD_SETTINGS("Help_Cmd_Settings", "/dxl settings ([edit|global|player])- Opens the settings menu"),
|
||||||
|
@ -25,6 +25,7 @@ import io.github.dre2n.dungeonsxl.config.DMessages;
|
|||||||
import io.github.dre2n.dungeonsxl.config.PlayerData;
|
import io.github.dre2n.dungeonsxl.config.PlayerData;
|
||||||
import io.github.dre2n.dungeonsxl.global.DPortal;
|
import io.github.dre2n.dungeonsxl.global.DPortal;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.util.List;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
@ -50,6 +51,7 @@ public class DGlobalPlayer {
|
|||||||
|
|
||||||
private ItemStack[] respawnInventory;
|
private ItemStack[] respawnInventory;
|
||||||
private ItemStack[] respawnArmor;
|
private ItemStack[] respawnArmor;
|
||||||
|
private List<ItemStack> rewardItems;
|
||||||
|
|
||||||
public DGlobalPlayer(Player player) {
|
public DGlobalPlayer(Player player) {
|
||||||
this(player, false);
|
this(player, false);
|
||||||
@ -227,6 +229,28 @@ public class DGlobalPlayer {
|
|||||||
return DPermissions.hasPermission(player, permission);
|
return DPermissions.hasPermission(player, permission);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the reward items
|
||||||
|
*/
|
||||||
|
public List<ItemStack> getRewardItems() {
|
||||||
|
return rewardItems;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return if the player has reward items left
|
||||||
|
*/
|
||||||
|
public boolean hasRewardItemsLeft() {
|
||||||
|
return rewardItems != null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param rewardItems
|
||||||
|
* the reward items to set
|
||||||
|
*/
|
||||||
|
public void setRewardItems(List<ItemStack> rewardItems) {
|
||||||
|
this.rewardItems = rewardItems;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param permission
|
* @param permission
|
||||||
* the permission to check
|
* the permission to check
|
||||||
|
@ -59,6 +59,7 @@ public enum DPermissions {
|
|||||||
PLAY("play", OP),
|
PLAY("play", OP),
|
||||||
PORTAL("portal", OP),
|
PORTAL("portal", OP),
|
||||||
RELOAD("reload", OP),
|
RELOAD("reload", OP),
|
||||||
|
REWARDS("rewards", TRUE),
|
||||||
SAVE("save", OP),
|
SAVE("save", OP),
|
||||||
STATUS("status", OP),
|
STATUS("status", OP),
|
||||||
/**
|
/**
|
||||||
|
@ -16,6 +16,8 @@
|
|||||||
*/
|
*/
|
||||||
package io.github.dre2n.dungeonsxl.reward;
|
package io.github.dre2n.dungeonsxl.reward;
|
||||||
|
|
||||||
|
import io.github.dre2n.commons.util.messageutil.MessageUtil;
|
||||||
|
import io.github.dre2n.dungeonsxl.config.DMessages;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -71,7 +73,14 @@ public class ItemReward extends Reward {
|
|||||||
/* Actions */
|
/* Actions */
|
||||||
@Override
|
@Override
|
||||||
public void giveTo(Player player) {
|
public void giveTo(Player player) {
|
||||||
new DLootInventory(player, getItems());
|
if (items.size() <= 54) {
|
||||||
|
new DLootInventory(player, getItems());
|
||||||
|
|
||||||
|
} else {
|
||||||
|
new DLootInventory(player, items.subList(0, 54).toArray(new ItemStack[54]));
|
||||||
|
plugin.getDPlayers().getByPlayer(player).setRewardItems(items.subList(54, items.size()));
|
||||||
|
MessageUtil.sendMessage(player, DMessages.ERROR_TOO_MANY_REWARDS.getMessage());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user