Skip to content

Commit

Permalink
annotate method
Browse files Browse the repository at this point in the history
  • Loading branch information
xGinko committed Aug 6, 2024
1 parent b16eace commit 569e2e2
Show file tree
Hide file tree
Showing 31 changed files with 101 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
import org.bukkit.event.Listener;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.jetbrains.annotations.NotNull;

import java.util.Collections;
import java.util.EnumSet;
Expand Down Expand Up @@ -78,7 +80,7 @@ public boolean shouldEnable() {
}

@Override
public ItemLegality legalityOf(ItemStack itemStack) {
public @NotNull ItemLegality legalityOf(@Nullable ItemStack itemStack) {
if (
itemStack == null
|| whitelistedTypes.contains(itemStack.getType())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import me.xginko.aef.utils.ItemUtil;
import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.jetbrains.annotations.NotNull;

import java.util.EnumSet;
import java.util.List;
Expand Down Expand Up @@ -65,7 +67,7 @@ public boolean shouldEnable() {
}

@Override
public ItemLegality legalityOf(ItemStack itemStack) {
public @NotNull ItemLegality legalityOf(@Nullable ItemStack itemStack) {
if (itemStack == null) {
return ItemLegality.LEGAL;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@
import org.bukkit.event.world.ChunkLoadEvent;
import org.bukkit.inventory.InventoryHolder;
import org.bukkit.inventory.ItemStack;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.checkerframework.checker.nullness.qual.PolyNull;
import org.jetbrains.annotations.NotNull;

import java.time.Duration;
import java.util.Arrays;
Expand All @@ -49,9 +51,6 @@

public abstract class IllegalItemModule extends AEFModule implements Listener {

public abstract ItemLegality legalityOf(ItemStack itemStack);
public abstract void handleItem(ItemStack itemStack, ItemLegality legality);

protected final AEFPermission bypassPermission;
protected final IllegalHandling handling;
protected final Set<Listener> optionalListeners;
Expand All @@ -62,6 +61,7 @@ public IllegalItemModule(String configPath, AEFPermission bypassPermission) {
super(configPath);
this.bypassPermission = bypassPermission;
this.optionalListeners = new HashSet<>();

String configuredHandling = config.getString(configPath + ".handling", IllegalHandling.PREVENT_USE_ONLY.name(),
"Available options:\n" + Arrays.stream(IllegalHandling.values())
.map(option -> option.name() + " - " + option.description())
Expand Down Expand Up @@ -157,6 +157,10 @@ private void onChunkLoad(ChunkLoadEvent event) {
this.createIfAbsent = eventClass -> new ExpiringSet<>(delay);
}

public abstract @NotNull ItemLegality legalityOf(@Nullable ItemStack itemStack);

public abstract void handleItem(ItemStack itemStack, ItemLegality legality);

@Override
public void enable() {
plugin.getServer().getPluginManager().registerEvents(this, plugin);
Expand All @@ -170,7 +174,7 @@ public void disable() {
optionalListeners.clear();
}

public ItemLegality legalityOf(Iterable<ItemStack> itemStacks) {
public ItemLegality legalityOf(@Nullable Iterable<ItemStack> itemStacks) {
if (itemStacks == null) {
return ItemLegality.LEGAL;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import me.xginko.aef.utils.MaterialUtil;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.PotionMeta;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.jetbrains.annotations.NotNull;

public class IllegalPotions extends IllegalItemModule {

Expand All @@ -27,7 +29,7 @@ public boolean shouldEnable() {
}

@Override
public ItemLegality legalityOf(ItemStack itemStack) {
public @NotNull ItemLegality legalityOf(@Nullable ItemStack itemStack) {
if (itemStack == null || !MaterialUtil.POTIONS.contains(itemStack.getType()) || !itemStack.hasItemMeta()) {
return ItemLegality.LEGAL;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import me.xginko.aef.utils.ItemUtil;
import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.jetbrains.annotations.NotNull;

import java.util.EnumSet;
import java.util.List;
Expand Down Expand Up @@ -47,7 +49,7 @@ public boolean shouldEnable() {
}

@Override
public ItemLegality legalityOf(ItemStack itemStack) {
public @NotNull ItemLegality legalityOf(@Nullable ItemStack itemStack) {
if (itemStack == null || itemStack.getType().isAir()) {
return ItemLegality.LEGAL;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import org.bukkit.inventory.ItemFlag;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.jetbrains.annotations.NotNull;

import java.util.EnumSet;
import java.util.List;
Expand Down Expand Up @@ -49,7 +51,7 @@ public boolean shouldEnable() {
}

@Override
public ItemLegality legalityOf(ItemStack itemStack) {
public @NotNull ItemLegality legalityOf(@Nullable ItemStack itemStack) {
if (itemStack == null || itemStack.getType().isAir() || !itemStack.hasItemMeta()) {
return ItemLegality.LEGAL;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import me.xginko.aef.utils.ItemUtil;
import me.xginko.aef.utils.MaterialUtil;
import org.bukkit.inventory.ItemStack;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.jetbrains.annotations.NotNull;

public class PlayerHeads extends IllegalItemModule {

Expand All @@ -26,7 +28,7 @@ public boolean shouldEnable() {
}

@Override
public ItemLegality legalityOf(ItemStack itemStack) {
public @NotNull ItemLegality legalityOf(@Nullable ItemStack itemStack) {
if (itemStack == null) {
return ItemLegality.LEGAL;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import me.xginko.aef.utils.ItemUtil;
import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.jetbrains.annotations.NotNull;

import java.util.Collections;
import java.util.EnumSet;
Expand Down Expand Up @@ -49,7 +51,7 @@ public boolean shouldEnable() {
}

@Override
public ItemLegality legalityOf(ItemStack itemStack) {
public @NotNull ItemLegality legalityOf(@Nullable ItemStack itemStack) {
if (itemStack == null || whitelistedTypes.contains(itemStack.getType())) {
return ItemLegality.LEGAL;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.Damageable;
import org.bukkit.inventory.meta.ItemMeta;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.jetbrains.annotations.NotNull;

import java.util.EnumSet;
import java.util.List;
Expand Down Expand Up @@ -53,7 +55,7 @@ public boolean shouldEnable() {
}

@Override
public ItemLegality legalityOf(ItemStack itemStack) {
public @NotNull ItemLegality legalityOf(@Nullable ItemStack itemStack) {
if (itemStack == null || itemStack.getType().isAir() || !itemStack.hasItemMeta()) {
return ItemLegality.LEGAL;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import org.bukkit.Material;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.inventory.ItemStack;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.jetbrains.annotations.NotNull;

import java.util.EnumSet;
import java.util.HashSet;
Expand Down Expand Up @@ -63,7 +65,7 @@ public boolean shouldEnable() {
}

@Override
public ItemLegality legalityOf(ItemStack itemStack) {
public @NotNull ItemLegality legalityOf(@Nullable ItemStack itemStack) {
if (itemStack == null || itemStack.getType().isAir()) {
return ItemLegality.LEGAL;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import org.bukkit.Material;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.inventory.ItemStack;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.jetbrains.annotations.NotNull;

import java.util.EnumSet;
import java.util.List;
Expand Down Expand Up @@ -51,7 +53,7 @@ public boolean shouldEnable() {
}

@Override
public ItemLegality legalityOf(ItemStack itemStack) {
public @NotNull ItemLegality legalityOf(@Nullable ItemStack itemStack) {
if (itemStack == null || itemStack.getType().isAir()) {
return ItemLegality.LEGAL;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import org.bukkit.Material;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.inventory.ItemStack;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.jetbrains.annotations.NotNull;

import java.util.Collections;
import java.util.EnumSet;
Expand Down Expand Up @@ -76,7 +78,7 @@ public boolean shouldEnable() {
}

@Override
public ItemLegality legalityOf(ItemStack itemStack) {
public @NotNull ItemLegality legalityOf(@Nullable ItemStack itemStack) {
if (itemStack == null || itemStack.getType() == Material.AIR) {
return ItemLegality.LEGAL;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import me.xginko.aef.modules.illegals.items.IllegalItemModule;
import me.xginko.aef.utils.MaterialUtil;
import org.bukkit.inventory.ItemStack;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.jetbrains.annotations.NotNull;

public class CommandItems extends IllegalItemModule {

Expand All @@ -27,7 +29,7 @@ public boolean shouldEnable() {
}

@Override
public ItemLegality legalityOf(ItemStack itemStack) {
public @NotNull ItemLegality legalityOf(@Nullable ItemStack itemStack) {
if (itemStack == null || itemStack.getType().isAir()) {
return ItemLegality.LEGAL;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import me.xginko.aef.utils.ItemUtil;
import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.jetbrains.annotations.NotNull;

import java.util.EnumSet;
import java.util.HashSet;
Expand Down Expand Up @@ -52,7 +54,7 @@ public boolean shouldEnable() {
}

@Override
public ItemLegality legalityOf(ItemStack itemStack) {
public @NotNull ItemLegality legalityOf(@Nullable ItemStack itemStack) {
if (itemStack == null || itemStack.getType().isAir()) {
return ItemLegality.LEGAL;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import me.xginko.aef.utils.MaterialUtil;
import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.jetbrains.annotations.NotNull;

import java.util.EnumSet;
import java.util.Objects;
Expand Down Expand Up @@ -55,7 +57,7 @@ public boolean shouldEnable() {
}

@Override
public ItemLegality legalityOf(ItemStack itemStack) {
public @NotNull ItemLegality legalityOf(@Nullable ItemStack itemStack) {
if (itemStack == null || itemStack.getType().isAir()) {
return ItemLegality.LEGAL;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.jetbrains.annotations.NotNull;

import java.util.Collections;
import java.util.EnumSet;
Expand Down Expand Up @@ -56,7 +58,7 @@ public boolean shouldEnable() {
}

@Override
public ItemLegality legalityOf(ItemStack itemStack) {
public @NotNull ItemLegality legalityOf(@Nullable ItemStack itemStack) {
if (
itemStack == null
|| whitelistedTypes.contains(itemStack.getType())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import me.xginko.aef.utils.ItemUtil;
import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.jetbrains.annotations.NotNull;

import java.util.EnumSet;
import java.util.List;
Expand Down Expand Up @@ -65,7 +67,7 @@ public boolean shouldEnable() {
}

@Override
public ItemLegality legalityOf(ItemStack itemStack) {
public @NotNull ItemLegality legalityOf(@Nullable ItemStack itemStack) {
if (itemStack == null) {
return ItemLegality.LEGAL;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@
import org.bukkit.event.world.ChunkLoadEvent;
import org.bukkit.inventory.InventoryHolder;
import org.bukkit.inventory.ItemStack;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.checkerframework.checker.nullness.qual.PolyNull;
import org.jetbrains.annotations.NotNull;

import java.time.Duration;
import java.util.Arrays;
Expand All @@ -49,13 +51,9 @@

public abstract class IllegalItemModule extends AEFModule implements Listener {

public abstract ItemLegality legalityOf(ItemStack itemStack);
public abstract void handleItem(ItemStack itemStack, ItemLegality legality);

protected final AEFPermission bypassPermission;
protected final IllegalHandling handling;
protected final Set<Listener> optionalListeners;

private final Cache<Class<? extends Event>, ExpiringSet<Object>> listenerCooldowns;
private final Function<Class<? extends Event>, @PolyNull ExpiringSet<Object>> createIfAbsent;

Expand Down Expand Up @@ -159,6 +157,10 @@ private void onChunkLoad(ChunkLoadEvent event) {
this.createIfAbsent = eventClass -> new ExpiringSet<>(delay);
}

public abstract @NotNull ItemLegality legalityOf(@Nullable ItemStack itemStack);

public abstract void handleItem(ItemStack itemStack, ItemLegality legality);

@Override
public void enable() {
plugin.getServer().getPluginManager().registerEvents(this, plugin);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import me.xginko.aef.utils.MaterialUtil;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.PotionMeta;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.jetbrains.annotations.NotNull;

public class IllegalPotions extends IllegalItemModule {

Expand All @@ -27,7 +29,7 @@ public boolean shouldEnable() {
}

@Override
public ItemLegality legalityOf(ItemStack itemStack) {
public @NotNull ItemLegality legalityOf(@Nullable ItemStack itemStack) {
if (itemStack == null || !MaterialUtil.POTIONS.contains(itemStack.getType()) || !itemStack.hasItemMeta()) {
return ItemLegality.LEGAL;
}
Expand Down
Loading

0 comments on commit 569e2e2

Please sign in to comment.