net.alpenblock.bungeeperms.BungeePerms Java Examples

The following examples show how to use net.alpenblock.bungeeperms.BungeePerms. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: YAMLBackEnd.java    From BungeePerms with GNU General Public License v3.0 6 votes vote down vote up
@Override
public synchronized void saveUserPrefix(User user, String server, String world)
{
    server = Statics.toLower(server);
    world = Statics.toLower(world);

    String prefix = user.getPrefix();
    if (server != null)
    {
        prefix = user.getServer(server).getPrefix();
        if (world != null)
        {
            prefix = user.getServer(server).getWorld(world).getPrefix();
        }
    }
    permsconfusers.setStringAndSave("users." + (BungeePerms.getInstance().getConfig().isUseUUIDs() ? user.getUUID().toString() : user.getName()) + (server != null ? ".servers." + server + (world != null ? ".worlds." + world : "") : "") + ".prefix", prefix);
}
 
Example #2
Source File: Injector.java    From BungeePerms with GNU General Public License v3.0 6 votes vote down vote up
public static Permissible getPermissible(CommandSender sender)
{
    try
    {
        Field perm = getPermField(sender);
        if (perm == null)
        {
            return null;
        }
        perm.setAccessible(true);
        Permissible permissible = (Permissible) perm.get(sender);

        return permissible;
    }
    catch (Exception e)
    {
        BungeePerms.getInstance().getDebug().log(e);
    }
    return null;
}
 
Example #3
Source File: YAMLBackEnd.java    From BungeePerms with GNU General Public License v3.0 6 votes vote down vote up
@Override
public synchronized void saveUserSuffix(User user, String server, String world)
{
    server = Statics.toLower(server);
    world = Statics.toLower(world);

    String suffix = user.getSuffix();
    if (server != null)
    {
        suffix = user.getServer(server).getSuffix();
        if (world != null)
        {
            suffix = user.getServer(server).getWorld(world).getSuffix();
        }
    }
    permsconfusers.setStringAndSave("users." + (BungeePerms.getInstance().getConfig().isUseUUIDs() ? user.getUUID().toString() : user.getName()) + (server != null ? ".servers." + server + (world != null ? ".worlds." + world : "") : "") + ".suffix", suffix);
}
 
Example #4
Source File: Injector.java    From BungeePerms with GNU General Public License v3.0 6 votes vote down vote up
private static Field getPermField(CommandSender sender)
{
    Field perm = null;
    try
    {
        if (sender instanceof Player)
        {
            perm = Class.forName(getVersionedClassName("entity.CraftHumanEntity")).getDeclaredField("perm");
        }
        else if (sender instanceof ConsoleCommandSender)
        {
            perm = Class.forName(getVersionedClassName("command.ServerCommandSender")).getDeclaredField("perm");
        }
    }
    catch (Exception e)
    {
        BungeePerms.getInstance().getDebug().log(e);
    }
    return perm;
}
 
Example #5
Source File: Injector.java    From BungeePerms with GNU General Public License v3.0 6 votes vote down vote up
public static void inject(CommandSender sender, Permissible newpermissible)
{
    try
    {
        Field perm = getPermField(sender);
        if (perm == null)
        {
            return;
        }
        perm.setAccessible(true);
        perm.set(sender, newpermissible);
    }
    catch (Exception e)
    {
        BungeePerms.getInstance().getDebug().log(e);
    }
}
 
Example #6
Source File: BukkitMessageEncoder.java    From BungeePerms with GNU General Public License v3.0 6 votes vote down vote up
@Override
public MessageEncoder event(HoverEvent hoverEvent)
{
    if (BungeePerms.getInstance().getPlugin().isChatApiPresent())
    {
        if (hoverEvent == null)
        {
            builder = builder.event((net.md_5.bungee.api.chat.HoverEvent) null);
        }
        else
        {
            cache = null;
            net.md_5.bungee.api.chat.HoverEvent.Action action = net.md_5.bungee.api.chat.HoverEvent.Action.valueOf(hoverEvent.getAction().name());
            builder = builder.event(new net.md_5.bungee.api.chat.HoverEvent(action, convert(hoverEvent.getValue().create())));
        }
    }

    return this;
}
 
