mirror of
https://github.com/plexusorg/Plex.git
synced 2024-12-22 17:17:37 +00:00
Code cleanup
This commit is contained in:
parent
d4761d4386
commit
4a05d90c17
4
src/main/java/dev/plex/cache/DataUtils.java
vendored
4
src/main/java/dev/plex/cache/DataUtils.java
vendored
@ -61,7 +61,9 @@ public class DataUtils
|
|||||||
if (Plex.get().getStorageType() == StorageType.MONGODB)
|
if (Plex.get().getStorageType() == StorageType.MONGODB)
|
||||||
{
|
{
|
||||||
Plex.get().getMongoPlayerData().save(plexPlayer);
|
Plex.get().getMongoPlayerData().save(plexPlayer);
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
Plex.get().getSqlPlayerData().insert(plexPlayer);
|
Plex.get().getSqlPlayerData().insert(plexPlayer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -54,7 +54,9 @@ public class SQLPlayerData
|
|||||||
String rankName = set.getString("rank").toUpperCase();
|
String rankName = set.getString("rank").toUpperCase();
|
||||||
long coins = set.getLong("coins");
|
long coins = set.getLong("coins");
|
||||||
boolean vanished = set.getBoolean("vanished");
|
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.setName(name);
|
||||||
plexPlayer.setLoginMSG(loginMSG);
|
plexPlayer.setLoginMSG(loginMSG);
|
||||||
plexPlayer.setPrefix(prefix);
|
plexPlayer.setPrefix(prefix);
|
||||||
|
@ -5,6 +5,7 @@ import dev.plex.rank.enums.Rank;
|
|||||||
public @interface CheckPermission
|
public @interface CheckPermission
|
||||||
{
|
{
|
||||||
String permission() default "";
|
String permission() default "";
|
||||||
|
|
||||||
Rank rank() default Rank.IMPOSTOR;
|
Rank rank() default Rank.IMPOSTOR;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -44,7 +44,8 @@ public class NameHistoryCMD extends PlexCommand
|
|||||||
if (offlinePlayer != null)
|
if (offlinePlayer != null)
|
||||||
{
|
{
|
||||||
uuid = offlinePlayer.getUniqueId();
|
uuid = offlinePlayer.getUniqueId();
|
||||||
} else
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
uuid = MojangUtils.getUUID(username);
|
uuid = MojangUtils.getUUID(username);
|
||||||
}
|
}
|
||||||
@ -68,7 +69,8 @@ public class NameHistoryCMD extends PlexCommand
|
|||||||
.append(Component.text("-").color(NamedTextColor.DARK_GRAY))
|
.append(Component.text("-").color(NamedTextColor.DARK_GRAY))
|
||||||
.append(Component.space())
|
.append(Component.space())
|
||||||
.append(Component.text(DATE_FORMAT.format(entry.getValue())).color(NamedTextColor.GOLD)));
|
.append(Component.text(DATE_FORMAT.format(entry.getValue())).color(NamedTextColor.GOLD)));
|
||||||
} else
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
historyList.add(
|
historyList.add(
|
||||||
Component.text(entry.getKey()).color(NamedTextColor.GOLD)
|
Component.text(entry.getKey()).color(NamedTextColor.GOLD)
|
||||||
|
@ -12,7 +12,6 @@ import java.util.List;
|
|||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
@CommandPermissions(level = Rank.OP, permission = "plex.plex", source = RequiredCommandSource.ANY)
|
@CommandPermissions(level = Rank.OP, permission = "plex.plex", source = RequiredCommandSource.ANY)
|
||||||
|
@ -14,10 +14,7 @@ import dev.plex.util.PlexUtils;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.OfflinePlayer;
|
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
@CommandParameters(name = "unban", usage = "/<command> <player>", description = "Unbans a player, offline or online")
|
@CommandParameters(name = "unban", usage = "/<command> <player>", description = "Unbans a player, offline or online")
|
||||||
|
@ -1,13 +1,9 @@
|
|||||||
package dev.plex.listener.impl;
|
package dev.plex.listener.impl;
|
||||||
|
|
||||||
import dev.plex.listener.PlexListener;
|
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 net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.player.AsyncPlayerPreLoginEvent;
|
import org.bukkit.event.player.AsyncPlayerPreLoginEvent;
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
|
|
||||||
public class LoginListener extends PlexListener
|
public class LoginListener extends PlexListener
|
||||||
{
|
{
|
||||||
|
@ -25,7 +25,8 @@ public class PunishedPlayerMenu extends AbstractMenu
|
|||||||
|
|
||||||
private final List<Inventory> inventories = Lists.newArrayList();
|
private final List<Inventory> inventories = Lists.newArrayList();
|
||||||
|
|
||||||
public PunishedPlayerMenu(PunishedPlayer player) {
|
public PunishedPlayerMenu(PunishedPlayer player)
|
||||||
|
{
|
||||||
super("§c§lPunishments");
|
super("§c§lPunishments");
|
||||||
this.punishedPlayer = player;
|
this.punishedPlayer = player;
|
||||||
for (int i = 0; i <= punishedPlayer.getPunishments().size() / 53; i++)
|
for (int i = 0; i <= punishedPlayer.getPunishments().size() / 53; i++)
|
||||||
@ -53,11 +54,13 @@ public class PunishedPlayerMenu extends AbstractMenu
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Inventory> getInventory() {
|
public List<Inventory> getInventory()
|
||||||
|
{
|
||||||
return inventories;
|
return inventories;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void openInv(Player player, int index) {
|
public void openInv(Player player, int index)
|
||||||
|
{
|
||||||
int currentItemIndex = 0;
|
int currentItemIndex = 0;
|
||||||
int currentInvIndex = 0;
|
int currentInvIndex = 0;
|
||||||
for (Punishment punishment : punishedPlayer.getPunishments())
|
for (Punishment punishment : punishedPlayer.getPunishments())
|
||||||
@ -68,7 +71,8 @@ public class PunishedPlayerMenu extends AbstractMenu
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (currentItemIndex == inv.getSize() - 1) {
|
if (currentItemIndex == inv.getSize() - 1)
|
||||||
|
{
|
||||||
currentInvIndex++;
|
currentInvIndex++;
|
||||||
currentItemIndex = 0;
|
currentItemIndex = 0;
|
||||||
inv = inventories.get(currentInvIndex);
|
inv = inventories.get(currentInvIndex);
|
||||||
@ -91,32 +95,59 @@ public class PunishedPlayerMenu extends AbstractMenu
|
|||||||
@EventHandler
|
@EventHandler
|
||||||
public void onClick(InventoryClickEvent event)
|
public void onClick(InventoryClickEvent event)
|
||||||
{
|
{
|
||||||
if (event.getClickedInventory() == null) return;
|
if (event.getClickedInventory() == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
Inventory inv = event.getClickedInventory();
|
Inventory inv = event.getClickedInventory();
|
||||||
if (!isValidInventory(inv)) return;
|
if (!isValidInventory(inv))
|
||||||
if (event.getCurrentItem() == null) return;
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (event.getCurrentItem() == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
ItemStack item = event.getCurrentItem();
|
ItemStack item = event.getCurrentItem();
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
if (item.getType() == Material.FEATHER)
|
if (item.getType() == Material.FEATHER)
|
||||||
{
|
{
|
||||||
if (item.getItemMeta().getDisplayName().equalsIgnoreCase(ChatColor.LIGHT_PURPLE + "Next Page"))
|
if (item.getItemMeta().getDisplayName().equalsIgnoreCase(ChatColor.LIGHT_PURPLE + "Next Page"))
|
||||||
{
|
{
|
||||||
if (getCurrentInventoryIndex(inv) + 1 > inventories.size() - 1) return;
|
if (getCurrentInventoryIndex(inv) + 1 > inventories.size() - 1)
|
||||||
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;
|
return;
|
||||||
if (getCurrentInventoryIndex(inv) - 1 > inventories.size() - 1) return;
|
}
|
||||||
if (inventories.get(getCurrentInventoryIndex(inv) - 1).getContents().length == 0) 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);
|
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);
|
new PunishmentMenu().openInv((Player)event.getWhoClicked(), 0);
|
||||||
} 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();
|
OfflinePlayer player = meta.getOwningPlayer();
|
||||||
|
@ -22,7 +22,8 @@ public class PunishmentMenu extends AbstractMenu
|
|||||||
|
|
||||||
private List<Inventory> inventories = Lists.newArrayList();
|
private List<Inventory> inventories = Lists.newArrayList();
|
||||||
|
|
||||||
public PunishmentMenu() {
|
public PunishmentMenu()
|
||||||
|
{
|
||||||
super("§c§lPunishments");
|
super("§c§lPunishments");
|
||||||
for (int i = 0; i <= Bukkit.getOnlinePlayers().size() / 53; i++)
|
for (int i = 0; i <= Bukkit.getOnlinePlayers().size() / 53; i++)
|
||||||
{
|
{
|
||||||
@ -43,11 +44,13 @@ public class PunishmentMenu extends AbstractMenu
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Inventory> getInventory() {
|
public List<Inventory> getInventory()
|
||||||
|
{
|
||||||
return inventories;
|
return inventories;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void openInv(Player player, int index) {
|
public void openInv(Player player, int index)
|
||||||
|
{
|
||||||
int currentItemIndex = 0;
|
int currentItemIndex = 0;
|
||||||
int currentInvIndex = 0;
|
int currentInvIndex = 0;
|
||||||
for (Player players : Bukkit.getOnlinePlayers())
|
for (Player players : Bukkit.getOnlinePlayers())
|
||||||
@ -58,7 +61,8 @@ public class PunishmentMenu extends AbstractMenu
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (currentItemIndex == inv.getSize() - 1) {
|
if (currentItemIndex == inv.getSize() - 1)
|
||||||
|
{
|
||||||
currentInvIndex++;
|
currentInvIndex++;
|
||||||
currentItemIndex = 0;
|
currentItemIndex = 0;
|
||||||
inv = inventories.get(currentInvIndex);
|
inv = inventories.get(currentInvIndex);
|
||||||
@ -81,29 +85,55 @@ public class PunishmentMenu extends AbstractMenu
|
|||||||
@EventHandler
|
@EventHandler
|
||||||
public void onClick(InventoryClickEvent event)
|
public void onClick(InventoryClickEvent event)
|
||||||
{
|
{
|
||||||
if (event.getClickedInventory() == null) return;
|
if (event.getClickedInventory() == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
Inventory inv = event.getClickedInventory();
|
Inventory inv = event.getClickedInventory();
|
||||||
if (!isValidInventory(inv)) return;
|
if (!isValidInventory(inv))
|
||||||
if (event.getCurrentItem() == null) return;
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (event.getCurrentItem() == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
ItemStack item = event.getCurrentItem();
|
ItemStack item = event.getCurrentItem();
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
if (item.getType() == Material.FEATHER)
|
if (item.getType() == Material.FEATHER)
|
||||||
{
|
{
|
||||||
if (item.getItemMeta().getDisplayName().equalsIgnoreCase(ChatColor.LIGHT_PURPLE + "Next Page"))
|
if (item.getItemMeta().getDisplayName().equalsIgnoreCase(ChatColor.LIGHT_PURPLE + "Next Page"))
|
||||||
{
|
{
|
||||||
if (getCurrentInventoryIndex(inv) + 1 > inventories.size() - 1) return;
|
if (getCurrentInventoryIndex(inv) + 1 > inventories.size() - 1)
|
||||||
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;
|
return;
|
||||||
if (getCurrentInventoryIndex(inv) - 1 > inventories.size() - 1) return;
|
}
|
||||||
if (inventories.get(getCurrentInventoryIndex(inv) - 1).getContents().length == 0) 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);
|
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();
|
OfflinePlayer player = meta.getOwningPlayer();
|
||||||
@ -119,7 +149,6 @@ public class PunishmentMenu extends AbstractMenu
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getCurrentInventoryIndex(Inventory inventory)
|
public int getCurrentInventoryIndex(Inventory inventory)
|
||||||
|
@ -69,7 +69,8 @@ public class PlexPlayer
|
|||||||
this.rank = "";
|
this.rank = "";
|
||||||
}
|
}
|
||||||
|
|
||||||
public String displayName() {
|
public String displayName()
|
||||||
|
{
|
||||||
return PlainTextComponentSerializer.plainText().serialize(player.displayName());
|
return PlainTextComponentSerializer.plainText().serialize(player.displayName());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -68,9 +68,12 @@ public class PunishedPlayer
|
|||||||
File file = new File(folder, getUuid() + ".json");
|
File file = new File(folder, getUuid() + ".json");
|
||||||
if (!file.exists())
|
if (!file.exists())
|
||||||
{
|
{
|
||||||
try {
|
try
|
||||||
|
{
|
||||||
file.createNewFile();
|
file.createNewFile();
|
||||||
} catch (IOException e) {
|
}
|
||||||
|
catch (IOException e)
|
||||||
|
{
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -86,24 +89,32 @@ public class PunishedPlayer
|
|||||||
|
|
||||||
if (isNotEmpty(file))
|
if (isNotEmpty(file))
|
||||||
{
|
{
|
||||||
try {
|
try
|
||||||
|
{
|
||||||
JSONTokener tokener = new JSONTokener(new FileInputStream(file));
|
JSONTokener tokener = new JSONTokener(new FileInputStream(file));
|
||||||
JSONObject object = new JSONObject(tokener);
|
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());
|
Punishment punishment = Punishment.fromJson(obj.toString());
|
||||||
punishments.add(punishment);
|
punishments.add(punishment);
|
||||||
});
|
});
|
||||||
} catch (FileNotFoundException e) {
|
}
|
||||||
|
catch (FileNotFoundException e)
|
||||||
|
{
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return punishments;
|
return punishments;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isNotEmpty(File file) {
|
private boolean isNotEmpty(File file)
|
||||||
try {
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
return !FileUtils.readFileToString(file, StandardCharsets.UTF_8).trim().isEmpty();
|
return !FileUtils.readFileToString(file, StandardCharsets.UTF_8).trim().isEmpty();
|
||||||
} catch (IOException e) {
|
}
|
||||||
|
catch (IOException e)
|
||||||
|
{
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
@ -29,7 +29,8 @@ public class PunishmentManager
|
|||||||
{
|
{
|
||||||
File file = player.getPunishmentsFile();
|
File file = player.getPunishmentsFile();
|
||||||
|
|
||||||
try {
|
try
|
||||||
|
{
|
||||||
if (isNotEmpty(file))
|
if (isNotEmpty(file))
|
||||||
{
|
{
|
||||||
JSONTokener tokener = new JSONTokener(new FileInputStream(file));
|
JSONTokener tokener = new JSONTokener(new FileInputStream(file));
|
||||||
@ -40,7 +41,9 @@ public class PunishmentManager
|
|||||||
writer.append(object.toString(8));
|
writer.append(object.toString(8));
|
||||||
writer.flush();
|
writer.flush();
|
||||||
writer.close();
|
writer.close();
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
JSONObject object = new JSONObject();
|
JSONObject object = new JSONObject();
|
||||||
Map<String, List<String>> punishments = Maps.newHashMap();
|
Map<String, List<String>> punishments = Maps.newHashMap();
|
||||||
|
|
||||||
@ -56,15 +59,21 @@ public class PunishmentManager
|
|||||||
writer.close();
|
writer.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (IOException e) {
|
}
|
||||||
|
catch (IOException e)
|
||||||
|
{
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isNotEmpty(File file) {
|
private boolean isNotEmpty(File file)
|
||||||
try {
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
return !FileUtils.readFileToString(file, StandardCharsets.UTF_8).trim().isEmpty();
|
return !FileUtils.readFileToString(file, StandardCharsets.UTF_8).trim().isEmpty();
|
||||||
} catch (IOException e) {
|
}
|
||||||
|
catch (IOException e)
|
||||||
|
{
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
return false;
|
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());
|
Ban ban = new Ban(punishment.getPunished(), (punishment.getPunisher() == null ? null : punishment.getPunisher()), "", punishment.getReason(), punishment.getEndDate());
|
||||||
Plex.get().getBanManager().executeBan(ban);
|
Plex.get().getBanManager().executeBan(ban);
|
||||||
} else if (punishment.getType() == PunishmentType.FREEZE)
|
}
|
||||||
|
else if (punishment.getType() == PunishmentType.FREEZE)
|
||||||
{
|
{
|
||||||
player.setFrozen(true);
|
player.setFrozen(true);
|
||||||
Date now = new Date();
|
Date now = new Date();
|
||||||
Date then = punishment.getEndDate();
|
Date then = punishment.getEndDate();
|
||||||
long seconds = TimeUnit.MILLISECONDS.toSeconds(then.getTime() - now.getTime());
|
long seconds = TimeUnit.MILLISECONDS.toSeconds(then.getTime() - now.getTime());
|
||||||
new BukkitRunnable() {
|
new BukkitRunnable()
|
||||||
|
{
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run()
|
||||||
|
{
|
||||||
if (!player.isFrozen())
|
if (!player.isFrozen())
|
||||||
{
|
{
|
||||||
this.cancel();
|
this.cancel();
|
||||||
@ -97,16 +109,18 @@ public class PunishmentManager
|
|||||||
}.runTaskLater(Plex.get(), 20 * seconds);
|
}.runTaskLater(Plex.get(), 20 * seconds);
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
} else if (punishment.getType() == PunishmentType.MUTE)
|
else if (punishment.getType() == PunishmentType.MUTE)
|
||||||
{
|
{
|
||||||
player.setMuted(true);
|
player.setMuted(true);
|
||||||
Date now = new Date();
|
Date now = new Date();
|
||||||
Date then = punishment.getEndDate();
|
Date then = punishment.getEndDate();
|
||||||
long seconds = TimeUnit.MILLISECONDS.toSeconds(then.getTime() - now.getTime());
|
long seconds = TimeUnit.MILLISECONDS.toSeconds(then.getTime() - now.getTime());
|
||||||
new BukkitRunnable() {
|
new BukkitRunnable()
|
||||||
|
{
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run()
|
||||||
|
{
|
||||||
player.setMuted(false);
|
player.setMuted(false);
|
||||||
}
|
}
|
||||||
}.runTaskLater(Plex.get(), 20 * seconds);
|
}.runTaskLater(Plex.get(), 20 * seconds);
|
||||||
|
@ -11,11 +11,13 @@ public abstract class AbstractService implements IService
|
|||||||
this.asynchronous = async;
|
this.asynchronous = async;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isRepeating() {
|
public boolean isRepeating()
|
||||||
|
{
|
||||||
return repeating;
|
return repeating;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isAsynchronous() {
|
public boolean isAsynchronous()
|
||||||
|
{
|
||||||
return asynchronous;
|
return asynchronous;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,6 @@ package dev.plex.services;
|
|||||||
|
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
import dev.plex.Plex;
|
import dev.plex.Plex;
|
||||||
import dev.plex.services.impl.BanService;
|
|
||||||
import dev.plex.services.impl.GameRuleService;
|
import dev.plex.services.impl.GameRuleService;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
|
@ -8,12 +8,14 @@ import org.bukkit.Bukkit;
|
|||||||
|
|
||||||
public class BanService extends AbstractService
|
public class BanService extends AbstractService
|
||||||
{
|
{
|
||||||
public BanService() {
|
public BanService()
|
||||||
|
{
|
||||||
super(true, true);
|
super(true, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run()
|
||||||
|
{
|
||||||
for (Ban ban : Plex.get().getBanManager().getActiveBans())
|
for (Ban ban : Plex.get().getBanManager().getActiveBans())
|
||||||
{
|
{
|
||||||
if (new Date().after(ban.getEndDate()))
|
if (new Date().after(ban.getEndDate()))
|
||||||
@ -25,7 +27,8 @@ public class BanService extends AbstractService
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int repeatInSeconds() {
|
public int repeatInSeconds()
|
||||||
|
{
|
||||||
return 10;
|
return 10;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -35,7 +35,8 @@ public class MojangUtils
|
|||||||
.insert(13, "-")
|
.insert(13, "-")
|
||||||
.insert(18, "-")
|
.insert(18, "-")
|
||||||
.insert(23, "-").toString());
|
.insert(23, "-").toString());
|
||||||
} catch (IOException e)
|
}
|
||||||
|
catch (IOException e)
|
||||||
{
|
{
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
return null;
|
return null;
|
||||||
@ -63,12 +64,14 @@ public class MojangUtils
|
|||||||
Instant instant = Instant.ofEpochMilli(dateTime);
|
Instant instant = Instant.ofEpochMilli(dateTime);
|
||||||
LocalDateTime time = LocalDateTime.ofInstant(instant, ZoneId.of("America/Los_Angeles"));
|
LocalDateTime time = LocalDateTime.ofInstant(instant, ZoneId.of("America/Los_Angeles"));
|
||||||
names.put(name, time);
|
names.put(name, time);
|
||||||
} else
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
names.put(name, null);
|
names.put(name, null);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} catch (IOException e)
|
}
|
||||||
|
catch (IOException e)
|
||||||
{
|
{
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
@ -14,7 +14,8 @@ public abstract class AbstractMenu implements Listener
|
|||||||
Plex.get().getServer().getPluginManager().registerEvents(this, Plex.get());
|
Plex.get().getServer().getPluginManager().registerEvents(this, Plex.get());
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getName() {
|
public String getName()
|
||||||
|
{
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user