Formatting

This commit is contained in:
Telesphoreo 2022-02-22 03:30:23 -06:00
parent 442ab21a6b
commit 553e5c6355
18 changed files with 138 additions and 93 deletions

View File

@ -21,14 +21,13 @@ import dev.plex.storage.StorageType;
import dev.plex.util.PlexLog;
import dev.plex.util.PlexUtils;
import dev.plex.world.CustomWorld;
import java.util.UUID;
import lombok.Getter;
import lombok.Setter;
import org.bstats.bukkit.Metrics;
import org.bukkit.Bukkit;
import org.bukkit.plugin.java.JavaPlugin;
import java.util.UUID;
@Getter
@Setter
public class Plex extends JavaPlugin
@ -82,7 +81,8 @@ public class Plex extends JavaPlugin
{
PlexUtils.testConnections();
PlexLog.log("Connected to " + storageType.name().toUpperCase());
} catch (Exception e)
}
catch (Exception e)
{
PlexLog.error("Failed to connect to " + storageType.name().toUpperCase());
e.printStackTrace();
@ -96,7 +96,8 @@ public class Plex extends JavaPlugin
{
redisConnection.getJedis();
PlexLog.log("Connected to Redis!");
} else
}
else
{
PlexLog.log("Redis is disabled in the configuration file, not connecting.");
}
@ -104,7 +105,8 @@ public class Plex extends JavaPlugin
if (storageType == StorageType.MONGODB)
{
mongoPlayerData = new MongoPlayerData();
} else
}
else
{
sqlPlayerData = new SQLPlayerData();
}
@ -149,7 +151,8 @@ public class Plex extends JavaPlugin
if (mongoPlayerData != null) //back to mongo checking
{
mongoPlayerData.update(plexPlayer); //update the player's document
} else if (sqlPlayerData != null) //sql checking
}
else if (sqlPlayerData != null) //sql checking
{
sqlPlayerData.update(plexPlayer);
}

View File

@ -436,8 +436,9 @@ public abstract class PlexCommand extends Command implements PluginIdentifiableC
/**
* Converts usage to a component
*
* <p>
* s The usage to convert
*
* @return A Kyori component stating the usage
*/
protected Component usage(String s)

View File

@ -1,7 +1,6 @@
package dev.plex.command.impl;
import com.google.common.collect.ImmutableList;
import dev.plex.Plex;
import dev.plex.command.PlexCommand;
import dev.plex.command.annotation.CommandParameters;
import dev.plex.command.annotation.CommandPermissions;

View File

@ -25,6 +25,7 @@ public class Config extends YamlConfiguration
/**
* Creates a config object
*
* @param plugin The plugin instance
* @param name The file name
*/

View File

@ -27,6 +27,7 @@ public abstract class PunishedPlayerEvent extends PlayerEvent implements Cancell
/**
* Creates an event object
*
* @param punishedPlayer The player who was punished
* @see PunishedPlayer
*/

View File

@ -6,6 +6,7 @@ import org.bukkit.event.Cancellable;
import org.bukkit.event.HandlerList;
//TODO: Event doesn't look like it is called
/**
* Event that is called when a player is frozen or unfrozen
*/
@ -21,6 +22,7 @@ public class PunishedPlayerFreezeEvent extends PunishedPlayerEvent implements Ca
/**
* Creates a new event instance
*
* @param punishedPlayer The player who was punished
* @param frozen The new frozen status
*/

View File

@ -6,6 +6,7 @@ import org.bukkit.event.Cancellable;
import org.bukkit.event.HandlerList;
//TODO: Event doesn't look like it is called
/**
* Event that is called when a player is frozen or unfrozen
*/
@ -21,6 +22,7 @@ public class PunishedPlayerMuteEvent extends PunishedPlayerEvent implements Canc
/**
* Creates a new event instance
*
* @param punishedPlayer The player who was punished
* @param muted The new muted status
*/

View File

