This commit is contained in:
Telesphoreo 2020-11-05 19:29:38 -06:00
parent ce76aa9ce1
commit e4cf18db38
49 changed files with 309 additions and 187 deletions

View File

@ -27,7 +27,7 @@
<dependency> <dependency>
<groupId>com.destroystokyo.paper</groupId> <groupId>com.destroystokyo.paper</groupId>
<artifactId>paper-api</artifactId> <artifactId>paper-api</artifactId>
<version>1.16.3-R0.1-SNAPSHOT</version> <version>1.16.4-R0.1-SNAPSHOT</version>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
@ -35,7 +35,7 @@
<dependency> <dependency>
<groupId>org.projectlombok</groupId> <groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId> <artifactId>lombok</artifactId>
<version>1.18.12</version> <version>1.18.16</version>
<scope>compile</scope> <scope>compile</scope>
</dependency> </dependency>
<dependency> <dependency>

View File

@ -18,8 +18,6 @@ import me.totalfreedom.plex.util.PlexUtils;
import me.totalfreedom.plex.world.CustomWorld; import me.totalfreedom.plex.world.CustomWorld;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
import java.io.File;
@Getter @Getter
@Setter @Setter
public class Plex extends JavaPlugin public class Plex extends JavaPlugin
@ -118,7 +116,9 @@ public class Plex extends JavaPlugin
{ {
PlexLog.log("Generating any worlds if needed..."); PlexLog.log("Generating any worlds if needed...");
for (String key : config.getConfigurationSection("worlds").getKeys(false)) for (String key : config.getConfigurationSection("worlds").getKeys(false))
{
CustomWorld.generateConfigFlatWorld(key); CustomWorld.generateConfigFlatWorld(key);
}
PlexLog.log("Finished with world generation!"); PlexLog.log("Finished with world generation!");
} }
} }

View File

@ -1,12 +1,11 @@
package me.totalfreedom.plex.admin; package me.totalfreedom.plex.admin;
import java.util.UUID;
import lombok.AccessLevel; import lombok.AccessLevel;
import lombok.Getter; import lombok.Getter;
import lombok.Setter; import lombok.Setter;
import me.totalfreedom.plex.rank.enums.Rank; import me.totalfreedom.plex.rank.enums.Rank;
import java.util.UUID;
@Getter @Getter
@Setter @Setter
public class Admin public class Admin
@ -26,6 +25,4 @@ public class Admin
} }
} }

View File

@ -4,13 +4,7 @@ import com.google.common.collect.Lists;
import com.google.common.collect.Maps; import com.google.common.collect.Maps;
import dev.morphia.Datastore; import dev.morphia.Datastore;
import dev.morphia.query.Query; import dev.morphia.query.Query;
import dev.morphia.query.experimental.filters.Filters;
import dev.morphia.query.internal.MorphiaCursor; import dev.morphia.query.internal.MorphiaCursor;
import me.totalfreedom.plex.Plex;
import me.totalfreedom.plex.player.PlexPlayer;
import me.totalfreedom.plex.rank.enums.Rank;
import me.totalfreedom.plex.storage.StorageType;
import java.sql.Connection; import java.sql.Connection;
import java.sql.PreparedStatement; import java.sql.PreparedStatement;
import java.sql.ResultSet; import java.sql.ResultSet;
@ -18,6 +12,10 @@ import java.sql.SQLException;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.UUID; import java.util.UUID;
import me.totalfreedom.plex.Plex;
import me.totalfreedom.plex.player.PlexPlayer;
import me.totalfreedom.plex.rank.enums.Rank;
import me.totalfreedom.plex.storage.StorageType;
public class AdminList public class AdminList
{ {
@ -51,7 +49,9 @@ public class AdminList
admins.add(player.getName()); admins.add(player.getName());
} }
} }
} else { }
else
{
try (Connection con = Plex.get().getSqlConnection().getCon()) try (Connection con = Plex.get().getSqlConnection().getCon())
{ {
PreparedStatement statement = con.prepareStatement("SELECT * FROM `players` WHERE rank IN(?, ?, ?)"); PreparedStatement statement = con.prepareStatement("SELECT * FROM `players` WHERE rank IN(?, ?, ?)");
@ -65,7 +65,9 @@ public class AdminList
admins.add(set.getString("name")); admins.add(set.getString("name"));
} }
} catch (SQLException throwables) { }
catch (SQLException throwables)
{
throwables.printStackTrace(); throwables.printStackTrace();
} }
} }

View File

@ -1,11 +1,10 @@
package me.totalfreedom.plex.cache; package me.totalfreedom.plex.cache;
import java.util.UUID;
import me.totalfreedom.plex.Plex; import me.totalfreedom.plex.Plex;
import me.totalfreedom.plex.player.PlexPlayer; import me.totalfreedom.plex.player.PlexPlayer;
import me.totalfreedom.plex.storage.StorageType; import me.totalfreedom.plex.storage.StorageType;
import java.util.UUID;
public class DataUtils public class DataUtils
{ {
@ -14,7 +13,9 @@ public class DataUtils
if (Plex.get().getStorageType() == StorageType.MONGO) if (Plex.get().getStorageType() == StorageType.MONGO)
{ {
return Plex.get().getMongoPlayerData().exists(uuid); return Plex.get().getMongoPlayerData().exists(uuid);
} else { }
else
{
return Plex.get().getSqlPlayerData().exists(uuid); return Plex.get().getSqlPlayerData().exists(uuid);
} }
} }
@ -29,7 +30,9 @@ public class DataUtils
if (Plex.get().getStorageType() == StorageType.MONGO) if (Plex.get().getStorageType() == StorageType.MONGO)
{ {
return Plex.get().getMongoPlayerData().getByUUID(uuid); return Plex.get().getMongoPlayerData().getByUUID(uuid);
} else { }
else
{
return Plex.get().getSqlPlayerData().getByUUID(uuid); return Plex.get().getSqlPlayerData().getByUUID(uuid);
} }
} }
@ -39,7 +42,9 @@ public class DataUtils
if (Plex.get().getStorageType() == StorageType.MONGO) if (Plex.get().getStorageType() == StorageType.MONGO)
{ {
Plex.get().getMongoPlayerData().update(plexPlayer); Plex.get().getMongoPlayerData().update(plexPlayer);
} else { }
else
{
Plex.get().getSqlPlayerData().update(plexPlayer); Plex.get().getSqlPlayerData().update(plexPlayer);
} }
} }

View File

