Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NoSuchMethodException CMIUser.hasGodMode #34

Open
LucidAPs opened this issue Feb 9, 2023 · 4 comments
Open

NoSuchMethodException CMIUser.hasGodMode #34

LucidAPs opened this issue Feb 9, 2023 · 4 comments

Comments

@LucidAPs
Copy link

LucidAPs commented Feb 9, 2023

    Player player = event.getPlayer();
    CMIUser user = CMI.getInstance().getPlayerManager().getUser(player.getUniqueId());

    if (godMode == StateFlag.State.ALLOW) {
        user.setGodMode(true);
    } else if (godMode == StateFlag.State.DENY) {
        user.setGodMode(false);
    }
@MagnetiteMC
Copy link

It's just .setGod(). Not setGodMode()

View here: https://github.com/Zrips/CMI-API/blob/master/src/com/Zrips/CMI/Containers/CMIUser.java#L633

@LucidAPs
Copy link
Author

LucidAPs commented Apr 19, 2023

It's just .setGod(). Not setGodMode()

View here: https://github.com/Zrips/CMI-API/blob/master/src/com/Zrips/CMI/Containers/CMIUser.java#L633

I did a lot of work, but it still doesnt work

    @EventHandler
    public void onEntityDamage(EntityDamageByEntityEvent event) {
        Entity damager = event.getDamager();
        Entity damaged = event.getEntity();

        if (damaged instanceof Player) {
            Player damagedPlayer = (Player) damaged;
            CMIUser damagedUser = CMI.getInstance().getPlayerManager().getUser(damagedPlayer);

            if (damagedUser == null) {
                return;
            }

            if (damager instanceof Player) {
                Player damagerPlayer = (Player) damager;
                ItemStack itemInHand = damagerPlayer.getInventory().getItemInMainHand();

                if (itemInHand != null && itemInHand.getType() == Material.WOODEN_AXE) {
                    com.sk89q.worldguard.WorldGuard worldGuard = com.sk89q.worldguard.WorldGuard.getInstance();
                    com.sk89q.worldedit.world.World bukkitWorld = BukkitAdapter.adapt(damagedPlayer.getWorld());
                    com.sk89q.worldguard.protection.ApplicableRegionSet regionSet = Objects.requireNonNull(worldGuard.getPlatform().getRegionContainer().get(bukkitWorld)).getApplicableRegions(BukkitAdapter.asBlockVector(damagedPlayer.getLocation()));

                    if (regionSet.queryState(null, godModeFlag) == StateFlag.State.DENY) {
                        if (isGod(damagedUser)) {
                            damagedUser.setGod(false);
                        }
                    }
                }
            }
        }
    }
    private void startGodModeCheckTask() {
        Bukkit.getScheduler().scheduleSyncRepeatingTask(this, () -> {
            for (Player player : Bukkit.getOnlinePlayers()) {
                updateGodModeStatus(player);
            }
        }, 0L, 100L); // Check every 5 seconds (20 ticks per second)
    }

    private boolean isGod(CMIUser user) {
        try {
            Method isGodMethod = user.getClass().getDeclaredMethod("hasGodMode");
            isGodMethod.setAccessible(true);
            return (boolean) isGodMethod.invoke(user);
        } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
            e.printStackTrace();
            return false;
        }
    }

    private void updateGodModeStatus(Player player) {
        CMIUser user = CMI.getInstance().getPlayerManager().getUser(player);

        if (user == null) {
            return;
        }

        com.sk89q.worldguard.WorldGuard worldGuard = com.sk89q.worldguard.WorldGuard.getInstance();
        com.sk89q.worldedit.world.World bukkitWorld = BukkitAdapter.adapt(player.getWorld());
        com.sk89q.worldguard.protection.ApplicableRegionSet regionSet = Objects.requireNonNull(worldGuard.getPlatform().getRegionContainer().get(bukkitWorld)).getApplicableRegions(BukkitAdapter.asBlockVector(player.getLocation()));

        if (regionSet.queryState(null, godModeFlag) == StateFlag.State.DENY) {
            if (isGod(user)) {
                user.setGod(false);
            }
        } else if (regionSet.queryState(null, godModeFlag) == StateFlag.State.ALLOW) {
            if (!isGod(user)) {
                user.setGod(true);
            }
        }
    }