Example #7
Source File: MySQLBackEnd.java    From BungeePerms with GNU General Public License v3.0 6 votes vote down vote up
@Override
public synchronized void saveUserTimedPerms(User user, String server, String world)
{
    server = Statics.toLower(server);
    world = server == null ? null : Statics.toLower(world);

    List<TimedValue<String>> perms = user.getTimedPerms();
    if (server != null)
    {
        perms = user.getServer(server).getTimedPerms();
        if (world != null)
        {
            perms = user.getServer(server).getWorld(world).getTimedPerms();
        }
    }

    adapter.saveData(BungeePerms.getInstance().getConfig().isUseUUIDs() ? user.getUUID().toString() : user.getName(),
                     EntityType.User, "timedpermissions",
                     mkValueListTimed(perms, server, world), server, world);
}
 
Example #8
Source File: BungeeNotifier.java    From BungeePerms with GNU General Public License v3.0 6 votes vote down vote up
private void sendConfig(ServerInfo info)
{
    synchronized (this)
    {
        long now = System.currentTimeMillis();
        if (lastConfigUpdate + 5 * 60 * 1000 < now)
        {
            lastConfigUpdate = now;
            info.sendData(BungeePerms.CHANNEL, ("configcheck"
                                                + ";" + info.getName()
                                                + ";" + config.getBackendType()
                                                + ";" + config.isUseUUIDs()
                                                + ";" + config.getResolvingMode()
                                                + ";" + config.isGroupPermission()
                                                + ";" + config.isUseRegexPerms()).getBytes());
        }
    }
}
 
Example #9
Source File: MysqlPermsAdapter.java    From BungeePerms with GNU General Public License v3.0 6 votes vote down vote up
public void clearTable(String table)
{
    PreparedStatement stmt = null;
    try
    {
        mysql.checkConnection();
        stmt = mysql.stmt("TRUNCATE `" + table + "`");
        mysql.runQuery(stmt);
    }
    catch (Exception e)
    {
        BungeePerms.getInstance().getDebug().log(e);
    }
    finally
    {
        Mysql.close(stmt);
    }
}
 
Example #10
Source File: GroupProcessor.java    From BungeePerms with GNU General Public License v3.0 6 votes vote down vote up
@Override
public List<BPPermission> process(List<BPPermission> perms, Sender s)
{
    if (s == null)
    {
        return perms;
    }
    BPConfig config = BungeePerms.getInstance().getConfig();
    if (config.isGroupPermission())
    {
        PermissionsManager pm = BungeePerms.getInstance().getPermissionsManager();
        User u = config.isUseUUIDs() ? pm.getUser(s.getUUID()) : pm.getUser(s.getName());
        if (u == null)
        {
            return perms;
        }

        for (String g : u.getGroupsString())
        {
            perms.add(0, new BPPermission("group." + Statics.toLower(g), "GroupProcessor", true, null, null, null, null));
        }
    }

    return perms;
}
 
Example #11
Source File: BungeeMessageEncoder.java    From BungeePerms with GNU General Public License v3.0 6 votes vote down vote up
public BungeeMessageEncoder(MessageEncoder original)
{
    super(original);
    if (!(original instanceof BungeeMessageEncoder))
    {
        throw new IllegalArgumentException("original is not a BungeeMessageEncoder");
    }

    if (BungeePerms.getInstance().getPlugin().isChatApiPresent())
    {
        builder = ((BungeeMessageEncoder) original).builder;
    }

    list = new ArrayList<>(((BungeeMessageEncoder) original).list);
    current = ((BungeeMessageEncoder) original).current;
}
 
Example #12
Source File: UUIDFetcher.java    From BungeePerms with GNU General Public License v3.0 6 votes vote down vote up
public static String getPlayerNameFromMojang(UUID uuid)
{
    String suuid = uuid.toString().toLowerCase().replaceAll("-", "");

    try
    {
        URL url = new URL("https://sessionserver.mojang.com/session/minecraft/profile/" + suuid);
        URLConnection con = url.openConnection();
        InputStream in = con.getInputStream();
        byte[] buffer = new byte[con.getContentLength()];
        int read = in.read(buffer);
        String res = new String(buffer, 0, read);
        Gson gson = new Gson();
        PlayerNameFetchResult result = gson.fromJson(res, PlayerNameFetchResult.class);
        return result.getName();
    }
    catch (Exception e)
    {
        BungeePerms.getInstance().getDebug().log(e);
    }
    return null;
}
 
