mirror of
https://github.com/plexusorg/Plex.git
synced 2024-12-22 09:07:37 +00:00
doesnt compile
This commit is contained in:
parent
f1744f2050
commit
f5c5c75ee1
@ -5,13 +5,13 @@ import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import me.totalfreedom.plex.cache.MongoPlayerData;
|
||||
import me.totalfreedom.plex.cache.SQLPlayerData;
|
||||
import me.totalfreedom.plex.config.MainConfig;
|
||||
import me.totalfreedom.plex.listeners.PlayerListener;
|
||||
import me.totalfreedom.plex.rank.RankManager;
|
||||
import me.totalfreedom.plex.storage.MongoConnection;
|
||||
import me.totalfreedom.plex.storage.RedisConnection;
|
||||
import me.totalfreedom.plex.storage.SQLConnection;
|
||||
import me.totalfreedom.plex.storage.StorageType;
|
||||
import me.totalfreedom.plex.util.PlexLog;
|
||||
import me.totalfreedom.plex.util.PlexUtils;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
@ -22,6 +22,8 @@ public class Plex extends JavaPlugin
|
||||
@Setter(AccessLevel.NONE)
|
||||
private static Plex plugin;
|
||||
|
||||
public MainConfig config;
|
||||
|
||||
private StorageType storageType = StorageType.SQLITE;
|
||||
|
||||
private SQLConnection sqlConnection;
|
||||
@ -33,13 +35,17 @@ public class Plex extends JavaPlugin
|
||||
|
||||
private RankManager rankManager;
|
||||
|
||||
public static Plex get()
|
||||
{
|
||||
return plugin;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLoad()
|
||||
{
|
||||
plugin = this;
|
||||
|
||||
getConfig().options().copyDefaults(true);
|
||||
saveConfig();
|
||||
config = new MainConfig(this, "config.yml");
|
||||
|
||||
saveResource("database.db", false);
|
||||
|
||||
@ -58,12 +64,16 @@ public class Plex extends JavaPlugin
|
||||
@Override
|
||||
public void onEnable()
|
||||
{
|
||||
config.load();
|
||||
|
||||
PlexUtils.testConnections();
|
||||
|
||||
if (storageType == StorageType.MONGO)
|
||||
{
|
||||
mongoPlayerData = new MongoPlayerData();
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
sqlPlayerData = new SQLPlayerData();
|
||||
}
|
||||
|
||||
@ -77,14 +87,11 @@ public class Plex extends JavaPlugin
|
||||
@Override
|
||||
public void onDisable()
|
||||
{
|
||||
config.save();
|
||||
/*if (redisConnection.getJedis().isConnected())
|
||||
{
|
||||
PlexLog.log("Disabling Redis/Jedis. No memory leaks in this Anarchy server !");
|
||||
redisConnection.getJedis().close();
|
||||
}*/
|
||||
}
|
||||
|
||||
public static Plex get() {
|
||||
return plugin;
|
||||
}
|
||||
}
|
@ -1,61 +1,57 @@
|
||||
package me.totalfreedom.plex.cache;
|
||||
|
||||
import dev.morphia.query.Query;
|
||||
import dev.morphia.query.UpdateOperations;
|
||||
import java.util.UUID;
|
||||
import me.totalfreedom.plex.Plex;
|
||||
import me.totalfreedom.plex.player.PlexPlayer;
|
||||
import org.mongodb.morphia.query.FindOptions;
|
||||
import org.mongodb.morphia.query.Query;
|
||||
import org.mongodb.morphia.query.UpdateOperations;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public class MongoPlayerData
|
||||
{
|
||||
|
||||
private PlexPlayerDAO plexPlayerDAO;
|
||||
private final PlexPlayerDAO plexPlayerDAO;
|
||||
|
||||
public MongoPlayerData()
|
||||
{
|
||||
this.plexPlayerDAO = new PlexPlayerDAO(PlexPlayer.class, Plex.get().getMongoConnection().getDatastore());
|
||||
}
|
||||
|
||||
public boolean exists(UUID uuid) {
|
||||
public boolean exists(UUID uuid)
|
||||
{
|
||||
|
||||
Query<PlexPlayer> query = plexPlayerDAO.createQuery();
|
||||
|
||||
if (query.field("uuid").exists().field("uuid").equal(uuid.toString()).get() != null)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
return query.field("uuid").exists().field("uuid").equal(uuid.toString()).find().tryNext() != null;
|
||||
}
|
||||
|
||||
public PlexPlayer getByUUID(UUID uuid) {
|
||||
public PlexPlayer getByUUID(UUID uuid)
|
||||
{
|
||||
|
||||
if (PlayerCache.getPlexPlayerMap().containsKey(uuid))
|
||||
{
|
||||
return PlayerCache.getPlexPlayerMap().get(uuid);
|
||||
}
|
||||
Query<PlexPlayer> query2 = plexPlayerDAO.createQuery().field("uuid").exists().field("uuid").equal(uuid.toString());
|
||||
return query2.get();
|
||||
return query2.first();
|
||||
}
|
||||
|
||||
public void update(PlexPlayer player)
|
||||
{
|
||||
Query<PlexPlayer> filter = plexPlayerDAO.createQuery()
|
||||
.field("uuid").equal(player.getUuid());
|
||||
.field("uuid").equal(player.getUuid());
|
||||
|
||||
UpdateOperations<PlexPlayer> updateOps = plexPlayerDAO.createUpdateOperations();
|
||||
|
||||
updateOps.set("name", player.getName());
|
||||
updateOps.set("loginMSG", player.getLoginMSG());
|
||||
updateOps.set("prefix", player.getPrefix());
|
||||
updateOps.set("rank", player.getRank().toLowerCase());
|
||||
updateOps.set("rank", player.getRank() == null ? "" : player.getRank().name().toLowerCase());
|
||||
updateOps.set("ips", player.getIps());
|
||||
updateOps.set("coins", player.getCoins());
|
||||
plexPlayerDAO.update(filter, updateOps);
|
||||
}
|
||||
|
||||
public PlexPlayerDAO getPlexPlayerDAO() {
|
||||
public PlexPlayerDAO getPlexPlayerDAO()
|
||||
{
|
||||
return plexPlayerDAO;
|
||||
}
|
||||
}
|
||||
|
@ -1,23 +1,23 @@
|
||||
package me.totalfreedom.plex.cache;
|
||||
|
||||
import com.google.common.collect.Maps;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import me.totalfreedom.plex.player.PlexPlayer;
|
||||
import me.totalfreedom.plex.player.PunishedPlayer;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
public class PlayerCache
|
||||
{
|
||||
private static final Map<UUID, PlexPlayer> plexPlayerMap = Maps.newHashMap();
|
||||
private static final Map<UUID, PunishedPlayer> punishedPlayerMap = Maps.newHashMap();
|
||||
|
||||
private static Map<UUID, PlexPlayer> plexPlayerMap = Maps.newHashMap();
|
||||
private static Map<UUID, PunishedPlayer> punishedPlayerMap = Maps.newHashMap();
|
||||
|
||||
public static Map<UUID, PunishedPlayer> getPunishedPlayerMap() {
|
||||
public static Map<UUID, PunishedPlayer> getPunishedPlayerMap()
|
||||
{
|
||||
return punishedPlayerMap;
|
||||
}
|
||||
|
||||
public static Map<UUID, PlexPlayer> getPlexPlayerMap() {
|
||||
public static Map<UUID, PlexPlayer> getPlexPlayerMap()
|
||||
{
|
||||
return plexPlayerMap;
|
||||
}
|
||||
}
|
||||
|
@ -8,41 +8,46 @@ import org.mongodb.morphia.query.Query;
|
||||
import org.mongodb.morphia.query.UpdateOperations;
|
||||
import org.mongodb.morphia.query.UpdateResults;
|
||||
|
||||
public class PlexPlayerDAO extends BasicDAO<PlexPlayer, Object> {
|
||||
|
||||
|
||||
public class PlexPlayerDAO extends BasicDAO<PlexPlayer, Object>
|
||||
{
|
||||
public PlexPlayerDAO(Class<PlexPlayer> entityclass, Datastore ds)
|
||||
{
|
||||
super(entityclass, ds);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean exists(Query<PlexPlayer> query) {
|
||||
public boolean exists(Query<PlexPlayer> query)
|
||||
{
|
||||
return super.exists(query);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlexPlayer findOne(String key, Object value) {
|
||||
public PlexPlayer findOne(String key, Object value)
|
||||
{
|
||||
return super.findOne(key, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlexPlayer get(Object id) {
|
||||
public PlexPlayer get(Object id)
|
||||
{
|
||||
return super.get(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public UpdateResults update(Query<PlexPlayer> query, UpdateOperations<PlexPlayer> ops) {
|
||||
public UpdateResults update(Query<PlexPlayer> query, UpdateOperations<PlexPlayer> ops)
|
||||
{
|
||||
return super.update(query, ops);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
public boolean equals(Object obj)
|
||||
{
|
||||
return super.equals(obj);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Key<PlexPlayer> save(PlexPlayer entity) {
|
||||
public Key<PlexPlayer> save(PlexPlayer entity)
|
||||
{
|
||||
return super.save(entity);
|
||||
}
|
||||
}
|
||||
|
@ -2,20 +2,18 @@ package me.totalfreedom.plex.cache;
|
||||
|
||||
import com.google.common.reflect.TypeToken;
|
||||
import com.google.gson.Gson;
|
||||
import me.totalfreedom.plex.Plex;
|
||||
import me.totalfreedom.plex.player.PlexPlayer;
|
||||
import me.totalfreedom.plex.rank.enums.Rank;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import me.totalfreedom.plex.Plex;
|
||||
import me.totalfreedom.plex.player.PlexPlayer;
|
||||
import me.totalfreedom.plex.rank.enums.Rank;
|
||||
|
||||
public class SQLPlayerData
|
||||
{
|
||||
|
||||
private final String SELECT = "SELECT * FROM `players` WHERE uuid=?";
|
||||
private final String UPDATE = "UPDATE `players` SET name=?, login_msg=?, prefix=?, rank=?, ips=?, coins=? WHERE uuid=?";
|
||||
private final String INSERT = "INSERT INTO `players` (`uuid`, `name`, `login_msg`, `prefix`, `rank`, `ips`, `coins`) VALUES (?, ?, ?, ?, ?, ?, ?);";
|
||||
@ -29,7 +27,8 @@ public class SQLPlayerData
|
||||
ResultSet set = statement.executeQuery();
|
||||
return set.next();
|
||||
}
|
||||
catch (SQLException throwables) {
|
||||
catch (SQLException throwables)
|
||||
{
|
||||
throwables.printStackTrace();
|
||||
}
|
||||
return false;
|
||||
@ -56,7 +55,9 @@ public class SQLPlayerData
|
||||
String rankName = set.getString("rank").toUpperCase();
|
||||
long coins = set.getLong("coins");
|
||||
Rank rank = Rank.valueOf(rankName);
|
||||
List<String> ips = new Gson().fromJson(set.getString("ips"), new TypeToken<List<String>>(){}.getType());
|
||||
List<String> ips = new Gson().fromJson(set.getString("ips"), new TypeToken<List<String>>()
|
||||
{
|
||||
}.getType());
|
||||
plexPlayer.setName(name);
|
||||
plexPlayer.setLoginMSG(loginMSG);
|
||||
plexPlayer.setPrefix(prefix);
|
||||
@ -66,7 +67,8 @@ public class SQLPlayerData
|
||||
}
|
||||
return plexPlayer;
|
||||
}
|
||||
catch (SQLException throwables) {
|
||||
catch (SQLException throwables)
|
||||
{
|
||||
throwables.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
@ -86,7 +88,8 @@ public class SQLPlayerData
|
||||
statement.setString(7, player.getUuid());
|
||||
statement.executeUpdate();
|
||||
}
|
||||
catch (SQLException throwables) {
|
||||
catch (SQLException throwables)
|
||||
{
|
||||
throwables.printStackTrace();
|
||||
}
|
||||
}
|
||||
@ -104,7 +107,8 @@ public class SQLPlayerData
|
||||
statement.setString(6, new Gson().toJson(player.getIps()));
|
||||
statement.execute();
|
||||
}
|
||||
catch (SQLException throwables) {
|
||||
catch (SQLException throwables)
|
||||
{
|
||||
throwables.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
@ -1,62 +0,0 @@
|
||||
package me.totalfreedom.plex.config;
|
||||
|
||||
import me.totalfreedom.plex.Plex;
|
||||
import me.totalfreedom.plex.util.PlexLog;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
public class Config
|
||||
{
|
||||
|
||||
private File file;
|
||||
|
||||
|
||||
public Config(String name, boolean copy)
|
||||
{
|
||||
if (copy)
|
||||
{
|
||||
Plex.get().saveResource(name, false);
|
||||
} else {
|
||||
file = new File(Plex.get().getDataFolder(), name);
|
||||
if (!file.exists())
|
||||
{
|
||||
try {
|
||||
file.createNewFile();
|
||||
PlexLog.log("Generating " + name + " configuration file!");
|
||||
} catch (IOException e) {
|
||||
PlexLog.error(String.format("An error occured trying to create the following file: %s", name));
|
||||
e.printStackTrace();
|
||||
}
|
||||
} else {
|
||||
PlexLog.log(name + " configuration file was loaded.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Config(String name, boolean copy, File folder)
|
||||
{
|
||||
if (copy)
|
||||
{
|
||||
Plex.get().saveResource(name, false);
|
||||
} else {
|
||||
file = new File(folder, name);
|
||||
if (!file.exists())
|
||||
{
|
||||
try {
|
||||
file.createNewFile();
|
||||
PlexLog.log("Generating " + name + " configuration file!");
|
||||
} catch (IOException e) {
|
||||
PlexLog.error(String.format("An error occured trying to create the following file: %s", name));
|
||||
e.printStackTrace();
|
||||
}
|
||||
} else {
|
||||
PlexLog.log(name + " configuration file was loaded.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public File getFile() {
|
||||
return file;
|
||||
}
|
||||
}
|
52
src/main/java/me/totalfreedom/plex/config/MainConfig.java
Normal file
52
src/main/java/me/totalfreedom/plex/config/MainConfig.java
Normal file
@ -0,0 +1,52 @@
|
||||
package me.totalfreedom.plex.config;
|
||||
|
||||
import java.io.File;
|
||||
import me.totalfreedom.plex.Plex;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
|
||||
public class MainConfig extends YamlConfiguration
|
||||
{
|
||||
private static MainConfig config;
|
||||
private final Plex plugin;
|
||||
private final File file;
|
||||
|
||||
public MainConfig(Plex plugin, String configName)
|
||||
{
|
||||
this.plugin = plugin;
|
||||
this.file = new File(plugin.getDataFolder(), configName);
|
||||
|
||||
if (!file.exists())
|
||||
{
|
||||
saveDefault(configName);
|
||||
}
|
||||
}
|
||||
|
||||
public void load()
|
||||
{
|
||||
try
|
||||
{
|
||||
super.load(file);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void save()
|
||||
{
|
||||
try
|
||||
{
|
||||
super.save(file);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private void saveDefault(String configName)
|
||||
{
|
||||
plugin.saveResource(configName, false);
|
||||
}
|
||||
}
|
@ -1,44 +0,0 @@
|
||||
package me.totalfreedom.plex.config;
|
||||
|
||||
import org.bukkit.configuration.InvalidConfigurationException;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
public class YamlConfig
|
||||
{
|
||||
|
||||
private YamlConfiguration config;
|
||||
private File file;
|
||||
|
||||
public YamlConfig(File file)
|
||||
{
|
||||
this.file = file;
|
||||
this.config = YamlConfiguration.loadConfiguration(file);
|
||||
}
|
||||
|
||||
public YamlConfiguration get() {
|
||||
return config;
|
||||
}
|
||||
|
||||
public void save()
|
||||
{
|
||||
try {
|
||||
this.config.save(file);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void reload()
|
||||
{
|
||||
try {
|
||||
this.config.load(file);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} catch (InvalidConfigurationException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
@ -1,5 +1,6 @@
|
||||
package me.totalfreedom.plex.listeners;
|
||||
|
||||
import java.util.Arrays;
|
||||
import me.totalfreedom.plex.Plex;
|
||||
import me.totalfreedom.plex.cache.MongoPlayerData;
|
||||
import me.totalfreedom.plex.cache.PlayerCache;
|
||||
@ -13,13 +14,10 @@ import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
public class PlayerListener implements Listener
|
||||
{
|
||||
|
||||
private MongoPlayerData mongoPlayerData = Plex.get().getMongoPlayerData() != null ? Plex.get().getMongoPlayerData() : null;
|
||||
private SQLPlayerData sqlPlayerData = Plex.get().getSqlPlayerData() != null ? Plex.get().getSqlPlayerData() : null;
|
||||
private final MongoPlayerData mongoPlayerData = Plex.get().getMongoPlayerData() != null ? Plex.get().getMongoPlayerData() : null;
|
||||
private final SQLPlayerData sqlPlayerData = Plex.get().getSqlPlayerData() != null ? Plex.get().getSqlPlayerData() : null;
|
||||
|
||||
@EventHandler
|
||||
public void onJoin(PlayerJoinEvent event)
|
||||
@ -38,12 +36,14 @@ public class PlayerListener implements Listener
|
||||
plexPlayer.setIps(Arrays.asList(player.getAddress().getAddress().getHostAddress().trim())); //set the arraylist of ips
|
||||
|
||||
mongoPlayerData.getPlexPlayerDAO().save(plexPlayer); //and put their document in mongo collection
|
||||
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
plexPlayer = mongoPlayerData.getByUUID(player.getUniqueId()); //oh they do exist!
|
||||
plexPlayer.setName(plexPlayer.getName()); //set the name!
|
||||
}
|
||||
} else if (sqlPlayerData != null)
|
||||
}
|
||||
else if (sqlPlayerData != null)
|
||||
{
|
||||
if (!sqlPlayerData.exists(player.getUniqueId())) //okay, we're saving with mongo! now check if the player's document exists
|
||||
{
|
||||
@ -51,10 +51,10 @@ public class PlayerListener implements Listener
|
||||
plexPlayer = new PlexPlayer(player.getUniqueId()); //it doesn't! okay so now create the object
|
||||
plexPlayer.setName(player.getName()); //set the name of the player
|
||||
plexPlayer.setIps(Arrays.asList(player.getAddress().getAddress().getHostAddress().trim())); //set the arraylist of ips
|
||||
|
||||
sqlPlayerData.insert(plexPlayer); //and put their document in mongo collection
|
||||
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
plexPlayer = sqlPlayerData.getByUUID(player.getUniqueId()); //oh they do exist!
|
||||
plexPlayer.setName(plexPlayer.getName()); //set the name!
|
||||
}
|
||||
@ -72,14 +72,13 @@ public class PlayerListener implements Listener
|
||||
if (mongoPlayerData != null) //back to mongo checking
|
||||
{
|
||||
mongoPlayerData.update(plexPlayer); //update the player's document
|
||||
} else if (sqlPlayerData != null)
|
||||
}
|
||||
else if (sqlPlayerData != null)
|
||||
{
|
||||
sqlPlayerData.update(plexPlayer);
|
||||
}
|
||||
|
||||
PlayerCache.getPlexPlayerMap().remove(event.getPlayer().getUniqueId()); //remove them from cache
|
||||
PlayerCache.getPunishedPlayerMap().remove(event.getPlayer().getUniqueId());
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,21 +1,19 @@
|
||||
package me.totalfreedom.plex.player;
|
||||
|
||||
import dev.morphia.annotations.Entity;
|
||||
import dev.morphia.annotations.Id;
|
||||
import dev.morphia.annotations.IndexOptions;
|
||||
import dev.morphia.annotations.Indexed;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import me.totalfreedom.plex.rank.enums.Rank;
|
||||
import org.mongodb.morphia.annotations.Entity;
|
||||
import org.mongodb.morphia.annotations.Id;
|
||||
import org.mongodb.morphia.annotations.IndexOptions;
|
||||
import org.mongodb.morphia.annotations.Indexed;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
|
||||
@Entity(value = "players", noClassnameStored = true)
|
||||
public class PlexPlayer
|
||||
{
|
||||
@ -35,12 +33,10 @@ public class PlexPlayer
|
||||
|
||||
private long coins;
|
||||
|
||||
private String rank;
|
||||
private Rank rank;
|
||||
|
||||
private List<String> ips;
|
||||
|
||||
public PlexPlayer(){}
|
||||
|
||||
public PlexPlayer(UUID playerUUID)
|
||||
{
|
||||
this.uuid = playerUUID.toString();
|
||||
@ -56,12 +52,6 @@ public class PlexPlayer
|
||||
|
||||
this.ips = new ArrayList<>();
|
||||
|
||||
this.rank = "";
|
||||
this.rank = null;
|
||||
}
|
||||
|
||||
public Rank getRankFromString()
|
||||
{
|
||||
return Rank.valueOf(rank.toUpperCase());
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,21 +1,18 @@
|
||||
package me.totalfreedom.plex.player;
|
||||
|
||||
import java.util.UUID;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
public class PunishedPlayer
|
||||
{
|
||||
//everything in here will be stored in redis
|
||||
|
||||
@Setter(AccessLevel.NONE)
|
||||
private String uuid;
|
||||
|
||||
|
||||
private boolean muted;
|
||||
private boolean frozen;
|
||||
|
||||
|
@ -1,23 +1,19 @@
|
||||
package me.totalfreedom.plex.rank;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import java.util.List;
|
||||
import lombok.Getter;
|
||||
import me.totalfreedom.plex.rank.enums.Rank;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Getter
|
||||
public class DefaultRankObj
|
||||
{
|
||||
|
||||
private String name;
|
||||
private List<String> permissions;
|
||||
private final String name;
|
||||
private final List<String> permissions;
|
||||
|
||||
public DefaultRankObj(Rank rank)
|
||||
{
|
||||
this.name = rank.name().toUpperCase();
|
||||
this.permissions = Lists.newArrayList();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -1,18 +1,18 @@
|
||||
package me.totalfreedom.plex.rank;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import java.io.File;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import me.totalfreedom.plex.Plex;
|
||||
import me.totalfreedom.plex.rank.enums.Rank;
|
||||
import me.totalfreedom.plex.util.PlexLog;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.List;
|
||||
|
||||
public class RankManager
|
||||
{
|
||||
|
||||
private File defaultRanks;
|
||||
private final File defaultRanks;
|
||||
|
||||
public RankManager()
|
||||
{
|
||||
@ -24,8 +24,11 @@ public class RankManager
|
||||
if (defaultRanks.exists())
|
||||
{
|
||||
return;
|
||||
} else {
|
||||
try {
|
||||
}
|
||||
else
|
||||
{
|
||||
try
|
||||
{
|
||||
defaultRanks.createNewFile();
|
||||
|
||||
List<DefaultRankObj> ranks = Lists.newArrayList();
|
||||
@ -45,11 +48,11 @@ public class RankManager
|
||||
writer.close();
|
||||
PlexLog.log("Generating default-ranks.json");
|
||||
}
|
||||
|
||||
} catch (IOException e) {
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -4,28 +4,29 @@ import org.bukkit.ChatColor;
|
||||
|
||||
public enum Rank
|
||||
{
|
||||
IMPOSTER(-1, ChatColor.AQUA + "an " + ChatColor.YELLOW + "Imposter", ChatColor.YELLOW + "[Imp]"),
|
||||
NONOP(0, ChatColor.WHITE + "a " + ChatColor.WHITE + "Non-Op", ChatColor.WHITE + ""),
|
||||
OP(1, ChatColor.GREEN + "an " + ChatColor.GREEN + "Operator", ChatColor.GREEN + "[OP]"),
|
||||
ADMIN(2, ChatColor.DARK_GREEN + "an " + ChatColor.DARK_GREEN + "Admin", ChatColor.DARK_GREEN + "[Admin]"),
|
||||
SENIOR_ADMIN(3, ChatColor.GOLD + "a " + ChatColor.GOLD + "Senior Admin", ChatColor.GOLD + "[SrA]"),
|
||||
EXECUTIVE(4, ChatColor.RED + "an " + ChatColor.RED + "Executive", ChatColor.RED + "[Exec]");
|
||||
|
||||
IMPOSTER(0, ChatColor.AQUA + "an " + ChatColor.YELLOW + "Imposter", ChatColor.YELLOW + "[IMP]"),
|
||||
ADMIN(1, ChatColor.AQUA + "an " + ChatColor.AQUA + "Admin", ChatColor.AQUA + "[ADMIN]"),
|
||||
SENIOR_ADMIN(2, ChatColor.AQUA + "a " + ChatColor.LIGHT_PURPLE + "Senior Admin", ChatColor.LIGHT_PURPLE + "[SrA]"),
|
||||
EXECUTIVE(3, ChatColor.AQUA + "an " + ChatColor.RED + "Executive", ChatColor.RED + "[EXEC]");
|
||||
private final String loginMessage;
|
||||
private final String prefix;
|
||||
|
||||
private int level;
|
||||
private String loginMSG;
|
||||
private String prefix;
|
||||
|
||||
Rank(int level, String loginMSG, String prefix)
|
||||
Rank(int level, String loginMessage, String prefix)
|
||||
{
|
||||
this.level = level;
|
||||
this.loginMSG = loginMSG;
|
||||
this.loginMessage = loginMessage;
|
||||
this.prefix = prefix;
|
||||
}
|
||||
|
||||
public String getPrefix() {
|
||||
public String getPrefix()
|
||||
{
|
||||
return prefix;
|
||||
}
|
||||
|
||||
public String getLoginMSG() {
|
||||
return loginMSG;
|
||||
public String getLoginMSG()
|
||||
{
|
||||
return loginMessage;
|
||||
}
|
||||
}
|
||||
|
@ -4,8 +4,7 @@ import org.bukkit.ChatColor;
|
||||
|
||||
public enum Title
|
||||
{
|
||||
|
||||
MASTER_BUILDER(0,ChatColor.AQUA + "a " + ChatColor.DARK_AQUA + "Master Builder", ChatColor.DARK_AQUA + "[MB]"),
|
||||
MASTER_BUILDER(0, ChatColor.AQUA + "a " + ChatColor.DARK_AQUA + "Master Builder", ChatColor.DARK_AQUA + "[MB]"),
|
||||
DEV(1, ChatColor.AQUA + "a " + ChatColor.DARK_PURPLE + "Developer", ChatColor.DARK_PURPLE + "[DEV]"),
|
||||
OWNER(2, ChatColor.AQUA + "an " + ChatColor.BLUE + "Owner", ChatColor.BLUE + "[Owner]");
|
||||
|
||||
@ -19,5 +18,4 @@ public enum Title
|
||||
this.loginMSG = loginMSG;
|
||||
this.prefix = prefix;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -2,43 +2,36 @@ package me.totalfreedom.plex.storage;
|
||||
|
||||
import com.mongodb.MongoClient;
|
||||
import com.mongodb.MongoClientURI;
|
||||
import dev.morphia.Datastore;
|
||||
import dev.morphia.Morphia;
|
||||
import me.totalfreedom.plex.Plex;
|
||||
import me.totalfreedom.plex.player.PlexPlayer;
|
||||
import org.mongodb.morphia.Datastore;
|
||||
import org.mongodb.morphia.Morphia;
|
||||
|
||||
public class MongoConnection
|
||||
{
|
||||
|
||||
// USE MORPHIA API FOR MONGO <3
|
||||
|
||||
private Plex plugin = Plex.get();
|
||||
private final Plex plugin = Plex.get();
|
||||
|
||||
public Datastore getDatastore()
|
||||
{
|
||||
if (!plugin.getConfig().getString("data.central.storage").equalsIgnoreCase("mongodb"))
|
||||
if (!plugin.config().getString("data.central.storage").equalsIgnoreCase("mongodb"))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
String host = plugin.getConfig().getString("data.central.hostname");
|
||||
int port = plugin.getConfig().getInt("data.central.port");
|
||||
String username = plugin.getConfig().getString("data.central.user");
|
||||
String password = plugin.getConfig().getString("data.central.password");
|
||||
String database = plugin.getConfig().getString("data.central.db");
|
||||
|
||||
String connectionString = "mongodb://" + username + ":" + password + "@" + host + ":" + port + "/?authSource=" + database;
|
||||
String host = plugin.config().getString("data.central.hostname");
|
||||
int port = plugin.config().getInt("data.central.port");
|
||||
String username = plugin.config().getString("data.central.user");
|
||||
String password = plugin.config().getString("data.central.password");
|
||||
String database = plugin.config().getString("data.central.db");
|
||||
|
||||
String connectionString = "mongodb://" + username + ":" + password + "@" + host + ":" + port + "/?authSource=" + database;
|
||||
MongoClient client = new MongoClient(new MongoClientURI(connectionString));
|
||||
|
||||
Morphia morphia = new Morphia();
|
||||
Datastore datastore = morphia.createDatastore(client, database);
|
||||
|
||||
morphia.map(PlexPlayer.class);
|
||||
datastore.getMapper().addMappedClass(PlexPlayer.class);
|
||||
datastore.ensureIndexes();
|
||||
|
||||
plugin.setStorageType(StorageType.MONGO);
|
||||
|
||||
return datastore;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -7,7 +7,6 @@ import redis.clients.jedis.JedisPoolConfig;
|
||||
|
||||
public class RedisConnection
|
||||
{
|
||||
|
||||
private JedisPool pool;
|
||||
private Jedis jedis;
|
||||
|
||||
|
@ -1,45 +1,46 @@
|
||||
package me.totalfreedom.plex.storage;
|
||||
|
||||
import me.totalfreedom.plex.Plex;
|
||||
|
||||
import java.io.File;
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.SQLException;
|
||||
import me.totalfreedom.plex.Plex;
|
||||
|
||||
public class SQLConnection
|
||||
{
|
||||
private Plex plugin = Plex.get();
|
||||
private final Plex plugin = Plex.get();
|
||||
|
||||
private Connection connection;
|
||||
|
||||
public Connection getCon()
|
||||
{
|
||||
String host = plugin.getConfig().getString("data.central.hostname");
|
||||
int port = plugin.getConfig().getInt("data.central.port");
|
||||
String username = plugin.getConfig().getString("data.central.user");
|
||||
String password = plugin.getConfig().getString("data.central.password");
|
||||
String database = plugin.getConfig().getString("data.central.db");
|
||||
String host = plugin.config.getString("data.central.hostname");
|
||||
int port = plugin.config.getInt("data.central.port");
|
||||
String username = plugin.config.getString("data.central.user");
|
||||
String password = plugin.config.getString("data.central.password");
|
||||
String database = plugin.config.getString("data.central.db");
|
||||
|
||||
try {
|
||||
if (plugin.getConfig().getString("data.central.storage").equalsIgnoreCase("sqlite"))
|
||||
try
|
||||
{
|
||||
if (plugin.config.getString("data.central.storage").equalsIgnoreCase("sqlite"))
|
||||
{
|
||||
connection = DriverManager.getConnection("jdbc:sqlite:" + new File(plugin.getDataFolder(), "database.db").getAbsolutePath());
|
||||
Plex.get().setStorageType(StorageType.SQLITE);
|
||||
}
|
||||
else if (plugin.getConfig().getString("data.central.storage").equalsIgnoreCase("mysql"))
|
||||
else if (plugin.config.getString("data.central.storage").equalsIgnoreCase("mysql"))
|
||||
{
|
||||
connection = DriverManager.getConnection("jdbc:mysql://" + host + ":" + port + "/" + database, username, password);
|
||||
Plex.get().setStorageType(StorageType.SQL);
|
||||
}
|
||||
} catch (SQLException throwables) {
|
||||
}
|
||||
catch (SQLException throwables)
|
||||
{
|
||||
throwables.printStackTrace();
|
||||
}
|
||||
|
||||
try {
|
||||
if (connection != null)
|
||||
{
|
||||
connection.prepareStatement("CREATE TABLE IF NOT EXISTS `players` (\n" +
|
||||
try
|
||||
{
|
||||
connection.prepareStatement("CREATE TABLE IF NOT EXISTS `players` (\n" +
|
||||
"\t`uuid` VARCHAR(46),\n" +
|
||||
"\t`name` VARCHAR(18),\n" +
|
||||
"\t`login_msg` VARCHAR(256),\n" +
|
||||
@ -49,13 +50,11 @@ public class SQLConnection
|
||||
"\t`coins` BIGINT,\n" +
|
||||
"\tPRIMARY KEY (`uuid`)\n" +
|
||||
");").execute();
|
||||
}
|
||||
} catch (SQLException throwables) {
|
||||
}
|
||||
catch (SQLException throwables)
|
||||
{
|
||||
throwables.printStackTrace();
|
||||
}
|
||||
|
||||
return connection;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -4,7 +4,6 @@ import me.totalfreedom.plex.Plex;
|
||||
|
||||
public class PlexLog
|
||||
{
|
||||
|
||||
public static void log(String message)
|
||||
{
|
||||
Plex.get().getServer().getConsoleSender().sendMessage(String.format("§e[Plex] §7%s", message));
|
||||
@ -14,5 +13,4 @@ public class PlexLog
|
||||
{
|
||||
Plex.get().getServer().getConsoleSender().sendMessage(String.format("§c[Plex Error] §6%s", message));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,13 +1,11 @@
|
||||
package me.totalfreedom.plex.util;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import me.totalfreedom.plex.Plex;
|
||||
import me.totalfreedom.plex.storage.StorageType;
|
||||
|
||||
import java.sql.SQLException;
|
||||
|
||||
public class PlexUtils
|
||||
{
|
||||
|
||||
public static void testConnections()
|
||||
{
|
||||
if (Plex.get().getSqlConnection().getCon() != null)
|
||||
@ -15,15 +13,20 @@ public class PlexUtils
|
||||
if (Plex.get().getStorageType() == StorageType.SQL)
|
||||
{
|
||||
PlexLog.log("Successfully enabled MySQL!");
|
||||
} else if (Plex.get().getStorageType() == StorageType.SQLITE)
|
||||
}
|
||||
else if (Plex.get().getStorageType() == StorageType.SQLITE)
|
||||
{
|
||||
PlexLog.log("Successfully enabled SQLite!");
|
||||
}
|
||||
try {
|
||||
try
|
||||
{
|
||||
Plex.get().getSqlConnection().getCon().close();
|
||||
} catch (SQLException throwables) {
|
||||
}
|
||||
} else if (Plex.get().getMongoConnection().getDatastore() != null)
|
||||
catch (SQLException ignored)
|
||||
{
|
||||
}
|
||||
}
|
||||
else if (Plex.get().getMongoConnection().getDatastore() != null)
|
||||
{
|
||||
PlexLog.log("Successfully enabled MongoDB!");
|
||||
}
|
||||
|
@ -2,4 +2,4 @@ name: ${project.name}
|
||||
version: ${project.version}
|
||||
author: Telesphoreo
|
||||
main: me.totalfreedom.plex.Plex
|
||||
api-version: 1.16
|
||||
api-version: 1.16
|
Loading…
Reference in New Issue
Block a user