1
mirror of https://github.com/StarWishsama/Slimefun4.git synced 2024-09-19 19:25:48 +00:00

Fixed a dupe bug with mcMMO

This commit is contained in:
TheBusyBiscuit 2020-10-15 13:50:12 +02:00
parent 9e0a5451e9
commit e18c7cb245
9 changed files with 93 additions and 2 deletions

View File

@ -92,6 +92,7 @@
* Fixed #2411
* Fixed #2423
* Fixed #2452
* Fixed a dupe bug with mcMMO
## Release Candidate 16 (07 Sep 2020)
https://thebusybiscuit.github.io/builds/TheBusyBiscuit/Slimefun4/stable/#16

View File

@ -11,8 +11,16 @@ import org.bukkit.event.Listener;
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin;
import io.github.thebusybiscuit.slimefun4.utils.SlimefunUtils;
import me.minebuilders.clearlag.Clearlag;
import me.minebuilders.clearlag.events.EntityRemoveEvent;
/**
* This handles all integrations with {@link Clearlag}.
* We don't want it to clear our altar items.
*
* @author TheBusyBiscuit
*
*/
class ClearLagIntegration implements Listener {
ClearLagIntegration(@Nonnull SlimefunPlugin plugin) {

View File

@ -12,6 +12,7 @@ import io.github.thebusybiscuit.slimefun4.core.categories.FlexCategory;
import io.github.thebusybiscuit.slimefun4.core.guide.SlimefunGuideLayout;
import me.mrCookieSlime.EmeraldEnchants.EnchantmentGuide;
@Deprecated
class EmeraldEnchantsCategory extends FlexCategory {
public EmeraldEnchantsCategory(@Nonnull NamespacedKey key) {

View File

@ -15,6 +15,12 @@ import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin;
import io.github.thebusybiscuit.slimefun4.implementation.items.VanillaItem;
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem;
/**
* This handles all integrations with {@link mcMMO}.
*
* @author TheBusyBiscuit
*
*/
class McMMOIntegration implements Listener {
McMMOIntegration(@Nonnull SlimefunPlugin plugin) {
@ -36,6 +42,16 @@ class McMMOIntegration implements Listener {
}
}
/**
* This method checks if an {@link ItemStack} can be salvaged or not.
* We basically don't want players to salvage any {@link SlimefunItem} unless
* it is a {@link VanillaItem}.
*
* @param item
* The {@link ItemStack} to check
*
* @return Whether this item can be safely salvaged
*/
private boolean isSalvageable(@Nonnull ItemStack item) {
SlimefunItem sfItem = SlimefunItem.getByItem(item);
return sfItem == null || sfItem instanceof VanillaItem;

View File

@ -13,8 +13,15 @@ import org.bukkit.entity.Player;
import io.github.thebusybiscuit.slimefun4.api.player.PlayerProfile;
import io.github.thebusybiscuit.slimefun4.core.researching.Research;
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin;
import me.clip.placeholderapi.PlaceholderAPI;
import me.clip.placeholderapi.expansion.PlaceholderExpansion;
/**
* This is our integration for {@link PlaceholderAPI}.
*
* @author TheBusyBiscuit
*
*/
class PlaceholderAPIIntegration extends PlaceholderExpansion {
private final String version;

View File

@ -9,9 +9,12 @@ import javax.annotation.ParametersAreNonnullByDefault;
import org.bukkit.NamespacedKey;
import org.bukkit.block.Block;
import org.bukkit.event.Event;
import org.bukkit.inventory.ItemStack;
import org.bukkit.plugin.Plugin;
import com.gmail.nossr50.events.fake.FakeBlockBreakEvent;
import io.github.thebusybiscuit.slimefun4.api.SlimefunAddon;
import io.github.thebusybiscuit.slimefun4.core.categories.FlexCategory;
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin;
@ -32,9 +35,11 @@ public class ThirdPartyPluginService {
private final SlimefunPlugin plugin;
private boolean initialized = false;
private boolean isExoticGardenInstalled = false;
private boolean isChestTerminalInstalled = false;
private boolean isEmeraldEnchantsInstalled = false;
private boolean isMcMMOInstalled = false;
/**
* This gets overridden if ExoticGarden is loaded
@ -51,7 +56,16 @@ public class ThirdPartyPluginService {
this.plugin = plugin;
}
/**
* This method initializes all third party integrations.
*/
public void start() {
if (initialized) {
throw new UnsupportedOperationException("Third Party Integrations have already been initialized!");
}
initialized = true;
if (isPluginInstalled("PlaceholderAPI")) {
try {
PlaceholderAPIIntegration hook = new PlaceholderAPIIntegration(plugin);
@ -84,9 +98,19 @@ public class ThirdPartyPluginService {
}
}
// mcMMO Block Placer Integration
// mcMMO Integration
if (isPluginInstalled("mcMMO")) {
new McMMOIntegration(plugin);
try {
// This makes sure that the FakeEvent interface is present.
// Class.forName("com.gmail.nossr50.events.fake.FakeEvent");
new McMMOIntegration(plugin);
isMcMMOInstalled = true;
} catch (Exception | LinkageError x) {
String version = plugin.getServer().getPluginManager().getPlugin("mcMMO").getDescription().getVersion();
Slimefun.getLogger().log(Level.WARNING, "Maybe consider updating mcMMO or Slimefun?");
Slimefun.getLogger().log(Level.WARNING, x, () -> "Failed to hook into mcMMO v" + version);
}
}
/*
@ -136,4 +160,18 @@ public class ThirdPartyPluginService {
return exoticGardenIntegration.apply(block);
}
/**
* This checks if one of our third party integrations faked an {@link Event}.
* Faked {@link Event Events} should be ignored in our logic.
*
* @param event
* The {@link Event} to test
*
* @return Whether this is a fake event
*/
public boolean isEventFaked(@Nonnull Event event) {
// TODO: Change this to FakeEvent once the new mcMMO build was released
return isMcMMOInstalled && event instanceof FakeBlockBreakEvent;
}
}

View File

@ -14,6 +14,13 @@ import com.sk89q.worldedit.world.block.BlockStateHolder;
import me.mrCookieSlime.Slimefun.api.BlockStorage;
/**
* This handles all integrations with {@link WorldEdit}.
* If an are is cleared, we also wanna clear all Slimefun-related block data.
*
* @author TheBusyBiscuit
*
*/
class WorldEditIntegration {
WorldEditIntegration() {

View File

@ -181,9 +181,14 @@ public final class SlimefunPlugin extends JavaPlugin implements SlimefunAddon {
command.register();
registry.load(config);
} else if (getServer().getPluginManager().isPluginEnabled("CS-CoreLib")) {
getLogger().log(Level.INFO, "CS-CoreLib was detected!");
long timestamp = System.nanoTime();
PaperLib.suggestPaper(this);
if (PaperLib.isPaper()) {
getLogger().log(Level.INFO, "Paper was detected! Performance optimizations have been applied.");
}
// We wanna ensure that the Server uses a compatible version of Minecraft
if (isVersionUnsupported()) {
getServer().getPluginManager().disablePlugin(this);
@ -275,7 +280,10 @@ public final class SlimefunPlugin extends JavaPlugin implements SlimefunAddon {
autoSavingService.start(this, config.getInt("options.auto-save-delay-in-minutes"));
ticker.start(this);
getLogger().log(Level.INFO, "Loading Third-Party plugin integrations...");
thirdPartySupportService.start();
gitHubService.start(this);
// Hooray!

View File

@ -83,6 +83,11 @@ public class BlockListener implements Listener {
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onBlockBreak(BlockBreakEvent e) {
if (SlimefunPlugin.getThirdPartySupportService().isEventFaked(e)) {
// This is a "fake" event, we can ignore it.
return;
}
checkForSensitiveBlockAbove(e.getPlayer(), e.getBlock());
ItemStack item = e.getPlayer().getInventory().getItemInMainHand();