9
0
mirror of https://github.com/Xiao-MoMi/Custom-Crops.git synced 2025-12-27 19:09:09 +00:00
This commit is contained in:
Xiao-MoMi
2023-05-30 01:13:44 +08:00
parent 126f5428a8
commit 3fed7b336b
13 changed files with 73 additions and 21 deletions

View File

@@ -24,13 +24,13 @@ import net.momirealms.customcrops.integration.JobInterface;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.Nullable;
public record JobXPImpl(double amount, double chance) implements Action {
public record JobXPImpl(double amount, double chance, @Nullable String job) implements Action {
@Override
public void doOn(@Nullable Player player, @Nullable SimpleLocation cropLoc, ItemMode itemMode) {
if (player == null || Math.random() > chance) return;
JobInterface jobInterface = CustomCrops.getInstance().getIntegrationManager().getJobInterface();
if (jobInterface == null) return;
jobInterface.addXp(player, amount);
jobInterface.addXp(player, amount, job);
}
}

View File

@@ -68,6 +68,7 @@ public class ConfigManager extends Function {
public static boolean preventTrampling;
public static boolean onlyInLoadedChunks;
public static boolean enableCorruptionFixer;
public static boolean debugWorld;
private final HashMap<String, Integer> cropPerWorld;
private final CustomCrops plugin;
@@ -96,6 +97,7 @@ public class ConfigManager extends Function {
lang = config.getString("lang");
debugScheduler = config.getBoolean("debug.log-scheduler", false);
debugCorruption = config.getBoolean("debug.log-corruption-fixer", false);
debugWorld = config.getBoolean("debug.log-world-state", false);
loadWorlds(Objects.requireNonNull(config.getConfigurationSection("worlds")));
loadOptimization(Objects.requireNonNull(config.getConfigurationSection("optimization")));
loadScheduleSystem(Objects.requireNonNull(config.getConfigurationSection("schedule-system")));

View File

@@ -123,7 +123,7 @@ public class FertilizerManager extends Function {
public ArrayList<Pair<Double, Integer>> getChancePair(ConfigurationSection fertilizerSec) {
ArrayList<Pair<Double, Integer>> pairs = new ArrayList<>();
ConfigurationSection effectSec = fertilizerSec.getConfigurationSection("effects");
ConfigurationSection effectSec = fertilizerSec.getConfigurationSection("chance");
if (effectSec == null) return new ArrayList<>();
for (String point : effectSec.getKeys(false)) {
Pair<Double, Integer> pair = new Pair<>(effectSec.getDouble(point), Integer.parseInt(point));

View File

@@ -24,17 +24,19 @@ import org.jetbrains.annotations.Nullable;
public class JobLevelImpl extends AbstractRequirement implements Requirement {
private final int level;
private final String jobName;
public JobLevelImpl(@Nullable String[] msg, int level) {
public JobLevelImpl(@Nullable String[] msg, int level, String jobName) {
super(msg);
this.level = level;
this.jobName = jobName;
}
@Override
public boolean isConditionMet(CurrentState currentState) {
JobInterface jobInterface = CustomCrops.getInstance().getIntegrationManager().getJobInterface();
if (jobInterface == null || currentState.getPlayer() == null) return true;
if (jobInterface.getLevel(currentState.getPlayer()) >= level) {
if (jobInterface.getLevel(currentState.getPlayer(), jobName) >= level) {
return true;
}
notMetMessage(currentState.getPlayer());

View File

@@ -0,0 +1,24 @@
package net.momirealms.customcrops.api.object.world;
import com.infernalsuite.aswm.api.events.LoadSlimeWorldEvent;
import org.bukkit.Bukkit;
import org.bukkit.World;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
public class SlimeWorldListener implements Listener {
private final WorldDataManager worldDataManager;
public SlimeWorldListener(WorldDataManager worldDataManager) {
this.worldDataManager = worldDataManager;
}
@EventHandler
public void onWorldLoad(LoadSlimeWorldEvent event) {
World world = Bukkit.getWorld(event.getSlimeWorld().getName());
if (world != null) {
worldDataManager.loadWorld(world);
}
}
}

View File

@@ -25,6 +25,7 @@ import net.momirealms.customcrops.api.object.fertilizer.Fertilizer;
import net.momirealms.customcrops.api.object.pot.Pot;
import net.momirealms.customcrops.api.object.sprinkler.Sprinkler;
import net.momirealms.customcrops.api.object.sprinkler.SprinklerConfig;
import net.momirealms.customcrops.api.util.AdventureUtils;
import org.bukkit.Bukkit;
import org.bukkit.Chunk;
import org.bukkit.World;
@@ -38,16 +39,23 @@ public class WorldDataManager extends Function {
private final ConcurrentHashMap<String, CCWorld> worldMap;
private final CustomCrops plugin;
private final WorldListener worldListener;
private SlimeWorldListener slimeWorldListener;
public WorldDataManager(CustomCrops plugin) {
this.plugin = plugin;
this.worldMap = new ConcurrentHashMap<>();
this.worldListener = new WorldListener(this);
try {
Class.forName("com.infernalsuite.aswm.api.world.SlimeWorld");
this.slimeWorldListener = new SlimeWorldListener(this);
} catch (ClassNotFoundException ignored) {
}
}
@Override
public void load() {
Bukkit.getPluginManager().registerEvents(worldListener, plugin);
if (slimeWorldListener != null) Bukkit.getPluginManager().registerEvents(slimeWorldListener, plugin);
for (CCWorld ccWorld : worldMap.values()) {
ccWorld.load();
}
@@ -56,6 +64,7 @@ public class WorldDataManager extends Function {
@Override
public void unload() {
HandlerList.unregisterAll(worldListener);
if (slimeWorldListener != null) HandlerList.unregisterAll(slimeWorldListener);
for (CCWorld ccWorld : worldMap.values()) {
ccWorld.unload();
}
@@ -71,18 +80,21 @@ public class WorldDataManager extends Function {
}
public void loadWorld(World world) {
if (ConfigManager.debugWorld) AdventureUtils.consoleMessage("World " + world.getName() + " is trying to load");
if (!isWorldAllowed(world)) return;
CCWorld ccWorld = new CCWorld(world, plugin);
ccWorld.init();
ccWorld.load();
ccWorld.onReachPoint();
worldMap.put(world.getName(), ccWorld);
if (ConfigManager.debugWorld) AdventureUtils.consoleMessage("World " + world.getName() + " is loaded");
}
public void unloadWorld(World world) {
CCWorld ccWorld = worldMap.remove(world.getName());
if (ccWorld != null) {
ccWorld.disable();
if (ConfigManager.debugWorld) AdventureUtils.consoleMessage("World " + world.getName() + " is unloaded");
}
}

View File

@@ -217,7 +217,7 @@ public class ConfigUtils {
case "permission" -> requirements.add(new PermissionImpl(msg, innerSec.getString("value")));
case "time" -> requirements.add(new TimeImpl(msg, innerSec.getStringList("value")));
case "skill-level" -> requirements.add(new SkillLevelImpl(msg, innerSec.getInt("value")));
case "job-level" -> requirements.add(new JobLevelImpl(msg, innerSec.getInt("value")));
case "job-level" -> requirements.add(new JobLevelImpl(msg, innerSec.getInt("value.level"), innerSec.getString("value.job")));
case "date" -> requirements.add(new DateImpl(msg, new HashSet<>(innerSec.getStringList("value"))));
case "papi-condition" -> requirements.add(new CustomPapi(msg, Objects.requireNonNull(innerSec.getConfigurationSection("value")).getValues(false)));
}
@@ -261,8 +261,9 @@ public class ConfigUtils {
actionSec.getDouble("chance", 1))
);
case "job-xp" -> actions.add(new JobXPImpl(
actionSec.getDouble("value"),
actionSec.getDouble("chance", 1))
actionSec.getDouble("value.xp"),
actionSec.getDouble("chance", 1),
actionSec.getString("value.job"))
);
case "sound" -> actions.add(new SoundActionImpl(
actionSec.getString("value.source"),

View File

@@ -24,6 +24,7 @@ import net.momirealms.customcrops.api.util.AdventureUtils;
import net.momirealms.customcrops.api.util.ConfigUtils;
import net.momirealms.customcrops.integration.item.DefaultImpl;
import net.momirealms.customcrops.integration.item.MMOItemsItemImpl;
import net.momirealms.customcrops.integration.item.MythicMobsItemImpl;
import net.momirealms.customcrops.integration.job.EcoJobsImpl;
import net.momirealms.customcrops.integration.job.JobsRebornImpl;
import net.momirealms.customcrops.integration.papi.PlaceholderManager;
@@ -93,7 +94,7 @@ public class IntegrationManager extends Function {
private void hookItems() {
ArrayList<ItemInterface> itemInterfaceList = new ArrayList<>();
if (pluginManager.isPluginEnabled("MythicMobs")) {
itemInterfaceList.add(new MMOItemsItemImpl());
itemInterfaceList.add(new MythicMobsItemImpl());
hookMessage("MythicMobs");
}
if (pluginManager.isPluginEnabled("MMOItems")) {

View File

@@ -18,8 +18,9 @@
package net.momirealms.customcrops.integration;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.Nullable;
public interface JobInterface {
void addXp(Player player, double amount);
int getLevel(Player player);
void addXp(Player player, double amount, @Nullable String job);
int getLevel(Player player, @Nullable String job);
}

View File

@@ -21,13 +21,15 @@ import com.willfp.ecojobs.api.EcoJobsAPI;
import com.willfp.ecojobs.jobs.Job;
import net.momirealms.customcrops.integration.JobInterface;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.Nullable;
public class EcoJobsImpl implements JobInterface {
@Override
public void addXp(Player player, double amount) {
public void addXp(Player player, double amount, @Nullable String jobName) {
if (jobName == null) jobName = "farmer";
for (Job job : EcoJobsAPI.getActiveJobs(player)) {
if (job.getId().equals("farmer")) {
if (job.getId().equals(jobName)) {
EcoJobsAPI.giveJobExperience(player, job, amount);
break;
}
@@ -35,7 +37,7 @@ public class EcoJobsImpl implements JobInterface {
}
@Override
public int getLevel(Player player) {
public int getLevel(Player player, @Nullable String jobName) {
// Job job = Jobs.getByID("farmer");
// if (job == null) return 0;
// return EcoJobsAPI.getJobLevel(player, job);

View File

@@ -25,17 +25,19 @@ import net.momirealms.customcrops.integration.JobInterface;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.jetbrains.annotations.Nullable;
import java.util.List;
public class JobsRebornImpl implements JobInterface, Listener {
@Override
public void addXp(Player player, double amount) {
public void addXp(Player player, double amount, String jobName) {
if (jobName == null) jobName = "Farmer";
JobsPlayer jobsPlayer = Jobs.getPlayerManager().getJobsPlayer(player);
if (jobsPlayer != null) {
List<JobProgression> jobs = jobsPlayer.getJobProgression();
Job job = Jobs.getJob("Farmer");
Job job = Jobs.getJob(jobName);
for (JobProgression progression : jobs) {
if (progression.getJob().equals(job)) {
progression.addExperience(amount);
@@ -46,11 +48,12 @@ public class JobsRebornImpl implements JobInterface, Listener {
}
@Override
public int getLevel(Player player) {
public int getLevel(Player player, @Nullable String jobName) {
if (jobName == null) jobName = "Farmer";
JobsPlayer jobsPlayer = Jobs.getPlayerManager().getJobsPlayer(player);
if (jobsPlayer != null) {
List<JobProgression> jobs = jobsPlayer.getJobProgression();
Job job = Jobs.getJob("Farmer");
Job job = Jobs.getJob(jobName);
for (JobProgression progression : jobs) {
if (progression.getJob().equals(job)) {
return progression.getLevel();

View File

@@ -1,11 +1,12 @@
# Don't change
config-version: '32'
config-version: '33'
# BStats
metrics: true
# Language: english / spanish / chinese / turkish
lang: english
# Debug
debug:
log-world-state: false
log-scheduler: false
log-corruption-fixer: false