@ -6,12 +6,11 @@ import dev.plex.player.PunishedPlayer;
import dev.plex.punishment.PunishmentType;
import dev.plex.util.MojangUtils;
import dev.plex.util.PlexUtils;
import java.time.format.DateTimeFormatter;
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
import org.bukkit.event.EventHandler;
import org.bukkit.event.player.AsyncPlayerPreLoginEvent;
import java.time.format.DateTimeFormatter;
public class BanListener extends PlexListener
{
private final String banUrl = plugin.config.getString("banning.ban_url");

View File

@ -8,6 +8,8 @@ import dev.plex.listener.PlexListener;
import dev.plex.player.PlexPlayer;
import dev.plex.player.PunishedPlayer;
import dev.plex.util.PlexLog;
import java.util.Collections;
import java.util.UUID;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
@ -18,9 +20,6 @@ import org.bukkit.event.EventPriority;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import java.util.Collections;
import java.util.UUID;
public class PlayerListener extends PlexListener
{
private final MongoPlayerData mongoPlayerData = plugin.getMongoPlayerData() != null ? plugin.getMongoPlayerData() : null;
@ -38,7 +37,8 @@ public class PlayerListener extends PlexListener
{
player.setOp(true);
PlexLog.debug("Automatically opped " + player.getName() + " since ranks are enabled.");
} else if (plugin.getSystem().equalsIgnoreCase("permissions"))
}
else if (plugin.getSystem().equalsIgnoreCase("permissions"))
{
player.setOp(false);
PlexLog.debug("Automatically deopped " + player.getName() + " since ranks are disabled.");
@ -51,7 +51,8 @@ public class PlayerListener extends PlexListener
plexPlayer.setName(player.getName()); //set the name of the player
plexPlayer.setIps(Collections.singletonList(player.getAddress().getAddress().getHostAddress().trim())); //set the arraylist of ips
DataUtils.insert(plexPlayer); // insert data in some wack db
} else
}
else
{
plexPlayer = DataUtils.getPlayer(player.getUniqueId());
}
@ -62,7 +63,8 @@ public class PlayerListener extends PlexListener
{
punishedPlayer = new PunishedPlayer(player.getUniqueId());
PlayerCache.getPunishedPlayerMap().put(player.getUniqueId(), punishedPlayer);
} else
}
else
{
punishedPlayer = PlayerCache.getPunishedPlayer(player.getUniqueId());
}
@ -96,7 +98,8 @@ public class PlayerListener extends PlexListener
if (mongoPlayerData != null) //back to mongo checking
{
mongoPlayerData.update(plexPlayer); //update the player's document
} else if (sqlPlayerData != null) //sql checking
}
else if (sqlPlayerData != null) //sql checking
{
sqlPlayerData.update(plexPlayer);
}

View File

@ -3,13 +3,12 @@ package dev.plex.listener.impl;
import com.destroystokyo.paper.event.server.PaperServerListPingEvent;
import dev.plex.listener.PlexListener;
import dev.plex.util.PlexUtils;
import java.util.List;
import java.util.stream.Collectors;
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
import org.bukkit.Bukkit;
import org.bukkit.event.EventHandler;
import java.util.List;
import java.util.stream.Collectors;
public class ServerListener extends PlexListener
{
@EventHandler
@ -27,7 +26,8 @@ public class ServerListener extends PlexListener
motd.append(PlexUtils.randomChatColor()).append(word).append(" ");
}
event.motd(LegacyComponentSerializer.legacyAmpersand().deserialize(motd.toString().trim()));
} else
}
else
{
event.motd(LegacyComponentSerializer.legacyAmpersand().deserialize(baseMotd.trim()));
}

View File

