diff --git a/Corvo/src/main/java/me/totalfreedom/corvo/listener/PlayerInteractionListener.java b/Corvo/src/main/java/me/totalfreedom/corvo/listener/PlayerInteractionListener.java new file mode 100644 index 0000000..0704003 --- /dev/null +++ b/Corvo/src/main/java/me/totalfreedom/corvo/listener/PlayerInteractionListener.java @@ -0,0 +1,43 @@ +package me.totalfreedom.corvo.listener; + +import io.papermc.paper.event.block.BlockBreakBlockEvent; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.block.BlockBreakEvent; +import org.bukkit.event.inventory.InventoryCloseEvent; +import org.bukkit.event.inventory.InventoryOpenEvent; +import org.bukkit.event.player.PlayerInteractEvent; + +public class PlayerInteractionListener implements Listener +{ + @EventHandler + public void playerBreakBlock(final BlockBreakEvent event) + { + + } + + @EventHandler + public void blockBreakBlock(final BlockBreakBlockEvent event) + { + + } + + @EventHandler + public void playerOpenContainer(final InventoryOpenEvent event) + { + + } + + @EventHandler + public void playerCloseContainer(final InventoryCloseEvent event) + { + + } + + @EventHandler + public void playerInteraction(final PlayerInteractEvent event) + { + + } + +} diff --git a/Datura/src/main/java/me/totalfreedom/datura/perms/DefaultNodes.java b/Datura/src/main/java/me/totalfreedom/datura/perms/DefaultNodes.java index 3ed35ff..5119871 100644 --- a/Datura/src/main/java/me/totalfreedom/datura/perms/DefaultNodes.java +++ b/Datura/src/main/java/me/totalfreedom/datura/perms/DefaultNodes.java @@ -1,7 +1,7 @@ package me.totalfreedom.datura.perms; -import me.totalfreedom.security.perm.Node; -import me.totalfreedom.security.perm.NodeType; +import me.totalfreedom.security.Node; +import me.totalfreedom.security.NodeType; public class DefaultNodes { diff --git a/Datura/src/main/java/me/totalfreedom/datura/perms/FreedomGroup.java b/Datura/src/main/java/me/totalfreedom/datura/perms/FreedomGroup.java index b518f24..6e9a6d6 100644 --- a/Datura/src/main/java/me/totalfreedom/datura/perms/FreedomGroup.java +++ b/Datura/src/main/java/me/totalfreedom/datura/perms/FreedomGroup.java @@ -1,8 +1,8 @@ package me.totalfreedom.datura.perms; import me.totalfreedom.base.CommonsBase; -import me.totalfreedom.security.perm.Group; -import me.totalfreedom.security.perm.Node; +import me.totalfreedom.security.Group; +import me.totalfreedom.security.Node; import net.kyori.adventure.text.Component; import org.bukkit.permissions.Permission; import org.bukkit.permissions.PermissionAttachment; diff --git a/Datura/src/main/java/me/totalfreedom/datura/perms/FreedomUser.java b/Datura/src/main/java/me/totalfreedom/datura/perms/FreedomUser.java index 2a5d82a..cdd00f1 100644 --- a/Datura/src/main/java/me/totalfreedom/datura/perms/FreedomUser.java +++ b/Datura/src/main/java/me/totalfreedom/datura/perms/FreedomUser.java @@ -3,7 +3,7 @@ package me.totalfreedom.datura.perms; import me.totalfreedom.base.CommonsBase; import me.totalfreedom.datura.Datura; import me.totalfreedom.datura.user.SimpleUserData; -import me.totalfreedom.security.perm.Node; +import me.totalfreedom.security.Node; import me.totalfreedom.user.User; import me.totalfreedom.user.UserData; import net.kyori.adventure.text.Component; diff --git a/Datura/src/main/java/me/totalfreedom/datura/perms/PermissionNode.java b/Datura/src/main/java/me/totalfreedom/datura/perms/PermissionNode.java index 22fd39b..2a88f40 100644 --- a/Datura/src/main/java/me/totalfreedom/datura/perms/PermissionNode.java +++ b/Datura/src/main/java/me/totalfreedom/datura/perms/PermissionNode.java @@ -1,7 +1,7 @@ package me.totalfreedom.datura.perms; -import me.totalfreedom.security.perm.Node; -import me.totalfreedom.security.perm.NodeType; +import me.totalfreedom.security.Node; +import me.totalfreedom.security.NodeType; import org.bukkit.permissions.Permission; import org.bukkit.permissions.PermissionDefault; diff --git a/Datura/src/main/java/me/totalfreedom/datura/perms/PermissionNodeBuilder.java b/Datura/src/main/java/me/totalfreedom/datura/perms/PermissionNodeBuilder.java index 3ac7361..a89e69b 100644 --- a/Datura/src/main/java/me/totalfreedom/datura/perms/PermissionNodeBuilder.java +++ b/Datura/src/main/java/me/totalfreedom/datura/perms/PermissionNodeBuilder.java @@ -1,8 +1,8 @@ package me.totalfreedom.datura.perms; -import me.totalfreedom.security.perm.Node; -import me.totalfreedom.security.perm.NodeBuilder; -import me.totalfreedom.security.perm.NodeType; +import me.totalfreedom.security.Node; +import me.totalfreedom.security.NodeBuilder; +import me.totalfreedom.security.NodeType; public class PermissionNodeBuilder implements NodeBuilder { diff --git a/Datura/src/main/java/me/totalfreedom/datura/user/ServerEconomyHolder.java b/Datura/src/main/java/me/totalfreedom/datura/user/ServerEconomyHolder.java new file mode 100644 index 0000000..6db83ee --- /dev/null +++ b/Datura/src/main/java/me/totalfreedom/datura/user/ServerEconomyHolder.java @@ -0,0 +1,53 @@ +package me.totalfreedom.datura.user; + +import me.totalfreedom.economy.EconomicEntity; +import me.totalfreedom.economy.EconomicEntityData; + +public class ServerEconomyHolder implements EconomicEntity, EconomicEntityData +{ + private long balance = Long.MAX_VALUE; + + @Override + public EconomicEntityData getEconomicData() + { + return this; + } + + @Override + public String getName() + { + return "TotalFreedom-Bank"; + } + + @Override + public boolean areTransactionsFrozen() + { + return false; + } + + @Override + public long getBalance() + { + return balance; + } + + @Override + public void setBalance(final long newBalance) + { + balance = newBalance; + } + + @Override + public long addToBalance(final long amount) + { + balance += amount; + return balance; + } + + @Override + public long removeFromBalance(final long amount) + { + balance -= amount; + return balance; + } +} diff --git a/Datura/src/main/java/me/totalfreedom/datura/user/SimpleUserData.java b/Datura/src/main/java/me/totalfreedom/datura/user/SimpleUserData.java index 2ecefd4..65df6a1 100644 --- a/Datura/src/main/java/me/totalfreedom/datura/user/SimpleUserData.java +++ b/Datura/src/main/java/me/totalfreedom/datura/user/SimpleUserData.java @@ -3,7 +3,7 @@ package me.totalfreedom.datura.user; import me.totalfreedom.base.CommonsBase; import me.totalfreedom.datura.event.UserDataUpdateEvent; import me.totalfreedom.datura.perms.FreedomUser; -import me.totalfreedom.security.perm.Group; +import me.totalfreedom.security.Group; import me.totalfreedom.sql.SQL; import me.totalfreedom.user.User; import me.totalfreedom.user.UserData; diff --git a/Patchwork/src/main/java/me/totalfreedom/data/GroupRegistry.java b/Patchwork/src/main/java/me/totalfreedom/data/GroupRegistry.java index 8e8643e..12e6c57 100644 --- a/Patchwork/src/main/java/me/totalfreedom/data/GroupRegistry.java +++ b/Patchwork/src/main/java/me/totalfreedom/data/GroupRegistry.java @@ -1,6 +1,6 @@ package me.totalfreedom.data; -import me.totalfreedom.security.perm.Group; +import me.totalfreedom.security.Group; import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer; import java.util.ArrayList; diff --git a/Patchwork/src/main/java/me/totalfreedom/data/UserRegistry.java b/Patchwork/src/main/java/me/totalfreedom/data/UserRegistry.java index 24bffa1..b5f47e4 100644 --- a/Patchwork/src/main/java/me/totalfreedom/data/UserRegistry.java +++ b/Patchwork/src/main/java/me/totalfreedom/data/UserRegistry.java @@ -2,6 +2,7 @@ package me.totalfreedom.data; import me.totalfreedom.user.User; import me.totalfreedom.user.UserData; +import org.bukkit.entity.Player; import java.util.HashMap; import java.util.Map; @@ -20,6 +21,15 @@ public class UserRegistry return userDataMap.get(user); } + public UserData fromPlayer(final Player player) { + return userDataMap.entrySet() + .stream() + .filter(entry -> entry.getKey().getUniqueId().equals(player.getUniqueId())) + .findFirst() + .map(Map.Entry::getValue) + .orElse(null); + } + public void registerUserData(final User user, final UserData userData) { userDataMap.put(user, userData); diff --git a/Patchwork/src/main/java/me/totalfreedom/display/BossBarDisplay.java b/Patchwork/src/main/java/me/totalfreedom/display/BossBarDisplay.java new file mode 100644 index 0000000..3c59ccd --- /dev/null +++ b/Patchwork/src/main/java/me/totalfreedom/display/BossBarDisplay.java @@ -0,0 +1,204 @@ +package me.totalfreedom.display; + +import net.kyori.adventure.audience.Audience; +import net.kyori.adventure.audience.ForwardingAudience; +import net.kyori.adventure.bossbar.BossBar; +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.format.TextColor; +import org.jetbrains.annotations.Range; + +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +public class BossBarDisplay +{ + private BossBar bossBar; + + public BossBarDisplay(final BossBar bossBar) + { + this.bossBar = bossBar; + } + + public static BossBarBuilder builder() + { + return new BossBarBuilder(); + } + + public void changeColor(final BossBar.Color color) + { + this.bossBar.color(color); + } + + public void changeOverlay(final BossBar.Overlay overlay) + { + this.bossBar.overlay(overlay); + } + + public void changeName(final Component name) + { + this.bossBar.name(name); + } + + public void changeName(final String name, final TextColor color) + { + this.bossBar.name(Component.text(name, color)); + } + + public void changeName(final String name) + { + this.bossBar.name(Component.text(name)); + } + + public void showTo(final Audience audience) + { + audience.showBossBar(getBossBar()); + } + + public BossBar getBossBar() + { + return this.bossBar; + } + + public void setBossBar(final BossBar bossBar) + { + this.bossBar = bossBar; + } + + public void hideFrom(final Audience audience) + { + audience.hideBossBar(getBossBar()); + } + + public void incrementProgress(final @Range(from = 0, to = 100) float progress) + { + final float currentProgress = this.bossBar.progress(); + final float newProgress = currentProgress + (progress / 100.0F); + + if (newProgress > 1) this.bossBar.progress(1.0F); + else this.bossBar.progress(newProgress); + } + + public void decrementProgress(final @Range(from = 0, to = 100) float progress) + { + final float currentProgress = this.bossBar.progress(); + final float newProgress = currentProgress - (progress / 100.0F); + + if (newProgress < 0) this.bossBar.progress(0.0F); + else this.bossBar.progress(newProgress); + } + + public void maximumProgress() + { + this.bossBar.progress(1.0F); + } + + public void halfProgress() + { + this.bossBar.progress(0.5F); + } + + public void minimumProgress() + { + this.bossBar.progress(0.0F); + } + + public void showForwarded(final ForwardingAudience forwardingAudience) + { + forwardingAudience.showBossBar(getBossBar()); + } + + public void hideForwarded(final ForwardingAudience forwardingAudience) + { + forwardingAudience.hideBossBar(getBossBar()); + } + + private static final class BossBarBuilder + { + private final Set flags = new HashSet<>(); + private Component name; + private BossBar.Color color; + private BossBar.Overlay overlay; + @Range(from = 0, to = 1) + private float progress; + + public BossBarBuilder() + { + this.name = Component.empty(); + this.color = BossBar.Color.GREEN; + this.overlay = BossBar.Overlay.PROGRESS; + this.progress = 0.0F; + } + + public BossBarBuilder setName(final Component name) + { + this.name = name; + return this; + } + + public BossBarBuilder setName(final String name, final TextColor color) + { + this.name = Component.text(name, color); + return this; + } + + public BossBarBuilder setName(final String name) + { + this.name = Component.text(name); + return this; + } + + public BossBarBuilder addFlag(final BossBar.Flag flag) + { + this.flags.add(flag); + return this; + } + + public BossBarBuilder addFlags(final BossBar.Flag... flags) + { + this.flags.addAll(List.of(flags)); + return this; + } + + public BossBarBuilder removeFlag(final BossBar.Flag flag) + { + this.flags.remove(flag); + return this; + } + + public BossBarBuilder removeFlags(final BossBar.Flag... flags) + { + this.flags.removeAll(List.of(flags)); + return this; + } + + public BossBarBuilder clearFlags() + { + this.flags.clear(); + return this; + } + + public BossBarBuilder setColor(final BossBar.Color color) + { + this.color = color; + return this; + } + + public BossBarBuilder setOverlay(final BossBar.Overlay overlay) + { + this.overlay = overlay; + return this; + } + + public BossBarBuilder setProgress(final @Range(from = 0, to = 100) float progress) + { + this.progress = progress / 100.0F; + return this; + } + + public BossBar build() + { + return BossBar.bossBar(this.name, this.progress, this.color, this.overlay, this.flags); + } + } +} diff --git a/Patchwork/src/main/java/me/totalfreedom/display/TitleDisplay.java b/Patchwork/src/main/java/me/totalfreedom/display/TitleDisplay.java new file mode 100644 index 0000000..1a7a4e4 --- /dev/null +++ b/Patchwork/src/main/java/me/totalfreedom/display/TitleDisplay.java @@ -0,0 +1,127 @@ +package me.totalfreedom.display; + +import net.kyori.adventure.audience.Audience; +import net.kyori.adventure.audience.ForwardingAudience; +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.format.TextColor; +import net.kyori.adventure.title.Title; + +import java.time.Duration; + +public class TitleDisplay +{ + private Title title; + + public TitleDisplay(final Title title) + { + this.title = title; + } + + public static TitleBuilder builder() + { + return new TitleBuilder(); + } + + public void displayTo(final Audience audience) + { + audience.clearTitle(); + audience.showTitle(getTitle()); + } + + public Title getTitle() + { + return this.title; + } + + public void setTitle(final Title title) + { + this.title = title; + } + + public void displayForwarded(final ForwardingAudience forwardingAudience) + { + forwardingAudience.clearTitle(); + forwardingAudience.showTitle(getTitle()); + } + + private static final class TitleBuilder + { + private Component mainTitle; + private Component subTitle; + private Duration fadeIn; + private Duration fadeOut; + private Duration displayDuration; + + public TitleBuilder() + { + this.mainTitle = Component.empty(); + this.subTitle = Component.empty(); + this.fadeIn = Title.DEFAULT_TIMES.fadeIn(); + this.fadeOut = Title.DEFAULT_TIMES.fadeOut(); + this.displayDuration = Title.DEFAULT_TIMES.stay(); + } + + public TitleBuilder setMainTitle(final String title) + { + this.mainTitle = Component.text(title); + return this; + } + + public TitleBuilder setMainTitle(final String title, final TextColor titleColor) + { + this.mainTitle = Component.text(title, titleColor); + return this; + } + + public TitleBuilder setMainTitle(final Component mainTitle) + { + this.mainTitle = mainTitle; + return this; + } + + public TitleBuilder setSubTitle(final String title) + { + this.subTitle = Component.text(title); + return this; + } + + public TitleBuilder setSubTitle(final String title, final TextColor titleColor) + { + this.subTitle = Component.text(title, titleColor); + return this; + } + + public TitleBuilder setSubTitle(final Component subTitle) + { + this.subTitle = subTitle; + return this; + } + + public TitleBuilder setFadeIn(final Duration duration) + { + this.fadeIn = duration; + return this; + } + + public TitleBuilder setFadeOut(final Duration duration) + { + this.fadeOut = duration; + return this; + } + + public TitleBuilder setDisplayDuration(final Duration duration) + { + this.displayDuration = duration; + return this; + } + + public Title build() + { + return Title.title( + this.mainTitle, + this.subTitle, + Title.Times.times(this.fadeIn, this.displayDuration, this.fadeOut) + ); + } + } +} diff --git a/Patchwork/src/main/java/me/totalfreedom/logging/BlockInteraction.java b/Patchwork/src/main/java/me/totalfreedom/logging/BlockInteraction.java new file mode 100644 index 0000000..ae64341 --- /dev/null +++ b/Patchwork/src/main/java/me/totalfreedom/logging/BlockInteraction.java @@ -0,0 +1,57 @@ +package me.totalfreedom.logging; + +import org.bukkit.Location; +import org.bukkit.block.data.BlockData; +import org.bukkit.entity.Player; +import org.jetbrains.annotations.NotNull; + +import java.time.Instant; +import java.util.UUID; + +public final class BlockInteraction implements Interaction +{ + private final Location location; + private final UUID whoClicked; + private final Instant when; + private final BlockData originalState; + private final BlockData newState; + + public BlockInteraction(final Player player, final BlockData originalState, final BlockData newState) + { + this.location = player.getLocation(); + this.whoClicked = player.getUniqueId(); + this.when = Instant.now(); + this.originalState = originalState; + this.newState = newState; + } + + @Override + public @NotNull UUID getWhoClicked() + { + return whoClicked; + } + + @Override + public @NotNull BlockData getOriginalState() + { + return originalState; + } + + @Override + public @NotNull BlockData getNewState() + { + return newState; + } + + @Override + public @NotNull Instant getWhen() + { + return when; + } + + @Override + public @NotNull Location getLocation() + { + return location; + } +} diff --git a/Patchwork/src/main/java/me/totalfreedom/logging/ContainerInteraction.java b/Patchwork/src/main/java/me/totalfreedom/logging/ContainerInteraction.java new file mode 100644 index 0000000..c09efee --- /dev/null +++ b/Patchwork/src/main/java/me/totalfreedom/logging/ContainerInteraction.java @@ -0,0 +1,63 @@ +package me.totalfreedom.logging; + +import org.bukkit.Location; +import org.bukkit.block.Container; +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; +import org.jetbrains.annotations.NotNull; + +import java.time.Instant; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import java.util.UUID; + +public final class ContainerInteraction implements Interaction> +{ + private final UUID whoClicked; + private final List originalState; + private final List newState; + private final Instant when; + private final Location location; + + public ContainerInteraction(final Player player, final Container originalState, final Container newState) + { + this.whoClicked = player.getUniqueId(); + this.originalState = Collections.unmodifiableList(Arrays.asList(originalState.getInventory() + .getContents())); + this.newState = Collections.unmodifiableList(Arrays.asList(newState.getInventory() + .getContents())); + this.location = originalState.getLocation(); + this.when = Instant.now(); + } + + @Override + public @NotNull UUID getWhoClicked() + { + return whoClicked; + } + + @Override + public @NotNull List getOriginalState() + { + return originalState; + } + + @Override + public @NotNull List getNewState() + { + return newState; + } + + @Override + public @NotNull Instant getWhen() + { + return when; + } + + @Override + public @NotNull Location getLocation() + { + return location; + } +} diff --git a/Patchwork/src/main/java/me/totalfreedom/logging/Interaction.java b/Patchwork/src/main/java/me/totalfreedom/logging/Interaction.java new file mode 100644 index 0000000..75aeb63 --- /dev/null +++ b/Patchwork/src/main/java/me/totalfreedom/logging/Interaction.java @@ -0,0 +1,33 @@ +package me.totalfreedom.logging; + +import com.google.errorprone.annotations.Immutable; +import org.bukkit.Location; +import org.jetbrains.annotations.NotNull; + +import java.time.Instant; +import java.util.UUID; + +@Immutable +public interface Interaction +{ + @NotNull + static String format(@NotNull final Interaction interaction) + { + return new InteractionFormatter().formatInteraction(interaction); + } + + @NotNull + UUID getWhoClicked(); + + @NotNull + T getOriginalState(); + + @NotNull + T getNewState(); + + @NotNull + Instant getWhen(); + + @NotNull + Location getLocation(); +} diff --git a/Patchwork/src/main/java/me/totalfreedom/logging/InteractionFormatter.java b/Patchwork/src/main/java/me/totalfreedom/logging/InteractionFormatter.java new file mode 100644 index 0000000..c34bf1a --- /dev/null +++ b/Patchwork/src/main/java/me/totalfreedom/logging/InteractionFormatter.java @@ -0,0 +1,139 @@ +package me.totalfreedom.logging; + +import me.totalfreedom.sql.SQL; +import org.bukkit.Location; +import org.bukkit.World; +import org.bukkit.block.Block; +import org.bukkit.inventory.ItemStack; + +import java.time.Instant; + +public final class InteractionFormatter +{ + public String formatInteraction(final Interaction interaction) + { + final String location = formatLocation(interaction.getLocation()); + final String world = formatWorld(interaction.getLocation() + .getWorld()); + final String player = interaction.getWhoClicked() + .toString(); + final String block = formatBlock(interaction.getLocation() + .getBlock()); + final String when = formatTime(interaction.getWhen()); + + if (interaction instanceof ContainerInteraction container) + { + final StringBuilder stringBuilder = new StringBuilder(); + stringBuilder.append("Container ") + .append(block) + .append(" at location ") + .append(location) + .append(" in world ") + .append(world) + .append(" was opened by ") + .append(player) + .append(" at ") + .append(when) + .append("\nHere is a list of items changed:\n"); + + container.getOriginalState() + .stream() + .filter(item -> + { + final ItemStack newItem = container.getNewState() + .stream() + .filter(item2 -> item2.isSimilar(item)) + .findFirst() + .orElse(null); + return newItem == null || newItem.getAmount() != item.getAmount(); + }) + .forEach(item -> + { + final ItemStack newItem = container.getNewState() + .stream() + .filter(item2 -> item2.isSimilar(item)) + .findFirst() + .orElse(null); + stringBuilder.append("Item ") + .append(formatItemStack(item)) + .append(" was changed to ") + .append(formatItemStack(newItem)) + .append("\n"); + }); + + stringBuilder.append("."); + + return stringBuilder.toString(); + } else if (interaction instanceof BlockInteraction blockData) + { + final StringBuilder stringBuilder = new StringBuilder(); + stringBuilder.append("Block ") + .append(block) + .append(" at location ") + .append(location) + .append(" in world ") + .append(world) + .append(" was changed by ") + .append(player) + .append(" at ") + .append(when) + .append("\nBlock was changed from ") + .append(blockData.getOriginalState() + .getAsString()) + .append(" to ") + .append(blockData.getNewState() + .getAsString()) + .append("."); + + return stringBuilder.toString(); + } else + { + throw new IllegalArgumentException("Unknown interaction type: " + interaction.getClass() + .getName()); + } + } + + // Format: ,, + public String formatLocation(final Location location) + { + return String.format("%s,%s,%s", location.getBlockX(), location.getBlockY(), location.getBlockZ()); + } + + // Format: + public String formatWorld(final World world) + { + return world.getName(); + } + + // Format: + public String formatBlock(final Block block) + { + return block.getType() + .toString() + .toLowerCase(); + } + + public String formatTime(final Instant instant) + { + final String trimmed = instant.toString() + .replaceAll("[TZ]", " "); + final int dotIndex = trimmed.indexOf('.'); + + return (dotIndex != -1) + ? trimmed.substring(0, dotIndex) + : trimmed; + } + + // Format: , + public String formatItemStack(final ItemStack stack) + { + if (stack == null) + { + return String.format("%s,%s", "empty", "0"); + } + + return String.format("%s,%s", stack.getType() + .toString() + .toLowerCase(), stack.getAmount()); + } +} diff --git a/Patchwork/src/main/java/me/totalfreedom/security/perm/Group.java b/Patchwork/src/main/java/me/totalfreedom/security/Group.java similarity index 86% rename from Patchwork/src/main/java/me/totalfreedom/security/perm/Group.java rename to Patchwork/src/main/java/me/totalfreedom/security/Group.java index a0f1dcd..d09ba61 100644 --- a/Patchwork/src/main/java/me/totalfreedom/security/perm/Group.java +++ b/Patchwork/src/main/java/me/totalfreedom/security/Group.java @@ -1,4 +1,4 @@ -package me.totalfreedom.security.perm; +package me.totalfreedom.security; import net.kyori.adventure.text.Component; diff --git a/Patchwork/src/main/java/me/totalfreedom/security/perm/Node.java b/Patchwork/src/main/java/me/totalfreedom/security/Node.java similarity index 89% rename from Patchwork/src/main/java/me/totalfreedom/security/perm/Node.java rename to Patchwork/src/main/java/me/totalfreedom/security/Node.java index d661221..8af9348 100644 --- a/Patchwork/src/main/java/me/totalfreedom/security/perm/Node.java +++ b/Patchwork/src/main/java/me/totalfreedom/security/Node.java @@ -1,4 +1,4 @@ -package me.totalfreedom.security.perm; +package me.totalfreedom.security; import org.bukkit.permissions.Permission; diff --git a/Patchwork/src/main/java/me/totalfreedom/security/perm/NodeBuilder.java b/Patchwork/src/main/java/me/totalfreedom/security/NodeBuilder.java similarity index 88% rename from Patchwork/src/main/java/me/totalfreedom/security/perm/NodeBuilder.java rename to Patchwork/src/main/java/me/totalfreedom/security/NodeBuilder.java index 6769556..c0503ff 100644 --- a/Patchwork/src/main/java/me/totalfreedom/security/perm/NodeBuilder.java +++ b/Patchwork/src/main/java/me/totalfreedom/security/NodeBuilder.java @@ -1,4 +1,4 @@ -package me.totalfreedom.security.perm; +package me.totalfreedom.security; public interface NodeBuilder { diff --git a/Patchwork/src/main/java/me/totalfreedom/security/perm/NodeType.java b/Patchwork/src/main/java/me/totalfreedom/security/NodeType.java similarity index 70% rename from Patchwork/src/main/java/me/totalfreedom/security/perm/NodeType.java rename to Patchwork/src/main/java/me/totalfreedom/security/NodeType.java index 31c5b83..11293a9 100644 --- a/Patchwork/src/main/java/me/totalfreedom/security/perm/NodeType.java +++ b/Patchwork/src/main/java/me/totalfreedom/security/NodeType.java @@ -1,4 +1,4 @@ -package me.totalfreedom.security.perm; +package me.totalfreedom.security; public enum NodeType { diff --git a/Patchwork/src/main/java/me/totalfreedom/security/perm/PermissionHolder.java b/Patchwork/src/main/java/me/totalfreedom/security/PermissionHolder.java similarity index 87% rename from Patchwork/src/main/java/me/totalfreedom/security/perm/PermissionHolder.java rename to Patchwork/src/main/java/me/totalfreedom/security/PermissionHolder.java index f15ec15..05f7e7c 100644 --- a/Patchwork/src/main/java/me/totalfreedom/security/perm/PermissionHolder.java +++ b/Patchwork/src/main/java/me/totalfreedom/security/PermissionHolder.java @@ -1,4 +1,4 @@ -package me.totalfreedom.security.perm; +package me.totalfreedom.security; import org.bukkit.permissions.Permissible; diff --git a/Patchwork/src/main/java/me/totalfreedom/security/ban/Ban.java b/Patchwork/src/main/java/me/totalfreedom/security/ban/Ban.java deleted file mode 100644 index 438b5f8..0000000 --- a/Patchwork/src/main/java/me/totalfreedom/security/ban/Ban.java +++ /dev/null @@ -1,78 +0,0 @@ -package me.totalfreedom.security.ban; - -import org.jetbrains.annotations.Nullable; - -import java.time.Instant; -import java.util.UUID; - -/** - * Represents a physical ban entry. This is used to store information about a ban, - * such as the player who was banned, the reason for why they were banned, the individual who issued the ban, - * when the ban expires, and when the ban was created. - *
- * Ban information is stored in the Database with the {@link BanID} as the PRIMARY KEY. - */ -public interface Ban -{ - /** - * Gets the ID of this ban. This is an object which represents a string prefixed with either a T or a P, - * and suffixed with a 6-10 digit numerical code. This is used to identify the ban in the database, and for - * easier ban referencing. - * - * @return The ID of this ban. - */ - BanID getBanID(); - - /** - * Gets the UUID of the player who was banned. This is formatted as a UUID - * which allows us to retrieve the particular player instance, if applicable, and also - * have a true identifier to check against user logins. - * - * @return The UUID of the player who was banned. - */ - UUID getOffenderID(); - - /** - * Gets the reason that the player was banned for. Typically, the default reason is "You are banned!". - * We've forced implementations to require a reason, as it's important to know why a player was banned. - * - * @return The reason that the player was banned for. - */ - String getReason(); - - /** - * Gets the username of the individual who issued the ban. This is not a reliable way to store data, but - * in our case, we should not need to interact with the ban issuer from the code. This is simply for - * reference purposes. - * - * @return The username of the individual who issued the ban. - */ - String getBanIssuer(); - - /** - * Gets the {@link Instant} which this ban was created. - * - * @return The ban's creation time. - */ - Instant getCreationTime(); - - /** - * Gets the {@link Instant} which this ban is due to expire, if applicable. - * This method is annotated as {@link Nullable}, as permanent bans do not have an expiry date. - * - * @return The ban's expiry time, or null if the ban is permanent. - */ - @Nullable - Instant getExpiry(); - - /** - * Checks if the ban has expired. This will return false if: - *
    - *
  • The {@link Instant} returned by {@link #getExpiry()} is null.
  • - *
  • The {@link Instant} returned by {@link #getExpiry()} is after the current time.
  • - *
- * - * @return True if the ban has expired, false otherwise. - */ - boolean isExpired(); -} diff --git a/Patchwork/src/main/java/me/totalfreedom/security/ban/BanID.java b/Patchwork/src/main/java/me/totalfreedom/security/ban/BanID.java deleted file mode 100644 index b6f004a..0000000 --- a/Patchwork/src/main/java/me/totalfreedom/security/ban/BanID.java +++ /dev/null @@ -1,54 +0,0 @@ -package me.totalfreedom.security.ban; - -/** - * Represents an ID for a ban. These are formatted either as: - *

- * P-00129381 - *
- * T-00128381 - *
- *

- * Where P marks a ban as permanent, and T marks a ban as temporary. - */ -public interface BanID -{ - /** - * This method returns the full Ban ID. - * - * @return The actual ID. - */ - String getID(); - - /** - * Checks the prefix of the Ban ID to see whether if it is permanent. - * - * @return true if the Ban ID is prefixed with a P, false otherwise. - */ - boolean isPermanent(); - - default boolean matches(BanID other) - { - if (other == null) - { - return false; - } - return (getIDPrefix() == other.getIDPrefix()) - && (getNumericalTag() == other.getNumericalTag()); - } - - /** - * This method returns the ban type denominator character for the Ban ID. - * This would either be T or P, where T = temporary and P = permanent. - * - * @return The ban type denominator character for the Ban ID. - */ - char getIDPrefix(); - - /** - * Gets the numerical tag of this ban ID. - * This would be the numerical section of the full Ban ID. - * - * @return The numerical tag of this ban ID. - */ - int getNumericalTag(); -} diff --git a/Patchwork/src/main/java/me/totalfreedom/shop/Reactable.java b/Patchwork/src/main/java/me/totalfreedom/shop/Reactable.java new file mode 100644 index 0000000..c8dacd2 --- /dev/null +++ b/Patchwork/src/main/java/me/totalfreedom/shop/Reactable.java @@ -0,0 +1,16 @@ +package me.totalfreedom.shop; + +import me.totalfreedom.economy.EconomicEntity; + +import java.time.Duration; + +public interface Reactable +{ + String getReactionMessage(); + + Duration getReactionDuration(); + + ReactionType getReactionType(); + + void onReact(final EconomicEntity entity); +} diff --git a/Patchwork/src/main/java/me/totalfreedom/shop/ReactionType.java b/Patchwork/src/main/java/me/totalfreedom/shop/ReactionType.java new file mode 100644 index 0000000..b2b308d --- /dev/null +++ b/Patchwork/src/main/java/me/totalfreedom/shop/ReactionType.java @@ -0,0 +1,6 @@ +package me.totalfreedom.shop; + +public enum ReactionType +{ + COPYCAT, UNSCRAMBLE; +} diff --git a/Patchwork/src/main/java/me/totalfreedom/user/User.java b/Patchwork/src/main/java/me/totalfreedom/user/User.java index 20f58e6..f925492 100644 --- a/Patchwork/src/main/java/me/totalfreedom/user/User.java +++ b/Patchwork/src/main/java/me/totalfreedom/user/User.java @@ -2,7 +2,7 @@ package me.totalfreedom.user; import me.totalfreedom.economy.EconomicEntity; import me.totalfreedom.economy.EconomicEntityData; -import me.totalfreedom.security.perm.PermissionHolder; +import me.totalfreedom.security.PermissionHolder; import net.kyori.adventure.text.Component; public interface User extends PermissionHolder, EconomicEntity diff --git a/Patchwork/src/main/java/me/totalfreedom/user/UserData.java b/Patchwork/src/main/java/me/totalfreedom/user/UserData.java index e482750..2cfb8d1 100644 --- a/Patchwork/src/main/java/me/totalfreedom/user/UserData.java +++ b/Patchwork/src/main/java/me/totalfreedom/user/UserData.java @@ -1,7 +1,7 @@ package me.totalfreedom.user; import me.totalfreedom.economy.EconomicEntityData; -import me.totalfreedom.security.perm.Group; +import me.totalfreedom.security.Group; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -27,10 +27,6 @@ public interface UserData extends EconomicEntityData void resetPlaytime(); - boolean isFrozen(); - - void setFrozen(boolean frozen); - boolean canInteract(); void setInteractionState(boolean canInteract);