Example #13
Source File: MysqlPermsAdapter.java    From BungeePerms with GNU General Public License v3.0 6 votes vote down vote up
public void removeGroupReferences(String group)
{
    PreparedStatement stmt = null;
    try
    {
        mysql.checkConnection();
        stmt = mysql.stmt("DELETE FROM `" + table + "` WHERE `value` = ? AND `key` IN ('groups', 'timedgroups', 'inheritances', 'timedinheritances')");
        stmt.setString(1, group);
        mysql.runQuery(stmt);
    }
    catch (Exception e)
    {
        BungeePerms.getInstance().getDebug().log(e);
    }
    finally
    {
        Mysql.close(stmt);
    }
}
 
Example #14
Source File: BukkitMessageEncoder.java    From BungeePerms with GNU General Public License v3.0 6 votes vote down vote up
@Override
public MessageEncoder event(ClickEvent clickEvent)
{
    if (BungeePerms.getInstance().getPlugin().isChatApiPresent())
    {
        if (clickEvent == null)
        {
            builder = builder.event((net.md_5.bungee.api.chat.ClickEvent) null);
        }
        else
        {
            cache = null;
            net.md_5.bungee.api.chat.ClickEvent.Action action = net.md_5.bungee.api.chat.ClickEvent.Action.valueOf(clickEvent.getAction().name());
            builder = builder.event(new net.md_5.bungee.api.chat.ClickEvent(action, clickEvent.getValue()));
        }
    }

    return this;
}
 
Example #15
Source File: BungeeMessageEncoder.java    From BungeePerms with GNU General Public License v3.0 6 votes vote down vote up
@Override
public MessageEncoder event(ClickEvent clickEvent)
{
    if (BungeePerms.getInstance().getPlugin().isChatApiPresent())
    {
        if (clickEvent == null)
        {
            builder = builder.event((net.md_5.bungee.api.chat.ClickEvent) null);
        }
        else
        {
            cache = null;
            net.md_5.bungee.api.chat.ClickEvent.Action action = net.md_5.bungee.api.chat.ClickEvent.Action.valueOf(clickEvent.getAction().name());
            builder = builder.event(new net.md_5.bungee.api.chat.ClickEvent(action, clickEvent.getValue()));
        }
    }

    return this;
}
 
Example #16
Source File: BukkitSender.java    From BungeePerms with GNU General Public License v3.0 6 votes vote down vote up
@Override
    public UUID getUUID()
    {
        if (!BungeePerms.getInstance().getConfig().isUseUUIDs())
        {
            throw new IllegalStateException("useuuid not enabled but uuid functionality called");
        }
        if (sender instanceof ConsoleCommandSender)
        {
            return UUID.fromString("00000000-0000-0000-0000-000000000000");
        }
        else if (sender instanceof Player)
        {
            return ((Player) sender).getUniqueId();
        }
        else
        {
            return null;
//            throw new UnsupportedOperationException("CommandSender derivative " + sender.getClass().getName() + " is unknown!");
        }
    }
 
Example #17
Source File: YAMLBackEnd.java    From BungeePerms with GNU General Public License v3.0 6 votes vote down vote up
@Override
public synchronized void saveUserTimedPerms(User user, String server, String world)
{
    server = Statics.toLower(server);
    world = server == null ? null : Statics.toLower(world);

    List<TimedValue<String>> timedperms;
    String key = "users." + (BungeePerms.getInstance().getConfig().isUseUUIDs() ? user.getUUID().toString() : user.getName());
    if (server == null)
    {
        timedperms = user.getTimedPerms();
    }
    else if (world == null)
    {
        timedperms = user.getServer(server).getTimedPerms();
        key += ".servers." + server;
    }
    else
    {
        timedperms = user.getServer(server).getWorld(world).getTimedPerms();
        key += ".servers." + server + ".worlds." + world;
    }

    setTimed(permsconfusers, key + ".timedpermissions", timedperms);
    permsconfusers.save();
}
 