@ -8,6 +8,9 @@ import dev.plex.rank.enums.Rank;
import dev.plex.rank.enums.Title;
import dev.plex.util.PlexLog;
import dev.plex.util.PlexUtils;
import java.util.Arrays;
import java.util.List;
import java.util.Locale;
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
import org.bukkit.World;
import org.bukkit.entity.EntityType;
@ -18,10 +21,6 @@ import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.event.entity.EntitySpawnEvent;
import org.jetbrains.annotations.NotNull;
import java.util.Arrays;
import java.util.List;
import java.util.Locale;
public class WorldListener extends PlexListener
{
@ -34,15 +33,27 @@ public class WorldListener extends PlexListener
if (plugin.getSystem().equalsIgnoreCase("permissions"))
{
String permission = plugin.config.getString("worlds." + world.getName().toLowerCase() + ".permission");
if (permission == null) return;
if (player.hasPermission(permission)) return;
} else if (plugin.getSystem().equalsIgnoreCase("ranks"))
if (permission == null)
{
return;
}
if (player.hasPermission(permission))
{
return;
}
}
else if (plugin.getSystem().equalsIgnoreCase("ranks"))
{
if (plugin.config.contains("worlds." + world.getName().toLowerCase() + ".requiredLevels"))
{
@NotNull List<String> requiredLevel = plugin.config.getStringList("worlds." + world.getName().toLowerCase() + ".requiredLevels");
if (checkLevel(plexPlayer, requiredLevel.toArray(String[]::new))) return;
} else {
if (checkLevel(plexPlayer, requiredLevel.toArray(String[]::new)))
{
return;
}
}
else
{
return;
}
}
@ -64,15 +75,27 @@ public class WorldListener extends PlexListener
if (plugin.getSystem().equalsIgnoreCase("permissions"))
{
String permission = plugin.config.getString("worlds." + world.getName().toLowerCase() + ".permission");
if (permission == null) return;
if (player.hasPermission(permission)) return;
} else if (plugin.getSystem().equalsIgnoreCase("ranks"))
if (permission == null)
{
return;
}
if (player.hasPermission(permission))
{
return;
}
}
else if (plugin.getSystem().equalsIgnoreCase("ranks"))
{
if (plugin.config.contains("worlds." + world.getName().toLowerCase() + ".requiredLevels"))
{
@NotNull List<String> requiredLevel = plugin.config.getStringList("worlds." + world.getName().toLowerCase() + ".requiredLevels");
if (checkLevel(plexPlayer, requiredLevel.toArray(String[]::new))) return;
} else {
if (checkLevel(plexPlayer, requiredLevel.toArray(String[]::new)))
{
return;
}
}
else
{
return;
}
}
@ -121,7 +144,8 @@ public class WorldListener extends PlexListener
return false;
}
}
} else if (required.startsWith("Rank"))
}
else if (required.startsWith("Rank"))
{
String rankString = required.split("\\.")[1];
Rank rank = Rank.valueOf(rankString.toUpperCase(Locale.ROOT));

View File

@ -8,16 +8,6 @@ import dev.plex.event.PunishedPlayerFreezeEvent;
import dev.plex.event.PunishedPlayerMuteEvent;
import dev.plex.punishment.Punishment;
import dev.plex.util.PlexLog;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.Setter;
import lombok.SneakyThrows;
import org.apache.commons.io.FileUtils;
import org.bukkit.Bukkit;
import org.json.JSONArray;
import org.json.JSONObject;
import org.json.JSONTokener;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
@ -27,6 +17,15 @@ import java.util.List;
import java.util.Map;
import java.util.UUID;
import java.util.stream.Collectors;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.Setter;
import lombok.SneakyThrows;
import org.apache.commons.io.FileUtils;
import org.bukkit.Bukkit;
import org.json.JSONArray;
import org.json.JSONObject;
import org.json.JSONTokener;
@Getter
public class PunishedPlayer extends PlexBase
@ -79,7 +78,8 @@ public class PunishedPlayer extends PlexBase
try
{
file.createNewFile();
} catch (IOException e)
}
catch (IOException e)
{
e.printStackTrace();
}
@ -91,7 +91,10 @@ public class PunishedPlayer extends PlexBase
@SneakyThrows
public void convertPunishments()
{
if (!plugin.getRedisConnection().isEnabled()) return;
if (!plugin.getRedisConnection().isEnabled())
{
return;
}
List<Punishment> punishments = Lists.newArrayList();
File file = getPunishmentsFile();
@ -121,7 +124,8 @@ public class PunishedPlayer extends PlexBase
plugin.getRedisConnection().getJedis().set(uuid, obj.toString());
PlexLog.debug("Updated Redis Punishments to match with file");
}
} else
}
else
{
plugin.getRedisConnection().getJedis().set(uuid, obj.toString());
}
@ -137,9 +141,15 @@ public class PunishedPlayer extends PlexBase
if (plugin.getRedisConnection().isEnabled())
{
PlexLog.debug("Getting punishments from Redis...");
if (!plugin.getRedisConnection().getJedis().exists(uuid)) return punishments;
if (!plugin.getRedisConnection().getJedis().exists(uuid))
{
return punishments;
}
String strObj = plugin.getRedisConnection().getJedis().get(uuid);
if (strObj.isEmpty() || !strObj.startsWith("{")) return punishments;
if (strObj.isEmpty() || !strObj.startsWith("{"))
{
return punishments;
}
JSONObject object = new JSONObject(strObj);
object.getJSONObject(uuid).getJSONArray("punishments").forEach(obj ->
{
@ -169,7 +179,8 @@ public class PunishedPlayer extends PlexBase
Punishment punishment = Punishment.fromJson(obj.toString());
punishments.add(punishment);
});
} catch (FileNotFoundException e)
}
catch (FileNotFoundException e)
{
e.printStackTrace();
}
@ -182,7 +193,8 @@ public class PunishedPlayer extends PlexBase
try
{
return !FileUtils.readFileToString(file, StandardCharsets.UTF_8).trim().isEmpty();
} catch (IOException e)
}
catch (IOException e)
{
e.printStackTrace();
}

View File

