mirror of
https://github.com/songoda/EpicBosses.git
synced 2025-03-12 22:49:13 +01:00
1.0.0-SNAPSHOT-U152
+ Completed the GiveRewardPositionPanel + Added DefaultDropTableRewardItem
This commit is contained in:
parent
a51ca13bd2
commit
dcfc94bfc7
@ -1,4 +1,8 @@
|
||||
{
|
||||
"DefaultDropTableRewardItem": {
|
||||
"type": "DIAMOND",
|
||||
"name": "&c&lDefault DropTable Reward Item"
|
||||
},
|
||||
"DefaultMinionMenuSpawnItem": {
|
||||
"type": "ZOMBIE_SPAWN_EGG",
|
||||
"name": "&c&lDefault Minion Menu Spawn Item"
|
||||
|
@ -110,10 +110,18 @@ Display:
|
||||
RewardList:
|
||||
name: '&bReward Section'
|
||||
lore:
|
||||
- '&bSelected Item: &f{itemName}'
|
||||
- '&3Selected Item: &f{itemName}'
|
||||
- '&3Chance: &f{chance}%'
|
||||
- '&7'
|
||||
- '&7Click to modify this reward.'
|
||||
GiveRewardList:
|
||||
name: '&bReward Section'
|
||||
lore:
|
||||
- '&3Position: &f{position}'
|
||||
- '&3Drops: &f{dropAmount}'
|
||||
- '&7'
|
||||
- '&7Shift Right-Click to remove.'
|
||||
- '&7Left-Click to edit.'
|
||||
Shop:
|
||||
menuName: '&b&lEpicBosses &3&lShop'
|
||||
name: '&b&lBuy {name}''s Egg'
|
||||
|
@ -1,17 +1,28 @@
|
||||
package com.songoda.epicbosses.panel.droptables.types.give;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
import com.songoda.epicbosses.CustomBosses;
|
||||
import com.songoda.epicbosses.api.BossAPI;
|
||||
import com.songoda.epicbosses.droptable.DropTable;
|
||||
import com.songoda.epicbosses.droptable.elements.GiveTableElement;
|
||||
import com.songoda.epicbosses.droptable.elements.GiveTableSubElement;
|
||||
import com.songoda.epicbosses.droptable.elements.SprayTableElement;
|
||||
import com.songoda.epicbosses.managers.BossPanelManager;
|
||||
import com.songoda.epicbosses.managers.files.ItemsFileManager;
|
||||
import com.songoda.epicbosses.utils.Debug;
|
||||
import com.songoda.epicbosses.utils.Message;
|
||||
import com.songoda.epicbosses.utils.NumberUtils;
|
||||
import com.songoda.epicbosses.utils.itemstack.ItemStackUtils;
|
||||
import com.songoda.epicbosses.utils.itemstack.holder.ItemStackHolder;
|
||||
import com.songoda.epicbosses.utils.panel.Panel;
|
||||
import com.songoda.epicbosses.utils.panel.base.ClickAction;
|
||||
import com.songoda.epicbosses.utils.panel.base.handlers.SubVariablePanelHandler;
|
||||
import com.songoda.epicbosses.utils.panel.builder.PanelBuilder;
|
||||
import com.songoda.epicbosses.utils.panel.builder.PanelBuilderCounter;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.inventory.ClickType;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
@ -22,8 +33,14 @@ import java.util.*;
|
||||
*/
|
||||
public class GiveRewardPositionListPanel extends SubVariablePanelHandler<DropTable, GiveTableElement> {
|
||||
|
||||
private ItemsFileManager itemsFileManager;
|
||||
private CustomBosses plugin;
|
||||
|
||||
public GiveRewardPositionListPanel(BossPanelManager bossPanelManager, PanelBuilder panelBuilder, CustomBosses plugin) {
|
||||
super(bossPanelManager, panelBuilder);
|
||||
|
||||
this.plugin = plugin;
|
||||
this.itemsFileManager = plugin.getItemStackManager();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -56,13 +73,76 @@ public class GiveRewardPositionListPanel extends SubVariablePanelHandler<DropTab
|
||||
|
||||
}
|
||||
|
||||
private int getNextAvailablePosition(List<String> keys) {
|
||||
private void loadPage(Panel panel, int page, DropTable dropTable, GiveTableElement giveTableElement, List<String> keys, Map<String, Map<String, GiveTableSubElement>> rewards) {
|
||||
panel.loadPage(page, (slot, realisticSlot) -> {
|
||||
if(slot >= keys.size()) {
|
||||
panel.setItem(realisticSlot, new ItemStack(Material.AIR), e->{});
|
||||
} else {
|
||||
String position = keys.get(slot);
|
||||
Map<String, GiveTableSubElement> innerRewards = rewards.get(position);
|
||||
ItemStack itemStack = this.itemsFileManager.getItemStackConverter().from(this.itemsFileManager.getItemStackHolder("DefaultDropTableRewardItem"));
|
||||
int dropAmount = innerRewards.keySet().size();
|
||||
Map<String, String> replaceMap = new HashMap<>();
|
||||
|
||||
replaceMap.put("{position}", NumberUtils.get().formatDouble(Integer.valueOf(position)));
|
||||
replaceMap.put("{dropAmount}", NumberUtils.get().formatDouble(dropAmount));
|
||||
|
||||
return 0;
|
||||
ItemStackUtils.applyDisplayName(itemStack, this.plugin.getConfig().getString("Display.DropTable.GiveRewardList.name"), replaceMap);
|
||||
ItemStackUtils.applyDisplayLore(itemStack, this.plugin.getConfig().getStringList("Display.DropTable.GiveRewardList.lore"), replaceMap);
|
||||
|
||||
panel.setItem(realisticSlot, itemStack, event -> {
|
||||
ClickType clickType = event.getClick();
|
||||
|
||||
if(clickType == ClickType.SHIFT_RIGHT) {
|
||||
rewards.remove(position);
|
||||
giveTableElement.setGiveRewards(rewards);
|
||||
saveDropTable((Player) event.getWhoClicked(), dropTable, giveTableElement, BossAPI.convertObjectToJsonObject(giveTableElement));
|
||||
} else {
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private ClickAction getNewPositionAction(DropTable dropTable, GiveTableElement giveTableElement) {
|
||||
return event -> {};
|
||||
return event -> {
|
||||
Map<String, Map<String, GiveTableSubElement>> rewards = giveTableElement.getGiveRewards();
|
||||
List<String> keys = new ArrayList<>(giveTableElement.getGiveRewards().keySet());
|
||||
int nextAvailable = getNextAvailablePosition(keys);
|
||||
String nextKey = ""+nextAvailable;
|
||||
|
||||
if(rewards.containsKey(nextKey)) {
|
||||
Debug.FAILED_TO_CREATE_NEWPOSITION.debug(nextKey, BossAPI.getDropTableName(dropTable));
|
||||
return;
|
||||
}
|
||||
|
||||
rewards.put(nextKey, new HashMap<>());
|
||||
giveTableElement.setGiveRewards(rewards);
|
||||
saveDropTable((Player) event.getWhoClicked(), dropTable, giveTableElement, BossAPI.convertObjectToJsonObject(giveTableElement));
|
||||
};
|
||||
}
|
||||
|
||||
private int getNextAvailablePosition(List<String> keys) {
|
||||
if(keys.isEmpty()) return 1;
|
||||
|
||||
List<Integer> currentIds = new ArrayList<>();
|
||||
|
||||
keys.stream().filter(NumberUtils.get()::isInt).forEach(s -> currentIds.add(Integer.valueOf(s)));
|
||||
currentIds.sort(Comparator.naturalOrder());
|
||||
|
||||
for(int i = 1; i <= currentIds.size(); i++) {
|
||||
if(i < currentIds.get(i-1)) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
return currentIds.size()+1;
|
||||
}
|
||||
|
||||
private void saveDropTable(Player player, DropTable dropTable, GiveTableElement giveTableElement, JsonObject jsonObject) {
|
||||
dropTable.setRewards(jsonObject);
|
||||
this.plugin.getDropTableFileManager().save();
|
||||
openFor(player, dropTable, giveTableElement);
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,9 @@
|
||||
package com.songoda.epicbosses.panel.droptables.types.give;
|
||||
|
||||
/**
|
||||
* @author Charles Cullen
|
||||
* @version 1.0.0
|
||||
* @since 31-Dec-18
|
||||
*/
|
||||
public class GiveRewardRewardsListPanel {
|
||||
}
|
@ -38,6 +38,7 @@ public enum Debug {
|
||||
FAILED_TO_LOAD_BOSSLISTENERMANAGER("The boss listener manager tried to load again, but it has already loaded previously."),
|
||||
FAILED_TO_LOAD_CUSTOM_ITEM("The itemstack name that is provided ({0}) for the spawn item doesn't exist or wasn't found."),
|
||||
FAILED_TO_LOAD_MESSAGES("The messages name that is provided ({0}) doesn't exist or wasn't found."),
|
||||
FAILED_TO_CREATE_NEWPOSITION("A new position with the number of {0} was attempted to be added to the {1} droptable, however there was already a position filled there."),
|
||||
FAILED_TO_LOAD_COMMANDS("The commands name that is provided ({0}) doesn't exist or wasn't found."),
|
||||
FAILED_TO_CREATE_ACTIVE_BOSS_HOLDER("Something went wrong while trying to create an active boss holder for someone who is trying to spawn a boss."),
|
||||
FAILED_TO_GIVE_SPAWN_EGG("{0} tried to obtain a spawn egg for the boss {1} but it has not been set yet."),
|
||||
|
2
pom.xml
2
pom.xml
@ -20,7 +20,7 @@
|
||||
|
||||
<properties>
|
||||
<!--<plugin.version>maven-version-number-SNAPSHOT-U90</plugin.version>-->
|
||||
<plugin.version>1.0.0-U151</plugin.version>
|
||||
<plugin.version>1.0.0-U152</plugin.version>
|
||||
<plugin.name>EpicBosses</plugin.name>
|
||||
<plugin.main>com.songoda.epicbosses.CustomBosses</plugin.main>
|
||||
<plugin.author>AMinecraftDev</plugin.author>
|
||||
|
Loading…
Reference in New Issue
Block a user