diff --git a/pom.xml b/pom.xml
index 199a6af..97e635c 100644
--- a/pom.xml
+++ b/pom.xml
@@ -44,6 +44,13 @@
20200518
compile
+
+ commons-io
+ commons-io
+ 2.8.0
+ compile
+
+
diff --git a/src/main/java/me/totalfreedom/plex/Plex.java b/src/main/java/me/totalfreedom/plex/Plex.java
index 52fe507..4a76671 100644
--- a/src/main/java/me/totalfreedom/plex/Plex.java
+++ b/src/main/java/me/totalfreedom/plex/Plex.java
@@ -8,6 +8,7 @@ import me.totalfreedom.plex.cache.SQLPlayerData;
import me.totalfreedom.plex.config.Config;
import me.totalfreedom.plex.handlers.CommandHandler;
import me.totalfreedom.plex.handlers.ListenerHandler;
+import me.totalfreedom.plex.punishment.PunishmentManager;
import me.totalfreedom.plex.rank.RankManager;
import me.totalfreedom.plex.storage.MongoConnection;
import me.totalfreedom.plex.storage.RedisConnection;
@@ -36,6 +37,8 @@ public class Plex extends JavaPlugin
private RankManager rankManager;
+ private PunishmentManager punishmentManager;
+
private AdminList adminList;
public static Plex get()
@@ -97,6 +100,9 @@ public class Plex extends JavaPlugin
rankManager.importDefaultRanks();
PlexLog.log("Rank Manager initialized");
+ punishmentManager = new PunishmentManager();
+ PlexLog.log("Punishment Manager initialized");
+
adminList = new AdminList();
generateWorlds();
diff --git a/src/main/java/me/totalfreedom/plex/cache/DataUtils.java b/src/main/java/me/totalfreedom/plex/cache/DataUtils.java
index df3b7c2..03592c3 100644
--- a/src/main/java/me/totalfreedom/plex/cache/DataUtils.java
+++ b/src/main/java/me/totalfreedom/plex/cache/DataUtils.java
@@ -8,6 +8,8 @@ import org.bukkit.Bukkit;
public class DataUtils
{
+ /* PLEX PLAYER METHODS */
+
public static boolean hasPlayedBefore(UUID uuid)
{
if (Plex.get().getStorageType() == StorageType.MONGO)
@@ -64,4 +66,6 @@ public class DataUtils
}
}
+ /* REDIS METHODS AT ONE POINT FOR BANS, AND JSON METHODS FOR PUNISHMENTS */
+
}
diff --git a/src/main/java/me/totalfreedom/plex/listener/impl/PlayerListener.java b/src/main/java/me/totalfreedom/plex/listener/impl/PlayerListener.java
index 909dc05..5388f22 100644
--- a/src/main/java/me/totalfreedom/plex/listener/impl/PlayerListener.java
+++ b/src/main/java/me/totalfreedom/plex/listener/impl/PlayerListener.java
@@ -11,6 +11,8 @@ import me.totalfreedom.plex.command.impl.FionnCMD;
import me.totalfreedom.plex.listener.PlexListener;
import me.totalfreedom.plex.player.PlexPlayer;
import me.totalfreedom.plex.player.PunishedPlayer;
+import me.totalfreedom.plex.punishment.Punishment;
+import me.totalfreedom.plex.punishment.PunishmentType;
import me.totalfreedom.plex.util.PlexLog;
import org.bukkit.ChatColor;
import org.bukkit.Location;
@@ -99,8 +101,14 @@ public class PlayerListener extends PlexListener
{
event.setJoinMessage(ChatColor.AQUA + player.getName() + " is " + plexPlayer.getRankFromString().getLoginMSG());
}
-
}
+
+ /*Punishment test = new Punishment(player.getUniqueId(), player.getUniqueId());
+ test.setPunishedUsername(player.getName());
+ test.setReason("hii");
+ test.setType(PunishmentType.FREEZE);
+ plugin.getPunishmentManager().insertPunishment(PlayerCache.getPunishedPlayer(player.getUniqueId()), test);*/
+
}
// saving the player's data
diff --git a/src/main/java/me/totalfreedom/plex/punishment/Punishment.java b/src/main/java/me/totalfreedom/plex/punishment/Punishment.java
new file mode 100644
index 0000000..727a5bf
--- /dev/null
+++ b/src/main/java/me/totalfreedom/plex/punishment/Punishment.java
@@ -0,0 +1,51 @@
+package me.totalfreedom.plex.punishment;
+
+import com.google.common.collect.Lists;
+import com.google.gson.Gson;
+import lombok.Getter;
+import lombok.Setter;
+
+import java.util.List;
+import java.util.UUID;
+
+@Getter
+@Setter
+public class Punishment
+{
+
+ private final UUID punished;
+ private final UUID punisher;
+
+ private final List IPS;
+
+ private String punishedUsername;
+
+ private PunishmentType type;
+ private String reason;
+ private boolean customTime;
+ private long endDate;
+
+ public Punishment(UUID punished, UUID punisher)
+ {
+ this.punished = punished;
+ this.punisher = punisher;
+ this.IPS = Lists.newArrayList();
+
+ this.punishedUsername = "";
+ this.type = null;
+ this.reason = "";
+ this.customTime = false;
+ this.endDate = 0;
+ }
+
+ public String toJSON()
+ {
+ return new Gson().toJson(this);
+ }
+
+ public static Punishment fromJson(String json)
+ {
+ return new Gson().fromJson(json, Punishment.class);
+ }
+
+}
diff --git a/src/main/java/me/totalfreedom/plex/punishment/PunishmentManager.java b/src/main/java/me/totalfreedom/plex/punishment/PunishmentManager.java
new file mode 100644
index 0000000..cadd49b
--- /dev/null
+++ b/src/main/java/me/totalfreedom/plex/punishment/PunishmentManager.java
@@ -0,0 +1,84 @@
+package me.totalfreedom.plex.punishment;
+
+import com.google.common.collect.Lists;
+import com.google.common.collect.Maps;
+import me.totalfreedom.plex.Plex;
+import me.totalfreedom.plex.cache.DataUtils;
+import me.totalfreedom.plex.player.PunishedPlayer;
+import me.totalfreedom.plex.util.PlexLog;
+import org.apache.commons.io.FileUtils;
+import org.json.JSONObject;
+import org.json.JSONTokener;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.nio.charset.StandardCharsets;
+import java.util.List;
+import java.util.Map;
+
+public class PunishmentManager
+{
+
+ public void insertPunishment(PunishedPlayer player, Punishment punishment)
+ {
+ File folder = new File(Plex.get().getDataFolder() + File.separator + "punishments");
+ if (!folder.exists())
+ {
+ folder.mkdir();
+ }
+
+ File file = new File(folder, player.getUuid() + ".json");
+ if (!file.exists())
+ {
+ try {
+ file.createNewFile();
+ PlexLog.log("Created new punishment file for " + player.getUuid() + " (" + DataUtils.getPlayer(punishment.getPunished()).getName() + ")");
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+
+ try {
+ if (isNotEmpty(file))
+ {
+ JSONTokener tokener = new JSONTokener(new FileInputStream(file));
+ JSONObject object = new JSONObject(tokener);
+ object.getJSONObject(punishment.getPunished().toString()).getJSONArray("punishments").put(punishment.toJSON());
+
+ FileWriter writer = new FileWriter(file);
+ writer.append(object.toString(8));
+ writer.flush();
+ writer.close();
+ } else {
+ JSONObject object = new JSONObject();
+ Map> punishments = Maps.newHashMap();
+
+ List punishmentList = Lists.newArrayList();
+ punishmentList.add(punishment.toJSON());
+
+ punishments.put("punishments", punishmentList);
+ object.put(punishment.getPunished().toString(), punishments);
+
+ FileWriter writer = new FileWriter(file);
+ writer.append(object.toString(8));
+ writer.flush();
+ writer.close();
+ }
+
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+
+ private boolean isNotEmpty(File file) {
+ try {
+ return !FileUtils.readFileToString(file, StandardCharsets.UTF_8).trim().isEmpty();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ return false;
+ }
+
+}
diff --git a/src/main/java/me/totalfreedom/plex/punishment/PunishmentType.java b/src/main/java/me/totalfreedom/plex/punishment/PunishmentType.java
new file mode 100644
index 0000000..aa200ad
--- /dev/null
+++ b/src/main/java/me/totalfreedom/plex/punishment/PunishmentType.java
@@ -0,0 +1,7 @@
+package me.totalfreedom.plex.punishment;
+
+public enum PunishmentType
+{
+ MUTE, FREEZE, BAN;
+
+}