Skip to content

Commit

Permalink
closes #143; And make ExperienceSources optional
Browse files Browse the repository at this point in the history
  • Loading branch information
NeumimTo committed Apr 26, 2020
1 parent c8dafc6 commit ce69d5a
Show file tree
Hide file tree
Showing 9 changed files with 46 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,9 @@ public Boolean convertFromField(Boolean value) {
private static class StringSet implements Converter<Set<String>, List<String>> {
@Override
public Set<String> convertToField(List<String> value) {
if (value == null) {
value = Collections.emptyList();
}
return new HashSet<>(value);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public static void initializeACF(CommandManager manager, List<BaseCommand> comma
Rpg.get().getSkillService().getSkills().keySet()
);

manager.getCommandCompletions().registerCompletion("learnedSkill", c -> {
manager.getCommandCompletions().registerCompletion("learnedskill", c -> {
UUID uuid = c.getIssuer().getUniqueId();
IActiveCharacter character = Rpg.get().getCharacterService().getCharacter(uuid);
Map<String, PlayerSkillContext> skills = character.getSkillsByName();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,10 @@ public Map<String, Object> initInventories(ClassLoader classLoader, String confN
CACHED_MENUS.put(guiName + "_weapons_" + classDef.getName(), i3);
}
break;
case "char_allowed_items":
ConfigInventory c5 = createCachedMenu(sFactorz, guiName, gui, null);
CACHED_MENUS.put(guiName, c5);
break;
case "char_view":
ConfigInventory c4 = createCachedMenu(sFactorz, guiName, gui, null);
CACHED_MENUS.put(guiName, c4);
Expand Down
1 change: 1 addition & 0 deletions Common/src/main/resources/guis.conf
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ gui: [
"-,,minecraft:gray_stained_glass_pane,12345,---"
"<,gui.button.back,minecraft:paper,12345,char"
]
template: true
conditions: ""
dynamic_space: "-"
command: """
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public class SpigotSkillBindCommands extends BaseCommand {
private SpigotInventoryService inventoryService;

@Default
@CommandCompletion("@learnedSkill")
@CommandCompletion("@learnedskill")
public void bindSkillCommand(Player executor, ISkill skill) {
if (!(skill instanceof ActiveSkill)) {
String msg = localizationService.translate(LocalizationKeys.CANNOT_BIND_NON_EXECUTABLE_SKILL);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -553,7 +553,7 @@ public static Inventory getCharacterAllowedArmor(ISpigotCharacter character, int
String name = "char_allowed_items_armor" + character.getName();
Inventory inventory = CACHED_MENUS.get(name);
if (inventory == null) {
TemplateInventory<ItemStack, Inventory> dView = (TemplateInventory<ItemStack, Inventory>) CACHED_MENU_TEMPLATES.get("char_view");
TemplateInventory<ItemStack, Inventory> dView = (TemplateInventory<ItemStack, Inventory>) CACHED_MENU_TEMPLATES.get("char_allowed_items");
Map<RpgItemType, Double> allowedWeapons = character.getAllowedWeapons();
List<ItemStack> content = new ArrayList<>();
for (Map.Entry<RpgItemType, Double> ent : allowedWeapons.entrySet()) {
Expand All @@ -575,7 +575,7 @@ public static Inventory getCharacterAllowedWeapons(ISpigotCharacter character, i
String name = "char_allowed_items_weapons" + character.getName();
Inventory inventory = CACHED_MENUS.get(name);
if (inventory == null) {
TemplateInventory<ItemStack, Inventory> dView = (TemplateInventory<ItemStack, Inventory>) CACHED_MENU_TEMPLATES.get("char_view");
TemplateInventory<ItemStack, Inventory> dView = (TemplateInventory<ItemStack, Inventory>) CACHED_MENU_TEMPLATES.get("char_allowed_items");
Set<RpgItemType> allowedWeapons = character.getAllowedArmor();
List<ItemStack> content = new ArrayList<>();
for (RpgItemType ent : allowedWeapons) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -643,7 +643,7 @@ public static Inventory getCharacterAllowedArmor(ISpongeCharacter character, int
String name = "char_allowed_items_armor" + character.getName();
Inventory inventory = CACHED_MENUS.get(name);
if (inventory == null) {
TemplateInventory<ItemStack, Inventory> dView = (TemplateInventory<ItemStack, Inventory>) CACHED_MENU_TEMPLATES.get("char_view");
TemplateInventory<ItemStack, Inventory> dView = (TemplateInventory<ItemStack, Inventory>) CACHED_MENU_TEMPLATES.get("char_allowed_items");
Map<RpgItemType, Double> allowedWeapons = character.getAllowedWeapons();
List<ItemStack> content = new ArrayList<>();
for (Map.Entry<RpgItemType, Double> ent : allowedWeapons.entrySet()) {
Expand All @@ -665,7 +665,7 @@ public static Inventory getCharacterAllowedWeapons(ISpongeCharacter character, i
String name = "char_allowed_items_weapons" + character.getName();
Inventory inventory = CACHED_MENUS.get(name);
if (inventory == null) {
TemplateInventory<ItemStack, Inventory> dView = (TemplateInventory<ItemStack, Inventory>) CACHED_MENU_TEMPLATES.get("char_view");
TemplateInventory<ItemStack, Inventory> dView = (TemplateInventory<ItemStack, Inventory>) CACHED_MENU_TEMPLATES.get("char_allowed_items");
Set<RpgItemType> allowedWeapons = character.getAllowedArmor();
List<ItemStack> content = new ArrayList<>();
for (RpgItemType ent : allowedWeapons) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -292,27 +292,47 @@ public void onSwapHands(ChangeInventoryEvent.SwapHand event, @Root Player player
if (!rpgItemStackMain.isPresent() && !rpgItemStackOff.isPresent()) {
return;
} else {
RpgItemStack futureOff = rpgItemStackOff.get();
RpgItemStack futureMain = rpgItemStackMain.get();
Map<Class<?>, RpgInventory> managedInventory = character.getManagedInventory();
RpgInventory rpgInventory = managedInventory.get(player.getInventory());
RpgInventory rpgInventory = managedInventory.get(player.getInventory().getClass());

Hotbar hotbar = player.getInventory()
.query(QueryOperationTypes.INVENTORY_TYPE.of(Hotbar.class));
int selectedSlotIndex = hotbar.getSelectedSlotIndex();

ManagedSlot managedSlotM = rpgInventory.getManagedSlots().get(selectedSlotIndex);
ManagedSlot offHandSlotO = rpgInventory.getManagedSlots().get(OFFHAND_SLOT_ID);

if (inventoryHandler.handleCharacterEquipActionPre(character, offHandSlotO, futureOff) &&
inventoryHandler.handleCharacterEquipActionPre(character, managedSlotM ,futureMain)
) {
Optional<RpgItemStack> content = managedSlotM.getContent();
Optional<RpgItemStack> content1 = offHandSlotO.getContent();
content.ifPresent(offHandSlotO::setContent);
content1.ifPresent(managedSlotM::setContent);
Optional<RpgItemStack> contentM = managedSlotM.getContent();
Optional<RpgItemStack> contentO = offHandSlotO.getContent();

if (rpgItemStackOff.isPresent() && !rpgItemStackMain.isPresent()) {
RpgItemStack futureOff = rpgItemStackOff.get();
if (inventoryHandler.handleCharacterEquipActionPre(character, offHandSlotO, futureOff)) {
managedSlotM.setContent(null);
offHandSlotO.setContent(futureOff);
} else {
event.setCancelled(true);
}
} else if (!rpgItemStackOff.isPresent()) {
RpgItemStack futureMain = rpgItemStackMain.get();
if (inventoryHandler.handleCharacterEquipActionPre(character, managedSlotM, futureMain)) {
managedSlotM.setContent(futureMain);
offHandSlotO.setContent(null);
} else {
event.setCancelled(true);
}
} else {
event.setCancelled(true);

RpgItemStack futureOff = rpgItemStackOff.get();
RpgItemStack futureMain = rpgItemStackMain.get();

if (inventoryHandler.handleCharacterEquipActionPre(character, offHandSlotO, futureOff) &&
inventoryHandler.handleCharacterEquipActionPre(character, managedSlotM, futureMain)
) {
contentM.ifPresent(offHandSlotO::setContent);
contentO.ifPresent(managedSlotM::setContent);
} else {
event.setCancelled(true);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,6 @@ ItemMetaSubtypes: [
#
#
#
# Do not put here any slots from the hotbar, or ContainerPlayer - 40 (which is the id offhand slot). These slots are handled by different bussines logic
# !! Slot ids might shift after mod or sponge update !!
InventorySlots: [
{
Expand Down

0 comments on commit ce69d5a

Please sign in to comment.