mirror of
https://github.com/plexusorg/Plex.git
synced 2025-06-29 14:56:43 +00:00
tttt
This commit is contained in:
141
src/main/java/dev/plex/Plex.java
Normal file
141
src/main/java/dev/plex/Plex.java
Normal file
@ -0,0 +1,141 @@
|
||||
package dev.plex;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import dev.plex.admin.AdminList;
|
||||
import dev.plex.banning.BanManager;
|
||||
import dev.plex.cache.MongoPlayerData;
|
||||
import dev.plex.cache.SQLPlayerData;
|
||||
import dev.plex.config.Config;
|
||||
import dev.plex.handlers.CommandHandler;
|
||||
import dev.plex.handlers.ListenerHandler;
|
||||
import dev.plex.punishment.PunishmentManager;
|
||||
import dev.plex.rank.RankManager;
|
||||
import dev.plex.services.ServiceManager;
|
||||
import dev.plex.storage.MongoConnection;
|
||||
import dev.plex.storage.RedisConnection;
|
||||
import dev.plex.storage.SQLConnection;
|
||||
import dev.plex.storage.StorageType;
|
||||
import dev.plex.util.PlexLog;
|
||||
import dev.plex.util.PlexUtils;
|
||||
import dev.plex.world.CustomWorld;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
public class Plex extends JavaPlugin
|
||||
{
|
||||
private static Plex plugin;
|
||||
public Config config;
|
||||
public Config messages;
|
||||
private StorageType storageType = StorageType.SQLITE;
|
||||
|
||||
private SQLConnection sqlConnection;
|
||||
private MongoConnection mongoConnection;
|
||||
private RedisConnection redisConnection;
|
||||
|
||||
private MongoPlayerData mongoPlayerData;
|
||||
private SQLPlayerData sqlPlayerData;
|
||||
|
||||
private RankManager rankManager;
|
||||
private ServiceManager serviceManager;
|
||||
|
||||
private PunishmentManager punishmentManager;
|
||||
private BanManager banManager;
|
||||
|
||||
private AdminList adminList;
|
||||
|
||||
public static Plex get()
|
||||
{
|
||||
return plugin;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLoad()
|
||||
{
|
||||
plugin = this;
|
||||
config = new Config(this, "config.yml");
|
||||
messages = new Config(this, "messages.yml");
|
||||
saveResource("database.db", false);
|
||||
|
||||
sqlConnection = new SQLConnection();
|
||||
mongoConnection = new MongoConnection();
|
||||
redisConnection = new RedisConnection();
|
||||
/*try {
|
||||
redisConnection.openPool();
|
||||
PlexLog.log("Successfully opened redis pool. Closing.");
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
redisConnection.getJedis().close();*/
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEnable()
|
||||
{
|
||||
config.load();
|
||||
messages.load();
|
||||
|
||||
try
|
||||
{
|
||||
PlexUtils.testConnections();
|
||||
PlexLog.log("Connected to " + storageType.name().toUpperCase());
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
PlexLog.error("Failed to connect to " + storageType.name().toUpperCase());
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
if (storageType == StorageType.MONGODB)
|
||||
{
|
||||
mongoPlayerData = new MongoPlayerData();
|
||||
}
|
||||
else
|
||||
{
|
||||
sqlPlayerData = new SQLPlayerData();
|
||||
}
|
||||
|
||||
new ListenerHandler(); // this doesn't need a variable.
|
||||
new CommandHandler();
|
||||
|
||||
rankManager = new RankManager();
|
||||
rankManager.generateDefaultRanks();
|
||||
rankManager.importDefaultRanks();
|
||||
PlexLog.log("Rank Manager initialized");
|
||||
|
||||
punishmentManager = new PunishmentManager();
|
||||
banManager = new BanManager();
|
||||
PlexLog.log("Punishment System initialized");
|
||||
|
||||
serviceManager = new ServiceManager();
|
||||
PlexLog.log("Service Manager initialized");
|
||||
|
||||
serviceManager.startServices();
|
||||
PlexLog.log("Started " + serviceManager.serviceCount() + " services.");
|
||||
|
||||
adminList = new AdminList();
|
||||
|
||||
generateWorlds();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisable()
|
||||
{
|
||||
/*if (redisConnection.getJedis().isConnected())
|
||||
{
|
||||
PlexLog.log("Disabling Redis/Jedis. No memory leaks in this Anarchy server !");
|
||||
redisConnection.getJedis().close();
|
||||
}*/
|
||||
}
|
||||
|
||||
private void generateWorlds()
|
||||
{
|
||||
PlexLog.log("Generating any worlds if needed...");
|
||||
for (String key : config.getConfigurationSection("worlds").getKeys(false))
|
||||
{
|
||||
CustomWorld.generateConfigFlatWorld(key);
|
||||
}
|
||||
PlexLog.log("Finished with world generation!");
|
||||
}
|
||||
}
|
6
src/main/java/dev/plex/PlexBase.java
Normal file
6
src/main/java/dev/plex/PlexBase.java
Normal file
@ -0,0 +1,6 @@
|
||||
package dev.plex;
|
||||
|
||||
public class PlexBase
|
||||
{
|
||||
protected static Plex plugin = Plex.get();
|
||||
}
|
28
src/main/java/dev/plex/admin/Admin.java
Normal file
28
src/main/java/dev/plex/admin/Admin.java
Normal file
@ -0,0 +1,28 @@
|
||||
package dev.plex.admin;
|
||||
|
||||
import java.util.UUID;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import dev.plex.rank.enums.Rank;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
public class Admin
|
||||
{
|
||||
@Setter(AccessLevel.NONE)
|
||||
private UUID uuid;
|
||||
|
||||
private Rank rank;
|
||||
|
||||
private boolean commandSpy = true;
|
||||
private boolean staffChat = false;
|
||||
|
||||
public Admin(UUID uuid)
|
||||
{
|
||||
this.uuid = uuid;
|
||||
this.rank = Rank.ADMIN;
|
||||
}
|
||||
|
||||
|
||||
}
|
74
src/main/java/dev/plex/admin/AdminList.java
Normal file
74
src/main/java/dev/plex/admin/AdminList.java
Normal file
@ -0,0 +1,74 @@
|
||||
package dev.plex.admin;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Maps;
|
||||
import dev.morphia.Datastore;
|
||||
import dev.morphia.query.Query;
|
||||
import dev.plex.Plex;
|
||||
import dev.plex.player.PlexPlayer;
|
||||
import dev.plex.storage.StorageType;
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import dev.plex.rank.enums.Rank;
|
||||
|
||||
public class AdminList
|
||||
{
|
||||
|
||||
private final Map<UUID, Admin> admins = Maps.newHashMap();
|
||||
|
||||
public void addToCache(Admin admin)
|
||||
{
|
||||
admins.put(admin.getUuid(), admin);
|
||||
}
|
||||
|
||||
public void removeFromCache(UUID uuid)
|
||||
{
|
||||
admins.remove(uuid);
|
||||
}
|
||||
|
||||
|
||||
public List<String> getAllAdmins()
|
||||
{
|
||||
List<String> admins = Lists.newArrayList();
|
||||
if (Plex.get().getStorageType() == StorageType.MONGODB)
|
||||
{
|
||||
Datastore store = Plex.get().getMongoConnection().getDatastore();
|
||||
Query<PlexPlayer> query = store.find(PlexPlayer.class);
|
||||
for (PlexPlayer player : query)
|
||||
{
|
||||
if (player.getRankFromString().isAtLeast(Rank.ADMIN))
|
||||
{
|
||||
admins.add(player.getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
try (Connection con = Plex.get().getSqlConnection().getCon())
|
||||
{
|
||||
PreparedStatement statement = con.prepareStatement("SELECT * FROM `players` WHERE rank IN(?, ?, ?)");
|
||||
statement.setString(1, Rank.ADMIN.name().toLowerCase());
|
||||
statement.setString(2, Rank.SENIOR_ADMIN.name().toLowerCase());
|
||||
statement.setString(3, Rank.EXECUTIVE.name().toLowerCase());
|
||||
|
||||
ResultSet set = statement.executeQuery();
|
||||
while (set.next())
|
||||
{
|
||||
admins.add(set.getString("name"));
|
||||
}
|
||||
|
||||
}
|
||||
catch (SQLException throwables)
|
||||
{
|
||||
throwables.printStackTrace();
|
||||
}
|
||||
}
|
||||
return admins;
|
||||
}
|
||||
|
||||
}
|
61
src/main/java/dev/plex/banning/Ban.java
Normal file
61
src/main/java/dev/plex/banning/Ban.java
Normal file
@ -0,0 +1,61 @@
|
||||
package dev.plex.banning;
|
||||
|
||||
import dev.morphia.annotations.Entity;
|
||||
import dev.morphia.annotations.Id;
|
||||
import dev.morphia.annotations.IndexOptions;
|
||||
import dev.morphia.annotations.Indexed;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.apache.commons.lang.RandomStringUtils;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.UUID;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@Entity(value = "bans", useDiscriminator = false)
|
||||
public class Ban
|
||||
{
|
||||
public Ban()
|
||||
{
|
||||
}
|
||||
|
||||
@Setter(AccessLevel.NONE)
|
||||
@Id
|
||||
private String id;
|
||||
|
||||
@Setter(AccessLevel.NONE)
|
||||
@Indexed(options = @IndexOptions(unique = true))
|
||||
private UUID uuid;
|
||||
|
||||
@Indexed // have the banner be indexed in the future to get bans issued by a person
|
||||
private UUID banner;
|
||||
|
||||
private String ip;
|
||||
private String reason;
|
||||
private Date endDate;
|
||||
private boolean active;
|
||||
|
||||
public Ban(UUID uuid, UUID banner, String ip, String reason, Date endDate)
|
||||
{
|
||||
this.uuid = uuid;
|
||||
this.id = uuid.toString().substring(0, 8) + "-" + RandomStringUtils.randomAlphabetic(6);
|
||||
this.banner = banner;
|
||||
this.ip = ip;
|
||||
this.reason = reason;
|
||||
this.endDate = endDate;
|
||||
this.active = true;
|
||||
}
|
||||
|
||||
public Ban(String id, UUID uuid, UUID banner, String ip, String reason, Date endDate)
|
||||
{
|
||||
this.uuid = uuid;
|
||||
this.id = id;
|
||||
this.banner = banner;
|
||||
this.ip = ip;
|
||||
this.reason = reason;
|
||||
this.endDate = endDate;
|
||||
this.active = true;
|
||||
}
|
||||
}
|
155
src/main/java/dev/plex/banning/BanManager.java
Normal file
155
src/main/java/dev/plex/banning/BanManager.java
Normal file
@ -0,0 +1,155 @@
|
||||
package dev.plex.banning;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import dev.morphia.query.Query;
|
||||
import dev.morphia.query.experimental.filters.Filters;
|
||||
import dev.morphia.query.experimental.updates.UpdateOperators;
|
||||
import dev.morphia.query.internal.MorphiaCursor;
|
||||
import dev.plex.Plex;
|
||||
import dev.plex.storage.StorageType;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
public class BanManager
|
||||
{
|
||||
private final String SELECT = "SELECT * FROM `bans` WHERE uuid=?";
|
||||
private final String INSERT = "INSERT INTO `bans` (`banID`, `uuid`, `banner`, `ip`, `reason`, `enddate`, `active`) VALUES (?, ?, ?, ?, ?, ?, ?);";
|
||||
|
||||
public void executeBan(Ban ban)
|
||||
{
|
||||
if (Plex.get().getStorageType() == StorageType.MONGODB)
|
||||
{
|
||||
Plex.get().getMongoConnection().getDatastore().save(ban);
|
||||
} else {
|
||||
try (Connection con = Plex.get().getSqlConnection().getCon())
|
||||
{
|
||||
|
||||
PreparedStatement statement = con.prepareStatement(INSERT);
|
||||
statement.setString(1, ban.getId());
|
||||
statement.setString(2, ban.getUuid().toString());
|
||||
statement.setString(3, ban.getBanner() == null ? "" : ban.getBanner().toString());
|
||||
statement.setString(4, ban.getIp());
|
||||
statement.setString(5, ban.getReason());
|
||||
statement.setLong(6, ban.getEndDate().toInstant().toEpochMilli());
|
||||
statement.setBoolean(7, ban.isActive());
|
||||
statement.execute();
|
||||
|
||||
} catch (SQLException throwables) {
|
||||
throwables.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isBanned(UUID uuid)
|
||||
{
|
||||
if (Plex.get().getStorageType() == StorageType.MONGODB)
|
||||
{
|
||||
return Plex.get().getMongoConnection().getDatastore().find(Ban.class)
|
||||
.filter(Filters.eq("uuid", uuid.toString())).filter(Filters.eq("active", true)).first() != null;
|
||||
} else {
|
||||
try (Connection con = Plex.get().getSqlConnection().getCon())
|
||||
{
|
||||
PreparedStatement statement = con.prepareStatement(SELECT);
|
||||
statement.setString(1, uuid.toString());
|
||||
ResultSet set = statement.executeQuery();
|
||||
if (!set.next()) return false;
|
||||
while (set.next())
|
||||
{
|
||||
if (set.getBoolean("active")) return true;
|
||||
}
|
||||
} catch (SQLException throwables) {
|
||||
throwables.printStackTrace();
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void unban(UUID uuid)
|
||||
{
|
||||
if (Plex.get().getStorageType() == StorageType.MONGODB)
|
||||
{
|
||||
Query<Ban> query = Plex.get().getMongoConnection().getDatastore().find(Ban.class).filter(Filters.eq("uuid", uuid.toString())).filter(Filters.eq("active", true));
|
||||
if (query.first() != null)
|
||||
{
|
||||
query.update(UpdateOperators.set("active", false)).execute();
|
||||
}
|
||||
} else {
|
||||
try (Connection con = Plex.get().getSqlConnection().getCon())
|
||||
{
|
||||
PreparedStatement statement = con.prepareStatement("UPDATE `bans` SET active=? WHERE uuid=?");
|
||||
statement.setBoolean(1, false);
|
||||
statement.setString(2, uuid.toString());
|
||||
statement.executeUpdate();
|
||||
} catch (SQLException throwables) {
|
||||
throwables.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void unban(String id)
|
||||
{
|
||||
if (Plex.get().getStorageType() == StorageType.MONGODB)
|
||||
{
|
||||
Query<Ban> query = Plex.get().getMongoConnection().getDatastore().find(Ban.class).filter(Filters.eq("_id", id)).filter(Filters.eq("active", true));
|
||||
if (query.first() != null)
|
||||
{
|
||||
query.update(UpdateOperators.set("active", false)).execute();
|
||||
}
|
||||
} else {
|
||||
try (Connection con = Plex.get().getSqlConnection().getCon())
|
||||
{
|
||||
PreparedStatement statement = con.prepareStatement("UPDATE `bans` SET active=? WHERE banID=?");
|
||||
statement.setBoolean(1, false);
|
||||
statement.setString(2, id);
|
||||
statement.executeUpdate();
|
||||
} catch (SQLException throwables) {
|
||||
throwables.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public List<Ban> getActiveBans()
|
||||
{
|
||||
List<Ban> bans = Lists.newArrayList();
|
||||
if (Plex.get().getStorageType() == StorageType.MONGODB)
|
||||
{
|
||||
MorphiaCursor<Ban> cursor = Plex.get().getMongoConnection().getDatastore().find(Ban.class).filter(Filters.eq("active", true)).iterator();
|
||||
while (cursor.hasNext())
|
||||
{
|
||||
Ban ban = cursor.next();
|
||||
bans.add(ban);
|
||||
}
|
||||
} else {
|
||||
try (Connection con = Plex.get().getSqlConnection().getCon())
|
||||
{
|
||||
PreparedStatement statement = con.prepareStatement("SELECT * FROM `bans`");
|
||||
ResultSet set = statement.executeQuery();
|
||||
while (set.next())
|
||||
{
|
||||
if (set.getBoolean("active"))
|
||||
{
|
||||
String id = set.getString("banID");
|
||||
UUID uuid = UUID.fromString(set.getString("uuid"));
|
||||
UUID banner = set.getString("banner").isEmpty() ? null : UUID.fromString(set.getString("banner"));
|
||||
String ip = set.getString("ip");
|
||||
String reason = set.getString("reason");
|
||||
Date endDate = set.getLong("enddate") != 0 ? new Date(set.getLong("enddate")) : null;
|
||||
Ban ban = new Ban(id, uuid, banner, ip, reason, endDate);
|
||||
bans.add(ban);
|
||||
}
|
||||
}
|
||||
} catch (SQLException throwables) {
|
||||
throwables.printStackTrace();
|
||||
}
|
||||
}
|
||||
return bans;
|
||||
}
|
||||
|
||||
|
||||
}
|
71
src/main/java/dev/plex/cache/DataUtils.java
vendored
Normal file
71
src/main/java/dev/plex/cache/DataUtils.java
vendored
Normal file
@ -0,0 +1,71 @@
|
||||
package dev.plex.cache;
|
||||
|
||||
import dev.plex.Plex;
|
||||
import dev.plex.player.PlexPlayer;
|
||||
import dev.plex.storage.StorageType;
|
||||
import java.util.UUID;
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
public class DataUtils
|
||||
{
|
||||
/* PLEX PLAYER METHODS */
|
||||
|
||||
public static boolean hasPlayedBefore(UUID uuid)
|
||||
{
|
||||
if (Plex.get().getStorageType() == StorageType.MONGODB)
|
||||
{
|
||||
return Plex.get().getMongoPlayerData().exists(uuid);
|
||||
}
|
||||
else
|
||||
{
|
||||
return Plex.get().getSqlPlayerData().exists(uuid);
|
||||
}
|
||||
}
|
||||
|
||||
public static PlexPlayer getPlayer(UUID uuid)
|
||||
{
|
||||
if (PlayerCache.getPlexPlayerMap().containsKey(uuid))
|
||||
{
|
||||
return PlayerCache.getPlexPlayerMap().get(uuid);
|
||||
}
|
||||
|
||||
if (Plex.get().getStorageType() == StorageType.MONGODB)
|
||||
{
|
||||
return Plex.get().getMongoPlayerData().getByUUID(uuid);
|
||||
}
|
||||
else
|
||||
{
|
||||
return Plex.get().getSqlPlayerData().getByUUID(uuid);
|
||||
}
|
||||
}
|
||||
|
||||
public static PlexPlayer getPlayer(String name)
|
||||
{
|
||||
return getPlayer(Bukkit.getPlayer(name).getUniqueId());
|
||||
}
|
||||
|
||||
public static void update(PlexPlayer plexPlayer)
|
||||
{
|
||||
if (Plex.get().getStorageType() == StorageType.MONGODB)
|
||||
{
|
||||
Plex.get().getMongoPlayerData().update(plexPlayer);
|
||||
}
|
||||
else
|
||||
{
|
||||
Plex.get().getSqlPlayerData().update(plexPlayer);
|
||||
}
|
||||
}
|
||||
|
||||
public static void insert(PlexPlayer plexPlayer)
|
||||
{
|
||||
if (Plex.get().getStorageType() == StorageType.MONGODB)
|
||||
{
|
||||
Plex.get().getMongoPlayerData().save(plexPlayer);
|
||||
} else {
|
||||
Plex.get().getSqlPlayerData().insert(plexPlayer);
|
||||
}
|
||||
}
|
||||
|
||||
/* REDIS METHODS AT ONE POINT FOR BANS, AND JSON METHODS FOR PUNISHMENTS */
|
||||
|
||||
}
|
64
src/main/java/dev/plex/cache/MongoPlayerData.java
vendored
Normal file
64
src/main/java/dev/plex/cache/MongoPlayerData.java
vendored
Normal file
@ -0,0 +1,64 @@
|
||||
package dev.plex.cache;
|
||||
|
||||
import dev.morphia.Datastore;
|
||||
import dev.morphia.query.Query;
|
||||
import dev.morphia.query.Update;
|
||||
import dev.morphia.query.experimental.filters.Filters;
|
||||
import dev.morphia.query.experimental.updates.UpdateOperators;
|
||||
import dev.plex.Plex;
|
||||
import dev.plex.player.PlexPlayer;
|
||||
import java.util.UUID;
|
||||
|
||||
public class MongoPlayerData
|
||||
{
|
||||
private final Datastore datastore;
|
||||
|
||||
public MongoPlayerData()
|
||||
{
|
||||
this.datastore = Plex.get().getMongoConnection().getDatastore();
|
||||
}
|
||||
|
||||
public boolean exists(UUID uuid)
|
||||
{
|
||||
Query<PlexPlayer> query = datastore.find(PlexPlayer.class)
|
||||
.filter(Filters.eq("uuid", uuid.toString()));
|
||||
|
||||
return query.first() != null;
|
||||
}
|
||||
|
||||
public PlexPlayer getByUUID(UUID uuid)
|
||||
{
|
||||
if (PlayerCache.getPlexPlayerMap().containsKey(uuid))
|
||||
{
|
||||
return PlayerCache.getPlexPlayerMap().get(uuid);
|
||||
}
|
||||
|
||||
Query<PlexPlayer> query2 = datastore.find(PlexPlayer.class).filter(Filters.eq("uuid", uuid.toString()));
|
||||
return query2.first();
|
||||
}
|
||||
|
||||
public void update(PlexPlayer player)
|
||||
{
|
||||
Query<PlexPlayer> filter = datastore.find(PlexPlayer.class)
|
||||
.filter(Filters.eq("uuid", player.getUuid()));
|
||||
|
||||
Update<PlexPlayer> updateOps = filter
|
||||
.update(
|
||||
UpdateOperators.set("name", player.getName()),
|
||||
UpdateOperators.set("loginMSG", player.getLoginMSG()),
|
||||
UpdateOperators.set("prefix", player.getPrefix()),
|
||||
UpdateOperators.set("rank", player.getRank().toLowerCase()),
|
||||
UpdateOperators.set("ips", player.getIps()),
|
||||
UpdateOperators.set("coins", player.getCoins()),
|
||||
UpdateOperators.set("vanished", player.isVanished()));
|
||||
|
||||
updateOps.execute();
|
||||
}
|
||||
|
||||
|
||||
public void save(PlexPlayer plexPlayer)
|
||||
{
|
||||
datastore.save(plexPlayer);
|
||||
}
|
||||
|
||||
}
|
33
src/main/java/dev/plex/cache/PlayerCache.java
vendored
Normal file
33
src/main/java/dev/plex/cache/PlayerCache.java
vendored
Normal file
@ -0,0 +1,33 @@
|
||||
package dev.plex.cache;
|
||||
|
||||
import com.google.common.collect.Maps;
|
||||
import dev.plex.player.PlexPlayer;
|
||||
import dev.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();
|
||||
|
||||
public static Map<UUID, PunishedPlayer> getPunishedPlayerMap()
|
||||
{
|
||||
return punishedPlayerMap;
|
||||
}
|
||||
|
||||
public static Map<UUID, PlexPlayer> getPlexPlayerMap()
|
||||
{
|
||||
return plexPlayerMap;
|
||||
}
|
||||
|
||||
public static PunishedPlayer getPunishedPlayer(UUID uuid)
|
||||
{
|
||||
return getPunishedPlayerMap().get(uuid);
|
||||
}
|
||||
|
||||
public static PlexPlayer getPlexPlayer(UUID uuid)
|
||||
{
|
||||
return getPlexPlayerMap().get(uuid);
|
||||
}
|
||||
}
|
117
src/main/java/dev/plex/cache/SQLPlayerData.java
vendored
Normal file
117
src/main/java/dev/plex/cache/SQLPlayerData.java
vendored
Normal file
@ -0,0 +1,117 @@
|
||||
package dev.plex.cache;
|
||||
|
||||
import com.google.common.reflect.TypeToken;
|
||||
import com.google.gson.Gson;
|
||||
import dev.plex.Plex;
|
||||
import dev.plex.player.PlexPlayer;
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
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=?, vanished=? WHERE uuid=?";
|
||||
private final String INSERT = "INSERT INTO `players` (`uuid`, `name`, `login_msg`, `prefix`, `rank`, `ips`, `coins`, `vanished`) VALUES (?, ?, ?, ?, ?, ?, ?, ?);";
|
||||
|
||||
public boolean exists(UUID uuid)
|
||||
{
|
||||
try (Connection con = Plex.get().getSqlConnection().getCon())
|
||||
{
|
||||
PreparedStatement statement = con.prepareStatement(SELECT);
|
||||
statement.setString(1, uuid.toString());
|
||||
ResultSet set = statement.executeQuery();
|
||||
return set.next();
|
||||
}
|
||||
catch (SQLException throwables)
|
||||
{
|
||||
throwables.printStackTrace();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public PlexPlayer getByUUID(UUID uuid)
|
||||
{
|
||||
if (PlayerCache.getPlexPlayerMap().containsKey(uuid))
|
||||
{
|
||||
return PlayerCache.getPlexPlayerMap().get(uuid);
|
||||
}
|
||||
|
||||
try (Connection con = Plex.get().getSqlConnection().getCon())
|
||||
{
|
||||
PreparedStatement statement = con.prepareStatement(SELECT);
|
||||
statement.setString(1, uuid.toString());
|
||||
ResultSet set = statement.executeQuery();
|
||||
PlexPlayer plexPlayer = new PlexPlayer(uuid);
|
||||
while (set.next())
|
||||
{
|
||||
String name = set.getString("name");
|
||||
String loginMSG = set.getString("login_msg");
|
||||
String prefix = set.getString("prefix");
|
||||
String rankName = set.getString("rank").toUpperCase();
|
||||
long coins = set.getLong("coins");
|
||||
boolean vanished = set.getBoolean("vanished");
|
||||
List<String> ips = new Gson().fromJson(set.getString("ips"), new TypeToken<List<String>>(){}.getType());
|
||||
plexPlayer.setName(name);
|
||||
plexPlayer.setLoginMSG(loginMSG);
|
||||
plexPlayer.setPrefix(prefix);
|
||||
plexPlayer.setRank(rankName);
|
||||
plexPlayer.setIps(ips);
|
||||
plexPlayer.setCoins(coins);
|
||||
plexPlayer.setVanished(vanished);
|
||||
}
|
||||
return plexPlayer;
|
||||
}
|
||||
catch (SQLException throwables)
|
||||
{
|
||||
throwables.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void update(PlexPlayer player)
|
||||
{
|
||||
try (Connection con = Plex.get().getSqlConnection().getCon())
|
||||
{
|
||||
PreparedStatement statement = con.prepareStatement(UPDATE);
|
||||
statement.setString(1, player.getName());
|
||||
statement.setString(2, player.getLoginMSG());
|
||||
statement.setString(3, player.getPrefix());
|
||||
statement.setString(4, player.getRank().toLowerCase());
|
||||
statement.setString(5, new Gson().toJson(player.getIps()));
|
||||
statement.setLong(6, player.getCoins());
|
||||
statement.setBoolean(7, player.isVanished());
|
||||
statement.setString(8, player.getUuid());
|
||||
statement.executeUpdate();
|
||||
}
|
||||
catch (SQLException throwables)
|
||||
{
|
||||
throwables.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void insert(PlexPlayer player)
|
||||
{
|
||||
try (Connection con = Plex.get().getSqlConnection().getCon())
|
||||
{
|
||||
PreparedStatement statement = con.prepareStatement(INSERT);
|
||||
statement.setString(1, player.getUuid());
|
||||
statement.setString(2, player.getName());
|
||||
statement.setString(3, player.getLoginMSG());
|
||||
statement.setString(4, player.getPrefix());
|
||||
statement.setString(5, player.getRank().toLowerCase());
|
||||
statement.setString(6, new Gson().toJson(player.getIps()));
|
||||
statement.setLong(7, player.getCoins());
|
||||
statement.setBoolean(8, player.isVanished());
|
||||
statement.execute();
|
||||
}
|
||||
catch (SQLException throwables)
|
||||
{
|
||||
throwables.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
11
src/main/java/dev/plex/command/IPlexCommand.java
Normal file
11
src/main/java/dev/plex/command/IPlexCommand.java
Normal file
@ -0,0 +1,11 @@
|
||||
package dev.plex.command;
|
||||
|
||||
import dev.plex.command.source.CommandSource;
|
||||
import java.util.List;
|
||||
|
||||
public interface IPlexCommand
|
||||
{
|
||||
void execute(CommandSource sender, String[] args);
|
||||
|
||||
List<String> onTabComplete(CommandSource sender, String[] args);
|
||||
}
|
265
src/main/java/dev/plex/command/PlexCommand.java
Normal file
265
src/main/java/dev/plex/command/PlexCommand.java
Normal file
@ -0,0 +1,265 @@
|
||||
package dev.plex.command;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import dev.plex.Plex;
|
||||
import dev.plex.command.annotation.CommandParameters;
|
||||
import dev.plex.command.annotation.CommandPermissions;
|
||||
import dev.plex.command.exception.CommandArgumentException;
|
||||
import dev.plex.command.exception.CommandFailException;
|
||||
import dev.plex.command.exception.PlayerNotFoundException;
|
||||
import dev.plex.command.source.CommandSource;
|
||||
import dev.plex.command.source.RequiredCommandSource;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import dev.plex.cache.DataUtils;
|
||||
import dev.plex.cache.PlayerCache;
|
||||
import dev.plex.player.PlexPlayer;
|
||||
import dev.plex.rank.enums.Rank;
|
||||
import dev.plex.util.PlexUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandMap;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.ConsoleCommandSender;
|
||||
import org.bukkit.command.TabExecutor;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public abstract class PlexCommand extends Command implements TabExecutor, IPlexCommand
|
||||
{
|
||||
protected static Plex plugin = Plex.get();
|
||||
|
||||
private final CommandParameters params;
|
||||
private final CommandPermissions perms;
|
||||
|
||||
private final Rank level;
|
||||
private CommandSource sender;
|
||||
private final RequiredCommandSource commandSource;
|
||||
|
||||
public PlexCommand(String name)
|
||||
{
|
||||
super(name);
|
||||
this.params = getClass().getAnnotation(CommandParameters.class);
|
||||
this.perms = getClass().getAnnotation(CommandPermissions.class);
|
||||
|
||||
setName(name);
|
||||
setLabel(name);
|
||||
setDescription(params.description());
|
||||
setUsage(params.usage().replace("<command>", name));
|
||||
if (params.aliases().split(",").length > 0)
|
||||
{
|
||||
setAliases(Arrays.asList(params.aliases().split(",")));
|
||||
}
|
||||
this.level = perms.level();
|
||||
this.commandSource = perms.source();
|
||||
|
||||
getMap().register("", this);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean execute(CommandSender sender, String label, String[] args)
|
||||
{
|
||||
onCommand(sender, this, label, args);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args)
|
||||
{
|
||||
if (!matches(label))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (commandSource == RequiredCommandSource.CONSOLE && sender instanceof Player)
|
||||
{
|
||||
sender.sendMessage(tl("noPermissionInGame"));
|
||||
return true;
|
||||
}
|
||||
if (commandSource == RequiredCommandSource.IN_GAME)
|
||||
{
|
||||
if (sender instanceof ConsoleCommandSender)
|
||||
{
|
||||
sender.sendMessage(tl("noPermissionConsole"));
|
||||
return true;
|
||||
}
|
||||
Player player = (Player)sender;
|
||||
|
||||
this.sender = new CommandSource(player);
|
||||
PlexPlayer plexPlayer = PlayerCache.getPlexPlayerMap().get(player.getUniqueId());
|
||||
if (!plexPlayer.getRankFromString().isAtLeast(getLevel()))
|
||||
{
|
||||
sender.sendMessage(tl("noPermissionRank", ChatColor.stripColor(getLevel().getLoginMSG())));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
try
|
||||
{
|
||||
this.sender = new CommandSource(sender);
|
||||
execute(this.sender, args);
|
||||
}
|
||||
catch (CommandArgumentException ex)
|
||||
{
|
||||
send(getUsage().replace("<command>", getLabel()));
|
||||
}
|
||||
catch (PlayerNotFoundException | CommandFailException ex)
|
||||
{
|
||||
send(ex.getMessage());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> tabComplete(CommandSender sender, String alias, String[] args)
|
||||
{
|
||||
if (!matches(alias))
|
||||
{
|
||||
return ImmutableList.of();
|
||||
}
|
||||
if (sender instanceof Player)
|
||||
{
|
||||
Player player = (Player)sender;
|
||||
|
||||
this.sender = new CommandSource(player);
|
||||
|
||||
PlexPlayer plexPlayer = PlayerCache.getPlexPlayerMap().get(player.getUniqueId());
|
||||
if (plexPlayer.getRankFromString().isAtLeast(getLevel()))
|
||||
{
|
||||
return onTabComplete(this.sender, args);
|
||||
}
|
||||
else
|
||||
{
|
||||
return ImmutableList.of();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
this.sender = new CommandSource(sender);
|
||||
return onTabComplete(this.sender, args);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> onTabComplete(CommandSender sender, Command cmd, String label, String[] args)
|
||||
{
|
||||
return tabComplete(sender, label, args);
|
||||
}
|
||||
|
||||
private boolean matches(String label)
|
||||
{
|
||||
if (params.aliases().split(",").length > 0)
|
||||
{
|
||||
for (String alias : params.aliases().split(","))
|
||||
{
|
||||
if (alias.equalsIgnoreCase(label) || getName().equalsIgnoreCase(label))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (params.aliases().split(",").length < 1)
|
||||
{
|
||||
return getName().equalsIgnoreCase(label);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
protected void send(String s, CommandSource sender)
|
||||
{
|
||||
sender.send(s);
|
||||
}
|
||||
|
||||
protected void send(String s, Player player)
|
||||
{
|
||||
player.sendMessage(s);
|
||||
}
|
||||
|
||||
protected boolean isAdmin(PlexPlayer plexPlayer)
|
||||
{
|
||||
return Plex.get().getRankManager().isAdmin(plexPlayer);
|
||||
}
|
||||
|
||||
protected boolean isAdmin(String name)
|
||||
{
|
||||
PlexPlayer plexPlayer = DataUtils.getPlayer(name);
|
||||
return Plex.get().getRankManager().isAdmin(plexPlayer);
|
||||
}
|
||||
|
||||
protected boolean isConsole()
|
||||
{
|
||||
return !(sender instanceof Player);
|
||||
}
|
||||
|
||||
protected String tl(String s, Object... objects)
|
||||
{
|
||||
return PlexUtils.tl(s, objects);
|
||||
}
|
||||
|
||||
protected String usage(String s)
|
||||
{
|
||||
return ChatColor.YELLOW + "Correct Usage: " + ChatColor.GRAY + s;
|
||||
}
|
||||
|
||||
protected void send(String s)
|
||||
{
|
||||
if (sender == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
send(s, sender);
|
||||
}
|
||||
|
||||
protected Player getNonNullPlayer(String name)
|
||||
{
|
||||
Player player = Bukkit.getPlayer(name);
|
||||
if (player == null)
|
||||
{
|
||||
throw new PlayerNotFoundException();
|
||||
}
|
||||
return player;
|
||||
}
|
||||
|
||||
protected PlexPlayer getOnlinePlexPlayer(String name)
|
||||
{
|
||||
Player player = getNonNullPlayer(name);
|
||||
PlexPlayer plexPlayer = PlayerCache.getPlexPlayer(player.getUniqueId());
|
||||
if (plexPlayer == null)
|
||||
{
|
||||
throw new PlayerNotFoundException();
|
||||
}
|
||||
return plexPlayer;
|
||||
}
|
||||
|
||||
protected PlexPlayer getOfflinePlexPlayer(UUID uuid)
|
||||
{
|
||||
PlexPlayer plexPlayer = PlayerCache.getPlexPlayer(uuid);
|
||||
if (plexPlayer == null)
|
||||
{
|
||||
throw new PlayerNotFoundException();
|
||||
}
|
||||
return plexPlayer;
|
||||
}
|
||||
|
||||
protected World getNonNullWorld(String name)
|
||||
{
|
||||
World world = Bukkit.getWorld(name);
|
||||
if (world == null)
|
||||
{
|
||||
throw new CommandFailException(tl("worldNotFound"));
|
||||
}
|
||||
return world;
|
||||
}
|
||||
|
||||
public Rank getLevel()
|
||||
{
|
||||
return level;
|
||||
}
|
||||
|
||||
public CommandMap getMap()
|
||||
{
|
||||
return Plex.get().getServer().getCommandMap();
|
||||
}
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
package dev.plex.command.annotation;
|
||||
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface CommandParameters
|
||||
{
|
||||
String description() default "";
|
||||
|
||||
String usage() default "/<command>";
|
||||
|
||||
String aliases() default "";
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
package dev.plex.command.annotation;
|
||||
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import dev.plex.command.source.RequiredCommandSource;
|
||||
import dev.plex.rank.enums.Rank;
|
||||
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface CommandPermissions
|
||||
{
|
||||
Rank level() default Rank.IMPOSTOR;
|
||||
|
||||
RequiredCommandSource source() default RequiredCommandSource.ANY;
|
||||
}
|
@ -0,0 +1,5 @@
|
||||
package dev.plex.command.exception;
|
||||
|
||||
public class CommandArgumentException extends RuntimeException
|
||||
{
|
||||
} // lolololol
|
@ -0,0 +1,9 @@
|
||||
package dev.plex.command.exception;
|
||||
|
||||
public class CommandFailException extends RuntimeException // this is literally just a runtime exception lol
|
||||
{
|
||||
public CommandFailException(String s)
|
||||
{
|
||||
super(s);
|
||||
}
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
package dev.plex.command.exception;
|
||||
|
||||
import static dev.plex.util.PlexUtils.tl;
|
||||
|
||||
public class ConsoleMustDefinePlayerException extends RuntimeException
|
||||
{
|
||||
public ConsoleMustDefinePlayerException()
|
||||
{
|
||||
super(tl("consoleMustDefinePlayer"));
|
||||
}
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
package dev.plex.command.exception;
|
||||
|
||||
import static dev.plex.util.PlexUtils.tl;
|
||||
|
||||
public class PlayerNotFoundException extends RuntimeException
|
||||
{
|
||||
public PlayerNotFoundException()
|
||||
{
|
||||
super(tl("playerNotFound"));
|
||||
}
|
||||
}
|
199
src/main/java/dev/plex/command/impl/AdminCMD.java
Normal file
199
src/main/java/dev/plex/command/impl/AdminCMD.java
Normal file
@ -0,0 +1,199 @@
|
||||
package dev.plex.command.impl;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import dev.plex.command.annotation.CommandParameters;
|
||||
import dev.plex.command.annotation.CommandPermissions;
|
||||
import dev.plex.command.exception.PlayerNotFoundException;
|
||||
import dev.plex.command.source.CommandSource;
|
||||
import dev.plex.command.source.RequiredCommandSource;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import dev.plex.cache.DataUtils;
|
||||
import dev.plex.command.PlexCommand;
|
||||
import dev.plex.event.AdminAddEvent;
|
||||
import dev.plex.event.AdminRemoveEvent;
|
||||
import dev.plex.event.AdminSetRankEvent;
|
||||
import dev.plex.player.PlexPlayer;
|
||||
import dev.plex.rank.enums.Rank;
|
||||
import dev.plex.util.PlexUtils;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
@CommandPermissions(level = Rank.SENIOR_ADMIN, source = RequiredCommandSource.ANY)
|
||||
@CommandParameters(usage = "/<command> <add | remove | setrank | list> [player] [rank]", aliases = "saconfig,slconfig,adminconfig,adminmanage", description = "Manage all admins")
|
||||
public class AdminCMD extends PlexCommand
|
||||
{
|
||||
//TODO: Better return messages
|
||||
|
||||
public AdminCMD()
|
||||
{
|
||||
super("admin");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(CommandSource sender, String[] args)
|
||||
{
|
||||
if (args.length == 0)
|
||||
{
|
||||
sender.send(usage(getUsage()));
|
||||
return;
|
||||
}
|
||||
|
||||
if (args[0].equalsIgnoreCase("add"))
|
||||
{
|
||||
if (args.length != 2)
|
||||
{
|
||||
sender.send(usage("/admin add <player>"));
|
||||
return;
|
||||
}
|
||||
|
||||
if (!sender.isConsoleSender())
|
||||
{
|
||||
sender.send("Console only");
|
||||
return;
|
||||
}
|
||||
|
||||
UUID targetUUID = PlexUtils.getFromName(args[1]);
|
||||
|
||||
if (targetUUID == null || !DataUtils.hasPlayedBefore(targetUUID))
|
||||
{
|
||||
throw new PlayerNotFoundException();
|
||||
}
|
||||
PlexPlayer plexPlayer = DataUtils.getPlayer(targetUUID);
|
||||
|
||||
if (isAdmin(plexPlayer))
|
||||
{
|
||||
sender.send("Player is an admin");
|
||||
return;
|
||||
}
|
||||
|
||||
plexPlayer.setRank(Rank.ADMIN.name());
|
||||
DataUtils.update(plexPlayer);
|
||||
Bukkit.getServer().getPluginManager().callEvent(new AdminAddEvent(sender, plexPlayer));
|
||||
return;
|
||||
}
|
||||
if (args[0].equalsIgnoreCase("remove"))
|
||||
{
|
||||
if (args.length != 2)
|
||||
{
|
||||
sender.send(usage("/admin remove <player>"));
|
||||
return;
|
||||
}
|
||||
|
||||
if (!sender.isConsoleSender())
|
||||
{
|
||||
sender.send("Console only");
|
||||
return;
|
||||
}
|
||||
|
||||
UUID targetUUID = PlexUtils.getFromName(args[1]);
|
||||
|
||||
if (targetUUID == null || !DataUtils.hasPlayedBefore(targetUUID))
|
||||
{
|
||||
throw new PlayerNotFoundException();
|
||||
}
|
||||
PlexPlayer plexPlayer = DataUtils.getPlayer(targetUUID);
|
||||
|
||||
if (!isAdmin(plexPlayer))
|
||||
{
|
||||
sender.send("Player is not an admin");
|
||||
return;
|
||||
}
|
||||
|
||||
plexPlayer.setRank("");
|
||||
DataUtils.update(plexPlayer);
|
||||
Bukkit.getServer().getPluginManager().callEvent(new AdminRemoveEvent(sender, plexPlayer));
|
||||
return;
|
||||
}
|
||||
|
||||
if (args[0].equalsIgnoreCase("setrank"))
|
||||
{
|
||||
if (args.length != 3)
|
||||
{
|
||||
sender.send(usage("/admin setrank <player> <rank>"));
|
||||
return;
|
||||
}
|
||||
|
||||
if (!sender.isConsoleSender())
|
||||
{
|
||||
sender.send("Console only");
|
||||
return;
|
||||
}
|
||||
|
||||
UUID targetUUID = PlexUtils.getFromName(args[1]);
|
||||
|
||||
if (targetUUID == null || !DataUtils.hasPlayedBefore(targetUUID))
|
||||
{
|
||||
throw new PlayerNotFoundException();
|
||||
}
|
||||
|
||||
if (!rankExists(args[2]))
|
||||
{
|
||||
sender.send("Rank not found");
|
||||
return;
|
||||
}
|
||||
|
||||
Rank rank = Rank.valueOf(args[2].toUpperCase());
|
||||
|
||||
if (!rank.isAtLeast(Rank.ADMIN))
|
||||
{
|
||||
sender.send("Must be admin+");
|
||||
return;
|
||||
}
|
||||
|
||||
PlexPlayer plexPlayer = DataUtils.getPlayer(targetUUID);
|
||||
|
||||
if (!isAdmin(plexPlayer))
|
||||
{
|
||||
sender.send("Player is not an admin");
|
||||
return;
|
||||
}
|
||||
|
||||
plexPlayer.setRank(rank.name().toLowerCase());
|
||||
DataUtils.update(plexPlayer);
|
||||
|
||||
Bukkit.getServer().getPluginManager().callEvent(new AdminSetRankEvent(sender, plexPlayer, rank));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (args[0].equalsIgnoreCase("list"))
|
||||
{
|
||||
if (args.length != 1)
|
||||
{
|
||||
sender.send(usage("/admin list"));
|
||||
return;
|
||||
}
|
||||
|
||||
sender.send("Admins: " + StringUtils.join(plugin.getAdminList().getAllAdmins(), ", "));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> onTabComplete(CommandSource sender, String[] args)
|
||||
{
|
||||
if (args.length == 1)
|
||||
{
|
||||
return Arrays.asList("add", "remove", "setrank", "list");
|
||||
}
|
||||
else if (args.length == 2 && !args[0].equalsIgnoreCase("list"))
|
||||
{
|
||||
return PlexUtils.getPlayerNameList();
|
||||
}
|
||||
return ImmutableList.of();
|
||||
}
|
||||
|
||||
private boolean rankExists(String rank)
|
||||
{
|
||||
for (Rank ranks : Rank.values())
|
||||
{
|
||||
if (ranks.name().equalsIgnoreCase(rank))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
72
src/main/java/dev/plex/command/impl/AdventureCMD.java
Normal file
72
src/main/java/dev/plex/command/impl/AdventureCMD.java
Normal file
@ -0,0 +1,72 @@
|
||||
package dev.plex.command.impl;
|
||||
|
||||
import dev.plex.command.annotation.CommandParameters;
|
||||
import dev.plex.command.annotation.CommandPermissions;
|
||||
import dev.plex.command.exception.CommandFailException;
|
||||
import dev.plex.command.source.CommandSource;
|
||||
import dev.plex.command.source.RequiredCommandSource;
|
||||
import java.util.List;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import dev.plex.command.PlexCommand;
|
||||
import dev.plex.rank.enums.Rank;
|
||||
import dev.plex.util.PlexUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@CommandPermissions(level = Rank.OP, source = RequiredCommandSource.ANY)
|
||||
@CommandParameters(aliases = "gma", description = "Set your own or another player's gamemode to adventure mode")
|
||||
public class AdventureCMD extends PlexCommand
|
||||
{
|
||||
public AdventureCMD()
|
||||
{
|
||||
super("adventure");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(CommandSource sender, String[] args)
|
||||
{
|
||||
if (args.length == 0)
|
||||
{
|
||||
// doesn't work
|
||||
if (sender.isConsoleSender())
|
||||
{
|
||||
throw new CommandFailException("You must define a player when using the console!");
|
||||
}
|
||||
|
||||
sender.getPlayer().setGameMode(GameMode.ADVENTURE);
|
||||
send(tl("gameModeSetTo", "adventure"));
|
||||
return;
|
||||
}
|
||||
|
||||
if (isAdmin(sender.getPlexPlayer()))
|
||||
{
|
||||
if (args[0].equals("-a"))
|
||||
{
|
||||
for (Player targetPlayer : Bukkit.getServer().getOnlinePlayers())
|
||||
{
|
||||
targetPlayer.setGameMode(GameMode.ADVENTURE);
|
||||
}
|
||||
send(tl("gameModeSetTo", "adventure"));
|
||||
return;
|
||||
}
|
||||
|
||||
Player player = getNonNullPlayer(args[0]);
|
||||
send(tl("setOtherPlayerGameModeTo", player.getName(), "adventure"));
|
||||
// use send
|
||||
player.sendMessage(tl("playerSetOtherGameMode", sender.getName(), "adventure"));
|
||||
player.setGameMode(GameMode.ADVENTURE);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> onTabComplete(CommandSource sender, String[] args)
|
||||
{
|
||||
if (isAdmin(sender.getPlexPlayer()))
|
||||
{
|
||||
return PlexUtils.getPlayerNameList();
|
||||
}
|
||||
return ImmutableList.of();
|
||||
}
|
||||
}
|
86
src/main/java/dev/plex/command/impl/BanCMD.java
Normal file
86
src/main/java/dev/plex/command/impl/BanCMD.java
Normal file
@ -0,0 +1,86 @@
|
||||
package dev.plex.command.impl;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import dev.plex.command.annotation.CommandParameters;
|
||||
import dev.plex.command.annotation.CommandPermissions;
|
||||
import dev.plex.command.exception.PlayerNotFoundException;
|
||||
import dev.plex.command.source.CommandSource;
|
||||
import dev.plex.command.source.RequiredCommandSource;
|
||||
import dev.plex.punishment.Punishment;
|
||||
import dev.plex.punishment.PunishmentType;
|
||||
import dev.plex.cache.DataUtils;
|
||||
import dev.plex.cache.PlayerCache;
|
||||
import dev.plex.command.PlexCommand;
|
||||
import dev.plex.player.PlexPlayer;
|
||||
import dev.plex.player.PunishedPlayer;
|
||||
import dev.plex.rank.enums.Rank;
|
||||
import dev.plex.util.PlexUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
@CommandParameters(usage = "/<command> <player> [reason]", aliases = "offlineban,gtfo", description = "Bans a player, offline or online")
|
||||
@CommandPermissions(level = Rank.ADMIN, source = RequiredCommandSource.ANY)
|
||||
|
||||
public class BanCMD extends PlexCommand
|
||||
{
|
||||
public BanCMD() {
|
||||
super("ban");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(CommandSource sender, String[] args)
|
||||
{
|
||||
if (args.length == 0)
|
||||
{
|
||||
sender.send(usage(getUsage()));
|
||||
return;
|
||||
}
|
||||
|
||||
if (args.length == 1)
|
||||
{
|
||||
UUID targetUUID = PlexUtils.getFromName(args[0]);
|
||||
|
||||
if (targetUUID == null || !DataUtils.hasPlayedBefore(targetUUID))
|
||||
{
|
||||
throw new PlayerNotFoundException();
|
||||
}
|
||||
PlexPlayer plexPlayer = DataUtils.getPlayer(targetUUID);
|
||||
|
||||
if (isAdmin(plexPlayer))
|
||||
{
|
||||
if (!sender.isConsoleSender())
|
||||
{
|
||||
PlexPlayer plexPlayer1 = sender.getPlexPlayer();
|
||||
if (!plexPlayer1.getRankFromString().isAtLeast(plexPlayer.getRankFromString()))
|
||||
{
|
||||
sender.send("This player is an admin and a higher rank than you.");
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
PunishedPlayer punishedPlayer = PlayerCache.getPunishedPlayer(targetUUID) == null ? new PunishedPlayer(targetUUID) : PlayerCache.getPunishedPlayer(targetUUID);
|
||||
Punishment punishment = new Punishment(targetUUID, !sender.isConsoleSender() ? sender.getPlayer().getUniqueId() : null);
|
||||
punishment.setType(PunishmentType.BAN);
|
||||
punishment.setReason("");
|
||||
punishment.setPunishedUsername(plexPlayer.getName());
|
||||
punishment.setEndDate(new Date(Instant.now().plusSeconds(10/*PlexUtils.secondsToHours(24)*/).getEpochSecond()));
|
||||
punishment.setCustomTime(false);
|
||||
plugin.getPunishmentManager().doPunishment(punishedPlayer, punishment);
|
||||
Bukkit.broadcastMessage(sender.getName() + " - Banning " + plexPlayer.getName());
|
||||
if (Bukkit.getPlayer(targetUUID) != null)
|
||||
{
|
||||
Bukkit.getPlayer(targetUUID).kickPlayer("§cYou've been banned.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> onTabComplete(CommandSource sender, String[] args) {
|
||||
return args.length == 1 ? PlexUtils.getPlayerNameList() : ImmutableList.of();
|
||||
}
|
||||
}
|
71
src/main/java/dev/plex/command/impl/CreativeCMD.java
Normal file
71
src/main/java/dev/plex/command/impl/CreativeCMD.java
Normal file
@ -0,0 +1,71 @@
|
||||
package dev.plex.command.impl;
|
||||
|
||||
import dev.plex.command.annotation.CommandParameters;
|
||||
import dev.plex.command.annotation.CommandPermissions;
|
||||
import dev.plex.command.exception.CommandFailException;
|
||||
import dev.plex.command.source.CommandSource;
|
||||
import dev.plex.command.source.RequiredCommandSource;
|
||||
import java.util.List;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import dev.plex.command.PlexCommand;
|
||||
import dev.plex.rank.enums.Rank;
|
||||
import dev.plex.util.PlexUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@CommandPermissions(level = Rank.OP, source = RequiredCommandSource.ANY)
|
||||
@CommandParameters(aliases = "gmc", description = "Set your own or another player's gamemode to creative mode")
|
||||
public class CreativeCMD extends PlexCommand
|
||||
{
|
||||
public CreativeCMD()
|
||||
{
|
||||
super("creative");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(CommandSource sender, String[] args)
|
||||
{
|
||||
if (args.length == 0)
|
||||
{
|
||||
// doesn't work
|
||||
if (sender.isConsoleSender())
|
||||
{
|
||||
throw new CommandFailException("You must define a player when using the console!");
|
||||
}
|
||||
|
||||
sender.getPlayer().setGameMode(GameMode.CREATIVE);
|
||||
send(tl("gameModeSetTo", "creative"));
|
||||
return;
|
||||
}
|
||||
|
||||
if (isAdmin(sender.getPlexPlayer()))
|
||||
{
|
||||
if (args[0].equals("-a"))
|
||||
{
|
||||
for (Player targetPlayer : Bukkit.getServer().getOnlinePlayers())
|
||||
{
|
||||
targetPlayer.setGameMode(GameMode.CREATIVE);
|
||||
}
|
||||
send(tl("gameModeSetTo", "creative"));
|
||||
return;
|
||||
}
|
||||
|
||||
Player player = getNonNullPlayer(args[0]);
|
||||
send(tl("setOtherPlayerGameModeTo", player.getName(), "creative"));
|
||||
player.sendMessage(tl("playerSetOtherGameMode", sender.getName(), "creative"));
|
||||
player.setGameMode(GameMode.CREATIVE);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> onTabComplete(CommandSource sender, String[] args)
|
||||
{
|
||||
if (isAdmin(sender.getPlexPlayer()))
|
||||
{
|
||||
return PlexUtils.getPlayerNameList();
|
||||
}
|
||||
return ImmutableList.of();
|
||||
}
|
||||
}
|
150
src/main/java/dev/plex/command/impl/FionnCMD.java
Normal file
150
src/main/java/dev/plex/command/impl/FionnCMD.java
Normal file
@ -0,0 +1,150 @@
|
||||
package dev.plex.command.impl;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import dev.plex.command.annotation.CommandParameters;
|
||||
import dev.plex.command.annotation.CommandPermissions;
|
||||
import dev.plex.command.exception.CommandArgumentException;
|
||||
import dev.plex.command.exception.CommandFailException;
|
||||
import dev.plex.command.source.CommandSource;
|
||||
import dev.plex.command.source.RequiredCommandSource;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import dev.plex.cache.PlayerCache;
|
||||
import dev.plex.command.PlexCommand;
|
||||
import dev.plex.util.PlexUtils;
|
||||
import dev.plex.world.BlockMapChunkGenerator;
|
||||
import dev.plex.world.CustomWorld;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Enderman;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.entity.Strider;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
@CommandParameters(description = "Subliminal message.")
|
||||
@CommandPermissions(source = RequiredCommandSource.IN_GAME)
|
||||
public class FionnCMD extends PlexCommand
|
||||
{
|
||||
public static boolean ENABLED = false;
|
||||
public static Map<Player, Location> LOCATION_CACHE = new HashMap<>();
|
||||
|
||||
public FionnCMD()
|
||||
{
|
||||
super("fionn");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(CommandSource sender, String[] args)
|
||||
{
|
||||
if (!sender.getPlayer().getUniqueId().equals(UUID.fromString("9aa3eda6-c271-440a-a578-a952ee9aee2f")))
|
||||
{
|
||||
throw new CommandFailException(tl("noPermission"));
|
||||
}
|
||||
if (args.length != 0)
|
||||
{
|
||||
throw new CommandArgumentException();
|
||||
}
|
||||
String name = "fionn";
|
||||
LinkedHashMap<Material, Integer> map = new LinkedHashMap<>();
|
||||
map.put(Material.CRIMSON_NYLIUM, 1);
|
||||
map.put(Material.BEDROCK, 1);
|
||||
World fionnWorld = new CustomWorld(name, new BlockMapChunkGenerator(map)).generate();
|
||||
ENABLED = true;
|
||||
fionnWorld.setTime(0);
|
||||
fionnWorld.getBlockAt(0, 5, 0).setType(Material.BARRIER);
|
||||
Strider fionn = (Strider)fionnWorld.spawnEntity(new Location(fionnWorld, 12, 6, 6, -180, -3), EntityType.STRIDER);
|
||||
fionn.setCustomNameVisible(true);
|
||||
fionn.setCustomName(ChatColor.GREEN + "fionn");
|
||||
fionn.setAI(false);
|
||||
Enderman elmon = (Enderman)fionnWorld.spawnEntity(new Location(fionnWorld, 12, 6, 0, 0, 18), EntityType.ENDERMAN);
|
||||
elmon.setCustomNameVisible(true);
|
||||
elmon.setCustomName(ChatColor.RED + "elmon");
|
||||
elmon.setInvulnerable(true);
|
||||
elmon.setAware(false);
|
||||
elmon.setGravity(true);
|
||||
// platforms in cage
|
||||
PlexUtils.setBlocks(new Location(fionnWorld, 10, 5, -2), new Location(fionnWorld, 14, 5, 2), Material.SMOOTH_STONE);
|
||||
PlexUtils.setBlocks(new Location(fionnWorld, 10, 9, -2), new Location(fionnWorld, 14, 9, 2), Material.SMOOTH_STONE_SLAB);
|
||||
// iron bars of cage
|
||||
PlexUtils.setBlocks(new Location(fionnWorld, 10, 8, -2), new Location(fionnWorld, 10, 6, 2), Material.IRON_BARS);
|
||||
PlexUtils.setBlocks(new Location(fionnWorld, 14, 8, 2), new Location(fionnWorld, 10, 6, 2), Material.IRON_BARS);
|
||||
PlexUtils.setBlocks(new Location(fionnWorld, 14, 8, 2), new Location(fionnWorld, 14, 6, -2), Material.IRON_BARS);
|
||||
PlexUtils.setBlocks(new Location(fionnWorld, 10, 8, -2), new Location(fionnWorld, 14, 6, -2), Material.IRON_BARS);
|
||||
// lava
|
||||
PlexUtils.setBlocks(new Location(fionnWorld, 10, 1, -2), new Location(fionnWorld, 14, 0, 2), Material.LAVA);
|
||||
|
||||
// iron bars of platform
|
||||
PlexUtils.setBlocks(new Location(fionnWorld, 12, 2, 6), new Location(fionnWorld, 12, 5, 6), Material.IRON_BARS);
|
||||
// platform
|
||||
PlexUtils.setBlocks(new Location(fionnWorld, 11, 6, 7), new Location(fionnWorld, 13, 6, 5), Material.SMOOTH_STONE_SLAB);
|
||||
for (Player p : Bukkit.getOnlinePlayers())
|
||||
{
|
||||
p.setInvisible(true);
|
||||
LOCATION_CACHE.put(p, p.getLocation());
|
||||
p.teleport(new Location(fionnWorld, 0, 5, 0, -90, 0));
|
||||
PlayerCache.getPunishedPlayer(p.getUniqueId()).setFrozen(true);
|
||||
}
|
||||
lateFakeChat("elmon", "fionn! i'm sorry for not being your sex slave...", ChatColor.RED, 20);
|
||||
lateFakeChat("fionn", "it's too late for that now...", ChatColor.GREEN, 60);
|
||||
new BukkitRunnable()
|
||||
{
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
PlexUtils.setBlocks(new Location(fionnWorld, 13, 5, -1), new Location(fionnWorld, 11, 5, 1), Material.AIR);
|
||||
}
|
||||
}.runTaskLater(plugin, 100);
|
||||
new BukkitRunnable()
|
||||
{
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
fionn.teleport(new Location(fionnWorld, 2.5, 5.5, 0, 90, -10));
|
||||
}
|
||||
}.runTaskLater(plugin, 160);
|
||||
new BukkitRunnable()
|
||||
{
|
||||
public void run()
|
||||
{
|
||||
fionn.remove();
|
||||
elmon.remove();
|
||||
for (Player p : Bukkit.getOnlinePlayers())
|
||||
{
|
||||
p.setInvisible(false);
|
||||
Location location = LOCATION_CACHE.get(p);
|
||||
if (location != null)
|
||||
{
|
||||
p.teleport(location);
|
||||
}
|
||||
PlayerCache.getPunishedPlayer(p.getUniqueId()).setFrozen(false);
|
||||
}
|
||||
LOCATION_CACHE.clear();
|
||||
ENABLED = false;
|
||||
}
|
||||
}.runTaskLater(plugin, 200);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> onTabComplete(CommandSource sender, String[] args)
|
||||
{
|
||||
return ImmutableList.of();
|
||||
}
|
||||
|
||||
public static void lateFakeChat(String name, String message, ChatColor color, int delay)
|
||||
{
|
||||
new BukkitRunnable()
|
||||
{
|
||||
public void run()
|
||||
{
|
||||
Bukkit.broadcastMessage(color + name + ChatColor.GRAY + ": " + ChatColor.WHITE + message);
|
||||
}
|
||||
}.runTaskLater(plugin, delay);
|
||||
}
|
||||
}
|
57
src/main/java/dev/plex/command/impl/FreezeCMD.java
Normal file
57
src/main/java/dev/plex/command/impl/FreezeCMD.java
Normal file
@ -0,0 +1,57 @@
|
||||
package dev.plex.command.impl;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
|
||||
import dev.plex.command.annotation.CommandParameters;
|
||||
import dev.plex.command.annotation.CommandPermissions;
|
||||
import dev.plex.command.exception.CommandArgumentException;
|
||||
import dev.plex.command.source.CommandSource;
|
||||
import dev.plex.punishment.Punishment;
|
||||
import dev.plex.punishment.PunishmentType;
|
||||
import java.time.Instant;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import dev.plex.cache.PlayerCache;
|
||||
import dev.plex.command.PlexCommand;
|
||||
import dev.plex.player.PunishedPlayer;
|
||||
import dev.plex.rank.enums.Rank;
|
||||
import dev.plex.util.PlexUtils;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@CommandParameters(description = "Freeze a player on the server", usage = "/<command> <player>")
|
||||
@CommandPermissions(level = Rank.ADMIN)
|
||||
public class FreezeCMD extends PlexCommand
|
||||
{
|
||||
public FreezeCMD()
|
||||
{
|
||||
super("freeze");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(CommandSource sender, String[] args)
|
||||
{
|
||||
if (args.length != 1)
|
||||
{
|
||||
throw new CommandArgumentException();
|
||||
}
|
||||
Player player = getNonNullPlayer(args[0]);
|
||||
PunishedPlayer punishedPlayer = PlayerCache.getPunishedPlayer(player.getUniqueId());
|
||||
Punishment punishment = new Punishment(UUID.fromString(punishedPlayer.getUuid()), sender.isConsoleSender() ? null : sender.getPlayer().getUniqueId());
|
||||
punishment.setCustomTime(false);
|
||||
punishment.setEndDate(new Date(Instant.now().plusSeconds(10).toEpochMilli()));
|
||||
punishment.setType(PunishmentType.FREEZE);
|
||||
punishment.setPunishedUsername(player.getName());
|
||||
punishment.setReason("");
|
||||
|
||||
plugin.getPunishmentManager().doPunishment(punishedPlayer, punishment);
|
||||
PlexUtils.broadcast(tl("frozePlayer", sender.getName(), player.getName()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> onTabComplete(CommandSource sender, String[] args)
|
||||
{
|
||||
return args.length == 1 ? PlexUtils.getPlayerNameList() : ImmutableList.of();
|
||||
}
|
||||
}
|
79
src/main/java/dev/plex/command/impl/NameHistoryCMD.java
Normal file
79
src/main/java/dev/plex/command/impl/NameHistoryCMD.java
Normal file
@ -0,0 +1,79 @@
|
||||
package dev.plex.command.impl;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import dev.plex.command.annotation.CommandParameters;
|
||||
import dev.plex.command.annotation.CommandPermissions;
|
||||
import dev.plex.command.exception.CommandArgumentException;
|
||||
import dev.plex.command.source.CommandSource;
|
||||
import java.io.IOException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import dev.plex.command.PlexCommand;
|
||||
import dev.plex.rank.enums.Rank;
|
||||
import dev.plex.util.PlexUtils;
|
||||
import org.json.simple.JSONArray;
|
||||
import org.json.simple.JSONObject;
|
||||
import org.json.simple.parser.ParseException;
|
||||
|
||||
@CommandParameters(description = "Get the name history of a player", usage = "/<command> <player>", aliases = "nh")
|
||||
@CommandPermissions(level = Rank.OP)
|
||||
public class NameHistoryCMD extends PlexCommand
|
||||
{
|
||||
private static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("MM/dd/yyyy 'at' HH:mm:ss");
|
||||
|
||||
public NameHistoryCMD()
|
||||
{
|
||||
super("namehistory");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(CommandSource sender, String[] args)
|
||||
{
|
||||
if (args.length != 1)
|
||||
{
|
||||
throw new CommandArgumentException();
|
||||
}
|
||||
String username = args[0];
|
||||
JSONArray array;
|
||||
try
|
||||
{
|
||||
JSONObject profile = (JSONObject)PlexUtils.simpleGET("https://api.mojang.com/users/profiles/minecraft/" + username);
|
||||
String uuid = (String)profile.get("id");
|
||||
array = (JSONArray)PlexUtils.simpleGET("https://api.mojang.com/user/profiles/" + uuid + "/names");
|
||||
}
|
||||
catch (ParseException | IOException ex)
|
||||
{
|
||||
send(tl("nameHistoryFail", username));
|
||||
return;
|
||||
}
|
||||
|
||||
array.sort(Comparator.reverseOrder());
|
||||
|
||||
StringBuilder result = new StringBuilder()
|
||||
.append(tl("nameHistoryTitle", username))
|
||||
.append("\n");
|
||||
for (Object o : array)
|
||||
{
|
||||
JSONObject object = (JSONObject)o;
|
||||
Object changedToAt = object.get("changedToAt");
|
||||
if (changedToAt == null)
|
||||
{
|
||||
changedToAt = "O";
|
||||
}
|
||||
else
|
||||
{
|
||||
changedToAt = DATE_FORMAT.format(changedToAt);
|
||||
}
|
||||
result.append(tl("nameHistoryBody", object.get("name"), changedToAt))
|
||||
.append("\n");
|
||||
}
|
||||
send(result.toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> onTabComplete(CommandSource sender, String[] args)
|
||||
{
|
||||
return args.length == 1 ? PlexUtils.getPlayerNameList() : ImmutableList.of();
|
||||
}
|
||||
}
|
38
src/main/java/dev/plex/command/impl/OpAllCMD.java
Normal file
38
src/main/java/dev/plex/command/impl/OpAllCMD.java
Normal file
@ -0,0 +1,38 @@
|
||||
package dev.plex.command.impl;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import dev.plex.command.annotation.CommandParameters;
|
||||
import dev.plex.command.annotation.CommandPermissions;
|
||||
import dev.plex.command.source.CommandSource;
|
||||
import java.util.List;
|
||||
import dev.plex.command.PlexCommand;
|
||||
import dev.plex.rank.enums.Rank;
|
||||
import dev.plex.util.PlexUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@CommandParameters(description = "Op everyone on the server", aliases = "opa")
|
||||
@CommandPermissions(level = Rank.ADMIN)
|
||||
public class OpAllCMD extends PlexCommand
|
||||
{
|
||||
public OpAllCMD()
|
||||
{
|
||||
super("opall");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(CommandSource sender, String[] args)
|
||||
{
|
||||
for (Player player : Bukkit.getOnlinePlayers())
|
||||
{
|
||||
player.setOp(true);
|
||||
}
|
||||
PlexUtils.broadcast(tl("oppedAllPlayers", sender.getName()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> onTabComplete(CommandSource sender, String[] args)
|
||||
{
|
||||
return ImmutableList.of();
|
||||
}
|
||||
}
|
40
src/main/java/dev/plex/command/impl/OpCMD.java
Normal file
40
src/main/java/dev/plex/command/impl/OpCMD.java
Normal file
@ -0,0 +1,40 @@
|
||||
package dev.plex.command.impl;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import dev.plex.command.annotation.CommandParameters;
|
||||
import dev.plex.command.annotation.CommandPermissions;
|
||||
import dev.plex.command.exception.CommandArgumentException;
|
||||
import dev.plex.command.source.CommandSource;
|
||||
import java.util.List;
|
||||
import dev.plex.command.PlexCommand;
|
||||
import dev.plex.rank.enums.Rank;
|
||||
import dev.plex.util.PlexUtils;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@CommandParameters(description = "Op a player on the server", usage = "/<command> <player>")
|
||||
@CommandPermissions(level = Rank.OP)
|
||||
public class OpCMD extends PlexCommand
|
||||
{
|
||||
public OpCMD()
|
||||
{
|
||||
super("op");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(CommandSource sender, String[] args)
|
||||
{
|
||||
if (args.length != 1)
|
||||
{
|
||||
throw new CommandArgumentException();
|
||||
}
|
||||
Player player = getNonNullPlayer(args[0]);
|
||||
player.setOp(true);
|
||||
PlexUtils.broadcast(tl("oppedPlayer", sender.getName(), player.getName()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> onTabComplete(CommandSource sender, String[] args)
|
||||
{
|
||||
return args.length == 1 ? PlexUtils.getPlayerNameList() : ImmutableList.of();
|
||||
}
|
||||
}
|
32
src/main/java/dev/plex/command/impl/PlexCMD.java
Normal file
32
src/main/java/dev/plex/command/impl/PlexCMD.java
Normal file
@ -0,0 +1,32 @@
|
||||
package dev.plex.command.impl;
|
||||
|
||||
import dev.plex.command.annotation.CommandParameters;
|
||||
import dev.plex.command.annotation.CommandPermissions;
|
||||
import dev.plex.command.source.CommandSource;
|
||||
import dev.plex.command.source.RequiredCommandSource;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import dev.plex.command.PlexCommand;
|
||||
import dev.plex.rank.enums.Rank;
|
||||
|
||||
@CommandPermissions(level = Rank.OP, source = RequiredCommandSource.ANY)
|
||||
@CommandParameters(aliases = "plexhelp", description = "Help with plex")
|
||||
public class PlexCMD extends PlexCommand
|
||||
{
|
||||
public PlexCMD()
|
||||
{
|
||||
super("plex");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(CommandSource sender, String[] args)
|
||||
{
|
||||
send("HI");
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> onTabComplete(CommandSource sender, String[] args)
|
||||
{
|
||||
return Arrays.asList("Telesphoreo", "super", "Taahh");
|
||||
}
|
||||
}
|
36
src/main/java/dev/plex/command/impl/PunishmentsCMD.java
Normal file
36
src/main/java/dev/plex/command/impl/PunishmentsCMD.java
Normal file
@ -0,0 +1,36 @@
|
||||
package dev.plex.command.impl;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import dev.plex.command.annotation.CommandParameters;
|
||||
import dev.plex.command.annotation.CommandPermissions;
|
||||
import dev.plex.command.source.CommandSource;
|
||||
import dev.plex.command.source.RequiredCommandSource;
|
||||
import dev.plex.command.PlexCommand;
|
||||
import dev.plex.menu.PunishmentMenu;
|
||||
import dev.plex.rank.enums.Rank;
|
||||
import dev.plex.util.PlexUtils;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@CommandParameters(usage = "/<command> [player]", description = "Opens the Punishments GUI", aliases = "punishlist,punishes")
|
||||
@CommandPermissions(level = Rank.ADMIN, source = RequiredCommandSource.IN_GAME)
|
||||
public class PunishmentsCMD extends PlexCommand
|
||||
{
|
||||
|
||||
public PunishmentsCMD() {
|
||||
super("punishments");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(CommandSource sender, String[] args)
|
||||
{
|
||||
Player player = sender.getPlayer();
|
||||
new PunishmentMenu().openInv(player, 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> onTabComplete(CommandSource sender, String[] args) {
|
||||
return args.length == 1 ? PlexUtils.getPlayerNameList() : ImmutableList.of();
|
||||
}
|
||||
}
|
68
src/main/java/dev/plex/command/impl/SpectatorCMD.java
Normal file
68
src/main/java/dev/plex/command/impl/SpectatorCMD.java
Normal file
@ -0,0 +1,68 @@
|
||||
package dev.plex.command.impl;
|
||||
|
||||
import dev.plex.command.annotation.CommandParameters;
|
||||
import dev.plex.command.annotation.CommandPermissions;
|
||||
import dev.plex.command.exception.CommandFailException;
|
||||
import dev.plex.command.source.CommandSource;
|
||||
import dev.plex.command.source.RequiredCommandSource;
|
||||
import java.util.List;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import dev.plex.command.PlexCommand;
|
||||
import dev.plex.rank.enums.Rank;
|
||||
import dev.plex.util.PlexUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@CommandPermissions(level = Rank.ADMIN, source = RequiredCommandSource.ANY)
|
||||
@CommandParameters(aliases = "gmsp", description = "Set your own or another player's gamemode to spectator mode")
|
||||
public class SpectatorCMD extends PlexCommand
|
||||
{
|
||||
public SpectatorCMD()
|
||||
{
|
||||
super("spectator");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(CommandSource sender, String[] args)
|
||||
{
|
||||
if (args.length == 0)
|
||||
{
|
||||
// doesn't work
|
||||
if (sender.isConsoleSender())
|
||||
{
|
||||
throw new CommandFailException("You must define a player when using the console!");
|
||||
}
|
||||
|
||||
sender.getPlayer().setGameMode(GameMode.SPECTATOR);
|
||||
send(tl("gameModeSetTo", "spectator"));
|
||||
return;
|
||||
}
|
||||
|
||||
if (args[0].equals("-a"))
|
||||
{
|
||||
for (Player targetPlayer : Bukkit.getServer().getOnlinePlayers())
|
||||
{
|
||||
targetPlayer.setGameMode(GameMode.SPECTATOR);
|
||||
}
|
||||
send(tl("gameModeSetTo", "spectator"));
|
||||
return;
|
||||
}
|
||||
|
||||
Player player = getNonNullPlayer(args[0]);
|
||||
send(tl("setOtherPlayerGameModeTo", player.getName(), "spectator"));
|
||||
player.sendMessage(tl("playerSetOtherGameMode", sender.getName(), "spectator"));
|
||||
player.setGameMode(GameMode.SPECTATOR);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> onTabComplete(CommandSource sender, String[] args)
|
||||
{
|
||||
if (isAdmin(sender.getPlexPlayer()))
|
||||
{
|
||||
return PlexUtils.getPlayerNameList();
|
||||
}
|
||||
return ImmutableList.of();
|
||||
}
|
||||
}
|
71
src/main/java/dev/plex/command/impl/SurvivalCMD.java
Normal file
71
src/main/java/dev/plex/command/impl/SurvivalCMD.java
Normal file
@ -0,0 +1,71 @@
|
||||
package dev.plex.command.impl;
|
||||
|
||||
import dev.plex.command.annotation.CommandParameters;
|
||||
import dev.plex.command.annotation.CommandPermissions;
|
||||
import dev.plex.command.exception.CommandFailException;
|
||||
import dev.plex.command.source.CommandSource;
|
||||
import dev.plex.command.source.RequiredCommandSource;
|
||||
import java.util.List;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import dev.plex.command.PlexCommand;
|
||||
import dev.plex.rank.enums.Rank;
|
||||
import dev.plex.util.PlexUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@CommandPermissions(level = Rank.OP, source = RequiredCommandSource.ANY)
|
||||
@CommandParameters(aliases = "gms", description = "Set your own or another player's gamemode to survival mode")
|
||||
public class SurvivalCMD extends PlexCommand
|
||||
{
|
||||
public SurvivalCMD()
|
||||
{
|
||||
super("survival");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(CommandSource sender, String[] args)
|
||||
{
|
||||
if (args.length == 0)
|
||||
{
|
||||
// doesn't work
|
||||
if (sender.isConsoleSender())
|
||||
{
|
||||
throw new CommandFailException("You must define a player when using the console!");
|
||||
}
|
||||
|
||||
sender.getPlayer().setGameMode(GameMode.SURVIVAL);
|
||||
send(tl("gameModeSetTo", "survival"));
|
||||
return;
|
||||
}
|
||||
|
||||
if (isAdmin(sender.getPlexPlayer()))
|
||||
{
|
||||
if (args[0].equals("-a"))
|
||||
{
|
||||
for (Player targetPlayer : Bukkit.getServer().getOnlinePlayers())
|
||||
{
|
||||
targetPlayer.setGameMode(GameMode.SURVIVAL);
|
||||
}
|
||||
send(tl("gameModeSetTo", "survival"));
|
||||
return;
|
||||
}
|
||||
|
||||
Player player = getNonNullPlayer(args[0]);
|
||||
send(tl("setOtherPlayerGameModeTo", player.getName(), "survival"));
|
||||
player.sendMessage(tl("playerSetOtherGameMode", sender.getName(), "survival"));
|
||||
player.setGameMode(GameMode.SURVIVAL);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> onTabComplete(CommandSource sender, String[] args)
|
||||
{
|
||||
if (isAdmin(sender.getPlexPlayer()))
|
||||
{
|
||||
return PlexUtils.getPlayerNameList();
|
||||
}
|
||||
return ImmutableList.of();
|
||||
}
|
||||
}
|
37
src/main/java/dev/plex/command/impl/TestCMD.java
Normal file
37
src/main/java/dev/plex/command/impl/TestCMD.java
Normal file
@ -0,0 +1,37 @@
|
||||
package dev.plex.command.impl;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import dev.plex.command.annotation.CommandParameters;
|
||||
import dev.plex.command.annotation.CommandPermissions;
|
||||
import dev.plex.command.source.CommandSource;
|
||||
import dev.plex.command.source.RequiredCommandSource;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import dev.plex.command.PlexCommand;
|
||||
import dev.plex.rank.enums.Rank;
|
||||
|
||||
@CommandPermissions(level = Rank.OP, source = RequiredCommandSource.ANY)
|
||||
@CommandParameters(aliases = "tst,tast", description = "HELLO")
|
||||
public class TestCMD extends PlexCommand
|
||||
{
|
||||
public TestCMD()
|
||||
{
|
||||
super("test");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(CommandSource sender, String[] args)
|
||||
{
|
||||
send(tl("variableTest", sender.getName()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> onTabComplete(CommandSource sender, String[] args)
|
||||
{
|
||||
if (args.length == 1)
|
||||
{
|
||||
return Arrays.asList("WHATTHEFAWK", "LUL");
|
||||
}
|
||||
return ImmutableList.of();
|
||||
}
|
||||
}
|
53
src/main/java/dev/plex/command/impl/WorldCMD.java
Normal file
53
src/main/java/dev/plex/command/impl/WorldCMD.java
Normal file
@ -0,0 +1,53 @@
|
||||
package dev.plex.command.impl;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import dev.plex.command.annotation.CommandParameters;
|
||||
import dev.plex.command.annotation.CommandPermissions;
|
||||
import dev.plex.command.exception.CommandArgumentException;
|
||||
import dev.plex.command.source.CommandSource;
|
||||
import dev.plex.command.source.RequiredCommandSource;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import dev.plex.command.PlexCommand;
|
||||
import dev.plex.rank.enums.Rank;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
|
||||
@CommandPermissions(level = Rank.OP, source = RequiredCommandSource.IN_GAME)
|
||||
@CommandParameters(description = "Teleport to a world.", usage = "/<command> <world>")
|
||||
public class WorldCMD extends PlexCommand
|
||||
{
|
||||
public WorldCMD()
|
||||
{
|
||||
super("world");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(CommandSource sender, String[] args)
|
||||
{
|
||||
if (args.length != 1)
|
||||
{
|
||||
throw new CommandArgumentException();
|
||||
}
|
||||
World world = getNonNullWorld(args[0]);
|
||||
sender.getPlayer().teleport(new Location(world, 0, world.getHighestBlockYAt(0, 0) + 1, 0, 0, 0));
|
||||
send(tl("playerWorldTeleport", world.getName()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> onTabComplete(CommandSource sender, String[] args)
|
||||
{
|
||||
List<String> worlds = new ArrayList<>();
|
||||
for (World world : Bukkit.getWorlds())
|
||||
{
|
||||
worlds.add(world.getName());
|
||||
}
|
||||
if (args.length == 1)
|
||||
{
|
||||
return worlds;
|
||||
}
|
||||
return ImmutableList.of();
|
||||
}
|
||||
|
||||
}
|
37
src/main/java/dev/plex/command/source/CommandSource.java
Normal file
37
src/main/java/dev/plex/command/source/CommandSource.java
Normal file
@ -0,0 +1,37 @@
|
||||
package dev.plex.command.source;
|
||||
|
||||
import lombok.Getter;
|
||||
import dev.plex.cache.PlayerCache;
|
||||
import dev.plex.player.PlexPlayer;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@Getter
|
||||
public class CommandSource
|
||||
{
|
||||
private final CommandSender sender;
|
||||
private final Player player;
|
||||
private final PlexPlayer plexPlayer;
|
||||
private final boolean isConsoleSender;
|
||||
|
||||
public CommandSource(CommandSender sender)
|
||||
{
|
||||
this.sender = sender;
|
||||
this.isConsoleSender = !(sender instanceof Player);
|
||||
this.player = sender instanceof Player ? Bukkit.getPlayer(sender.getName()) : null;
|
||||
this.plexPlayer = sender instanceof Player ? PlayerCache.getPlexPlayerMap().get(((Player)sender).getUniqueId()) : null;
|
||||
}
|
||||
|
||||
// there's a bug here where it sends it to the player not the console
|
||||
// i assume this is because there's no checking. no idea why but it always sends it to the player even if executed from the console
|
||||
public void send(String s)
|
||||
{
|
||||
sender.sendMessage(s);
|
||||
}
|
||||
|
||||
public String getName()
|
||||
{
|
||||
return sender.getName();
|
||||
}
|
||||
}
|
@ -0,0 +1,8 @@
|
||||
package dev.plex.command.source;
|
||||
|
||||
public enum RequiredCommandSource
|
||||
{
|
||||
IN_GAME,
|
||||
CONSOLE,
|
||||
ANY
|
||||
}
|
53
src/main/java/dev/plex/config/Config.java
Normal file
53
src/main/java/dev/plex/config/Config.java
Normal file
@ -0,0 +1,53 @@
|
||||
package dev.plex.config;
|
||||
|
||||
import dev.plex.Plex;
|
||||
import java.io.File;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
|
||||
public class Config extends YamlConfiguration
|
||||
{
|
||||
private Plex plugin;
|
||||
private File file;
|
||||
private String name;
|
||||
|
||||
public Config(Plex plugin, String name)
|
||||
{
|
||||
this.plugin = plugin;
|
||||
this.file = new File(plugin.getDataFolder(), name);
|
||||
this.name = name;
|
||||
|
||||
if (!file.exists())
|
||||
{
|
||||
saveDefault();
|
||||
}
|
||||
}
|
||||
|
||||
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()
|
||||
{
|
||||
plugin.saveResource(name, false);
|
||||
}
|
||||
}
|
40
src/main/java/dev/plex/event/AdminAddEvent.java
Normal file
40
src/main/java/dev/plex/event/AdminAddEvent.java
Normal file
@ -0,0 +1,40 @@
|
||||
package dev.plex.event;
|
||||
|
||||
import dev.plex.command.source.CommandSource;
|
||||
import dev.plex.player.PlexPlayer;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
||||
public class AdminAddEvent extends Event
|
||||
{
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
|
||||
private CommandSource sender;
|
||||
private PlexPlayer plexPlayer;
|
||||
|
||||
public AdminAddEvent(CommandSource sender, PlexPlayer plexPlayer)
|
||||
{
|
||||
this.sender = sender;
|
||||
this.plexPlayer = plexPlayer;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HandlerList getHandlers()
|
||||
{
|
||||
return handlers;
|
||||
}
|
||||
|
||||
public static HandlerList getHandlerList()
|
||||
{
|
||||
return handlers;
|
||||
}
|
||||
|
||||
public PlexPlayer getPlexPlayer()
|
||||
{
|
||||
return plexPlayer;
|
||||
}
|
||||
|
||||
public CommandSource getSender() {
|
||||
return sender;
|
||||
}
|
||||
}
|
40
src/main/java/dev/plex/event/AdminRemoveEvent.java
Normal file
40
src/main/java/dev/plex/event/AdminRemoveEvent.java
Normal file
@ -0,0 +1,40 @@
|
||||
package dev.plex.event;
|
||||
|
||||
import dev.plex.command.source.CommandSource;
|
||||
import dev.plex.player.PlexPlayer;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
||||
public class AdminRemoveEvent extends Event
|
||||
{
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
|
||||
private PlexPlayer plexPlayer;
|
||||
private CommandSource sender;
|
||||
|
||||
public AdminRemoveEvent(CommandSource sender, PlexPlayer plexPlayer)
|
||||
{
|
||||
this.sender = sender;
|
||||
this.plexPlayer = plexPlayer;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HandlerList getHandlers()
|
||||
{
|
||||
return handlers;
|
||||
}
|
||||
|
||||
public static HandlerList getHandlerList()
|
||||
{
|
||||
return handlers;
|
||||
}
|
||||
|
||||
public PlexPlayer getPlexPlayer()
|
||||
{
|
||||
return plexPlayer;
|
||||
}
|
||||
|
||||
public CommandSource getSender() {
|
||||
return sender;
|
||||
}
|
||||
}
|
48
src/main/java/dev/plex/event/AdminSetRankEvent.java
Normal file
48
src/main/java/dev/plex/event/AdminSetRankEvent.java
Normal file
@ -0,0 +1,48 @@
|
||||
package dev.plex.event;
|
||||
|
||||
import dev.plex.command.source.CommandSource;
|
||||
import dev.plex.player.PlexPlayer;
|
||||
import dev.plex.rank.enums.Rank;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
||||
public class AdminSetRankEvent extends Event
|
||||
{
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
|
||||
private CommandSource sender;
|
||||
private PlexPlayer plexPlayer;
|
||||
private Rank rank;
|
||||
|
||||
public AdminSetRankEvent(CommandSource sender, PlexPlayer plexPlayer, Rank rank)
|
||||
{
|
||||
this.sender = sender;
|
||||
this.plexPlayer = plexPlayer;
|
||||
this.rank = rank;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HandlerList getHandlers()
|
||||
{
|
||||
return handlers;
|
||||
}
|
||||
|
||||
public static HandlerList getHandlerList()
|
||||
{
|
||||
return handlers;
|
||||
}
|
||||
|
||||
public PlexPlayer getPlexPlayer()
|
||||
{
|
||||
return plexPlayer;
|
||||
}
|
||||
|
||||
public Rank getRank()
|
||||
{
|
||||
return rank;
|
||||
}
|
||||
|
||||
public CommandSource getSender() {
|
||||
return sender;
|
||||
}
|
||||
}
|
23
src/main/java/dev/plex/event/PunishedPlayerEvent.java
Normal file
23
src/main/java/dev/plex/event/PunishedPlayerEvent.java
Normal file
@ -0,0 +1,23 @@
|
||||
package dev.plex.event;
|
||||
|
||||
import dev.plex.player.PunishedPlayer;
|
||||
import java.util.UUID;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.event.Cancellable;
|
||||
import org.bukkit.event.player.PlayerEvent;
|
||||
|
||||
@Getter
|
||||
public abstract class PunishedPlayerEvent extends PlayerEvent implements Cancellable
|
||||
{
|
||||
protected PunishedPlayer punishedPlayer;
|
||||
@Setter
|
||||
protected boolean cancelled;
|
||||
|
||||
protected PunishedPlayerEvent(PunishedPlayer punishedPlayer)
|
||||
{
|
||||
super(Bukkit.getPlayer(UUID.fromString(punishedPlayer.getUuid())));
|
||||
this.punishedPlayer = punishedPlayer;
|
||||
}
|
||||
}
|
34
src/main/java/dev/plex/event/PunishedPlayerFreezeEvent.java
Normal file
34
src/main/java/dev/plex/event/PunishedPlayerFreezeEvent.java
Normal file
@ -0,0 +1,34 @@
|
||||
package dev.plex.event;
|
||||
|
||||
import dev.plex.player.PunishedPlayer;
|
||||
import lombok.Getter;
|
||||
import org.bukkit.event.Cancellable;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
||||
@Getter
|
||||
public class PunishedPlayerFreezeEvent extends PunishedPlayerEvent implements Cancellable
|
||||
{
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
|
||||
/**
|
||||
* Status of the Punished Player being frozen before the event's occurrence.
|
||||
*/
|
||||
private final boolean frozen;
|
||||
|
||||
public PunishedPlayerFreezeEvent(PunishedPlayer punishedPlayer, boolean frozen)
|
||||
{
|
||||
super(punishedPlayer);
|
||||
this.frozen = frozen;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HandlerList getHandlers()
|
||||
{
|
||||
return handlers;
|
||||
}
|
||||
|
||||
public static HandlerList getHandlerList()
|
||||
{
|
||||
return handlers;
|
||||
}
|
||||
}
|
34
src/main/java/dev/plex/event/PunishedPlayerMuteEvent.java
Normal file
34
src/main/java/dev/plex/event/PunishedPlayerMuteEvent.java
Normal file
@ -0,0 +1,34 @@
|
||||
package dev.plex.event;
|
||||
|
||||
import dev.plex.player.PunishedPlayer;
|
||||
import lombok.Getter;
|
||||
import org.bukkit.event.Cancellable;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
||||
@Getter
|
||||
public class PunishedPlayerMuteEvent extends PunishedPlayerEvent implements Cancellable
|
||||
{
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
|
||||
/**
|
||||
* Status of the Punished Player being frozen before the event's occurrence.
|
||||
*/
|
||||
private final boolean muted;
|
||||
|
||||
public PunishedPlayerMuteEvent(PunishedPlayer punishedPlayer, boolean muted)
|
||||
{
|
||||
super(punishedPlayer);
|
||||
this.muted = muted;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HandlerList getHandlers()
|
||||
{
|
||||
return handlers;
|
||||
}
|
||||
|
||||
public static HandlerList getHandlerList()
|
||||
{
|
||||
return handlers;
|
||||
}
|
||||
}
|
46
src/main/java/dev/plex/handlers/CommandHandler.java
Normal file
46
src/main/java/dev/plex/handlers/CommandHandler.java
Normal file
@ -0,0 +1,46 @@
|
||||
package dev.plex.handlers;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import dev.plex.command.impl.AdminCMD;
|
||||
import dev.plex.command.impl.AdventureCMD;
|
||||
import dev.plex.command.impl.BanCMD;
|
||||
import dev.plex.command.impl.CreativeCMD;
|
||||
import dev.plex.command.impl.FionnCMD;
|
||||
import dev.plex.command.impl.FreezeCMD;
|
||||
import dev.plex.command.impl.NameHistoryCMD;
|
||||
import dev.plex.command.impl.OpAllCMD;
|
||||
import dev.plex.command.impl.OpCMD;
|
||||
import dev.plex.command.impl.PlexCMD;
|
||||
import dev.plex.command.impl.PunishmentsCMD;
|
||||
import dev.plex.command.impl.SpectatorCMD;
|
||||
import dev.plex.command.impl.SurvivalCMD;
|
||||
import dev.plex.command.impl.TestCMD;
|
||||
import dev.plex.command.impl.WorldCMD;
|
||||
import java.util.List;
|
||||
import dev.plex.command.PlexCommand;
|
||||
import dev.plex.util.PlexLog;
|
||||
|
||||
public class CommandHandler
|
||||
{
|
||||
private List<PlexCommand> commands = Lists.newArrayList();
|
||||
|
||||
public CommandHandler()
|
||||
{
|
||||
commands.add(new TestCMD());
|
||||
commands.add(new PlexCMD());
|
||||
commands.add(new FionnCMD());
|
||||
commands.add(new WorldCMD());
|
||||
commands.add(new OpAllCMD());
|
||||
commands.add(new OpCMD());
|
||||
commands.add(new FreezeCMD());
|
||||
commands.add(new NameHistoryCMD());
|
||||
commands.add(new AdminCMD());
|
||||
commands.add(new AdventureCMD());
|
||||
commands.add(new CreativeCMD());
|
||||
commands.add(new SurvivalCMD());
|
||||
commands.add(new SpectatorCMD());
|
||||
commands.add(new BanCMD());
|
||||
commands.add(new PunishmentsCMD());
|
||||
PlexLog.log(String.format("Registered %s commands!", commands.size()));
|
||||
}
|
||||
}
|
29
src/main/java/dev/plex/handlers/ListenerHandler.java
Normal file
29
src/main/java/dev/plex/handlers/ListenerHandler.java
Normal file
@ -0,0 +1,29 @@
|
||||
package dev.plex.handlers;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import dev.plex.listener.impl.AdminListener;
|
||||
import dev.plex.listener.impl.ChatListener;
|
||||
import dev.plex.listener.impl.FreezeListener;
|
||||
import dev.plex.listener.impl.LoginListener;
|
||||
import dev.plex.listener.impl.PlayerListener;
|
||||
import dev.plex.listener.impl.ServerListener;
|
||||
import dev.plex.listener.impl.WorldListener;
|
||||
import java.util.List;
|
||||
import dev.plex.listener.PlexListener;
|
||||
import dev.plex.util.PlexLog;
|
||||
|
||||
public class ListenerHandler
|
||||
{
|
||||
List<PlexListener> listeners = Lists.newArrayList();
|
||||
public ListenerHandler()
|
||||
{
|
||||
listeners.add(new ServerListener());
|
||||
listeners.add(new ChatListener());
|
||||
listeners.add(new PlayerListener());
|
||||
listeners.add(new WorldListener());
|
||||
listeners.add(new FreezeListener());
|
||||
listeners.add(new AdminListener());
|
||||
listeners.add(new LoginListener());
|
||||
PlexLog.log(String.format("Registered %s listeners!", listeners.size()));
|
||||
}
|
||||
}
|
12
src/main/java/dev/plex/listener/PlexListener.java
Normal file
12
src/main/java/dev/plex/listener/PlexListener.java
Normal file
@ -0,0 +1,12 @@
|
||||
package dev.plex.listener;
|
||||
|
||||
import dev.plex.PlexBase;
|
||||
import org.bukkit.event.Listener;
|
||||
|
||||
public abstract class PlexListener extends PlexBase implements Listener
|
||||
{
|
||||
public PlexListener()
|
||||
{
|
||||
plugin.getServer().getPluginManager().registerEvents(this, plugin);
|
||||
}
|
||||
}
|
42
src/main/java/dev/plex/listener/impl/AdminListener.java
Normal file
42
src/main/java/dev/plex/listener/impl/AdminListener.java
Normal file
@ -0,0 +1,42 @@
|
||||
package dev.plex.listener.impl;
|
||||
|
||||
import dev.plex.event.AdminAddEvent;
|
||||
import dev.plex.event.AdminRemoveEvent;
|
||||
import dev.plex.event.AdminSetRankEvent;
|
||||
import dev.plex.listener.PlexListener;
|
||||
import dev.plex.player.PlexPlayer;
|
||||
import dev.plex.rank.enums.Rank;
|
||||
import static dev.plex.util.PlexUtils.tl;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.event.EventHandler;
|
||||
|
||||
public class AdminListener extends PlexListener
|
||||
{
|
||||
@EventHandler
|
||||
public void onAdminAdd(AdminAddEvent event)
|
||||
{
|
||||
String userSender = event.getSender().getName();
|
||||
PlexPlayer target = event.getPlexPlayer();
|
||||
|
||||
Bukkit.broadcastMessage(tl("newAdminAdded", userSender, target.getName()));
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onAdminRemove(AdminRemoveEvent event)
|
||||
{
|
||||
String userSender = event.getSender().getName();
|
||||
PlexPlayer target = event.getPlexPlayer();
|
||||
|
||||
Bukkit.broadcastMessage(tl("adminRemoved", userSender, target.getName()));
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onAdminSetRank(AdminSetRankEvent event)
|
||||
{
|
||||
String userSender = event.getSender().getName();
|
||||
PlexPlayer target = event.getPlexPlayer();
|
||||
Rank newRank = event.getRank();
|
||||
|
||||
Bukkit.broadcastMessage(tl("adminSetRank", userSender, target.getName(), newRank.name().toUpperCase()));
|
||||
}
|
||||
}
|
28
src/main/java/dev/plex/listener/impl/ChatListener.java
Normal file
28
src/main/java/dev/plex/listener/impl/ChatListener.java
Normal file
@ -0,0 +1,28 @@
|
||||
package dev.plex.listener.impl;
|
||||
|
||||
import dev.plex.Plex;
|
||||
import dev.plex.cache.PlayerCache;
|
||||
import dev.plex.listener.PlexListener;
|
||||
import dev.plex.player.PlexPlayer;
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
||||
|
||||
public class ChatListener extends PlexListener
|
||||
{
|
||||
|
||||
@EventHandler
|
||||
public void onChat(AsyncPlayerChatEvent event)
|
||||
{
|
||||
PlexPlayer plexPlayer = PlayerCache.getPlexPlayerMap().get(event.getPlayer().getUniqueId());
|
||||
if (!plexPlayer.getPrefix().isEmpty())
|
||||
{
|
||||
event.setFormat(String.format("%s %s §7» %s", plexPlayer.getPrefix(), ChatColor.RESET + plexPlayer.getName(), event.getMessage()));
|
||||
}
|
||||
else if (Plex.get().getRankManager().isAdmin(plexPlayer))
|
||||
{
|
||||
event.setFormat(String.format("%s %s §7» %s", plexPlayer.getRankFromString().getPrefix(), ChatColor.RESET + plexPlayer.getName(), event.getMessage()));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
21
src/main/java/dev/plex/listener/impl/FreezeListener.java
Normal file
21
src/main/java/dev/plex/listener/impl/FreezeListener.java
Normal file
@ -0,0 +1,21 @@
|
||||
package dev.plex.listener.impl;
|
||||
|
||||
import dev.plex.cache.PlayerCache;
|
||||
import dev.plex.listener.PlexListener;
|
||||
import dev.plex.player.PunishedPlayer;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.player.PlayerMoveEvent;
|
||||
|
||||
public class FreezeListener extends PlexListener
|
||||
{
|
||||
@EventHandler
|
||||
public void onPlayerMove(PlayerMoveEvent e)
|
||||
{
|
||||
PunishedPlayer player = PlayerCache.getPunishedPlayer(e.getPlayer().getUniqueId());
|
||||
if (player.isFrozen())
|
||||
{
|
||||
e.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
23
src/main/java/dev/plex/listener/impl/LoginListener.java
Normal file
23
src/main/java/dev/plex/listener/impl/LoginListener.java
Normal file
@ -0,0 +1,23 @@
|
||||
package dev.plex.listener.impl;
|
||||
|
||||
import dev.plex.listener.PlexListener;
|
||||
import dev.plex.util.PlexLog;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.player.AsyncPlayerPreLoginEvent;
|
||||
|
||||
public class LoginListener extends PlexListener
|
||||
{
|
||||
|
||||
//TODO: Customizable MSGS
|
||||
|
||||
@EventHandler
|
||||
public void onPreLogin(AsyncPlayerPreLoginEvent event)
|
||||
{
|
||||
PlexLog.log(String.valueOf(plugin.getBanManager().isBanned(event.getUniqueId())));
|
||||
if (plugin.getBanManager().isBanned(event.getUniqueId()))
|
||||
{
|
||||
event.disallow(AsyncPlayerPreLoginEvent.Result.KICK_BANNED, "§cYou're currently banned from this server.\n§cPlease appeal at §6https://forums.telesphoreo.me");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
160
src/main/java/dev/plex/listener/impl/PlayerListener.java
Normal file
160
src/main/java/dev/plex/listener/impl/PlayerListener.java
Normal file
@ -0,0 +1,160 @@
|
||||
package dev.plex.listener.impl;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.UUID;
|
||||
import dev.plex.admin.Admin;
|
||||
import dev.plex.cache.DataUtils;
|
||||
import dev.plex.cache.MongoPlayerData;
|
||||
import dev.plex.cache.PlayerCache;
|
||||
import dev.plex.cache.SQLPlayerData;
|
||||
import dev.plex.command.impl.FionnCMD;
|
||||
import dev.plex.listener.PlexListener;
|
||||
import dev.plex.player.PlexPlayer;
|
||||
import dev.plex.player.PunishedPlayer;
|
||||
import dev.plex.util.PlexLog;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
|
||||
public class PlayerListener extends PlexListener
|
||||
{
|
||||
private final MongoPlayerData mongoPlayerData = plugin.getMongoPlayerData() != null ? plugin.getMongoPlayerData() : null;
|
||||
private final SQLPlayerData sqlPlayerData = plugin.getSqlPlayerData() != null ? plugin.getSqlPlayerData() : null;
|
||||
|
||||
// setting up a player's data
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
public void onPlayerSetup(PlayerJoinEvent event)
|
||||
{
|
||||
Player player = event.getPlayer();
|
||||
|
||||
PlexPlayer plexPlayer;
|
||||
|
||||
if (!DataUtils.hasPlayedBefore(player.getUniqueId()))
|
||||
{
|
||||
PlexLog.log("AYO THIS MAN DONT EXIST"); // funi msg
|
||||
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
|
||||
|
||||
DataUtils.insert(plexPlayer); // insert data in some wack db
|
||||
} else {
|
||||
plexPlayer = DataUtils.getPlayer(player.getUniqueId());
|
||||
}
|
||||
|
||||
/*if (mongoPlayerData != null) // Alright, check if we're saving with Mongo first
|
||||
{
|
||||
if (!mongoPlayerData.exists(player.getUniqueId())) //okay, we're saving with mongo! now check if the player's document exists
|
||||
{
|
||||
PlexLog.log("AYO THIS MAN DONT EXIST"); // funi msg
|
||||
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
|
||||
|
||||
mongoPlayerData.save(plexPlayer); //and put their document in mongo collection
|
||||
}
|
||||
else
|
||||
{
|
||||
plexPlayer = mongoPlayerData.getByUUID(player.getUniqueId()); //oh they do exist!
|
||||
plexPlayer.setName(plexPlayer.getName()); //set the name!
|
||||
}
|
||||
}
|
||||
else if (sqlPlayerData != null)
|
||||
{
|
||||
if (!sqlPlayerData.exists(player.getUniqueId())) //okay, we're saving with sql! now check if the player's document exists
|
||||
{
|
||||
PlexLog.log("AYO THIS MAN DONT EXIST"); // funi msg
|
||||
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 row into the sql table
|
||||
}
|
||||
else
|
||||
{
|
||||
plexPlayer = sqlPlayerData.getByUUID(player.getUniqueId()); //oh they do exist!
|
||||
plexPlayer.setName(plexPlayer.getName()); //set the name!
|
||||
}
|
||||
}*/
|
||||
|
||||
PlayerCache.getPlexPlayerMap().put(player.getUniqueId(), plexPlayer); //put them into the cache
|
||||
PlayerCache.getPunishedPlayerMap().put(player.getUniqueId(), new PunishedPlayer(player.getUniqueId()));
|
||||
|
||||
assert plexPlayer != null;
|
||||
|
||||
if (plugin.getRankManager().isAdmin(plexPlayer))
|
||||
{
|
||||
Admin admin = new Admin(UUID.fromString(plexPlayer.getUuid()));
|
||||
admin.setRank(plexPlayer.getRankFromString());
|
||||
|
||||
plugin.getAdminList().addToCache(admin);
|
||||
|
||||
if (!plexPlayer.getLoginMSG().isEmpty())
|
||||
{
|
||||
event.setJoinMessage(ChatColor.AQUA + player.getName() + " is " + plexPlayer.getLoginMSG());
|
||||
}
|
||||
else
|
||||
{
|
||||
event.setJoinMessage(ChatColor.AQUA + player.getName() + " is " + plexPlayer.getRankFromString().getLoginMSG());
|
||||
}
|
||||
}
|
||||
|
||||
/*Punishment test = new Punishment(player.getUniqueId(), player.getUniqueId());
|
||||
test.setPunishedUsername(player.getName());
|
||||
test.setReason("hii");
|
||||
test.setType(PunishmentType.BAN);
|
||||
test.setEndDate(new Date(Instant.now().plusSeconds(10).getEpochSecond()));
|
||||
plugin.getPunishmentManager().doPunishment(PlayerCache.getPunishedPlayer(player.getUniqueId()), test);*/
|
||||
|
||||
|
||||
}
|
||||
|
||||
// saving the player's data
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
public void onPlayerSave(PlayerQuitEvent event)
|
||||
{
|
||||
PlexPlayer plexPlayer = PlayerCache.getPlexPlayerMap().get(event.getPlayer().getUniqueId()); //get the player because it's literally impossible for them to not have an object
|
||||
|
||||
if (plugin.getRankManager().isAdmin(plexPlayer))
|
||||
{
|
||||
plugin.getAdminList().removeFromCache(UUID.fromString(plexPlayer.getUuid()));
|
||||
}
|
||||
|
||||
if (mongoPlayerData != null) //back to mongo checking
|
||||
{
|
||||
mongoPlayerData.update(plexPlayer); //update the player's document
|
||||
}
|
||||
else if (sqlPlayerData != null) //sql checking
|
||||
{
|
||||
sqlPlayerData.update(plexPlayer);
|
||||
}
|
||||
|
||||
if (FionnCMD.ENABLED)
|
||||
{
|
||||
PlayerCache.getPunishedPlayer(event.getPlayer().getUniqueId()).setFrozen(false);
|
||||
}
|
||||
|
||||
PlayerCache.getPlexPlayerMap().remove(event.getPlayer().getUniqueId()); //remove them from cache
|
||||
PlayerCache.getPunishedPlayerMap().remove(event.getPlayer().getUniqueId());
|
||||
|
||||
}
|
||||
|
||||
// unrelated player quitting
|
||||
@EventHandler
|
||||
public void onPlayerQuit(PlayerQuitEvent e)
|
||||
{
|
||||
Player player = e.getPlayer();
|
||||
|
||||
if (FionnCMD.ENABLED)
|
||||
{
|
||||
player.setInvisible(false);
|
||||
Location location = FionnCMD.LOCATION_CACHE.get(player);
|
||||
if (location != null)
|
||||
{
|
||||
player.teleport(location);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
32
src/main/java/dev/plex/listener/impl/ServerListener.java
Normal file
32
src/main/java/dev/plex/listener/impl/ServerListener.java
Normal file
@ -0,0 +1,32 @@
|
||||
package dev.plex.listener.impl;
|
||||
|
||||
import dev.plex.listener.PlexListener;
|
||||
import dev.plex.util.PlexUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.server.ServerListPingEvent;
|
||||
|
||||
public class ServerListener extends PlexListener
|
||||
{
|
||||
@EventHandler
|
||||
public void onServerPing(ServerListPingEvent event)
|
||||
{
|
||||
String baseMotd = plugin.config.getString("server.motd");
|
||||
baseMotd = baseMotd.replace("\\n", "\n");
|
||||
baseMotd = baseMotd.replace("%servername%", plugin.config.getString("server.name"));
|
||||
baseMotd = baseMotd.replace("%mcversion%", Bukkit.getBukkitVersion().split("-")[0]);
|
||||
if (plugin.config.getBoolean("server.colorize_motd"))
|
||||
{
|
||||
final StringBuilder motd = new StringBuilder();
|
||||
for (final String word : baseMotd.split(" "))
|
||||
{
|
||||
motd.append(PlexUtils.randomChatColor()).append(word).append(" ");
|
||||
}
|
||||
event.setMotd(motd.toString().trim());
|
||||
}
|
||||
else
|
||||
{
|
||||
event.setMotd(baseMotd.trim());
|
||||
}
|
||||
}
|
||||
}
|
51
src/main/java/dev/plex/listener/impl/WorldListener.java
Normal file
51
src/main/java/dev/plex/listener/impl/WorldListener.java
Normal file
@ -0,0 +1,51 @@
|
||||
package dev.plex.listener.impl;
|
||||
|
||||
import dev.plex.cache.PlayerCache;
|
||||
import dev.plex.listener.PlexListener;
|
||||
import dev.plex.player.PlexPlayer;
|
||||
import dev.plex.rank.enums.Rank;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.block.BlockPlaceEvent;
|
||||
import org.bukkit.event.entity.EntitySpawnEvent;
|
||||
import static dev.plex.util.PlexUtils.tl;
|
||||
|
||||
public class WorldListener extends PlexListener
|
||||
{
|
||||
@EventHandler
|
||||
public void onBlockPlace(BlockPlaceEvent e)
|
||||
{
|
||||
Player player = e.getPlayer();
|
||||
PlexPlayer plexPlayer = PlayerCache.getPlexPlayerMap().get(player.getUniqueId());
|
||||
World world = player.getWorld();
|
||||
switch (world.getName().toLowerCase())
|
||||
{
|
||||
case "adminworld":
|
||||
{
|
||||
if (plexPlayer.getRankFromString().isAtLeast(Rank.ADMIN))
|
||||
{
|
||||
return;
|
||||
}
|
||||
e.setCancelled(true);
|
||||
player.sendMessage(tl("noAdminWorldBlockPlace"));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onEntitySpawn(EntitySpawnEvent e)
|
||||
{
|
||||
if (!e.getLocation().getWorld().getName().equals("fionn"))
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (e.getEntityType() != EntityType.SLIME)
|
||||
{
|
||||
return;
|
||||
}
|
||||
e.setCancelled(true);
|
||||
}
|
||||
}
|
153
src/main/java/dev/plex/menu/PunishedPlayerMenu.java
Normal file
153
src/main/java/dev/plex/menu/PunishedPlayerMenu.java
Normal file
@ -0,0 +1,153 @@
|
||||
package dev.plex.menu;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import dev.plex.cache.PlayerCache;
|
||||
import dev.plex.player.PunishedPlayer;
|
||||
import dev.plex.punishment.Punishment;
|
||||
import dev.plex.util.menu.AbstractMenu;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.inventory.meta.SkullMeta;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class PunishedPlayerMenu extends AbstractMenu
|
||||
{
|
||||
private final PunishedPlayer punishedPlayer;
|
||||
|
||||
private final List<Inventory> inventories = Lists.newArrayList();
|
||||
|
||||
public PunishedPlayerMenu(PunishedPlayer player) {
|
||||
super("§c§lPunishments");
|
||||
this.punishedPlayer = player;
|
||||
for (int i = 0; i <= punishedPlayer.getPunishments().size() / 53; i++)
|
||||
{
|
||||
Inventory inventory = Bukkit.createInventory(null, 54, "Punishments Page " + (i + 1));
|
||||
ItemStack nextPage = new ItemStack(Material.FEATHER);
|
||||
ItemMeta meta = nextPage.getItemMeta();
|
||||
meta.setDisplayName(ChatColor.LIGHT_PURPLE + "Next Page");
|
||||
nextPage.setItemMeta(meta);
|
||||
|
||||
ItemStack previousPage = new ItemStack(Material.FEATHER);
|
||||
ItemMeta meta2 = previousPage.getItemMeta();
|
||||
meta2.setDisplayName(ChatColor.LIGHT_PURPLE + "Previous Page");
|
||||
previousPage.setItemMeta(meta2);
|
||||
|
||||
ItemStack back = new ItemStack(Material.BARRIER);
|
||||
ItemMeta meta3 = back.getItemMeta();
|
||||
meta3.setDisplayName(ChatColor.RED + "Return");
|
||||
back.setItemMeta(meta3);
|
||||
|
||||
inventory.setItem(50, nextPage);
|
||||
inventory.setItem(49, back);
|
||||
inventory.setItem(48, previousPage);
|
||||
inventories.add(inventory);
|
||||
}
|
||||
}
|
||||
|
||||
public List<Inventory> getInventory() {
|
||||
return inventories;
|
||||
}
|
||||
|
||||
public void openInv(Player player, int index) {
|
||||
int currentItemIndex = 0;
|
||||
int currentInvIndex = 0;
|
||||
for (Punishment punishment : punishedPlayer.getPunishments())
|
||||
{
|
||||
Inventory inv = inventories.get(currentInvIndex);
|
||||
if (currentInvIndex > inventories.size() - 1)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
if (currentItemIndex == inv.getSize() - 1) {
|
||||
currentInvIndex++;
|
||||
currentItemIndex = 0;
|
||||
inv = inventories.get(currentInvIndex);
|
||||
}
|
||||
|
||||
|
||||
ItemStack item = new ItemStack(Material.NETHER_STAR);
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
meta.setDisplayName(ChatColor.RED + punishment.getType().name().toUpperCase());
|
||||
meta.setLore(Arrays.asList(ChatColor.YELLOW + "Reason: \n" + ChatColor.GRAY + punishment.getReason()));
|
||||
item.setItemMeta(meta);
|
||||
|
||||
inv.setItem(currentItemIndex, item);
|
||||
|
||||
currentItemIndex++;
|
||||
}
|
||||
player.openInventory(inventories.get(index));
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onClick(InventoryClickEvent event)
|
||||
{
|
||||
if (event.getClickedInventory() == null) return;
|
||||
Inventory inv = event.getClickedInventory();
|
||||
if (!isValidInventory(inv)) return;
|
||||
if (event.getCurrentItem() == null) return;
|
||||
ItemStack item = event.getCurrentItem();
|
||||
event.setCancelled(true);
|
||||
if (item.getType() == Material.FEATHER)
|
||||
{
|
||||
if (item.getItemMeta().getDisplayName().equalsIgnoreCase(ChatColor.LIGHT_PURPLE + "Next Page"))
|
||||
{
|
||||
if (getCurrentInventoryIndex(inv) + 1 > inventories.size() - 1) return;
|
||||
if (inventories.get(getCurrentInventoryIndex(inv) + 1).getContents().length == 0) return;
|
||||
openInv((Player) event.getWhoClicked(), getCurrentInventoryIndex(inv) + 1);
|
||||
} else if (item.getItemMeta().getDisplayName().equalsIgnoreCase(ChatColor.LIGHT_PURPLE + "Previous Page"))
|
||||
{
|
||||
if (getCurrentInventoryIndex(inv) - 1 < 0) return;
|
||||
if (getCurrentInventoryIndex(inv) - 1 > inventories.size() - 1) return;
|
||||
if (inventories.get(getCurrentInventoryIndex(inv) - 1).getContents().length == 0) return;
|
||||
openInv((Player) event.getWhoClicked(), getCurrentInventoryIndex(inv) - 1);
|
||||
}
|
||||
|
||||
|
||||
} else if (item.getType() == Material.BARRIER)
|
||||
{
|
||||
new PunishmentMenu().openInv((Player) event.getWhoClicked(), 0);
|
||||
} else if (item.getType() == Material.PLAYER_HEAD)
|
||||
{
|
||||
SkullMeta meta = (SkullMeta) item.getItemMeta();
|
||||
OfflinePlayer player = meta.getOwningPlayer();
|
||||
assert player != null;
|
||||
PunishedPlayer punishedPlayer = PlayerCache.getPunishedPlayer(player.getUniqueId()) == null ? null : PlayerCache.getPunishedPlayer(player.getUniqueId());
|
||||
if (punishedPlayer == null)
|
||||
{
|
||||
event.getWhoClicked().sendMessage(ChatColor.RED + "This player does not exist. Try doing /punishments <player> instead.");
|
||||
event.getWhoClicked().closeInventory();
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public int getCurrentInventoryIndex(Inventory inventory)
|
||||
{
|
||||
for (int i = 0; i <= inventories.size() - 1; i++)
|
||||
{
|
||||
if (inventories.get(i).hashCode() == inventory.hashCode())
|
||||
{
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
private boolean isValidInventory(Inventory inventory)
|
||||
{
|
||||
return inventories.contains(inventory);
|
||||
}
|
||||
}
|
142
src/main/java/dev/plex/menu/PunishmentMenu.java
Normal file
142
src/main/java/dev/plex/menu/PunishmentMenu.java
Normal file
@ -0,0 +1,142 @@
|
||||
package dev.plex.menu;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import dev.plex.cache.PlayerCache;
|
||||
import dev.plex.player.PunishedPlayer;
|
||||
import dev.plex.util.menu.AbstractMenu;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.inventory.meta.SkullMeta;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class PunishmentMenu extends AbstractMenu
|
||||
{
|
||||
|
||||
private List<Inventory> inventories = Lists.newArrayList();
|
||||
|
||||
public PunishmentMenu() {
|
||||
super("§c§lPunishments");
|
||||
for (int i = 0; i <= Bukkit.getOnlinePlayers().size() / 53; i++)
|
||||
{
|
||||
Inventory inventory = Bukkit.createInventory(null, 54, "Punishments Page " + (i + 1));
|
||||
ItemStack nextPage = new ItemStack(Material.FEATHER);
|
||||
ItemMeta meta = nextPage.getItemMeta();
|
||||
meta.setDisplayName(ChatColor.LIGHT_PURPLE + "Next Page");
|
||||
nextPage.setItemMeta(meta);
|
||||
|
||||
ItemStack previousPage = new ItemStack(Material.FEATHER);
|
||||
ItemMeta meta2 = previousPage.getItemMeta();
|
||||
meta2.setDisplayName(ChatColor.LIGHT_PURPLE + "Previous Page");
|
||||
previousPage.setItemMeta(meta2);
|
||||
|
||||
inventory.setItem(50, nextPage);
|
||||
inventory.setItem(48, previousPage);
|
||||
inventories.add(inventory);
|
||||
}
|
||||
}
|
||||
|
||||
public List<Inventory> getInventory() {
|
||||
return inventories;
|
||||
}
|
||||
|
||||
public void openInv(Player player, int index) {
|
||||
int currentItemIndex = 0;
|
||||
int currentInvIndex = 0;
|
||||
for (Player players : Bukkit.getOnlinePlayers())
|
||||
{
|
||||
Inventory inv = inventories.get(currentInvIndex);
|
||||
if (currentInvIndex > inventories.size() - 1)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
if (currentItemIndex == inv.getSize() - 1) {
|
||||
currentInvIndex++;
|
||||
currentItemIndex = 0;
|
||||
inv = inventories.get(currentInvIndex);
|
||||
}
|
||||
|
||||
|
||||
ItemStack item = new ItemStack(Material.PLAYER_HEAD);
|
||||
SkullMeta meta = (SkullMeta) item.getItemMeta();
|
||||
meta.setOwningPlayer(players);
|
||||
meta.setDisplayName(ChatColor.YELLOW + players.getName());
|
||||
item.setItemMeta(meta);
|
||||
|
||||
inv.setItem(currentItemIndex, item);
|
||||
|
||||
currentItemIndex++;
|
||||
}
|
||||
player.openInventory(inventories.get(index));
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onClick(InventoryClickEvent event)
|
||||
{
|
||||
if (event.getClickedInventory() == null) return;
|
||||
Inventory inv = event.getClickedInventory();
|
||||
if (!isValidInventory(inv)) return;
|
||||
if (event.getCurrentItem() == null) return;
|
||||
ItemStack item = event.getCurrentItem();
|
||||
event.setCancelled(true);
|
||||
if (item.getType() == Material.FEATHER)
|
||||
{
|
||||
if (item.getItemMeta().getDisplayName().equalsIgnoreCase(ChatColor.LIGHT_PURPLE + "Next Page"))
|
||||
{
|
||||
if (getCurrentInventoryIndex(inv) + 1 > inventories.size() - 1) return;
|
||||
if (inventories.get(getCurrentInventoryIndex(inv) + 1).getContents().length == 0) return;
|
||||
openInv((Player) event.getWhoClicked(), getCurrentInventoryIndex(inv) + 1);
|
||||
} else if (item.getItemMeta().getDisplayName().equalsIgnoreCase(ChatColor.LIGHT_PURPLE + "Previous Page"))
|
||||
{
|
||||
if (getCurrentInventoryIndex(inv) - 1 < 0) return;
|
||||
if (getCurrentInventoryIndex(inv) - 1 > inventories.size() - 1) return;
|
||||
if (inventories.get(getCurrentInventoryIndex(inv) - 1).getContents().length == 0) return;
|
||||
openInv((Player) event.getWhoClicked(), getCurrentInventoryIndex(inv) - 1);
|
||||
}
|
||||
|
||||
|
||||
} else if (item.getType() == Material.PLAYER_HEAD)
|
||||
{
|
||||
SkullMeta meta = (SkullMeta) item.getItemMeta();
|
||||
OfflinePlayer player = meta.getOwningPlayer();
|
||||
assert player != null;
|
||||
PunishedPlayer punishedPlayer = PlayerCache.getPunishedPlayer(player.getUniqueId()) == null ? null : PlayerCache.getPunishedPlayer(player.getUniqueId());
|
||||
if (punishedPlayer == null)
|
||||
{
|
||||
event.getWhoClicked().sendMessage(ChatColor.RED + "This player does not exist. Try doing /punishments <player> instead.");
|
||||
event.getWhoClicked().closeInventory();
|
||||
return;
|
||||
}
|
||||
new PunishedPlayerMenu(punishedPlayer).openInv((Player) event.getWhoClicked(), 0);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
public int getCurrentInventoryIndex(Inventory inventory)
|
||||
{
|
||||
for (int i = 0; i <= inventories.size() - 1; i++)
|
||||
{
|
||||
if (inventories.get(i).hashCode() == inventory.hashCode())
|
||||
{
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
private boolean isValidInventory(Inventory inventory)
|
||||
{
|
||||
return inventories.contains(inventory);
|
||||
}
|
||||
}
|
87
src/main/java/dev/plex/player/PlexPlayer.java
Normal file
87
src/main/java/dev/plex/player/PlexPlayer.java
Normal file
@ -0,0 +1,87 @@
|
||||
package dev.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 dev.plex.rank.enums.Rank;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@Entity(value = "players", useDiscriminator = false)
|
||||
public class PlexPlayer
|
||||
{
|
||||
@Setter(AccessLevel.NONE)
|
||||
@Id
|
||||
private String id;
|
||||
|
||||
@Setter(AccessLevel.NONE)
|
||||
@Indexed(options = @IndexOptions(unique = true))
|
||||
private String uuid;
|
||||
|
||||
@Indexed
|
||||
private String name;
|
||||
|
||||
private String loginMSG;
|
||||
private String prefix;
|
||||
|
||||
private boolean vanished;
|
||||
|
||||
private long coins;
|
||||
|
||||
private String rank;
|
||||
|
||||
private List<String> ips;
|
||||
|
||||
public PlexPlayer()
|
||||
{
|
||||
}
|
||||
|
||||
public PlexPlayer(UUID playerUUID)
|
||||
{
|
||||
this.uuid = playerUUID.toString();
|
||||
|
||||
this.id = uuid.substring(0, 8);
|
||||
|
||||
this.name = "";
|
||||
|
||||
this.loginMSG = "";
|
||||
this.prefix = "";
|
||||
|
||||
this.vanished = false;
|
||||
|
||||
this.coins = 0;
|
||||
|
||||
this.ips = new ArrayList<>();
|
||||
|
||||
this.rank = "";
|
||||
}
|
||||
|
||||
public Rank getRankFromString()
|
||||
{
|
||||
OfflinePlayer player = Bukkit.getOfflinePlayer(UUID.fromString(uuid));
|
||||
if (rank.isEmpty())
|
||||
{
|
||||
if (player.isOp())
|
||||
{
|
||||
return Rank.OP;
|
||||
}
|
||||
else
|
||||
{
|
||||
return Rank.NONOP;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return Rank.valueOf(rank.toUpperCase());
|
||||
}
|
||||
}
|
||||
}
|
112
src/main/java/dev/plex/player/PunishedPlayer.java
Normal file
112
src/main/java/dev/plex/player/PunishedPlayer.java
Normal file
@ -0,0 +1,112 @@
|
||||
package dev.plex.player;
|
||||
|
||||
import dev.plex.Plex;
|
||||
import dev.plex.punishment.Punishment;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import dev.plex.event.PunishedPlayerFreezeEvent;
|
||||
import dev.plex.event.PunishedPlayerMuteEvent;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.json.JSONObject;
|
||||
import org.json.JSONTokener;
|
||||
|
||||
@Getter
|
||||
public class PunishedPlayer
|
||||
{
|
||||
//everything in here will be stored in redis
|
||||
@Setter(AccessLevel.NONE)
|
||||
private String uuid;
|
||||
|
||||
private boolean muted;
|
||||
private boolean frozen;
|
||||
|
||||
public PunishedPlayer(UUID playerUUID)
|
||||
{
|
||||
this.uuid = playerUUID.toString();
|
||||
this.muted = false;
|
||||
this.frozen = false;
|
||||
}
|
||||
|
||||
public void setFrozen(boolean frozen)
|
||||
{
|
||||
PunishedPlayerFreezeEvent e = new PunishedPlayerFreezeEvent(this, this.frozen);
|
||||
Bukkit.getServer().getPluginManager().callEvent(e);
|
||||
if (!e.isCancelled())
|
||||
{
|
||||
this.frozen = frozen;
|
||||
}
|
||||
}
|
||||
|
||||
public void setMuted(boolean muted)
|
||||
{
|
||||
PunishedPlayerMuteEvent e = new PunishedPlayerMuteEvent(this, this.muted);
|
||||
Bukkit.getServer().getPluginManager().callEvent(e);
|
||||
if (!e.isCancelled())
|
||||
{
|
||||
this.muted = muted;
|
||||
}
|
||||
}
|
||||
|
||||
public File getPunishmentsFile()
|
||||
{
|
||||
File folder = new File(Plex.get().getDataFolder() + File.separator + "punishments");
|
||||
if (!folder.exists())
|
||||
{
|
||||
folder.mkdir();
|
||||
}
|
||||
|
||||
File file = new File(folder, getUuid() + ".json");
|
||||
if (!file.exists())
|
||||
{
|
||||
try {
|
||||
file.createNewFile();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
return file;
|
||||
|
||||
}
|
||||
|
||||
public List<Punishment> getPunishments()
|
||||
{
|
||||
List<Punishment> punishments = Lists.newArrayList();
|
||||
|
||||
File file = getPunishmentsFile();
|
||||
|
||||
if (isNotEmpty(file))
|
||||
{
|
||||
try {
|
||||
JSONTokener tokener = new JSONTokener(new FileInputStream(file));
|
||||
JSONObject object = new JSONObject(tokener);
|
||||
object.getJSONObject(getUuid()).getJSONArray("punishments").forEach(obj -> {
|
||||
Punishment punishment = Punishment.fromJson(obj.toString());
|
||||
punishments.add(punishment);
|
||||
});
|
||||
} catch (FileNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
return punishments;
|
||||
}
|
||||
|
||||
private boolean isNotEmpty(File file) {
|
||||
try {
|
||||
return !FileUtils.readFileToString(file, StandardCharsets.UTF_8).trim().isEmpty();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
52
src/main/java/dev/plex/punishment/Punishment.java
Normal file
52
src/main/java/dev/plex/punishment/Punishment.java
Normal file
@ -0,0 +1,52 @@
|
||||
package dev.plex.punishment;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.gson.Gson;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
public class Punishment
|
||||
{
|
||||
|
||||
private final UUID punished;
|
||||
private final UUID punisher;
|
||||
|
||||
private final List<String> IPS;
|
||||
|
||||
private String punishedUsername;
|
||||
|
||||
private PunishmentType type;
|
||||
private String reason;
|
||||
private boolean customTime;
|
||||
private Date endDate;
|
||||
|
||||
public Punishment(UUID punished, UUID punisher)
|
||||
{
|
||||
this.punished = punished;
|
||||
this.punisher = punisher;
|
||||
this.IPS = Lists.newArrayList();
|
||||
|
||||
this.punishedUsername = "";
|
||||
this.type = null;
|
||||
this.reason = "";
|
||||
this.customTime = false;
|
||||
this.endDate = null;
|
||||
}
|
||||
|
||||
public String toJSON()
|
||||
{
|
||||
return new Gson().toJson(this);
|
||||
}
|
||||
|
||||
public static Punishment fromJson(String json)
|
||||
{
|
||||
return new Gson().fromJson(json, Punishment.class);
|
||||
}
|
||||
|
||||
}
|
123
src/main/java/dev/plex/punishment/PunishmentManager.java
Normal file
123
src/main/java/dev/plex/punishment/PunishmentManager.java
Normal file
@ -0,0 +1,123 @@
|
||||
package dev.plex.punishment;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Maps;
|
||||
import dev.plex.Plex;
|
||||
import dev.plex.banning.Ban;
|
||||
import dev.plex.player.PunishedPlayer;
|
||||
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 java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class PunishmentManager
|
||||
{
|
||||
|
||||
public void insertPunishment(PunishedPlayer player, Punishment punishment)
|
||||
{
|
||||
File file = player.getPunishmentsFile();
|
||||
|
||||
try {
|
||||
if (isNotEmpty(file))
|
||||
{
|
||||
JSONTokener tokener = new JSONTokener(new FileInputStream(file));
|
||||
JSONObject object = new JSONObject(tokener);
|
||||
object.getJSONObject(punishment.getPunished().toString()).getJSONArray("punishments").put(punishment.toJSON());
|
||||
|
||||
FileWriter writer = new FileWriter(file);
|
||||
writer.append(object.toString(8));
|
||||
writer.flush();
|
||||
writer.close();
|
||||
} else {
|
||||
JSONObject object = new JSONObject();
|
||||
Map<String, List<String>> punishments = Maps.newHashMap();
|
||||
|
||||
List<String> punishmentList = Lists.newArrayList();
|
||||
punishmentList.add(punishment.toJSON());
|
||||
|
||||
punishments.put("punishments", punishmentList);
|
||||
object.put(punishment.getPunished().toString(), punishments);
|
||||
|
||||
FileWriter writer = new FileWriter(file);
|
||||
writer.append(object.toString(8));
|
||||
writer.flush();
|
||||
writer.close();
|
||||
}
|
||||
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isNotEmpty(File file) {
|
||||
try {
|
||||
return !FileUtils.readFileToString(file, StandardCharsets.UTF_8).trim().isEmpty();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private void issuePunishment(PunishedPlayer player, Punishment punishment)
|
||||
{
|
||||
if (punishment.getType() == PunishmentType.BAN)
|
||||
{
|
||||
Ban ban = new Ban(punishment.getPunished(), (punishment.getPunisher() == null ? null : punishment.getPunisher()), "", punishment.getReason(), punishment.getEndDate());
|
||||
Plex.get().getBanManager().executeBan(ban);
|
||||
} else if (punishment.getType() == PunishmentType.FREEZE)
|
||||
{
|
||||
player.setFrozen(true);
|
||||
Date now = new Date();
|
||||
Date then = punishment.getEndDate();
|
||||
long seconds = TimeUnit.MILLISECONDS.toSeconds(then.getTime() - now.getTime());
|
||||
new BukkitRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (!player.isFrozen())
|
||||
{
|
||||
this.cancel();
|
||||
return;
|
||||
}
|
||||
player.setFrozen(false);
|
||||
Bukkit.broadcastMessage(PlexUtils.tl("unfrozePlayer", "Plex", Bukkit.getOfflinePlayer(UUID.fromString(player.getUuid())).getName()));
|
||||
Bukkit.getLogger().info("Unfroze");
|
||||
}
|
||||
}.runTaskLater(Plex.get(), 20 * seconds);
|
||||
|
||||
|
||||
|
||||
} else if (punishment.getType() == PunishmentType.MUTE)
|
||||
{
|
||||
player.setMuted(true);
|
||||
Date now = new Date();
|
||||
Date then = punishment.getEndDate();
|
||||
long seconds = TimeUnit.MILLISECONDS.toSeconds(then.getTime() - now.getTime());
|
||||
new BukkitRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
player.setMuted(false);
|
||||
}
|
||||
}.runTaskLater(Plex.get(), 20 * seconds);
|
||||
}
|
||||
}
|
||||
|
||||
public void doPunishment(PunishedPlayer player, Punishment punishment)
|
||||
{
|
||||
issuePunishment(player, punishment);
|
||||
insertPunishment(player, punishment);
|
||||
}
|
||||
|
||||
}
|
7
src/main/java/dev/plex/punishment/PunishmentType.java
Normal file
7
src/main/java/dev/plex/punishment/PunishmentType.java
Normal file
@ -0,0 +1,7 @@
|
||||
package dev.plex.punishment;
|
||||
|
||||
public enum PunishmentType
|
||||
{
|
||||
MUTE, FREEZE, BAN;
|
||||
|
||||
}
|
22
src/main/java/dev/plex/rank/DefaultRankObj.java
Normal file
22
src/main/java/dev/plex/rank/DefaultRankObj.java
Normal file
@ -0,0 +1,22 @@
|
||||
package dev.plex.rank;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import dev.plex.rank.enums.Rank;
|
||||
import java.util.List;
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
public class DefaultRankObj
|
||||
{
|
||||
private final String prefix;
|
||||
private final String loginMSG;
|
||||
private final List<String> permissions;
|
||||
|
||||
public DefaultRankObj(Rank rank)
|
||||
{
|
||||
this.prefix = rank.getPrefix();
|
||||
this.loginMSG = rank.getLoginMSG();
|
||||
this.permissions = Lists.newArrayList();
|
||||
permissions.add("example.permission");
|
||||
}
|
||||
}
|
102
src/main/java/dev/plex/rank/RankManager.java
Normal file
102
src/main/java/dev/plex/rank/RankManager.java
Normal file
@ -0,0 +1,102 @@
|
||||
package dev.plex.rank;
|
||||
|
||||
import com.google.common.collect.Maps;
|
||||
import dev.plex.Plex;
|
||||
import dev.plex.player.PlexPlayer;
|
||||
import dev.plex.util.PlexLog;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
import dev.plex.rank.enums.Rank;
|
||||
import org.json.JSONObject;
|
||||
import org.json.JSONTokener;
|
||||
|
||||
public class RankManager
|
||||
{
|
||||
private final File defaultRanks;
|
||||
|
||||
public RankManager()
|
||||
{
|
||||
File ranksFolder = new File(Plex.get().getDataFolder() + File.separator + "ranks");
|
||||
if (!ranksFolder.exists())
|
||||
{
|
||||
ranksFolder.mkdir();
|
||||
}
|
||||
|
||||
defaultRanks = new File(ranksFolder, "default-ranks.json");
|
||||
}
|
||||
|
||||
public void generateDefaultRanks()
|
||||
{
|
||||
if (defaultRanks.exists())
|
||||
{
|
||||
return;
|
||||
}
|
||||
try
|
||||
{
|
||||
defaultRanks.createNewFile();
|
||||
|
||||
Map<String, DefaultRankObj> rankMap = Maps.newHashMap();
|
||||
for (Rank rank : Rank.values())
|
||||
{
|
||||
rankMap.put(rank.name().toUpperCase(), new DefaultRankObj(rank));
|
||||
}
|
||||
|
||||
JSONObject obj = new JSONObject();
|
||||
if (obj.length() == 0)
|
||||
{
|
||||
obj.put("ranks", rankMap);
|
||||
|
||||
FileWriter writer = new FileWriter(defaultRanks);
|
||||
writer.append(obj.toString(4));
|
||||
writer.flush();
|
||||
writer.close();
|
||||
PlexLog.log("Generating default-ranks.json");
|
||||
}
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void importDefaultRanks()
|
||||
{
|
||||
if (!defaultRanks.exists())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
FileInputStream stream = new FileInputStream(defaultRanks);
|
||||
JSONTokener tokener = new JSONTokener(stream);
|
||||
JSONObject object = new JSONObject(tokener);
|
||||
JSONObject rankObj = object.getJSONObject("ranks");
|
||||
for (Rank rank : Rank.values())
|
||||
{
|
||||
if (rankObj.isNull(rank.name().toUpperCase()))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
rank.setLoginMessage(rankObj.getJSONObject(rank.name().toUpperCase()).getString("loginMSG"));
|
||||
rank.setPrefix(rankObj.getJSONObject(rank.name().toUpperCase()).getString("prefix")); //should i even be doing this
|
||||
rank.setPermissions(rankObj.getJSONObject(rank.name().toUpperCase()).getJSONArray("permissions").toList().stream().map(Object::toString).collect(Collectors.toList()));
|
||||
|
||||
}
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public boolean isAdmin(PlexPlayer plexPlayer)
|
||||
{
|
||||
return !plexPlayer.getRank().isEmpty() && plexPlayer.getRankFromString().isAtLeast(Rank.ADMIN);
|
||||
}
|
||||
}
|
68
src/main/java/dev/plex/rank/enums/Rank.java
Normal file
68
src/main/java/dev/plex/rank/enums/Rank.java
Normal file
@ -0,0 +1,68 @@
|
||||
package dev.plex.rank.enums;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import java.util.List;
|
||||
import org.bukkit.ChatColor;
|
||||
|
||||
public enum Rank
|
||||
{
|
||||
IMPOSTOR(-1, ChatColor.AQUA + "an " + ChatColor.YELLOW + "Impostor", ChatColor.YELLOW + "[Imp]"),
|
||||
NONOP(0, "a " + ChatColor.WHITE + "Non-Op", ChatColor.WHITE + ""),
|
||||
OP(1, "an " + ChatColor.GREEN + "Operator", ChatColor.GREEN + "[OP]"),
|
||||
ADMIN(2, "an " + ChatColor.DARK_GREEN + "Admin", ChatColor.DARK_GREEN + "[Admin]"),
|
||||
SENIOR_ADMIN(3, "a " + ChatColor.GOLD + "Senior Admin", ChatColor.GOLD + "[SrA]"),
|
||||
EXECUTIVE(4, "an " + ChatColor.RED + "Executive", ChatColor.RED + "[Exec]");
|
||||
|
||||
private String loginMessage;
|
||||
private String prefix;
|
||||
private int level;
|
||||
private List<String> permissions;
|
||||
|
||||
Rank(int level, String loginMessage, String prefix)
|
||||
{
|
||||
this.level = level;
|
||||
this.loginMessage = loginMessage;
|
||||
this.prefix = prefix;
|
||||
this.permissions = Lists.newArrayList();
|
||||
}
|
||||
|
||||
public String getPrefix()
|
||||
{
|
||||
return ChatColor.translateAlternateColorCodes('&', prefix);
|
||||
}
|
||||
|
||||
public String getLoginMSG()
|
||||
{
|
||||
return ChatColor.translateAlternateColorCodes('&', loginMessage);
|
||||
}
|
||||
|
||||
public int getLevel()
|
||||
{
|
||||
return level;
|
||||
}
|
||||
|
||||
public void setLoginMessage(String msg)
|
||||
{
|
||||
this.loginMessage = msg;
|
||||
}
|
||||
|
||||
public void setPrefix(String prefix)
|
||||
{
|
||||
this.prefix = prefix;
|
||||
}
|
||||
|
||||
public boolean isAtLeast(Rank rank)
|
||||
{
|
||||
return getLevel() >= rank.getLevel();
|
||||
}
|
||||
|
||||
public List<String> getPermissions()
|
||||
{
|
||||
return permissions;
|
||||
}
|
||||
|
||||
public void setPermissions(List<String> permissions)
|
||||
{
|
||||
this.permissions = permissions;
|
||||
}
|
||||
}
|
21
src/main/java/dev/plex/rank/enums/Title.java
Normal file
21
src/main/java/dev/plex/rank/enums/Title.java
Normal file
@ -0,0 +1,21 @@
|
||||
package dev.plex.rank.enums;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
|
||||
public enum Title
|
||||
{
|
||||
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]");
|
||||
|
||||
private int level;
|
||||
private String loginMSG;
|
||||
private String prefix;
|
||||
|
||||
Title(int level, String loginMSG, String prefix)
|
||||
{
|
||||
this.level = level;
|
||||
this.loginMSG = loginMSG;
|
||||
this.prefix = prefix;
|
||||
}
|
||||
}
|
16
src/main/java/dev/plex/services/AbstractService.java
Normal file
16
src/main/java/dev/plex/services/AbstractService.java
Normal file
@ -0,0 +1,16 @@
|
||||
package dev.plex.services;
|
||||
|
||||
public abstract class AbstractService implements IService
|
||||
{
|
||||
|
||||
private boolean asynchronous;
|
||||
|
||||
public AbstractService(boolean async)
|
||||
{
|
||||
this.asynchronous = async;
|
||||
}
|
||||
|
||||
public boolean isAsynchronous() {
|
||||
return asynchronous;
|
||||
}
|
||||
}
|
9
src/main/java/dev/plex/services/IService.java
Normal file
9
src/main/java/dev/plex/services/IService.java
Normal file
@ -0,0 +1,9 @@
|
||||
package dev.plex.services;
|
||||
|
||||
public interface IService
|
||||
{
|
||||
|
||||
void run();
|
||||
|
||||
int repeatInSeconds();
|
||||
}
|
44
src/main/java/dev/plex/services/ServiceManager.java
Normal file
44
src/main/java/dev/plex/services/ServiceManager.java
Normal file
@ -0,0 +1,44 @@
|
||||
package dev.plex.services;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import dev.plex.Plex;
|
||||
import dev.plex.services.impl.BanService;
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class ServiceManager
|
||||
{
|
||||
|
||||
private final List<AbstractService> services = Lists.newArrayList();
|
||||
|
||||
public ServiceManager()
|
||||
{
|
||||
registerService(new BanService());
|
||||
}
|
||||
|
||||
public void startServices()
|
||||
{
|
||||
for (AbstractService service : services)
|
||||
{
|
||||
if (service.isAsynchronous())
|
||||
{
|
||||
Bukkit.getScheduler().runTaskTimerAsynchronously(Plex.get(), service::run, 0, 20 * service.repeatInSeconds());
|
||||
} else {
|
||||
Bukkit.getScheduler().runTaskTimer(Plex.get(), service::run, 0, 20 * service.repeatInSeconds());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void registerService(AbstractService service)
|
||||
{
|
||||
services.add(service);
|
||||
}
|
||||
|
||||
public int serviceCount()
|
||||
{
|
||||
return services.size();
|
||||
}
|
||||
|
||||
}
|
32
src/main/java/dev/plex/services/impl/BanService.java
Normal file
32
src/main/java/dev/plex/services/impl/BanService.java
Normal file
@ -0,0 +1,32 @@
|
||||
package dev.plex.services.impl;
|
||||
|
||||
import dev.plex.Plex;
|
||||
import dev.plex.services.AbstractService;
|
||||
import dev.plex.banning.Ban;
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
public class BanService extends AbstractService
|
||||
{
|
||||
public BanService() {
|
||||
super(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
for (Ban ban : Plex.get().getBanManager().getActiveBans())
|
||||
{
|
||||
if (new Date().after(ban.getEndDate()))
|
||||
{
|
||||
Plex.get().getBanManager().unban(ban.getId());
|
||||
Bukkit.broadcastMessage("Plex - Unbanned " + Bukkit.getOfflinePlayer(ban.getUuid()).getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int repeatInSeconds() {
|
||||
return 10;
|
||||
}
|
||||
}
|
39
src/main/java/dev/plex/storage/MongoConnection.java
Normal file
39
src/main/java/dev/plex/storage/MongoConnection.java
Normal file
@ -0,0 +1,39 @@
|
||||
package dev.plex.storage;
|
||||
|
||||
import com.mongodb.client.MongoClient;
|
||||
import com.mongodb.client.MongoClients;
|
||||
import dev.morphia.Datastore;
|
||||
import dev.morphia.Morphia;
|
||||
import dev.morphia.mapping.MapperOptions;
|
||||
import dev.plex.Plex;
|
||||
import dev.plex.banning.Ban;
|
||||
import dev.plex.player.PlexPlayer;
|
||||
|
||||
public class MongoConnection
|
||||
{
|
||||
// USE MORPHIA API FOR MONGO <3
|
||||
|
||||
private final Plex plugin = Plex.get();
|
||||
|
||||
public Datastore getDatastore()
|
||||
{
|
||||
if (!plugin.config.getString("data.central.storage").equalsIgnoreCase("mongodb"))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
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 = MongoClients.create(connectionString);
|
||||
Datastore datastore = Morphia.createDatastore(client, database, MapperOptions.DEFAULT);
|
||||
datastore.getMapper().map(PlexPlayer.class);
|
||||
datastore.getMapper().map(Ban.class);
|
||||
datastore.ensureIndexes();
|
||||
plugin.setStorageType(StorageType.MONGODB);
|
||||
return datastore;
|
||||
}
|
||||
}
|
32
src/main/java/dev/plex/storage/RedisConnection.java
Normal file
32
src/main/java/dev/plex/storage/RedisConnection.java
Normal file
@ -0,0 +1,32 @@
|
||||
package dev.plex.storage;
|
||||
|
||||
import dev.plex.Plex;
|
||||
import redis.clients.jedis.Jedis;
|
||||
import redis.clients.jedis.JedisPool;
|
||||
import redis.clients.jedis.JedisPoolConfig;
|
||||
|
||||
public class RedisConnection
|
||||
{
|
||||
private JedisPool pool;
|
||||
private Jedis jedis;
|
||||
|
||||
public JedisPool openPool()
|
||||
{
|
||||
ClassLoader previous = Thread.currentThread().getContextClassLoader();
|
||||
Thread.currentThread().setContextClassLoader(RedisConnection.class.getClassLoader());
|
||||
this.pool = new JedisPool(new JedisPoolConfig(), Plex.get().getConfig().getString("data.side.hostname"), Plex.get().getConfig().getInt("data.side.port"));
|
||||
Thread.currentThread().setContextClassLoader(previous);
|
||||
return pool;
|
||||
}
|
||||
|
||||
public Jedis getJedis()
|
||||
{
|
||||
this.jedis = pool.getResource();
|
||||
if (Plex.get().getConfig().getBoolean("data.side.auth"))
|
||||
{
|
||||
jedis.auth(Plex.get().getConfig().getString("data.side.password"));
|
||||
}
|
||||
return jedis;
|
||||
}
|
||||
|
||||
}
|
72
src/main/java/dev/plex/storage/SQLConnection.java
Normal file
72
src/main/java/dev/plex/storage/SQLConnection.java
Normal file
@ -0,0 +1,72 @@
|
||||
package dev.plex.storage;
|
||||
|
||||
import dev.plex.Plex;
|
||||
import dev.plex.PlexBase;
|
||||
import java.io.File;
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.SQLException;
|
||||
|
||||
public class SQLConnection extends PlexBase
|
||||
{
|
||||
private Connection connection;
|
||||
|
||||
public Connection getCon()
|
||||
{
|
||||
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.config.getString("data.central.storage").equalsIgnoreCase("sqlite"))
|
||||
{
|
||||
connection = DriverManager.getConnection("jdbc:sqlite:" + new File(plugin.getDataFolder(), "database.db").getAbsolutePath());
|
||||
plugin.setStorageType(StorageType.SQLITE);
|
||||
}
|
||||
else if (plugin.config.getString("data.central.storage").equalsIgnoreCase("mariadb"))
|
||||
{
|
||||
Class.forName("org.mariadb.jdbc.Driver");
|
||||
connection = DriverManager.getConnection("jdbc:mariadb://" + host + ":" + port + "/" + database, username, password);
|
||||
Plex.get().setStorageType(StorageType.MARIADB);
|
||||
}
|
||||
}
|
||||
catch (SQLException | ClassNotFoundException throwables)
|
||||
{
|
||||
throwables.printStackTrace();
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
if (connection != null)
|
||||
{
|
||||
connection.prepareStatement("CREATE TABLE IF NOT EXISTS `players` (" +
|
||||
"`uuid` VARCHAR(46) NOT NULL, " +
|
||||
"`name` VARCHAR(18), " +
|
||||
"`login_msg` VARCHAR(70), " +
|
||||
"`prefix` VARCHAR(45), " +
|
||||
"`rank` VARCHAR(20), " +
|
||||
"`ips` VARCHAR(2000), " +
|
||||
"`coins` BIGINT, " +
|
||||
"`vanished` BOOLEAN, " +
|
||||
"PRIMARY KEY (`uuid`));").execute();
|
||||
connection.prepareStatement("CREATE TABLE IF NOT EXISTS `bans` (" +
|
||||
"`banID` VARCHAR(46)," +
|
||||
" `uuid` VARCHAR(46) NOT NULL," +
|
||||
" `banner` VARCHAR(46)," +
|
||||
"`ip` VARCHAR(2000)," +
|
||||
" `reason` VARCHAR(256)," +
|
||||
" `enddate` BIGINT," +
|
||||
" `active` BOOLEAN," +
|
||||
" PRIMARY KEY (`banID`)" +
|
||||
");").execute();
|
||||
}
|
||||
}
|
||||
catch (SQLException throwables)
|
||||
{
|
||||
throwables.printStackTrace();
|
||||
}
|
||||
return connection;
|
||||
}
|
||||
}
|
6
src/main/java/dev/plex/storage/StorageType.java
Normal file
6
src/main/java/dev/plex/storage/StorageType.java
Normal file
@ -0,0 +1,6 @@
|
||||
package dev.plex.storage;
|
||||
|
||||
public enum StorageType
|
||||
{
|
||||
MONGODB, MARIADB, SQLITE
|
||||
}
|
17
src/main/java/dev/plex/util/PlexLog.java
Normal file
17
src/main/java/dev/plex/util/PlexLog.java
Normal file
@ -0,0 +1,17 @@
|
||||
package dev.plex.util;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
|
||||
public class PlexLog
|
||||
{
|
||||
public static void log(String message)
|
||||
{
|
||||
Bukkit.getConsoleSender().sendMessage(String.format(ChatColor.YELLOW + "[Plex] " + ChatColor.GRAY + "%s", message));
|
||||
}
|
||||
|
||||
public static void error(String message)
|
||||
{
|
||||
Bukkit.getConsoleSender().sendMessage(String.format(ChatColor.RED + "[Plex Error]" + ChatColor.GOLD + "%s", message));
|
||||
}
|
||||
}
|
257
src/main/java/dev/plex/util/PlexUtils.java
Normal file
257
src/main/java/dev/plex/util/PlexUtils.java
Normal file
@ -0,0 +1,257 @@
|
||||
package dev.plex.util;
|
||||
|
||||
import dev.plex.Plex;
|
||||
import dev.plex.config.Config;
|
||||
import dev.plex.storage.StorageType;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
import java.sql.SQLException;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
import java.util.stream.Collectors;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.PluginCommandYamlParser;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.json.simple.JSONObject;
|
||||
import org.json.simple.parser.JSONParser;
|
||||
import org.json.simple.parser.ParseException;
|
||||
|
||||
public class PlexUtils
|
||||
{
|
||||
public static Map<String, ChatColor> CHAT_COLOR_NAMES;
|
||||
public static List<ChatColor> CHAT_COLOR_POOL;
|
||||
private static Random RANDOM;
|
||||
|
||||
static
|
||||
{
|
||||
RANDOM = new Random();
|
||||
CHAT_COLOR_NAMES = new HashMap<>();
|
||||
CHAT_COLOR_POOL = Arrays.asList(ChatColor.DARK_RED, ChatColor.RED, ChatColor.GOLD, ChatColor.YELLOW, ChatColor.GREEN, ChatColor.DARK_GREEN, ChatColor.AQUA, ChatColor.DARK_AQUA, ChatColor.BLUE, ChatColor.DARK_BLUE, ChatColor.DARK_PURPLE, ChatColor.LIGHT_PURPLE);
|
||||
for (final ChatColor chatColor : CHAT_COLOR_POOL)
|
||||
{
|
||||
CHAT_COLOR_NAMES.put(chatColor.name().toLowerCase().replace("_", ""), chatColor);
|
||||
}
|
||||
}
|
||||
|
||||
public static ChatColor randomChatColor()
|
||||
{
|
||||
return CHAT_COLOR_POOL.get(RANDOM.nextInt(CHAT_COLOR_POOL.size()));
|
||||
}
|
||||
|
||||
public static void testConnections()
|
||||
{
|
||||
if (Plex.get().getSqlConnection().getCon() != null)
|
||||
{
|
||||
if (Plex.get().getStorageType() == StorageType.MARIADB)
|
||||
{
|
||||
PlexLog.log("Successfully enabled MySQL!");
|
||||
}
|
||||
else if (Plex.get().getStorageType() == StorageType.SQLITE)
|
||||
{
|
||||
PlexLog.log("Successfully enabled SQLite!");
|
||||
}
|
||||
try
|
||||
{
|
||||
Plex.get().getSqlConnection().getCon().close();
|
||||
}
|
||||
catch (SQLException ignored)
|
||||
{
|
||||
}
|
||||
}
|
||||
else if (Plex.get().getMongoConnection().getDatastore() != null)
|
||||
{
|
||||
PlexLog.log("Successfully enabled MongoDB!");
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isPluginCMD(String cmd, String pluginName)
|
||||
{
|
||||
Plugin plugin = Bukkit.getServer().getPluginManager().getPlugin(pluginName);
|
||||
if (plugin == null)
|
||||
{
|
||||
PlexLog.error(pluginName + " can not be found on the server! Make sure it is spelt correctly!");
|
||||
return false;
|
||||
}
|
||||
List<Command> cmds = PluginCommandYamlParser.parse(plugin);
|
||||
for (Command pluginCmd : cmds)
|
||||
{
|
||||
List<String> cmdAliases = pluginCmd.getAliases().size() > 0 ? pluginCmd.getAliases().stream().map(String::toLowerCase).collect(Collectors.toList()) : null;
|
||||
if (pluginCmd.getName().equalsIgnoreCase(cmd) || (cmdAliases != null && cmdAliases.contains(cmd.toLowerCase())))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static String color(String s)
|
||||
{
|
||||
return ChatColor.translateAlternateColorCodes('&', s);
|
||||
}
|
||||
|
||||
public static String colorize(final String string)
|
||||
{
|
||||
return ChatColor.translateAlternateColorCodes('&', string);
|
||||
}
|
||||
|
||||
// if you think the name of this method is dumb feel free to change it i just thought it'd be cool
|
||||
public static String tl(String s, Object... objects)
|
||||
{
|
||||
Plex plugin = Plex.get();
|
||||
if (s.equals("baseColor") || s.equals("errorColor") || s.equals("broadcastColor"))
|
||||
{
|
||||
return getChatColorFromConfig(plugin.messages, ChatColor.WHITE, s).toString();
|
||||
}
|
||||
String f = plugin.messages.getString(s);
|
||||
if (f == null)
|
||||
{
|
||||
return ChatColor.RED + "No message";
|
||||
}
|
||||
for (Object object : objects)
|
||||
{
|
||||
f = f.replaceFirst("<v>", String.valueOf(object));
|
||||
}
|
||||
ChatColor base = getChatColorFromConfig(plugin.messages, ChatColor.GRAY, "baseColor");
|
||||
ChatColor broadcast = getChatColorFromConfig(plugin.messages, ChatColor.AQUA, "broadcastColor");
|
||||
ChatColor error = getChatColorFromConfig(plugin.messages, ChatColor.RED, "errorColor");
|
||||
f = f.replaceAll("<r>", base.toString());
|
||||
f = f.replaceAll("<b>", broadcast.toString());
|
||||
f = f.replaceAll("<e>", error.toString());
|
||||
f = color(f);
|
||||
return base + f;
|
||||
}
|
||||
|
||||
public static ChatColor getChatColorFromConfig(Config config, ChatColor def, String path)
|
||||
{
|
||||
ChatColor color;
|
||||
if (config.getString(path) == null)
|
||||
{
|
||||
color = def;
|
||||
}
|
||||
else if (ChatColor.getByChar(config.getString(path)) == null)
|
||||
{
|
||||
color = def;
|
||||
}
|
||||
else
|
||||
{
|
||||
color = ChatColor.getByChar(config.getString(path));
|
||||
}
|
||||
return color;
|
||||
}
|
||||
|
||||
public static void setBlocks(Location c1, Location c2, Material material)
|
||||
{
|
||||
if (!c1.getWorld().getName().equals(c1.getWorld().getName()))
|
||||
{
|
||||
return;
|
||||
}
|
||||
int sy = Math.min(c1.getBlockY(), c2.getBlockY()),
|
||||
ey = Math.max(c1.getBlockY(), c2.getBlockY()),
|
||||
sx = Math.min(c1.getBlockX(), c2.getBlockX()),
|
||||
ex = Math.max(c1.getBlockX(), c2.getBlockX()),
|
||||
sz = Math.min(c1.getBlockZ(), c2.getBlockZ()),
|
||||
ez = Math.max(c1.getBlockZ(), c2.getBlockZ());
|
||||
World world = c1.getWorld();
|
||||
for (int y = sy; y <= ey; y++)
|
||||
{
|
||||
for (int x = sx; x <= ex; x++)
|
||||
{
|
||||
for (int z = sz; z <= ez; z++)
|
||||
{
|
||||
world.getBlockAt(x, y, z).setType(material);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static List<String> getPlayerNameList()
|
||||
{
|
||||
List<String> names = new ArrayList<>();
|
||||
for (Player player : Bukkit.getOnlinePlayers())
|
||||
{
|
||||
names.add(player.getName());
|
||||
}
|
||||
return names;
|
||||
}
|
||||
|
||||
public static void broadcast(String s)
|
||||
{
|
||||
Bukkit.broadcastMessage(s);
|
||||
}
|
||||
|
||||
public static Object simpleGET(String url) throws IOException, ParseException
|
||||
{
|
||||
URL u = new URL(url);
|
||||
HttpURLConnection connection = (HttpURLConnection)u.openConnection();
|
||||
connection.setRequestMethod("GET");
|
||||
BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
|
||||
String line;
|
||||
StringBuilder content = new StringBuilder();
|
||||
while ((line = in.readLine()) != null)
|
||||
{
|
||||
content.append(line);
|
||||
}
|
||||
in.close();
|
||||
connection.disconnect();
|
||||
return new JSONParser().parse(content.toString());
|
||||
}
|
||||
|
||||
public static UUID getFromName(String name)
|
||||
{
|
||||
JSONObject profile;
|
||||
try
|
||||
{
|
||||
profile = (JSONObject)PlexUtils.simpleGET("https://api.ashcon.app/mojang/v2/user/" + name);
|
||||
}
|
||||
catch (IOException | ParseException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
String uuidString = (String)profile.get("uuid");
|
||||
return UUID.fromString(uuidString);
|
||||
}
|
||||
|
||||
public static int randomNum()
|
||||
{
|
||||
return ThreadLocalRandom.current().nextInt();
|
||||
}
|
||||
|
||||
public static int randomNum(int limit)
|
||||
{
|
||||
return ThreadLocalRandom.current().nextInt(limit);
|
||||
}
|
||||
public static int randomNum(int start, int limit)
|
||||
{
|
||||
return ThreadLocalRandom.current().nextInt(start, limit);
|
||||
}
|
||||
|
||||
public static long getDateNow()
|
||||
{
|
||||
return new Date().getTime();
|
||||
}
|
||||
|
||||
public static Date getDateFromLong(long epoch)
|
||||
{
|
||||
return new Date(epoch);
|
||||
}
|
||||
|
||||
public static long hoursToSeconds(long hours)
|
||||
{
|
||||
return hours * 60 * 60;
|
||||
}
|
||||
|
||||
public static long minutesToSeconds(long minutes)
|
||||
{
|
||||
return minutes * 60;
|
||||
}
|
||||
}
|
20
src/main/java/dev/plex/util/menu/AbstractMenu.java
Normal file
20
src/main/java/dev/plex/util/menu/AbstractMenu.java
Normal file
@ -0,0 +1,20 @@
|
||||
package dev.plex.util.menu;
|
||||
|
||||
import dev.plex.Plex;
|
||||
import org.bukkit.event.Listener;
|
||||
|
||||
public abstract class AbstractMenu implements Listener
|
||||
{
|
||||
private String name;
|
||||
|
||||
public AbstractMenu(String name)
|
||||
{
|
||||
this.name = name;
|
||||
|
||||
Plex.get().getServer().getPluginManager().registerEvents(this, Plex.get());
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
}
|
20
src/main/java/dev/plex/util/menu/IMenu.java
Normal file
20
src/main/java/dev/plex/util/menu/IMenu.java
Normal file
@ -0,0 +1,20 @@
|
||||
package dev.plex.util.menu;
|
||||
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
|
||||
public interface IMenu
|
||||
{
|
||||
|
||||
Inventory getInventory();
|
||||
|
||||
|
||||
void openInv(Player player);
|
||||
|
||||
@EventHandler
|
||||
void onClick(InventoryClickEvent event);
|
||||
|
||||
}
|
34
src/main/java/dev/plex/world/BlockMapChunkGenerator.java
Normal file
34
src/main/java/dev/plex/world/BlockMapChunkGenerator.java
Normal file
@ -0,0 +1,34 @@
|
||||
package dev.plex.world;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.generator.BlockPopulator;
|
||||
|
||||
public class BlockMapChunkGenerator extends FlatChunkGenerator
|
||||
{
|
||||
protected LinkedHashMap<Material, Integer> blockMap;
|
||||
|
||||
public BlockMapChunkGenerator(LinkedHashMap<Material, Integer> blockMap, BlockPopulator... populators)
|
||||
{
|
||||
super(0, populators);
|
||||
this.blockMap = blockMap;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void createLoopChunkData(int x, int y, int z, ChunkData chunk)
|
||||
{
|
||||
int height = -1;
|
||||
for (int i : blockMap.values())
|
||||
{
|
||||
height += i;
|
||||
}
|
||||
for (Map.Entry<Material, Integer> entry : blockMap.entrySet())
|
||||
{
|
||||
for (int i = 0; i < entry.getValue(); i++, height--)
|
||||
{
|
||||
chunk.setBlock(x, height, z, entry.getKey());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,32 @@
|
||||
package dev.plex.world;
|
||||
|
||||
import dev.plex.Plex;
|
||||
import java.util.LinkedHashMap;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.generator.BlockPopulator;
|
||||
|
||||
public class ConfigurationChunkGenerator extends BlockMapChunkGenerator
|
||||
{
|
||||
private static final Plex plugin = Plex.get();
|
||||
|
||||
public ConfigurationChunkGenerator(String worldName, BlockPopulator... populators)
|
||||
{
|
||||
super(createBlockMap(worldName), populators);
|
||||
}
|
||||
|
||||
private static LinkedHashMap<Material, Integer> createBlockMap(String worldName)
|
||||
{
|
||||
LinkedHashMap<Material, Integer> blockMap = new LinkedHashMap<>();
|
||||
for (String key : plugin.config.getConfigurationSection("worlds." + worldName + ".parameters").getKeys(false))
|
||||
{
|
||||
Material material = Material.getMaterial(key.toUpperCase());
|
||||
if (material == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
int count = plugin.config.getInt("worlds." + worldName + ".parameters." + key);
|
||||
blockMap.put(material, count);
|
||||
}
|
||||
return blockMap;
|
||||
}
|
||||
}
|
26
src/main/java/dev/plex/world/CustomChunkGenerator.java
Normal file
26
src/main/java/dev/plex/world/CustomChunkGenerator.java
Normal file
@ -0,0 +1,26 @@
|
||||
package dev.plex.world;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.generator.BlockPopulator;
|
||||
import org.bukkit.generator.ChunkGenerator;
|
||||
|
||||
public abstract class CustomChunkGenerator extends ChunkGenerator
|
||||
{
|
||||
protected int height;
|
||||
private final List<BlockPopulator> populators;
|
||||
|
||||
protected CustomChunkGenerator(int height, BlockPopulator... populators)
|
||||
{
|
||||
this.height = height;
|
||||
this.populators = Arrays.asList(populators);
|
||||
}
|
||||
|
||||
public List<BlockPopulator> getDefaultPopulators(World world)
|
||||
{
|
||||
return populators;
|
||||
}
|
||||
|
||||
public abstract void createLoopChunkData(int x, int y, int z, ChunkData chunk);
|
||||
}
|
69
src/main/java/dev/plex/world/CustomWorld.java
Normal file
69
src/main/java/dev/plex/world/CustomWorld.java
Normal file
@ -0,0 +1,69 @@
|
||||
package dev.plex.world;
|
||||
|
||||
import dev.plex.Plex;
|
||||
import java.io.File;
|
||||
import java.util.Objects;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.WorldCreator;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockState;
|
||||
import org.bukkit.block.Sign;
|
||||
import org.bukkit.generator.ChunkGenerator;
|
||||
|
||||
public class CustomWorld extends WorldCreator
|
||||
{
|
||||
private static final Plex plugin = Plex.get();
|
||||
|
||||
private final CustomChunkGenerator chunks;
|
||||
|
||||
public CustomWorld(String name, CustomChunkGenerator generator)
|
||||
{
|
||||
super(name);
|
||||
this.chunks = generator;
|
||||
this.generator(this.chunks);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChunkGenerator generator()
|
||||
{
|
||||
return chunks;
|
||||
}
|
||||
|
||||
public World generate()
|
||||
{
|
||||
return this.createWorld();
|
||||
}
|
||||
|
||||
public static World generateConfigFlatWorld(String name)
|
||||
{
|
||||
if (!plugin.config.contains("worlds." + name))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
CustomWorld customWorld = new CustomWorld(name, new ConfigurationChunkGenerator(name))
|
||||
{
|
||||
@Override
|
||||
public World generate()
|
||||
{
|
||||
boolean existed = new File(name).exists();
|
||||
World world = super.generate();
|
||||
if (!existed)
|
||||
{
|
||||
Block block = world.getBlockAt(0, world.getHighestBlockYAt(0, 0) + 1, 0);
|
||||
block.setType(Material.OAK_SIGN);
|
||||
BlockState state = block.getState();
|
||||
if (state instanceof Sign)
|
||||
{
|
||||
Sign sign = (Sign)state;
|
||||
sign.setLine(1, Objects.requireNonNull(plugin.config.getString("worlds." + name + ".name")));
|
||||
sign.setLine(2, "- 0, 0 -");
|
||||
sign.update();
|
||||
}
|
||||
}
|
||||
return world;
|
||||
}
|
||||
};
|
||||
return customWorld.generate();
|
||||
}
|
||||
}
|
29
src/main/java/dev/plex/world/FlatChunkGenerator.java
Normal file
29
src/main/java/dev/plex/world/FlatChunkGenerator.java
Normal file
@ -0,0 +1,29 @@
|
||||
package dev.plex.world;
|
||||
|
||||
import java.util.Random;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.generator.BlockPopulator;
|
||||
|
||||
public abstract class FlatChunkGenerator extends CustomChunkGenerator
|
||||
{
|
||||
public FlatChunkGenerator(int height, BlockPopulator... populators)
|
||||
{
|
||||
super(height, populators);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChunkData generateChunkData(World world, Random random, int x, int z, BiomeGrid biome)
|
||||
{
|
||||
ChunkData chunk = this.createChunkData(world);
|
||||
for (int xx = 0; xx < 16; xx++)
|
||||
{
|
||||
for (int zz = 0; zz < 16; zz++)
|
||||
{
|
||||
createLoopChunkData(xx, height, zz, chunk);
|
||||
}
|
||||
}
|
||||
return chunk;
|
||||
}
|
||||
|
||||
public abstract void createLoopChunkData(int x, int y, int z, ChunkData chunk);
|
||||
}
|
35
src/main/java/dev/plex/world/NoiseChunkGenerator.java
Normal file
35
src/main/java/dev/plex/world/NoiseChunkGenerator.java
Normal file
@ -0,0 +1,35 @@
|
||||
package dev.plex.world;
|
||||
|
||||
import java.util.Random;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.generator.BlockPopulator;
|
||||
import org.bukkit.util.noise.PerlinNoiseGenerator;
|
||||
|
||||
public abstract class NoiseChunkGenerator extends CustomChunkGenerator
|
||||
{
|
||||
private final NoiseOptions options;
|
||||
|
||||
public NoiseChunkGenerator(int height, NoiseOptions options, BlockPopulator... populators)
|
||||
{
|
||||
super(height, populators);
|
||||
this.options = options;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChunkData generateChunkData(World world, Random random, int x, int z, BiomeGrid biome)
|
||||
{
|
||||
ChunkData chunk = this.createChunkData(world);
|
||||
PerlinNoiseGenerator generator = new PerlinNoiseGenerator(new Random(world.getSeed()));
|
||||
for (int xx = 0; xx < 16; xx++)
|
||||
{
|
||||
for (int zz = 0; zz < 16; zz++)
|
||||
{
|
||||
height = (int)generator.noise(options.getX(), options.getY(), options.getFrequency(), options.getAmplitude(), options.isNormalized());
|
||||
createLoopChunkData(xx, height, zz, chunk);
|
||||
}
|
||||
}
|
||||
return chunk;
|
||||
}
|
||||
|
||||
public abstract void createLoopChunkData(int x, int y, int z, ChunkData chunk);
|
||||
}
|
22
src/main/java/dev/plex/world/NoiseOptions.java
Normal file
22
src/main/java/dev/plex/world/NoiseOptions.java
Normal file
@ -0,0 +1,22 @@
|
||||
package dev.plex.world;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
public class NoiseOptions
|
||||
{
|
||||
private final int x;
|
||||
private final int y;
|
||||
private final double frequency;
|
||||
private final double amplitude;
|
||||
private final boolean normalized;
|
||||
|
||||
public NoiseOptions(int x, int y, double frequency, double amplitude, boolean normalized)
|
||||
{
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.frequency = frequency;
|
||||
this.amplitude = amplitude;
|
||||
this.normalized = normalized;
|
||||
}
|
||||
}
|
35
src/main/java/dev/plex/world/OctaveChunkGenerator.java
Normal file
35
src/main/java/dev/plex/world/OctaveChunkGenerator.java
Normal file
@ -0,0 +1,35 @@
|
||||
package dev.plex.world;
|
||||
|
||||
import java.util.Random;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.generator.BlockPopulator;
|
||||
import org.bukkit.util.noise.PerlinOctaveGenerator;
|
||||
|
||||
public abstract class OctaveChunkGenerator extends CustomChunkGenerator
|
||||
{
|
||||
private final OctaveOptions options;
|
||||
|
||||
public OctaveChunkGenerator(int height, OctaveOptions options, BlockPopulator... populators)
|
||||
{
|
||||
super(height, populators);
|
||||
this.options = options;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChunkData generateChunkData(World world, Random random, int x, int z, BiomeGrid biome)
|
||||
{
|
||||
ChunkData chunk = this.createChunkData(world);
|
||||
PerlinOctaveGenerator generator = new PerlinOctaveGenerator(new Random(world.getSeed()), options.getOctaves());
|
||||
for (int xx = 0; xx < 16; xx++)
|
||||
{
|
||||
for (int zz = 0; zz < 16; zz++)
|
||||
{
|
||||
height = (int)generator.noise(options.getX(), options.getY(), options.getFrequency(), options.getAmplitude(), options.isNormalized());
|
||||
createLoopChunkData(xx, height, zz, chunk);
|
||||
}
|
||||
}
|
||||
return chunk;
|
||||
}
|
||||
|
||||
public abstract void createLoopChunkData(int x, int y, int z, ChunkData chunk);
|
||||
}
|
15
src/main/java/dev/plex/world/OctaveOptions.java
Normal file
15
src/main/java/dev/plex/world/OctaveOptions.java
Normal file
@ -0,0 +1,15 @@
|
||||
package dev.plex.world;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
public class OctaveOptions extends NoiseOptions
|
||||
{
|
||||
private final int octaves;
|
||||
|
||||
public OctaveOptions(int x, int y, double frequency, double amplitude, boolean normalized, int octaves)
|
||||
{
|
||||
super(x, y, frequency, amplitude, normalized);
|
||||
this.octaves = octaves;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user