Skip to content

Commit

Permalink
Uncuck input/output handlers
Browse files Browse the repository at this point in the history
  • Loading branch information
kennytv committed Jan 23, 2022
1 parent bca7765 commit e2eef21
Show file tree
Hide file tree
Showing 56 changed files with 406 additions and 398 deletions.
4 changes: 2 additions & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ plugins {
allprojects {
apply(plugin = "java")
group = "io.papermc.debuggery"
version = "1.3.0"
version = "1.4.0-SNAPSHOT"

java {
toolchain.languageVersion.set(JavaLanguageVersion.of(17))
toolchain.languageVersion.set(JavaLanguageVersion.of(11))
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import io.zachbr.debuggery.Logger;
import io.zachbr.debuggery.reflection.types.TypeHandler;
import io.zachbr.debuggery.reflection.types.handlers.base.Handler;
import io.zachbr.debuggery.reflection.types.handlers.base.IHandler;
import io.zachbr.debuggery.reflection.types.handlers.base.InputHandler;
import io.zachbr.debuggery.reflection.types.handlers.base.platform.PlatformExtension;
import io.zachbr.debuggery.reflection.types.handlers.base.platform.PlatformSpecific;
import io.zachbr.debuggery.reflection.types.handlers.bukkit.input.*;
Expand All @@ -43,40 +43,40 @@ public BukkitBootstrap(TypeHandler typeHandler, Logger logger) {
//

// order can matter here
bukkitHandlers.add(new IBukkitClassHandler());
bukkitHandlers.add(new IDifficultyHandler());
bukkitHandlers.add(new IEntityHandler());
bukkitHandlers.add(new IEulerAngleHandler());
bukkitHandlers.add(new IGameModeHandler());
bukkitHandlers.add(new IInventoryHandler());
bukkitHandlers.add(new IItemStackHandler());
bukkitHandlers.add(new ILocationHandler());
bukkitHandlers.add(new IMaterialDataHandler());
bukkitHandlers.add(new IMaterialHandler());
bukkitHandlers.add(new INamespacedKeyHandler());
bukkitHandlers.add(new IPermissionHandler());
bukkitHandlers.add(new IPlayerHandler());
bukkitHandlers.add(new IPotionEffectHandler());
bukkitHandlers.add(new IPotionEffectTypeHandler());
bukkitHandlers.add(new IVectorHandler());
bukkitHandlers.add(new BukkitClassInputHandler());
bukkitHandlers.add(new DifficultyInputHandler());
bukkitHandlers.add(new EntityInputHandler());
bukkitHandlers.add(new EulerAngleInputHandler());
bukkitHandlers.add(new GameModeInputHandler());
bukkitHandlers.add(new InventoryInputHandler());
bukkitHandlers.add(new ItemStackInputHandler());
bukkitHandlers.add(new LocationInputHandler());
bukkitHandlers.add(new MaterialDataInputHandler());
bukkitHandlers.add(new MaterialInputHandler());
bukkitHandlers.add(new NamespacedKeyInputHandler());
bukkitHandlers.add(new PermissionInputHandler());
bukkitHandlers.add(new PlayerInputHandler());
bukkitHandlers.add(new PotionEffectInputHandler());
bukkitHandlers.add(new PotionEffectTypeInputHandler());
bukkitHandlers.add(new VectorInputHandler());
// register polymorphics last
bukkitHandlers.add(new IBlockDataHandler());
bukkitHandlers.add(new BlockDataInputHandler());

//
// Output Handlers
//

// order can matter here
bukkitHandlers.add(new OBlockStateHandler());
bukkitHandlers.add(new OEntityHandler()); // above CommandSender
bukkitHandlers.add(new OCommandSender());
bukkitHandlers.add(new OEulerAngleHandler());
bukkitHandlers.add(new OHelpMapHandler());
bukkitHandlers.add(new OInventoryHandler(this.typeHandler));
bukkitHandlers.add(new OMessengerHandler(this.typeHandler));
bukkitHandlers.add(new OOfflinePlayerHandler());
bukkitHandlers.add(new OPermissionAttachmentInfoHandler());
bukkitHandlers.add(new OWorldBorderHandler());
bukkitHandlers.add(new OutputBlockStateHandler());
bukkitHandlers.add(new EntityOutputHandler()); // above CommandSender
bukkitHandlers.add(new CommandSenderOutputHandler());
bukkitHandlers.add(new EulerAngleOutputHandler());
bukkitHandlers.add(new HelpMapOutputHandler());
bukkitHandlers.add(new InventoryOutputHandler(this.typeHandler));
bukkitHandlers.add(new MessengerOutputHandler(this.typeHandler));
bukkitHandlers.add(new OfflinePlayerOutputHandler());
bukkitHandlers.add(new PermissionAttachmentInfoOutputHandler());
bukkitHandlers.add(new WorldBorderOutputHandler());

//
// Register
Expand Down Expand Up @@ -104,7 +104,7 @@ public BukkitBootstrap(TypeHandler typeHandler, Logger logger) {
}

private <T> void addExtensionFor(Class<T> clazz, PlatformExtension<T> extension) {
IHandler handler = typeHandler.getIHandlerForClass(clazz);
InputHandler<?> handler = typeHandler.getIHandlerForClass(clazz);
if (handler == null) {
throw new IllegalArgumentException("Cannot get input handler for type: " + clazz.getCanonicalName());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,22 @@

package io.zachbr.debuggery.reflection.types.handlers.bukkit.input;

import io.zachbr.debuggery.reflection.types.handlers.base.IPolymorphicHandler;
import io.zachbr.debuggery.reflection.types.handlers.base.InputPolymorphicHandler;
import io.zachbr.debuggery.reflection.types.handlers.base.platform.PlatformSender;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.block.data.BlockData;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

public class IBlockDataHandler implements IPolymorphicHandler {
public class BlockDataInputHandler implements InputPolymorphicHandler<BlockData> {

@Override
public @NotNull Object instantiateInstance(String input, Class<?> clazz, @Nullable PlatformSender<?> sender) {
public @NotNull BlockData instantiateInstance(String input, Class<? extends BlockData> clazz, @Nullable PlatformSender<?> sender) {
// first try from straight material name
Material material;
try {
material = IMaterialHandler.getMaterial(input);
material = MaterialInputHandler.getMaterial(input);
return Bukkit.createBlockData(material);
} catch (NullPointerException ignored) {
}
Expand All @@ -42,7 +42,7 @@ public class IBlockDataHandler implements IPolymorphicHandler {
}

@Override
public @NotNull Class<?> getRelevantClass() {
public @NotNull Class<BlockData> getRelevantClass() {
return BlockData.class;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@

package io.zachbr.debuggery.reflection.types.handlers.bukkit.input;

import io.zachbr.debuggery.reflection.types.handlers.base.IHandler;
import io.zachbr.debuggery.reflection.types.handlers.base.InputHandler;
import io.zachbr.debuggery.reflection.types.handlers.base.platform.PlatformSender;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

public class IBukkitClassHandler implements IHandler {
public class BukkitClassInputHandler implements InputHandler<Class> {

static @NotNull Class<?> getClass(String input) throws ClassNotFoundException {
// This is only used for entities right now, so we can save some drama and just search those packages
Expand Down Expand Up @@ -50,12 +50,12 @@ public class IBukkitClassHandler implements IHandler {
}

@Override
public @NotNull Class<?> instantiateInstance(String input, Class<?> clazz, @Nullable PlatformSender<?> sender) throws ClassNotFoundException {
public @NotNull Class<?> instantiateInstance(String input, Class<? extends Class> clazz, @Nullable PlatformSender<?> sender) throws ClassNotFoundException {
return getClass(input); // separate method so that IBukkitClassesHandler can get to it
}

@Override
public @NotNull Class<?> getRelevantClass() {
public @NotNull Class<Class> getRelevantClass() {
return Class.class; // This is only used for entities right now, so we can save some drama and just search those packages
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,22 @@

package io.zachbr.debuggery.reflection.types.handlers.bukkit.input;

import io.zachbr.debuggery.reflection.types.handlers.base.IHandler;
import io.zachbr.debuggery.reflection.types.handlers.base.InputHandler;
import io.zachbr.debuggery.reflection.types.handlers.base.platform.PlatformSender;
import io.zachbr.debuggery.reflection.types.handlers.input.EnumHandler;
import io.zachbr.debuggery.reflection.types.handlers.input.EnumInputHandler;
import io.zachbr.debuggery.util.StringUtil;
import org.bukkit.Difficulty;
import org.jetbrains.annotations.NotNull;

public class IDifficultyHandler implements IHandler {
public class DifficultyInputHandler implements InputHandler<Difficulty> {

@Override
public @NotNull Difficulty instantiateInstance(String input, Class<?> clazz, PlatformSender<?> sender) {
return StringUtil.parseAsIntOrFallback(input, Difficulty::getByValue, s -> EnumHandler.getEnumValue(s, Difficulty.class));
public @NotNull Difficulty instantiateInstance(String input, Class<? extends Difficulty> clazz, PlatformSender<?> sender) {
return StringUtil.parseAsIntOrFallback(input, Difficulty::getByValue, s -> EnumInputHandler.getEnumValue(s, Difficulty.class));
}

@Override
public @NotNull Class<?> getRelevantClass() {
public @NotNull Class<Difficulty> getRelevantClass() {
return Difficulty.class;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

package io.zachbr.debuggery.reflection.types.handlers.bukkit.input;

import io.zachbr.debuggery.reflection.types.handlers.base.IHandler;
import io.zachbr.debuggery.reflection.types.handlers.base.InputHandler;
import io.zachbr.debuggery.reflection.types.handlers.base.platform.PlatformSender;
import io.zachbr.debuggery.util.PlatformUtil;
import org.bukkit.Location;
Expand All @@ -26,7 +26,7 @@
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

public class IEntityHandler implements IHandler {
public class EntityInputHandler implements InputHandler<Entity> {

static @NotNull Entity getEntity(String input, @Nullable PlatformSender<?> sender) {
Entity target;
Expand All @@ -46,7 +46,7 @@ public class IEntityHandler implements IHandler {
}

// otherwise fall back to just getting the closest entity to the given location
Location loc = ILocationHandler.getLocation(input, sender);
Location loc = LocationInputHandler.getLocation(input, sender);
Entity nearest = PlatformUtil.getEntityNearestTo(loc, 25, 1.5D);

if (nearest != null) {
Expand All @@ -57,12 +57,12 @@ public class IEntityHandler implements IHandler {
}

@Override
public @NotNull Entity instantiateInstance(String input, Class<?> clazz, @Nullable PlatformSender<?> sender) {
public @NotNull Entity instantiateInstance(String input, Class<? extends Entity> clazz, @Nullable PlatformSender<?> sender) {
return getEntity(input, sender); // separate method so that other entity related commands can get to it
}

@Override
public @NotNull Class<?> getRelevantClass() {
public @NotNull Class<Entity> getRelevantClass() {
return Entity.class;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,23 @@

package io.zachbr.debuggery.reflection.types.handlers.bukkit.input;

import io.zachbr.debuggery.reflection.types.handlers.base.IHandler;
import io.zachbr.debuggery.reflection.types.handlers.base.InputHandler;
import io.zachbr.debuggery.reflection.types.handlers.base.platform.PlatformSender;
import io.zachbr.debuggery.util.StringUtil;
import org.bukkit.util.EulerAngle;
import org.jetbrains.annotations.NotNull;

public class IEulerAngleHandler implements IHandler {
public class EulerAngleInputHandler implements InputHandler<EulerAngle> {

@Override
public @NotNull Object instantiateInstance(String input, Class<?> clazz, PlatformSender<?> sender) {
public @NotNull EulerAngle instantiateInstance(String input, Class<? extends EulerAngle> clazz, PlatformSender<?> sender) {
double[] parsed = StringUtil.parseDoublesFromString(input, 3);

return new EulerAngle(parsed[0], parsed[1], parsed[2]);
}

@Override
public @NotNull Class<?> getRelevantClass() {
public @NotNull Class<EulerAngle> getRelevantClass() {
return EulerAngle.class;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,23 @@

package io.zachbr.debuggery.reflection.types.handlers.bukkit.input;

import io.zachbr.debuggery.reflection.types.handlers.base.IHandler;
import io.zachbr.debuggery.reflection.types.handlers.base.InputHandler;
import io.zachbr.debuggery.reflection.types.handlers.base.platform.PlatformSender;
import io.zachbr.debuggery.reflection.types.handlers.input.EnumHandler;
import io.zachbr.debuggery.reflection.types.handlers.input.EnumInputHandler;
import io.zachbr.debuggery.util.StringUtil;
import org.bukkit.GameMode;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

public class IGameModeHandler implements IHandler {
public class GameModeInputHandler implements InputHandler<GameMode> {

@Override
public @NotNull GameMode instantiateInstance(String input, Class<?> clazz, @Nullable PlatformSender<?> sender) {
return StringUtil.parseAsIntOrFallback(input, GameMode::getByValue, s -> EnumHandler.getEnumValue(s, GameMode.class));
public @NotNull GameMode instantiateInstance(String input, Class<? extends GameMode> clazz, @Nullable PlatformSender<?> sender) {
return StringUtil.parseAsIntOrFallback(input, GameMode::getByValue, s -> EnumInputHandler.getEnumValue(s, GameMode.class));
}

@Override
public @NotNull Class<?> getRelevantClass() {
public @NotNull Class<GameMode> getRelevantClass() {
return GameMode.class;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

package io.zachbr.debuggery.reflection.types.handlers.bukkit.input;

import io.zachbr.debuggery.reflection.types.handlers.base.IHandler;
import io.zachbr.debuggery.reflection.types.handlers.base.InputHandler;
import io.zachbr.debuggery.reflection.types.handlers.base.platform.PlatformSender;
import org.bukkit.Bukkit;
import org.bukkit.block.*;
Expand All @@ -26,9 +26,9 @@
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

public class IInventoryHandler implements IHandler {
public class InventoryInputHandler implements InputHandler<Inventory> {
@Override
public @NotNull Object instantiateInstance(String input, Class<?> clazz, @Nullable PlatformSender<?> sender) throws Exception {
public @NotNull Inventory instantiateInstance(String input, Class<? extends Inventory> clazz, @Nullable PlatformSender<?> sender) throws Exception {
if (sender == null || !(sender.getRawSender() instanceof Player)) {
throw new UnsupportedOperationException("Inventory input handler is only supported when used by a player!");
}
Expand All @@ -55,7 +55,7 @@ public class IInventoryHandler implements IHandler {
}

@Override
public @NotNull Class<?> getRelevantClass() {
public @NotNull Class<Inventory> getRelevantClass() {
return Inventory.class;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@

package io.zachbr.debuggery.reflection.types.handlers.bukkit.input;

import io.zachbr.debuggery.reflection.types.handlers.base.IHandler;
import io.zachbr.debuggery.reflection.types.handlers.base.InputHandler;
import io.zachbr.debuggery.reflection.types.handlers.base.platform.PlatformSender;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

public class IItemStackHandler implements IHandler {
public class ItemStackInputHandler implements InputHandler<ItemStack> {

static @NotNull ItemStack getItemStack(String input, @Nullable PlatformSender<?> sender) {
if (sender != null && sender.getRawSender() instanceof Player) {
Expand All @@ -34,16 +34,16 @@ public class IItemStackHandler implements IHandler {
}

// try creating a new itemstack from material
return new ItemStack(IMaterialHandler.getMaterial(input));
return new ItemStack(MaterialInputHandler.getMaterial(input));
}

@Override
public @NotNull ItemStack instantiateInstance(String input, Class<?> clazz, @Nullable PlatformSender<?> sender) {
public @NotNull ItemStack instantiateInstance(String input, Class<? extends ItemStack> clazz, @Nullable PlatformSender<?> sender) {
return getItemStack(input, sender);
}

@Override
public @NotNull Class<?> getRelevantClass() {
public @NotNull Class<ItemStack> getRelevantClass() {
return ItemStack.class;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@

package io.zachbr.debuggery.reflection.types.handlers.bukkit.input;

import io.zachbr.debuggery.reflection.types.handlers.base.IHandler;
import io.zachbr.debuggery.reflection.types.handlers.base.InputHandler;
import io.zachbr.debuggery.reflection.types.handlers.base.platform.PlatformSender;
import org.bukkit.*;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

public class ILocationHandler implements IHandler {
public class LocationInputHandler implements InputHandler<Location> {

static @NotNull Location getLocation(String input, @Nullable PlatformSender<?> sender) {
if (sender != null && sender.getRawSender() instanceof Player) {
Expand Down Expand Up @@ -52,12 +52,12 @@ public class ILocationHandler implements IHandler {
}

@Override
public @NotNull Location instantiateInstance(String input, Class<?> clazz, @Nullable PlatformSender<?> sender) {
public @NotNull Location instantiateInstance(String input, Class<? extends Location> clazz, @Nullable PlatformSender<?> sender) {
return getLocation(input, sender); // separate method so that related commands can get to it
}

@Override
public @NotNull Class<?> getRelevantClass() {
public @NotNull Class<Location> getRelevantClass() {
return Location.class;
}
}
Loading

0 comments on commit e2eef21

Please sign in to comment.