Code cleanup batch 2
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -35,6 +35,7 @@ public class Discord implements Module {
|
|||||||
@Override
|
@Override
|
||||||
public boolean onEnable() {
|
public boolean onEnable() {
|
||||||
Config config;
|
Config config;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
config = Config.getConfig("Discord.json");
|
config = Config.getConfig("Discord.json");
|
||||||
} catch (IOException | org.json.simple.parser.ParseException e1) {
|
} catch (IOException | org.json.simple.parser.ParseException e1) {
|
||||||
@@ -42,20 +43,26 @@ public class Discord implements Module {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (config == null || !config.containsKey("database") || !config.containsKey("table")
|
if (config == null || !config.containsKey("database") || !config.containsKey("table") || !config.containsKey("inviteLink")) {
|
||||||
|| !config.containsKey("inviteLink")) {
|
|
||||||
getLogger().error("Could not load the Discord config file, disabling!");
|
getLogger().error("Could not load the Discord config file, disabling!");
|
||||||
|
|
||||||
config.put("database", "redstoner");
|
config.put("database", "redstoner");
|
||||||
config.put("table", "discord");
|
config.put("table", "discord");
|
||||||
config.put("inviteLink", "https://discord.gg/example");
|
config.put("inviteLink", "https://discord.gg/example");
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inviteLink = config.get("inviteLink");
|
||||||
|
|
||||||
try {
|
try {
|
||||||
MysqlDatabase database = MysqlHandler.INSTANCE.getDatabase(config.get("database") + "?autoReconnect=true");
|
MysqlDatabase database = MysqlHandler.INSTANCE.getDatabase(config.get("database") + "?autoReconnect=true");
|
||||||
|
|
||||||
MysqlField uuid = new MysqlField("uuid", new VarChar(36), false);
|
MysqlField uuid = new MysqlField("uuid", new VarChar(36), false);
|
||||||
MysqlField pass = new MysqlField("token", new VarChar(8), false);
|
MysqlField pass = new MysqlField("token", new VarChar(8), false);
|
||||||
|
|
||||||
database.createTableIfNotExists((String) config.get("table"), uuid, pass);
|
database.createTableIfNotExists((String) config.get("table"), uuid, pass);
|
||||||
|
|
||||||
table = database.getTable(config.get("table"));
|
table = database.getTable(config.get("table"));
|
||||||
} catch (NullPointerException e) {
|
} catch (NullPointerException e) {
|
||||||
getLogger().error("Could not use the Discord config, aborting!");
|
getLogger().error("Could not use the Discord config, aborting!");
|
||||||
@@ -82,8 +89,7 @@ public class Discord implements Module {
|
|||||||
tries++;
|
tries++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tries > 10)
|
if (tries > 10) break;
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (token == null) {
|
if (token == null) {
|
||||||
@@ -97,11 +103,8 @@ public class Discord implements Module {
|
|||||||
table.insert(pUUID, token);
|
table.insert(pUUID, token);
|
||||||
|
|
||||||
new Message(sender, null).appendText("\n&cRedstoner&7 has a &2Discord&7 Now! \nClick ")
|
new Message(sender, null).appendText("\n&cRedstoner&7 has a &2Discord&7 Now! \nClick ")
|
||||||
.appendLinkHover("&e" + inviteLink, inviteLink, "&aClick to Join")
|
.appendLinkHover("&e" + inviteLink, inviteLink, "&aClick to Join").appendText("&7 to join. \n\nTo sync you rank, copy ")
|
||||||
.appendText("&7 to join. \n\nTo sync you rank, copy ")
|
.appendSuggestHover("&e" + token, token, "&aClick to Copy").appendText("&7 into &3#rank-sync&7.\n").send();
|
||||||
.appendSuggestHover("&e" + token, token, "&aClick to Copy")
|
|
||||||
.appendText("&7 into &3#rank-sync&7.\n")
|
|
||||||
.send();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private String randomToken(int length) {
|
private String randomToken(int length) {
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
package com.redstoner.modules.friends;
|
package com.redstoner.modules.friends;
|
||||||
|
|
||||||
import java.lang.reflect.InvocationTargetException;
|
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
@@ -31,330 +30,316 @@ import com.redstoner.modules.datamanager.DataManager;
|
|||||||
@AutoRegisterListener
|
@AutoRegisterListener
|
||||||
@Commands(CommandHolderType.File)
|
@Commands(CommandHolderType.File)
|
||||||
@Version(major = 4, minor = 0, revision = 0, compatible = 4)
|
@Version(major = 4, minor = 0, revision = 0, compatible = 4)
|
||||||
public class Friends implements CoreModule
|
public class Friends implements CoreModule {
|
||||||
{
|
|
||||||
@EventHandler(priority = EventPriority.MONITOR)
|
@EventHandler(priority = EventPriority.MONITOR)
|
||||||
public void onPlayerJoin(PlayerJoinEvent e)
|
public void onPlayerJoin(PlayerJoinEvent e) {
|
||||||
{
|
|
||||||
JSONArray friended_by = (JSONArray) DataManager.getOrDefault(e.getPlayer(), "friended_by", new JSONArray());
|
JSONArray friended_by = (JSONArray) DataManager.getOrDefault(e.getPlayer(), "friended_by", new JSONArray());
|
||||||
for (Object obj : friended_by)
|
|
||||||
{
|
for (Object obj : friended_by) {
|
||||||
UUID uuid = UUID.fromString((String) obj);
|
UUID uuid = UUID.fromString((String) obj);
|
||||||
Player p = Bukkit.getPlayer(uuid);
|
Player p = Bukkit.getPlayer(uuid);
|
||||||
if (p != null && p.canSee(e.getPlayer()))
|
|
||||||
{
|
if (p != null && p.canSee(e.getPlayer())) {
|
||||||
getLogger().message(p, "Your friend &e" + e.getPlayer().getDisplayName() + "&7 just joined!");
|
getLogger().message(p, "Your friend &e" + e.getPlayer().getDisplayName() + "&7 just joined!");
|
||||||
p.playSound(p.getLocation(), Sound.ENTITY_CHICKEN_EGG, 1, 1);
|
p.playSound(p.getLocation(), Sound.ENTITY_CHICKEN_EGG, 1, 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
JSONArray notifications = (JSONArray) DataManager.getOrDefault(e.getPlayer(), "scheduled_notifications",
|
|
||||||
new JSONArray());
|
JSONArray notifications = (JSONArray) DataManager.getOrDefault(e.getPlayer(), "scheduled_notifications", new JSONArray());
|
||||||
for (Object obj : notifications)
|
|
||||||
|
for (Object obj : notifications) {
|
||||||
getLogger().message(e.getPlayer(), (String) obj);
|
getLogger().message(e.getPlayer(), (String) obj);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.MONITOR)
|
@EventHandler(priority = EventPriority.MONITOR)
|
||||||
public void onPlayerLeave(PlayerQuitEvent e)
|
public void onPlayerLeave(PlayerQuitEvent e) {
|
||||||
{
|
|
||||||
JSONArray friended_by = (JSONArray) DataManager.getOrDefault(e.getPlayer(), "friended_by", new JSONArray());
|
JSONArray friended_by = (JSONArray) DataManager.getOrDefault(e.getPlayer(), "friended_by", new JSONArray());
|
||||||
for (Object obj : friended_by)
|
|
||||||
{
|
for (Object obj : friended_by) {
|
||||||
UUID uuid = UUID.fromString((String) obj);
|
UUID uuid = UUID.fromString((String) obj);
|
||||||
Player p = Bukkit.getPlayer(uuid);
|
Player p = Bukkit.getPlayer(uuid);
|
||||||
if (p != null && p.canSee(e.getPlayer()))
|
|
||||||
{
|
if (p != null && p.canSee(e.getPlayer())) {
|
||||||
getLogger().message(p, "Your friend &e" + e.getPlayer().getDisplayName() + "&7 just left!");
|
getLogger().message(p, "Your friend &e" + e.getPlayer().getDisplayName() + "&7 just left!");
|
||||||
p.playSound(p.getLocation(), Sound.ENTITY_CHICKEN_EGG, 1, 1);
|
p.playSound(p.getLocation(), Sound.ENTITY_CHICKEN_EGG, 1, 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings({"unchecked", "deprecation"})
|
@SuppressWarnings({ "unchecked", "deprecation" })
|
||||||
@Command(hook = "add")
|
@Command(hook = "add")
|
||||||
public boolean add(CommandSender sender, String target)
|
public boolean add(CommandSender sender, String target) {
|
||||||
{
|
if (target.equalsIgnoreCase("CONSOLE")) {
|
||||||
if (target.equalsIgnoreCase("CONSOLE"))
|
|
||||||
{
|
|
||||||
getLogger().message(sender, true, "You can't add console to your friends!");
|
getLogger().message(sender, true, "You can't add console to your friends!");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
OfflinePlayer p = Bukkit.getPlayer(target);
|
OfflinePlayer p = Bukkit.getPlayer(target);
|
||||||
if (p == null)
|
|
||||||
p = Bukkit.getOfflinePlayer(target);
|
if (p == null) p = Bukkit.getOfflinePlayer(target);
|
||||||
if (p == null)
|
if (p == null) {
|
||||||
{
|
|
||||||
getLogger().message(sender, true, "That player couldn't be found!");
|
getLogger().message(sender, true, "That player couldn't be found!");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
JSONArray friends = ((JSONArray) DataManager.getOrDefault(sender, "friends", new JSONArray()));
|
JSONArray friends = ((JSONArray) DataManager.getOrDefault(sender, "friends", new JSONArray()));
|
||||||
if (friends.contains(p.getUniqueId().toString()))
|
|
||||||
{
|
if (friends.contains(p.getUniqueId().toString())) {
|
||||||
getLogger().message(sender, true, "You are already friends with this person!");
|
getLogger().message(sender, true, "You are already friends with this person!");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
friends.add(p.getUniqueId().toString());
|
friends.add(p.getUniqueId().toString());
|
||||||
DataManager.save(sender);
|
DataManager.save(sender);
|
||||||
JSONArray friended_by = ((JSONArray) DataManager.getOrDefault(p.getUniqueId().toString(), "friended_by",
|
|
||||||
new JSONArray()));
|
JSONArray friended_by = ((JSONArray) DataManager.getOrDefault(p.getUniqueId().toString(), "friended_by", new JSONArray()));
|
||||||
friended_by.add(getID(sender));
|
friended_by.add(getID(sender));
|
||||||
|
|
||||||
DataManager.save(p.getUniqueId().toString());
|
DataManager.save(p.getUniqueId().toString());
|
||||||
|
|
||||||
getLogger().message(sender, "You are now friends with &e" + p.getName() + "&7!");
|
getLogger().message(sender, "You are now friends with &e" + p.getName() + "&7!");
|
||||||
if (p instanceof Player)
|
|
||||||
{
|
if (p instanceof Player) {
|
||||||
getLogger().message((Player) p, "&e" + Utils.getName(sender) + "&7 added you as a friend!");
|
getLogger().message((Player) p, "&e" + Utils.getName(sender) + "&7 added you as a friend!");
|
||||||
}
|
} else {
|
||||||
else
|
JSONArray notifications = (JSONArray) DataManager.getOrDefault(p.getUniqueId().toString(), "scheduled_notifications", new JSONArray());
|
||||||
{
|
|
||||||
JSONArray notifications = (JSONArray) DataManager.getOrDefault(p.getUniqueId().toString(),
|
|
||||||
"scheduled_notifications", new JSONArray());
|
|
||||||
notifications.add("&e" + Utils.getName(sender) + "&7 added you as a friend!");
|
notifications.add("&e" + Utils.getName(sender) + "&7 added you as a friend!");
|
||||||
notifications.remove("&e" + Utils.getName(sender) + "&7 removed you as a friend!");
|
notifications.remove("&e" + Utils.getName(sender) + "&7 removed you as a friend!");
|
||||||
|
|
||||||
DataManager.setData(p.getUniqueId().toString(), "scheduled_notifications", notifications);
|
DataManager.setData(p.getUniqueId().toString(), "scheduled_notifications", notifications);
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings({"deprecation", "unchecked"})
|
@SuppressWarnings({ "deprecation", "unchecked" })
|
||||||
@Command(hook = "add_grouped")
|
@Command(hook = "add_grouped")
|
||||||
public boolean add_grouped(CommandSender sender, String target, String group)
|
public boolean add_grouped(CommandSender sender, String target, String group) {
|
||||||
{
|
if (target.equalsIgnoreCase("CONSOLE")) {
|
||||||
if (target.equalsIgnoreCase("CONSOLE"))
|
|
||||||
{
|
|
||||||
getLogger().message(sender, true, "You can't add console to your friends!");
|
getLogger().message(sender, true, "You can't add console to your friends!");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
OfflinePlayer p = Bukkit.getPlayer(target);
|
OfflinePlayer p = Bukkit.getPlayer(target);
|
||||||
if (p == null)
|
|
||||||
p = Bukkit.getOfflinePlayer(target);
|
if (p == null) p = Bukkit.getOfflinePlayer(target);
|
||||||
if (p == null)
|
if (p == null) {
|
||||||
{
|
|
||||||
getLogger().message(sender, true, "That player couldn't be found!");
|
getLogger().message(sender, true, "That player couldn't be found!");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
JSONArray friends = ((JSONArray) DataManager.getOrDefault(sender, "groups." + group, new JSONArray()));
|
JSONArray friends = ((JSONArray) DataManager.getOrDefault(sender, "groups." + group, new JSONArray()));
|
||||||
if (friends.contains(p.getUniqueId().toString()))
|
|
||||||
{
|
if (friends.contains(p.getUniqueId().toString())) {
|
||||||
getLogger().message(sender, true, "This person already is part of that friendsgroup!");
|
getLogger().message(sender, true, "This person already is part of that friendsgroup!");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
friends.add(p.getUniqueId().toString());
|
friends.add(p.getUniqueId().toString());
|
||||||
DataManager.save(sender);
|
DataManager.save(sender);
|
||||||
|
|
||||||
getLogger().message(sender, "&e" + p.getName() + "&7 is now part of the group &e" + group + "&7!");
|
getLogger().message(sender, "&e" + p.getName() + "&7 is now part of the group &e" + group + "&7!");
|
||||||
if (p instanceof Player)
|
|
||||||
{
|
if (p instanceof Player) {
|
||||||
getLogger().message((Player) p,
|
getLogger().message((Player) p, "&e" + Utils.getName(sender) + " &7added you to their friendsgroup &e" + group + "&7!");
|
||||||
"&e" + Utils.getName(sender) + " &7added you to their friendsgroup &e" + group + "&7!");
|
} else {
|
||||||
}
|
JSONArray notifications = (JSONArray) DataManager.getOrDefault(p.getUniqueId().toString(), "scheduled_notifications", new JSONArray());
|
||||||
else
|
|
||||||
{
|
|
||||||
JSONArray notifications = (JSONArray) DataManager.getOrDefault(p.getUniqueId().toString(),
|
|
||||||
"scheduled_notifications", new JSONArray());
|
|
||||||
notifications.add("&e" + Utils.getName(sender) + " &7added you to their friendsgroup &e" + group + "&7!");
|
notifications.add("&e" + Utils.getName(sender) + " &7added you to their friendsgroup &e" + group + "&7!");
|
||||||
notifications
|
notifications.remove("&e" + Utils.getName(sender) + " &7removed you from their friendsgroup &e" + group + "&7!");
|
||||||
.remove("&e" + Utils.getName(sender) + " &7removed you from their friendsgroup &e" + group + "&7!");
|
|
||||||
DataManager.setData(p.getUniqueId().toString(), "scheduled_notifications", notifications);
|
DataManager.setData(p.getUniqueId().toString(), "scheduled_notifications", notifications);
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings({"deprecation", "unchecked"})
|
@SuppressWarnings({ "deprecation", "unchecked" })
|
||||||
@Command(hook = "del")
|
@Command(hook = "del")
|
||||||
public boolean del(CommandSender sender, String target)
|
public boolean del(CommandSender sender, String target) {
|
||||||
{
|
if (target.equalsIgnoreCase("CONSOLE")) {
|
||||||
if (target.equalsIgnoreCase("CONSOLE"))
|
|
||||||
{
|
|
||||||
getLogger().message(sender, true, "You can't add console to your friends!");
|
getLogger().message(sender, true, "You can't add console to your friends!");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
OfflinePlayer p = Bukkit.getPlayer(target);
|
OfflinePlayer p = Bukkit.getPlayer(target);
|
||||||
if (p == null)
|
|
||||||
p = Bukkit.getOfflinePlayer(target);
|
if (p == null) p = Bukkit.getOfflinePlayer(target);
|
||||||
if (p == null)
|
if (p == null) {
|
||||||
{
|
|
||||||
getLogger().message(sender, true, "That player couldn't be found!");
|
getLogger().message(sender, true, "That player couldn't be found!");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
JSONArray friends = ((JSONArray) DataManager.getOrDefault(sender, "friends", new JSONArray()));
|
JSONArray friends = ((JSONArray) DataManager.getOrDefault(sender, "friends", new JSONArray()));
|
||||||
if (friends.contains(p.getUniqueId().toString()))
|
|
||||||
{
|
if (friends.contains(p.getUniqueId().toString())) {
|
||||||
getLogger().message(sender, true, "You are already friends with this person!");
|
getLogger().message(sender, true, "You are already friends with this person!");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
friends.remove(p.getUniqueId().toString());
|
friends.remove(p.getUniqueId().toString());
|
||||||
DataManager.save(sender);
|
DataManager.save(sender);
|
||||||
JSONArray friended_by = ((JSONArray) DataManager.getOrDefault(p.getUniqueId().toString(), "friended_by",
|
|
||||||
new JSONArray()));
|
JSONArray friended_by = ((JSONArray) DataManager.getOrDefault(p.getUniqueId().toString(), "friended_by", new JSONArray()));
|
||||||
friended_by.remove(getID(sender));
|
friended_by.remove(getID(sender));
|
||||||
|
|
||||||
DataManager.save(p.getUniqueId().toString());
|
DataManager.save(p.getUniqueId().toString());
|
||||||
|
|
||||||
getLogger().message(sender, "You are now friends with &e" + p.getName() + "&7!");
|
getLogger().message(sender, "You are now friends with &e" + p.getName() + "&7!");
|
||||||
if (p instanceof Player)
|
|
||||||
{
|
if (p instanceof Player) {
|
||||||
getLogger().message((Player) p, "&e" + Utils.getName(sender) + "&7 added you as a friend!");
|
getLogger().message((Player) p, "&e" + Utils.getName(sender) + "&7 added you as a friend!");
|
||||||
}
|
} else {
|
||||||
else
|
JSONArray notifications = (JSONArray) DataManager.getOrDefault(p.getUniqueId().toString(), "scheduled_notifications", new JSONArray());
|
||||||
{
|
|
||||||
JSONArray notifications = (JSONArray) DataManager.getOrDefault(p.getUniqueId().toString(),
|
|
||||||
"scheduled_notifications", new JSONArray());
|
|
||||||
notifications.add("&e" + Utils.getName(sender) + "&7 removed you as a friend!");
|
notifications.add("&e" + Utils.getName(sender) + "&7 removed you as a friend!");
|
||||||
notifications.remove("&e" + Utils.getName(sender) + "&7 added you as a friend!");
|
notifications.remove("&e" + Utils.getName(sender) + "&7 added you as a friend!");
|
||||||
|
|
||||||
DataManager.setData(p.getUniqueId().toString(), "scheduled_notifications", notifications);
|
DataManager.setData(p.getUniqueId().toString(), "scheduled_notifications", notifications);
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings({"deprecation", "unchecked"})
|
@SuppressWarnings({ "deprecation", "unchecked" })
|
||||||
@Command(hook = "del_grouped")
|
@Command(hook = "del_grouped")
|
||||||
public boolean del_grouped(CommandSender sender, String target, String group)
|
public boolean del_grouped(CommandSender sender, String target, String group) {
|
||||||
{
|
if (target.equalsIgnoreCase("CONSOLE")) {
|
||||||
if (target.equalsIgnoreCase("CONSOLE"))
|
|
||||||
{
|
|
||||||
getLogger().message(sender, true, "You can't add console to your friends!");
|
getLogger().message(sender, true, "You can't add console to your friends!");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
OfflinePlayer p = Bukkit.getPlayer(target);
|
OfflinePlayer p = Bukkit.getPlayer(target);
|
||||||
if (p == null)
|
|
||||||
p = Bukkit.getOfflinePlayer(target);
|
if (p == null) p = Bukkit.getOfflinePlayer(target);
|
||||||
if (p == null)
|
if (p == null) {
|
||||||
{
|
|
||||||
getLogger().message(sender, true, "That player couldn't be found!");
|
getLogger().message(sender, true, "That player couldn't be found!");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
JSONArray friends = ((JSONArray) DataManager.getOrDefault(sender, "groups." + group, new JSONArray()));
|
JSONArray friends = ((JSONArray) DataManager.getOrDefault(sender, "groups." + group, new JSONArray()));
|
||||||
if (friends.contains(p.getUniqueId().toString()))
|
|
||||||
{
|
if (friends.contains(p.getUniqueId().toString())) {
|
||||||
getLogger().message(sender, true, "This person already is part of that friendsgroup!");
|
getLogger().message(sender, true, "This person already is part of that friendsgroup!");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
friends.add(p.getUniqueId().toString());
|
friends.add(p.getUniqueId().toString());
|
||||||
DataManager.save(sender);
|
DataManager.save(sender);
|
||||||
|
|
||||||
getLogger().message(sender, "&e" + p.getName() + "&7 is now part of the group &e" + group + "&7!");
|
getLogger().message(sender, "&e" + p.getName() + "&7 is now part of the group &e" + group + "&7!");
|
||||||
if (p instanceof Player)
|
|
||||||
{
|
if (p instanceof Player) {
|
||||||
getLogger().message((Player) p,
|
getLogger().message((Player) p, "&e" + Utils.getName(sender) + " &7added you to their friendsgroup &e" + group + "&7!");
|
||||||
"&e" + Utils.getName(sender) + " &7added you to their friendsgroup &e" + group + "&7!");
|
} else {
|
||||||
}
|
JSONArray notifications = (JSONArray) DataManager.getOrDefault(p.getUniqueId().toString(), "scheduled_notifications", new JSONArray());
|
||||||
else
|
|
||||||
{
|
notifications.add("&e" + Utils.getName(sender) + " &7removed you from their friendsgroup &e" + group + "&7!");
|
||||||
JSONArray notifications = (JSONArray) DataManager.getOrDefault(p.getUniqueId().toString(),
|
notifications.remove("&e" + Utils.getName(sender) + " &7added you to their friendsgroup &e" + group + "&7!");
|
||||||
"scheduled_notifications", new JSONArray());
|
|
||||||
notifications
|
|
||||||
.add("&e" + Utils.getName(sender) + " &7removed you from their friendsgroup &e" + group + "&7!");
|
|
||||||
notifications
|
|
||||||
.remove("&e" + Utils.getName(sender) + " &7added you to their friendsgroup &e" + group + "&7!");
|
|
||||||
DataManager.setData(p.getUniqueId().toString(), "scheduled_notifications", notifications);
|
DataManager.setData(p.getUniqueId().toString(), "scheduled_notifications", notifications);
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Command(hook = "list")
|
@Command(hook = "list")
|
||||||
public boolean list(CommandSender sender)
|
public boolean list(CommandSender sender) {
|
||||||
{
|
|
||||||
JSONArray friends = (JSONArray) DataManager.getOrDefault(sender, "friends", new JSONArray());
|
JSONArray friends = (JSONArray) DataManager.getOrDefault(sender, "friends", new JSONArray());
|
||||||
if (friends.size() == 0)
|
|
||||||
{
|
if (friends.size() == 0) {
|
||||||
getLogger().message(sender, true, "You didn't add anyone to your friendslist yet.");
|
getLogger().message(sender, true, "You didn't add anyone to your friendslist yet.");
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new StringBuilder();
|
||||||
for (Object o : friends.toArray())
|
|
||||||
{
|
for (Object o : friends.toArray()) {
|
||||||
UUID id = UUID.fromString((String) o);
|
UUID id = UUID.fromString((String) o);
|
||||||
Player p = Bukkit.getPlayer(id);
|
Player p = Bukkit.getPlayer(id);
|
||||||
if (p != null)
|
|
||||||
sb.append(p.getDisplayName() + "&7, ");
|
if (p != null) sb.append(p.getDisplayName() + "&7, ");
|
||||||
else
|
else sb.append("&9" + Bukkit.getOfflinePlayer(id).getName() + "&7, ");
|
||||||
sb.append("&9" + Bukkit.getOfflinePlayer(id).getName() + "&7, ");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
String out = sb.toString().replaceAll(", $", "");
|
String out = sb.toString().replaceAll(", $", "");
|
||||||
getLogger().message(sender, "You have a total of &e" + friends.size() + "&7 friends:", out);
|
getLogger().message(sender, "You have a total of &e" + friends.size() + "&7 friends:", out);
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Command(hook = "list_group")
|
@Command(hook = "list_group")
|
||||||
public boolean list_group(CommandSender sender, String group)
|
public boolean list_group(CommandSender sender, String group) {
|
||||||
{
|
|
||||||
JSONArray friends = (JSONArray) DataManager.getOrDefault(sender, "group." + group, new JSONArray());
|
JSONArray friends = (JSONArray) DataManager.getOrDefault(sender, "group." + group, new JSONArray());
|
||||||
if (friends.size() == 0)
|
|
||||||
{
|
if (friends.size() == 0) {
|
||||||
getLogger().message(sender, true, "You didn't add anyone to this group yet.");
|
getLogger().message(sender, true, "You didn't add anyone to this group yet.");
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new StringBuilder();
|
||||||
for (Object o : friends.toArray())
|
|
||||||
{
|
for (Object o : friends.toArray()) {
|
||||||
UUID id = UUID.fromString((String) o);
|
UUID id = UUID.fromString((String) o);
|
||||||
Player p = Bukkit.getPlayer(id);
|
Player p = Bukkit.getPlayer(id);
|
||||||
if (p != null)
|
|
||||||
sb.append(p.getDisplayName() + "&7, ");
|
if (p != null) sb.append(p.getDisplayName() + "&7, ");
|
||||||
else
|
else sb.append("&9" + Bukkit.getOfflinePlayer(id).getName() + "&7, ");
|
||||||
sb.append("&9" + Bukkit.getOfflinePlayer(id).getName() + "&7, ");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
String out = sb.toString().replaceAll(", $", "");
|
String out = sb.toString().replaceAll(", $", "");
|
||||||
getLogger().message(sender, "You have a total of &e" + friends.size() + "&7 friends added to this group:", out);
|
getLogger().message(sender, "You have a total of &e" + friends.size() + "&7 friends added to this group:", out);
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Command(hook = "list_groups")
|
@Command(hook = "list_groups")
|
||||||
public boolean list_groups(CommandSender sender)
|
public boolean list_groups(CommandSender sender) {
|
||||||
{
|
|
||||||
JSONObject raw = (JSONObject) DataManager.getOrDefault(sender, null, new JSONObject());
|
JSONObject raw = (JSONObject) DataManager.getOrDefault(sender, null, new JSONObject());
|
||||||
Set<?> keys = raw.keySet();
|
Set<?> keys = raw.keySet();
|
||||||
if (keys.size() == 0 || (keys.contains("friends") && keys.size() == 1))
|
|
||||||
{
|
if (keys.size() == 0 || (keys.contains("friends") && keys.size() == 1)) {
|
||||||
getLogger().message(sender, true, "You don't have any custom groups made yet.");
|
getLogger().message(sender, true, "You don't have any custom groups made yet.");
|
||||||
return true;
|
return true;
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new StringBuilder();
|
||||||
for (Object o : keys)
|
|
||||||
{
|
for (Object o : keys) {
|
||||||
sb.append("&e" + (String) o + "&7, ");
|
sb.append("&e" + (String) o + "&7, ");
|
||||||
}
|
}
|
||||||
|
|
||||||
String out = sb.toString().replaceAll(", $", "");
|
String out = sb.toString().replaceAll(", $", "");
|
||||||
getLogger().message(sender, "", out);
|
getLogger().message(sender, "", out);
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isFriend(CommandSender player, CommandSender friend)
|
public static boolean isFriend(CommandSender player, CommandSender friend) {
|
||||||
{
|
|
||||||
return isFriend(player, friend, null);
|
return isFriend(player, friend, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isFriend(CommandSender player, CommandSender friend, String condition)
|
public static boolean isFriend(CommandSender player, CommandSender friend, String condition) {
|
||||||
{
|
try {
|
||||||
try
|
|
||||||
{
|
|
||||||
Module mod = ModuleLoader.getModule("Friends");
|
Module mod = ModuleLoader.getModule("Friends");
|
||||||
Method m = mod.getClass().getDeclaredMethod("isFriend_", String.class);
|
Method m = mod.getClass().getDeclaredMethod("isFriend_", String.class);
|
||||||
|
|
||||||
return (boolean) m.invoke(mod, player, friend, condition);
|
return (boolean) m.invoke(mod, player, friend, condition);
|
||||||
|
} catch (Exception e) {
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
catch (NoSuchMethodException | SecurityException | IllegalAccessException | IllegalArgumentException
|
|
||||||
| InvocationTargetException e)
|
|
||||||
{}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected boolean isFriend_(CommandSender player, CommandSender friend, String group)
|
protected boolean isFriend_(CommandSender player, CommandSender friend, String group) {
|
||||||
{
|
if (group == null) group = "friends";
|
||||||
if (group == null)
|
else if (!group.startsWith("group.")) group = "group." + group;
|
||||||
group = "friends";
|
|
||||||
else if (!group.startsWith("group."))
|
|
||||||
group = "group." + group;
|
|
||||||
JSONArray array = (JSONArray) DataManager.getOrDefault(player, group, new JSONArray());
|
JSONArray array = (JSONArray) DataManager.getOrDefault(player, group, new JSONArray());
|
||||||
return array.contains(getID(friend));
|
return array.contains(getID(friend));
|
||||||
}
|
}
|
||||||
|
|
||||||
private final String getID(CommandSender sender)
|
private final String getID(CommandSender sender) {
|
||||||
{
|
if (sender instanceof Player) return ((Player) sender).getUniqueId().toString();
|
||||||
if (sender instanceof Player)
|
else return sender.getName();
|
||||||
return ((Player) sender).getUniqueId().toString();
|
|
||||||
else
|
|
||||||
return sender.getName();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
package com.redstoner.modules.ignore;
|
package com.redstoner.modules.ignore;
|
||||||
|
|
||||||
import java.lang.reflect.InvocationTargetException;
|
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
@@ -27,30 +26,24 @@ import net.nemez.chatapi.click.Message;
|
|||||||
@Commands(CommandHolderType.File)
|
@Commands(CommandHolderType.File)
|
||||||
@AutoRegisterListener
|
@AutoRegisterListener
|
||||||
@Version(major = 4, minor = 0, revision = 0, compatible = 4)
|
@Version(major = 4, minor = 0, revision = 0, compatible = 4)
|
||||||
public class Ignore implements Module
|
public class Ignore implements Module {
|
||||||
{
|
|
||||||
|
|
||||||
@Command(hook = "unignore", async = AsyncType.ALWAYS)
|
@Command(hook = "unignore", async = AsyncType.ALWAYS)
|
||||||
public boolean unignore(CommandSender sender, String player)
|
public boolean unignore(CommandSender sender, String player) {
|
||||||
{
|
|
||||||
return ignore(sender, player, false);
|
return ignore(sender, player, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Command(hook = "ignore", async = AsyncType.ALWAYS)
|
@Command(hook = "ignore", async = AsyncType.ALWAYS)
|
||||||
public boolean ignore(CommandSender sender, String player)
|
public boolean ignore(CommandSender sender, String player) {
|
||||||
{
|
|
||||||
return ignore(sender, player, true);
|
return ignore(sender, player, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Command(hook = "list", async = AsyncType.ALWAYS)
|
@Command(hook = "list", async = AsyncType.ALWAYS)
|
||||||
public boolean list(CommandSender sender)
|
public boolean list(CommandSender sender) {
|
||||||
{
|
|
||||||
getLogger().message(sender, "§7You are currently ignoring:");
|
getLogger().message(sender, "§7You are currently ignoring:");
|
||||||
|
|
||||||
JSONArray ignores = (JSONArray) DataManager.getOrDefault(sender, "ignores", new JSONArray());
|
JSONArray ignores = (JSONArray) DataManager.getOrDefault(sender, "ignores", new JSONArray());
|
||||||
|
|
||||||
if (ignores.isEmpty())
|
if (ignores.isEmpty()) {
|
||||||
{
|
|
||||||
new Message(sender, null).appendText(" §7Nobody \\o/").send();
|
new Message(sender, null).appendText(" §7Nobody \\o/").send();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -59,8 +52,7 @@ public class Ignore implements Module
|
|||||||
OfflinePlayer pi = Bukkit.getOfflinePlayer(UUID.fromString((String) ignores.get(0)));
|
OfflinePlayer pi = Bukkit.getOfflinePlayer(UUID.fromString((String) ignores.get(0)));
|
||||||
players = " §3" + pi.getName() + "§7";
|
players = " §3" + pi.getName() + "§7";
|
||||||
|
|
||||||
for (int i = 1; i < ignores.size(); i++)
|
for (int i = 1; i < ignores.size(); i++) {
|
||||||
{
|
|
||||||
OfflinePlayer p = Bukkit.getOfflinePlayer(UUID.fromString((String) ignores.get(i)));
|
OfflinePlayer p = Bukkit.getOfflinePlayer(UUID.fromString((String) ignores.get(i)));
|
||||||
players += ", §3" + p.getName() + "§7";
|
players += ", §3" + p.getName() + "§7";
|
||||||
}
|
}
|
||||||
@@ -68,92 +60,75 @@ public class Ignore implements Module
|
|||||||
Message m = new Message(sender, null);
|
Message m = new Message(sender, null);
|
||||||
m.appendText(players);
|
m.appendText(players);
|
||||||
m.send();
|
m.send();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings({"unchecked", "deprecation"})
|
@SuppressWarnings({ "unchecked", "deprecation" })
|
||||||
public boolean ignore(CommandSender sender, String player, boolean allowIgnore)
|
public boolean ignore(CommandSender sender, String player, boolean allowIgnore) {
|
||||||
{
|
|
||||||
JSONArray ignores = (JSONArray) DataManager.getOrDefault(sender, "ignores", new JSONArray());
|
JSONArray ignores = (JSONArray) DataManager.getOrDefault(sender, "ignores", new JSONArray());
|
||||||
|
|
||||||
Player p = Utils.isUUID(player) ? Bukkit.getPlayer(UUID.fromString(player)) : Bukkit.getPlayer(player);
|
Player p = Utils.isUUID(player) ? Bukkit.getPlayer(UUID.fromString(player)) : Bukkit.getPlayer(player);
|
||||||
|
|
||||||
OfflinePlayer op = Utils.isUUID(player) ? Bukkit.getOfflinePlayer(UUID.fromString(player))
|
OfflinePlayer op = Utils.isUUID(player) ? Bukkit.getOfflinePlayer(UUID.fromString(player)) : Bukkit.getOfflinePlayer(player);
|
||||||
: Bukkit.getOfflinePlayer(player);
|
|
||||||
|
|
||||||
String pName = p != null ? p.getDisplayName() : op.getName();
|
String pName = p != null ? p.getDisplayName() : op.getName();
|
||||||
String pUUID = p != null ? p.getUniqueId().toString() : op.getUniqueId().toString();
|
String pUUID = p != null ? p.getUniqueId().toString() : op.getUniqueId().toString();
|
||||||
String sUUID = ((Player) sender).getUniqueId().toString();
|
String sUUID = ((Player) sender).getUniqueId().toString();
|
||||||
|
|
||||||
if (pUUID.equals(sUUID))
|
if (pUUID.equals(sUUID)) {
|
||||||
{
|
|
||||||
getLogger().message(sender, true, "§7You can't ignore yourself :P");
|
getLogger().message(sender, true, "§7You can't ignore yourself :P");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ignores.contains(pUUID))
|
if (ignores.contains(pUUID)) {
|
||||||
{
|
|
||||||
ignores.remove(pUUID);
|
ignores.remove(pUUID);
|
||||||
getLogger().message(sender, "§7You are no longer ignoring §3" + pName + "§7.");
|
getLogger().message(sender, "§7You are no longer ignoring §3" + pName + "§7.");
|
||||||
}
|
} else if (!allowIgnore) {
|
||||||
else if (!allowIgnore)
|
|
||||||
{
|
|
||||||
getLogger().message(sender, "§7You weren't ignoring §3" + pName + "§7.");
|
getLogger().message(sender, "§7You weren't ignoring §3" + pName + "§7.");
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
ignores.add(pUUID);
|
ignores.add(pUUID);
|
||||||
getLogger().message(sender, "§7You are now ignoring §3" + pName + "§7.");
|
getLogger().message(sender, "§7You are now ignoring §3" + pName + "§7.");
|
||||||
}
|
}
|
||||||
|
|
||||||
DataManager.setData(sender, "ignores", ignores);
|
DataManager.setData(sender, "ignores", ignores);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static BroadcastFilter getIgnoredBy(CommandSender sender)
|
public static BroadcastFilter getIgnoredBy(CommandSender sender) {
|
||||||
{
|
try {
|
||||||
try
|
|
||||||
{
|
|
||||||
Module mod = ModuleLoader.getModule("Ignore");
|
Module mod = ModuleLoader.getModule("Ignore");
|
||||||
|
|
||||||
Method m = mod.getClass().getDeclaredMethod("_getIgnoredBy", CommandSender.class);
|
Method m = mod.getClass().getDeclaredMethod("_getIgnoredBy", CommandSender.class);
|
||||||
m.setAccessible(true);
|
m.setAccessible(true);
|
||||||
|
|
||||||
return (BroadcastFilter) m.invoke(mod, sender);
|
return (BroadcastFilter) m.invoke(mod, sender);
|
||||||
|
} catch (Exception e) {
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
catch (NoSuchMethodException | SecurityException | IllegalAccessException | IllegalArgumentException
|
|
||||||
| InvocationTargetException e)
|
|
||||||
{}
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
private BroadcastFilter _getIgnoredBy(CommandSender sender)
|
private BroadcastFilter _getIgnoredBy(CommandSender sender) {
|
||||||
{
|
return new BroadcastFilter() {
|
||||||
return new BroadcastFilter()
|
private final String sUUID = sender instanceof Player ? ((Player) sender).getUniqueId().toString() : "CONSOLE";
|
||||||
{
|
|
||||||
|
|
||||||
private final String sUUID = sender instanceof Player ? ((Player) sender).getUniqueId().toString()
|
|
||||||
: "CONSOLE";
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean sendTo(CommandSender recipient)
|
public boolean sendTo(CommandSender recipient) {
|
||||||
{
|
if (sUUID.equals("CONSOLE")) return true;
|
||||||
if (sUUID.equals("CONSOLE"))
|
|
||||||
return true;
|
|
||||||
|
|
||||||
if (recipient instanceof Player)
|
if ((recipient instanceof Player)) return true;
|
||||||
{
|
|
||||||
Player player = (Player) recipient;
|
|
||||||
|
|
||||||
if (sender.hasPermission("utils.ignore.override"))
|
Player player = (Player) recipient;
|
||||||
return true;
|
|
||||||
|
if (sender.hasPermission("utils.ignore.override")) return true;
|
||||||
|
|
||||||
|
JSONArray ignores = (JSONArray) DataManager.getOrDefault(recipient, "ignores", new JSONArray());
|
||||||
|
return !ignores.contains(sUUID);
|
||||||
|
|
||||||
JSONArray ignores = (JSONArray) DataManager.getOrDefault(recipient, "ignores", new JSONArray());
|
|
||||||
return !ignores.contains(sUUID);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user