|
10 | 10 | import com.laytonsmith.abstraction.MCHumanEntity; |
11 | 11 | import com.laytonsmith.abstraction.MCItemStack; |
12 | 12 | import com.laytonsmith.abstraction.MCLocation; |
| 13 | +import com.laytonsmith.abstraction.MCNamespacedKey; |
13 | 14 | import com.laytonsmith.abstraction.MCOfflinePlayer; |
14 | 15 | import com.laytonsmith.abstraction.MCPlayer; |
15 | 16 | import com.laytonsmith.abstraction.MCServer; |
@@ -6703,4 +6704,135 @@ public Boolean runAsync() { |
6703 | 6704 | return false; |
6704 | 6705 | } |
6705 | 6706 | } |
| 6707 | + |
| 6708 | + @api |
| 6709 | + public static class phas_recipe extends AbstractFunction { |
| 6710 | + |
| 6711 | + @Override |
| 6712 | + public String getName() { |
| 6713 | + return "phas_recipe"; |
| 6714 | + } |
| 6715 | + |
| 6716 | + @Override |
| 6717 | + public String docs() { |
| 6718 | + return "boolean {[player], recipeKey} Gets whether a player has a recipe in their recipe book."; |
| 6719 | + } |
| 6720 | + |
| 6721 | + @Override |
| 6722 | + public Integer[] numArgs() { |
| 6723 | + return new Integer[]{1, 2}; |
| 6724 | + } |
| 6725 | + |
| 6726 | + @Override |
| 6727 | + public Mixed exec(Target t, Environment env, Mixed... args) throws ConfigRuntimeException { |
| 6728 | + MCPlayer p; |
| 6729 | + String stringKey; |
| 6730 | + if(args.length == 1) { |
| 6731 | + p = env.getEnv(CommandHelperEnvironment.class).GetPlayer(); |
| 6732 | + Static.AssertPlayerNonNull(p, t); |
| 6733 | + stringKey = args[0].val(); |
| 6734 | + } else { |
| 6735 | + p = Static.GetPlayer(args[0], t); |
| 6736 | + stringKey = args[1].val(); |
| 6737 | + } |
| 6738 | + MCNamespacedKey key = StaticLayer.GetConvertor().GetNamespacedKey(stringKey); |
| 6739 | + if(key == null) { |
| 6740 | + throw new CREFormatException("Invalid namespaced key format: " + stringKey, t); |
| 6741 | + } |
| 6742 | + return CBoolean.get(p.hasDiscoveredRecipe(key)); |
| 6743 | + } |
| 6744 | + |
| 6745 | + @Override |
| 6746 | + public Class<? extends CREThrowable>[] thrown() { |
| 6747 | + return new Class[]{CREPlayerOfflineException.class, CRELengthException.class, CREFormatException.class}; |
| 6748 | + } |
| 6749 | + |
| 6750 | + @Override |
| 6751 | + public Version since() { |
| 6752 | + return MSVersion.V3_3_5; |
| 6753 | + } |
| 6754 | + |
| 6755 | + @Override |
| 6756 | + public boolean isRestricted() { |
| 6757 | + return true; |
| 6758 | + } |
| 6759 | + |
| 6760 | + @Override |
| 6761 | + public Boolean runAsync() { |
| 6762 | + return false; |
| 6763 | + } |
| 6764 | + } |
| 6765 | + |
| 6766 | + @api |
| 6767 | + public static class pgive_recipe extends AbstractFunction { |
| 6768 | + |
| 6769 | + @Override |
| 6770 | + public String getName() { |
| 6771 | + return "pgive_recipe"; |
| 6772 | + } |
| 6773 | + |
| 6774 | + @Override |
| 6775 | + public String docs() { |
| 6776 | + return "int {[player], recipeKey(s)} Adds one or more recipes to a player's recipe book." |
| 6777 | + + " Can take a single recipe key or an array of keys." |
| 6778 | + + " Returns how many recipes were newly discovered."; |
| 6779 | + } |
| 6780 | + |
| 6781 | + @Override |
| 6782 | + public Integer[] numArgs() { |
| 6783 | + return new Integer[]{1, 2}; |
| 6784 | + } |
| 6785 | + |
| 6786 | + @Override |
| 6787 | + public Mixed exec(Target t, Environment env, Mixed... args) throws ConfigRuntimeException { |
| 6788 | + MCPlayer p; |
| 6789 | + Mixed value; |
| 6790 | + if(args.length == 1) { |
| 6791 | + p = env.getEnv(CommandHelperEnvironment.class).GetPlayer(); |
| 6792 | + Static.AssertPlayerNonNull(p, t); |
| 6793 | + value = args[0]; |
| 6794 | + } else { |
| 6795 | + p = Static.GetPlayer(args[0], t); |
| 6796 | + value = args[1]; |
| 6797 | + } |
| 6798 | + if(value.isInstanceOf(CArray.TYPE)) { |
| 6799 | + int result = 0; |
| 6800 | + for(Mixed element : ((CArray) value).asList()) { |
| 6801 | + MCNamespacedKey key = StaticLayer.GetConvertor().GetNamespacedKey(element.val()); |
| 6802 | + if(key == null) { |
| 6803 | + throw new CREFormatException("Invalid namespaced key format: " + element.val(), t); |
| 6804 | + } |
| 6805 | + boolean success = p.discoverRecipe(key); |
| 6806 | + result += success ? 1 : 0; |
| 6807 | + } |
| 6808 | + return new CInt(result, t); |
| 6809 | + } |
| 6810 | + MCNamespacedKey key = StaticLayer.GetConvertor().GetNamespacedKey(value.val()); |
| 6811 | + if(key == null) { |
| 6812 | + throw new CREFormatException("Invalid namespaced key format: " + value.val(), t); |
| 6813 | + } |
| 6814 | + boolean success = p.discoverRecipe(key); |
| 6815 | + return new CInt(success ? 1 : 0, t); |
| 6816 | + } |
| 6817 | + |
| 6818 | + @Override |
| 6819 | + public Class<? extends CREThrowable>[] thrown() { |
| 6820 | + return new Class[]{CREPlayerOfflineException.class, CRELengthException.class, CREFormatException.class}; |
| 6821 | + } |
| 6822 | + |
| 6823 | + @Override |
| 6824 | + public Version since() { |
| 6825 | + return MSVersion.V3_3_5; |
| 6826 | + } |
| 6827 | + |
| 6828 | + @Override |
| 6829 | + public boolean isRestricted() { |
| 6830 | + return true; |
| 6831 | + } |
| 6832 | + |
| 6833 | + @Override |
| 6834 | + public Boolean runAsync() { |
| 6835 | + return false; |
| 6836 | + } |
| 6837 | + } |
6706 | 6838 | } |
0 commit comments