Example #18
Source File: VersionCheck.java    From BungeePerms with GNU General Public License v3.0 6 votes vote down vote up
public static void checkForUpdate()
{
    try
    {
        //get current version
        int curVersion = BungeePerms.getInstance().getPlugin().getBuild();

        URL url = new URL("https://ci.wea-ondara.net/job/BungeePerms/api/json");
        URLConnection request = url.openConnection();
        request.connect();
        JsonParser jp = new JsonParser();
        JsonElement root = jp.parse(new InputStreamReader((InputStream) request.getContent()));
        JsonObject j = root.getAsJsonObject();
        int remoteVersion = j.getAsJsonObject("lastSuccessfulBuild").get("number").getAsInt();

        if (remoteVersion > curVersion)
        {
            BungeePerms.getInstance().getPlugin().getConsole().sendMessage("[BungeePerms] " + Lang.translate(Lang.MessageType.UPDATE_AVAILABLE));
        }
    }
    catch (Exception e)
    {
    }
}
 
Example #19
Source File: MySQLBackEnd.java    From BungeePerms with GNU General Public License v3.0 6 votes vote down vote up
@Override
public synchronized void saveUserPerms(User user, String server, String world)
{
    server = Statics.toLower(server);
    world = server == null ? null : Statics.toLower(world);

    List<String> perms = user.getPerms();
    if (server != null)
    {
        perms = user.getServer(server).getPerms();
        if (world != null)
        {
            perms = user.getServer(server).getWorld(world).getPerms();
        }
    }

    adapter.saveData(BungeePerms.getInstance().getConfig().isUseUUIDs() ? user.getUUID().toString() : user.getName(),
                     EntityType.User, "permissions",
                     mkValueList(perms, server, world), server, world);
}
 
Example #20
Source File: Permission_BungeePerms.java    From BungeePerms with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean playerAddGroup(String world, String player, String group)
{
    User u = BungeePerms.getInstance().getPermissionsManager().getUser(player);
    if (u == null)
        return false;

    Group g = BungeePerms.getInstance().getPermissionsManager().getGroup(group);
    if (g == null)
        return false;

    if (u.getGroups().contains(g))
        return false;

    BungeePerms.getInstance().getPermissionsManager().addUserGroup(u, g);
    return true;
}
 
Example #21
Source File: Permission_BungeePerms.java    From BungeePerms with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean playerRemoveGroup(String world, String player, String group)
{
    User u = BungeePerms.getInstance().getPermissionsManager().getUser(player);
    if (u == null)
        return false;

    Group g = BungeePerms.getInstance().getPermissionsManager().getGroup(group);
    if (g == null)
        return false;

    if (!u.getGroups().contains(g))
        return false;

    BungeePerms.getInstance().getPermissionsManager().removeUserGroup(u, g);
    return true;
}
 
Example #22
Source File: BukkitNotifier.java    From BungeePerms with GNU General Public License v3.0 6 votes vote down vote up
private void sendPMAll(String msg, String origin)
{
    //if standalone don't notify bungee
    if (config.isStandalone())
    {
        return;
    }
    List<Player> players = BukkitPlugin.getBukkitPlayers();
    Player p = players.iterator().hasNext() ? players.iterator().next() : null;
    if (p != null)
    {
        p.sendPluginMessage(BukkitPlugin.getInstance(), BungeePerms.CHANNEL, msg.getBytes());//todo use utf8 encoding

        //send config for match checking
        sendConfig(p);
    }
}
 
Example #23
Source File: BukkitNotifier.java    From BungeePerms with GNU General Public License v3.0 6 votes vote down vote up
private void sendPM(UUID player, String msg, String origin)
{
    //if standalone don't notify bungee
    if (config.isStandalone())
    {
        return;
    }

    Player p = Bukkit.getPlayer(player);
    if (p != null)
    {
        p.sendPluginMessage(BukkitPlugin.getInstance(), BungeePerms.CHANNEL, msg.getBytes());

        //send config for match checking
        sendConfig(p);
    }
    else
    {
        sendPMAll(msg, origin);
    }
}
 
