<commit_before>package nu.nerd.modmode;

import de.bananaco.bpermissions.api.ApiLayer;
import de.bananaco.bpermissions.api.util.CalculableType;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.logging.Level;
import net.minecraft.server.*;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.craftbukkit.entity.CraftPlayer;
import org.bukkit.entity.Player;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.plugin.java.JavaPlugin;

public class ModMode extends JavaPlugin {

    private final ModModeListener listener = new ModModeListener(this);
    public List<String> vanished;
    public List<String> fullvanished;
    public List<String> modmode;
    public boolean allowFlight;
    public boolean usingbperms;
    public String bPermsModGroup;
    public String bPermsModModeGroup;

    public boolean isInvisible(Player player) {
        return vanished.contains(player.getName()) || fullvanished.contains(player.getName());
    }

    public boolean isModMode(Player player) {
        return modmode.contains(player.getDisplayName());
    }

    public void enableVanish(Player player) {
        for (Player other : getServer().getOnlinePlayers()) {
            if (Permissions.hasPermission(other, Permissions.SHOWVANISHED)) {
                continue;
            }
            if (Permissions.hasPermission(other, Permissions.SHOWMODS)) {
                continue;
            }
            other.hidePlayer(player);
        }

        player.sendMessage(ChatColor.RED + "Poof!");
    }

    public void enableFullVanish(Player player) {
        for (Player other : getServer().getOnlinePlayers()) {
            if (Permissions.hasPermission(other, Permissions.SHOWVANISHED)) {
                continue;
            }
            other.hidePlayer(player);
        }

        player.sendMessage(ChatColor.RED + "You are fully vanished!");
    }

    public void disableVanish(Player player) {
        if (vanished.remove(player.getName()) || fullvanished.remove(player.getName())) {
            for (Player other : getServer().getOnlinePlayers()) {
                other.showPlayer(player);
            }

            player.sendMessage(ChatColor.RED + "You have reappeared!");
        } else {
            player.sendMessage(ChatColor.RED + "You are not vanished!");
        }
    }

    public void showVanishList(Player player) {
        String result = "";
        boolean first = true;
        for (String hidden : vanished) {
            if (getServer().getPlayerExact(hidden) == null) {
                continue;
            }

            if (first) {
                result += hidden + ChatColor.RED;
                first = false;
                continue;
            }

            result += ", " + hidden + ChatColor.RED;
        }

        for (String hidden : fullvanished) {
            if (getServer().getPlayerExact(hidden) == null) {
                continue;
            }

            if (first) {
                result += hidden + ChatColor.RED;
                first = false;
                continue;
            }

            result += ", " + hidden + ChatColor.RED;
        }

        if (result.length() == 0) {
            player.sendMessage(ChatColor.RED + "All players are visible!");
        } else {
            player.sendMessage(ChatColor.RED + "Vanished players: " + result);
        }
    }