It just returns error as if it doesnt exists
[20:18:24 WARN]: java.lang.NoSuchMethodException: com.Zrips.CMI.Containers.CMIUser.hasGodMode() [20:18:24 WARN]: at java.base/java.lang.Class.getDeclaredMethod(Class.java:2675) [20:18:24 WARN]: at ExtraFlags.jar//com.extraflags.ExtraFlags.isGod(ExtraFlags.java:132) [20:18:24 WARN]: at ExtraFlags.jar//com.extraflags.ExtraFlags.updateGodModeStatus(ExtraFlags.java:153) [20:18:24 WARN]: at ExtraFlags.jar//com.extraflags.ExtraFlags.lambda$startGodModeCheckTask$0(ExtraFlags.java:125) [20:18:24 WARN]: at org.bukkit.craftbukkit.v1_19_R3.scheduler.CraftTask.run(CraftTask.java:101) [20:18:24 WARN]: at org.bukkit.craftbukkit.v1_19_R3.scheduler.CraftScheduler.mainThreadHeartbeat(CraftScheduler.java:483) [20:18:24 WARN]: at net.minecraft.server.MinecraftServer.b(MinecraftServer.java:1485) [20:18:24 WARN]: at net.minecraft.server.dedicated.DedicatedServer.b(DedicatedServer.java:450) [20:18:24 WARN]: at net.minecraft.server.MinecraftServer.a(MinecraftServer.java:1399) [20:18:24 WARN]: at net.minecraft.server.MinecraftServer.w(MinecraftServer.java:1176) [20:18:24 WARN]: at net.minecraft.server.MinecraftServer.lambda$spin$0(MinecraftServer.java:322) [20:18:24 WARN]: at java.base/java.lang.Thread.run(Thread.java:833) [20:18:29 WARN]: java.lang.NoSuchMethodException: com.Zrips.CMI.Containers.CMIUser.hasGodMode() [20:18:29 WARN]: at java.base/java.lang.Class.getDeclaredMethod(Class.java:2675) [20:18:29 WARN]: at ExtraFlags.jar//com.extraflags.ExtraFlags.isGod(ExtraFlags.java:132) [20:18:29 WARN]: at ExtraFlags.jar//com.extraflags.ExtraFlags.updateGodModeStatus(ExtraFlags.java:153) [20:18:29 WARN]: at ExtraFlags.jar//com.extraflags.ExtraFlags.lambda$startGodModeCheckTask$0(ExtraFlags.java:125) [20:18:29 WARN]: at org.bukkit.craftbukkit.v1_19_R3.scheduler.CraftTask.run(CraftTask.java:101) [20:18:29 WARN]: at org.bukkit.craftbukkit.v1_19_R3.scheduler.CraftScheduler.mainThreadHeartbeat(CraftScheduler.java:483) [20:18:29 WARN]: at net.minecraft.server.MinecraftServer.b(MinecraftServer.java:1485) [20:18:29 WARN]: at net.minecraft.server.dedicated.DedicatedServer.b(DedicatedServer.java:450) [20:18:29 WARN]: at net.minecraft.server.MinecraftServer.a(MinecraftServer.java:1399) [20:18:29 WARN]: at net.minecraft.server.MinecraftServer.w(MinecraftServer.java:1176) [20:18:29 WARN]: at net.minecraft.server.MinecraftServer.lambda$spin$0(MinecraftServer.java:322) [20:18:29 WARN]: at java.base/java.lang.Thread.run(Thread.java:833)

@LucidAPs LucidAPs changed the title I cannot find setGodMode in the CMI api 😦 NoSuchMethodException CMIUser.hasGodMode Apr 19, 2023
@MrCrazys
Copy link

It's just .setGod(). Not setGodMode()
View here: https://github.com/Zrips/CMI-API/blob/master/src/com/Zrips/CMI/Containers/CMIUser.java#L633

I did a lot of work, but it still doesnt work

    @EventHandler
    public void onEntityDamage(EntityDamageByEntityEvent event) {
        Entity damager = event.getDamager();
        Entity damaged = event.getEntity();

        if (damaged instanceof Player) {
            Player damagedPlayer = (Player) damaged;
            CMIUser damagedUser = CMI.getInstance().getPlayerManager().getUser(damagedPlayer);

            if (damagedUser == null) {
                return;
            }

            if (damager instanceof Player) {
                Player damagerPlayer = (Player) damager;
                ItemStack itemInHand = damagerPlayer.getInventory().getItemInMainHand();

                if (itemInHand != null && itemInHand.getType() == Material.WOODEN_AXE) {
                    com.sk89q.worldguard.WorldGuard worldGuard = com.sk89q.worldguard.WorldGuard.getInstance();
                    com.sk89q.worldedit.world.World bukkitWorld = BukkitAdapter.adapt(damagedPlayer.getWorld());
                    com.sk89q.worldguard.protection.ApplicableRegionSet regionSet = Objects.requireNonNull(worldGuard.getPlatform().getRegionContainer().get(bukkitWorld)).getApplicableRegions(BukkitAdapter.asBlockVector(damagedPlayer.getLocation()));

                    if (regionSet.queryState(null, godModeFlag) == StateFlag.State.DENY) {
                        if (isGod(damagedUser)) {
                            damagedUser.setGod(false);
                        }
                    }
                }
            }
        }
    }
    private void startGodModeCheckTask() {
        Bukkit.getScheduler().scheduleSyncRepeatingTask(this, () -> {
            for (Player player : Bukkit.getOnlinePlayers()) {
                updateGodModeStatus(player);
            }
        }, 0L, 100L); // Check every 5 seconds (20 ticks per second)
    }

    private boolean isGod(CMIUser user) {
        try {
            Method isGodMethod = user.getClass().getDeclaredMethod("hasGodMode");
            isGodMethod.setAccessible(true);
            return (boolean) isGodMethod.invoke(user);
        } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
            e.printStackTrace();
            return false;
        }
    }

    private void updateGodModeStatus(Player player) {
        CMIUser user = CMI.getInstance().getPlayerManager().getUser(player);

        if (user == null) {
            return;
        }

        com.sk89q.worldguard.WorldGuard worldGuard = com.sk89q.worldguard.WorldGuard.getInstance();
        com.sk89q.worldedit.world.World bukkitWorld = BukkitAdapter.adapt(player.getWorld());
        com.sk89q.worldguard.protection.ApplicableRegionSet regionSet = Objects.requireNonNull(worldGuard.getPlatform().getRegionContainer().get(bukkitWorld)).getApplicableRegions(BukkitAdapter.asBlockVector(player.getLocation()));

        if (regionSet.queryState(null, godModeFlag) == StateFlag.State.DENY) {
            if (isGod(user)) {
                user.setGod(false);
            }
        } else if (regionSet.queryState(null, godModeFlag) == StateFlag.State.ALLOW) {
            if (!isGod(user)) {
                user.setGod(true);
            }
        }
    }

