mirror of
https://github.com/PikaMug/Quests.git
synced 2025-02-21 23:11:27 +01:00
Unstable, changing quest item inventory clicking
This commit is contained in:
parent
99879b5817
commit
8a2d0e1eed
@ -242,36 +242,138 @@ public class PlayerListener implements Listener {
|
||||
}
|
||||
|
||||
}
|
||||
/*
|
||||
*
|
||||
* CRAFTING (Player)
|
||||
|
||||
0 - Crafted Slot
|
||||
1 - Top-left Craft Slot
|
||||
2 - Top-right Craft Slot
|
||||
3 - Bottom-left Craft Slot
|
||||
4 - Bottom-right Craft Slot
|
||||
|
||||
5 - Head Slot
|
||||
6 - Body Slot
|
||||
7 - Leg Slot
|
||||
8 - Boots Slot
|
||||
|
||||
9-35 - Top-left to Bottom-right inventory slots
|
||||
36-44 - Left to Right hotbar slots
|
||||
|
||||
-999 - Drop Slot
|
||||
|
||||
|
||||
BREWING
|
||||
|
||||
0 - Left Potion Slot
|
||||
1 - Middle Potion Slot
|
||||
2 - Right Potion Slot
|
||||
3- Ingredient Slot
|
||||
|
||||
4-30 - Top-left to Bottom-right inventory slots
|
||||
31-39 - Left to Right hotbar slots
|
||||
|
||||
ENCHANTING
|
||||
|
||||
0 - Enchant Slot
|
||||
|
||||
1-27 - Top-left to Bottom-right inventory slots
|
||||
28-36 - Left to Right hotbar slots
|
||||
|
||||
ENDER CHEST
|
||||
|
||||
0-26 - Top-left to Bottom-right chest slots
|
||||
|
||||
27-53 - Top-left to Bottom-right inventory slots
|
||||
54-62 - Left to Right hotbar slots
|
||||
|
||||
DISPENSER
|
||||
|
||||
0-8 - Top-left to Bottom-right dispenser slots
|
||||
|
||||
9-35 - Top-left to Bottom-right inventory slots
|
||||
36-44 - Left to Right hotbar slots
|
||||
|
||||
FURNACE
|
||||
|
||||
0 - Furnace Slot
|
||||
1 - Fuel Slot
|
||||
2 - Product Slot
|
||||
|
||||
3-29 - Top-left to Bottom-right inventory slots
|
||||
30-38 - Left to Right hotbar slots
|
||||
|
||||
WORKBENCH
|
||||
|
||||
0 - Product Slot
|
||||
1-9 - Top-left to Bottom-right crafting slots
|
||||
|
||||
CHEST
|
||||
|
||||
0-26 - Top-left to Bottom-right chest slots
|
||||
|
||||
27-53 - Top-left to Bottom-right inventory slots
|
||||
54-62 - Left to Right hotbar slots
|
||||
|
||||
CHEST (Double)
|
||||
|
||||
0-53 - Top-left to Bottom-right chest slots
|
||||
|
||||
54-80 - Top-left to Bottom-right inventory slots
|
||||
81-89 - Left to Right hotbar slots
|
||||
*
|
||||
*/
|
||||
@EventHandler
|
||||
public void onInventoryClick(InventoryClickEvent evt) {
|
||||
|
||||
System.out.println("Slot: " + evt.getRawSlot() + "\n");
|
||||
((Player)evt.getWhoClicked()).sendMessage("Slot: " + evt.getRawSlot() + "\n");
|
||||
/*if (evt.getWhoClicked() instanceof Player && evt.getCursor() != null) {
|
||||
if (evt.getWhoClicked() instanceof Player && evt.getCursor() != null && evt.getCurrentItem() == null) {
|
||||
|
||||
Quester quester = plugin.getQuester(evt.getWhoClicked().getName());
|
||||
if (quester.currentQuest != null) {
|
||||
|
||||
if (quester.currentQuest.questItems.containsKey(evt.getCursor().getType())) {
|
||||
|
||||
if (evt.getInventory().getType().equals(InventoryType.CHEST) == true && evt.getRawSlot() > 52) {
|
||||
quester.collectItem(evt.getCursor());
|
||||
//Placing Quest item in empty slot
|
||||
|
||||
String s = Quester.checkPlacement(evt.getInventory(), evt.getRawSlot());
|
||||
if (s == null) {
|
||||
//Placing Quest item in an allowed player inventory slot
|
||||
if(quester.holdingQuestItem)
|
||||
quester.collectItem(evt.getCursor());
|
||||
}else{
|
||||
((Player) evt.getWhoClicked()).sendMessage(ChatColor.YELLOW + s);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (evt.getWhoClicked() instanceof Player && evt.getCurrentItem() != null) {
|
||||
} else if (evt.getWhoClicked() instanceof Player && evt.getCursor() != null && evt.getCurrentItem() != null) {
|
||||
|
||||
Quester quester = plugin.getQuester(evt.getWhoClicked().getName());
|
||||
if (quester.currentQuest != null) {
|
||||
|
||||
if (quester.currentQuest.questItems.containsKey(evt.getCurrentItem().getType())) {
|
||||
if (quester.currentQuest.questItems.containsKey(evt.getCurrentItem().getType()) || quester.currentQuest.questItems.containsKey(evt.getCursor().getType())) {
|
||||
|
||||
//Either the cursor item or the slot item (or both) is a Quest item
|
||||
|
||||
Material cursor = evt.getCursor().getType();
|
||||
Material slot = evt.getCurrentItem().getType();
|
||||
|
||||
if(cursor != slot && quester.currentQuest.questItems.containsKey(cursor)){
|
||||
|
||||
//Cursor is a quest item, item in clicked slot is not
|
||||
|
||||
}else if(cursor != slot && quester.currentQuest.questItems.containsKey(slot)){
|
||||
|
||||
//Item in clicked slot is a quest item, cursor is not
|
||||
|
||||
}else{
|
||||
|
||||
//Both are quest items
|
||||
|
||||
}
|
||||
|
||||
if (evt.getInventory().getType().equals(InventoryType.CHEST) == false || evt.getInventory().getType().equals(InventoryType.CHEST) == true && evt.getRawSlot() > 52) {
|
||||
((Player) evt.getWhoClicked()).sendMessage(ChatColor.YELLOW + "You may not modify Quest items in your inventory.");
|
||||
evt.setCancelled(true);
|
||||
@ -284,7 +386,11 @@ public class PlayerListener implements Listener {
|
||||
|
||||
}
|
||||
|
||||
}*/
|
||||
}else if (evt.getWhoClicked() instanceof Player && evt.getCursor() == null && evt.getCurrentItem() != null){
|
||||
|
||||
//Check for taking Quest items out of inventories (to set quester.HoldingQuestItem)
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -149,13 +149,16 @@ public class Quest {
|
||||
q.completedQuests.add(name);
|
||||
String none = ChatColor.GRAY + "- (None)";
|
||||
player.sendMessage(plugin.parseString(finished, q.currentQuest));
|
||||
if(moneyReward > 0 && Quests.economy != null)
|
||||
if(moneyReward > 0 && Quests.economy != null){
|
||||
Quests.economy.depositPlayer(q.name, moneyReward);
|
||||
none = null;
|
||||
}
|
||||
if(redoDelay > -1)
|
||||
q.completedTimes.put(this.name, System.currentTimeMillis());
|
||||
|
||||
for(ItemStack i : itemRewards){
|
||||
Quests.addItem(player, i);
|
||||
none = null;
|
||||
}
|
||||
|
||||
for(Entry entry : questItems.entrySet()){
|
||||
@ -195,7 +198,8 @@ public class Quest {
|
||||
s = s.replaceAll("<player>", player.getName());
|
||||
|
||||
plugin.getServer().dispatchCommand(plugin.getServer().getConsoleSender(), s);
|
||||
|
||||
none = null;
|
||||
|
||||
}
|
||||
|
||||
for(String s : permissions){
|
||||
@ -208,31 +212,38 @@ public class Quest {
|
||||
for(String s : mcmmoSkills){
|
||||
|
||||
Quests.mcmmo.getPlayerProfile(player.getName()).skillUp(Quests.getMcMMOSkill(s), mcmmoAmounts.get(mcmmoSkills.indexOf(s)));
|
||||
|
||||
none = null;
|
||||
|
||||
}
|
||||
|
||||
if(exp > 0)
|
||||
if(exp > 0){
|
||||
player.giveExp(exp);
|
||||
none = null;
|
||||
}
|
||||
|
||||
if(heroesExp > 0)
|
||||
if(heroesExp > 0){
|
||||
plugin.heroes.getCharacterManager().getHero(player).gainExp(heroesExp, ExperienceType.QUESTING, player.getLocation());
|
||||
|
||||
if(heroesClass != null)
|
||||
none = null;
|
||||
}
|
||||
|
||||
if(heroesClass != null){
|
||||
plugin.heroes.getCharacterManager().getHero(player).changeHeroClass(plugin.heroes.getClassManager().getClass(heroesClass), false);
|
||||
|
||||
if(heroesSecClass != null)
|
||||
none = null;
|
||||
}
|
||||
|
||||
if(heroesSecClass != null){
|
||||
plugin.heroes.getCharacterManager().getHero(player).changeHeroClass(plugin.heroes.getClassManager().getClass(heroesSecClass), true);
|
||||
|
||||
none = null;
|
||||
}
|
||||
player.sendMessage(ChatColor.GOLD + "**QUEST COMPLETE: " + ChatColor.YELLOW + q.currentQuest.name + ChatColor.GOLD + "**");
|
||||
player.sendMessage(ChatColor.GREEN + "Rewards:");
|
||||
|
||||
if(questPoints > 0){
|
||||
player.sendMessage("- " + ChatColor.DARK_GREEN + questPoints + " Quest Points");
|
||||
q.questPoints += questPoints;
|
||||
none = null;
|
||||
}
|
||||
|
||||
q.questPoints += questPoints;
|
||||
|
||||
for(ItemStack i : itemRewards){
|
||||
player.sendMessage("- " + ChatColor.DARK_GREEN + Quester.prettyItemString(i.getTypeId()) + ChatColor.GRAY + " x " + i.getAmount());
|
||||
none = null;
|
||||
|
@ -13,6 +13,8 @@ import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.inventory.InventoryType;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.potion.Potion;
|
||||
import org.bukkit.potion.PotionType;
|
||||
@ -21,6 +23,7 @@ public class Quester {
|
||||
|
||||
String name;
|
||||
boolean editorMode = false;
|
||||
boolean holdingQuestItem = false;
|
||||
Quest currentQuest;
|
||||
String questToTake;
|
||||
Stage currentStage;
|
||||
@ -2596,4 +2599,77 @@ public class Quester {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static String checkPlacement(Inventory inv, int rawSlot){
|
||||
|
||||
if(rawSlot < 0){
|
||||
return "You may not drop Quest items.";
|
||||
}
|
||||
|
||||
InventoryType type = inv.getType();
|
||||
|
||||
if(type.equals(InventoryType.BREWING)){
|
||||
|
||||
if(rawSlot < 4){
|
||||
return "You may not brew using Quest items.";
|
||||
}
|
||||
|
||||
}else if(type.equals(InventoryType.CHEST)){
|
||||
|
||||
if(inv.getContents().length == 27){
|
||||
|
||||
if(rawSlot < 27){
|
||||
return "You may not store Quest items.";
|
||||
}
|
||||
|
||||
}else {
|
||||
|
||||
if(rawSlot < 54){
|
||||
return "You may not store Quest items.";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}else if(type.equals(InventoryType.CRAFTING)){
|
||||
|
||||
if(rawSlot < 5){
|
||||
return "You may not craft using Quest items.";
|
||||
}else if(rawSlot < 9){
|
||||
return "You may not equip Quest items.";
|
||||
}
|
||||
|
||||
}else if(type.equals(InventoryType.DISPENSER)){
|
||||
|
||||
if(rawSlot < 9){
|
||||
return "You may not put Quest items in dispensers.";
|
||||
}
|
||||
|
||||
}else if(type.equals(InventoryType.ENCHANTING)){
|
||||
|
||||
if(rawSlot == 0){
|
||||
return "You may not enchant Quest items.";
|
||||
}
|
||||
|
||||
}else if(type.equals(InventoryType.ENDER_CHEST)){
|
||||
|
||||
if(rawSlot < 27){
|
||||
return "You may not store Quest items.";
|
||||
}
|
||||
|
||||
}else if(type.equals(InventoryType.FURNACE)){
|
||||
|
||||
if(rawSlot < 3){
|
||||
return "You may not smelt using Quest items.";
|
||||
}
|
||||
|
||||
}else if(type.equals(InventoryType.WORKBENCH)){
|
||||
|
||||
if(rawSlot < 10){
|
||||
return "You may not craft using Quest items.";
|
||||
}
|
||||
|
||||
}
|
||||
return null;
|
||||
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user