-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Made authenticated items unusable in crafts. Fixes DEV-25
- Loading branch information
1 parent
8a3440d
commit a417f44
Showing
4 changed files
with
65 additions
and
5 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
54 changes: 54 additions & 0 deletions
54
src/main/java/net/laboulangerie/laboulangeriecore/authenticate/AuthenticateListener.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,54 @@ | ||
package net.laboulangerie.laboulangeriecore.authenticate; | ||
|
||
import org.bukkit.Material; | ||
import org.bukkit.event.EventHandler; | ||
import org.bukkit.event.EventPriority; | ||
import org.bukkit.event.Listener; | ||
import org.bukkit.event.inventory.InventoryClickEvent; | ||
import org.bukkit.inventory.Inventory; | ||
import org.bukkit.inventory.ItemStack; | ||
|
||
public class AuthenticateListener implements Listener { | ||
|
||
@EventHandler(priority = EventPriority.MONITOR) | ||
private void onInventoryClickWithAuthenticate(InventoryClickEvent event) { | ||
Inventory inventory = event.getInventory(); | ||
|
||
int resultSlot = inventory.getSize() - 1; | ||
switch (inventory.getType()) { | ||
case WORKBENCH: | ||
case CRAFTING: | ||
resultSlot = 0; | ||
break; | ||
case CARTOGRAPHY: | ||
case ENCHANTING: | ||
case ANVIL: | ||
break; | ||
default: | ||
return; | ||
} | ||
|
||
if (!containsAuthenticate(inventory) | ||
|| !isAuthenticated(event.getCurrentItem())) | ||
return; | ||
|
||
inventory.setItem(resultSlot, new ItemStack(Material.AIR)); | ||
} | ||
|
||
private boolean containsAuthenticate(Inventory inventory) { | ||
ItemStack[] items = inventory.getContents(); | ||
boolean containsAuthenticated = false; | ||
|
||
for (int i = 0; i < items.length; i++) { | ||
if (isAuthenticated(items[i])) { | ||
containsAuthenticated = true; | ||
break; | ||
} | ||
} | ||
return containsAuthenticated; | ||
} | ||
|
||
private boolean isAuthenticated(ItemStack item) { | ||
return item != null && new Authenticable(item).isAuthenticated(); | ||
} | ||
} |
5 changes: 4 additions & 1 deletion
5
src/main/java/net/laboulangerie/laboulangeriecore/authenticate/AuthorityType.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