It just returns error as if it doesnt exists [20:18:24 WARN]: java.lang.NoSuchMethodException: com.Zrips.CMI.Containers.CMIUser.hasGodMode() [20:18:24 WARN]: at java.base/java.lang.Class.getDeclaredMethod(Class.java:2675) [20:18:24 WARN]: at ExtraFlags.jar//com.extraflags.ExtraFlags.isGod(ExtraFlags.java:132) [20:18:24 WARN]: at ExtraFlags.jar//com.extraflags.ExtraFlags.updateGodModeStatus(ExtraFlags.java:153) [20:18:24 WARN]: at ExtraFlags.jar//com.extraflags.ExtraFlags.lambda$startGodModeCheckTask$0(ExtraFlags.java:125) [20:18:24 WARN]: at org.bukkit.craftbukkit.v1_19_R3.scheduler.CraftTask.run(CraftTask.java:101) [20:18:24 WARN]: at org.bukkit.craftbukkit.v1_19_R3.scheduler.CraftScheduler.mainThreadHeartbeat(CraftScheduler.java:483) [20:18:24 WARN]: at net.minecraft.server.MinecraftServer.b(MinecraftServer.java:1485) [20:18:24 WARN]: at net.minecraft.server.dedicated.DedicatedServer.b(DedicatedServer.java:450) [20:18:24 WARN]: at net.minecraft.server.MinecraftServer.a(MinecraftServer.java:1399) [20:18:24 WARN]: at net.minecraft.server.MinecraftServer.w(MinecraftServer.java:1176) [20:18:24 WARN]: at net.minecraft.server.MinecraftServer.lambda$spin$0(MinecraftServer.java:322) [20:18:24 WARN]: at java.base/java.lang.Thread.run(Thread.java:833) [20:18:29 WARN]: java.lang.NoSuchMethodException: com.Zrips.CMI.Containers.CMIUser.hasGodMode() [20:18:29 WARN]: at java.base/java.lang.Class.getDeclaredMethod(Class.java:2675) [20:18:29 WARN]: at ExtraFlags.jar//com.extraflags.ExtraFlags.isGod(ExtraFlags.java:132) [20:18:29 WARN]: at ExtraFlags.jar//com.extraflags.ExtraFlags.updateGodModeStatus(ExtraFlags.java:153) [20:18:29 WARN]: at ExtraFlags.jar//com.extraflags.ExtraFlags.lambda$startGodModeCheckTask$0(ExtraFlags.java:125) [20:18:29 WARN]: at org.bukkit.craftbukkit.v1_19_R3.scheduler.CraftTask.run(CraftTask.java:101) [20:18:29 WARN]: at org.bukkit.craftbukkit.v1_19_R3.scheduler.CraftScheduler.mainThreadHeartbeat(CraftScheduler.java:483) [20:18:29 WARN]: at net.minecraft.server.MinecraftServer.b(MinecraftServer.java:1485) [20:18:29 WARN]: at net.minecraft.server.dedicated.DedicatedServer.b(DedicatedServer.java:450) [20:18:29 WARN]: at net.minecraft.server.MinecraftServer.a(MinecraftServer.java:1399) [20:18:29 WARN]: at net.minecraft.server.MinecraftServer.w(MinecraftServer.java:1176) [20:18:29 WARN]: at net.minecraft.server.MinecraftServer.lambda$spin$0(MinecraftServer.java:322) [20:18:29 WARN]: at java.base/java.lang.Thread.run(Thread.java:833)

It was removed in recent CMI versions.

@ChanceSD
Copy link

ChanceSD commented Jun 1, 2023

When will setGod be added back? What was the reason for removing it in the first place?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants