Skip to content

Commit

Permalink
Import Cleanups and added Docstrings
Browse files Browse the repository at this point in the history
  • Loading branch information
ahmadk953 committed Jun 15, 2024
1 parent 953a909 commit 68a5944
Show file tree
Hide file tree
Showing 16 changed files with 213 additions and 32 deletions.
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,15 @@ A custom plugin that I created for my Minecraft server, Poixpixel.

## Installation

### Dependencies
### Dependencies (Must-Haves)

- Vault

### Soft Dependencies (Optional, but Recommended)

- Luckperms
- ProtocoLib

### Where to download

Head over to the [GitHub releases page](https://github.com/ahmadk953/Poixpixel-Custom/releases) and download the latest version
Expand Down
13 changes: 6 additions & 7 deletions src/main/java/com/poixpixelcustom/PoixpixelCustom.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,7 @@
import com.poixpixelcustom.tasks.LaserPointerTask;
import com.poixpixelcustom.utils.ConfigHandler;
import com.poixpixelcustom.utils.CustomRecipes;

import org.bstats.bukkit.Metrics;

import net.milkbowl.vault.chat.Chat;
import net.milkbowl.vault.economy.Economy;
import net.milkbowl.vault.permission.Permission;

import org.bukkit.plugin.RegisteredServiceProvider;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.scheduler.BukkitTask;

Expand Down Expand Up @@ -102,6 +95,12 @@ private void setup() {
CustomRecipes.register();
}

/**
* Cancels the running tasks if they are not already cancelled.
*
* This method checks if each task is not null and not already cancelled,
* and if so, cancels the task.
*/
private void disablePlugin() {
/*
* Cancel Tasks if they are Running
Expand Down
13 changes: 12 additions & 1 deletion src/main/java/com/poixpixelcustom/commands/ButterflyCommand.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.poixpixelcustom.commands;

import com.poixpixelcustom.tasks.ButterflyTask;

import net.kyori.adventure.text.Component;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
Expand All @@ -11,6 +10,18 @@

public class ButterflyCommand implements CommandExecutor {

/**
* Executes the command when a player runs the command. If the sender is not a player,
* sends a message to the sender and returns true. Otherwise, checks if the player has
* butterfly wings. If they do, removes the wings and sends a message to the player. If
* they don't, adds the wings and sends a message to the player. Returns true.
*
* @param sender the command sender
* @param command the command being executed
* @param s the label of the command
* @param strings the arguments passed to the command
* @return true if the command was executed successfully, false otherwise
*/
@Override
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String s, @NotNull String[] strings) {
if (!(sender instanceof Player)) {
Expand Down
14 changes: 11 additions & 3 deletions src/main/java/com/poixpixelcustom/commands/CustomItemCommand.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
package com.poixpixelcustom.commands;

import com.poixpixelcustom.constants.Keys;

import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
import net.kyori.adventure.text.format.TextDecoration;

import org.bukkit.Material;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
Expand All @@ -16,13 +14,23 @@
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.persistence.PersistentDataType;

import org.jetbrains.annotations.NotNull;

import java.util.Arrays;

public class CustomItemCommand implements CommandExecutor {

/**
* Executes the command for the player. If the sender is not a player, sends a message and returns true.
* Otherwise, creates a custom bucket item with a display name and lore, adds enchantments and metadata,
* and adds the item to the player's inventory.
*
* @param sender the command sender
* @param command the command that was executed
* @param s the command name
* @param strings the command arguments
* @return true if the command was executed successfully
*/
@Override
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String s, @NotNull String[] strings) {
if (!(sender instanceof Player)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,19 @@
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
import net.kyori.adventure.text.format.TextDecoration;

import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabExecutor;
import org.bukkit.entity.*;
import org.bukkit.entity.BlockDisplay;
import org.bukkit.entity.Display.Billboard;
import org.bukkit.entity.ItemDisplay;
import org.bukkit.entity.Player;
import org.bukkit.entity.TextDisplay;
import org.bukkit.inventory.ItemStack;
import org.bukkit.util.Transformation;

import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

Expand All @@ -25,6 +26,15 @@
public class DisplayEntityCommand implements CommandExecutor, TabExecutor {
private static final Logger log = Logger.getLogger("Minecraft");

/**
* Executes the display entity command based on the provided arguments.
*
* @param sender the command sender
* @param command the command being executed
* @param label the label of the command
* @param args the arguments passed to the command
* @return true if the command was executed successfully, false otherwise
*/
@Override
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
if (!(sender instanceof Player)) {
Expand Down Expand Up @@ -100,6 +110,16 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command
return true;
}

/**
* Overrides the onTabComplete method of the TabExecutor interface to provide tab completion suggestions
* for the DisplayEntityCommand.
*
* @param sender the command sender
* @param command the command being executed
* @param label the label of the command
* @param args the arguments passed to the command
* @return a list of suggestions for the next argument, or an empty list if no suggestions are available
*/
@Override
public @Nullable List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@

import com.poixpixelcustom.constants.Keys;
import com.poixpixelcustom.utils.ConfigHandler;

import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabExecutor;
import org.bukkit.entity.*;
import org.bukkit.entity.Ageable;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.persistence.PersistentDataType;

import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

Expand All @@ -23,6 +23,15 @@

public class ExplodingEntityCommand implements CommandExecutor, TabExecutor {

/**
* Executes the exploding entity command.
*
* @param sender the command sender
* @param command the command being executed
* @param label the command label
* @param args the command arguments
* @return true if the command was executed successfully, false otherwise
*/
@Override
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
if (!(sender instanceof Player)) {
Expand Down Expand Up @@ -74,6 +83,15 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command
return true;
}

/**
* Generates a list of tab completion suggestions for the ExplodingEntityCommand.
*
* @param sender the command sender
* @param command the command being executed
* @param label the command label
* @param args the command arguments
* @return a list of tab completion suggestions or an empty list if none
*/
@Override
public @Nullable List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
if (args.length == 1)
Expand Down
16 changes: 13 additions & 3 deletions src/main/java/com/poixpixelcustom/commands/GuiCommand.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
package com.poixpixelcustom.commands;

import com.poixpixelcustom.PoixpixelCustom;

import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;

import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.command.Command;
Expand All @@ -16,11 +14,23 @@
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.metadata.FixedMetadataValue;

import org.jetbrains.annotations.NotNull;

public class GuiCommand implements CommandExecutor {

/**
* Executes the GUI command for the player. Opens an inventory with a utility menu and sets metadata to
* track the opened menu. The inventory contains three items: a diamond button, a lava bucket button,
* and a sunflower button. The diamond button displays the text "Get Diamond" in aqua color. The lava
* bucket button displays the text "Clear Inventory" in red color. The sunflower button displays the
* text "Clear Weather" in yellow color.
*
* @param sender the command sender
* @param command the command that was executed
* @param s the command name
* @param strings the command arguments
* @return true if the command was executed successfully
*/
@Override
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String s, @NotNull String[] strings) {
if (!(sender instanceof Player)) {
Expand Down
7 changes: 5 additions & 2 deletions src/main/java/com/poixpixelcustom/listeners/ChatListener.java
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
package com.poixpixelcustom.listeners;

import io.papermc.paper.event.player.AsyncChatEvent;

import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.TextComponent;
import net.kyori.adventure.text.minimessage.MiniMessage;

import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;

public class ChatListener implements Listener {

/**
* Handles the asynchronous chat event by deserializing the message using MiniMessage and replacing the original message with the deserialized one.
*
* @param event the AsyncChatEvent representing the chat event
*/
@EventHandler
public void onChat(AsyncChatEvent event) {
TextComponent textComponent = (TextComponent) event.message();
Expand Down
10 changes: 8 additions & 2 deletions src/main/java/com/poixpixelcustom/listeners/EntityListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@

import com.poixpixelcustom.constants.Keys;
import com.poixpixelcustom.utils.ConfigHandler;

import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;

import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
Expand All @@ -19,6 +17,14 @@ public class EntityListener implements Listener {
// FIXME: Figure out why this does not work
private final float explosionPower = ConfigHandler.getInstance().getExplosionPower();

/**
* Handles the event when a player right-clicks on an entity with the main hand item.
* If the entity is of the exploding type, has the custom entity tag, and the main hand item has the custom bucket tag,
* and the player has the permission to use the exploding entity, it creates an explosion at the entity's location.
* Otherwise, it sends a message to the player.
*
* @param event the PlayerInteractEntityEvent representing the right-click event
*/
@EventHandler
public void onEntityRightClick(PlayerInteractEntityEvent event) {

Expand Down
12 changes: 11 additions & 1 deletion src/main/java/com/poixpixelcustom/listeners/GuiListener.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.poixpixelcustom.listeners;

import com.poixpixelcustom.PoixpixelCustom;

import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
Expand All @@ -12,6 +11,11 @@

public class GuiListener implements Listener {

/**
* Handles the click event in a GUI inventory.
*
* @param event the InventoryClickEvent that triggered the click
*/
@EventHandler
public void onClick(InventoryClickEvent event) {
Player player = (Player) event.getWhoClicked();
Expand All @@ -36,6 +40,12 @@ public void onClick(InventoryClickEvent event) {
}
}

/**
* Handles the event when a player closes a GUI inventory. Removes the "OpenedMenu" metadata from the player
* if it exists.
*
* @param event the InventoryCloseEvent that triggered the event
*/
@EventHandler
public void onClose(InventoryCloseEvent event) {
Player player = (Player) event.getPlayer();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@

public final class LaserPointerListener implements Listener {

/**
* Handles the event when a player interacts with an item in their hand. If the player right clicks in the air,
* checks if they have the permission to use the laser and if the item in their hand is a laser pointer. If so,
* traces a line in the air and creates an explosion at the location of the hit block if it is a solid block. If the
* hit block is too far or not a solid block, sends a message to the player.
*
* @param event the PlayerInteractEvent representing the interaction event
*/
@EventHandler
public void onClick(final PlayerInteractEvent event) {
if (event.getHand() != EquipmentSlot.HAND || event.getAction() != Action.RIGHT_CLICK_AIR)
Expand Down
2 changes: 0 additions & 2 deletions src/main/java/com/poixpixelcustom/tasks/Board.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
package com.poixpixelcustom.tasks;

import com.poixpixelcustom.PoixpixelCustom;

import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
import net.kyori.adventure.text.format.TextDecoration;

import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Statistic;
Expand Down
Loading

0 comments on commit 68a5944

Please sign in to comment.