@ -5,11 +5,10 @@ import dev.morphia.query.Query;
import dev.morphia.query.Update; import dev.morphia.query.Update;
import dev.morphia.query.experimental.filters.Filters; import dev.morphia.query.experimental.filters.Filters;
import dev.morphia.query.experimental.updates.UpdateOperators; import dev.morphia.query.experimental.updates.UpdateOperators;
import java.util.UUID;
import me.totalfreedom.plex.Plex; import me.totalfreedom.plex.Plex;
import me.totalfreedom.plex.player.PlexPlayer; import me.totalfreedom.plex.player.PlexPlayer;
import java.util.UUID;
public class MongoPlayerData public class MongoPlayerData
{ {
private final Datastore datastore; private final Datastore datastore;

View File

@ -1,11 +1,10 @@
package me.totalfreedom.plex.cache; package me.totalfreedom.plex.cache;
import com.google.common.collect.Maps; import com.google.common.collect.Maps;
import me.totalfreedom.plex.player.PlexPlayer;
import me.totalfreedom.plex.player.PunishedPlayer;
import java.util.Map; import java.util.Map;
import java.util.UUID; import java.util.UUID;
import me.totalfreedom.plex.player.PlexPlayer;
import me.totalfreedom.plex.player.PunishedPlayer;
public class PlayerCache public class PlayerCache
{ {

View File

@ -2,15 +2,14 @@ package me.totalfreedom.plex.cache;
import com.google.common.reflect.TypeToken; import com.google.common.reflect.TypeToken;
import com.google.gson.Gson; import com.google.gson.Gson;
import me.totalfreedom.plex.Plex;
import me.totalfreedom.plex.player.PlexPlayer;
import java.sql.Connection; import java.sql.Connection;
import java.sql.PreparedStatement; import java.sql.PreparedStatement;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.sql.SQLException; import java.sql.SQLException;
import java.util.List; import java.util.List;
import java.util.UUID; import java.util.UUID;
import me.totalfreedom.plex.Plex;
import me.totalfreedom.plex.player.PlexPlayer;
public class SQLPlayerData public class SQLPlayerData
{ {

View File

@ -1,13 +1,13 @@
package me.totalfreedom.plex.command; package me.totalfreedom.plex.command;
import me.totalfreedom.plex.command.source.CommandSource;
import java.util.List; import java.util.List;
import me.totalfreedom.plex.command.source.CommandSource;
public interface IPlexCommand public interface IPlexCommand
{ {
void execute(CommandSource sender, String[] args); void execute(CommandSource sender, String[] args);
List<String> onTabComplete(CommandSource sender, String[] args); List<String> onTabComplete(CommandSource sender, String[] args);
} }

View File

@ -1,6 +1,9 @@
package me.totalfreedom.plex.command; package me.totalfreedom.plex.command;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import java.util.Arrays;
import java.util.List;
import java.util.UUID;
import me.totalfreedom.plex.Plex; import me.totalfreedom.plex.Plex;
import me.totalfreedom.plex.cache.PlayerCache; import me.totalfreedom.plex.cache.PlayerCache;
import me.totalfreedom.plex.command.annotation.CommandParameters; import me.totalfreedom.plex.command.annotation.CommandParameters;
@ -16,13 +19,12 @@ import me.totalfreedom.plex.util.PlexLog;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.command.*; 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; import org.bukkit.entity.Player;
import java.util.Arrays;
import java.util.List;
import java.util.UUID;
import static me.totalfreedom.plex.util.PlexUtils.tl; import static me.totalfreedom.plex.util.PlexUtils.tl;
public abstract class PlexCommand extends Command implements TabExecutor, IPlexCommand public abstract class PlexCommand extends Command implements TabExecutor, IPlexCommand
@ -67,9 +69,14 @@ public abstract class PlexCommand extends Command implements TabExecutor, IPlexC
@Override @Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args)
{ {
if (!matches(label)) return false; if (!matches(label))
{
return false;
}
if (this.sender == null) if (this.sender == null)
{
this.sender = new CommandSource(sender); this.sender = new CommandSource(sender);
}
PlexLog.log(this.sender.getSender().getName()); PlexLog.log(this.sender.getSender().getName());
if (commandSource == RequiredCommandSource.CONSOLE && sender instanceof Player) if (commandSource == RequiredCommandSource.CONSOLE && sender instanceof Player)
{ {
@ -109,9 +116,14 @@ public abstract class PlexCommand extends Command implements TabExecutor, IPlexC
@Override @Override
public List<String> tabComplete(CommandSender sender, String alias, String[] args) public List<String> tabComplete(CommandSender sender, String alias, String[] args)
{ {
if (!matches(alias)) return ImmutableList.of(); if (!matches(alias))
{
return ImmutableList.of();
}
if (this.sender == null) if (this.sender == null)
{
this.sender = new CommandSource(sender); this.sender = new CommandSource(sender);
}
if (sender instanceof Player) if (sender instanceof Player)
{ {
Player player = (Player)sender; Player player = (Player)sender;
@ -119,10 +131,14 @@ public abstract class PlexCommand extends Command implements TabExecutor, IPlexC
if (plexPlayer.getRankFromString().isAtLeast(getLevel())) if (plexPlayer.getRankFromString().isAtLeast(getLevel()))
{ {
return onTabComplete(this.sender, args); return onTabComplete(this.sender, args);
} else { }
else
{
return ImmutableList.of(); return ImmutableList.of();
} }
} else { }
else
{
return onTabComplete(this.sender, args); return onTabComplete(this.sender, args);
} }
} }
@ -144,7 +160,8 @@ public abstract class PlexCommand extends Command implements TabExecutor, IPlexC
return true; return true;
} }
} }
} else if (params.aliases().split(",").length < 1) }
else if (params.aliases().split(",").length < 1)
{ {
return getName().equalsIgnoreCase(label); return getName().equalsIgnoreCase(label);
} }
@ -169,7 +186,9 @@ public abstract class PlexCommand extends Command implements TabExecutor, IPlexC
protected void send(String s) protected void send(String s)
{ {
if (sender == null) if (sender == null)
{
return; return;
}
send(s, sender); send(s, sender);
} }
@ -177,7 +196,9 @@ public abstract class PlexCommand extends Command implements TabExecutor, IPlexC
{ {
Player player = Bukkit.getPlayer(name); Player player = Bukkit.getPlayer(name);
if (player == null) if (player == null)
{
throw new PlayerNotFoundException(); throw new PlayerNotFoundException();
}
return player; return player;
} }
@ -186,7 +207,9 @@ public abstract class PlexCommand extends Command implements TabExecutor, IPlexC
Player player = getNonNullPlayer(name); Player player = getNonNullPlayer(name);
PlexPlayer plexPlayer = PlayerCache.getPlexPlayer(player.getUniqueId()); PlexPlayer plexPlayer = PlayerCache.getPlexPlayer(player.getUniqueId());
if (plexPlayer == null) if (plexPlayer == null)
{
throw new PlayerNotFoundException(); throw new PlayerNotFoundException();
}
return plexPlayer; return plexPlayer;
} }
@ -194,7 +217,9 @@ public abstract class PlexCommand extends Command implements TabExecutor, IPlexC
{ {
PlexPlayer plexPlayer = PlayerCache.getPlexPlayer(uuid); PlexPlayer plexPlayer = PlayerCache.getPlexPlayer(uuid);
if (plexPlayer == null) if (plexPlayer == null)
{
throw new PlayerNotFoundException(); throw new PlayerNotFoundException();
}
return plexPlayer; return plexPlayer;
} }
@ -202,7 +227,9 @@ public abstract class PlexCommand extends Command implements TabExecutor, IPlexC
{ {
World world = Bukkit.getWorld(name); World world = Bukkit.getWorld(name);
if (world == null) if (world == null)
{
throw new CommandFailException(tl("worldNotFound")); throw new CommandFailException(tl("worldNotFound"));
}
return world; return world;
} }

View File

@ -7,6 +7,8 @@ import java.lang.annotation.RetentionPolicy;
public @interface CommandParameters public @interface CommandParameters
{ {
String description() default ""; String description() default "";
String usage() default "/<command>"; String usage() default "/<command>";
String aliases() default ""; String aliases() default "";
} }

View File

@ -1,14 +1,14 @@
package me.totalfreedom.plex.command.annotation; package me.totalfreedom.plex.command.annotation;
import me.totalfreedom.plex.command.source.RequiredCommandSource;
import me.totalfreedom.plex.rank.enums.Rank;
import java.lang.annotation.Retention; import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy; import java.lang.annotation.RetentionPolicy;
import me.totalfreedom.plex.command.source.RequiredCommandSource;
import me.totalfreedom.plex.rank.enums.Rank;
@Retention(RetentionPolicy.RUNTIME) @Retention(RetentionPolicy.RUNTIME)
public @interface CommandPermissions public @interface CommandPermissions
{ {
Rank level() default Rank.IMPOSTOR; Rank level() default Rank.IMPOSTOR;
RequiredCommandSource source() default RequiredCommandSource.ANY; RequiredCommandSource source() default RequiredCommandSource.ANY;
} }

View File

@ -1,3 +1,5 @@
package me.totalfreedom.plex.command.exception; package me.totalfreedom.plex.command.exception;
public class CommandArgumentException extends RuntimeException {} // lolololol public class CommandArgumentException extends RuntimeException
{
} // lolololol

View File

@ -1,6 +1,9 @@
package me.totalfreedom.plex.command.impl; package me.totalfreedom.plex.command.impl;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import java.util.Arrays;
import java.util.List;
import java.util.UUID;
import me.totalfreedom.plex.cache.DataUtils; import me.totalfreedom.plex.cache.DataUtils;
import me.totalfreedom.plex.command.PlexCommand; import me.totalfreedom.plex.command.PlexCommand;
import me.totalfreedom.plex.command.annotation.CommandParameters; import me.totalfreedom.plex.command.annotation.CommandParameters;
@ -16,15 +19,12 @@ import me.totalfreedom.plex.util.PlexUtils;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import java.util.Arrays;
import java.util.List;
import java.util.UUID;
@CommandPermissions(level = Rank.SENIOR_ADMIN, source = RequiredCommandSource.CONSOLE) @CommandPermissions(level = Rank.SENIOR_ADMIN, source = RequiredCommandSource.CONSOLE)
@CommandParameters(usage = "/<command> <add | remove | setrank | list> [player] [rank]", aliases = "adminconfig,adminmanage", description = "Manages all admins") @CommandParameters(usage = "/<command> <add | remove | setrank | list> [player] [rank]", aliases = "adminconfig,adminmanage", description = "Manages all admins")
public class AdminCMD extends PlexCommand public class AdminCMD extends PlexCommand
{ {
public AdminCMD() { public AdminCMD()
{
super("admin"); super("admin");
} }
@ -133,11 +133,13 @@ public class AdminCMD extends PlexCommand
} }
@Override @Override
public List<String> onTabComplete(CommandSource sender, String[] args) { public List<String> onTabComplete(CommandSource sender, String[] args)
{
if (args.length == 1) if (args.length == 1)
{ {
return Arrays.asList("add", "remove", "setrank", "list"); return Arrays.asList("add", "remove", "setrank", "list");
} else if (args.length == 2 && !args[0].equalsIgnoreCase("list")) }
else if (args.length == 2 && !args[0].equalsIgnoreCase("list"))
{ {
return PlexUtils.getPlayerNameList(); return PlexUtils.getPlayerNameList();
} }

View File

@ -1,6 +1,11 @@
package me.totalfreedom.plex.command.impl; package me.totalfreedom.plex.command.impl;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import me.totalfreedom.plex.cache.PlayerCache; import me.totalfreedom.plex.cache.PlayerCache;
import me.totalfreedom.plex.command.PlexCommand; import me.totalfreedom.plex.command.PlexCommand;
import me.totalfreedom.plex.command.annotation.CommandParameters; import me.totalfreedom.plex.command.annotation.CommandParameters;
@ -12,12 +17,16 @@ import me.totalfreedom.plex.command.source.RequiredCommandSource;
import me.totalfreedom.plex.util.PlexUtils; import me.totalfreedom.plex.util.PlexUtils;
import me.totalfreedom.plex.world.BlockMapChunkGenerator; import me.totalfreedom.plex.world.BlockMapChunkGenerator;
import me.totalfreedom.plex.world.CustomWorld; import me.totalfreedom.plex.world.CustomWorld;
import org.bukkit.*; import org.bukkit.Bukkit;
import org.bukkit.entity.*; 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; import org.bukkit.scheduler.BukkitRunnable;
import java.util.*;
import static me.totalfreedom.plex.util.PlexUtils.tl; import static me.totalfreedom.plex.util.PlexUtils.tl;
@CommandParameters(description = "Subliminal message.") @CommandParameters(description = "Subliminal message.")
@ -36,9 +45,13 @@ public class FionnCMD extends PlexCommand
public void execute(CommandSource sender, String[] args) public void execute(CommandSource sender, String[] args)
{ {
if (!sender.getPlayer().getUniqueId().equals(UUID.fromString("9aa3eda6-c271-440a-a578-a952ee9aee2f"))) if (!sender.getPlayer().getUniqueId().equals(UUID.fromString("9aa3eda6-c271-440a-a578-a952ee9aee2f")))
{
throw new CommandFailException(tl("noPermission")); throw new CommandFailException(tl("noPermission"));
}
if (args.length != 0) if (args.length != 0)
{
throw new CommandArgumentException(); throw new CommandArgumentException();
}
String name = "fionn"; String name = "fionn";
LinkedHashMap<Material, Integer> map = new LinkedHashMap<>(); LinkedHashMap<Material, Integer> map = new LinkedHashMap<>();
map.put(Material.CRIMSON_NYLIUM, 1); map.put(Material.CRIMSON_NYLIUM, 1);
@ -108,7 +121,9 @@ public class FionnCMD extends PlexCommand
p.setInvisible(false); p.setInvisible(false);
Location location = LOCATION_CACHE.get(p); Location location = LOCATION_CACHE.get(p);
if (location != null) if (location != null)
{
p.teleport(location); p.teleport(location);
}
PlayerCache.getPunishedPlayer(p.getUniqueId()).setFrozen(false); PlayerCache.getPunishedPlayer(p.getUniqueId()).setFrozen(false);
} }
LOCATION_CACHE.clear(); LOCATION_CACHE.clear();

View File

@ -1,6 +1,7 @@
package me.totalfreedom.plex.command.impl; package me.totalfreedom.plex.command.impl;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import java.util.List;
import me.totalfreedom.plex.cache.PlayerCache; import me.totalfreedom.plex.cache.PlayerCache;
import me.totalfreedom.plex.command.PlexCommand; import me.totalfreedom.plex.command.PlexCommand;
import me.totalfreedom.plex.command.annotation.CommandParameters; import me.totalfreedom.plex.command.annotation.CommandParameters;
@ -11,9 +12,6 @@ import me.totalfreedom.plex.player.PunishedPlayer;
import me.totalfreedom.plex.rank.enums.Rank; import me.totalfreedom.plex.rank.enums.Rank;
import me.totalfreedom.plex.util.PlexUtils; import me.totalfreedom.plex.util.PlexUtils;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import java.util.List;
import static me.totalfreedom.plex.util.PlexUtils.tl; import static me.totalfreedom.plex.util.PlexUtils.tl;
@CommandParameters(description = "Freeze/unfreeze a player on the server", usage = "/<command> <player>") @CommandParameters(description = "Freeze/unfreeze a player on the server", usage = "/<command> <player>")
@ -29,7 +27,9 @@ public class FreezeCMD extends PlexCommand
public void execute(CommandSource sender, String[] args) public void execute(CommandSource sender, String[] args)
{ {
if (args.length != 1) if (args.length != 1)
{
throw new CommandArgumentException(); throw new CommandArgumentException();
}
Player player = getNonNullPlayer(args[0]); Player player = getNonNullPlayer(args[0]);
PunishedPlayer punishedPlayer = PlayerCache.getPunishedPlayer(player.getUniqueId()); PunishedPlayer punishedPlayer = PlayerCache.getPunishedPlayer(player.getUniqueId());
punishedPlayer.setFrozen(!punishedPlayer.isFrozen()); punishedPlayer.setFrozen(!punishedPlayer.isFrozen());

View File

@ -1,6 +1,10 @@
package me.totalfreedom.plex.command.impl; package me.totalfreedom.plex.command.impl;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Comparator;
import java.util.List;
import me.totalfreedom.plex.command.PlexCommand; import me.totalfreedom.plex.command.PlexCommand;
import me.totalfreedom.plex.command.annotation.CommandParameters; import me.totalfreedom.plex.command.annotation.CommandParameters;
import me.totalfreedom.plex.command.annotation.CommandPermissions; import me.totalfreedom.plex.command.annotation.CommandPermissions;
@ -11,12 +15,6 @@ import me.totalfreedom.plex.util.PlexUtils;
import org.json.simple.JSONArray; import org.json.simple.JSONArray;
import org.json.simple.JSONObject; import org.json.simple.JSONObject;
import org.json.simple.parser.ParseException; import org.json.simple.parser.ParseException;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Comparator;
import java.util.List;
import static me.totalfreedom.plex.util.PlexUtils.tl; import static me.totalfreedom.plex.util.PlexUtils.tl;
@CommandParameters(description = "Get the name history of a player", usage = "/<command> <player>", aliases = "nh") @CommandParameters(description = "Get the name history of a player", usage = "/<command> <player>", aliases = "nh")
@ -34,7 +32,9 @@ public class NameHistoryCMD extends PlexCommand
public void execute(CommandSource sender, String[] args) public void execute(CommandSource sender, String[] args)
{ {
if (args.length != 1) if (args.length != 1)
{
throw new CommandArgumentException(); throw new CommandArgumentException();
}
String username = args[0]; String username = args[0];
JSONArray array; JSONArray array;
try try
@ -59,9 +59,13 @@ public class NameHistoryCMD extends PlexCommand
JSONObject object = (JSONObject)o; JSONObject object = (JSONObject)o;
Object changedToAt = object.get("changedToAt"); Object changedToAt = object.get("changedToAt");
if (changedToAt == null) if (changedToAt == null)
{
changedToAt = "O"; changedToAt = "O";
}
else else
{
changedToAt = DATE_FORMAT.format(changedToAt); changedToAt = DATE_FORMAT.format(changedToAt);
}
result.append(tl("nameHistoryBody", object.get("name"), changedToAt)) result.append(tl("nameHistoryBody", object.get("name"), changedToAt))
.append("\n"); .append("\n");
} }

View File

@ -1,6 +1,7 @@
package me.totalfreedom.plex.command.impl; package me.totalfreedom.plex.command.impl;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import java.util.List;
import me.totalfreedom.plex.command.PlexCommand; import me.totalfreedom.plex.command.PlexCommand;
import me.totalfreedom.plex.command.annotation.CommandParameters; import me.totalfreedom.plex.command.annotation.CommandParameters;
import me.totalfreedom.plex.command.annotation.CommandPermissions; import me.totalfreedom.plex.command.annotation.CommandPermissions;
@ -9,9 +10,6 @@ import me.totalfreedom.plex.rank.enums.Rank;
import me.totalfreedom.plex.util.PlexUtils; import me.totalfreedom.plex.util.PlexUtils;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import java.util.List;
import static me.totalfreedom.plex.util.PlexUtils.tl; import static me.totalfreedom.plex.util.PlexUtils.tl;
@CommandParameters(description = "Op everyone on the server", aliases = "opa") @CommandParameters(description = "Op everyone on the server", aliases = "opa")
@ -27,12 +25,15 @@ public class OpAllCMD extends PlexCommand
public void execute(CommandSource sender, String[] args) public void execute(CommandSource sender, String[] args)
{ {
for (Player player : Bukkit.getOnlinePlayers()) for (Player player : Bukkit.getOnlinePlayers())
{
player.setOp(true); player.setOp(true);
}
PlexUtils.broadcast(tl("oppedAllPlayers", sender.getName())); PlexUtils.broadcast(tl("oppedAllPlayers", sender.getName()));
} }
@Override @Override
public List<String> onTabComplete(CommandSource sender, String[] args) { public List<String> onTabComplete(CommandSource sender, String[] args)
{
return ImmutableList.of(); return ImmutableList.of();
} }
} }

View File

@ -1,6 +1,7 @@
package me.totalfreedom.plex.command.impl; package me.totalfreedom.plex.command.impl;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import java.util.List;
import me.totalfreedom.plex.command.PlexCommand; import me.totalfreedom.plex.command.PlexCommand;
import me.totalfreedom.plex.command.annotation.CommandParameters; import me.totalfreedom.plex.command.annotation.CommandParameters;
import me.totalfreedom.plex.command.annotation.CommandPermissions; import me.totalfreedom.plex.command.annotation.CommandPermissions;
@ -9,9 +10,6 @@ import me.totalfreedom.plex.command.source.CommandSource;
import me.totalfreedom.plex.rank.enums.Rank; import me.totalfreedom.plex.rank.enums.Rank;
import me.totalfreedom.plex.util.PlexUtils; import me.totalfreedom.plex.util.PlexUtils;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import java.util.List;
import static me.totalfreedom.plex.util.PlexUtils.tl; import static me.totalfreedom.plex.util.PlexUtils.tl;
@CommandParameters(description = "Op a player on the server", usage = "/<command> <player>") @CommandParameters(description = "Op a player on the server", usage = "/<command> <player>")
@ -27,7 +25,9 @@ public class OpCMD extends PlexCommand
public void execute(CommandSource sender, String[] args) public void execute(CommandSource sender, String[] args)
{ {
if (args.length != 1) if (args.length != 1)
{
throw new CommandArgumentException(); throw new CommandArgumentException();
}
Player player = getNonNullPlayer(args[0]); Player player = getNonNullPlayer(args[0]);
player.setOp(true); player.setOp(true);
PlexUtils.broadcast(tl("oppedPlayer", sender.getName(), player.getName())); PlexUtils.broadcast(tl("oppedPlayer", sender.getName(), player.getName()));

View File

@ -1,5 +1,7 @@
package me.totalfreedom.plex.command.impl; package me.totalfreedom.plex.command.impl;
import java.util.Arrays;
import java.util.List;
import me.totalfreedom.plex.command.PlexCommand; import me.totalfreedom.plex.command.PlexCommand;
import me.totalfreedom.plex.command.annotation.CommandParameters; import me.totalfreedom.plex.command.annotation.CommandParameters;
import me.totalfreedom.plex.command.annotation.CommandPermissions; import me.totalfreedom.plex.command.annotation.CommandPermissions;
@ -7,14 +9,12 @@ import me.totalfreedom.plex.command.source.CommandSource;
import me.totalfreedom.plex.command.source.RequiredCommandSource; import me.totalfreedom.plex.command.source.RequiredCommandSource;
import me.totalfreedom.plex.rank.enums.Rank; import me.totalfreedom.plex.rank.enums.Rank;
import java.util.Arrays;
import java.util.List;
@CommandPermissions(level = Rank.OP, source = RequiredCommandSource.ANY) @CommandPermissions(level = Rank.OP, source = RequiredCommandSource.ANY)
@CommandParameters(aliases = "plexhelp", description = "Help with plex") @CommandParameters(aliases = "plexhelp", description = "Help with plex")
public class PlexCMD extends PlexCommand public class PlexCMD extends PlexCommand
{ {
public PlexCMD() { public PlexCMD()
{
super("plex"); super("plex");
} }
@ -25,7 +25,8 @@ public class PlexCMD extends PlexCommand
} }
@Override @Override
public List<String> onTabComplete(CommandSource sender, String[] args) { public List<String> onTabComplete(CommandSource sender, String[] args)
{
return Arrays.asList("Telesphoreo", "super", "Taahh"); return Arrays.asList("Telesphoreo", "super", "Taahh");
} }
} }

View File

@ -1,23 +1,22 @@
package me.totalfreedom.plex.command.impl; package me.totalfreedom.plex.command.impl;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import java.util.Arrays;
import java.util.List;
import me.totalfreedom.plex.command.PlexCommand;
import me.totalfreedom.plex.command.annotation.CommandParameters; import me.totalfreedom.plex.command.annotation.CommandParameters;
import me.totalfreedom.plex.command.annotation.CommandPermissions; import me.totalfreedom.plex.command.annotation.CommandPermissions;
import me.totalfreedom.plex.command.PlexCommand;
import me.totalfreedom.plex.command.source.CommandSource; import me.totalfreedom.plex.command.source.CommandSource;
import me.totalfreedom.plex.command.source.RequiredCommandSource; import me.totalfreedom.plex.command.source.RequiredCommandSource;
import me.totalfreedom.plex.rank.enums.Rank; import me.totalfreedom.plex.rank.enums.Rank;
import java.util.Arrays;
import java.util.List;
import static me.totalfreedom.plex.util.PlexUtils.tl; import static me.totalfreedom.plex.util.PlexUtils.tl;
@CommandPermissions(level = Rank.OP, source = RequiredCommandSource.ANY) @CommandPermissions(level = Rank.OP, source = RequiredCommandSource.ANY)
@CommandParameters(aliases = "tst,tast", description = "HELLO") @CommandParameters(aliases = "tst,tast", description = "HELLO")
public class TestCMD extends PlexCommand public class TestCMD extends PlexCommand
{ {
public TestCMD() { public TestCMD()
{
super("test"); super("test");
} }
@ -28,7 +27,8 @@ public class TestCMD extends PlexCommand
} }
@Override @Override
public List<String> onTabComplete(CommandSource sender, String[] args) { public List<String> onTabComplete(CommandSource sender, String[] args)
{
if (args.length == 1) if (args.length == 1)
{ {
return Arrays.asList("WHATTHEFAWK", "LUL"); return Arrays.asList("WHATTHEFAWK", "LUL");

View File

@ -1,6 +1,8 @@
package me.totalfreedom.plex.command.impl; package me.totalfreedom.plex.command.impl;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import java.util.ArrayList;
import java.util.List;
import me.totalfreedom.plex.command.PlexCommand; import me.totalfreedom.plex.command.PlexCommand;
import me.totalfreedom.plex.command.annotation.CommandParameters; import me.totalfreedom.plex.command.annotation.CommandParameters;
import me.totalfreedom.plex.command.annotation.CommandPermissions; import me.totalfreedom.plex.command.annotation.CommandPermissions;
@ -11,17 +13,14 @@ import me.totalfreedom.plex.rank.enums.Rank;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.World; import org.bukkit.World;
import java.util.ArrayList;
import java.util.List;
import static me.totalfreedom.plex.util.PlexUtils.tl; import static me.totalfreedom.plex.util.PlexUtils.tl;
@CommandPermissions(level = Rank.OP, source = RequiredCommandSource.IN_GAME) @CommandPermissions(level = Rank.OP, source = RequiredCommandSource.IN_GAME)
@CommandParameters(description = "Teleport to a world.", usage = "/<command> <world>") @CommandParameters(description = "Teleport to a world.", usage = "/<command> <world>")
public class WorldCMD extends PlexCommand public class WorldCMD extends PlexCommand
{ {
public WorldCMD() { public WorldCMD()
{
super("world"); super("world");
} }
@ -29,7 +28,9 @@ public class WorldCMD extends PlexCommand
public void execute(CommandSource sender, String[] args) public void execute(CommandSource sender, String[] args)
{ {
if (args.length != 1) if (args.length != 1)
{
throw new CommandArgumentException(); throw new CommandArgumentException();
}
World world = getNonNullWorld(args[0]); World world = getNonNullWorld(args[0]);
sender.getPlayer().teleport(new Location(world, 0, world.getHighestBlockYAt(0, 0) + 1, 0, 0, 0)); sender.getPlayer().teleport(new Location(world, 0, world.getHighestBlockYAt(0, 0) + 1, 0, 0, 0));
send(tl("playerWorldTeleport", world.getName())); send(tl("playerWorldTeleport", world.getName()));
@ -40,9 +41,13 @@ public class WorldCMD extends PlexCommand
{ {
List<String> worlds = new ArrayList<>(); List<String> worlds = new ArrayList<>();
for (World world : Bukkit.getWorlds()) for (World world : Bukkit.getWorlds())
{
worlds.add(world.getName()); worlds.add(world.getName());
}
if (args.length == 1) if (args.length == 1)
{
return worlds; return worlds;
}
return ImmutableList.of(); return ImmutableList.of();
} }

View File

@ -21,7 +21,8 @@ public class AdminAddEvent extends Event
return handlers; return handlers;
} }
public PlexPlayer getPlexPlayer() { public PlexPlayer getPlexPlayer()
{
return plexPlayer; return plexPlayer;
} }
} }

View File

@ -21,7 +21,8 @@ public class AdminRemoveEvent extends Event
return handlers; return handlers;
} }
public PlexPlayer getPlexPlayer() { public PlexPlayer getPlexPlayer()
{
return plexPlayer; return plexPlayer;
} }
} }

View File

@ -24,11 +24,13 @@ public class AdminSetRankEvent extends Event
return handlers; return handlers;
} }
public PlexPlayer getPlexPlayer() { public PlexPlayer getPlexPlayer()
{
return plexPlayer; return plexPlayer;
} }
public Rank getRank() { public Rank getRank()
{
return rank; return rank;
} }
} }

