forked from Upstream/mmocore
improved exp and level commands
This commit is contained in:
parent
ac84e94697
commit
376d475686
@ -12,13 +12,13 @@ public class Parameter {
|
||||
// private final ParameterType type;ParameterType type,
|
||||
private final Consumer<List<String>> autoComplete;
|
||||
|
||||
public static final Parameter PROFESSION = new Parameter("<profession/main>", (list) -> {
|
||||
public static final Parameter PROFESSION = new Parameter("<profession/main>", list -> {
|
||||
MMOCore.plugin.professionManager.getAll().forEach(profession -> list.add(profession.getId()));
|
||||
list.add("main");
|
||||
});
|
||||
public static final Parameter PLAYER = new Parameter("<player>", (list) -> Bukkit.getOnlinePlayers().forEach(online -> list.add(online.getName())));
|
||||
public static final Parameter PLAYER_OPTIONAL = new Parameter("(player)", (list) -> Bukkit.getOnlinePlayers().forEach(online -> list.add(online.getName())));
|
||||
public static final Parameter AMOUNT = new Parameter("<amount>", (list) -> {
|
||||
public static final Parameter PLAYER = new Parameter("<player>", list -> Bukkit.getOnlinePlayers().forEach(online -> list.add(online.getName())));
|
||||
public static final Parameter PLAYER_OPTIONAL = new Parameter("(player)", list -> Bukkit.getOnlinePlayers().forEach(online -> list.add(online.getName())));
|
||||
public static final Parameter AMOUNT = new Parameter("<amount>", list -> {
|
||||
for (int j = 0; j <= 10; j++)
|
||||
list.add("" + j);
|
||||
});
|
||||
|
@ -1,5 +1,7 @@
|
||||
package net.Indyuce.mmocore.command.rpg.admin;
|
||||
|
||||
import java.util.function.BiConsumer;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
@ -8,6 +10,7 @@ import org.bukkit.entity.Player;
|
||||
import net.Indyuce.mmocore.MMOCore;
|
||||
import net.Indyuce.mmocore.api.experience.Profession;
|
||||
import net.Indyuce.mmocore.api.player.PlayerData;
|
||||
import net.Indyuce.mmocore.api.player.Professions;
|
||||
import net.Indyuce.mmocore.command.api.CommandEnd;
|
||||
import net.Indyuce.mmocore.command.api.CommandMap;
|
||||
import net.Indyuce.mmocore.command.api.Parameter;
|
||||
@ -16,6 +19,20 @@ public class ExperienceCommandMap extends CommandEnd {
|
||||
public ExperienceCommandMap(CommandMap parent) {
|
||||
super(parent, "exp");
|
||||
|
||||
addFloor(new ActionCommandMap(this, "set", (data, value) -> data.setExperience(value), (professions, profession, value) -> professions.setExperience(profession, value)));
|
||||
addFloor(new ActionCommandMap(this, "give", (data, value) -> data.giveExperience(value), (professions, profession, value) -> professions.giveExperience(profession, value)));
|
||||
}
|
||||
|
||||
public class ActionCommandMap extends CommandEnd {
|
||||
private final BiConsumer<PlayerData, Integer> main;
|
||||
private final TriConsumer<Professions, Profession, Integer> profession;
|
||||
|
||||
public ActionCommandMap(CommandMap parent, String type, BiConsumer<PlayerData, Integer> main, TriConsumer<Professions, Profession, Integer> profession) {
|
||||
super(parent, type);
|
||||
|
||||
this.main = main;
|
||||
this.profession = profession;
|
||||
|
||||
addParameter(Parameter.PLAYER);
|
||||
addParameter(Parameter.PROFESSION);
|
||||
addParameter(Parameter.AMOUNT);
|
||||
@ -23,40 +40,50 @@ public class ExperienceCommandMap extends CommandEnd {
|
||||
|
||||
@Override
|
||||
public CommandResult execute(CommandSender sender, String[] args) {
|
||||
if (args.length < 5)
|
||||
if (args.length < 6)
|
||||
return CommandResult.THROW_USAGE;
|
||||
|
||||
Player player = Bukkit.getPlayer(args[2]);
|
||||
Player player = Bukkit.getPlayer(args[3]);
|
||||
if (player == null) {
|
||||
sender.sendMessage(ChatColor.RED + "Could not find the player called " + args[2] + ".");
|
||||
sender.sendMessage(ChatColor.RED + "Could not find the player called " + args[3] + ".");
|
||||
return CommandResult.FAILURE;
|
||||
}
|
||||
|
||||
int amount;
|
||||
int amount = 0;
|
||||
try {
|
||||
amount = Integer.parseInt(args[4]);
|
||||
} catch (Exception e) {
|
||||
sender.sendMessage(ChatColor.RED + args[4] + " is not a valid number.");
|
||||
amount = Integer.parseInt(args[5]);
|
||||
} catch (NumberFormatException exception) {
|
||||
sender.sendMessage(ChatColor.RED + args[5] + " is not a valid number.");
|
||||
return CommandResult.FAILURE;
|
||||
}
|
||||
|
||||
if (args[3].equalsIgnoreCase("main")) {
|
||||
PlayerData data = PlayerData.get(player);
|
||||
data.giveExperience(amount);
|
||||
if (args[4].equalsIgnoreCase("main")) {
|
||||
main.accept(data, amount);
|
||||
sender.sendMessage(ChatColor.GOLD + player.getName() + ChatColor.YELLOW + " now has " + ChatColor.GOLD + data.getExperience() + ChatColor.YELLOW + " EXP.");
|
||||
return CommandResult.SUCCESS;
|
||||
}
|
||||
|
||||
String format = args[3].toLowerCase().replace("_", "-");
|
||||
String format = args[4].toLowerCase().replace("_", "-");
|
||||
if (!MMOCore.plugin.professionManager.has(format)) {
|
||||
sender.sendMessage(ChatColor.RED + format + " is not a valid profession.");
|
||||
return CommandResult.FAILURE;
|
||||
}
|
||||
|
||||
Profession profession = MMOCore.plugin.professionManager.get(format);
|
||||
PlayerData data = PlayerData.get(player);
|
||||
data.getCollectionSkills().giveExperience(profession, amount);
|
||||
this.profession.accept(data.getCollectionSkills(), profession, amount);
|
||||
sender.sendMessage(ChatColor.GOLD + player.getName() + ChatColor.YELLOW + " now has " + ChatColor.GOLD + data.getCollectionSkills().getExperience(profession) + ChatColor.YELLOW + " EXP in " + profession.getName() + ".");
|
||||
return CommandResult.SUCCESS;
|
||||
}
|
||||
}
|
||||
|
||||
@FunctionalInterface
|
||||
interface TriConsumer<A, B, C> {
|
||||
void accept(A a, B b, C c);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandResult execute(CommandSender sender, String[] args) {
|
||||
return CommandResult.THROW_USAGE;
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,7 @@
|
||||
package net.Indyuce.mmocore.command.rpg.admin;
|
||||
|
||||
import java.util.function.BiConsumer;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
@ -8,14 +10,29 @@ import org.bukkit.entity.Player;
|
||||
import net.Indyuce.mmocore.MMOCore;
|
||||
import net.Indyuce.mmocore.api.experience.Profession;
|
||||
import net.Indyuce.mmocore.api.player.PlayerData;
|
||||
import net.Indyuce.mmocore.api.player.Professions;
|
||||
import net.Indyuce.mmocore.command.api.CommandEnd;
|
||||
import net.Indyuce.mmocore.command.api.CommandMap;
|
||||
import net.Indyuce.mmocore.command.api.Parameter;
|
||||
|
||||
public class LevelCommandMap extends CommandEnd {
|
||||
public class LevelCommandMap extends CommandMap {
|
||||
public LevelCommandMap(CommandMap parent) {
|
||||
super(parent, "level");
|
||||
|
||||
addFloor(new ActionCommandMap(this, "set", (data, value) -> data.setLevel(value), (professions, profession, value) -> professions.setLevel(profession, value)));
|
||||
addFloor(new ActionCommandMap(this, "give", (data, value) -> data.giveLevels(value), (professions, profession, value) -> professions.giveLevels(profession, value)));
|
||||
}
|
||||
|
||||
public class ActionCommandMap extends CommandEnd {
|
||||
private final BiConsumer<PlayerData, Integer> main;
|
||||
private final TriConsumer<Professions, Profession, Integer> profession;
|
||||
|
||||
public ActionCommandMap(CommandMap parent, String type, BiConsumer<PlayerData, Integer> main, TriConsumer<Professions, Profession, Integer> profession) {
|
||||
super(parent, type);
|
||||
|
||||
this.main = main;
|
||||
this.profession = profession;
|
||||
|
||||
addParameter(Parameter.PLAYER);
|
||||
addParameter(Parameter.PROFESSION);
|
||||
addParameter(Parameter.AMOUNT);
|
||||
@ -23,46 +40,50 @@ public class LevelCommandMap extends CommandEnd {
|
||||
|
||||
@Override
|
||||
public CommandResult execute(CommandSender sender, String[] args) {
|
||||
if (args.length < 5)
|
||||
if (args.length < 6)
|
||||
return CommandResult.THROW_USAGE;
|
||||
|
||||
Player player = Bukkit.getPlayer(args[2]);
|
||||
Player player = Bukkit.getPlayer(args[3]);
|
||||
if (player == null) {
|
||||
sender.sendMessage(ChatColor.RED + "Could not find the player called " + args[2] + ".");
|
||||
sender.sendMessage(ChatColor.RED + "Could not find the player called " + args[3] + ".");
|
||||
return CommandResult.FAILURE;
|
||||
}
|
||||
|
||||
int amount = 0;
|
||||
try {
|
||||
amount = Integer.parseInt(args[4]);
|
||||
} catch (Exception e) {
|
||||
sender.sendMessage(ChatColor.RED + args[4] + " is not a valid number.");
|
||||
amount = Integer.parseInt(args[5]);
|
||||
} catch (NumberFormatException exception) {
|
||||
sender.sendMessage(ChatColor.RED + args[5] + " is not a valid number.");
|
||||
return CommandResult.FAILURE;
|
||||
}
|
||||
|
||||
if (args[3].equalsIgnoreCase("main")) {
|
||||
PlayerData data = PlayerData.get(player);
|
||||
|
||||
int total = 0;
|
||||
while (amount-- > 0)
|
||||
total += MMOCore.plugin.configManager.getNeededExperience(data.getLevel() + amount + 1);
|
||||
data.giveExperience(total);
|
||||
|
||||
if (args[4].equalsIgnoreCase("main")) {
|
||||
main.accept(data, amount);
|
||||
sender.sendMessage(ChatColor.GOLD + player.getName() + ChatColor.YELLOW + " is now Lvl " + ChatColor.GOLD + data.getLevel() + ChatColor.YELLOW + ".");
|
||||
return CommandResult.SUCCESS;
|
||||
}
|
||||
|
||||
String format = args[3].toLowerCase().replace("_", "-");
|
||||
String format = args[4].toLowerCase().replace("_", "-");
|
||||
if (!MMOCore.plugin.professionManager.has(format)) {
|
||||
sender.sendMessage(ChatColor.RED + format + " is not a valid profession.");
|
||||
return CommandResult.FAILURE;
|
||||
}
|
||||
|
||||
Profession profession = MMOCore.plugin.professionManager.get(format);
|
||||
PlayerData data = PlayerData.get(player);
|
||||
while (amount-- > 0)
|
||||
data.getCollectionSkills().giveExperience(profession, MMOCore.plugin.configManager.getNeededExperience(data.getCollectionSkills().getLevel(profession) + 1));
|
||||
this.profession.accept(data.getCollectionSkills(), profession, amount);
|
||||
sender.sendMessage(ChatColor.GOLD + player.getName() + ChatColor.YELLOW + " is now Lvl " + ChatColor.GOLD + data.getCollectionSkills().getLevel(profession) + ChatColor.YELLOW + " in " + profession.getName() + ".");
|
||||
return CommandResult.SUCCESS;
|
||||
}
|
||||
}
|
||||
|
||||
@FunctionalInterface
|
||||
interface TriConsumer<A, B, C> {
|
||||
void accept(A a, B b, C c);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandResult execute(CommandSender sender, String[] args) {
|
||||
return CommandResult.THROW_USAGE;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user