Rework activity
This commit is contained in:
34
src/main/java/dev/heliosares/auxprotect/core/Activity.java
Normal file
34
src/main/java/dev/heliosares/auxprotect/core/Activity.java
Normal file
@@ -0,0 +1,34 @@
|
||||
package dev.heliosares.auxprotect.core;
|
||||
|
||||
public enum Activity {
|
||||
|
||||
IN_SPAWN('$', 100),
|
||||
COMMAND('/', 5),
|
||||
CHAT('c', 5),
|
||||
DAMAGE('d', 0.25),
|
||||
INTERACT_ENTITY('e', 1),
|
||||
INTERACT_BLOCK('f', 1),
|
||||
INTERACT_AIR('g', 1),
|
||||
CLICK_ITEM('i', 1),
|
||||
OPEN_INVENTORY('o', 1),
|
||||
PICKUP('p', 1),
|
||||
DROP('q', 1),
|
||||
BLOCK_BREAK('r', 1),
|
||||
BLOCK_PLACE('s', 1);
|
||||
|
||||
|
||||
public final char character;
|
||||
public final double score;
|
||||
|
||||
Activity(char character, double score) {
|
||||
this.character = character;
|
||||
this.score = score;
|
||||
}
|
||||
|
||||
public static Activity getByChar(char c) {
|
||||
for (Activity value : values()) {
|
||||
if (value.character == c) return value;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
package dev.heliosares.auxprotect.core;
|
||||
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
|
||||
public record ActivityRecord(@Nonnull List<Activity> activities, double distanceMoved) {
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder activityString = new StringBuilder(getActivityString());
|
||||
|
||||
activityString.append(";");
|
||||
final double moved = distanceMoved();
|
||||
if (moved > 1E-6) {
|
||||
if (moved >= 10) {
|
||||
activityString.append((int) Math.round(moved));
|
||||
} else {
|
||||
activityString.append(Math.round(moved * 10) / 10D);
|
||||
}
|
||||
}
|
||||
return activityString.toString();
|
||||
}
|
||||
|
||||
public String getActivityString() {
|
||||
StringBuilder activityString = new StringBuilder();
|
||||
|
||||
for (Activity a : activities()) {
|
||||
activityString.append(a.character);
|
||||
}
|
||||
|
||||
return activityString.toString();
|
||||
}
|
||||
|
||||
public double countScore() {
|
||||
double score = Math.floor((distanceMoved()) / 10);
|
||||
|
||||
if (distanceMoved() > 1E-6) score++;
|
||||
|
||||
for (Activity activity : activities()) {
|
||||
score += activity.score;
|
||||
}
|
||||
|
||||
return score;
|
||||
}
|
||||
|
||||
public static ActivityRecord parse(String data) throws IllegalArgumentException {
|
||||
if (data == null) return null;
|
||||
|
||||
if (data.matches("\\d+")) {
|
||||
throw new IllegalArgumentException("Legacy activity");
|
||||
}
|
||||
if (!data.matches("[^;]*;(\\d+(\\.\\d)?)?")) {
|
||||
throw new IllegalArgumentException("Invalid activity string");
|
||||
}
|
||||
List<Activity> activities = new ArrayList<>();
|
||||
if (data.startsWith(";")) data = " " + data;
|
||||
if (data.endsWith(";")) data += " ";
|
||||
String[] parts = data.split(";");
|
||||
|
||||
if (parts.length != 2) {
|
||||
throw new IllegalArgumentException("Invalid activity string format");
|
||||
}
|
||||
|
||||
for (char c : parts[0].trim().toCharArray()) {
|
||||
activities.add(Activity.getByChar(c));
|
||||
}
|
||||
|
||||
double distance = parts[1].isBlank() ? 0 : Double.parseDouble(parts[1].trim());
|
||||
|
||||
return new ActivityRecord(activities, distance);
|
||||
}
|
||||
|
||||
public String getHoverText() {
|
||||
StringBuilder hoverText = new StringBuilder("\n\n");
|
||||
hoverText.append(ChatColor.COLOR_CHAR + "7Activity: " + ChatColor.COLOR_CHAR + "9").append(getActivityString()).append("\n");
|
||||
for (Activity activity : new HashSet<>(activities())) {
|
||||
hoverText.append(ChatColor.COLOR_CHAR + "7 ").append(activity.character).append(" = ").append(activity.toString().toLowerCase()).append(" (").append(activity.score).append(")\n");
|
||||
}
|
||||
hoverText.append(ChatColor.COLOR_CHAR + "7Moved " + ChatColor.COLOR_CHAR + "9").append(distanceMoved()).append(ChatColor.COLOR_CHAR).append("7 Blocks");
|
||||
return hoverText.toString();
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,9 @@
|
||||
package dev.heliosares.auxprotect.database;
|
||||
|
||||
import dev.heliosares.auxprotect.adapters.sender.SenderAdapter;
|
||||
import dev.heliosares.auxprotect.api.AuxProtectAPI;
|
||||
import dev.heliosares.auxprotect.core.APPermission;
|
||||
import dev.heliosares.auxprotect.core.APPlayer;
|
||||
import dev.heliosares.auxprotect.core.ActivityRecord;
|
||||
import dev.heliosares.auxprotect.core.IAuxProtect;
|
||||
import dev.heliosares.auxprotect.core.Language;
|
||||
import dev.heliosares.auxprotect.core.Parameters;
|
||||
@@ -185,12 +185,24 @@ public class Results {
|
||||
}
|
||||
String data = entry.getData();
|
||||
if (data != null && !data.isEmpty()) {
|
||||
HoverEvent hoverEvent = clickToCopy;
|
||||
if (entry.getAction().equals(EntryAction.ACTIVITY)) {
|
||||
try {
|
||||
ActivityRecord record = ActivityRecord.parse(data);
|
||||
if (record != null) {
|
||||
message.append(" " + org.bukkit.ChatColor.COLOR_CHAR + "a" + record.countScore());
|
||||
hoverEvent = new HoverEvent(HoverEvent.Action.SHOW_TEXT, new Text(Language.L.RESULTS__CLICK_TO_COPY.translate() + record.getHoverText()));
|
||||
}
|
||||
} catch (IllegalArgumentException ignored) {
|
||||
message.append(ignored.getMessage());
|
||||
}
|
||||
}
|
||||
if (entry.getAction().equals(EntryAction.SESSION) && !APPermission.LOOKUP_ACTION.dot(EntryAction.SESSION.toString().toLowerCase()).dot("ip").hasPermission(player)) {
|
||||
message.append(" " + ChatColor.COLOR_CHAR + "8[" + ChatColor.COLOR_CHAR + "7" + Language.L.RESULTS__REDACTED.translate() + ChatColor.COLOR_CHAR + "8]");
|
||||
message.event((ClickEvent) null).event((HoverEvent) null);
|
||||
} else {
|
||||
message.append(" " + ChatColor.COLOR_CHAR + "8[" + ChatColor.COLOR_CHAR + "7" + data + ChatColor.COLOR_CHAR + "8]");
|
||||
message.event(clickToCopy).event(new ClickEvent(ClickEvent.Action.COPY_TO_CLIPBOARD, data));
|
||||
message.event(hoverEvent).event(new ClickEvent(ClickEvent.Action.COPY_TO_CLIPBOARD, data));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package dev.heliosares.auxprotect.spigot;
|
||||
|
||||
import dev.heliosares.auxprotect.core.APPlayer;
|
||||
import dev.heliosares.auxprotect.core.Activity;
|
||||
import dev.heliosares.auxprotect.core.ActivityRecord;
|
||||
import dev.heliosares.auxprotect.core.IAuxProtect;
|
||||
import dev.heliosares.auxprotect.database.DbEntry;
|
||||
import dev.heliosares.auxprotect.database.EntryAction;
|
||||
@@ -13,11 +15,12 @@ import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
public class APPlayerSpigot extends APPlayer<Player> {
|
||||
public final double[] activity = new double[30];
|
||||
private final List<ActivityRecord> activityStack = new ArrayList<>();
|
||||
private ArrayList<Activity> currentActivity;
|
||||
private final Player player;
|
||||
private final List<Byte> posBlob = new ArrayList<>();
|
||||
public long lastLoggedMoney;
|
||||
@@ -25,12 +28,10 @@ public class APPlayerSpigot extends APPlayer<Player> {
|
||||
public long lastLoggedInventoryDiff;
|
||||
public long lastLoggedPos;
|
||||
public long lastMoved;
|
||||
public long lastLoggedActivity;
|
||||
public Location lastLocation;
|
||||
public long lastCheckedMovement;
|
||||
public double movedAmountThisMinute;
|
||||
private double movedAmountThisMinute;
|
||||
public boolean hasMovedThisMinute;
|
||||
public int activityIndex;
|
||||
public long lastNotifyInactive;
|
||||
// hotbar, main, armor, offhand, echest
|
||||
private List<ItemStack> invDiffItems;
|
||||
@@ -41,7 +42,6 @@ public class APPlayerSpigot extends APPlayer<Player> {
|
||||
super(plugin, player);
|
||||
|
||||
this.player = player;
|
||||
Arrays.fill(activity, -1);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -49,8 +49,45 @@ public class APPlayerSpigot extends APPlayer<Player> {
|
||||
return player.getName();
|
||||
}
|
||||
|
||||
public void addActivity(double d) {
|
||||
activity[activityIndex] += d;
|
||||
public void addActivity(Activity a) {
|
||||
synchronized (activityStack) {
|
||||
if (currentActivity == null) currentActivity = new ArrayList<>();
|
||||
currentActivity.add(a);
|
||||
}
|
||||
}
|
||||
|
||||
public String concludeActivityForMinute() {
|
||||
synchronized (activityStack) {
|
||||
while (activityStack.size() >= 30) {
|
||||
activityStack.remove(0);
|
||||
}
|
||||
ActivityRecord record = null;
|
||||
if (currentActivity != null || movedAmountThisMinute > 1E-6) {
|
||||
if (currentActivity == null) currentActivity = new ArrayList<>();
|
||||
record = new ActivityRecord(currentActivity, movedAmountThisMinute);
|
||||
}
|
||||
activityStack.add(record);
|
||||
currentActivity = null;
|
||||
movedAmountThisMinute = 0;
|
||||
hasMovedThisMinute = false;
|
||||
|
||||
if (record == null) return null;
|
||||
return record.toString();
|
||||
}
|
||||
}
|
||||
|
||||
public void move() {
|
||||
synchronized (activityStack) {
|
||||
if (lastLocation != null && Objects.equals(lastLocation.getWorld(), getPlayer().getWorld())) {
|
||||
movedAmountThisMinute += Math.min(lastLocation.distance(getPlayer().getLocation()), 10);
|
||||
}
|
||||
lastLocation = getPlayer().getLocation();
|
||||
lastCheckedMovement = System.currentTimeMillis();
|
||||
}
|
||||
}
|
||||
|
||||
public List<ActivityRecord> getActivityStack() {
|
||||
return activityStack;
|
||||
}
|
||||
|
||||
public long logInventory(String reason) {
|
||||
|
||||
@@ -6,6 +6,8 @@ import dev.heliosares.auxprotect.adapters.sender.SpigotSenderAdapter;
|
||||
import dev.heliosares.auxprotect.api.AuxProtectAPI;
|
||||
import dev.heliosares.auxprotect.core.APConfig;
|
||||
import dev.heliosares.auxprotect.core.APPermission;
|
||||
import dev.heliosares.auxprotect.core.Activity;
|
||||
import dev.heliosares.auxprotect.core.ActivityRecord;
|
||||
import dev.heliosares.auxprotect.core.IAuxProtect;
|
||||
import dev.heliosares.auxprotect.core.Language;
|
||||
import dev.heliosares.auxprotect.core.PlatformType;
|
||||
@@ -64,6 +66,7 @@ import java.sql.SQLException;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
@@ -358,6 +361,7 @@ public final class AuxProtectSpigot extends JavaPlugin implements IAuxProtect {
|
||||
new BukkitRunnable() {
|
||||
|
||||
private boolean running;
|
||||
private int lastLoggedActivityMinute = -1;
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
@@ -371,6 +375,15 @@ public final class AuxProtectSpigot extends JavaPlugin implements IAuxProtect {
|
||||
synchronized (apPlayers) {
|
||||
players = new ArrayList<>(apPlayers.values());
|
||||
}
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
int minute = calendar.get(Calendar.MINUTE);
|
||||
int second = calendar.get(Calendar.SECOND);
|
||||
|
||||
boolean logActivity = lastLoggedActivityMinute != minute && second >= 30;
|
||||
// Put in the middle of the minute to make parsing it later easier
|
||||
if (logActivity) {
|
||||
lastLoggedActivityMinute = minute;
|
||||
}
|
||||
for (APPlayerSpigot apPlayer : players) {
|
||||
if (!apPlayer.getPlayer().isOnline()) {
|
||||
continue;
|
||||
@@ -403,43 +416,25 @@ public final class AuxProtectSpigot extends JavaPlugin implements IAuxProtect {
|
||||
}
|
||||
|
||||
if (System.currentTimeMillis() - apPlayer.lastCheckedMovement >= 1000) {
|
||||
if (apPlayer.lastLocation != null
|
||||
&& Objects.equals(apPlayer.lastLocation.getWorld(), apPlayer.getPlayer().getWorld())) {
|
||||
apPlayer.movedAmountThisMinute += Math
|
||||
.min(apPlayer.lastLocation.distance(apPlayer.getPlayer().getLocation()), 10);
|
||||
}
|
||||
apPlayer.lastLocation = apPlayer.getPlayer().getLocation();
|
||||
apPlayer.lastCheckedMovement = System.currentTimeMillis();
|
||||
apPlayer.move();
|
||||
}
|
||||
|
||||
if (apPlayer.lastLoggedActivity == 0) {
|
||||
apPlayer.lastLoggedActivity = System.currentTimeMillis();
|
||||
}
|
||||
if (System.currentTimeMillis() - apPlayer.lastLoggedActivity > 60000L && config.isPrivate()) {
|
||||
if (logActivity && config.isPrivate()) {
|
||||
if (apPlayer.getPlayer().getWorld().getName().equals("flat") && config.isPrivate()) {
|
||||
apPlayer.activity[apPlayer.activityIndex] += 100;
|
||||
}
|
||||
apPlayer.addActivity(Math.floor((apPlayer.movedAmountThisMinute + 7) / 10));
|
||||
apPlayer.movedAmountThisMinute = 0;
|
||||
|
||||
if (apPlayer.hasMovedThisMinute) {
|
||||
apPlayer.addActivity(1);
|
||||
apPlayer.hasMovedThisMinute = false;
|
||||
apPlayer.addActivity(Activity.IN_SPAWN);
|
||||
}
|
||||
|
||||
add(new DbEntry(AuxProtectSpigot.getLabel(apPlayer.getPlayer()), EntryAction.ACTIVITY, false,
|
||||
apPlayer.getPlayer().getLocation(), "",
|
||||
(int) Math.round(apPlayer.activity[apPlayer.activityIndex]) + ""));
|
||||
apPlayer.lastLoggedActivity = System.currentTimeMillis();
|
||||
add(new DbEntry(AuxProtectSpigot.getLabel(apPlayer.getPlayer()), EntryAction.ACTIVITY, false, apPlayer.getPlayer().getLocation(), "", apPlayer.concludeActivityForMinute()));
|
||||
|
||||
int tallied = 0;
|
||||
int inactive = 0;
|
||||
for (double activity : apPlayer.activity) {
|
||||
if (activity < 0) {
|
||||
for (ActivityRecord record : apPlayer.getActivityStack()) {
|
||||
if (record == null || record.activities().isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
tallied++;
|
||||
if (activity < 10) {
|
||||
if (record.countScore() < 10) {
|
||||
inactive++;
|
||||
}
|
||||
}
|
||||
@@ -459,12 +454,6 @@ public final class AuxProtectSpigot extends JavaPlugin implements IAuxProtect {
|
||||
apPlayer.getPlayer().getLocation(), "inactive", inactive + "/" + tallied));
|
||||
}
|
||||
}
|
||||
|
||||
apPlayer.activityIndex++;
|
||||
if (apPlayer.activityIndex >= apPlayer.activity.length) {
|
||||
apPlayer.activityIndex = 0;
|
||||
}
|
||||
apPlayer.activity[apPlayer.activityIndex] = 0;
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package dev.heliosares.auxprotect.spigot.listeners;
|
||||
|
||||
import dev.heliosares.auxprotect.core.APPermission;
|
||||
import dev.heliosares.auxprotect.core.Activity;
|
||||
import dev.heliosares.auxprotect.core.IAuxProtect;
|
||||
import dev.heliosares.auxprotect.database.DbEntry;
|
||||
import dev.heliosares.auxprotect.database.EntryAction;
|
||||
@@ -147,7 +148,7 @@ public class EntityListener implements Listener {
|
||||
if (e.getCause() == DamageCause.THORNS) {
|
||||
itemname += "THORNS";
|
||||
} else if (source instanceof Player sourcePl) {
|
||||
plugin.getAPPlayer(sourcePl).addActivity(0.25);
|
||||
plugin.getAPPlayer(sourcePl).addActivity(Activity.DAMAGE);
|
||||
itemname += sourcePl.getInventory().getItemInMainHand().getType().toString().toLowerCase();
|
||||
}
|
||||
|
||||
@@ -252,7 +253,7 @@ public class EntityListener implements Listener {
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||
public void onPlayerDropEvent(PlayerDropItemEvent e) {
|
||||
plugin.getAPPlayer(e.getPlayer()).addActivity(1);
|
||||
plugin.getAPPlayer(e.getPlayer()).addActivity(Activity.DROP);
|
||||
|
||||
if (isChartMap(e.getItemDrop().getItemStack())) {
|
||||
e.getItemDrop().remove();
|
||||
@@ -266,7 +267,7 @@ public class EntityListener implements Listener {
|
||||
public void onPickupEvent(EntityPickupItemEvent e) {
|
||||
if (e.getEntity() instanceof Player player) {
|
||||
|
||||
plugin.getAPPlayer(player).addActivity(1);
|
||||
plugin.getAPPlayer(player).addActivity(Activity.PICKUP);
|
||||
|
||||
if (isChartMap(e.getItem().getItemStack()) && !APPermission.LOOKUP_MONEY.hasPermission(player)) {
|
||||
e.setCancelled(true);
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package dev.heliosares.auxprotect.spigot.listeners;
|
||||
|
||||
import dev.heliosares.auxprotect.api.AuxProtectAPI;
|
||||
import dev.heliosares.auxprotect.core.Activity;
|
||||
import dev.heliosares.auxprotect.database.DbEntry;
|
||||
import dev.heliosares.auxprotect.database.EntryAction;
|
||||
import dev.heliosares.auxprotect.database.SingleItemEntry;
|
||||
@@ -10,11 +11,17 @@ import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.HumanEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.enchantment.EnchantItemEvent;
|
||||
import org.bukkit.event.inventory.*;
|
||||
import org.bukkit.event.inventory.ClickType;
|
||||
import org.bukkit.event.inventory.CraftItemEvent;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.event.inventory.InventoryCloseEvent;
|
||||
import org.bukkit.event.inventory.InventoryOpenEvent;
|
||||
import org.bukkit.event.inventory.InventoryType;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
@@ -30,6 +37,7 @@ public class InventoryListener implements Listener {
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||
public void onInventoryOpenEvent(InventoryOpenEvent e) {
|
||||
plugin.getAPPlayer((Player) e.getPlayer()).addActivity(Activity.OPEN_INVENTORY);
|
||||
log(e.getPlayer(), e.getInventory(), true);
|
||||
}
|
||||
|
||||
@@ -70,11 +78,12 @@ public class InventoryListener implements Listener {
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||
public void onInventoryClick(InventoryClickEvent e) {
|
||||
plugin.getAPPlayer((Player) e.getWhoClicked()).addActivity(Activity.CLICK_ITEM);
|
||||
|
||||
InventoryType type = e.getWhoClicked().getOpenInventory().getTopInventory().getType();
|
||||
if (e.getSlotType() != InventoryType.SlotType.RESULT) return;
|
||||
if (e.getCurrentItem() == null || e.getCurrentItem().getType() == Material.AIR) return;
|
||||
|
||||
|
||||
EntryAction action;
|
||||
String data = "";
|
||||
ItemStack[] entryItems;
|
||||
|
||||
@@ -2,6 +2,7 @@ package dev.heliosares.auxprotect.spigot.listeners;
|
||||
|
||||
import dev.heliosares.auxprotect.adapters.sender.SpigotSenderAdapter;
|
||||
import dev.heliosares.auxprotect.core.APPermission;
|
||||
import dev.heliosares.auxprotect.core.Activity;
|
||||
import dev.heliosares.auxprotect.core.Language;
|
||||
import dev.heliosares.auxprotect.database.DbEntry;
|
||||
import dev.heliosares.auxprotect.database.EntryAction;
|
||||
@@ -27,6 +28,8 @@ import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.block.Action;
|
||||
import org.bukkit.event.block.BlockBreakEvent;
|
||||
import org.bukkit.event.block.BlockPlaceEvent;
|
||||
import org.bukkit.event.entity.EntityPlaceEvent;
|
||||
import org.bukkit.event.entity.EntityToggleGlideEvent;
|
||||
import org.bukkit.event.entity.PlayerLeashEntityEvent;
|
||||
@@ -115,7 +118,7 @@ public class PlayerListener implements Listener {
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||
public void onPlayerInteractEntityEvent(PlayerInteractEntityEvent e) {
|
||||
plugin.getAPPlayer(e.getPlayer()).addActivity(1);
|
||||
plugin.getAPPlayer(e.getPlayer()).addActivity(Activity.INTERACT_ENTITY);
|
||||
|
||||
ItemStack item = e.getPlayer().getInventory().getItem(e.getHand());
|
||||
|
||||
@@ -156,7 +159,7 @@ public class PlayerListener implements Listener {
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||
public void onPlayerInteractEvent(PlayerInteractEvent e) {
|
||||
plugin.getAPPlayer(e.getPlayer()).addActivity(1);
|
||||
plugin.getAPPlayer(e.getPlayer()).addActivity(e.getClickedBlock() == null ? Activity.INTERACT_AIR : Activity.INTERACT_BLOCK);
|
||||
|
||||
if (e.useInteractedBlock() == Result.DENY) {
|
||||
return;
|
||||
@@ -366,7 +369,7 @@ public class PlayerListener implements Listener {
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||
public void onCommand(PlayerCommandPreprocessEvent e) {
|
||||
plugin.getAPPlayer(e.getPlayer()).addActivity(5);
|
||||
plugin.getAPPlayer(e.getPlayer()).addActivity(Activity.COMMAND);
|
||||
|
||||
plugin.add(new DbEntry(AuxProtectSpigot.getLabel(e.getPlayer()), EntryAction.COMMAND, false,
|
||||
e.getPlayer().getLocation(), e.getMessage(), ""));
|
||||
@@ -374,11 +377,21 @@ public class PlayerListener implements Listener {
|
||||
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void onChat(AsyncPlayerChatEvent e) {
|
||||
plugin.getAPPlayer(e.getPlayer()).addActivity(5);
|
||||
plugin.getAPPlayer(e.getPlayer()).addActivity(Activity.CHAT);
|
||||
plugin.add(new DbEntry(AuxProtectSpigot.getLabel(e.getPlayer()), EntryAction.CHAT, false, e.getPlayer().getLocation(), e.getMessage().trim(), ""));
|
||||
if (plugin.getAPConfig().isDemoMode()) {
|
||||
e.getPlayer().sendMessage(ChatColor.COLOR_CHAR + "cChat is disabled.");
|
||||
e.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR)
|
||||
public void onBlockPlace(BlockPlaceEvent e) {
|
||||
plugin.getAPPlayer(e.getPlayer()).addActivity(Activity.BLOCK_PLACE);
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR)
|
||||
public void onBlockBreak(BlockBreakEvent e) {
|
||||
plugin.getAPPlayer(e.getPlayer()).addActivity(Activity.BLOCK_BREAK);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package dev.heliosares.auxprotect.utils;
|
||||
|
||||
import dev.heliosares.auxprotect.core.Activity;
|
||||
import dev.heliosares.auxprotect.core.ActivityRecord;
|
||||
import dev.heliosares.auxprotect.database.DbEntry;
|
||||
import dev.heliosares.auxprotect.database.EntryAction;
|
||||
import dev.heliosares.auxprotect.spigot.AuxProtectSpigot;
|
||||
@@ -19,6 +21,7 @@ import java.time.ZoneId;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
|
||||
public class ActivitySolver {
|
||||
@@ -30,7 +33,7 @@ public class ActivitySolver {
|
||||
DateTimeFormatter formatterHour = DateTimeFormatter.ofPattern("Ka");
|
||||
final long startMillis = startTime.atZone(ZoneId.systemDefault()).toInstant().toEpochMilli();
|
||||
final int minutes = (int) Math.ceil((rangeEnd - rangeStart) / 1000.0 / 60.0);
|
||||
int[] counter = new int[minutes];
|
||||
double[] counter = new double[minutes];
|
||||
Location[] locations = new Location[minutes];
|
||||
Arrays.fill(counter, -1);
|
||||
StringBuilder line = new StringBuilder("" + ChatColor.COLOR_CHAR + "7" + ChatColor.COLOR_CHAR + "m");
|
||||
@@ -41,6 +44,8 @@ public class ActivitySolver {
|
||||
components.add(message.create());
|
||||
message = new ComponentBuilder();
|
||||
|
||||
ActivityRecord[] activityRecords = new ActivityRecord[minutes];
|
||||
|
||||
long lastTime = startMillis;
|
||||
for (int i = entries.size() - 1, minute = 0; i >= 0; i--) {
|
||||
DbEntry entry = entries.get(i);
|
||||
@@ -70,7 +75,20 @@ public class ActivitySolver {
|
||||
counter[minute] = 0;
|
||||
}
|
||||
|
||||
int activity = Integer.parseInt(entry.getData());
|
||||
|
||||
double activity = 0;
|
||||
try {
|
||||
ActivityRecord record = ActivityRecord.parse(entry.getData());
|
||||
activityRecords[minute] = record;
|
||||
if (record != null) {
|
||||
activity = record.countScore();
|
||||
}
|
||||
} catch (IllegalArgumentException e) {
|
||||
try {
|
||||
activity = Integer.parseInt(entry.getData());
|
||||
} catch (IllegalArgumentException ignored) {
|
||||
}
|
||||
}
|
||||
counter[minute] += activity;
|
||||
locations[minute] = new Location(Bukkit.getWorld(entry.getWorld()), entry.getX(), entry.getY(), entry.getZ());
|
||||
|
||||
@@ -103,7 +121,7 @@ public class ActivitySolver {
|
||||
message.color(ChatColor.BLACK);
|
||||
} else {
|
||||
|
||||
int activity = counter[i];
|
||||
double activity = counter[i];
|
||||
|
||||
String hovertext = ChatColor.COLOR_CHAR + "9" + time.format(formatterDateTime) + "\n";
|
||||
|
||||
@@ -124,6 +142,11 @@ public class ActivitySolver {
|
||||
locations[i].getWorld().getName()));
|
||||
}
|
||||
|
||||
ActivityRecord activityRecord = activityRecords[i];
|
||||
if (activityRecord != null) {
|
||||
hovertext += activityRecord.getHoverText();
|
||||
}
|
||||
|
||||
message.append(AuxProtectSpigot.BLOCK + "")
|
||||
.event(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new Text(hovertext))).event(clickevent);
|
||||
if (activity >= 20) {
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
package dev.heliosares.auxprotect.core;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
public class ActivityTest {
|
||||
@Test
|
||||
public void checkNoDuplicateCharacters() {
|
||||
Set<Character> chars = new HashSet<>();
|
||||
for (Activity activity : Activity.values()) {
|
||||
if (!chars.add(activity.character)) {
|
||||
throw new IllegalArgumentException("Duplicate characters " + activity.character);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testActivityParsing() {
|
||||
ActivityRecord record = new ActivityRecord(List.of(Activity.values()), 0.69);
|
||||
String data = record.toString();
|
||||
System.out.println(data);
|
||||
|
||||
ActivityRecord parsed = ActivityRecord.parse(data);
|
||||
String dataParsed = parsed.toString();
|
||||
|
||||
assertEquals(data, dataParsed);
|
||||
|
||||
assertEquals(record.distanceMoved(), parsed.distanceMoved(), 0.1);
|
||||
|
||||
assertEquals(record.activities(), parsed.activities());
|
||||
|
||||
assertNotNull(ActivityRecord.parse(";"));
|
||||
assertNotNull(ActivityRecord.parse(";0"));
|
||||
assertNotNull(ActivityRecord.parse(";0.0"));
|
||||
assertNotNull(ActivityRecord.parse("/;0.0"));
|
||||
assertNotNull(ActivityRecord.parse("/;0"));
|
||||
assertNotNull(ActivityRecord.parse("/;"));
|
||||
assertNotNull(ActivityRecord.parse("///;"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testActivityScoring() {
|
||||
ActivityRecord record = new ActivityRecord(List.of(Activity.values()), 0);
|
||||
double totalScore = 0;
|
||||
for (Activity activity : Activity.values()) {
|
||||
totalScore += activity.score;
|
||||
}
|
||||
assertEquals(totalScore, record.countScore(), 1E-6);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user