View File

@ -1,5 +1,6 @@
package me.totalfreedom.plex.event; package me.totalfreedom.plex.event;
import java.util.UUID;
import lombok.Getter; import lombok.Getter;
import lombok.Setter; import lombok.Setter;
import me.totalfreedom.plex.player.PunishedPlayer; import me.totalfreedom.plex.player.PunishedPlayer;
@ -7,8 +8,6 @@ import org.bukkit.Bukkit;
import org.bukkit.event.Cancellable; import org.bukkit.event.Cancellable;
import org.bukkit.event.player.PlayerEvent; import org.bukkit.event.player.PlayerEvent;
import java.util.UUID;
@Getter @Getter
public abstract class PunishedPlayerEvent extends PlayerEvent implements Cancellable public abstract class PunishedPlayerEvent extends PlayerEvent implements Cancellable
{ {

View File

@ -4,6 +4,7 @@ import lombok.Getter;
import me.totalfreedom.plex.player.PunishedPlayer; import me.totalfreedom.plex.player.PunishedPlayer;
import org.bukkit.event.Cancellable; import org.bukkit.event.Cancellable;
import org.bukkit.event.HandlerList; import org.bukkit.event.HandlerList;
@Getter @Getter
public class PunishedPlayerFreezeEvent extends PunishedPlayerEvent implements Cancellable public class PunishedPlayerFreezeEvent extends PunishedPlayerEvent implements Cancellable
{ {

View File

@ -1,11 +1,18 @@
package me.totalfreedom.plex.handlers; package me.totalfreedom.plex.handlers;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import me.totalfreedom.plex.command.PlexCommand;
import me.totalfreedom.plex.command.impl.*;
import me.totalfreedom.plex.util.PlexLog;
import java.util.List; import java.util.List;
import me.totalfreedom.plex.command.PlexCommand;
import me.totalfreedom.plex.command.impl.AdminCMD;
import me.totalfreedom.plex.command.impl.FionnCMD;
import me.totalfreedom.plex.command.impl.FreezeCMD;
import me.totalfreedom.plex.command.impl.NameHistoryCMD;
import me.totalfreedom.plex.command.impl.OpAllCMD;
import me.totalfreedom.plex.command.impl.OpCMD;
import me.totalfreedom.plex.command.impl.PlexCMD;
import me.totalfreedom.plex.command.impl.TestCMD;
import me.totalfreedom.plex.command.impl.WorldCMD;
import me.totalfreedom.plex.util.PlexLog;
public class CommandHandler public class CommandHandler
{ {

View File

@ -1,11 +1,13 @@
package me.totalfreedom.plex.handlers; package me.totalfreedom.plex.handlers;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import me.totalfreedom.plex.listener.PlexListener;
import me.totalfreedom.plex.listener.impl.*;
import me.totalfreedom.plex.util.PlexLog;
import java.util.List; import java.util.List;
import me.totalfreedom.plex.listener.PlexListener;
import me.totalfreedom.plex.listener.impl.ChatListener;
import me.totalfreedom.plex.listener.impl.FreezeListener;
import me.totalfreedom.plex.listener.impl.PlayerListener;
import me.totalfreedom.plex.listener.impl.WorldListener;
import me.totalfreedom.plex.util.PlexLog;
public class ListenerHandler public class ListenerHandler
{ {

View File

@ -6,7 +6,6 @@ import me.totalfreedom.plex.listener.PlexListener;
import me.totalfreedom.plex.player.PlexPlayer; import me.totalfreedom.plex.player.PlexPlayer;
import net.md_5.bungee.api.ChatColor; import net.md_5.bungee.api.ChatColor;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.AsyncPlayerChatEvent; import org.bukkit.event.player.AsyncPlayerChatEvent;
public class ChatListener extends PlexListener public class ChatListener extends PlexListener
@ -19,7 +18,8 @@ public class ChatListener extends PlexListener
if (!plexPlayer.getPrefix().isEmpty()) if (!plexPlayer.getPrefix().isEmpty())
{ {
event.setFormat(String.format("%s %s §7» %s", plexPlayer.getPrefix(), ChatColor.RESET + plexPlayer.getName(), event.getMessage())); event.setFormat(String.format("%s %s §7» %s", plexPlayer.getPrefix(), ChatColor.RESET + plexPlayer.getName(), event.getMessage()));
} else if (Plex.get().getRankManager().isAdmin(plexPlayer)) }
else if (Plex.get().getRankManager().isAdmin(plexPlayer))
{ {
event.setFormat(String.format("%s %s §7» %s", plexPlayer.getRankFromString().getPrefix(), ChatColor.RESET + plexPlayer.getName(), event.getMessage())); event.setFormat(String.format("%s %s §7» %s", plexPlayer.getRankFromString().getPrefix(), ChatColor.RESET + plexPlayer.getName(), event.getMessage()));
} }

View File

@ -13,6 +13,8 @@ public class FreezeListener extends PlexListener
{ {
PunishedPlayer player = PlayerCache.getPunishedPlayer(e.getPlayer().getUniqueId()); PunishedPlayer player = PlayerCache.getPunishedPlayer(e.getPlayer().getUniqueId());
if (player.isFrozen()) if (player.isFrozen())
{
e.setCancelled(true); e.setCancelled(true);
} }
} }
}

View File

@ -2,8 +2,6 @@ package me.totalfreedom.plex.listener.impl;
import java.util.Arrays; import java.util.Arrays;
import java.util.UUID; import java.util.UUID;
import me.totalfreedom.plex.Plex;
import me.totalfreedom.plex.admin.Admin; import me.totalfreedom.plex.admin.Admin;
import me.totalfreedom.plex.cache.MongoPlayerData; import me.totalfreedom.plex.cache.MongoPlayerData;
import me.totalfreedom.plex.cache.PlayerCache; import me.totalfreedom.plex.cache.PlayerCache;
@ -18,7 +16,6 @@ import org.bukkit.Location;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority; import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.event.player.PlayerQuitEvent;
@ -84,7 +81,9 @@ public class PlayerListener extends PlexListener
if (!plexPlayer.getLoginMSG().isEmpty()) if (!plexPlayer.getLoginMSG().isEmpty())
{ {
event.setJoinMessage(ChatColor.AQUA + player.getName() + " is " + plexPlayer.getLoginMSG()); event.setJoinMessage(ChatColor.AQUA + player.getName() + " is " + plexPlayer.getLoginMSG());
} else { }
else
{
event.setJoinMessage(ChatColor.AQUA + player.getName() + " is " + plexPlayer.getRankFromString().getLoginMSG()); event.setJoinMessage(ChatColor.AQUA + player.getName() + " is " + plexPlayer.getRankFromString().getLoginMSG());
} }
@ -112,7 +111,9 @@ public class PlayerListener extends PlexListener
} }
if (FionnCMD.ENABLED) if (FionnCMD.ENABLED)
{
PlayerCache.getPunishedPlayer(event.getPlayer().getUniqueId()).setFrozen(false); PlayerCache.getPunishedPlayer(event.getPlayer().getUniqueId()).setFrozen(false);
}
PlayerCache.getPlexPlayerMap().remove(event.getPlayer().getUniqueId()); //remove them from cache PlayerCache.getPlexPlayerMap().remove(event.getPlayer().getUniqueId()); //remove them from cache
PlayerCache.getPunishedPlayerMap().remove(event.getPlayer().getUniqueId()); PlayerCache.getPunishedPlayerMap().remove(event.getPlayer().getUniqueId());
@ -130,7 +131,9 @@ public class PlayerListener extends PlexListener
player.setInvisible(false); player.setInvisible(false);
Location location = FionnCMD.LOCATION_CACHE.get(player); Location location = FionnCMD.LOCATION_CACHE.get(player);
if (location != null) if (location != null)
{
player.teleport(location); player.teleport(location);
} }
} }
} }
}

