PlayerSelectionWrapper kit choices are now set.

This commit is contained in:
officereso 2020-06-10 04:17:48 -05:00
parent 89042af922
commit 8597361e79
2 changed files with 108 additions and 19 deletions

View File

@ -6,6 +6,7 @@ import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class PlayerSelectionWrapper {
public final Player player;
@ -14,8 +15,8 @@ public class PlayerSelectionWrapper {
public Kit selectedChestplate;
public Kit selectedLeggings;
public Kit selectedBoots;
public HashMap<Kit, Integer> selectedPotions;
public HashMap<Kit, Integer> selectedAdditions;
public HashMap<Kit, Integer> selectedPotions = new HashMap<>();
public HashMap<Kit, Integer> selectedAdditions = new HashMap<>();
public PlayerSelectionWrapper(Player player, Kit kit) {
this.player = player;
@ -49,10 +50,33 @@ public class PlayerSelectionWrapper {
public HashMap<Integer, Integer> getGreenSlots() {
HashMap<Integer, Integer> slots = new HashMap<>();
if (selectedKit != null) {
slots.put(selectedKit.getViewPosition(), selectedKit.getViewPosition());
slots.put(selectedKit.getViewPosition(), 1);
}
if (selectedHelmet != null) {
slots.put(selectedHelmet.getViewPosition(), selectedHelmet.getViewPosition());
slots.put(selectedHelmet.getViewPosition(), 1);
}
if (selectedChestplate != null) {
slots.put(selectedChestplate.getViewPosition(), 1);
}
if (selectedLeggings != null) {
slots.put(selectedLeggings.getViewPosition(), 1);
}
if (selectedBoots != null) {
slots.put(selectedBoots.getViewPosition(), 1);
}
if (selectedPotions != null) {
for (Map.Entry<Kit, Integer> entryKit : selectedPotions.entrySet()) {
if (entryKit.getValue() == null)
continue;
slots.put(entryKit.getKey().getViewPosition(), entryKit.getValue());
}
}
if (selectedAdditions != null) {
for (Map.Entry<Kit, Integer> entryKit : selectedAdditions.entrySet()) {
if (entryKit.getValue() == null)
continue;
slots.put(entryKit.getKey().getViewPosition(), entryKit.getValue());
}
}
return slots;
@ -63,6 +87,11 @@ public class PlayerSelectionWrapper {
}
public void addAdditions(Kit kit, int amount) {
selectedAdditions.putIfAbsent(kit, 0);
if (selectedAdditions.get(kit) + amount <= 0) {
selectedAdditions.put(kit, null);
return;
}
selectedAdditions.put(kit, selectedAdditions.get(kit) + amount);
}
@ -83,6 +112,11 @@ public class PlayerSelectionWrapper {
}
public void addPotions(Kit kit, int amount) {
selectedPotions.putIfAbsent(kit, 0);
if (selectedPotions.get(kit) + amount <= 0) {
selectedPotions.put(kit, null);
return;
}
selectedPotions.put(kit, selectedPotions.get(kit) + amount);
}

View File

@ -10,6 +10,7 @@ import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.inventory.ClickType;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
@ -80,26 +81,80 @@ public class pvp extends JavaPlugin implements Listener {
public void slotFunction(Slot slot, Kit kit, PlayerSelectionWrapper selectionWrapper, Menu menu) {
slot.setClickHandler((player, info) -> {
if (kit.getType() == Kit.Type.KIT) {
if (selectionWrapper.getSelectedKit() != kit) {
for (Map.Entry<Integer, Kit> entryKit : kits.entrySet()) {
Kit updateKit = entryKit.getValue();
int slotPos = entryKit.getKey();
Slot updateSlot = menu.getSlot(slotPos);
selectionWrapper.setSelectedKit(kit);
if (selectionWrapper.getGreenSlots().get(slotPos) != null) {
updateSlot.setItem(new ItemStack(Material.GREEN_WOOL));
} else {
updateSlot.setItem(updateKit.getInventoryItemList().get(0).getItemStack());
}
}
Kit.Type type = kit.getType();
if (type == Kit.Type.KIT) {
if (info.getClickType() == ClickType.LEFT) {
selectionWrapper.setSelectedKit(kit);
updateMenu(selectionWrapper, menu);
} else if (info.getClickType() == ClickType.RIGHT) {
selectionWrapper.setSelectedKit(null);
updateMenu(selectionWrapper, menu);
}
} else if (type == Kit.Type.HELMET) {
if (info.getClickType() == ClickType.LEFT) {
selectionWrapper.setSelectedHelmet(kit);
updateMenu(selectionWrapper, menu);
} else if (info.getClickType() == ClickType.RIGHT) {
selectionWrapper.setSelectedHelmet(null);
updateMenu(selectionWrapper, menu);
}
} else if (type == Kit.Type.CHESTPLATE) {
if (info.getClickType() == ClickType.LEFT) {
selectionWrapper.setSelectedChestplate(kit);
updateMenu(selectionWrapper, menu);
} else if (info.getClickType() == ClickType.RIGHT) {
selectionWrapper.setSelectedChestplate(null);
updateMenu(selectionWrapper, menu);
}
} else if (type == Kit.Type.LEGGINGS) {
if (info.getClickType() == ClickType.LEFT) {
selectionWrapper.setSelectedLeggings(kit);
updateMenu(selectionWrapper, menu);
} else if (info.getClickType() == ClickType.RIGHT) {
selectionWrapper.setSelectedLeggings(null);
updateMenu(selectionWrapper, menu);
}
} else if (type == Kit.Type.BOOTS) {
if (info.getClickType() == ClickType.LEFT) {
selectionWrapper.setSelectedBoots(kit);
updateMenu(selectionWrapper, menu);
} else if (info.getClickType() == ClickType.RIGHT) {
selectionWrapper.setSelectedBoots(null);
updateMenu(selectionWrapper, menu);
}
} else if (type == Kit.Type.POTION) {
if (info.getClickType() == ClickType.LEFT) {
selectionWrapper.addPotions(kit, 1);
updateMenu(selectionWrapper, menu);
} else if (info.getClickType() == ClickType.RIGHT) {
selectionWrapper.addPotions(kit, -1);
updateMenu(selectionWrapper, menu);
}
} else if (type == Kit.Type.ADDITIONAL) {
if (info.getClickType() == ClickType.LEFT) {
selectionWrapper.addAdditions(kit, 1);
updateMenu(selectionWrapper, menu);
} else if (info.getClickType() == ClickType.RIGHT) {
selectionWrapper.addAdditions(kit, -1);
updateMenu(selectionWrapper, menu);
}
}
if (kit.getType() == Kit.Type.HELMET)
System.out.println("ldkfsjld");
});
}
private void updateMenu(PlayerSelectionWrapper selectionWrapper, Menu menu) {
for (Map.Entry<Integer, Kit> entryKit : kits.entrySet()) {
Kit updateKit = entryKit.getValue();
int slotPos = entryKit.getKey();
Slot updateSlot = menu.getSlot(slotPos);
if (selectionWrapper.getGreenSlots().get(slotPos) != null) {
updateSlot.setItem(new ItemStack(Material.GREEN_WOOL, selectionWrapper.getGreenSlots().get(slotPos)));
} else {
updateSlot.setItem(updateKit.getInventoryItemList().get(0).getItemStack());
}
}
}
public void load() {
World world = Bukkit.getWorld("world");
String[] signPos = config.getString("sign_pos").split(" ");