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

@ -1,16 +1,16 @@
name: Java CI name: Java CI
on: [push] on: [ push ]
jobs: jobs:
build: build:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: actions/checkout@v1 - uses: actions/checkout@v1
- name: Set up JDK 11 - name: Set up JDK 11
uses: actions/setup-java@v1 uses: actions/setup-java@v1
with: with:
java-version: 11 java-version: 11
- name: Build with Maven - name: Build with Maven
run: mvn -B package --file pom.xml run: mvn -B package --file pom.xml

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)
{ {
@ -83,7 +90,7 @@ public abstract class PlexCommand extends Command implements TabExecutor, IPlexC
sender.sendMessage(tl("noPermissionConsole")); sender.sendMessage(tl("noPermissionConsole"));
return true; return true;
} }
Player player = (Player) sender; Player player = (Player)sender;
PlexPlayer plexPlayer = PlayerCache.getPlexPlayerMap().get(player.getUniqueId()); PlexPlayer plexPlayer = PlayerCache.getPlexPlayerMap().get(player.getUniqueId());
if (!plexPlayer.getRankFromString().isAtLeast(getLevel())) if (!plexPlayer.getRankFromString().isAtLeast(getLevel()))
{ {
@ -109,20 +116,29 @@ 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;
PlexPlayer plexPlayer = PlayerCache.getPlexPlayerMap().get(player.getUniqueId()); PlexPlayer plexPlayer = PlayerCache.getPlexPlayerMap().get(player.getUniqueId());
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);
@ -47,11 +60,11 @@ public class FionnCMD extends PlexCommand
ENABLED = true; ENABLED = true;
fionnWorld.setTime(0); fionnWorld.setTime(0);
fionnWorld.getBlockAt(0, 5, 0).setType(Material.BARRIER); fionnWorld.getBlockAt(0, 5, 0).setType(Material.BARRIER);
Strider fionn = (Strider) fionnWorld.spawnEntity(new Location(fionnWorld, 12, 6, 6, -180, -3), EntityType.STRIDER); Strider fionn = (Strider)fionnWorld.spawnEntity(new Location(fionnWorld, 12, 6, 6, -180, -3), EntityType.STRIDER);
fionn.setCustomNameVisible(true); fionn.setCustomNameVisible(true);
fionn.setCustomName(ChatColor.GREEN + "fionn"); fionn.setCustomName(ChatColor.GREEN + "fionn");
fionn.setAI(false); fionn.setAI(false);
Enderman elmon = (Enderman) fionnWorld.spawnEntity(new Location(fionnWorld, 12, 6, 0, 0, 18), EntityType.ENDERMAN); Enderman elmon = (Enderman)fionnWorld.spawnEntity(new Location(fionnWorld, 12, 6, 0, 0, 18), EntityType.ENDERMAN);
elmon.setCustomNameVisible(true); elmon.setCustomNameVisible(true);
elmon.setCustomName(ChatColor.RED + "elmon"); elmon.setCustomName(ChatColor.RED + "elmon");
elmon.setInvulnerable(true); elmon.setInvulnerable(true);
@ -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,14 +32,16 @@ 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
{ {
JSONObject profile = (JSONObject) PlexUtils.simpleGET("https://api.mojang.com/users/profiles/minecraft/" + username); JSONObject profile = (JSONObject)PlexUtils.simpleGET("https://api.mojang.com/users/profiles/minecraft/" + username);
String uuid = (String) profile.get("id"); String uuid = (String)profile.get("id");
array = (JSONArray) PlexUtils.simpleGET("https://api.mojang.com/user/profiles/" + uuid + "/names"); array = (JSONArray)PlexUtils.simpleGET("https://api.mojang.com/user/profiles/" + uuid + "/names");
} }
catch (ParseException | IOException ex) catch (ParseException | IOException ex)
{ {
@ -56,14 +56,18 @@ public class NameHistoryCMD extends PlexCommand
.append("\n"); .append("\n");
for (Object o : array) for (Object o : array)
{ {
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");
} }
send(result.toString()); send(result.toString());
} }

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

@ -18,7 +18,7 @@ public class CommandSource
{ {
this.sender = sender; this.sender = sender;
this.player = sender instanceof Player ? Bukkit.getPlayer(sender.getName()) : null; this.player = sender instanceof Player ? Bukkit.getPlayer(sender.getName()) : null;
this.plexPlayer = sender instanceof Player ? PlayerCache.getPlexPlayerMap().get(((Player) sender).getUniqueId()) : null; this.plexPlayer = sender instanceof Player ? PlayerCache.getPlexPlayerMap().get(((Player)sender).getUniqueId()) : null;
} }
public void send(String s) public void send(String s)

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;
@ -28,7 +25,7 @@ public class PlayerListener extends PlexListener
private final SQLPlayerData sqlPlayerData = plugin.getSqlPlayerData() != null ? plugin.getSqlPlayerData() : null; private final SQLPlayerData sqlPlayerData = plugin.getSqlPlayerData() != null ? plugin.getSqlPlayerData() : null;
// setting up a player's data // setting up a player's data
@EventHandler(priority = EventPriority.HIGHEST) @EventHandler(priority = EventPriority.HIGHEST)
public void onPlayerSetup(PlayerJoinEvent event) public void onPlayerSetup(PlayerJoinEvent event)
{ {
Player player = event.getPlayer(); Player player = event.getPlayer();
@ -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
{ {
@ -15,7 +14,7 @@ public enum Rank
EXECUTIVE(4, ChatColor.RED + "an " + ChatColor.RED + "Executive", ChatColor.RED + "[Exec]"); EXECUTIVE(4, ChatColor.RED + "an " + ChatColor.RED + "Executive", ChatColor.RED + "[Exec]");
private String loginMessage; private String loginMessage;
private String prefix; private String prefix;
private int level; private int level;
private List<String> permissions; private List<String> permissions;
@ -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,24 +110,32 @@ 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()),
ex = Math.max(c1.getBlockX(), c2.getBlockX()), ex = Math.max(c1.getBlockX(), c2.getBlockX()),
sz = Math.min(c1.getBlockZ(), c2.getBlockZ()), sz = Math.min(c1.getBlockZ(), c2.getBlockZ()),
ez = Math.max(c1.getBlockZ(), c2.getBlockZ()); ez = Math.max(c1.getBlockZ(), c2.getBlockZ());
World world = c1.getWorld(); World world = c1.getWorld();
for (int y = sy; y <= ey; y++) for (int y = sy; y <= ey; y++)
{ {
@ -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;
} }
@ -148,13 +167,15 @@ public class PlexUtils
public static Object simpleGET(String url) throws IOException, ParseException public static Object simpleGET(String url) throws IOException, ParseException
{ {
URL u = new URL(url); URL u = new URL(url);
HttpURLConnection connection = (HttpURLConnection) u.openConnection(); HttpURLConnection connection = (HttpURLConnection)u.openConnection();
connection.setRequestMethod("GET"); connection.setRequestMethod("GET");
BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream())); BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
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,13 +184,16 @@ 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); {
} catch (IOException | ParseException e) { profile = (JSONObject)PlexUtils.simpleGET("https://api.ashcon.app/mojang/v2/user/" + name);
}
catch (IOException | ParseException e)
{
e.printStackTrace(); e.printStackTrace();
return null; return null;
} }
String uuidString = (String) profile.get("uuid"); String uuidString = (String)profile.get("uuid");
return UUID.fromString(uuidString); return UUID.fromString(uuidString);
} }
} }

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
@ -54,7 +55,7 @@ public class CustomWorld extends WorldCreator
BlockState state = block.getState(); BlockState state = block.getState();
if (state instanceof Sign) if (state instanceof Sign)
{ {
Sign sign = (Sign) state; Sign sign = (Sign)state;
sign.setLine(1, Objects.requireNonNull(plugin.config.getString("worlds." + name + ".name"))); sign.setLine(1, Objects.requireNonNull(plugin.config.getString("worlds." + name + ".name")));
sign.setLine(2, "- 0, 0 -"); sign.setLine(2, "- 0, 0 -");
sign.update(); sign.update();

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;
@ -25,7 +24,7 @@ public abstract class NoiseChunkGenerator extends CustomChunkGenerator
{ {
for (int zz = 0; zz < 16; zz++) for (int zz = 0; zz < 16; zz++)
{ {
height = (int) generator.noise(options.getX(), options.getY(), options.getFrequency(), options.getAmplitude(), options.isNormalized()); height = (int)generator.noise(options.getX(), options.getY(), options.getFrequency(), options.getAmplitude(), options.isNormalized());
createLoopChunkData(xx, height, zz, chunk); createLoopChunkData(xx, height, zz, chunk);
} }
} }

View File

@ -1,16 +1,15 @@
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;
public OctaveChunkGenerator(int height, OctaveOptions options, BlockPopulator... populators) public OctaveChunkGenerator(int height, OctaveOptions options, BlockPopulator... populators)
{ {
super(height, populators); super(height, populators);
this.options = options; this.options = options;
@ -25,7 +24,7 @@ public abstract class OctaveChunkGenerator extends CustomChunkGenerator
{ {
for (int zz = 0; zz < 16; zz++) for (int zz = 0; zz < 16; zz++)
{ {
height = (int) generator.noise(options.getX(), options.getY(), options.getFrequency(), options.getAmplitude(), options.isNormalized()); height = (int)generator.noise(options.getX(), options.getY(), options.getFrequency(), options.getAmplitude(), options.isNormalized());
createLoopChunkData(xx, height, zz, chunk); createLoopChunkData(xx, height, zz, chunk);
} }
} }

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