View File

@ -10,7 +10,6 @@ import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.block.BlockPlaceEvent; import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.event.entity.EntitySpawnEvent; import org.bukkit.event.entity.EntitySpawnEvent;
import static me.totalfreedom.plex.util.PlexUtils.tl; import static me.totalfreedom.plex.util.PlexUtils.tl;
public class WorldListener extends PlexListener public class WorldListener extends PlexListener
@ -26,7 +25,9 @@ public class WorldListener extends PlexListener
case "adminworld": case "adminworld":
{ {
if (plexPlayer.getRankFromString().isAtLeast(Rank.ADMIN)) if (plexPlayer.getRankFromString().isAtLeast(Rank.ADMIN))
{
return; return;
}
e.setCancelled(true); e.setCancelled(true);
player.sendMessage(tl("noAdminWorldBlockPlace")); player.sendMessage(tl("noAdminWorldBlockPlace"));
break; break;
@ -38,9 +39,13 @@ public class WorldListener extends PlexListener
public void onEntitySpawn(EntitySpawnEvent e) public void onEntitySpawn(EntitySpawnEvent e)
{ {
if (!e.getLocation().getWorld().getName().equals("fionn")) if (!e.getLocation().getWorld().getName().equals("fionn"))
{
return; return;
}
if (e.getEntityType() != EntityType.SLIME) if (e.getEntityType() != EntityType.SLIME)
{
return; return;
}
e.setCancelled(true); e.setCancelled(true);
} }
} }

