-
-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extra thanks to @booky10 for their help with cracking this one!
- Loading branch information
Showing
19 changed files
with
339 additions
and
26 deletions.
There are no files selected for viewing
37 changes: 37 additions & 0 deletions
37
...-annotations/src/main/java/dev/jorel/commandapi/annotations/arguments/AWorldArgument.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 @@ | ||
/******************************************************************************* | ||
* Copyright 2022 Jorel Ali (Skepter) - MIT License | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy of | ||
* this software and associated documentation files (the "Software"), to deal in | ||
* the Software without restriction, including without limitation the rights to | ||
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of | ||
* the Software, and to permit persons to whom the Software is furnished to do so, | ||
* subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in all | ||
* copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS | ||
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR | ||
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER | ||
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | ||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
*******************************************************************************/ | ||
package dev.jorel.commandapi.annotations.arguments; | ||
|
||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
|
||
import dev.jorel.commandapi.arguments.WorldArgument; | ||
|
||
/** | ||
* Annotation equivalent of the {@link WorldArgument} | ||
*/ | ||
@Primitive("org.bukkit.World") | ||
@Retention(RetentionPolicy.SOURCE) | ||
@Target(ElementType.PARAMETER) | ||
public @interface AWorldArgument { | ||
} |
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
66 changes: 66 additions & 0 deletions
66
commandapi-core/src/main/java/dev/jorel/commandapi/arguments/WorldArgument.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,66 @@ | ||
/******************************************************************************* | ||
* Copyright 2022 Jorel Ali (Skepter) - MIT License | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy of | ||
* this software and associated documentation files (the "Software"), to deal in | ||
* the Software without restriction, including without limitation the rights to | ||
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of | ||
* the Software, and to permit persons to whom the Software is furnished to do so, | ||
* subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in all | ||
* copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS | ||
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR | ||
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER | ||
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | ||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
*******************************************************************************/ | ||
package dev.jorel.commandapi.arguments; | ||
|
||
import java.util.function.Function; | ||
|
||
import org.bukkit.World; | ||
|
||
import com.mojang.brigadier.context.CommandContext; | ||
import com.mojang.brigadier.exceptions.CommandSyntaxException; | ||
|
||
import dev.jorel.commandapi.CommandAPIHandler; | ||
import dev.jorel.commandapi.nms.NMS; | ||
|
||
/** | ||
* An argument that represents the Bukkit World object | ||
*/ | ||
public class WorldArgument extends SafeOverrideableArgument<World, World> { | ||
|
||
/** | ||
* A World argument. Represents Bukkit's World object | ||
* | ||
* @param nodeName the name of the node for this argument | ||
*/ | ||
public WorldArgument(String nodeName) { | ||
super(nodeName, CommandAPIHandler.getInstance().getNMS()._ArgumentDimension(), ((Function<World, String>) World::getName).andThen(String::toLowerCase)); | ||
} | ||
|
||
@Override | ||
public Class<World> getPrimitiveType() { | ||
return World.class; | ||
} | ||
|
||
@Override | ||
public CommandAPIArgumentType getArgumentType() { | ||
// We're keeping this underlying internal name as Dimension. The only thing | ||
// that differs is the name of this class which is "WorldArgument", because | ||
// the CommandAPI argument class names represent Bukkit objects wherever | ||
// possible | ||
return CommandAPIArgumentType.DIMENSION; | ||
} | ||
|
||
@Override | ||
public <CommandListenerWrapper> World parseArgument(NMS<CommandListenerWrapper> nms, | ||
CommandContext<CommandListenerWrapper> cmdCtx, String key, Object[] previousArgs) throws CommandSyntaxException { | ||
return nms.getDimension(cmdCtx, key); | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
...pi-core/src/main/java/dev/jorel/commandapi/exceptions/UnimplementedArgumentException.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,35 @@ | ||
/******************************************************************************* | ||
* Copyright 2022 Jorel Ali (Skepter) - MIT License | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy of | ||
* this software and associated documentation files (the "Software"), to deal in | ||
* the Software without restriction, including without limitation the rights to | ||
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of | ||
* the Software, and to permit persons to whom the Software is furnished to do so, | ||
* subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in all | ||
* copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS | ||
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR | ||
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER | ||
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | ||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
*******************************************************************************/ | ||
package dev.jorel.commandapi.exceptions; | ||
|
||
/** | ||
* An exception caused when using an argument which hasn't been implemented in this Minecraft version | ||
*/ | ||
public class UnimplementedArgumentException extends RuntimeException { | ||
|
||
/** | ||
* Creates an EnvironmentArgumentException | ||
*/ | ||
public UnimplementedArgumentException(String type, String versionSupportedIn) { | ||
super("The " + type + " is only compatible with Minecraft " + versionSupportedIn + " or later"); | ||
} | ||
|
||
} |
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
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
Oops, something went wrong.