mirror of
https://github.com/Auxilor/EcoMobs.git
synced 2025-12-22 08:29:20 +00:00
Added /ebspawn
This commit is contained in:
@@ -11,6 +11,7 @@ import com.willfp.ecobosses.bosses.listeners.DeathListeners;
|
|||||||
import com.willfp.ecobosses.bosses.listeners.SpawnListeners;
|
import com.willfp.ecobosses.bosses.listeners.SpawnListeners;
|
||||||
import com.willfp.ecobosses.commands.CommandEbdrop;
|
import com.willfp.ecobosses.commands.CommandEbdrop;
|
||||||
import com.willfp.ecobosses.commands.CommandEbreload;
|
import com.willfp.ecobosses.commands.CommandEbreload;
|
||||||
|
import com.willfp.ecobosses.commands.CommandEbspawn;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
@@ -94,7 +95,8 @@ public class EcoBossesPlugin extends AbstractEcoPlugin {
|
|||||||
public List<AbstractCommand> getCommands() {
|
public List<AbstractCommand> getCommands() {
|
||||||
return Arrays.asList(
|
return Arrays.asList(
|
||||||
new CommandEbreload(this),
|
new CommandEbreload(this),
|
||||||
new CommandEbdrop(this)
|
new CommandEbdrop(this),
|
||||||
|
new CommandEbspawn(this)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,143 @@
|
|||||||
|
package com.willfp.ecobosses.commands;
|
||||||
|
|
||||||
|
import com.willfp.eco.util.command.AbstractCommand;
|
||||||
|
import com.willfp.eco.util.command.AbstractTabCompleter;
|
||||||
|
import com.willfp.ecobosses.EcoBossesPlugin;
|
||||||
|
import com.willfp.ecobosses.bosses.EcoBoss;
|
||||||
|
import com.willfp.ecobosses.bosses.EcoBosses;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.World;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class CommandEbspawn extends AbstractCommand {
|
||||||
|
/**
|
||||||
|
* Instantiate a new executor for /ebspawn.
|
||||||
|
*
|
||||||
|
* @param plugin The plugin to manage the execution for.
|
||||||
|
*/
|
||||||
|
public CommandEbspawn(@NotNull final EcoBossesPlugin plugin) {
|
||||||
|
super(plugin, "ebspawn", "ecobosses.ebspawn", false);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Nullable
|
||||||
|
public AbstractTabCompleter getTab() {
|
||||||
|
return new TabCompleterEbspawn(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onExecute(@NotNull final CommandSender sender,
|
||||||
|
@NotNull final List<String> args) {
|
||||||
|
if (args.isEmpty()) {
|
||||||
|
sender.sendMessage(this.getPlugin().getLangYml().getMessage("specify-boss"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
String bossName = args.get(0);
|
||||||
|
|
||||||
|
EcoBoss boss = EcoBosses.getByName(bossName.toLowerCase());
|
||||||
|
|
||||||
|
Location location = null;
|
||||||
|
|
||||||
|
if (sender instanceof Player) {
|
||||||
|
location = ((Player) sender).getLocation();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (args.size() >= 4) {
|
||||||
|
String xString = args.get(1);
|
||||||
|
String yString = args.get(2);
|
||||||
|
String zString = args.get(3);
|
||||||
|
|
||||||
|
double xPos;
|
||||||
|
double yPos;
|
||||||
|
double zPos;
|
||||||
|
|
||||||
|
if (xString.startsWith("~") && sender instanceof Player) {
|
||||||
|
String xDiff = xString.replace("~", "");
|
||||||
|
String yDiff = yString.replace("~", "");
|
||||||
|
String zDiff = zString.replace("~", "");
|
||||||
|
|
||||||
|
if (xDiff.isEmpty()) {
|
||||||
|
xPos = ((Player) sender).getLocation().getX();
|
||||||
|
} else {
|
||||||
|
try {
|
||||||
|
xPos = ((Player) sender).getLocation().getX() + Double.parseDouble(xDiff);
|
||||||
|
} catch (NumberFormatException e) {
|
||||||
|
xPos = ((Player) sender).getLocation().getX();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (yDiff.isEmpty()) {
|
||||||
|
yPos = ((Player) sender).getLocation().getY();
|
||||||
|
} else {
|
||||||
|
try {
|
||||||
|
yPos = ((Player) sender).getLocation().getY() + Double.parseDouble(yDiff);
|
||||||
|
} catch (NumberFormatException e) {
|
||||||
|
yPos = ((Player) sender).getLocation().getY();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (zDiff.isEmpty()) {
|
||||||
|
zPos = ((Player) sender).getLocation().getZ();
|
||||||
|
} else {
|
||||||
|
try {
|
||||||
|
zPos = ((Player) sender).getLocation().getZ() + Double.parseDouble(yDiff);
|
||||||
|
} catch (NumberFormatException e) {
|
||||||
|
zPos = ((Player) sender).getLocation().getZ();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
try {
|
||||||
|
xPos = Double.parseDouble(xString);
|
||||||
|
} catch (NumberFormatException e) {
|
||||||
|
sender.sendMessage(this.getPlugin().getLangYml().getMessage("invalid-location"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
yPos = Double.parseDouble(yString);
|
||||||
|
} catch (NumberFormatException e) {
|
||||||
|
sender.sendMessage(this.getPlugin().getLangYml().getMessage("invalid-location"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
zPos = Double.parseDouble(zString);
|
||||||
|
} catch (NumberFormatException e) {
|
||||||
|
sender.sendMessage(this.getPlugin().getLangYml().getMessage("invalid-location"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
location = new Location(null, xPos, yPos, zPos);
|
||||||
|
}
|
||||||
|
|
||||||
|
World world = null;
|
||||||
|
if (sender instanceof Player) {
|
||||||
|
world = ((Player) sender).getWorld();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (args.size() >= 5) {
|
||||||
|
world = Bukkit.getWorld(args.get(4));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (location == null) {
|
||||||
|
sender.sendMessage(this.getPlugin().getLangYml().getMessage("invalid-location"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
location.setWorld(world);
|
||||||
|
|
||||||
|
if (world == null) {
|
||||||
|
sender.sendMessage(this.getPlugin().getLangYml().getMessage("invalid-world"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
boss.spawn(location);
|
||||||
|
sender.sendMessage(this.getPlugin().getLangYml().getMessage("spawned"));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,105 @@
|
|||||||
|
package com.willfp.ecobosses.commands;
|
||||||
|
|
||||||
|
import com.willfp.eco.util.command.AbstractTabCompleter;
|
||||||
|
import com.willfp.eco.util.config.updating.annotations.ConfigUpdater;
|
||||||
|
import com.willfp.ecobosses.bosses.EcoBoss;
|
||||||
|
import com.willfp.ecobosses.bosses.EcoBosses;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.World;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.util.StringUtil;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
public class TabCompleterEbspawn extends AbstractTabCompleter {
|
||||||
|
/**
|
||||||
|
* The cached names.
|
||||||
|
*/
|
||||||
|
private static final List<String> BOSS_NAMES = new ArrayList<>();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The cached numbers.
|
||||||
|
*/
|
||||||
|
private static final List<String> TILDE = Arrays.asList(
|
||||||
|
"~"
|
||||||
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Instantiate a new tab-completer for /ebspawn.
|
||||||
|
*
|
||||||
|
* @param command Instance of /ebspawn.
|
||||||
|
*/
|
||||||
|
public TabCompleterEbspawn(@NotNull final CommandEbspawn command) {
|
||||||
|
super(command);
|
||||||
|
reload();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called on reload.
|
||||||
|
*/
|
||||||
|
@ConfigUpdater
|
||||||
|
public static void reload() {
|
||||||
|
BOSS_NAMES.clear();
|
||||||
|
BOSS_NAMES.addAll(EcoBosses.values().stream().map(EcoBoss::getName).collect(Collectors.toList()));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The execution of the tabcompleter.
|
||||||
|
*
|
||||||
|
* @param sender The sender of the command.
|
||||||
|
* @param args The arguments of the command.
|
||||||
|
* @return A list of tab-completions.
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public List<String> onTab(@NotNull final CommandSender sender,
|
||||||
|
@NotNull final List<String> args) {
|
||||||
|
List<String> completions = new ArrayList<>();
|
||||||
|
|
||||||
|
if (args.isEmpty()) {
|
||||||
|
// Currently, this case is not ever reached
|
||||||
|
return new ArrayList<>();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (args.size() == 1) {
|
||||||
|
StringUtil.copyPartialMatches(args.get(0), BOSS_NAMES, completions);
|
||||||
|
|
||||||
|
Collections.sort(completions);
|
||||||
|
return completions;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (args.size() == 2) {
|
||||||
|
StringUtil.copyPartialMatches(args.get(1), TILDE, completions);
|
||||||
|
|
||||||
|
Collections.sort(completions);
|
||||||
|
return completions;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (args.size() == 3) {
|
||||||
|
StringUtil.copyPartialMatches(args.get(2), TILDE, completions);
|
||||||
|
|
||||||
|
Collections.sort(completions);
|
||||||
|
return completions;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (args.size() == 4) {
|
||||||
|
StringUtil.copyPartialMatches(args.get(3), TILDE, completions);
|
||||||
|
|
||||||
|
Collections.sort(completions);
|
||||||
|
return completions;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (args.size() == 5) {
|
||||||
|
StringUtil.copyPartialMatches(args.get(4), Bukkit.getWorlds().stream().map(World::getName).collect(Collectors.toList()), completions);
|
||||||
|
|
||||||
|
Collections.sort(completions);
|
||||||
|
return completions;
|
||||||
|
}
|
||||||
|
|
||||||
|
return new ArrayList<>(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -3,4 +3,7 @@ messages:
|
|||||||
no-permission: "&cYou don't have permission to do this!"
|
no-permission: "&cYou don't have permission to do this!"
|
||||||
not-player: "&cThis command must be run by a player"
|
not-player: "&cThis command must be run by a player"
|
||||||
reloaded: "Reloaded!"
|
reloaded: "Reloaded!"
|
||||||
sent-drop: "Check console for the drop!"
|
sent-drop: "Check console for the drop!"
|
||||||
|
specify-boss: "&cYou must specify a valid boss!"
|
||||||
|
invalid-location: "&cInvalid location!"
|
||||||
|
spawned: "Spawned a boss!"
|
||||||
@@ -13,6 +13,9 @@ commands:
|
|||||||
ebdrop:
|
ebdrop:
|
||||||
description: Sends the held item to console to be added as a drop
|
description: Sends the held item to console to be added as a drop
|
||||||
permission: ecobosses.ebdrop
|
permission: ecobosses.ebdrop
|
||||||
|
ebspawn:
|
||||||
|
description: Spawns a boss
|
||||||
|
permission: ecobosses.ebspawn
|
||||||
|
|
||||||
permissions:
|
permissions:
|
||||||
ecobosses.*:
|
ecobosses.*:
|
||||||
@@ -21,6 +24,7 @@ permissions:
|
|||||||
children:
|
children:
|
||||||
ecobosses.reload: true
|
ecobosses.reload: true
|
||||||
ecobosses.ebdrop: true
|
ecobosses.ebdrop: true
|
||||||
|
ecobosses.ebspawn: true
|
||||||
|
|
||||||
ecobosses.reload:
|
ecobosses.reload:
|
||||||
description: Allows reloading the config
|
description: Allows reloading the config
|
||||||
@@ -28,4 +32,8 @@ permissions:
|
|||||||
|
|
||||||
ecobosses.ebdrop:
|
ecobosses.ebdrop:
|
||||||
description: Allows the use of /ebdrop
|
description: Allows the use of /ebdrop
|
||||||
|
default: op
|
||||||
|
|
||||||
|
ecobosses.ebspawn:
|
||||||
|
description: Allows the use of /ebspawn
|
||||||
default: op
|
default: op
|
||||||
Reference in New Issue
Block a user