-
-
Notifications
You must be signed in to change notification settings - Fork 368
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Tool Components #7200
Open
TheAbsolutionism
wants to merge
7
commits into
SkriptLang:dev/feature
Choose a base branch
from
TheAbsolutionism:dev/ToolComponents
base: dev/feature
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Tool Components #7200
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
da23e33
Starter Commit
TheAbsolutionism 3441021
Merge branch 'dev/feature' into dev/ToolComponents
sovdeeth 97ce295
Partial Changes
TheAbsolutionism ecc728e
Merge branch 'dev/ToolComponents' of https://github.com/TheAbsolution…
TheAbsolutionism 74cac7e
Merge branch 'dev/feature' into dev/ToolComponents
TheAbsolutionism e49a8a2
Update
TheAbsolutionism ab6209c
Merge branch 'dev/feature' into dev/ToolComponents
TheAbsolutionism File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
37 changes: 37 additions & 0 deletions
37
src/main/java/org/skriptlang/skript/bukkit/toolcomponent/ToolComponentModule.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,37 @@ | ||
package org.skriptlang.skript.bukkit.toolcomponent; | ||
|
||
import ch.njol.skript.Skript; | ||
import ch.njol.skript.classes.ClassInfo; | ||
import ch.njol.skript.registrations.Classes; | ||
import org.bukkit.inventory.meta.components.ToolComponent; | ||
import org.bukkit.inventory.meta.components.ToolComponent.ToolRule; | ||
|
||
import java.io.IOException; | ||
|
||
public class ToolComponentModule { | ||
|
||
public static void load() throws IOException { | ||
if (!Skript.classExists("org.bukkit.inventory.meta.components.ToolComponent")) | ||
return; | ||
|
||
Skript.getAddonInstance().loadClasses("org.skriptlang.skript.bukkit.toolcomponent", "elements"); | ||
|
||
Classes.registerClass(new ClassInfo<>(ToolComponent.class, "toolcomponent") | ||
.user("tool ?components?") | ||
.name("Tool Component") | ||
.description("The tool component of an item") | ||
.requiredPlugins("Minecraft 1.20.6+") | ||
.since("INSERT VERSION") | ||
); | ||
|
||
Classes.registerClass(new ClassInfo<>(ToolRule.class, "toolrule") | ||
.user("tool ?rules?") | ||
.name("Tool Rule") | ||
.description("The tool rule of a tool component") | ||
.requiredPlugins("Minecraft 1.20.6+") | ||
.since("INSERT VERSION") | ||
); | ||
|
||
} | ||
|
||
} |
59 changes: 59 additions & 0 deletions
59
src/main/java/org/skriptlang/skript/bukkit/toolcomponent/elements/CondToolRuleDrops.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,59 @@ | ||
package org.skriptlang.skript.bukkit.toolcomponent.elements; | ||
|
||
import ch.njol.skript.Skript; | ||
import ch.njol.skript.conditions.base.PropertyCondition; | ||
import ch.njol.skript.doc.*; | ||
import ch.njol.skript.lang.Expression; | ||
import ch.njol.skript.lang.SkriptParser.ParseResult; | ||
import ch.njol.util.Kleenean; | ||
import org.bukkit.event.Event; | ||
import org.bukkit.inventory.meta.components.ToolComponent.ToolRule; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
@Name("Tool Rule - Drops Enabled") | ||
@Description("If the drops of a tool rule are enabled.") | ||
@Examples({ | ||
"set {_rules::*} to the tool rules of {_item}", | ||
"loop {_rules::*}:", | ||
"\tif the tool rule drops of loop-value is enabled:", | ||
"\tremove loop-value from the tool rules of {_item}" | ||
}) | ||
@RequiredPlugins("Minecraft 1.20.6") | ||
@Since("INSERT VERSION") | ||
public class CondToolRuleDrops extends PropertyCondition<ToolRule> { | ||
|
||
static { | ||
Skript.registerCondition(CondToolRuleDrops.class, ConditionType.PROPERTY, | ||
"[the] tool rule drops of %toolrules% (is|are) enabled", | ||
"[the] tool rule drops of %toolrules% (is|are) disabled" | ||
); | ||
} | ||
|
||
private boolean enable; | ||
private Expression<ToolRule> toolRules; | ||
|
||
@Override | ||
public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) { | ||
enable = matchedPattern == 0; | ||
//noinspection unchecked | ||
toolRules = (Expression<ToolRule>) exprs[0]; | ||
setExpr(toolRules); | ||
return true; | ||
} | ||
|
||
@Override | ||
public boolean check(ToolRule toolRule) { | ||
return toolRule.isCorrectForDrops() == enable; | ||
} | ||
|
||
@Override | ||
protected String getPropertyName() { | ||
return "tool rule drops"; | ||
} | ||
|
||
@Override | ||
public String toString(@Nullable Event event, boolean debug) { | ||
return "the tool rule drops of " + toolRules.toString(event, debug) + " are " + (enable ? "enabled" : "disabled"); | ||
} | ||
|
||
} |
54 changes: 54 additions & 0 deletions
54
src/main/java/org/skriptlang/skript/bukkit/toolcomponent/elements/EffToolRuleDrops.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 org.skriptlang.skript.bukkit.toolcomponent.elements; | ||
|
||
import ch.njol.skript.Skript; | ||
import ch.njol.skript.doc.*; | ||
import ch.njol.skript.lang.Effect; | ||
import ch.njol.skript.lang.Expression; | ||
import ch.njol.skript.lang.SkriptParser.ParseResult; | ||
import ch.njol.util.Kleenean; | ||
import org.bukkit.event.Event; | ||
import org.bukkit.inventory.meta.components.ToolComponent.ToolRule; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
@Name("Tool Rule - Drops") | ||
@Description("If the tool with this tool rule should drop items of a block defined from the blocks of this tool rule.") | ||
@Examples({ | ||
"set {_rule} to a new tool rule with block types oak log, stone and obsidian", | ||
"set the tool rule speed of {_rule} to 10", | ||
"enable the tool rule drops of {_rule}", | ||
"add {_rule} to the tool rules of {_item}" | ||
}) | ||
@RequiredPlugins("Minecraft 1.20.6+") | ||
@Since("INSERT VERSION") | ||
public class EffToolRuleDrops extends Effect { | ||
|
||
static { | ||
Skript.registerEffect(EffToolRuleDrops.class, | ||
"enable [the] tool rule drops (of|for) %toolrules%", | ||
"disable [the] tool rule drops (of|for) %toolrules%"); | ||
} | ||
|
||
private boolean enable; | ||
private Expression<? extends ToolRule> exprToolRule; | ||
|
||
@Override | ||
public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) { | ||
//noinspection unchecked | ||
exprToolRule = (Expression<? extends ToolRule>) exprs[0]; | ||
enable = matchedPattern == 0; | ||
return true; | ||
} | ||
|
||
@Override | ||
protected void execute(Event event) { | ||
for (ToolRule rule : exprToolRule.getArray(event)) { | ||
rule.setCorrectForDrops(enable); | ||
} | ||
} | ||
|
||
@Override | ||
public String toString(@Nullable Event event, boolean debug) { | ||
return (enable ? "enable" : "disable") + " tool rule drops for " + exprToolRule.toString(event, debug); | ||
} | ||
|
||
} |
56 changes: 56 additions & 0 deletions
56
src/main/java/org/skriptlang/skript/bukkit/toolcomponent/elements/ExprNewToolComp.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,56 @@ | ||
package org.skriptlang.skript.bukkit.toolcomponent.elements; | ||
|
||
import ch.njol.skript.Skript; | ||
import ch.njol.skript.doc.*; | ||
import ch.njol.skript.lang.Expression; | ||
import ch.njol.skript.lang.ExpressionType; | ||
import ch.njol.skript.lang.SkriptParser.ParseResult; | ||
import ch.njol.skript.lang.util.SimpleExpression; | ||
import ch.njol.util.Kleenean; | ||
import org.bukkit.Material; | ||
import org.bukkit.event.Event; | ||
import org.bukkit.inventory.ItemStack; | ||
import org.bukkit.inventory.meta.components.ToolComponent; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
@Name("New Tool Component") | ||
@Description("Gets a blank tool component.") | ||
@Examples({ | ||
"set {_component} to a new blank tool component", | ||
"set the tool component of {_item} to {_component}" | ||
}) | ||
@RequiredPlugins("Minecraft 1.20.6+") | ||
@Since("INSERT VERSION") | ||
public class ExprNewToolComp extends SimpleExpression<ToolComponent> { | ||
|
||
static { | ||
Skript.registerExpression(ExprNewToolComp.class, ToolComponent.class, ExpressionType.SIMPLE, | ||
TheAbsolutionism marked this conversation as resolved.
Show resolved
Hide resolved
|
||
"a new [blank|empty] tool component"); | ||
} | ||
|
||
@Override | ||
public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) { | ||
return true; | ||
} | ||
|
||
@Override | ||
protected ToolComponent @Nullable [] get(Event event) { | ||
return new ToolComponent[]{(new ItemStack(Material.APPLE)).getItemMeta().getTool()}; | ||
} | ||
|
||
@Override | ||
public boolean isSingle() { | ||
return true; | ||
} | ||
|
||
@Override | ||
public Class<ToolComponent> getReturnType() { | ||
return ToolComponent.class; | ||
} | ||
|
||
@Override | ||
public String toString(@Nullable Event event, boolean debug) { | ||
return "a new tool component"; | ||
} | ||
|
||
} |
69 changes: 69 additions & 0 deletions
69
src/main/java/org/skriptlang/skript/bukkit/toolcomponent/elements/ExprNewToolRule.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,69 @@ | ||
package org.skriptlang.skript.bukkit.toolcomponent.elements; | ||
|
||
import ch.njol.skript.Skript; | ||
import ch.njol.skript.aliases.ItemType; | ||
import ch.njol.skript.doc.*; | ||
import ch.njol.skript.lang.Expression; | ||
import ch.njol.skript.lang.ExpressionType; | ||
import ch.njol.skript.lang.SkriptParser.ParseResult; | ||
import ch.njol.skript.lang.util.SimpleExpression; | ||
import ch.njol.util.Kleenean; | ||
import org.bukkit.Material; | ||
import org.bukkit.event.Event; | ||
import org.bukkit.inventory.ItemStack; | ||
import org.bukkit.inventory.meta.components.ToolComponent.ToolRule; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
import java.util.List; | ||
|
||
@Name("New Tool Rule") | ||
@Description({ | ||
"Gets a new tool rule with provided block types.", | ||
"NOTE: A tool rule must have at least one block type or will be considered invalid." | ||
}) | ||
@Examples({ | ||
"set {_rule} to a new tool rule with block types oak log, stone and obsidian", | ||
"set the tool rule speed of {_rule} to 10", | ||
"enable the tool rule drops of {_rule}", | ||
"add {_rule} to the tool rules of {_item}" | ||
}) | ||
@RequiredPlugins("Minecraft 1.20.6+") | ||
@Since("INSERT VERSION") | ||
public class ExprNewToolRule extends SimpleExpression<ToolRule> { | ||
|
||
static { | ||
Skript.registerExpression(ExprNewToolRule.class, ToolRule.class, ExpressionType.SIMPLE, | ||
"a new tool rule with block types %itemtypes%"); | ||
} | ||
|
||
private Expression<ItemType> types; | ||
|
||
@Override | ||
public boolean init(Expression<?>[] expressions, int matchedPattern, Kleenean isDelayed, ParseResult parseResult) { | ||
//noinspection unchecked | ||
types = (Expression<ItemType>) expressions[0]; | ||
return true; | ||
} | ||
|
||
@Override | ||
protected ToolRule @Nullable [] get(Event event) { | ||
List<Material> materials = types.stream(event).map(ItemType::getMaterial).toList(); | ||
return new ToolRule[]{(new ItemStack(Material.APPLE).getItemMeta().getTool().addRule(materials, null, null))}; | ||
} | ||
|
||
@Override | ||
public boolean isSingle() { | ||
return true; | ||
} | ||
|
||
@Override | ||
public Class<? extends ToolRule> getReturnType() { | ||
return ToolRule.class; | ||
} | ||
|
||
@Override | ||
public String toString(@Nullable Event event, boolean debug) { | ||
return null; | ||
} | ||
|
||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any chance we can possibly get one that reflects the behavior more?