1.0.0-SNAPSHOT-U161

+ Completed GiveRewardMainEditPanel
+ Started implementing the GiveRewardDrops panels
This commit is contained in:
Charles 2019-01-02 14:56:16 +08:00
parent 6f64e31251
commit ab87e02294
7 changed files with 296 additions and 8 deletions

View File

@ -2656,11 +2656,11 @@ GiveRewardMainEditMenu:
- '&75% then you need to do 5% damage to the boss to'
- '&7get the rewards in this drop section.'
- '&7'
- '&bLeft Click &8» &f+1'
- '&bShift Left-Click &8» &f+10'
- '&bLeft Click &8» &f+1%'
- '&bShift Left-Click &8» &f+10%'
- '&7'
- '&bRight Click &8» &f-1'
- '&bShift Right-Click &8» &f-10'
- '&bRight Click &8» &f-1%'
- '&bShift Right-Click &8» &f-10%'
Button: RequiredPercentage
'15':
type: CHEST

View File

@ -3,16 +3,23 @@ package com.songoda.epicbosses.panel.droptables.types.give;
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.panel.droptables.types.give.handlers.GiveRewardEditHandler;
import com.songoda.epicbosses.utils.Message;
import com.songoda.epicbosses.utils.NumberUtils;
import com.songoda.epicbosses.utils.ObjectUtils;
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.entity.Player;
import org.bukkit.event.inventory.ClickType;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.player.PlayerEvent;
import java.util.HashMap;
import java.util.Map;
@ -24,8 +31,12 @@ import java.util.Map;
*/
public class GiveRewardMainEditPanel extends SubVariablePanelHandler<DropTable, GiveRewardEditHandler> {
private CustomBosses plugin;
public GiveRewardMainEditPanel(BossPanelManager bossPanelManager, PanelBuilder panelBuilder, CustomBosses plugin) {
super(bossPanelManager, panelBuilder);
this.plugin = plugin;
}
@Override
@ -41,7 +52,6 @@ public class GiveRewardMainEditPanel extends SubVariablePanelHandler<DropTable,
Boolean randomDrops = ObjectUtils.getValue(giveTableSubElement.getRandomDrops(), false);
Boolean randomCommands = ObjectUtils.getValue(giveTableSubElement.getRandomCommands(), false);
replaceMap.put("{name}", BossAPI.getDropTableName(dropTable));
replaceMap.put("{position}", giveRewardEditHandler.getDamagePosition());
replaceMap.put("{randomDrops}", ""+randomDrops);
@ -53,11 +63,17 @@ public class GiveRewardMainEditPanel extends SubVariablePanelHandler<DropTable,
replaceMap.put("{randomCommands}", ""+randomCommands);
panelBuilder.addReplaceData(replaceMap);
PanelBuilderCounter panelBuilderCounter = panelBuilder.getPanelBuilderCounter();
PanelBuilderCounter counter = panelBuilder.getPanelBuilderCounter();
Panel panel = panelBuilder.getPanel()
.setParentPanelHandler(this.bossPanelManager.getGiveRewardRewardsListMenu(), dropTable, giveRewardEditHandler.getGiveTableElement(), giveRewardEditHandler.getDamagePosition());
//handle buttons
counter.getSlotsWith("RandomDrops").forEach(slot -> panel.setOnClick(slot, getRandomDropsAction(dropTable, giveRewardEditHandler)));
counter.getSlotsWith("MaxDrops").forEach(slot -> panel.setOnClick(slot, getMaxDropsAction(dropTable, giveRewardEditHandler)));
counter.getSlotsWith("ItemDrops").forEach(slot -> {});
counter.getSlotsWith("RequiredPercentage").forEach(slot -> panel.setOnClick(slot, getRequiredPercentageAction(dropTable, giveRewardEditHandler)));
counter.getSlotsWith("CommandDrops").forEach(slot -> {});
counter.getSlotsWith("MaxCommands").forEach(slot -> panel.setOnClick(slot, getMaxCommandsAction(dropTable, giveRewardEditHandler)));
counter.getSlotsWith("RandomDrops").forEach(slot -> panel.setOnClick(slot, getRandomCommandsAction(dropTable, giveRewardEditHandler)));
panel.openFor(player);
}
@ -71,4 +87,147 @@ public class GiveRewardMainEditPanel extends SubVariablePanelHandler<DropTable,
public void initializePanel(PanelBuilder panelBuilder) {
}
private ClickAction getRequiredPercentageAction(DropTable dropTable, GiveRewardEditHandler giveRewardEditHandler) {
return event -> {
GiveTableSubElement giveTableSubElement = giveRewardEditHandler.getGiveTableSubElement();
ClickType clickType = event.getClick();
double amountToModifyBy;
if(clickType == ClickType.SHIFT_LEFT) {
amountToModifyBy = 10;
} else if(clickType == ClickType.RIGHT) {
amountToModifyBy = -1;
} else if(clickType == ClickType.SHIFT_RIGHT) {
amountToModifyBy = -10;
} else {
amountToModifyBy = 1;
}
String modifyValue = amountToModifyBy > 0? "increased" : "decreased";
double currentAmount = ObjectUtils.getValue(giveTableSubElement.getRequiredPercentage(), 0.0);
double newAmount = currentAmount + amountToModifyBy;
if(newAmount < 0) {
newAmount = 0;
}
if(newAmount > 100) {
newAmount = 100;
}
giveTableSubElement.setRequiredPercentage(newAmount);
saveDropTable(dropTable, giveRewardEditHandler, event);
Message.Boss_DropTable_GiveMaxCommands.msg(event.getWhoClicked(), modifyValue, BossAPI.getDropTableName(dropTable), NumberUtils.get().formatDouble(newAmount));
};
}
private ClickAction getMaxCommandsAction(DropTable dropTable, GiveRewardEditHandler giveRewardEditHandler) {
return event -> {
GiveTableSubElement giveTableSubElement = giveRewardEditHandler.getGiveTableSubElement();
ClickType clickType = event.getClick();
int amountToModifyBy;
if(clickType == ClickType.SHIFT_LEFT) {
amountToModifyBy = 10;
} else if(clickType == ClickType.RIGHT) {
amountToModifyBy = -1;
} else if(clickType == ClickType.SHIFT_RIGHT) {
amountToModifyBy = -10;
} else {
amountToModifyBy = 1;
}
String modifyValue = amountToModifyBy > 0? "increased" : "decreased";
int currentAmount = ObjectUtils.getValue(giveTableSubElement.getMaxCommands(), 3);
int newAmount = currentAmount + amountToModifyBy;
if(newAmount < -1) {
newAmount = -1;
}
giveTableSubElement.setMaxCommands(newAmount);
saveDropTable(dropTable, giveRewardEditHandler, event);
Message.Boss_DropTable_GiveMaxCommands.msg(event.getWhoClicked(), modifyValue, BossAPI.getDropTableName(dropTable), NumberUtils.get().formatDouble(newAmount));
};
}
private ClickAction getMaxDropsAction(DropTable dropTable, GiveRewardEditHandler giveRewardEditHandler) {
return event -> {
GiveTableSubElement giveTableSubElement = giveRewardEditHandler.getGiveTableSubElement();
ClickType clickType = event.getClick();
int amountToModifyBy;
if(clickType == ClickType.SHIFT_LEFT) {
amountToModifyBy = 10;
} else if(clickType == ClickType.RIGHT) {
amountToModifyBy = -1;
} else if(clickType == ClickType.SHIFT_RIGHT) {
amountToModifyBy = -10;
} else {
amountToModifyBy = 1;
}
String modifyValue = amountToModifyBy > 0? "increased" : "decreased";
int currentAmount = ObjectUtils.getValue(giveTableSubElement.getMaxDrops(), 3);
int newAmount = currentAmount + amountToModifyBy;
if(newAmount < -1) {
newAmount = -1;
}
giveTableSubElement.setMaxDrops(newAmount);
saveDropTable(dropTable, giveRewardEditHandler, event);
Message.Boss_DropTable_GiveMaxDrops.msg(event.getWhoClicked(), modifyValue, BossAPI.getDropTableName(dropTable), NumberUtils.get().formatDouble(newAmount));
};
}
private ClickAction getRandomDropsAction(DropTable dropTable, GiveRewardEditHandler giveRewardEditHandler) {
return event -> {
GiveTableSubElement giveTableSubElement = giveRewardEditHandler.getGiveTableSubElement();
boolean randomValue = ObjectUtils.getValue(giveTableSubElement.getRandomDrops(), false);
boolean newValue = !randomValue;
giveTableSubElement.setRandomDrops(newValue);
saveDropTable(dropTable, giveRewardEditHandler, event);
Message.Boss_DropTable_GiveRandomDrops.msg(event.getWhoClicked(), BossAPI.getDropTableName(dropTable), newValue);
};
}
private ClickAction getRandomCommandsAction(DropTable dropTable, GiveRewardEditHandler giveRewardEditHandler) {
return event -> {
GiveTableSubElement giveTableSubElement = giveRewardEditHandler.getGiveTableSubElement();
boolean randomValue = ObjectUtils.getValue(giveTableSubElement.getRandomCommands(), false);
boolean newValue = !randomValue;
giveTableSubElement.setRandomCommands(newValue);
saveDropTable(dropTable, giveRewardEditHandler, event);
Message.Boss_DropTable_GiveRandomDrops.msg(event.getWhoClicked(), BossAPI.getDropTableName(dropTable), newValue);
};
}
private void saveDropTable(DropTable dropTable, GiveRewardEditHandler giveRewardEditHandler, InventoryClickEvent event) {
GiveTableElement giveTableElement = giveRewardEditHandler.getGiveTableElement();
GiveTableSubElement giveTableSubElement = giveRewardEditHandler.getGiveTableSubElement();
Map<String, Map<String, GiveTableSubElement>> rewardMap = giveTableElement.getGiveRewards();
String itemSlot = giveRewardEditHandler.getDropSection();
String damagePosition = giveRewardEditHandler.getDamagePosition();
Map<String, GiveTableSubElement> itemMap = rewardMap.get(damagePosition);
itemMap.put(itemSlot, giveTableSubElement);
rewardMap.put(damagePosition, itemMap);
giveTableElement.setGiveRewards(rewardMap);
dropTable.setRewards(BossAPI.convertObjectToJsonObject(giveTableElement));
this.plugin.getDropTableFileManager().save();
openFor((Player) event.getWhoClicked(), dropTable, giveRewardEditHandler);
}
}

