mirror of
https://github.com/plexusorg/Plex.git
synced 2024-12-28 02:54:17 +00:00
Code cleanup
This commit is contained in:
parent
d4761d4386
commit
4a05d90c17
25 changed files with 191 additions and 97 deletions
2
.github/workflows/gradle.yml
vendored
2
.github/workflows/gradle.yml
vendored
|
@ -1,6 +1,6 @@
|
|||
name: Gradle
|
||||
|
||||
on: [push]
|
||||
on: [ push ]
|
||||
|
||||
jobs:
|
||||
build:
|
||||
|
|
|
@ -1,2 +1,3 @@
|
|||
# Plex
|
||||
|
||||
A new freedom plugin.
|
||||
|
|
6
src/main/java/dev/plex/cache/DataUtils.java
vendored
6
src/main/java/dev/plex/cache/DataUtils.java
vendored
|
@ -8,7 +8,7 @@ import org.bukkit.Bukkit;
|
|||
|
||||
public class DataUtils
|
||||
{
|
||||
/* PLEX PLAYER METHODS */
|
||||
/* PLEX PLAYER METHODS */
|
||||
|
||||
public static boolean hasPlayedBefore(UUID uuid)
|
||||
{
|
||||
|
@ -61,7 +61,9 @@ public class DataUtils
|
|||
if (Plex.get().getStorageType() == StorageType.MONGODB)
|
||||
{
|
||||
Plex.get().getMongoPlayerData().save(plexPlayer);
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
Plex.get().getSqlPlayerData().insert(plexPlayer);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -54,7 +54,9 @@ public class SQLPlayerData
|
|||
String rankName = set.getString("rank").toUpperCase();
|
||||
long coins = set.getLong("coins");
|
||||
boolean vanished = set.getBoolean("vanished");
|
||||
List<String> ips = new Gson().fromJson(set.getString("ips"), new TypeToken<List<String>>(){}.getType());
|
||||
List<String> ips = new Gson().fromJson(set.getString("ips"), new TypeToken<List<String>>()
|
||||
{
|
||||
}.getType());
|
||||
plexPlayer.setName(name);
|
||||
plexPlayer.setLoginMSG(loginMSG);
|
||||
plexPlayer.setPrefix(prefix);
|
||||
|
|
|
@ -5,6 +5,7 @@ import dev.plex.rank.enums.Rank;
|
|||
public @interface CheckPermission
|
||||
{
|
||||
String permission() default "";
|
||||
|
||||
Rank rank() default Rank.IMPOSTOR;
|
||||
|
||||
}
|
||||
|
|
|
@ -24,7 +24,7 @@ public class AdventureCMD extends PlexCommand
|
|||
@Override
|
||||
public Component execute(CommandSender sender, String[] args)
|
||||
{
|
||||
Player player = (Player) sender;
|
||||
Player player = (Player)sender;
|
||||
if (args.length == 0)
|
||||
{
|
||||
if (isConsole(sender))
|
||||
|
|
|
@ -51,7 +51,7 @@ public class BanCMD extends PlexCommand
|
|||
{
|
||||
if (!isConsole(sender))
|
||||
{
|
||||
PlexPlayer plexPlayer1 = getPlexPlayer((Player) sender);
|
||||
PlexPlayer plexPlayer1 = getPlexPlayer((Player)sender);
|
||||
if (!plexPlayer1.getRankFromString().isAtLeast(plexPlayer.getRankFromString()))
|
||||
{
|
||||
return tl("higherRankThanYou");
|
||||
|
|
|
@ -23,7 +23,7 @@ public class CreativeCMD extends PlexCommand
|
|||
@Override
|
||||
public Component execute(CommandSender sender, String[] args)
|
||||
{
|
||||
Player player = (Player) sender;
|
||||
Player player = (Player)sender;
|
||||
if (args.length == 0)
|
||||
{
|
||||
if (isConsole(sender))
|
||||
|
|
|
@ -44,7 +44,8 @@ public class NameHistoryCMD extends PlexCommand
|
|||
if (offlinePlayer != null)
|
||||
{
|
||||
uuid = offlinePlayer.getUniqueId();
|
||||
} else
|
||||
}
|
||||
else
|
||||
{
|
||||
uuid = MojangUtils.getUUID(username);
|
||||
}
|
||||
|
@ -68,7 +69,8 @@ public class NameHistoryCMD extends PlexCommand
|
|||
.append(Component.text("-").color(NamedTextColor.DARK_GRAY))
|
||||
.append(Component.space())
|
||||
.append(Component.text(DATE_FORMAT.format(entry.getValue())).color(NamedTextColor.GOLD)));
|
||||
} else
|
||||
}
|
||||
else
|
||||
{
|
||||
historyList.add(
|
||||
Component.text(entry.getKey()).color(NamedTextColor.GOLD)
|
||||
|
|
|
@ -12,7 +12,6 @@ import java.util.List;
|
|||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@CommandPermissions(level = Rank.OP, permission = "plex.plex", source = RequiredCommandSource.ANY)
|
||||
|
|
|
@ -21,7 +21,7 @@ public class PunishmentsCMD extends PlexCommand
|
|||
@Override
|
||||
public Component execute(CommandSender sender, String[] args)
|
||||
{
|
||||
new PunishmentMenu().openInv(((Player) sender), 0);
|
||||
new PunishmentMenu().openInv(((Player)sender), 0);
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
|
@ -23,7 +23,7 @@ public class SpectatorCMD extends PlexCommand
|
|||
@Override
|
||||
public Component execute(CommandSender sender, String[] args)
|
||||
{
|
||||
Player player = (Player) sender;
|
||||
Player player = (Player)sender;
|
||||
if (args.length == 0)
|
||||
{
|
||||
if (isConsole(sender))
|
||||
|
|
|
@ -23,7 +23,7 @@ public class SurvivalCMD extends PlexCommand
|
|||
@Override
|
||||
public Component execute(CommandSender sender, String[] args)
|
||||
{
|
||||
Player player = (Player) sender;
|
||||
Player player = (Player)sender;
|
||||
if (args.length == 0)
|
||||
{
|
||||
if (isConsole(sender))
|
||||
|
|
|
@ -14,10 +14,7 @@ import dev.plex.util.PlexUtils;
|
|||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@CommandParameters(name = "unban", usage = "/<command> <player>", description = "Unbans a player, offline or online")
|
||||
|
|
|
@ -1,13 +1,9 @@
|
|||
package dev.plex.listener.impl;
|
||||
|
||||
import dev.plex.listener.PlexListener;
|
||||
import net.kyori.adventure.audience.Audience;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.player.AsyncPlayerPreLoginEvent;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class LoginListener extends PlexListener
|
||||
{
|
||||
|
|
|
@ -25,7 +25,8 @@ public class PunishedPlayerMenu extends AbstractMenu
|
|||
|
||||
private final List<Inventory> inventories = Lists.newArrayList();
|
||||
|
||||
public PunishedPlayerMenu(PunishedPlayer player) {
|
||||
public PunishedPlayerMenu(PunishedPlayer player)
|
||||
{
|
||||
super("§c§lPunishments");
|
||||
this.punishedPlayer = player;
|
||||
for (int i = 0; i <= punishedPlayer.getPunishments().size() / 53; i++)
|
||||
|
@ -35,7 +36,7 @@ public class PunishedPlayerMenu extends AbstractMenu
|
|||
ItemMeta meta = nextPage.getItemMeta();
|
||||
meta.setDisplayName(ChatColor.LIGHT_PURPLE + "Next Page");
|
||||
nextPage.setItemMeta(meta);
|
||||
|
||||
|
||||
ItemStack previousPage = new ItemStack(Material.FEATHER);
|
||||
ItemMeta meta2 = previousPage.getItemMeta();
|
||||
meta2.setDisplayName(ChatColor.LIGHT_PURPLE + "Previous Page");
|
||||
|
@ -45,7 +46,7 @@ public class PunishedPlayerMenu extends AbstractMenu
|
|||
ItemMeta meta3 = back.getItemMeta();
|
||||
meta3.setDisplayName(ChatColor.RED + "Return");
|
||||
back.setItemMeta(meta3);
|
||||
|
||||
|
||||
inventory.setItem(50, nextPage);
|
||||
inventory.setItem(49, back);
|
||||
inventory.setItem(48, previousPage);
|
||||
|
@ -53,11 +54,13 @@ public class PunishedPlayerMenu extends AbstractMenu
|
|||
}
|
||||
}
|
||||
|
||||
public List<Inventory> getInventory() {
|
||||
public List<Inventory> getInventory()
|
||||
{
|
||||
return inventories;
|
||||
}
|
||||
|
||||
public void openInv(Player player, int index) {
|
||||
public void openInv(Player player, int index)
|
||||
{
|
||||
int currentItemIndex = 0;
|
||||
int currentInvIndex = 0;
|
||||
for (Punishment punishment : punishedPlayer.getPunishments())
|
||||
|
@ -68,7 +71,8 @@ public class PunishedPlayerMenu extends AbstractMenu
|
|||
break;
|
||||
}
|
||||
|
||||
if (currentItemIndex == inv.getSize() - 1) {
|
||||
if (currentItemIndex == inv.getSize() - 1)
|
||||
{
|
||||
currentInvIndex++;
|
||||
currentItemIndex = 0;
|
||||
inv = inventories.get(currentInvIndex);
|
||||
|
@ -91,34 +95,61 @@ public class PunishedPlayerMenu extends AbstractMenu
|
|||
@EventHandler
|
||||
public void onClick(InventoryClickEvent event)
|
||||
{
|
||||
if (event.getClickedInventory() == null) return;
|
||||
if (event.getClickedInventory() == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Inventory inv = event.getClickedInventory();
|
||||
if (!isValidInventory(inv)) return;
|
||||
if (event.getCurrentItem() == null) return;
|
||||
if (!isValidInventory(inv))
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (event.getCurrentItem() == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
ItemStack item = event.getCurrentItem();
|
||||
event.setCancelled(true);
|
||||
if (item.getType() == Material.FEATHER)
|
||||
{
|
||||
if (item.getItemMeta().getDisplayName().equalsIgnoreCase(ChatColor.LIGHT_PURPLE + "Next Page"))
|
||||
{
|
||||
if (getCurrentInventoryIndex(inv) + 1 > inventories.size() - 1) return;
|
||||
if (inventories.get(getCurrentInventoryIndex(inv) + 1).getContents().length == 0) return;
|
||||
openInv((Player) event.getWhoClicked(), getCurrentInventoryIndex(inv) + 1);
|
||||
} else if (item.getItemMeta().getDisplayName().equalsIgnoreCase(ChatColor.LIGHT_PURPLE + "Previous Page"))
|
||||
if (getCurrentInventoryIndex(inv) + 1 > inventories.size() - 1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (inventories.get(getCurrentInventoryIndex(inv) + 1).getContents().length == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
openInv((Player)event.getWhoClicked(), getCurrentInventoryIndex(inv) + 1);
|
||||
}
|
||||
else if (item.getItemMeta().getDisplayName().equalsIgnoreCase(ChatColor.LIGHT_PURPLE + "Previous Page"))
|
||||
{
|
||||
if (getCurrentInventoryIndex(inv) - 1 < 0) return;
|
||||
if (getCurrentInventoryIndex(inv) - 1 > inventories.size() - 1) return;
|
||||
if (inventories.get(getCurrentInventoryIndex(inv) - 1).getContents().length == 0) return;
|
||||
openInv((Player) event.getWhoClicked(), getCurrentInventoryIndex(inv) - 1);
|
||||
if (getCurrentInventoryIndex(inv) - 1 < 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (getCurrentInventoryIndex(inv) - 1 > inventories.size() - 1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (inventories.get(getCurrentInventoryIndex(inv) - 1).getContents().length == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
openInv((Player)event.getWhoClicked(), getCurrentInventoryIndex(inv) - 1);
|
||||
}
|
||||
|
||||
|
||||
} else if (item.getType() == Material.BARRIER)
|
||||
}
|
||||
else if (item.getType() == Material.BARRIER)
|
||||
{
|
||||
new PunishmentMenu().openInv((Player) event.getWhoClicked(), 0);
|
||||
} else if (item.getType() == Material.PLAYER_HEAD)
|
||||
new PunishmentMenu().openInv((Player)event.getWhoClicked(), 0);
|
||||
}
|
||||
else if (item.getType() == Material.PLAYER_HEAD)
|
||||
{
|
||||
SkullMeta meta = (SkullMeta) item.getItemMeta();
|
||||
SkullMeta meta = (SkullMeta)item.getItemMeta();
|
||||
OfflinePlayer player = meta.getOwningPlayer();
|
||||
assert player != null;
|
||||
PunishedPlayer punishedPlayer = PlayerCache.getPunishedPlayer(player.getUniqueId()) == null ? null : PlayerCache.getPunishedPlayer(player.getUniqueId());
|
||||
|
|
|
@ -22,7 +22,8 @@ public class PunishmentMenu extends AbstractMenu
|
|||
|
||||
private List<Inventory> inventories = Lists.newArrayList();
|
||||
|
||||
public PunishmentMenu() {
|
||||
public PunishmentMenu()
|
||||
{
|
||||
super("§c§lPunishments");
|
||||
for (int i = 0; i <= Bukkit.getOnlinePlayers().size() / 53; i++)
|
||||
{
|
||||
|
@ -31,23 +32,25 @@ public class PunishmentMenu extends AbstractMenu
|
|||
ItemMeta meta = nextPage.getItemMeta();
|
||||
meta.setDisplayName(ChatColor.LIGHT_PURPLE + "Next Page");
|
||||
nextPage.setItemMeta(meta);
|
||||
|
||||
|
||||
ItemStack previousPage = new ItemStack(Material.FEATHER);
|
||||
ItemMeta meta2 = previousPage.getItemMeta();
|
||||
meta2.setDisplayName(ChatColor.LIGHT_PURPLE + "Previous Page");
|
||||
previousPage.setItemMeta(meta2);
|
||||
|
||||
|
||||
inventory.setItem(50, nextPage);
|
||||
inventory.setItem(48, previousPage);
|
||||
inventories.add(inventory);
|
||||
}
|
||||
}
|
||||
|
||||
public List<Inventory> getInventory() {
|
||||
public List<Inventory> getInventory()
|
||||
{
|
||||
return inventories;
|
||||
}
|
||||
|
||||
public void openInv(Player player, int index) {
|
||||
public void openInv(Player player, int index)
|
||||
{
|
||||
int currentItemIndex = 0;
|
||||
int currentInvIndex = 0;
|
||||
for (Player players : Bukkit.getOnlinePlayers())
|
||||
|
@ -58,7 +61,8 @@ public class PunishmentMenu extends AbstractMenu
|
|||
break;
|
||||
}
|
||||
|
||||
if (currentItemIndex == inv.getSize() - 1) {
|
||||
if (currentItemIndex == inv.getSize() - 1)
|
||||
{
|
||||
currentInvIndex++;
|
||||
currentItemIndex = 0;
|
||||
inv = inventories.get(currentInvIndex);
|
||||
|
@ -66,7 +70,7 @@ public class PunishmentMenu extends AbstractMenu
|
|||
|
||||
|
||||
ItemStack item = new ItemStack(Material.PLAYER_HEAD);
|
||||
SkullMeta meta = (SkullMeta) item.getItemMeta();
|
||||
SkullMeta meta = (SkullMeta)item.getItemMeta();
|
||||
meta.setOwningPlayer(players);
|
||||
meta.setDisplayName(ChatColor.YELLOW + players.getName());
|
||||
item.setItemMeta(meta);
|
||||
|
@ -81,31 +85,57 @@ public class PunishmentMenu extends AbstractMenu
|
|||
@EventHandler
|
||||
public void onClick(InventoryClickEvent event)
|
||||
{
|
||||
if (event.getClickedInventory() == null) return;
|
||||
if (event.getClickedInventory() == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Inventory inv = event.getClickedInventory();
|
||||
if (!isValidInventory(inv)) return;
|
||||
if (event.getCurrentItem() == null) return;
|
||||
if (!isValidInventory(inv))
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (event.getCurrentItem() == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
ItemStack item = event.getCurrentItem();
|
||||
event.setCancelled(true);
|
||||
if (item.getType() == Material.FEATHER)
|
||||
{
|
||||
if (item.getItemMeta().getDisplayName().equalsIgnoreCase(ChatColor.LIGHT_PURPLE + "Next Page"))
|
||||
{
|
||||
if (getCurrentInventoryIndex(inv) + 1 > inventories.size() - 1) return;
|
||||
if (inventories.get(getCurrentInventoryIndex(inv) + 1).getContents().length == 0) return;
|
||||
openInv((Player) event.getWhoClicked(), getCurrentInventoryIndex(inv) + 1);
|
||||
} else if (item.getItemMeta().getDisplayName().equalsIgnoreCase(ChatColor.LIGHT_PURPLE + "Previous Page"))
|
||||
if (getCurrentInventoryIndex(inv) + 1 > inventories.size() - 1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (inventories.get(getCurrentInventoryIndex(inv) + 1).getContents().length == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
openInv((Player)event.getWhoClicked(), getCurrentInventoryIndex(inv) + 1);
|
||||
}
|
||||
else if (item.getItemMeta().getDisplayName().equalsIgnoreCase(ChatColor.LIGHT_PURPLE + "Previous Page"))
|
||||
{
|
||||
if (getCurrentInventoryIndex(inv) - 1 < 0) return;
|
||||
if (getCurrentInventoryIndex(inv) - 1 > inventories.size() - 1) return;
|
||||
if (inventories.get(getCurrentInventoryIndex(inv) - 1).getContents().length == 0) return;
|
||||
openInv((Player) event.getWhoClicked(), getCurrentInventoryIndex(inv) - 1);
|
||||
if (getCurrentInventoryIndex(inv) - 1 < 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (getCurrentInventoryIndex(inv) - 1 > inventories.size() - 1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (inventories.get(getCurrentInventoryIndex(inv) - 1).getContents().length == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
openInv((Player)event.getWhoClicked(), getCurrentInventoryIndex(inv) - 1);
|
||||
}
|
||||
|
||||
|
||||
} else if (item.getType() == Material.PLAYER_HEAD)
|
||||
}
|
||||
else if (item.getType() == Material.PLAYER_HEAD)
|
||||
{
|
||||
SkullMeta meta = (SkullMeta) item.getItemMeta();
|
||||
SkullMeta meta = (SkullMeta)item.getItemMeta();
|
||||
OfflinePlayer player = meta.getOwningPlayer();
|
||||
assert player != null;
|
||||
PunishedPlayer punishedPlayer = PlayerCache.getPunishedPlayer(player.getUniqueId()) == null ? null : PlayerCache.getPunishedPlayer(player.getUniqueId());
|
||||
|
@ -115,11 +145,10 @@ public class PunishmentMenu extends AbstractMenu
|
|||
event.getWhoClicked().closeInventory();
|
||||
return;
|
||||
}
|
||||
new PunishedPlayerMenu(punishedPlayer).openInv((Player) event.getWhoClicked(), 0);
|
||||
new PunishedPlayerMenu(punishedPlayer).openInv((Player)event.getWhoClicked(), 0);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
public int getCurrentInventoryIndex(Inventory inventory)
|
||||
|
|
|
@ -69,7 +69,8 @@ public class PlexPlayer
|
|||
this.rank = "";
|
||||
}
|
||||
|
||||
public String displayName() {
|
||||
public String displayName()
|
||||
{
|
||||
return PlainTextComponentSerializer.plainText().serialize(player.displayName());
|
||||
}
|
||||
|
||||
|
|
|
@ -68,9 +68,12 @@ public class PunishedPlayer
|
|||
File file = new File(folder, getUuid() + ".json");
|
||||
if (!file.exists())
|
||||
{
|
||||
try {
|
||||
try
|
||||
{
|
||||
file.createNewFile();
|
||||
} catch (IOException e) {
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
@ -86,24 +89,32 @@ public class PunishedPlayer
|
|||
|
||||
if (isNotEmpty(file))
|
||||
{
|
||||
try {
|
||||
try
|
||||
{
|
||||
JSONTokener tokener = new JSONTokener(new FileInputStream(file));
|
||||
JSONObject object = new JSONObject(tokener);
|
||||
object.getJSONObject(getUuid()).getJSONArray("punishments").forEach(obj -> {
|
||||
object.getJSONObject(getUuid()).getJSONArray("punishments").forEach(obj ->
|
||||
{
|
||||
Punishment punishment = Punishment.fromJson(obj.toString());
|
||||
punishments.add(punishment);
|
||||
});
|
||||
} catch (FileNotFoundException e) {
|
||||
}
|
||||
catch (FileNotFoundException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
return punishments;
|
||||
}
|
||||
|
||||
private boolean isNotEmpty(File file) {
|
||||
try {
|
||||
private boolean isNotEmpty(File file)
|
||||
{
|
||||
try
|
||||
{
|
||||
return !FileUtils.readFileToString(file, StandardCharsets.UTF_8).trim().isEmpty();
|
||||
} catch (IOException e) {
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
return false;
|
||||
|
|
|
@ -29,7 +29,8 @@ public class PunishmentManager
|
|||
{
|
||||
File file = player.getPunishmentsFile();
|
||||
|
||||
try {
|
||||
try
|
||||
{
|
||||
if (isNotEmpty(file))
|
||||
{
|
||||
JSONTokener tokener = new JSONTokener(new FileInputStream(file));
|
||||
|
@ -40,7 +41,9 @@ public class PunishmentManager
|
|||
writer.append(object.toString(8));
|
||||
writer.flush();
|
||||
writer.close();
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
JSONObject object = new JSONObject();
|
||||
Map<String, List<String>> punishments = Maps.newHashMap();
|
||||
|
||||
|
@ -56,15 +59,21 @@ public class PunishmentManager
|
|||
writer.close();
|
||||
}
|
||||
|
||||
} catch (IOException e) {
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isNotEmpty(File file) {
|
||||
try {
|
||||
private boolean isNotEmpty(File file)
|
||||
{
|
||||
try
|
||||
{
|
||||
return !FileUtils.readFileToString(file, StandardCharsets.UTF_8).trim().isEmpty();
|
||||
} catch (IOException e) {
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
return false;
|
||||
|
@ -76,15 +85,18 @@ public class PunishmentManager
|
|||
{
|
||||
Ban ban = new Ban(punishment.getPunished(), (punishment.getPunisher() == null ? null : punishment.getPunisher()), "", punishment.getReason(), punishment.getEndDate());
|
||||
Plex.get().getBanManager().executeBan(ban);
|
||||
} else if (punishment.getType() == PunishmentType.FREEZE)
|
||||
}
|
||||
else if (punishment.getType() == PunishmentType.FREEZE)
|
||||
{
|
||||
player.setFrozen(true);
|
||||
Date now = new Date();
|
||||
Date then = punishment.getEndDate();
|
||||
long seconds = TimeUnit.MILLISECONDS.toSeconds(then.getTime() - now.getTime());
|
||||
new BukkitRunnable() {
|
||||
long seconds = TimeUnit.MILLISECONDS.toSeconds(then.getTime() - now.getTime());
|
||||
new BukkitRunnable()
|
||||
{
|
||||
@Override
|
||||
public void run() {
|
||||
public void run()
|
||||
{
|
||||
if (!player.isFrozen())
|
||||
{
|
||||
this.cancel();
|
||||
|
@ -97,16 +109,18 @@ public class PunishmentManager
|
|||
}.runTaskLater(Plex.get(), 20 * seconds);
|
||||
|
||||
|
||||
|
||||
} else if (punishment.getType() == PunishmentType.MUTE)
|
||||
}
|
||||
else if (punishment.getType() == PunishmentType.MUTE)
|
||||
{
|
||||
player.setMuted(true);
|
||||
Date now = new Date();
|
||||
Date then = punishment.getEndDate();
|
||||
long seconds = TimeUnit.MILLISECONDS.toSeconds(then.getTime() - now.getTime());
|
||||
new BukkitRunnable() {
|
||||
long seconds = TimeUnit.MILLISECONDS.toSeconds(then.getTime() - now.getTime());
|
||||
new BukkitRunnable()
|
||||
{
|
||||
@Override
|
||||
public void run() {
|
||||
public void run()
|
||||
{
|
||||
player.setMuted(false);
|
||||
}
|
||||
}.runTaskLater(Plex.get(), 20 * seconds);
|
||||
|
|
|
@ -11,11 +11,13 @@ public abstract class AbstractService implements IService
|
|||
this.asynchronous = async;
|
||||
}
|
||||
|
||||
public boolean isRepeating() {
|
||||
public boolean isRepeating()
|
||||
{
|
||||
return repeating;
|
||||
}
|
||||
|
||||
public boolean isAsynchronous() {
|
||||
public boolean isAsynchronous()
|
||||
{
|
||||
return asynchronous;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,7 +2,6 @@ package dev.plex.services;
|
|||
|
||||
import com.google.common.collect.Lists;
|
||||
import dev.plex.Plex;
|
||||
import dev.plex.services.impl.BanService;
|
||||
import dev.plex.services.impl.GameRuleService;
|
||||
import java.util.List;
|
||||
import org.bukkit.Bukkit;
|
||||
|
|
|
@ -8,12 +8,14 @@ import org.bukkit.Bukkit;
|
|||
|
||||
public class BanService extends AbstractService
|
||||
{
|
||||
public BanService() {
|
||||
public BanService()
|
||||
{
|
||||
super(true, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
public void run()
|
||||
{
|
||||
for (Ban ban : Plex.get().getBanManager().getActiveBans())
|
||||
{
|
||||
if (new Date().after(ban.getEndDate()))
|
||||
|
@ -25,7 +27,8 @@ public class BanService extends AbstractService
|
|||
}
|
||||
|
||||
@Override
|
||||
public int repeatInSeconds() {
|
||||
public int repeatInSeconds()
|
||||
{
|
||||
return 10;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -35,7 +35,8 @@ public class MojangUtils
|
|||
.insert(13, "-")
|
||||
.insert(18, "-")
|
||||
.insert(23, "-").toString());
|
||||
} catch (IOException e)
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
|
@ -63,12 +64,14 @@ public class MojangUtils
|
|||
Instant instant = Instant.ofEpochMilli(dateTime);
|
||||
LocalDateTime time = LocalDateTime.ofInstant(instant, ZoneId.of("America/Los_Angeles"));
|
||||
names.put(name, time);
|
||||
} else
|
||||
}
|
||||
else
|
||||
{
|
||||
names.put(name, null);
|
||||
}
|
||||
});
|
||||
} catch (IOException e)
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
|
|
@ -14,7 +14,8 @@ public abstract class AbstractMenu implements Listener
|
|||
Plex.get().getServer().getPluginManager().registerEvents(this, Plex.get());
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
public String getName()
|
||||
{
|
||||
return name;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue