Skip to content

Commit c3cbcb3

Browse files
committed
Add PositionInputHandler
1 parent 794d4c3 commit c3cbcb3

File tree

2 files changed

+56
-0
lines changed

2 files changed

+56
-0
lines changed

debuggery-bukkit/src/main/java/io/zachbr/debuggery/reflection/types/handlers/bukkit/BukkitBootstrap.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ public BukkitBootstrap(TypeHandler typeHandler, Logger logger) {
5151
bukkitHandlers.add(new InventoryInputHandler());
5252
bukkitHandlers.add(new ItemStackInputHandler());
5353
bukkitHandlers.add(new LocationInputHandler());
54+
bukkitHandlers.add(new PositionInputHandler());
5455
bukkitHandlers.add(new MaterialInputHandler());
5556
bukkitHandlers.add(new NamespacedKeyInputHandler());
5657
bukkitHandlers.add(new PermissionInputHandler());
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*
2+
* This file is part of Debuggery.
3+
*
4+
* Debuggery is free software: you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License as published by
6+
* the Free Software Foundation, either version 3 of the License, or
7+
* (at your option) any later version.
8+
*
9+
* Debuggery is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with Debuggery. If not, see <http://www.gnu.org/licenses/>.
16+
*/
17+
18+
package io.zachbr.debuggery.reflection.types.handlers.bukkit.input;
19+
20+
import io.papermc.paper.math.Position;
21+
import io.zachbr.debuggery.reflection.types.handlers.base.InputHandler;
22+
import io.zachbr.debuggery.reflection.types.handlers.base.platform.PlatformSender;
23+
import org.bukkit.Bukkit;
24+
import org.bukkit.Location;
25+
import org.bukkit.World;
26+
import org.bukkit.entity.Player;
27+
import org.jetbrains.annotations.NotNull;
28+
import org.jetbrains.annotations.Nullable;
29+
30+
public class PositionInputHandler implements InputHandler<Position> {
31+
32+
static @NotNull Position getLocation(String input, @Nullable PlatformSender<?> sender) {
33+
if (sender != null && sender.getRawSender() instanceof final Player player) {
34+
if (input.equalsIgnoreCase("here")) {
35+
return player.getLocation();
36+
} else if (input.equalsIgnoreCase("there")) {
37+
return player.getTargetBlock(null, 50).getLocation();
38+
}
39+
}
40+
41+
String[] contents = input.split(",", 3);
42+
43+
return Position.block(Integer.parseInt(contents[0]), Integer.parseInt(contents[1]), Integer.parseInt(contents[2]));
44+
}
45+
46+
@Override
47+
public @NotNull Position instantiateInstance(String input, Class<? extends Position> clazz, @Nullable PlatformSender<?> sender) {
48+
return getLocation(input, sender); // separate method so that related commands can get to it
49+
}
50+
51+
@Override
52+
public @NotNull Class<Position> getRelevantClass() {
53+
return Position.class;
54+
}
55+
}

0 commit comments

Comments
 (0)