View File

@ -0,0 +1,106 @@
package com.songoda.epicbosses.panel.droptables.types.give.drops;
import com.songoda.epicbosses.CustomBosses;
import com.songoda.epicbosses.api.BossAPI;
import com.songoda.epicbosses.droptable.DropTable;
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.panel.droptables.types.give.handlers.GiveRewardEditHandler;
import com.songoda.epicbosses.utils.NumberUtils;
import com.songoda.epicbosses.utils.itemstack.ItemStackUtils;
import com.songoda.epicbosses.utils.panel.Panel;
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.inventory.ItemStack;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* @author Charles Cullen
* @version 1.0.0
* @since 02-Jan-19
*/
public class GiveRewardDropsListEditPanel extends SubVariablePanelHandler<DropTable, GiveRewardEditHandler> {
private ItemsFileManager itemsFileManager;
private CustomBosses plugin;
public GiveRewardDropsListEditPanel(BossPanelManager bossPanelManager, PanelBuilder panelBuilder, CustomBosses plugin) {
super(bossPanelManager, panelBuilder);
this.itemsFileManager = plugin.getItemStackManager();
this.plugin = plugin;
}
@Override
public void fillPanel(Panel panel, DropTable dropTable, GiveRewardEditHandler giveRewardEditHandler) {
GiveTableSubElement giveTableSubElement = giveRewardEditHandler.getGiveTableSubElement();
Map<String, Double> rewardMap = giveTableSubElement.getItems();
List<String> keyList = new ArrayList<>();
int maxPage = panel.getMaxPage(keyList);
panel.setOnPageChange((player, currentPage, requestedPage) -> {
if(requestedPage < 0 || requestedPage > maxPage) return false;
loadPage(panel, requestedPage, dropTable, giveRewardEditHandler, rewardMap, keyList);
return true;
});
loadPage(panel, 0, dropTable, giveRewardEditHandler, rewardMap, keyList);
}
@Override
public void openFor(Player player, DropTable dropTable, GiveRewardEditHandler giveRewardEditHandler) {
PanelBuilder panelBuilder = getPanelBuilder().cloneBuilder();
Map<String, String> replaceMap = new HashMap<>();
replaceMap.put("{name}", BossAPI.getDropTableName(dropTable));
panelBuilder.addReplaceData(replaceMap);
PanelBuilderCounter panelBuilderCounter = panelBuilder.getPanelBuilderCounter();
Panel panel = panelBuilder.getPanel()
.setParentPanelHandler(this.bossPanelManager.getGiveRewardMainEditMenu(), dropTable, giveRewardEditHandler);
// panelBuilderCounter.getSlotsWith("NewReward").forEach(slot -> panel.setOnClick(slot, event -> this.bossPanelManager.getSprayNewRewardEditMenu().openFor((Player) event.getWhoClicked(), dropTable, giveRewardEditHandler)));
fillPanel(panel, dropTable, giveRewardEditHandler);
panel.openFor(player);
}
@Override
public void initializePanel(PanelBuilder panelBuilder) {
}
private void loadPage(Panel panel, int page, DropTable dropTable, GiveRewardEditHandler giveRewardEditHandler, Map<String, Double> rewardMap, List<String> keyList) {
panel.loadPage(page, (slot, realisticSlot) -> {
if(slot >= keyList.size()) {
panel.setItem(realisticSlot, new ItemStack(Material.AIR), e -> {});
} else {
String name = keyList.get(slot);
Double chance = rewardMap.get(name);
Map<String, String> replaceMap = new HashMap<>();
if(chance == null) chance = 100.0;
replaceMap.put("{itemName}", name);
replaceMap.put("{chance}", NumberUtils.get().formatDouble(chance));
ItemStack itemStack = this.itemsFileManager.getItemStackConverter().from(this.itemsFileManager.getItemStackHolder(name));
ItemStackUtils.applyDisplayName(itemStack, this.plugin.getConfig().getString("Display.DropTable.RewardList.name"), replaceMap);
ItemStackUtils.applyDisplayLore(itemStack, this.plugin.getConfig().getStringList("Display.DropTable.RewardList.lore"), replaceMap);
// panel.setItem(realisticSlot, itemStack, event -> this.bossPanelManager.getSprayRewardMainEditMenu().openFor((Player) event.getWhoClicked(), dropTable, giveRewardEditHandler, name));
}
});
}
}

