-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Deleted old class that housed all commands in a switch statement - Created a new abstract command class to easily extend and create commands - Commands have now been moved to their own classes - Permissions and access to commands have been organized in the rewrite - Unrelated changes - Moved library to paper instead of spigot - Added lombok dependency for reduction of code - Added some comments to the events - Removed redundant casts and unused imports
- Loading branch information
Showing
14 changed files
with
449 additions
and
268 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package net.jeqo.bloons.commands; | ||
|
||
import net.jeqo.bloons.Bloons; | ||
import net.jeqo.bloons.commands.manager.Command; | ||
import net.jeqo.bloons.commands.manager.enums.CommandPermission; | ||
import net.jeqo.bloons.data.BalloonOwner; | ||
import net.jeqo.bloons.utils.Utils; | ||
import org.bukkit.Sound; | ||
import org.bukkit.command.CommandSender; | ||
import org.bukkit.entity.Player; | ||
import org.bukkit.plugin.java.JavaPlugin; | ||
|
||
import static net.jeqo.bloons.commands.utils.ErrorHandling.usage; | ||
|
||
public class CommandEquip extends Command { | ||
|
||
public CommandEquip(JavaPlugin plugin) { | ||
super(plugin); | ||
this.addCommandAlias("equip"); | ||
this.setCommandDescription("Equips a balloon to you"); | ||
this.setCommandSyntax("/bloons equip <balloon>"); | ||
this.setRequiredPermission(CommandPermission.EQUIP); | ||
} | ||
|
||
@Override | ||
public boolean execute(CommandSender sender, String[] args) { | ||
if (args.length < 1) { | ||
usage(sender); | ||
} | ||
|
||
Player player = (Player) sender; | ||
String str1 = args[0]; | ||
|
||
if (!plugin.getConfig().contains("balloons." + str1)) { | ||
player.sendMessage(Bloons.getMessage("prefix") + Bloons.getMessage("balloon-not-found")); | ||
return false; | ||
} | ||
|
||
if (!player.hasPermission(plugin.getConfig().getString("balloons." + str1 + ".permission", "balloons." + str1))) { | ||
player.sendMessage(Bloons.getMessage("prefix") + Bloons.getMessage("no-permission")); | ||
return false; | ||
} | ||
|
||
Utils.removeBalloon(player, Bloons.playerBalloons.get(player.getUniqueId())); | ||
BalloonOwner.checkBalloonRemovalOrAdd(player, str1); | ||
player.playSound(player.getLocation(), Sound.ENTITY_CHICKEN_EGG, 1, 1); | ||
String balloonName = Bloons.getString("balloons." + str1 + ".name"); | ||
player.sendMessage(Bloons.getMessage("prefix") + Bloons.getMessage("equipped", balloonName)); | ||
return false; | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
src/main/java/net/jeqo/bloons/commands/CommandForceEquip.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package net.jeqo.bloons.commands; | ||
|
||
import net.jeqo.bloons.Bloons; | ||
import net.jeqo.bloons.commands.manager.Command; | ||
import net.jeqo.bloons.commands.manager.enums.CommandPermission; | ||
import net.jeqo.bloons.data.BalloonOwner; | ||
import org.bukkit.Bukkit; | ||
import org.bukkit.command.CommandSender; | ||
import org.bukkit.entity.Player; | ||
import org.bukkit.plugin.java.JavaPlugin; | ||
|
||
import static net.jeqo.bloons.commands.utils.ErrorHandling.usage; | ||
|
||
public class CommandForceEquip extends Command { | ||
|
||
public CommandForceEquip(JavaPlugin plugin) { | ||
super(plugin); | ||
this.addCommandAlias("fequip"); | ||
this.setCommandDescription("Force equips a balloon to you"); | ||
this.setCommandSyntax("/bloons fequip <player> <balloon>"); | ||
this.setRequiredPermission(CommandPermission.FORCE); | ||
} | ||
|
||
@Override | ||
public boolean execute(CommandSender sender, String[] args) { | ||
if (args.length < 1) { | ||
usage(sender); | ||
System.out.println("args.length < 1"); | ||
} | ||
|
||
Player player = Bukkit.getPlayer(args[0]); | ||
|
||
if (player == null) { | ||
sender.sendMessage(Bloons.getMessage("prefix") + Bloons.getMessage("player-not-found")); | ||
return false; | ||
} | ||
String balloonId = args[1]; | ||
if (!plugin.getConfig().contains("balloons." + balloonId)) { | ||
sender.sendMessage(Bloons.getMessage("prefix") + Bloons.getMessage("balloon-not-found")); | ||
return false; | ||
} | ||
|
||
BalloonOwner.checkBalloonRemovalOrAdd(player.getPlayer(), balloonId); | ||
String balloonName2 = Bloons.getString("balloons." + balloonId + ".name"); | ||
player.sendMessage(Bloons.getMessage("prefix") + Bloons.getMessage("equipped", balloonName2)); | ||
return false; | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
src/main/java/net/jeqo/bloons/commands/CommandForceUnequip.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package net.jeqo.bloons.commands; | ||
|
||
import net.jeqo.bloons.Bloons; | ||
import net.jeqo.bloons.commands.manager.Command; | ||
import net.jeqo.bloons.commands.manager.enums.CommandPermission; | ||
import net.jeqo.bloons.data.BalloonOwner; | ||
import net.jeqo.bloons.utils.Utils; | ||
import org.bukkit.Bukkit; | ||
import org.bukkit.Sound; | ||
import org.bukkit.command.CommandSender; | ||
import org.bukkit.entity.Player; | ||
import org.bukkit.plugin.java.JavaPlugin; | ||
|
||
public class CommandForceUnequip extends Command { | ||
|
||
public CommandForceUnequip(JavaPlugin plugin) { | ||
super(plugin); | ||
this.addCommandAlias("funequip"); | ||
this.setCommandDescription("Force unequips a balloon that you have equipped"); | ||
this.setCommandSyntax("/bloons funequip <player>"); | ||
this.setRequiredPermission(CommandPermission.FORCE); | ||
} | ||
|
||
@Override | ||
public boolean execute(CommandSender sender, String[] args) { | ||
Player player = Bukkit.getPlayer(args[0]); | ||
if (player == null) { | ||
sender.sendMessage(Bloons.getMessage("prefix") + Bloons.getMessage("player-not-found")); | ||
return false; | ||
} | ||
|
||
BalloonOwner owner = Bloons.playerBalloons.get(player.getUniqueId()); | ||
if (owner == null) { | ||
player.playSound(player.getLocation(), Sound.BLOCK_NOTE_BLOCK_DIDGERIDOO, 1, 1); | ||
sender.sendMessage(Bloons.getMessage("prefix") + Bloons.getMessage("not-equipped")); | ||
return false; | ||
} | ||
Utils.removeBalloon(player, owner); | ||
sender.sendMessage(Bloons.getMessage("prefix") + Bloons.getMessage("unequipped")); | ||
return false; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package net.jeqo.bloons.commands; | ||
|
||
import net.jeqo.bloons.Bloons; | ||
import net.jeqo.bloons.commands.manager.Command; | ||
import net.jeqo.bloons.commands.manager.enums.CommandPermission; | ||
import org.bukkit.command.CommandSender; | ||
import org.bukkit.plugin.java.JavaPlugin; | ||
|
||
public class CommandReload extends Command { | ||
|
||
public CommandReload(JavaPlugin plugin) { | ||
super(plugin); | ||
this.addCommandAlias("reload"); | ||
this.addCommandAlias("rl"); | ||
this.setCommandDescription("Reloads the bloons config"); | ||
this.setCommandSyntax("/bloons reload"); | ||
this.setRequiredPermission(CommandPermission.RELOAD); | ||
} | ||
|
||
@Override | ||
public boolean execute(CommandSender sender, String[] args) { | ||
Bloons.getInstance().reloadConfig(); | ||
sender.sendMessage(Bloons.getMessage("prefix") + Bloons.getMessage("config-reloaded")); | ||
return false; | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
src/main/java/net/jeqo/bloons/commands/CommandUnequip.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package net.jeqo.bloons.commands; | ||
|
||
import net.jeqo.bloons.Bloons; | ||
import net.jeqo.bloons.commands.manager.Command; | ||
import net.jeqo.bloons.commands.manager.enums.CommandPermission; | ||
import net.jeqo.bloons.data.BalloonOwner; | ||
import net.jeqo.bloons.utils.Utils; | ||
import org.bukkit.Sound; | ||
import org.bukkit.command.CommandSender; | ||
import org.bukkit.entity.Player; | ||
import org.bukkit.plugin.java.JavaPlugin; | ||
|
||
public class CommandUnequip extends Command { | ||
|
||
public CommandUnequip(JavaPlugin plugin) { | ||
super(plugin); | ||
this.addCommandAlias("equip"); | ||
this.setCommandDescription("Equips a balloon to you"); | ||
this.setCommandSyntax("/bloons unequip <balloon>"); | ||
this.setRequiredPermission(CommandPermission.UNEQUIP); | ||
} | ||
|
||
@Override | ||
public boolean execute(CommandSender sender, String[] args) { | ||
Player player = (Player) sender; | ||
BalloonOwner balloonOwner1 = Bloons.playerBalloons.get(player.getUniqueId()); | ||
if (balloonOwner1 == null) { | ||
player.playSound(player.getLocation(), Sound.BLOCK_NOTE_BLOCK_DIDGERIDOO, 1, 1); | ||
player.sendMessage(Bloons.getMessage("prefix") + Bloons.getMessage("not-equipped")); | ||
return false; | ||
} | ||
Utils.removeBalloon(player, balloonOwner1); | ||
player.sendMessage(Bloons.getMessage("prefix") + Bloons.getMessage("unequipped")); | ||
player.playSound(player.getLocation(), Sound.ENTITY_PLAYER_HURT_SWEET_BERRY_BUSH, 1, 1); | ||
return false; | ||
} | ||
} |
82 changes: 82 additions & 0 deletions
82
src/main/java/net/jeqo/bloons/commands/manager/Command.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
package net.jeqo.bloons.commands.manager; | ||
|
||
import lombok.Getter; | ||
import lombok.Setter; | ||
import net.jeqo.bloons.commands.manager.enums.CommandAccess; | ||
import net.jeqo.bloons.commands.manager.enums.CommandPermission; | ||
import org.bukkit.command.CommandSender; | ||
import org.bukkit.entity.Player; | ||
import org.bukkit.plugin.java.JavaPlugin; | ||
|
||
import java.util.ArrayList; | ||
|
||
public abstract class Command { | ||
|
||
protected JavaPlugin plugin; | ||
|
||
@Getter @Setter | ||
private CommandPermission requiredPermission; | ||
@Getter @Setter | ||
private CommandAccess requiredAccess = CommandAccess.ENABLED; | ||
@Getter @Setter | ||
private String commandSyntax; | ||
@Getter @Setter | ||
private String commandDescription; | ||
@Getter | ||
private final ArrayList<String> commandAliases = new ArrayList<>(); | ||
|
||
public Command(JavaPlugin providedPlugin) { | ||
plugin = providedPlugin; | ||
} | ||
|
||
/** | ||
* Adds alias commands to the current command | ||
* Note: All aliases added here must be added to the plugin.yml file | ||
* @param alias The alias to add to the command | ||
*/ | ||
public void addCommandAlias(String alias) { | ||
commandAliases.add(alias); | ||
} | ||
|
||
public abstract boolean execute(CommandSender sender, String[] args) throws Exception; | ||
|
||
/** | ||
* Checks if the command meets the requirements to be executed | ||
* @param s The sender of the command | ||
* @param perm The permission required to execute the command | ||
* @return Whether or not the command meets the requirements | ||
*/ | ||
public boolean hasRequirement(CommandSender s, CommandPermission perm) { | ||
switch (perm) { | ||
case EQUIP -> { | ||
if (s instanceof Player) { | ||
if (!s.hasPermission("bloons.equip")) { | ||
return false; | ||
} | ||
} | ||
} | ||
case UNEQUIP -> { | ||
if (s instanceof Player) { | ||
if (!s.hasPermission("bloons.unequip")) { | ||
return false; | ||
} | ||
} | ||
} | ||
case FORCE -> { | ||
if (s instanceof Player) { | ||
if (!s.hasPermission("bloons.force")) { | ||
return false; | ||
} | ||
} | ||
} | ||
case RELOAD -> { | ||
if (s instanceof Player) { | ||
if (!s.hasPermission("bloons.reload")) { | ||
return false; | ||
} | ||
} | ||
} | ||
} | ||
return true; | ||
} | ||
} |
Oops, something went wrong.