Example #24
Source File: BukkitNotifier.java    From BungeePerms with GNU General Public License v3.0 6 votes vote down vote up
private void sendPM(String player, String msg, String origin)
{
    //if standalone don't notify bungee
    if (config.isStandalone())
    {
        return;
    }

    Player p = Bukkit.getPlayer(player);
    if (p != null)
    {
        p.sendPluginMessage(BukkitPlugin.getInstance(), BungeePerms.CHANNEL, msg.getBytes());

        //send config for match checking
        sendConfig(p);
    }
    else
    {
        sendPMAll(msg, origin);
    }
}
 
Example #25
Source File: BukkitPluginMessageSender.java    From BungeePerms with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void sendPluginMessage(String target, String channel, String msg)
{
    if (!target.equalsIgnoreCase("bungee"))
    {
        return;
    }
    List<Player> players = BukkitPlugin.getBukkitPlayers();
    Player p = players.iterator().hasNext() ? players.iterator().next() : null;
    if (p == null)
    {
        BungeePerms.getLogger().info("No server found for " + target);
        return;
    }

    p.sendPluginMessage(BukkitPlugin.getInstance(), BungeePerms.CHANNEL, msg.getBytes());
}
 
Example #26
Source File: SuperPermsPreProcessor.java    From BungeePerms with GNU General Public License v3.0 6 votes vote down vote up
@Override
public List<BPPermission> process(List<BPPermission> perms, Sender s)
{
    BukkitConfig config = (BukkitConfig) BungeePerms.getInstance().getConfig();
    if (!config.isSuperpermscompat())
    {
        return perms;
    }

    if (s != null)
    {
        List<String> l = getSuperPerms(s);
        for (int i = 0; i < l.size(); i++)
        {
            perms.add(i, new BPPermission(l.get(i), "SuperPerms", true, null, null, null, null));
        }
    }

    //expand permissions
    expandChildPermsWithOrigin(perms);

    return perms;
}
 
Example #27
Source File: MySQLBackEnd.java    From BungeePerms with GNU General Public License v3.0 6 votes vote down vote up
@Override
public synchronized void saveUserDisplay(User user, String server, String world)
{
    server = Statics.toLower(server);
    world = Statics.toLower(world);

    String display = user.getDisplay();
    if (server != null)
    {
        display = user.getServer(server).getDisplay();
        if (world != null)
        {
            display = user.getServer(server).getWorld(world).getDisplay();
        }
    }
    adapter.saveData(BungeePerms.getInstance().getConfig().isUseUUIDs() ? user.getUUID().toString() : user.getName(),
                     EntityType.User, "display", mkList(new ValueEntry(display, server, world)), server, world);
}
 
Example #28
Source File: WorldEditBridge.java    From BungeePerms with GNU General Public License v3.0 6 votes vote down vote up
public void uninject(Plugin plugin)
{
    BungeePerms.getLogger().info("Uninjection of Bungeeperms into WorldEdit");
    try
    {
        WorldEditPlugin we = (WorldEditPlugin) plugin;

        //inject BungeePerms
        Field f = we.getPermissionsResolver().getClass().getDeclaredField("enabledResolvers");
        f.setAccessible(true);
        ((List) f.get(we.getPermissionsResolver())).remove(BungeePermsResolver.class);

        we.getPermissionsResolver().findResolver();
    }
    catch (Exception ex)//todo report error
    {
    }
}
 
Example #29
Source File: MysqlPermsAdapter.java    From BungeePerms with GNU General Public License v3.0 6 votes vote down vote up
public void deleteEntity(String name, EntityType type)
{
    PreparedStatement stmt = null;
    try
    {
        mysql.checkConnection();
        stmt = mysql.stmt("DELETE FROM `" + table + "` WHERE `name`=? AND `type`=" + type.getCode());
        stmt.setString(1, name);
        mysql.runQuery(stmt);
    }
    catch (Exception e)
    {
        BungeePerms.getInstance().getDebug().log(e);
    }
    finally
    {
        Mysql.close(stmt);
    }
}
 
Example #30
Source File: BungeePermsResolver.java    From BungeePerms with GNU General Public License v3.0 6 votes vote down vote up
public static PermissionsResolver factory(Server server, YAMLProcessor config)
{
    try
    {
        PermissionsManager manager = BungeePerms.getInstance().getPermissionsManager();

        if (manager == null)
        {
            return null;
        }

        return new BungeePermsResolver(server, manager);
    }
    catch (Throwable t)
    {
        return null;
    }
}