Skip to content

Commit

Permalink
Start Warp Editing Commands
Browse files Browse the repository at this point in the history
Took 15 minutes
  • Loading branch information
Oribuin committed Feb 28, 2024
1 parent 8b264c4 commit 754ba15
Show file tree
Hide file tree
Showing 14 changed files with 484 additions and 7 deletions.
16 changes: 15 additions & 1 deletion src/main/java/xyz/oribuin/playerwarps/command/BaseCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,16 @@
import org.bukkit.entity.Player;
import xyz.oribuin.playerwarps.command.defaults.WarpHelpCommand;
import xyz.oribuin.playerwarps.command.defaults.WarpReloadCommand;
import xyz.oribuin.playerwarps.command.impl.BanCommand;
import xyz.oribuin.playerwarps.command.impl.CreateCommand;
import xyz.oribuin.playerwarps.command.impl.DeleteCommand;
import xyz.oribuin.playerwarps.command.impl.DescCommand;
import xyz.oribuin.playerwarps.command.impl.IconCommand;
import xyz.oribuin.playerwarps.command.impl.NameCommand;
import xyz.oribuin.playerwarps.command.impl.OwnerCommand;
import xyz.oribuin.playerwarps.command.impl.PositionCommand;
import xyz.oribuin.playerwarps.command.impl.TeleportCommand;
import xyz.oribuin.playerwarps.command.impl.UnbanCommand;
import xyz.oribuin.playerwarps.gui.MenuProvider;
import xyz.oribuin.playerwarps.gui.menu.WarpsMenu;

Expand Down Expand Up @@ -43,9 +50,16 @@ protected ArgumentsDefinition createArgumentsDefinition() {
new WarpReloadCommand(this.rosePlugin),

// Plugin Commands
new BanCommand(this.rosePlugin),
new CreateCommand(this.rosePlugin),
new DeleteCommand(this.rosePlugin),
new TeleportCommand(this.rosePlugin)
new DescCommand(this.rosePlugin),
new IconCommand(this.rosePlugin),
new NameCommand(this.rosePlugin),
new OwnerCommand(this.rosePlugin),
new PositionCommand(this.rosePlugin),
new TeleportCommand(this.rosePlugin),
new UnbanCommand(this.rosePlugin)
);
}

Expand Down
65 changes: 65 additions & 0 deletions src/main/java/xyz/oribuin/playerwarps/command/impl/BanCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package xyz.oribuin.playerwarps.command.impl;

import dev.rosewood.rosegarden.RosePlugin;
import dev.rosewood.rosegarden.command.argument.ArgumentHandlers;
import dev.rosewood.rosegarden.command.framework.ArgumentsDefinition;
import dev.rosewood.rosegarden.command.framework.BaseRoseCommand;
import dev.rosewood.rosegarden.command.framework.CommandContext;
import dev.rosewood.rosegarden.command.framework.CommandInfo;
import dev.rosewood.rosegarden.command.framework.annotation.RoseExecutable;
import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import xyz.oribuin.playerwarps.command.argument.WarpArgumentHandler;
import xyz.oribuin.playerwarps.manager.DataManager;
import xyz.oribuin.playerwarps.model.Warp;

