Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add new inventory functions and virtual inventories.
New functions: popen_inventory(), pinventory_holder(), get_inventory_viewers(), get_virtual_inventories(), create_virtual_inventory(), and delete_virtual_inventory(). New "virtual" prefilter for inventory_click, inventory_drag, inventory_open, and inventory_close events. New inventory "holder" data for inventory_open and inventory_close events.
- Loading branch information
1 parent
9fdb6fe
commit 90ddb51
Showing
17 changed files
with
776 additions
and
304 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package com.laytonsmith.abstraction; | ||
|
||
public interface MCDoubleChest extends MCInventoryHolder { | ||
MCLocation getLocation(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
src/main/java/com/laytonsmith/abstraction/MCVirtualInventoryHolder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package com.laytonsmith.abstraction; | ||
|
||
public interface MCVirtualInventoryHolder extends MCInventoryHolder { | ||
String getID(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 14 additions & 56 deletions
70
src/main/java/com/laytonsmith/abstraction/bukkit/BukkitMCDoubleChest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,72 +1,30 @@ | ||
package com.laytonsmith.abstraction.bukkit; | ||
|
||
import com.laytonsmith.abstraction.MCItemStack; | ||
import org.bukkit.inventory.Inventory; | ||
import org.bukkit.inventory.ItemStack; | ||
import com.laytonsmith.abstraction.MCDoubleChest; | ||
import com.laytonsmith.abstraction.MCInventory; | ||
import com.laytonsmith.abstraction.MCLocation; | ||
import org.bukkit.block.DoubleChest; | ||
|
||
public class BukkitMCDoubleChest extends BukkitMCInventory { | ||
public class BukkitMCDoubleChest implements MCDoubleChest { | ||
|
||
Inventory left; | ||
Inventory right; | ||
DoubleChest dc; | ||
|
||
public BukkitMCDoubleChest(Inventory left, Inventory right) { | ||
super(left); | ||
public BukkitMCDoubleChest(DoubleChest chest) { | ||
this.dc = chest; | ||
} | ||
|
||
@Override | ||
public int getSize() { | ||
return left.getSize() + right.getSize(); | ||
public MCInventory getInventory() { | ||
return new BukkitMCInventory(this.dc.getInventory()); | ||
} | ||
|
||
@Override | ||
public MCItemStack getItem(int slot) { | ||
ItemStack is; | ||
if(slot < left.getSize()) { | ||
is = left.getItem(slot); | ||
} else { | ||
is = right.getItem(slot - left.getSize()); | ||
} | ||
return new BukkitMCItemStack(is); | ||
public MCLocation getLocation() { | ||
return new BukkitMCLocation(this.dc.getLocation()); | ||
} | ||
|
||
@Override | ||
public void setItem(int slot, MCItemStack stack) { | ||
ItemStack is = (ItemStack) stack.getHandle(); | ||
if(slot < left.getSize()) { | ||
left.setItem(slot, is); | ||
} else { | ||
right.setItem(slot - left.getSize(), is); | ||
} | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return left.toString() + ":" + right.toString(); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object obj) { | ||
if(obj == null) { | ||
return false; | ||
} | ||
if(getClass() != obj.getClass()) { | ||
return false; | ||
} | ||
final BukkitMCDoubleChest other = (BukkitMCDoubleChest) obj; | ||
if(this.left != other.left && (this.left == null || !this.left.equals(other.left))) { | ||
return false; | ||
} | ||
if(this.right != other.right && (this.right == null || !this.right.equals(other.right))) { | ||
return false; | ||
} | ||
return true; | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
int hash = 7; | ||
hash = 59 * hash + (this.left != null ? this.left.hashCode() : 0); | ||
hash = 59 * hash + (this.right != null ? this.right.hashCode() : 0); | ||
return hash; | ||
public Object getHandle() { | ||
return this.dc; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
src/main/java/com/laytonsmith/abstraction/bukkit/BukkitMCVirtualInventoryHolder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package com.laytonsmith.abstraction.bukkit; | ||
|
||
import com.laytonsmith.abstraction.MCInventory; | ||
import com.laytonsmith.abstraction.MCVirtualInventoryHolder; | ||
import com.laytonsmith.core.functions.InventoryManagement; | ||
import org.bukkit.inventory.Inventory; | ||
import org.bukkit.inventory.InventoryHolder; | ||
|
||
public class BukkitMCVirtualInventoryHolder implements MCVirtualInventoryHolder { | ||
|
||
private VirtualHolder vholder; | ||
|
||
public BukkitMCVirtualInventoryHolder(String id) { | ||
this.vholder = new VirtualHolder(id); | ||
} | ||
|
||
public BukkitMCVirtualInventoryHolder(InventoryHolder ih) { | ||
this.vholder = (VirtualHolder) ih; | ||
} | ||
|
||
@Override | ||
public MCInventory getInventory() { | ||
return new BukkitMCInventory(vholder.getInventory()); | ||
} | ||
|
||
@Override | ||
public String getID() { | ||
return vholder.id; | ||
} | ||
|
||
@Override | ||
public Object getHandle() { | ||
return this.vholder; | ||
} | ||
|
||
public class VirtualHolder implements InventoryHolder { | ||
private String id; | ||
|
||
VirtualHolder(String id) { | ||
this.id = id; | ||
} | ||
|
||
@Override | ||
public Inventory getInventory() { | ||
return (Inventory) InventoryManagement.VIRTUAL_INVENTORIES.get(this.id).getHandle(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 2 additions & 3 deletions
5
src/main/java/com/laytonsmith/abstraction/entities/MCVillager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,10 @@ | ||
package com.laytonsmith.abstraction.entities; | ||
|
||
import com.laytonsmith.abstraction.MCAgeable; | ||
import com.laytonsmith.abstraction.MCInventoryHolder; | ||
import com.laytonsmith.abstraction.enums.MCProfession; | ||
|
||
public interface MCVillager extends MCAgeable { | ||
|
||
public interface MCVillager extends MCAgeable, MCInventoryHolder { | ||
MCProfession getProfession(); | ||
|
||
void setProfession(MCProfession profession); | ||
} |
Oops, something went wrong.