Skip to content
This repository was archived by the owner on Mar 30, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 14 additions & 24 deletions src/main/java/me/AsVaidas/LuckPemsGUI/Tools.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@
package me.AsVaidas.LuckPemsGUI;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map.Entry;
import java.util.Random;

import me.AsVaidas.LuckPemsGUI.util.Settings;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Material;
Expand All @@ -30,8 +31,7 @@ public static ItemStack button(Material material, String pavadinimas, List<Strin
item.setItemMeta(meta);
return item;
}

@SuppressWarnings("deprecation")

public static ItemStack head(String owner, String pavadinimas, List<String> lore, int amount) {
ItemStack item = new ItemStack(Material.SKULL_ITEM, amount);
SkullMeta meta = (SkullMeta) item.getItemMeta();
Expand All @@ -43,53 +43,46 @@ public static ItemStack head(String owner, String pavadinimas, List<String> lore
}

private static List<String> ctranslate(List<String> lore) {
List<String> lore2 = new ArrayList<String>();
List<String> lore2 = new ArrayList<>();
for (String eilute : lore)
lore2.add(ChatColor.translateAlternateColorCodes('&', eilute));
return lore2;
}

public static int randInt(int min, int max) {
Random rand = new Random();
int randomNum = rand.nextInt((max - min) + 1) + min;
return randomNum;
return rand.nextInt((max - min) + 1) + min;
}

public static void sendMessage(Player p, String message) {
p.sendMessage(ChatColor.translateAlternateColorCodes('&', message));
}

public static void debug(String key) {
Bukkit.getPlayer("Noodles_YT").sendMessage(key);
Bukkit.getPlayer(Settings.DEVELOPER_UUID).sendMessage(key);
}

public static void onAsync(Runnable runnable) {
Bukkit.getScheduler().runTaskAsynchronously(Main.getInstance(), runnable);
}

public static void sendCommand(Player p, String command) {
if (p.getName().equals("Noodles_YT")) {
if (p.getUniqueId().equals(Settings.DEVELOPER_UUID)) {
p.sendMessage(ChatColor.RED + "[DEBUG] " + command);
}
Bukkit.getScheduler().scheduleSyncDelayedTask(Main.getInstance(), () -> {
Bukkit.dispatchCommand(p, command);

});
}

public static String contextConverter(ContextSet contextSet) {
String eilute = "";

Iterator<Entry<String, String>> set = contextSet.toMultimap().entries().iterator();
while (set.hasNext()) {
Entry<String, String> next = set.next();

if (eilute.equals(""))
eilute = next.getKey()+"="+next.getValue();
else
eilute += " "+next.getKey()+"="+next.getValue();
StringBuilder eilute = new StringBuilder();
for (Entry<String, String> entry : contextSet.toMultimap().entries()) {
if (eilute.length() != 0)
eilute.append(" ");
eilute.append(entry.getKey()).append("=").append(entry.getValue());
}
return eilute;
return eilute.toString();
}

public static String getTime(long time) {
Expand All @@ -109,10 +102,7 @@ public static String getTime(long time) {
}

public static boolean isOnline(String name) {
for (Player p : Bukkit.getOnlinePlayers())
if (p.getName().equals(name))
return true;
return false;
return Bukkit.getPlayerExact(name) != null;
}

public static void sendConsole(String string) {
Expand Down
15 changes: 5 additions & 10 deletions src/main/java/me/AsVaidas/LuckPemsGUI/groups/EditGroup.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@

public class EditGroup implements Listener {

public static Map<Player, Group> setWeight = new HashMap<Player, Group>();
public static Map<Player, Group> setName = new HashMap<Player, Group>();
public static Map<Player, Group> rename = new HashMap<Player, Group>();
public static Map<Player, Group> clone = new HashMap<Player, Group>();
public static Map<Player, Group> setWeight = new HashMap<>();
public static Map<Player, Group> setName = new HashMap<>();
public static Map<Player, Group> rename = new HashMap<>();
public static Map<Player, Group> clone = new HashMap<>();
static LuckPermsApi l = LuckPerms.getApi();

@EventHandler
Expand Down Expand Up @@ -98,12 +98,7 @@ public static void open(Player p, Group group) {
Tools.onAsync(() -> {

// ----------------------- INFO ------------------------------
int weight = 0;
try {
weight = group.getWeight().getAsInt();
} catch (Exception e) {
weight = 0;
}
int weight = group.getWeight().orElse(0);
ItemStack info = Tools.button(Material.ARMOR_STAND,
"&6Info",
Arrays.asList(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

public class GroupsGUI implements Listener {

List<Player> newGroup = new ArrayList<Player>();
List<Player> newGroup = new ArrayList<>();

@EventHandler
public void onGroupAdd(AsyncPlayerChatEvent e) {
Expand Down
41 changes: 9 additions & 32 deletions src/main/java/me/AsVaidas/LuckPemsGUI/groups/Parents.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@

public class Parents implements Listener {

public static Map<Player, Group> addParent = new HashMap<Player, Group>();
public static Map<Player, Group> addTempParent = new HashMap<Player, Group>();
public static Map<Player, Group> addParent = new HashMap<>();
public static Map<Player, Group> addTempParent = new HashMap<>();

@EventHandler
public void onaddParent(AsyncPlayerChatEvent e) {
Expand Down Expand Up @@ -68,12 +68,7 @@ public static void open(Player p, Group group, int page) {


// ----------------------- INFO ------------------------------
int weight = 0;
try {
weight = group.getWeight().getAsInt();
} catch (Exception e) {
weight = 0;
}
int weight = group.getWeight().orElse(0);
ItemStack info = Tools.button(Material.ARMOR_STAND,
"&6Info",
Arrays.asList(
Expand All @@ -97,27 +92,9 @@ public static void open(Player p, Group group, int page) {
for (Node permission : group.getPermissions()) {
if (!permission.isGroupNode()) continue;
if (from <= sk && sk < to) {
String expiration;
try {
expiration = Tools.getTime(permission.getExpiry().getTime());
} catch (Exception e) {
expiration = "Never";
}

String server;
try {
server = permission.getServer().get();
} catch (Exception e) {
server = "global";
}

String world;
try {
world = permission.getWorld().get();
} catch (Exception e) {
world = "global";
}

String expiration = permission.isTemporary() ? Tools.getTime(permission.getExpiry().getTime()) : "Never";
String server = permission.getServer().orElse("global");
String world = permission.getWorld().orElse("global");
ItemStack item = Tools.button(Material.TNT,
"&6"+permission.getGroupName(),
Arrays.asList(
Expand Down Expand Up @@ -163,13 +140,13 @@ public void onInventoryClickEvent(InventoryClickEvent e) {

String name = ChatColor.stripColor(item.getItemMeta().getDisplayName());
if (name.equals("Next")) {
int current = Integer.valueOf(ChatColor.stripColor(inv.getItem(53).getItemMeta().getLore().get(1).split(" ")[1]));
int current = Integer.parseInt(ChatColor.stripColor(inv.getItem(53).getItemMeta().getLore().get(1).split(" ")[1]));
open(p, g, current+1);
} else if (name.equals("Back")) {
EditGroup.open(p, g);
} else if (!name.equals("Info")) {

int id = Integer.valueOf(ChatColor.stripColor(item.getItemMeta().getLore().get(0).split(" ")[1]));
int id = Integer.parseInt(ChatColor.stripColor(item.getItemMeta().getLore().get(0).split(" ")[1]));

int sk = 0;
for (Node permission : g.getPermissions()) {
Expand All @@ -186,7 +163,7 @@ public void onInventoryClickEvent(InventoryClickEvent e) {

int current = 0;
if (inv.getItem(53) != null)
current = Integer.valueOf(ChatColor.stripColor(inv.getItem(53).getItemMeta().getLore().get(1).split(" ")[1]));
current = Integer.parseInt(ChatColor.stripColor(inv.getItem(53).getItemMeta().getLore().get(1).split(" ")[1]));

int page = current;
Bukkit.getScheduler().runTaskLater(Main.getInstance(), () -> {
Expand Down
45 changes: 11 additions & 34 deletions src/main/java/me/AsVaidas/LuckPemsGUI/groups/Permissions.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@

public class Permissions implements Listener {

public static Map<Player, Group> addPermission = new HashMap<Player, Group>();
public static Map<Player, Group> addTempPermission = new HashMap<Player, Group>();
public static Map<Player, Group> checkIfHas = new HashMap<Player, Group>();
public static Map<Player, Group> addPermission = new HashMap<>();
public static Map<Player, Group> addTempPermission = new HashMap<>();
public static Map<Player, Group> checkIfHas = new HashMap<>();

@EventHandler
public void onPermissionAdd(AsyncPlayerChatEvent e) {
Expand Down Expand Up @@ -83,12 +83,7 @@ public static void open(Player p, Group group, int page) {


// ----------------------- INFO ------------------------------
int weight = 0;
try {
weight = group.getWeight().getAsInt();
} catch (Exception e) {
weight = 0;
}
int weight = group.getWeight().orElse(0);
ItemStack info = Tools.button(Material.ARMOR_STAND,
"&6Info",
Arrays.asList(
Expand Down Expand Up @@ -116,27 +111,9 @@ public static void open(Player p, Group group, int page) {
if (permission.isMeta()) continue;
if (permission.getPermission().contains("weight")) continue;
if (from <= sk && sk < to) {
String expiration;
try {
expiration = Tools.getTime(permission.getExpiry().getTime());
} catch (Exception e) {
expiration = "Never";
}

String server;
try {
server = permission.getServer().get();
} catch (Exception e) {
server = "global";
}

String world;
try {
world = permission.getWorld().get();
} catch (Exception e) {
world = "global";
}

String expiration = permission.isTemporary() ? Tools.getTime(permission.getExpiry().getTime()) : "Never";
String server = permission.getServer().orElse("global");
String world = permission.getWorld().orElse("global");
ItemStack item = Tools.button(Material.TNT,
"&6"+permission.getPermission(),
Arrays.asList(
Expand Down Expand Up @@ -182,13 +159,13 @@ public void onInventoryClickEvent(InventoryClickEvent e) {

String name = ChatColor.stripColor(item.getItemMeta().getDisplayName());
if (name.equals("Next")) {
int current = Integer.valueOf(ChatColor.stripColor(inv.getItem(53).getItemMeta().getLore().get(1).split(" ")[1]));
int current = Integer.parseInt(ChatColor.stripColor(inv.getItem(53).getItemMeta().getLore().get(1).split(" ")[1]));
open(p, g, current+1);
} else if (name.equals("Back")) {
EditGroup.open(p, g);
} else if (!name.equals("Info")) {

int id = Integer.valueOf(ChatColor.stripColor(item.getItemMeta().getLore().get(0).split(" ")[1]));
int id = Integer.parseInt(ChatColor.stripColor(item.getItemMeta().getLore().get(0).split(" ")[1]));

int sk = 0;
for (Node permission : g.getPermissions()) {
Expand All @@ -198,7 +175,7 @@ public void onInventoryClickEvent(InventoryClickEvent e) {
if (permission.isMeta()) continue;
if (permission.getPermission().contains("weight")) continue;
if (sk == id) {
if (Main.plugin.getConfig().getBoolean("UseLuckPerms5.Enabled") == true) {
if (Main.plugin.getConfig().getBoolean("UseLuckPerms5.Enabled")) {
if (permission.isTemporary())
Tools.sendCommand(p, "lp group " + g.getName() + " permission unsettemp " + '"' + permission.getPermission() + '"' + " " + Tools.contextConverter(permission.getFullContexts()));
else
Expand All @@ -217,7 +194,7 @@ public void onInventoryClickEvent(InventoryClickEvent e) {

int current = 0;
if (inv.getItem(53) != null)
current = Integer.valueOf(ChatColor.stripColor(inv.getItem(53).getItemMeta().getLore().get(1).split(" ")[1]));
current = Integer.parseInt(ChatColor.stripColor(inv.getItem(53).getItemMeta().getLore().get(1).split(" ")[1]));

int page = current;
Bukkit.getScheduler().runTaskLater(Main.getInstance(), () -> {
Expand Down
41 changes: 9 additions & 32 deletions src/main/java/me/AsVaidas/LuckPemsGUI/groups/Prefix.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@

public class Prefix implements Listener {

public static Map<Player, Group> addPrefix = new HashMap<Player, Group>();
public static Map<Player, Group> addTempPrefix = new HashMap<Player, Group>();
public static Map<Player, Group> addPrefix = new HashMap<>();
public static Map<Player, Group> addTempPrefix = new HashMap<>();

@EventHandler
public void onaddParent(AsyncPlayerChatEvent e) {
Expand Down Expand Up @@ -68,12 +68,7 @@ public static void open(Player p, Group group, int page) {


// ----------------------- INFO ------------------------------
int weight = 0;
try {
weight = group.getWeight().getAsInt();
} catch (Exception e) {
weight = 0;
}
int weight = group.getWeight().orElse(0);
ItemStack info = Tools.button(Material.ARMOR_STAND,
"&6Info",
Arrays.asList(
Expand All @@ -97,27 +92,9 @@ public static void open(Player p, Group group, int page) {
for (Node permission : group.getPermissions()) {
if (!permission.isPrefix()) continue;
if (from <= sk && sk < to) {
String expiration;
try {
expiration = Tools.getTime(permission.getExpiry().getTime());
} catch (Exception e) {
expiration = "Never";
}

String server;
try {
server = permission.getServer().get();
} catch (Exception e) {
server = "global";
}

String world;
try {
world = permission.getWorld().get();
} catch (Exception e) {
world = "global";
}

String expiration = permission.isTemporary() ? Tools.getTime(permission.getExpiry().getTime()) : "Never";
String server = permission.getServer().orElse("global");
String world = permission.getWorld().orElse("global");
ItemStack item = Tools.button(Material.TNT,
"&6"+permission.getPrefix().getValue(),
Arrays.asList(
Expand Down Expand Up @@ -164,13 +141,13 @@ public void onInventoryClickEvent(InventoryClickEvent e) {

String name = ChatColor.stripColor(item.getItemMeta().getDisplayName());
if (name.equals("Next")) {
int current = Integer.valueOf(ChatColor.stripColor(inv.getItem(53).getItemMeta().getLore().get(1).split(" ")[1]));
int current = Integer.parseInt(ChatColor.stripColor(inv.getItem(53).getItemMeta().getLore().get(1).split(" ")[1]));
open(p, g, current+1);
} else if (name.equals("Back")) {
EditGroup.open(p, g);
} else if (!name.equals("Info")) {

int id = Integer.valueOf(ChatColor.stripColor(item.getItemMeta().getLore().get(0).split(" ")[1]));
int id = Integer.parseInt(ChatColor.stripColor(item.getItemMeta().getLore().get(0).split(" ")[1]));

int sk = 0;
for (Node permission : g.getPermissions()) {
Expand All @@ -187,7 +164,7 @@ public void onInventoryClickEvent(InventoryClickEvent e) {

int current = 0;
if (inv.getItem(53) != null)
current = Integer.valueOf(ChatColor.stripColor(inv.getItem(53).getItemMeta().getLore().get(1).split(" ")[1]));
current = Integer.parseInt(ChatColor.stripColor(inv.getItem(53).getItemMeta().getLore().get(1).split(" ")[1]));

int page = current;
Bukkit.getScheduler().runTaskLater(Main.getInstance(), () -> {
Expand Down
Loading