public class BanCommand extends BaseRoseCommand {

public BanCommand(RosePlugin rosePlugin) {
super(rosePlugin);
}

@RoseExecutable
public void execute(CommandContext context) {
Player player = (Player) context.getSender();
Warp warp = context.get("warp");
OfflinePlayer target = context.get("target");

if (!warp.getOwner().equals(player.getUniqueId())) {
player.sendMessage("You don't own this warp");
return;
}

if (warp.isBanned(target)) {
player.sendMessage("Player is already banned from " + warp.getId());
return;
}

if (warp.getOwner().equals(target.getUniqueId())) {
player.sendMessage("You cannot ban the owner of " + warp.getId());
return;
}

warp.getBanned().add(target.getUniqueId());
warp.save();
player.sendMessage("Banned " + target.getName() + " from " + warp.getId());
}

@Override
protected CommandInfo createCommandInfo() {
return CommandInfo.builder("ban")
.descriptionKey("command-ban-description")
.permission("playerwarps.ban")
.build();
}

@Override
protected ArgumentsDefinition createArgumentsDefinition() {
return ArgumentsDefinition.builder()
.required("warp", new WarpArgumentHandler())
.required("target", ArgumentHandlers.OFFLINE_PLAYER)
.build();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@ public void execute(CommandContext context) {
// TODO: Check if the player has enough to make it

Warp warp = new Warp(name, player.getUniqueId(), player.getLocation());
manager.update(warp);

warp.save();
player.sendMessage("Warp created wahoo");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ public void execute(CommandContext context) {

DataManager manager = this.rosePlugin.getManager(DataManager.class);
manager.delete(warp.getId());

player.sendMessage("Warp deleted.");
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
package xyz.oribuin.playerwarps.command.impl;

import dev.rosewood.rosegarden.RosePlugin;
import dev.rosewood.rosegarden.command.argument.ArgumentHandlers;
import dev.rosewood.rosegarden.command.framework.ArgumentsDefinition;
import dev.rosewood.rosegarden.command.framework.BaseRoseCommand;
import dev.rosewood.rosegarden.command.framework.CommandContext;
import dev.rosewood.rosegarden.command.framework.CommandInfo;
import dev.rosewood.rosegarden.command.framework.annotation.RoseExecutable;
import org.bukkit.entity.Player;
import xyz.oribuin.playerwarps.command.argument.WarpArgumentHandler;
import xyz.oribuin.playerwarps.manager.ConfigurationManager.Setting;
import xyz.oribuin.playerwarps.manager.DataManager;
import xyz.oribuin.playerwarps.model.Warp;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.regex.Pattern;
import java.util.stream.Collectors;

public class DescCommand extends BaseRoseCommand {

public DescCommand(RosePlugin rosePlugin) {
super(rosePlugin);
}

@RoseExecutable
public void execute(CommandContext context) {
Player player = (Player) context.getSender();
Warp warp = context.get("warp");
String desc = context.get("desc");

if (!warp.getOwner().equals(player.getUniqueId())) {
player.sendMessage("You don't own this warp");
return;
}

if (desc == null) {
warp.setDescription(new ArrayList<>());
warp.save();
player.sendMessage("Removed description for " + warp.getId());
return;
}

if (this.getPatterns().stream().anyMatch(p -> p.matcher(desc).matches())) {
player.sendMessage("Invalid name");
return;
}

warp.setDescription(Arrays.stream(desc.split("\n")).toList());
warp.save();
player.sendMessage("Set description for " + warp.getId());
}

public List<Pattern> getPatterns() {
return Setting.WARP_DESC_FILTERS.getStringList().stream()
.map(Pattern::compile)
.collect(Collectors.toList());
}

@Override
protected CommandInfo createCommandInfo() {
return CommandInfo.builder("desc")
.descriptionKey("command-desc-description")
.permission("playerwarps.desc")
.build();
}

@Override
protected ArgumentsDefinition createArgumentsDefinition() {
return ArgumentsDefinition.builder()
.required("warp", new WarpArgumentHandler())
.optional("desc", ArgumentHandlers.GREEDY_STRING)
.build();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package xyz.oribuin.playerwarps.command.impl;

import dev.rosewood.rosegarden.RosePlugin;
import dev.rosewood.rosegarden.command.framework.ArgumentsDefinition;
import dev.rosewood.rosegarden.command.framework.BaseRoseCommand;
import dev.rosewood.rosegarden.command.framework.CommandContext;
import dev.rosewood.rosegarden.command.framework.CommandInfo;
import dev.rosewood.rosegarden.command.framework.annotation.RoseExecutable;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import xyz.oribuin.playerwarps.command.argument.WarpArgumentHandler;
import xyz.oribuin.playerwarps.manager.DataManager;
import xyz.oribuin.playerwarps.model.Warp;

public class IconCommand extends BaseRoseCommand {

public IconCommand(RosePlugin rosePlugin) {
super(rosePlugin);
}

@RoseExecutable
public void execute(CommandContext context) {
Player player = (Player) context.getSender();
Warp warp = context.get("warp");

if (!warp.getOwner().equals(player.getUniqueId())) {
player.sendMessage("You don't own this warp");
return;
}

ItemStack handIcon = player.getInventory().getItemInMainHand();
if (handIcon.getType().isAir()) {
warp.setIcon(null);
warp.save();
player.sendMessage("removed icon from " + warp.getId());
return;
}

warp.setIcon(handIcon);
warp.save();
player.sendMessage("set icon for " + warp.getId());
}

@Override
protected CommandInfo createCommandInfo() {
return CommandInfo.builder("icon")
.descriptionKey("command-icon-description")
.permission("playerwarps.icon")
.build();
}

@Override
protected ArgumentsDefinition createArgumentsDefinition() {
return ArgumentsDefinition.builder()
.required("warp", new WarpArgumentHandler())
.build();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package xyz.oribuin.playerwarps.command.impl;

import dev.rosewood.rosegarden.RosePlugin;
import dev.rosewood.rosegarden.command.argument.ArgumentHandlers;
import dev.rosewood.rosegarden.command.framework.ArgumentsDefinition;
import dev.rosewood.rosegarden.command.framework.BaseRoseCommand;
import dev.rosewood.rosegarden.command.framework.CommandContext;
import dev.rosewood.rosegarden.command.framework.CommandInfo;
import dev.rosewood.rosegarden.command.framework.annotation.RoseExecutable;
import org.bukkit.entity.Player;
import xyz.oribuin.playerwarps.command.argument.WarpArgumentHandler;
import xyz.oribuin.playerwarps.manager.ConfigurationManager.Setting;
import xyz.oribuin.playerwarps.manager.DataManager;
import xyz.oribuin.playerwarps.model.Warp;

import java.util.List;
import java.util.regex.Pattern;
import java.util.stream.Collectors;

public class NameCommand extends BaseRoseCommand {

public NameCommand(RosePlugin rosePlugin) {
super(rosePlugin);
}

@RoseExecutable
public void execute(CommandContext context) {
Player player = (Player) context.getSender();
Warp warp = context.get("warp");
String name = context.get("name");

if (!warp.getOwner().equals(player.getUniqueId())) {
player.sendMessage("You don't own this warp");
return;
}

if (this.getPatterns().stream().anyMatch(p -> p.matcher(name).matches())) {
player.sendMessage("Invalid name");
return;
}

warp.setDisplayName(name);
warp.save();
player.sendMessage("Set name for " + warp.getId());
}

public List<Pattern> getPatterns() {
return Setting.WARP_NAME_FILTERS.getStringList().stream()
.map(Pattern::compile)
.collect(Collectors.toList());
}

@Override
protected CommandInfo createCommandInfo() {
return CommandInfo.builder("name")
.descriptionKey("command-name-description")
.permission("playerwarps.name")
.build();
}

@Override
protected ArgumentsDefinition createArgumentsDefinition() {
return ArgumentsDefinition.builder()
.required("warp", new WarpArgumentHandler())
.required("name", ArgumentHandlers.GREEDY_STRING)
.build();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package xyz.oribuin.playerwarps.command.impl;

import dev.rosewood.rosegarden.RosePlugin;
import dev.rosewood.rosegarden.command.argument.ArgumentHandlers;
import dev.rosewood.rosegarden.command.framework.ArgumentsDefinition;
import dev.rosewood.rosegarden.command.framework.BaseRoseCommand;
import dev.rosewood.rosegarden.command.framework.CommandContext;
import dev.rosewood.rosegarden.command.framework.CommandInfo;
import dev.rosewood.rosegarden.command.framework.annotation.RoseExecutable;
import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Player;
import xyz.oribuin.playerwarps.command.argument.WarpArgumentHandler;
import xyz.oribuin.playerwarps.manager.DataManager;
import xyz.oribuin.playerwarps.model.Warp;

public class OwnerCommand extends BaseRoseCommand {

public OwnerCommand(RosePlugin rosePlugin) {
super(rosePlugin);
}

@RoseExecutable
public void execute(CommandContext context) {
Player player = (Player) context.getSender();
Warp warp = context.get("warp");
OfflinePlayer target = context.get("target");

if (!warp.getOwner().equals(player.getUniqueId())) {
player.sendMessage("You don't own this warp");
return;
}

// TODO: ARE YOU SURE????????????????????????
warp.setOwner(target.getUniqueId());
warp.setOwnerName(target.getName());
warp.save();
player.sendMessage("Set owner of " + warp.getId() + " to " + target.getName());
}

@Override
protected CommandInfo createCommandInfo() {
return CommandInfo.builder("owner")
.descriptionKey("command-owner-description")
.permission("playerwarps.owner")
.build();
}

@Override
protected ArgumentsDefinition createArgumentsDefinition() {
return ArgumentsDefinition.builder()
.required("warp", new WarpArgumentHandler())
.required("target", ArgumentHandlers.OFFLINE_PLAYER)
.build();
}

}
Loading

0 comments on commit 754ba15

Please sign in to comment.