mirror of
https://github.com/plexusorg/Plex.git
synced 2025-06-29 06:46:43 +00:00
tttt
This commit is contained in:
87
src/main/java/dev/plex/player/PlexPlayer.java
Normal file
87
src/main/java/dev/plex/player/PlexPlayer.java
Normal file
@ -0,0 +1,87 @@
|
||||
package dev.plex.player;
|
||||
|
||||
import dev.morphia.annotations.Entity;
|
||||
import dev.morphia.annotations.Id;
|
||||
import dev.morphia.annotations.IndexOptions;
|
||||
import dev.morphia.annotations.Indexed;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import dev.plex.rank.enums.Rank;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@Entity(value = "players", useDiscriminator = false)
|
||||
public class PlexPlayer
|
||||
{
|
||||
@Setter(AccessLevel.NONE)
|
||||
@Id
|
||||
private String id;
|
||||
|
||||
@Setter(AccessLevel.NONE)
|
||||
@Indexed(options = @IndexOptions(unique = true))
|
||||
private String uuid;
|
||||
|
||||
@Indexed
|
||||
private String name;
|
||||
|
||||
private String loginMSG;
|
||||
private String prefix;
|
||||
|
||||
private boolean vanished;
|
||||
|
||||
private long coins;
|
||||
|
||||
private String rank;
|
||||
|
||||
private List<String> ips;
|
||||
|
||||
public PlexPlayer()
|
||||
{
|
||||
}
|
||||
|
||||
public PlexPlayer(UUID playerUUID)
|
||||
{
|
||||
this.uuid = playerUUID.toString();
|
||||
|
||||
this.id = uuid.substring(0, 8);
|
||||
|
||||
this.name = "";
|
||||
|
||||
this.loginMSG = "";
|
||||
this.prefix = "";
|
||||
|
||||
this.vanished = false;
|
||||
|
||||
this.coins = 0;
|
||||
|
||||
this.ips = new ArrayList<>();
|
||||
|
||||
this.rank = "";
|
||||
}
|
||||
|
||||
public Rank getRankFromString()
|
||||
{
|
||||
OfflinePlayer player = Bukkit.getOfflinePlayer(UUID.fromString(uuid));
|
||||
if (rank.isEmpty())
|
||||
{
|
||||
if (player.isOp())
|
||||
{
|
||||
return Rank.OP;
|
||||
}
|
||||
else
|
||||
{
|
||||
return Rank.NONOP;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return Rank.valueOf(rank.toUpperCase());
|
||||
}
|
||||
}
|
||||
}
|
112
src/main/java/dev/plex/player/PunishedPlayer.java
Normal file
112
src/main/java/dev/plex/player/PunishedPlayer.java
Normal file
@ -0,0 +1,112 @@
|
||||
package dev.plex.player;
|
||||
|
||||
import dev.plex.Plex;
|
||||
import dev.plex.punishment.Punishment;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import dev.plex.event.PunishedPlayerFreezeEvent;
|
||||
import dev.plex.event.PunishedPlayerMuteEvent;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.json.JSONObject;
|
||||
import org.json.JSONTokener;
|
||||
|
||||
@Getter
|
||||
public class PunishedPlayer
|
||||
{
|
||||
//everything in here will be stored in redis
|
||||
@Setter(AccessLevel.NONE)
|
||||
private String uuid;
|
||||
|
||||
private boolean muted;
|
||||
private boolean frozen;
|
||||
|
||||
public PunishedPlayer(UUID playerUUID)
|
||||
{
|
||||
this.uuid = playerUUID.toString();
|
||||
this.muted = false;
|
||||
this.frozen = false;
|
||||
}
|
||||
|
||||
public void setFrozen(boolean frozen)
|
||||
{
|
||||
PunishedPlayerFreezeEvent e = new PunishedPlayerFreezeEvent(this, this.frozen);
|
||||
Bukkit.getServer().getPluginManager().callEvent(e);
|
||||
if (!e.isCancelled())
|
||||
{
|
||||
this.frozen = frozen;
|
||||
}
|
||||
}
|
||||
|
||||
public void setMuted(boolean muted)
|
||||
{
|
||||
PunishedPlayerMuteEvent e = new PunishedPlayerMuteEvent(this, this.muted);
|
||||
Bukkit.getServer().getPluginManager().callEvent(e);
|
||||
if (!e.isCancelled())
|
||||
{
|
||||
this.muted = muted;
|
||||
}
|
||||
}
|
||||
|
||||
public File getPunishmentsFile()
|
||||
{
|
||||
File folder = new File(Plex.get().getDataFolder() + File.separator + "punishments");
|
||||
if (!folder.exists())
|
||||
{
|
||||
folder.mkdir();
|
||||
}
|
||||
|
||||
File file = new File(folder, getUuid() + ".json");
|
||||
if (!file.exists())
|
||||
{
|
||||
try {
|
||||
file.createNewFile();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
return file;
|
||||
|
||||
}
|
||||
|
||||
public List<Punishment> getPunishments()
|
||||
{
|
||||
List<Punishment> punishments = Lists.newArrayList();
|
||||
|
||||
File file = getPunishmentsFile();
|
||||
|
||||
if (isNotEmpty(file))
|
||||
{
|
||||
try {
|
||||
JSONTokener tokener = new JSONTokener(new FileInputStream(file));
|
||||
JSONObject object = new JSONObject(tokener);
|
||||
object.getJSONObject(getUuid()).getJSONArray("punishments").forEach(obj -> {
|
||||
Punishment punishment = Punishment.fromJson(obj.toString());
|
||||
punishments.add(punishment);
|
||||
});
|
||||
} catch (FileNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
return punishments;
|
||||
}
|
||||
|
||||
private boolean isNotEmpty(File file) {
|
||||
try {
|
||||
return !FileUtils.readFileToString(file, StandardCharsets.UTF_8).trim().isEmpty();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user