forked from ChestShop-authors/ChestShop-3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add ItemChecker in pre-shop creation process
ItemChecker class has been added for the pre-shop creation process. It validates the ItemStack, and sets the name of the item type as the third line of signLines in PreShopCreationEvent. Unused import in PreShopCreationEvent has been removed.
- Loading branch information
Showing
3 changed files
with
40 additions
and
4 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
34 changes: 34 additions & 0 deletions
34
src/main/java/com/Acrobot/ChestShop/Listeners/PreShopCreation/ItemChecker.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,34 @@ | ||
package com.Acrobot.ChestShop.Listeners.PreShopCreation; | ||
|
||
import static com.Acrobot.ChestShop.Events.PreShopCreationEvent.CreationOutcome.INVALID_ITEM; | ||
|
||
import org.bukkit.event.EventHandler; | ||
import org.bukkit.event.EventPriority; | ||
import org.bukkit.event.Listener; | ||
import org.bukkit.inventory.ItemStack; | ||
|
||
import com.Acrobot.Breeze.Utils.MaterialUtil; | ||
import com.Acrobot.ChestShop.Events.PreShopCreationEvent; | ||
|
||
/** | ||
* @author Acrobot | ||
*/ | ||
public class ItemChecker implements Listener { | ||
|
||
@EventHandler(priority = EventPriority.LOWEST) | ||
public static void onPreShopCreation(PreShopCreationEvent event) { | ||
|
||
ItemStack itemStack = event.getItemStack(); | ||
if (itemStack == null) { | ||
event.setOutcome(INVALID_ITEM); | ||
return; | ||
} | ||
|
||
String itemName = MaterialUtil.getName(itemStack.getType()); | ||
if (itemName == null) { | ||
event.setOutcome(INVALID_ITEM); | ||
return; | ||
} | ||
event.setItemLine(itemName); | ||
} | ||
} |