@ -8,13 +8,6 @@ import dev.plex.cache.PlayerCache;
import dev.plex.player.PunishedPlayer;
import dev.plex.util.PlexLog;
import dev.plex.util.PlexUtils;
import org.apache.commons.io.FileUtils;
import org.bukkit.Bukkit;
import org.bukkit.scheduler.BukkitRunnable;
import org.json.JSONObject;
import org.json.JSONTokener;
import redis.clients.jedis.Jedis;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileWriter;
@ -26,6 +19,12 @@ import java.util.List;
import java.util.Map;
import java.util.UUID;
import java.util.stream.Collectors;
import org.apache.commons.io.FileUtils;
import org.bukkit.Bukkit;
import org.bukkit.scheduler.BukkitRunnable;
import org.json.JSONObject;
import org.json.JSONTokener;
import redis.clients.jedis.Jedis;
public class PunishmentManager extends PlexBase
{
@ -51,7 +50,8 @@ public class PunishmentManager extends PlexBase
writer.append(object.toString(8));
writer.flush();
writer.close();
} else
}
else
{
JSONObject object = new JSONObject();
Map<String, List<String>> punishments = Maps.newHashMap();
@ -73,7 +73,8 @@ public class PunishmentManager extends PlexBase
writer.flush();
writer.close();
}
} catch (IOException e)
}
catch (IOException e)
{
e.printStackTrace();
}
@ -84,7 +85,8 @@ public class PunishmentManager extends PlexBase
try
{
return !FileUtils.readFileToString(file, StandardCharsets.UTF_8).trim().isEmpty();
} catch (IOException e)
}
catch (IOException e)
{
e.printStackTrace();
}
@ -120,7 +122,8 @@ public class PunishmentManager extends PlexBase
punishments.add(punishment);
}
});
} catch (IllegalArgumentException e)
}
catch (IllegalArgumentException e)
{
}
@ -161,7 +164,8 @@ public class PunishmentManager extends PlexBase
if (PlayerCache.getPunishedPlayerMap().containsKey(uuid))
{
player = PlayerCache.getPunishedPlayer(uuid);
} else
}
else
{
player = new PunishedPlayer(uuid);
}
@ -188,7 +192,8 @@ public class PunishmentManager extends PlexBase
writer.append(object.toString());
writer.flush();
writer.close();
} catch (IOException e)
}
catch (IOException e)
{
e.printStackTrace();
}
@ -224,7 +229,8 @@ public class PunishmentManager extends PlexBase
Bukkit.getLogger().info("Unfroze");
}
}.runTaskLater(Plex.get(), 20 * seconds);
} else if (punishment.getType() == PunishmentType.MUTE)
}
else if (punishment.getType() == PunishmentType.MUTE)
{
player.setMuted(true);
LocalDateTime now = LocalDateTime.now();

View File

@ -5,17 +5,16 @@ import dev.plex.player.PlexPlayer;
import dev.plex.rank.enums.Rank;
import dev.plex.rank.enums.Title;
import dev.plex.util.PlexUtils;
import lombok.SneakyThrows;
import org.json.JSONArray;
import org.json.JSONObject;
import org.json.JSONTokener;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Arrays;
import java.util.stream.Collectors;
import lombok.SneakyThrows;
import org.json.JSONArray;
import org.json.JSONObject;
import org.json.JSONTokener;
public class RankManager
{
@ -82,7 +81,8 @@ public class RankManager
Title.valueOf(key).setLoginMessage(title.getJSONObject(key).getString("loginMessage"));
Title.valueOf(key).setPrefix(title.getJSONObject(key).getString("prefix"));
});
} catch (IOException e)
}
catch (IOException e)
{
e.printStackTrace();
}

View File

@ -1,11 +1,5 @@
package dev.plex.rank.enums;
import com.google.common.collect.Lists;
import java.util.Arrays;
import java.util.List;
import com.google.gson.Gson;
import lombok.Getter;
import lombok.Setter;
import org.bukkit.ChatColor;

View File

@ -4,7 +4,6 @@ import dev.plex.Plex;
import dev.plex.punishment.Punishment;
import dev.plex.services.AbstractService;
import java.time.LocalDateTime;
import net.kyori.adventure.text.Component;
import org.bukkit.Bukkit;

View File

@ -2,13 +2,6 @@ package dev.plex.util;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonDeserializer;
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;
import org.json.JSONObject;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.time.Instant;
@ -16,6 +9,12 @@ import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.util.Arrays;
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;
import org.json.JSONObject;
public class MojangUtils
{

View File

@ -9,7 +9,7 @@ server:
- "&cForums: https://forum.plex.us.org"
titles:
masterbuilders: []
masterbuilders: [ ]
owners:
- Telesphoreo