mirror of
https://github.com/Xiao-MoMi/Custom-Crops.git
synced 2026-01-04 15:41:46 +00:00
2.2.6
This commit is contained in:
@@ -109,10 +109,10 @@ public class CropConfig {
|
||||
List<ActionInterface> actions = new ArrayList<>();
|
||||
for (String action : Objects.requireNonNull(config.getConfigurationSection(key + ".harvest-actions")).getKeys(false)) {
|
||||
switch (action) {
|
||||
case "xp" -> actions.add(new ActionXP(config.getInt(key + ".harvest-actions." + action)));
|
||||
case "skill-xp" -> actions.add(new ActionSkillXP(config.getDouble(key + ".harvest-actions." + action)));
|
||||
case "commands" -> actions.add(new ActionCommand(config.getStringList(key + ".harvest-actions." + action).toArray(new String[0])));
|
||||
case "messages" -> actions.add(new ActionMessage(config.getStringList(key + ".harvest-actions." + action).toArray(new String[0])));
|
||||
case "xp" -> actions.add(new ActionXP(config.getInt(key + ".harvest-actions." + action), config.getDouble(key + ".harvest-actions." + action + "-chance", 1)));
|
||||
case "skill-xp" -> actions.add(new ActionSkillXP(config.getDouble(key + ".harvest-actions." + action), config.getDouble(key + ".harvest-actions." + action + "-chance", 1)));
|
||||
case "commands" -> actions.add(new ActionCommand(config.getStringList(key + ".harvest-actions." + action).toArray(new String[0]), config.getDouble(key + ".harvest-actions." + action + "-chance", 1)));
|
||||
case "messages" -> actions.add(new ActionMessage(config.getStringList(key + ".harvest-actions." + action).toArray(new String[0]), config.getDouble(key + ".harvest-actions." + action + "-chance", 1)));
|
||||
}
|
||||
}
|
||||
crop.setActions(actions.toArray(new ActionInterface[0]));
|
||||
|
||||
@@ -355,7 +355,9 @@ public class CropManager extends Function {
|
||||
|
||||
public void performActions(ActionInterface[] actions, Player player) {
|
||||
for (ActionInterface action : actions) {
|
||||
action.performOn(player);
|
||||
if (Math.random() <= action.getChance()) {
|
||||
action.performOn(player);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -23,9 +23,11 @@ import org.bukkit.entity.Player;
|
||||
public class ActionCommand implements ActionInterface {
|
||||
|
||||
private final String[] commands;
|
||||
private final double chance;
|
||||
|
||||
public ActionCommand(String[] commands) {
|
||||
public ActionCommand(String[] commands, double chance) {
|
||||
this.commands = commands;
|
||||
this.chance = chance;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -34,4 +36,9 @@ public class ActionCommand implements ActionInterface {
|
||||
Bukkit.getServer().dispatchCommand(Bukkit.getConsoleSender(), command.replace("{player}", player.getName()));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getChance() {
|
||||
return chance;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,4 +21,6 @@ import org.bukkit.entity.Player;
|
||||
|
||||
public interface ActionInterface {
|
||||
void performOn(Player player);
|
||||
|
||||
double getChance();
|
||||
}
|
||||
@@ -23,9 +23,11 @@ import org.bukkit.entity.Player;
|
||||
public class ActionMessage implements ActionInterface{
|
||||
|
||||
private final String[] messages;
|
||||
private final double chance;
|
||||
|
||||
public ActionMessage(String[] messages) {
|
||||
public ActionMessage(String[] messages, double chance) {
|
||||
this.messages = messages;
|
||||
this.chance = chance;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -34,4 +36,9 @@ public class ActionMessage implements ActionInterface{
|
||||
AdventureUtil.playerMessage(player, message.replace("{player}", player.getName()));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getChance() {
|
||||
return chance;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,9 +23,11 @@ import org.bukkit.entity.Player;
|
||||
public class ActionSkillXP implements ActionInterface {
|
||||
|
||||
private final double xp;
|
||||
private final double chance;
|
||||
|
||||
public ActionSkillXP(double xp) {
|
||||
public ActionSkillXP(double xp, double chance) {
|
||||
this.xp = xp;
|
||||
this.chance = chance;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -34,4 +36,9 @@ public class ActionSkillXP implements ActionInterface {
|
||||
MainConfig.skillXP.addXp(player, xp);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getChance() {
|
||||
return chance;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,13 +22,20 @@ import org.bukkit.entity.Player;
|
||||
public class ActionXP implements ActionInterface {
|
||||
|
||||
private final int amount;
|
||||
private final double chance;
|
||||
|
||||
public ActionXP(int amount) {
|
||||
public ActionXP(int amount, double chance) {
|
||||
this.amount = amount;
|
||||
this.chance = chance;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void performOn(Player player) {
|
||||
player.giveExp(amount);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getChance() {
|
||||
return chance;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user