From f9d6274732dae9667544192260d1adfebb747137 Mon Sep 17 00:00:00 2001 From: Xiao-MoMi <70987828+Xiao-MoMi@users.noreply.github.com> Date: Sat, 13 May 2023 01:53:38 +0800 Subject: [PATCH] 3.1.2 --- build.gradle | 3 +- .../crucible/CrucibleHandler.java | 29 ++++ .../crucible/CruciblePluginImpl.java | 153 ++++++++++++++++++ .../itemsadder/ItemsAdderPluginImpl.java | 4 +- .../customplugin/oraxen/OraxenPluginImpl.java | 4 +- .../command/CustomCropsCommand.java | 1 + .../command/subcmd/CorruptionTest.java | 44 +++++ .../integration/IntegrationManager.java | 6 + .../integration/job/JobsRebornImpl.java | 45 +++++- 9 files changed, 280 insertions(+), 9 deletions(-) create mode 100644 src/main/java/net/momirealms/customcrops/api/customplugin/crucible/CrucibleHandler.java create mode 100644 src/main/java/net/momirealms/customcrops/api/customplugin/crucible/CruciblePluginImpl.java create mode 100644 src/main/java/net/momirealms/customcrops/command/subcmd/CorruptionTest.java diff --git a/build.gradle b/build.gradle index 41b3fde..000f81e 100644 --- a/build.gradle +++ b/build.gradle @@ -4,7 +4,7 @@ plugins { } group = 'net.momirealms' -version = '3.1.2' +version = '3.1.3' repositories { mavenCentral() @@ -34,6 +34,7 @@ dependencies { compileOnly ('com.willfp:eco:6.53.1') compileOnly ('com.willfp:EcoJobs:3.2.5') compileOnly ('net.objecthunter:exp4j:0.4.8') + compileOnly ('io.lumine:Mythic-Dist:5.2.1') compileOnly fileTree (dir:'libs',includes:['*.jar']) implementation ('net.kyori:adventure-api:4.13.1') implementation ('net.kyori:adventure-platform-bukkit:4.3.0') diff --git a/src/main/java/net/momirealms/customcrops/api/customplugin/crucible/CrucibleHandler.java b/src/main/java/net/momirealms/customcrops/api/customplugin/crucible/CrucibleHandler.java new file mode 100644 index 0000000..7eb5519 --- /dev/null +++ b/src/main/java/net/momirealms/customcrops/api/customplugin/crucible/CrucibleHandler.java @@ -0,0 +1,29 @@ +/* + * Copyright (C) <2022> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package net.momirealms.customcrops.api.customplugin.crucible; + +import net.momirealms.customcrops.api.customplugin.Handler; +import net.momirealms.customcrops.api.customplugin.PlatformManager; + +public class CrucibleHandler extends Handler { + + public CrucibleHandler(PlatformManager platformManager) { + super(platformManager); + //TODO NO API Events + } +} diff --git a/src/main/java/net/momirealms/customcrops/api/customplugin/crucible/CruciblePluginImpl.java b/src/main/java/net/momirealms/customcrops/api/customplugin/crucible/CruciblePluginImpl.java new file mode 100644 index 0000000..fb66328 --- /dev/null +++ b/src/main/java/net/momirealms/customcrops/api/customplugin/crucible/CruciblePluginImpl.java @@ -0,0 +1,153 @@ +/* + * Copyright (C) <2022> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package net.momirealms.customcrops.api.customplugin.crucible; + +import io.lumine.mythic.bukkit.BukkitAdapter; +import io.lumine.mythiccrucible.MythicCrucible; +import io.lumine.mythiccrucible.items.CrucibleItem; +import io.lumine.mythiccrucible.items.blocks.CustomBlockItemContext; +import net.momirealms.customcrops.api.customplugin.PlatformInterface; +import net.momirealms.customcrops.api.util.AdventureUtils; +import org.bukkit.Location; +import org.bukkit.block.Block; +import org.bukkit.block.BlockFace; +import org.bukkit.entity.ItemDisplay; +import org.bukkit.entity.ItemFrame; +import org.bukkit.inventory.ItemStack; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.util.Optional; + +public class CruciblePluginImpl implements PlatformInterface { + + @Override + public boolean removeCustomBlock(Location location) { + Optional optionalCB = MythicCrucible.inst().getItemManager().getCustomBlockManager().getBlockFromBlock(location.getBlock()); + if (optionalCB.isEmpty()) return false; + optionalCB.get().remove(location.getBlock(), null, false); + return true; + } + + @Nullable + @Override + public String getCustomBlockID(Location location) { + Optional optionalCB = MythicCrucible.inst().getItemManager().getCustomBlockManager().getBlockFromBlock(location.getBlock()); + if (optionalCB.isEmpty()) return null; + else return optionalCB.get().getCrucibleItem().getInternalName(); + } + + @Nullable + @Override + public ItemStack getItemStack(String id) { + Optional optionalCI = MythicCrucible.inst().getItemManager().getItem(id); + if (optionalCI.isEmpty()) return null; + else return BukkitAdapter.adapt(optionalCI.get().getMythicItem().generateItemStack(1)); + } + + @Nullable + @Override + public ItemFrame placeItemFrame(Location location, String id) { + Optional optionalCI = MythicCrucible.inst().getItemManager().getItem(id); + if (optionalCI.isPresent()) { + optionalCI.get().getFurnitureData().place(location.getBlock(), BlockFace.UP, 0); + } else { + AdventureUtils.consoleMessage("[CustomCrop] ItemFrame not exists: " + id); + } + //TODO API limits (It's using private methods to place) + return null; + } + + @Nullable + @Override + public ItemDisplay placeItemDisplay(Location location, String id) { + //TODO Not implemented feature + return null; + } + + @Override + public void placeNoteBlock(Location location, String id) { + Optional optionalCI = MythicCrucible.inst().getItemManager().getItem(id); + if (optionalCI.isPresent()) { + location.getBlock().setBlockData(optionalCI.get().getBlockData().getBlockData()); + } else { + AdventureUtils.consoleMessage("[CustomCrop] NoteBlock not exists: " + id); + } + } + + @Override + public void placeTripWire(Location location, String id) { + Optional optionalCI = MythicCrucible.inst().getItemManager().getItem(id); + if (optionalCI.isPresent()) { + location.getBlock().setBlockData(optionalCI.get().getBlockData().getBlockData()); + } else { + AdventureUtils.consoleMessage("[CustomCrop] Tirpwire not exists: " + id); + } + } + + @NotNull + @Override + public String getBlockID(Block block) { + Optional optionalCB = MythicCrucible.inst().getItemManager().getCustomBlockManager().getBlockFromBlock(block); + if (optionalCB.isEmpty()) return block.getType().name(); + else return optionalCB.get().getCrucibleItem().getInternalName(); + } + + @Override + public boolean doesItemExist(String id) { + Optional optionalCI = MythicCrucible.inst().getItemManager().getItem(id); + return optionalCI.isPresent(); + } + + @Override + public void dropBlockLoot(Block block) { + //TODO Not necessary + } + + @Override + public void placeChorus(Location location, String id) { + Optional optionalCI = MythicCrucible.inst().getItemManager().getItem(id); + if (optionalCI.isPresent()) { + location.getBlock().setBlockData(optionalCI.get().getBlockData().getBlockData()); + } else { + AdventureUtils.consoleMessage("[CustomCrop] Chorus not exists: " + id); + } + } + + @NotNull + @Override + public String getItemStackID(@NotNull ItemStack itemStack) { + Optional optionalCI = MythicCrucible.inst().getItemManager().getItem(itemStack); + if (optionalCI.isEmpty()) return itemStack.getType().name(); + else return optionalCI.get().getInternalName(); + } + + @Nullable + @Override + public String getItemDisplayID(ItemDisplay itemDisplay) { + return null; + } + + @Nullable + @Override + public String getItemFrameID(ItemFrame itemFrame) { + Optional optionalCI = MythicCrucible.inst().getItemManager().getFurnitureManager().getItemFromFrame(itemFrame); + if (optionalCI.isEmpty()) return null; + else return optionalCI.get().getInternalName(); + } +} diff --git a/src/main/java/net/momirealms/customcrops/api/customplugin/itemsadder/ItemsAdderPluginImpl.java b/src/main/java/net/momirealms/customcrops/api/customplugin/itemsadder/ItemsAdderPluginImpl.java index 8d2ae0d..146b4da 100644 --- a/src/main/java/net/momirealms/customcrops/api/customplugin/itemsadder/ItemsAdderPluginImpl.java +++ b/src/main/java/net/momirealms/customcrops/api/customplugin/itemsadder/ItemsAdderPluginImpl.java @@ -67,7 +67,7 @@ public class ItemsAdderPluginImpl implements PlatformInterface { if (entity instanceof ItemFrame itemFrame) return itemFrame; else { - AdventureUtils.consoleMessage("[CustomCrops] Item Frame not exists: " + id); + AdventureUtils.consoleMessage("[CustomCrops] ItemFrame not exists: " + id); customFurniture.remove(false); } return null; @@ -85,7 +85,7 @@ public class ItemsAdderPluginImpl implements PlatformInterface { if (entity instanceof ItemDisplay itemDisplay) return itemDisplay; else { - AdventureUtils.consoleMessage("[CustomCrops] Item Display not exists: " + id); + AdventureUtils.consoleMessage("[CustomCrops] ItemDisplay not exists: " + id); customFurniture.remove(false); } return null; diff --git a/src/main/java/net/momirealms/customcrops/api/customplugin/oraxen/OraxenPluginImpl.java b/src/main/java/net/momirealms/customcrops/api/customplugin/oraxen/OraxenPluginImpl.java index dfaf88d..c48941d 100644 --- a/src/main/java/net/momirealms/customcrops/api/customplugin/oraxen/OraxenPluginImpl.java +++ b/src/main/java/net/momirealms/customcrops/api/customplugin/oraxen/OraxenPluginImpl.java @@ -78,7 +78,7 @@ public class OraxenPluginImpl implements PlatformInterface { if (entity instanceof ItemFrame itemFrame) return itemFrame; else { - AdventureUtils.consoleMessage("[CustomCrops] Item Frame not exists: " + id); + AdventureUtils.consoleMessage("[CustomCrops] ItemFrame not exists: " + id); entity.remove(); return null; } @@ -96,7 +96,7 @@ public class OraxenPluginImpl implements PlatformInterface { if (entity instanceof ItemDisplay itemDisplay) return itemDisplay; else { - AdventureUtils.consoleMessage("[CustomCrops] Item Display not exists: " + id); + AdventureUtils.consoleMessage("[CustomCrops] ItemDisplay not exists: " + id); entity.remove(); return null; } diff --git a/src/main/java/net/momirealms/customcrops/command/CustomCropsCommand.java b/src/main/java/net/momirealms/customcrops/command/CustomCropsCommand.java index 13c15c4..c774e97 100644 --- a/src/main/java/net/momirealms/customcrops/command/CustomCropsCommand.java +++ b/src/main/java/net/momirealms/customcrops/command/CustomCropsCommand.java @@ -30,6 +30,7 @@ public class CustomCropsCommand extends AbstractMainCommand { regSubCommand(ForceCommand.INSTANCE); regSubCommand(MigrateCommand.INSTANCE); regSubCommand(ConvertCommand.INSTANCE); +// regSubCommand(CorruptionTest.INSTANCE); // regSubCommand(PerformanceTest.INSTANCE); } } diff --git a/src/main/java/net/momirealms/customcrops/command/subcmd/CorruptionTest.java b/src/main/java/net/momirealms/customcrops/command/subcmd/CorruptionTest.java new file mode 100644 index 0000000..5e5acbc --- /dev/null +++ b/src/main/java/net/momirealms/customcrops/command/subcmd/CorruptionTest.java @@ -0,0 +1,44 @@ +//package net.momirealms.customcrops.command.subcmd; +// +//import net.momirealms.customcrops.CustomCrops; +//import net.momirealms.customcrops.command.AbstractSubCommand; +//import org.bukkit.Bukkit; +//import org.bukkit.Location; +//import org.bukkit.command.CommandSender; +// +//import java.util.List; +// +//public class CorruptionTest extends AbstractSubCommand { +// +// public static final CorruptionTest INSTANCE = new CorruptionTest(); +// +// public CorruptionTest() { +// super("test"); +// } +// +// @Override +// public boolean onCommand(CommandSender sender, List args) { +// Location location = new Location(Bukkit.getWorld("world"), 1604, 100, 1604); +// for (int i = 0; i < 8; i++) { +// for (int j = 0; j < 8; j++) { +// Location newLoc = location.clone().add(i, 0, j); +// Thread t1 = new Thread(() -> CustomCrops.getInstance().getScheduler().callSyncMethod(() -> { +// CustomCrops.getInstance().getPlatformInterface().placeNoteBlock(newLoc, "customcrops:wet_pot"); +// return null; +// })); +// Thread t2 = new Thread(() -> CustomCrops.getInstance().getScheduler().callSyncMethod(() -> { +// CustomCrops.getInstance().getPlatformInterface().placeNoteBlock(newLoc, "customcrops:dry_pot"); +// return null; +// })); +// Thread t3 = new Thread(() -> CustomCrops.getInstance().getScheduler().callSyncMethod(() -> { +// CustomCrops.getInstance().getPlatformInterface().removeAnyBlock(newLoc); +// return null; +// })); +// t1.start(); +// t2.start(); +// t3.start(); +// } +// } +// return true; +// } +//} diff --git a/src/main/java/net/momirealms/customcrops/integration/IntegrationManager.java b/src/main/java/net/momirealms/customcrops/integration/IntegrationManager.java index 54976a8..75ef29a 100644 --- a/src/main/java/net/momirealms/customcrops/integration/IntegrationManager.java +++ b/src/main/java/net/momirealms/customcrops/integration/IntegrationManager.java @@ -39,6 +39,8 @@ import net.momirealms.customcrops.integration.skill.MMOCoreImpl; import net.momirealms.customcrops.integration.skill.mcMMOImpl; import org.bukkit.Bukkit; import org.bukkit.Material; +import org.bukkit.event.HandlerList; +import org.bukkit.event.Listener; import org.bukkit.inventory.ItemStack; import org.bukkit.plugin.PluginManager; import org.jetbrains.annotations.NotNull; @@ -113,8 +115,12 @@ public class IntegrationManager extends Function { } private void hookJobs() { + if (this.jobInterface instanceof JobsRebornImpl jobsReborn) { + HandlerList.unregisterAll(jobsReborn); + } if (pluginManager.isPluginEnabled("Jobs")) { this.jobInterface = new JobsRebornImpl(); + Bukkit.getPluginManager().registerEvents((Listener) jobInterface, plugin); hookMessage("JobsReborn"); } else if (pluginManager.isPluginEnabled("EcoJobs")) { this.jobInterface = new EcoJobsImpl(); diff --git a/src/main/java/net/momirealms/customcrops/integration/job/JobsRebornImpl.java b/src/main/java/net/momirealms/customcrops/integration/job/JobsRebornImpl.java index eda7088..908e149 100644 --- a/src/main/java/net/momirealms/customcrops/integration/job/JobsRebornImpl.java +++ b/src/main/java/net/momirealms/customcrops/integration/job/JobsRebornImpl.java @@ -18,15 +18,17 @@ package net.momirealms.customcrops.integration.job; import com.gamingmesh.jobs.Jobs; -import com.gamingmesh.jobs.container.Job; -import com.gamingmesh.jobs.container.JobProgression; -import com.gamingmesh.jobs.container.JobsPlayer; +import com.gamingmesh.jobs.container.*; +import com.gamingmesh.jobs.listeners.JobsPaymentListener; +import net.momirealms.customcrops.api.event.CropBreakEvent; import net.momirealms.customcrops.integration.JobInterface; import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; import java.util.List; -public class JobsRebornImpl implements JobInterface { +public class JobsRebornImpl implements JobInterface, Listener { @Override public void addXp(Player player, double amount) { @@ -57,4 +59,39 @@ public class JobsRebornImpl implements JobInterface { } return 0; } + + @EventHandler + public void onHarvest(CropBreakEvent event) { + if (!Jobs.getGCManager().canPerformActionInWorld(event.getEntity().getWorld())) return; + if (!(event.getEntity() instanceof Player player)) return; + + // check if in creative + if (!JobsPaymentListener.payIfCreative(player)) + return; + + if (!Jobs.getPermissionHandler().hasWorldPermission(player, player.getLocation().getWorld().getName())) + return; + + JobsPlayer jobsPlayer = Jobs.getPlayerManager().getJobsPlayer(player); + if (jobsPlayer == null) return; + + Jobs.action(jobsPlayer, new CustomCropsInfo(event.getCropItemID(), ActionType.MMKILL)); + } + + public static class CustomCropsInfo extends BaseActionInfo { + private final String name; + + public CustomCropsInfo(String name, ActionType type) { + super(type); + this.name = name; + } + + public String getName() { + return this.name; + } + + public String getNameWithSub() { + return this.name; + } + } }