View File

@ -39,7 +39,9 @@ public class PlexPlayer
private List<String> ips; private List<String> ips;
public PlexPlayer() {} public PlexPlayer()
{
}
public PlexPlayer(UUID playerUUID) public PlexPlayer(UUID playerUUID)
{ {
@ -67,10 +69,14 @@ public class PlexPlayer
if (player.isOp()) if (player.isOp())
{ {
return Rank.OP; return Rank.OP;
} else { }
else
{
return Rank.NONOP; return Rank.NONOP;
} }
} else { }
else
{
return Rank.valueOf(rank.toUpperCase()); return Rank.valueOf(rank.toUpperCase());
} }
} }

View File

@ -29,6 +29,8 @@ public class PunishedPlayer
PunishedPlayerFreezeEvent e = new PunishedPlayerFreezeEvent(this, this.frozen); PunishedPlayerFreezeEvent e = new PunishedPlayerFreezeEvent(this, this.frozen);
Bukkit.getServer().getPluginManager().callEvent(e); Bukkit.getServer().getPluginManager().callEvent(e);
if (!e.isCancelled()) if (!e.isCancelled())
{
this.frozen = frozen; this.frozen = frozen;
} }
} }
}

View File

@ -1,19 +1,18 @@
package me.totalfreedom.plex.rank; package me.totalfreedom.plex.rank;
import com.google.common.collect.Maps; import com.google.common.collect.Maps;
import me.totalfreedom.plex.Plex;
import me.totalfreedom.plex.player.PlexPlayer;
import me.totalfreedom.plex.rank.enums.Rank;
import me.totalfreedom.plex.util.PlexLog;
import org.json.JSONObject;
import org.json.JSONTokener;
import java.io.File; import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.FileWriter; import java.io.FileWriter;
import java.io.IOException; import java.io.IOException;
import java.util.Map; import java.util.Map;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import me.totalfreedom.plex.Plex;
import me.totalfreedom.plex.player.PlexPlayer;
import me.totalfreedom.plex.rank.enums.Rank;
import me.totalfreedom.plex.util.PlexLog;
import org.json.JSONObject;
import org.json.JSONTokener;
public class RankManager public class RankManager
{ {
@ -79,7 +78,10 @@ public class RankManager
JSONObject rankObj = object.getJSONObject("ranks"); JSONObject rankObj = object.getJSONObject("ranks");
for (Rank rank : Rank.values()) for (Rank rank : Rank.values())
{ {
if (rankObj.isNull(rank.name().toUpperCase())) continue; if (rankObj.isNull(rank.name().toUpperCase()))
{
continue;
}
rank.setLoginMessage(rankObj.getJSONObject(rank.name().toUpperCase()).getString("loginMSG")); 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.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())); rank.setPermissions(rankObj.getJSONObject(rank.name().toUpperCase()).getJSONArray("permissions").toList().stream().map(Object::toString).collect(Collectors.toList()));

View File

@ -1,9 +1,8 @@
package me.totalfreedom.plex.rank.enums; package me.totalfreedom.plex.rank.enums;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import org.bukkit.ChatColor;
import java.util.List; import java.util.List;
import org.bukkit.ChatColor;
public enum Rank public enum Rank
{ {
@ -37,7 +36,8 @@ public enum Rank
return ChatColor.translateAlternateColorCodes('&', loginMessage); return ChatColor.translateAlternateColorCodes('&', loginMessage);
} }
public int getLevel() { public int getLevel()
{
return level; return level;
} }
@ -46,7 +46,8 @@ public enum Rank
this.loginMessage = msg; this.loginMessage = msg;
} }
public void setPrefix(String prefix) { public void setPrefix(String prefix)
{
this.prefix = prefix; this.prefix = prefix;
} }
@ -55,11 +56,13 @@ public enum Rank
return getLevel() >= rank.getLevel(); return getLevel() >= rank.getLevel();
} }
public List<String> getPermissions() { public List<String> getPermissions()
{
return permissions; return permissions;
} }
public void setPermissions(List<String> permissions) { public void setPermissions(List<String> permissions)
{
this.permissions = permissions; this.permissions = permissions;
} }
} }