View File

@ -0,0 +1,9 @@
package com.songoda.epicbosses.panel.droptables.types.give.drops;
/**
* @author Charles Cullen
* @version 1.0.0
* @since 02-Jan-19
*/
public class GiveRewardDropsMainEditPanel {
}

View File

@ -0,0 +1,9 @@
package com.songoda.epicbosses.panel.droptables.types.give.drops;
/**
* @author Charles Cullen
* @version 1.0.0
* @since 02-Jan-19
*/
public class GiveRewardDropsNewDropEditPanel {
}

View File

@ -44,6 +44,11 @@ public enum Message {
Boss_DropTable_DropAddedNewReward("&b&lEpicBosses &8» &7You have added a new reward to the drop table &f{0}&7. Now opening the editing panel for the new reward."),
Boss_DropTable_DropRewardChance("&b&lEpicBosses &8» &7You have {0} the chance for the reward section for &f{1}&7 to &f{2}%&7."),
Boss_DropTable_DropRewardRemoved("&b&lEpicBosses &8» &7You have removed the reward section from the drop drop table."),
Boss_DropTable_GiveRandomDrops("&b&lEpicBosses &8» &7You have set the random drops for the &f{0}&7 drop table to &f{1}&7."),
Boss_DropTable_GiveRandomCommands("&b&lEpicBosses &8» &7You have set the random commands for the &f{0}&7 drop table to &f{1}&7."),
Boss_DropTable_GiveMaxDrops("&b&lEpicBosses &8» &7You have {0} the max drops for the &f{1}&7 damage section to &f{1}&7."),
Boss_DropTable_GiveMaxCommands("&b&lEpicBosses &8» &7You have {0} the max commands for the &f{1}&7 damage section to &f{1}&7."),
Boss_DropTable_GiveRequiredPercentage("&b&lEpicBosses &8» &7You have {0} the required percentage for the &f{1}&7 damage section to &f{1}&7."),
Boss_Edit_NoPermission("&c&l(!) &cYou do not have access to this command."),
Boss_Edit_ItemStackHolderNull("&c&l(!) &cThe itemstack name that is provided for the spawn item doesn't exist or wasn't found."),

View File

@ -20,7 +20,7 @@
<properties>
<!--<plugin.version>maven-version-number-SNAPSHOT-U90</plugin.version>-->
<plugin.version>1.0.0-U160</plugin.version>
<plugin.version>1.0.0-U161</plugin.version>
<plugin.name>EpicBosses</plugin.name>
<plugin.main>com.songoda.epicbosses.CustomBosses</plugin.main>
<plugin.author>AMinecraftDev</plugin.author>