9
0
mirror of https://github.com/Auxilor/EcoMobs.git synced 2025-12-20 15:39:31 +00:00

Updated eco

This commit is contained in:
Auxilor
2022-01-06 18:53:42 +00:00
parent c4a04ed048
commit ab23e19804
9 changed files with 213 additions and 216 deletions

View File

@@ -47,7 +47,7 @@ allprojects {
}
dependencies {
compileOnly 'com.willfp:eco:6.9.0'
compileOnly 'com.willfp:eco:6.17.1'
compileOnly 'org.jetbrains:annotations:19.0.0'

View File

@@ -500,15 +500,15 @@ public class EcoBoss extends PluginDependent<EcoPlugin> {
// Messages
this.spawnMessages = new ArrayList<>();
for (String string : this.getConfig().getStrings("broadcast.spawn")) {
for (String string : this.getConfig().getFormattedStrings("broadcast.spawn")) {
this.spawnMessages.add(StringUtils.format(string));
}
this.deathMessages = new ArrayList<>();
for (String string : this.getConfig().getStrings("broadcast.death")) {
for (String string : this.getConfig().getFormattedStrings("broadcast.death")) {
this.deathMessages.add(StringUtils.format(string));
}
this.despawnMessages = new ArrayList<>();
for (String string : this.getConfig().getStrings("broadcast.despawn")) {
for (String string : this.getConfig().getFormattedStrings("broadcast.despawn")) {
this.despawnMessages.add(StringUtils.format(string));
}

View File

@@ -1,10 +1,12 @@
package com.willfp.ecobosses.commands;
import com.willfp.eco.core.command.CommandHandler;
import com.willfp.eco.core.command.impl.PluginCommand;
import com.willfp.ecobosses.EcoBossesPlugin;
import org.bukkit.command.CommandSender;
import org.jetbrains.annotations.NotNull;
import java.util.List;
public class CommandEcobosses extends PluginCommand {
/**
* Instantiate a new executor for /ebdrop.
@@ -20,9 +22,8 @@ public class CommandEcobosses extends PluginCommand {
}
@Override
public CommandHandler getHandler() {
return (sender, args) -> {
sender.sendMessage(this.getPlugin().getLangYml().getMessage("invalid-command"));
};
public void onExecute(@NotNull final CommandSender sender,
@NotNull final List<String> args) {
sender.sendMessage(this.getPlugin().getLangYml().getMessage("invalid-command"));
}
}

View File

@@ -2,13 +2,12 @@ package com.willfp.ecobosses.commands;
import com.willfp.eco.core.EcoPlugin;
import com.willfp.eco.core.command.CommandHandler;
import com.willfp.eco.core.command.TabCompleteHandler;
import com.willfp.eco.core.command.impl.Subcommand;
import com.willfp.eco.core.config.updating.ConfigUpdater;
import com.willfp.ecobosses.bosses.EcoBoss;
import com.willfp.ecobosses.bosses.EcoBosses;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.util.StringUtil;
@@ -62,90 +61,88 @@ public class CommandGive extends Subcommand {
}
@Override
public CommandHandler getHandler() {
return (sender, args) -> {
if (args.isEmpty()) {
sender.sendMessage(this.getPlugin().getLangYml().getMessage("needs-player"));
return;
public void onExecute(@NotNull final CommandSender sender,
@NotNull final List<String> args) {
if (args.isEmpty()) {
sender.sendMessage(this.getPlugin().getLangYml().getMessage("needs-player"));
return;
}
if (args.size() == 1) {
sender.sendMessage(this.getPlugin().getLangYml().getMessage("needs-boss"));
return;
}
int amount = 1;
if (args.size() > 2) {
try {
amount = Integer.parseInt(args.get(2));
} catch (NumberFormatException ignored) {
// do nothing
}
}
if (args.size() == 1) {
sender.sendMessage(this.getPlugin().getLangYml().getMessage("needs-boss"));
return;
}
String recieverName = args.get(0);
Player reciever = Bukkit.getPlayer(recieverName);
int amount = 1;
if (reciever == null) {
sender.sendMessage(this.getPlugin().getLangYml().getMessage("invalid-player"));
return;
}
if (args.size() > 2) {
try {
amount = Integer.parseInt(args.get(2));
} catch (NumberFormatException ignored) {
// do nothing
}
}
String key = args.get(1);
String recieverName = args.get(0);
Player reciever = Bukkit.getPlayer(recieverName);
EcoBoss boss = EcoBosses.getByName(key);
if (reciever == null) {
sender.sendMessage(this.getPlugin().getLangYml().getMessage("invalid-player"));
return;
}
if (boss == null || boss.getSpawnEgg() == null) {
sender.sendMessage(this.getPlugin().getLangYml().getMessage("invalid-boss"));
return;
}
String key = args.get(1);
String message = this.getPlugin().getLangYml().getMessage("give-success");
message = message.replace("%boss%", boss.getName()).replace("%recipient%", reciever.getName());
sender.sendMessage(message);
EcoBoss boss = EcoBosses.getByName(key);
if (boss == null || boss.getSpawnEgg() == null) {
sender.sendMessage(this.getPlugin().getLangYml().getMessage("invalid-boss"));
return;
}
String message = this.getPlugin().getLangYml().getMessage("give-success");
message = message.replace("%boss%", boss.getName()).replace("%recipient%", reciever.getName());
sender.sendMessage(message);
ItemStack itemStack = boss.getSpawnEgg();
itemStack.setAmount(amount);
reciever.getInventory().addItem(itemStack);
};
ItemStack itemStack = boss.getSpawnEgg();
itemStack.setAmount(amount);
reciever.getInventory().addItem(itemStack);
}
@Override
public TabCompleteHandler getTabCompleter() {
return (sender, args) -> {
List<String> completions = new ArrayList<>();
public List<String> tabComplete(@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 BOSS_NAMES;
}
if (args.isEmpty()) {
// Currently, this case is not ever reached
return BOSS_NAMES;
}
if (args.size() == 1) {
StringUtil.copyPartialMatches(args.get(0), Bukkit.getOnlinePlayers().stream().map(Player::getName).collect(Collectors.toList()), completions);
return completions;
}
if (args.size() == 1) {
StringUtil.copyPartialMatches(args.get(0), Bukkit.getOnlinePlayers().stream().map(Player::getName).collect(Collectors.toList()), completions);
return completions;
}
if (args.size() == 2) {
StringUtil.copyPartialMatches(args.get(1), BOSS_NAMES, completions);
if (args.size() == 2) {
StringUtil.copyPartialMatches(args.get(1), BOSS_NAMES, completions);
Collections.sort(completions);
return completions;
}
Collections.sort(completions);
return completions;
}
if (args.size() == 3) {
StringUtil.copyPartialMatches(args.get(2), NUMBERS, completions);
if (args.size() == 3) {
StringUtil.copyPartialMatches(args.get(2), NUMBERS, completions);
completions.sort((s1, s2) -> {
int t1 = Integer.parseInt(s1);
int t2 = Integer.parseInt(s2);
return t1 - t2;
});
completions.sort((s1, s2) -> {
int t1 = Integer.parseInt(s1);
int t2 = Integer.parseInt(s2);
return t1 - t2;
});
return completions;
}
return completions;
}
return new ArrayList<>(0);
};
return new ArrayList<>(0);
}
}

View File

@@ -1,11 +1,13 @@
package com.willfp.ecobosses.commands;
import com.willfp.eco.core.command.CommandHandler;
import com.willfp.eco.core.command.impl.Subcommand;
import com.willfp.ecobosses.EcoBossesPlugin;
import com.willfp.ecobosses.bosses.util.BossUtils;
import org.bukkit.command.CommandSender;
import org.jetbrains.annotations.NotNull;
import java.util.List;
public class CommandKillall extends Subcommand {
/**
* Instantiate a new executor for /ebspawn.
@@ -17,14 +19,13 @@ public class CommandKillall extends Subcommand {
}
@Override
public CommandHandler getHandler() {
return (sender, args) -> {
boolean force = false;
if (args.size() == 1) {
force = args.get(0).equalsIgnoreCase("force");
}
public void onExecute(@NotNull final CommandSender sender,
@NotNull final List<String> args) {
boolean force = false;
if (args.size() == 1) {
force = args.get(0).equalsIgnoreCase("force");
}
sender.sendMessage(this.getPlugin().getLangYml().getMessage("killall").replace("%amount%", String.valueOf(BossUtils.killAllBosses(force))));
};
sender.sendMessage(this.getPlugin().getLangYml().getMessage("killall").replace("%amount%", String.valueOf(BossUtils.killAllBosses(force))));
}
}

View File

@@ -1,10 +1,12 @@
package com.willfp.ecobosses.commands;
import com.willfp.eco.core.command.CommandHandler;
import com.willfp.eco.core.command.impl.Subcommand;
import com.willfp.ecobosses.EcoBossesPlugin;
import org.bukkit.command.CommandSender;
import org.jetbrains.annotations.NotNull;
import java.util.List;
public class CommandReload extends Subcommand {
/**
* Instantiate a new executor for /ebreload.
@@ -16,11 +18,10 @@ public class CommandReload extends Subcommand {
}
@Override
public CommandHandler getHandler() {
return (sender, args) -> {
this.getPlugin().reload();
this.getPlugin().reload();
sender.sendMessage(this.getPlugin().getLangYml().getMessage("reloaded"));
};
public void onExecute(@NotNull final CommandSender sender,
@NotNull final List<String> args) {
this.getPlugin().reload();
this.getPlugin().reload();
sender.sendMessage(this.getPlugin().getLangYml().getMessage("reloaded"));
}
}

View File

@@ -1,7 +1,5 @@
package com.willfp.ecobosses.commands;
import com.willfp.eco.core.command.CommandHandler;
import com.willfp.eco.core.command.TabCompleteHandler;
import com.willfp.eco.core.command.impl.Subcommand;
import com.willfp.eco.core.config.updating.ConfigUpdater;
import com.willfp.ecobosses.EcoBossesPlugin;
@@ -10,6 +8,7 @@ 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.bukkit.util.StringUtil;
import org.jetbrains.annotations.NotNull;
@@ -53,158 +52,155 @@ public class CommandSpawn extends Subcommand {
}
@Override
public CommandHandler getHandler() {
return (sender, args) -> {
if (args.isEmpty()) {
sender.sendMessage(this.getPlugin().getLangYml().getMessage("specify-boss"));
return;
}
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);
String bossName = args.get(0);
EcoBoss boss = EcoBosses.getByName(bossName.toLowerCase());
EcoBoss boss = EcoBosses.getByName(bossName.toLowerCase());
if (boss == null) {
sender.sendMessage(this.getPlugin().getLangYml().getMessage("specify-boss"));
return;
}
if (boss == null) {
sender.sendMessage(this.getPlugin().getLangYml().getMessage("specify-boss"));
return;
}
Location location = null;
Location location = null;
if (sender instanceof Player) {
location = ((Player) sender).getLocation();
}
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);
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;
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 (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();
}
}
if (xDiff.isEmpty()) {
xPos = ((Player) sender).getLocation().getX();
} else {
try {
xPos = Double.parseDouble(xString);
yPos = Double.parseDouble(yString);
zPos = Double.parseDouble(zString);
xPos = ((Player) sender).getLocation().getX() + Double.parseDouble(xDiff);
} catch (NumberFormatException e) {
sender.sendMessage(this.getPlugin().getLangYml().getMessage("invalid-location"));
return;
xPos = ((Player) sender).getLocation().getX();
}
}
location = new Location(null, xPos, yPos, zPos);
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);
yPos = Double.parseDouble(yString);
zPos = Double.parseDouble(zString);
} catch (NumberFormatException e) {
sender.sendMessage(this.getPlugin().getLangYml().getMessage("invalid-location"));
return;
}
}
World world = null;
if (sender instanceof Player) {
world = ((Player) sender).getWorld();
}
location = new Location(null, xPos, yPos, zPos);
}
if (args.size() >= 5) {
world = Bukkit.getWorld(args.get(4));
}
World world = null;
if (sender instanceof Player) {
world = ((Player) sender).getWorld();
}
if (location == null) {
sender.sendMessage(this.getPlugin().getLangYml().getMessage("invalid-location"));
return;
}
if (args.size() >= 5) {
world = Bukkit.getWorld(args.get(4));
}
location.setWorld(world);
if (location == null) {
sender.sendMessage(this.getPlugin().getLangYml().getMessage("invalid-location"));
return;
}
if (world == null) {
sender.sendMessage(this.getPlugin().getLangYml().getMessage("invalid-world"));
return;
}
location.setWorld(world);
boss.spawn(location);
sender.sendMessage(this.getPlugin().getLangYml().getMessage("spawned"));
};
if (world == null) {
sender.sendMessage(this.getPlugin().getLangYml().getMessage("invalid-world"));
return;
}
boss.spawn(location);
sender.sendMessage(this.getPlugin().getLangYml().getMessage("spawned"));
}
@Override
public TabCompleteHandler getTabCompleter() {
return (sender, args) -> {
public List<String> tabComplete(@NotNull final CommandSender sender,
@NotNull final List<String> args) {
List<String> completions = new ArrayList<>();
List<String> completions = new ArrayList<>();
if (args.isEmpty()) {
// Currently, this case is not ever reached
return 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);
if (args.size() == 1) {
StringUtil.copyPartialMatches(args.get(0), BOSS_NAMES, completions);
Collections.sort(completions);
return completions;
}
Collections.sort(completions);
return completions;
}
if (args.size() == 2) {
StringUtil.copyPartialMatches(args.get(1), TILDE, completions);
if (args.size() == 2) {
StringUtil.copyPartialMatches(args.get(1), TILDE, completions);
Collections.sort(completions);
return completions;
}
Collections.sort(completions);
return completions;
}
if (args.size() == 3) {
StringUtil.copyPartialMatches(args.get(2), TILDE, completions);
if (args.size() == 3) {
StringUtil.copyPartialMatches(args.get(2), TILDE, completions);
Collections.sort(completions);
return completions;
}
Collections.sort(completions);
return completions;
}
if (args.size() == 4) {
StringUtil.copyPartialMatches(args.get(3), TILDE, completions);
if (args.size() == 4) {
StringUtil.copyPartialMatches(args.get(3), TILDE, completions);
Collections.sort(completions);
return 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);
if (args.size() == 5) {
StringUtil.copyPartialMatches(args.get(4), Bukkit.getWorlds().stream().map(World::getName).collect(Collectors.toList()), completions);
Collections.sort(completions);
return completions;
}
Collections.sort(completions);
return completions;
}
return new ArrayList<>(0);
};
return new ArrayList<>(0);
}
}

View File

@@ -1,16 +1,17 @@
package com.willfp.ecobosses.config;
import com.willfp.eco.core.config.yaml.YamlExtendableConfig;
import com.willfp.eco.core.config.ConfigType;
import com.willfp.eco.core.config.ExtendableConfig;
import com.willfp.ecobosses.EcoBossesPlugin;
import org.jetbrains.annotations.NotNull;
public class BaseBossConfig extends YamlExtendableConfig {
public class BaseBossConfig extends ExtendableConfig {
/**
* Create new EcoBoss config.
*
* @param configName The name of the config.
*/
public BaseBossConfig(@NotNull final String configName) {
super(configName, true, EcoBossesPlugin.getInstance(), EcoBossesPlugin.class, "bosses/");
super(configName, true, EcoBossesPlugin.getInstance(), EcoBossesPlugin.class, "bosses/", ConfigType.YAML);
}
}

View File

@@ -1,11 +1,11 @@
package com.willfp.ecobosses.config;
import com.willfp.eco.core.config.yaml.YamlTransientConfig;
import com.willfp.eco.core.config.TransientConfig;
import lombok.Getter;
import org.bukkit.configuration.file.YamlConfiguration;
import org.jetbrains.annotations.NotNull;
public class CustomConfig extends YamlTransientConfig {
public class CustomConfig extends TransientConfig {
/**
* The name of the config.
*/