    public void toggleModMode(Player player, boolean toggle, boolean onJoin) {
        String displayName = player.getName();
        String name = ChatColor.GREEN + player.getDisplayName() + ChatColor.WHITE;
        if (!toggle) {
            displayName = player.getDisplayName();
            name = displayName;
            if (usingbperms) {
                List<org.bukkit.World> worlds = getServer().getWorlds();
                for (org.bukkit.World world : worlds) {
                    getLogger().log(Level.INFO, "Removing " + name + " from " + bPermsModModeGroup + " in " + world.getName());
                    ApiLayer.removeGroup(world.getName(), CalculableType.USER, name, bPermsModModeGroup);
                    List<String> groups = Arrays.asList(ApiLayer.getGroups(world.getName(), CalculableType.USER, name));
                    
                    if (!groups.contains(bPermsModGroup)) {
                        ApiLayer.addGroup(world.getName(), CalculableType.USER, name, bPermsModGroup);
                    }
                }
            }
            player.sendMessage(ChatColor.RED + "You are no longer in ModMode!");
        } else {
            if (usingbperms) {
                List<org.bukkit.World> worlds = getServer().getWorlds();
                for (org.bukkit.World world : worlds) {
                    getLogger().log(Level.INFO, "Adding " + name + " to " + bPermsModModeGroup + " in " + world.getName());
                    ApiLayer.addGroup(world.getName(), CalculableType.USER, name, bPermsModModeGroup);
                    
                    List<String> groups = Arrays.asList(ApiLayer.getGroups(world.getName(), CalculableType.USER, name));
                    
                    if (groups.contains(bPermsModGroup)) {
                        ApiLayer.removeGroup(world.getName(), CalculableType.USER, name, bPermsModGroup);
                    }
                }
            }
            player.sendMessage(ChatColor.RED + "You are now in ModMode!");
        }

        Location loc = player.getLocation();
        EntityPlayer entityplayer = ((CraftPlayer) player).getHandle();
        MinecraftServer server = entityplayer.server;

        //send fake quit message
        if (!onJoin) {
            PlayerQuitEvent playerQuitEvent = new PlayerQuitEvent(player, "\u00A7e" + entityplayer.name + " left the game.");
            getServer().getPluginManager().callEvent(playerQuitEvent);
            if ((playerQuitEvent.getQuitMessage() != null) && (playerQuitEvent.getQuitMessage().length() > 0)) {
                server.getServerConfigurationManager().sendAll(new Packet3Chat(playerQuitEvent.getQuitMessage()));
            }
        }

        //save with the old name, change it, then load with the new name
        server.getServerConfigurationManager().playerFileData.save(entityplayer);
        entityplayer.name = name;
        entityplayer.displayName = displayName;
        server.getServerConfigurationManager().playerFileData.load(entityplayer);

        //send fake join message
        PlayerJoinEvent playerJoinEvent = new PlayerJoinEvent(player, "\u00A7e" + entityplayer.name + " joined the game.");
        getServer().getPluginManager().callEvent(playerJoinEvent);
        if ((playerJoinEvent.getJoinMessage() != null) && (playerJoinEvent.getJoinMessage().length() > 0)) {
            server.getServerConfigurationManager().sendAll(new Packet3Chat(playerJoinEvent.getJoinMessage()));
        }

        //untrack and track to show new name to clients
        ((WorldServer) entityplayer.world).tracker.untrackEntity(entityplayer);
        ((WorldServer) entityplayer.world).tracker.track(entityplayer);

        //teleport to avoid speedhack
        if (!toggle || onJoin) {
            loc = new Location(entityplayer.world.getWorld(), entityplayer.locX, entityplayer.locY, entityplayer.locZ, entityplayer.yaw, entityplayer.pitch);<commit_msg>Trying to fix invis modmodeness<commit_after>package nu.nerd.modmode;

import de.bananaco.bpermissions.api.ApiLayer;
import de.bananaco.bpermissions.api.util.CalculableType;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.logging.Level;
import net.minecraft.server.*;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.craftbukkit.CraftWorld;
import org.bukkit.craftbukkit.entity.CraftPlayer;
import org.bukkit.entity.Player;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.plugin.java.JavaPlugin;

public class ModMode extends JavaPlugin {

    private final ModModeListener listener = new ModModeListener(this);
    public List<String> vanished;
    public List<String> fullvanished;
    public List<String> modmode;
    public boolean allowFlight;
    public boolean usingbperms;
    public String bPermsModGroup;
    public String bPermsModModeGroup;

    public boolean isInvisible(Player player) {
        return vanished.contains(player.getName()) || fullvanished.contains(player.getName());
    }

    public boolean isModMode(Player player) {
        return modmode.contains(player.getDisplayName());
    }

    public void enableVanish(Player player) {
        for (Player other : getServer().getOnlinePlayers()) {
            if (Permissions.hasPermission(other, Permissions.SHOWVANISHED)) {
                continue;
            }
            if (Permissions.hasPermission(other, Permissions.SHOWMODS)) {
                continue;
            }
            other.hidePlayer(player);
        }

        player.sendMessage(ChatColor.RED + "Poof!");
    }

    public void enableFullVanish(Player player) {
        for (Player other : getServer().getOnlinePlayers()) {
            if (Permissions.hasPermission(other, Permissions.SHOWVANISHED)) {
                continue;
            }
            other.hidePlayer(player);
        }

        player.sendMessage(ChatColor.RED + "You are fully vanished!");
    }

    public void disableVanish(Player player) {
        if (vanished.remove(player.getName()) || fullvanished.remove(player.getName())) {
            for (Player other : getServer().getOnlinePlayers()) {
                other.showPlayer(player);
            }

            player.sendMessage(ChatColor.RED + "You have reappeared!");
        } else {
            player.sendMessage(ChatColor.RED + "You are not vanished!");
        }
    }

    public void showVanishList(Player player) {
        String result = "";
        boolean first = true;
        for (String hidden : vanished) {
            if (getServer().getPlayerExact(hidden) == null) {
                continue;
            }

            if (first) {
                result += hidden + ChatColor.RED;
                first = false;
                continue;
            }

            result += ", " + hidden + ChatColor.RED;
        }

        for (String hidden : fullvanished) {
            if (getServer().getPlayerExact(hidden) == null) {
                continue;
            }

            if (first) {
                result += hidden + ChatColor.RED;
                first = false;
                continue;
            }

            result += ", " + hidden + ChatColor.RED;
        }

        if (result.length() == 0) {
            player.sendMessage(ChatColor.RED + "All players are visible!");
        } else {
            player.sendMessage(ChatColor.RED + "Vanished players: " + result);
        }
    }

    public void toggleModMode(Player player, boolean toggle, boolean onJoin) {
        String displayName = player.getName();
        String name = ChatColor.GREEN + player.getDisplayName() + ChatColor.WHITE;
        if (!toggle) {
            displayName = player.getDisplayName();
            name = displayName;
            if (usingbperms) {
                List<org.bukkit.World> worlds = getServer().getWorlds();
                for (org.bukkit.World world : worlds) {
                    getLogger().log(Level.INFO, "Removing " + name + " from " + bPermsModModeGroup + " in " + world.getName());
                    ApiLayer.removeGroup(world.getName(), CalculableType.USER, name, bPermsModModeGroup);
                    List<String> groups = Arrays.asList(ApiLayer.getGroups(world.getName(), CalculableType.USER, name));
                    
                    if (!groups.contains(bPermsModGroup)) {
                        ApiLayer.addGroup(world.getName(), CalculableType.USER, name, bPermsModGroup);
                    }
                }
            }
            player.sendMessage(ChatColor.RED + "You are no longer in ModMode!");
        } else {
            if (usingbperms) {
                List<org.bukkit.World> worlds = getServer().getWorlds();
                for (org.bukkit.World world : worlds) {
                    getLogger().log(Level.INFO, "Adding " + name + " to " + bPermsModModeGroup + " in " + world.getName());
                    ApiLayer.addGroup(world.getName(), CalculableType.USER, name, bPermsModModeGroup);
                    
                    List<String> groups = Arrays.asList(ApiLayer.getGroups(world.getName(), CalculableType.USER, name));
                    
                    if (groups.contains(bPermsModGroup)) {
                        ApiLayer.removeGroup(world.getName(), CalculableType.USER, name, bPermsModGroup);
                    }
                }
            }
            player.sendMessage(ChatColor.RED + "You are now in ModMode!");
        }

        Location loc = player.getLocation();
        EntityPlayer entityplayer = ((CraftPlayer) player).getHandle();
        MinecraftServer server = entityplayer.server;

        //send fake quit message
        if (!onJoin) {
            PlayerQuitEvent playerQuitEvent = new PlayerQuitEvent(player, "\u00A7e" + entityplayer.name + " left the game.");
            getServer().getPluginManager().callEvent(playerQuitEvent);
            if ((playerQuitEvent.getQuitMessage() != null) && (playerQuitEvent.getQuitMessage().length() > 0)) {
                server.getServerConfigurationManager().sendAll(new Packet3Chat(playerQuitEvent.getQuitMessage()));
            }
        }

        //save with the old name, change it, then load with the new name
        server.getServerConfigurationManager().playerFileData.save(entityplayer);
        entityplayer.name = name;
        entityplayer.displayName = displayName;
        server.getServerConfigurationManager().playerFileData.load(entityplayer);

        //send fake join message
        PlayerJoinEvent playerJoinEvent = new PlayerJoinEvent(player, "\u00A7e" + entityplayer.name + " joined the game.");
        getServer().getPluginManager().callEvent(playerJoinEvent);
        if ((playerJoinEvent.getJoinMessage() != null) && (playerJoinEvent.getJoinMessage().length() > 0)) {
            server.getServerConfigurationManager().sendAll(new Packet3Chat(playerJoinEvent.getJoinMessage()));
        }

        //untrack and track to show new name to clients
        ((WorldServer) entityplayer.world).tracker.untrackEntity(entityplayer);
        ((WorldServer) entityplayer.world).tracker.track(entityplayer);
        
        server.getServerConfigurationManager().sendPacketNearby(player.getLocation().getX(), player.getLocation().getY(), player.getLocation().getZ(), 50, ((CraftWorld)player.getWorld()).getHandle().dimension, new Packet20NamedEntitySpawn(entityplayer));

        //teleport to avoid speedhack
        if (!toggle || onJoin) {
            loc = new Location(entityplayer.world.getWorld(), entityplayer.locX, entityplayer.locY, entityplayer.locZ, entityplayer.yaw, entityplayer.pitch);
{'fraction_non_alphanumeric': 0.1106252447461167, 'fraction_numerical': 0.001696906409084976, 'mean_word_length': 2.2903156538544125, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1664642', 'n_tokens_mistral': 4194, 'n_tokens_neox': 4010, 'n_words': 810}