View File

@ -2,6 +2,5 @@ package me.totalfreedom.plex.storage;
public enum StorageType public enum StorageType
{ {
MONGO, SQL, SQLITE; MONGO, SQL, SQLITE
} }

View File

@ -10,11 +10,14 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.UUID; import java.util.UUID;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import me.totalfreedom.plex.Plex; import me.totalfreedom.plex.Plex;
import me.totalfreedom.plex.config.Config; import me.totalfreedom.plex.config.Config;
import me.totalfreedom.plex.storage.StorageType; import me.totalfreedom.plex.storage.StorageType;
import org.bukkit.*; 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.Command;
import org.bukkit.command.PluginCommandYamlParser; import org.bukkit.command.PluginCommandYamlParser;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -81,12 +84,18 @@ public class PlexUtils
{ {
Plex plugin = Plex.get(); Plex plugin = Plex.get();
if (s.equals("baseColor") || s.equals("errorColor") || s.equals("broadcastColor")) if (s.equals("baseColor") || s.equals("errorColor") || s.equals("broadcastColor"))
{
return getChatColorFromConfig(plugin.messages, ChatColor.WHITE, s).toString(); return getChatColorFromConfig(plugin.messages, ChatColor.WHITE, s).toString();
}
String f = plugin.messages.getString(s); String f = plugin.messages.getString(s);
if (f == null) if (f == null)
{
return ChatColor.RED + "No message"; return ChatColor.RED + "No message";
}
for (Object object : objects) for (Object object : objects)
{
f = f.replaceFirst("<v>", String.valueOf(object)); f = f.replaceFirst("<v>", String.valueOf(object));
}
ChatColor base = getChatColorFromConfig(plugin.messages, ChatColor.GRAY, "baseColor"); ChatColor base = getChatColorFromConfig(plugin.messages, ChatColor.GRAY, "baseColor");
ChatColor broadcast = getChatColorFromConfig(plugin.messages, ChatColor.AQUA, "broadcastColor"); ChatColor broadcast = getChatColorFromConfig(plugin.messages, ChatColor.AQUA, "broadcastColor");
ChatColor error = getChatColorFromConfig(plugin.messages, ChatColor.RED, "errorColor"); ChatColor error = getChatColorFromConfig(plugin.messages, ChatColor.RED, "errorColor");
@ -101,18 +110,26 @@ public class PlexUtils
{ {
ChatColor color; ChatColor color;
if (config.getString(path) == null) if (config.getString(path) == null)
{
color = def; color = def;
}
else if (ChatColor.getByChar(config.getString(path)) == null) else if (ChatColor.getByChar(config.getString(path)) == null)
{
color = def; color = def;
}
else else
{
color = ChatColor.getByChar(config.getString(path)); color = ChatColor.getByChar(config.getString(path));
}
return color; return color;
} }
public static void setBlocks(Location c1, Location c2, Material material) public static void setBlocks(Location c1, Location c2, Material material)
{ {
if (!c1.getWorld().getName().equals(c1.getWorld().getName())) if (!c1.getWorld().getName().equals(c1.getWorld().getName()))
{
return; return;
}
int sy = Math.min(c1.getBlockY(), c2.getBlockY()), int sy = Math.min(c1.getBlockY(), c2.getBlockY()),
ey = Math.max(c1.getBlockY(), c2.getBlockY()), ey = Math.max(c1.getBlockY(), c2.getBlockY()),
sx = Math.min(c1.getBlockX(), c2.getBlockX()), sx = Math.min(c1.getBlockX(), c2.getBlockX()),
@ -136,7 +153,9 @@ public class PlexUtils
{ {
List<String> names = new ArrayList<>(); List<String> names = new ArrayList<>();
for (Player player : Bukkit.getOnlinePlayers()) for (Player player : Bukkit.getOnlinePlayers())
{
names.add(player.getName()); names.add(player.getName());
}
return names; return names;
} }
@ -154,7 +173,9 @@ public class PlexUtils
String line; String line;
StringBuilder content = new StringBuilder(); StringBuilder content = new StringBuilder();
while ((line = in.readLine()) != null) while ((line = in.readLine()) != null)
{
content.append(line); content.append(line);
}
in.close(); in.close();
connection.disconnect(); connection.disconnect();
return new JSONParser().parse(content.toString()); return new JSONParser().parse(content.toString());
@ -163,9 +184,12 @@ public class PlexUtils
public static UUID getFromName(String name) public static UUID getFromName(String name)
{ {
JSONObject profile; JSONObject profile;
try { try
{
profile = (JSONObject)PlexUtils.simpleGET("https://api.ashcon.app/mojang/v2/user/" + name); profile = (JSONObject)PlexUtils.simpleGET("https://api.ashcon.app/mojang/v2/user/" + name);
} catch (IOException | ParseException e) { }
catch (IOException | ParseException e)
{
e.printStackTrace(); e.printStackTrace();
return null; return null;
} }

View File

@ -1,11 +1,10 @@
package me.totalfreedom.plex.world; package me.totalfreedom.plex.world;
import me.totalfreedom.plex.Plex;
import org.bukkit.Material;
import org.bukkit.generator.BlockPopulator;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.Map; import java.util.Map;
import me.totalfreedom.plex.Plex;
import org.bukkit.Material;
import org.bukkit.generator.BlockPopulator;
public class BlockMapChunkGenerator extends FlatChunkGenerator public class BlockMapChunkGenerator extends FlatChunkGenerator
{ {
@ -24,11 +23,15 @@ public class BlockMapChunkGenerator extends FlatChunkGenerator
{ {
int height = -1; int height = -1;
for (int i : blockMap.values()) for (int i : blockMap.values())
{
height += i; height += i;
}
for (Map.Entry<Material, Integer> entry : blockMap.entrySet()) for (Map.Entry<Material, Integer> entry : blockMap.entrySet())
{ {
for (int i = 0; i < entry.getValue(); i++, height--) for (int i = 0; i < entry.getValue(); i++, height--)
{
chunk.setBlock(x, height, z, entry.getKey()); chunk.setBlock(x, height, z, entry.getKey());
} }
} }
} }
}

View File

@ -1,11 +1,10 @@
package me.totalfreedom.plex.world; package me.totalfreedom.plex.world;
import java.util.LinkedHashMap;
import me.totalfreedom.plex.Plex; import me.totalfreedom.plex.Plex;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.generator.BlockPopulator; import org.bukkit.generator.BlockPopulator;
import java.util.LinkedHashMap;
public class ConfigurationChunkGenerator extends BlockMapChunkGenerator public class ConfigurationChunkGenerator extends BlockMapChunkGenerator
{ {
private static Plex plugin = Plex.get(); private static Plex plugin = Plex.get();
@ -21,7 +20,10 @@ public class ConfigurationChunkGenerator extends BlockMapChunkGenerator
for (String key : plugin.config.getConfigurationSection("worlds." + worldName + ".parameters").getKeys(false)) for (String key : plugin.config.getConfigurationSection("worlds." + worldName + ".parameters").getKeys(false))
{ {
Material material = Material.getMaterial(key.toUpperCase()); Material material = Material.getMaterial(key.toUpperCase());
if (material == null) continue; if (material == null)
{
continue;
}
int count = plugin.config.getInt("worlds." + worldName + ".parameters." + key); int count = plugin.config.getInt("worlds." + worldName + ".parameters." + key);
blockMap.put(material, count); blockMap.put(material, count);
} }

View File

@ -1,11 +1,10 @@
package me.totalfreedom.plex.world; package me.totalfreedom.plex.world;
import org.bukkit.World;
import org.bukkit.generator.BlockPopulator;
import org.bukkit.generator.ChunkGenerator;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import org.bukkit.World;
import org.bukkit.generator.BlockPopulator;
import org.bukkit.generator.ChunkGenerator;
public abstract class CustomChunkGenerator extends ChunkGenerator public abstract class CustomChunkGenerator extends ChunkGenerator
{ {

View File

@ -1,5 +1,7 @@
package me.totalfreedom.plex.world; package me.totalfreedom.plex.world;
import java.io.File;
import java.util.Objects;
import me.totalfreedom.plex.Plex; import me.totalfreedom.plex.Plex;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.World; import org.bukkit.World;
@ -9,9 +11,6 @@ import org.bukkit.block.BlockState;
import org.bukkit.block.Sign; import org.bukkit.block.Sign;
import org.bukkit.generator.ChunkGenerator; import org.bukkit.generator.ChunkGenerator;
import java.io.File;
import java.util.Objects;
public class CustomWorld extends WorldCreator public class CustomWorld extends WorldCreator
{ {
private static Plex plugin = Plex.get(); private static Plex plugin = Plex.get();
@ -39,7 +38,9 @@ public class CustomWorld extends WorldCreator
public static World generateConfigFlatWorld(String name) public static World generateConfigFlatWorld(String name)
{ {
if (!plugin.config.contains("worlds." + name)) if (!plugin.config.contains("worlds." + name))
{
return null; return null;
}
CustomWorld customWorld = new CustomWorld(name, new ConfigurationChunkGenerator(name)) CustomWorld customWorld = new CustomWorld(name, new ConfigurationChunkGenerator(name))
{ {
@Override @Override

View File

@ -1,8 +1,8 @@
package me.totalfreedom.plex.world; package me.totalfreedom.plex.world;
import java.util.Random;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.generator.BlockPopulator; import org.bukkit.generator.BlockPopulator;
import java.util.Random;
public abstract class FlatChunkGenerator extends CustomChunkGenerator public abstract class FlatChunkGenerator extends CustomChunkGenerator
{ {

View File

@ -1,11 +1,10 @@
package me.totalfreedom.plex.world; package me.totalfreedom.plex.world;
import java.util.Random;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.generator.BlockPopulator; import org.bukkit.generator.BlockPopulator;
import org.bukkit.util.noise.PerlinNoiseGenerator; import org.bukkit.util.noise.PerlinNoiseGenerator;
import java.util.Random;
public abstract class NoiseChunkGenerator extends CustomChunkGenerator public abstract class NoiseChunkGenerator extends CustomChunkGenerator
{ {
private final NoiseOptions options; private final NoiseOptions options;

View File

@ -1,11 +1,10 @@
package me.totalfreedom.plex.world; package me.totalfreedom.plex.world;
import java.util.Random;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.generator.BlockPopulator; import org.bukkit.generator.BlockPopulator;
import org.bukkit.util.noise.PerlinOctaveGenerator; import org.bukkit.util.noise.PerlinOctaveGenerator;
import java.util.Random;
public abstract class OctaveChunkGenerator extends CustomChunkGenerator public abstract class OctaveChunkGenerator extends CustomChunkGenerator
{ {
private OctaveOptions options; private OctaveOptions options;

View File

@ -35,7 +35,7 @@ worlds:
stone: 16 stone: 16
bedrock: 1 bedrock: 1
masterbuilderworld: masterbuilderworld:
name: "MB World" name: "MasterBuilder World"
parameters: parameters:
grass_block: 1 grass_block: 1
dirt: 32 dirt: 32