Backup before major refactor of AdminMode based on user feedback
This commit is contained in:
253
src/main/java/org/blz/adminmode/moderation/ModeSession.java
Normal file
253
src/main/java/org/blz/adminmode/moderation/ModeSession.java
Normal file
@@ -0,0 +1,253 @@
|
||||
package org.blz.adminmode.moderation;
|
||||
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.attribute.Attribute;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.potion.PotionEffect;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
public final class ModeSession {
|
||||
|
||||
private final UUID playerId;
|
||||
private final String playerName;
|
||||
private final ModeratorProfile profile;
|
||||
private final long startTimestamp;
|
||||
private final String previousGroup;
|
||||
private final String activeGroup;
|
||||
private final ItemStack[] inventoryContents;
|
||||
private final ItemStack[] armorContents;
|
||||
private final ItemStack offHandItem;
|
||||
private final Location location;
|
||||
private final GameMode gameMode;
|
||||
private final double health;
|
||||
private final double maxHealth;
|
||||
private final int foodLevel;
|
||||
private final float saturation;
|
||||
private final float exhaustion;
|
||||
private final int expLevel;
|
||||
private final float exp;
|
||||
private final int totalExperience;
|
||||
private final Collection<PotionEffect> potionEffects;
|
||||
private final boolean flying;
|
||||
private final boolean allowFlight;
|
||||
private final float flySpeed;
|
||||
private final float walkSpeed;
|
||||
private final int fireTicks;
|
||||
|
||||
public ModeSession(
|
||||
UUID playerId,
|
||||
String playerName,
|
||||
ModeratorProfile profile,
|
||||
long startTimestamp,
|
||||
String previousGroup,
|
||||
String activeGroup,
|
||||
ItemStack[] inventoryContents,
|
||||
ItemStack[] armorContents,
|
||||
ItemStack offHandItem,
|
||||
Location location,
|
||||
GameMode gameMode,
|
||||
double health,
|
||||
double maxHealth,
|
||||
int foodLevel,
|
||||
float saturation,
|
||||
float exhaustion,
|
||||
int expLevel,
|
||||
float exp,
|
||||
int totalExperience,
|
||||
Collection<PotionEffect> potionEffects,
|
||||
boolean flying,
|
||||
boolean allowFlight,
|
||||
float flySpeed,
|
||||
float walkSpeed,
|
||||
int fireTicks) {
|
||||
this.playerId = playerId;
|
||||
this.playerName = playerName;
|
||||
this.profile = profile;
|
||||
this.startTimestamp = startTimestamp;
|
||||
this.previousGroup = previousGroup;
|
||||
this.activeGroup = activeGroup;
|
||||
this.inventoryContents = cloneItems(inventoryContents);
|
||||
this.armorContents = cloneItems(armorContents);
|
||||
this.offHandItem = cloneItem(offHandItem);
|
||||
this.location = location == null ? null : location.clone();
|
||||
this.gameMode = gameMode;
|
||||
this.health = health;
|
||||
this.maxHealth = maxHealth;
|
||||
this.foodLevel = foodLevel;
|
||||
this.saturation = saturation;
|
||||
this.exhaustion = exhaustion;
|
||||
this.expLevel = expLevel;
|
||||
this.exp = exp;
|
||||
this.totalExperience = totalExperience;
|
||||
this.potionEffects = potionEffects == null ? List.of() : new ArrayList<>(potionEffects);
|
||||
this.flying = flying;
|
||||
this.allowFlight = allowFlight;
|
||||
this.flySpeed = flySpeed;
|
||||
this.walkSpeed = walkSpeed;
|
||||
this.fireTicks = fireTicks;
|
||||
}
|
||||
|
||||
public static ModeSession capture(Player player, ModeratorProfile profile, String previousGroup, String activeGroup) {
|
||||
double maxHealth = 20.0D;
|
||||
if (player.getAttribute(Attribute.MAX_HEALTH) != null) {
|
||||
maxHealth = player.getAttribute(Attribute.MAX_HEALTH).getBaseValue();
|
||||
}
|
||||
|
||||
return new ModeSession(
|
||||
player.getUniqueId(),
|
||||
player.getName(),
|
||||
profile,
|
||||
System.currentTimeMillis(),
|
||||
previousGroup,
|
||||
activeGroup,
|
||||
player.getInventory().getContents(),
|
||||
player.getInventory().getArmorContents(),
|
||||
player.getInventory().getItemInOffHand(),
|
||||
player.getLocation(),
|
||||
player.getGameMode(),
|
||||
player.getHealth(),
|
||||
maxHealth,
|
||||
player.getFoodLevel(),
|
||||
player.getSaturation(),
|
||||
player.getExhaustion(),
|
||||
player.getLevel(),
|
||||
player.getExp(),
|
||||
player.getTotalExperience(),
|
||||
player.getActivePotionEffects(),
|
||||
player.isFlying(),
|
||||
player.getAllowFlight(),
|
||||
player.getFlySpeed(),
|
||||
player.getWalkSpeed(),
|
||||
player.getFireTicks());
|
||||
}
|
||||
|
||||
public UUID getPlayerId() {
|
||||
return playerId;
|
||||
}
|
||||
|
||||
public String getPlayerName() {
|
||||
return playerName;
|
||||
}
|
||||
|
||||
public ModeratorProfile getProfile() {
|
||||
return profile;
|
||||
}
|
||||
|
||||
public long getStartTimestamp() {
|
||||
return startTimestamp;
|
||||
}
|
||||
|
||||
public String getPreviousGroup() {
|
||||
return previousGroup;
|
||||
}
|
||||
|
||||
public String getActiveGroup() {
|
||||
return activeGroup;
|
||||
}
|
||||
|
||||
public ItemStack[] getInventoryContents() {
|
||||
return cloneItems(inventoryContents);
|
||||
}
|
||||
|
||||
public ItemStack[] getArmorContents() {
|
||||
return cloneItems(armorContents);
|
||||
}
|
||||
|
||||
public ItemStack getOffHandItem() {
|
||||
return cloneItem(offHandItem);
|
||||
}
|
||||
|
||||
public Location getLocation() {
|
||||
return location == null ? null : location.clone();
|
||||
}
|
||||
|
||||
public GameMode getGameMode() {
|
||||
return gameMode;
|
||||
}
|
||||
|
||||
public double getHealth() {
|
||||
return health;
|
||||
}
|
||||
|
||||
public double getMaxHealth() {
|
||||
return maxHealth;
|
||||
}
|
||||
|
||||
public int getFoodLevel() {
|
||||
return foodLevel;
|
||||
}
|
||||
|
||||
public float getSaturation() {
|
||||
return saturation;
|
||||
}
|
||||
|
||||
public float getExhaustion() {
|
||||
return exhaustion;
|
||||
}
|
||||
|
||||
public int getExpLevel() {
|
||||
return expLevel;
|
||||
}
|
||||
|
||||
public float getExp() {
|
||||
return exp;
|
||||
}
|
||||
|
||||
public int getTotalExperience() {
|
||||
return totalExperience;
|
||||
}
|
||||
|
||||
public Collection<PotionEffect> getPotionEffects() {
|
||||
return new ArrayList<>(potionEffects);
|
||||
}
|
||||
|
||||
public boolean isFlying() {
|
||||
return flying;
|
||||
}
|
||||
|
||||
public boolean isAllowFlight() {
|
||||
return allowFlight;
|
||||
}
|
||||
|
||||
public float getFlySpeed() {
|
||||
return flySpeed;
|
||||
}
|
||||
|
||||
public float getWalkSpeed() {
|
||||
return walkSpeed;
|
||||
}
|
||||
|
||||
public int getFireTicks() {
|
||||
return fireTicks;
|
||||
}
|
||||
|
||||
public long getDurationMillis() {
|
||||
return Math.max(0L, System.currentTimeMillis() - startTimestamp);
|
||||
}
|
||||
|
||||
private static ItemStack[] cloneItems(ItemStack[] source) {
|
||||
if (source == null) {
|
||||
return new ItemStack[0];
|
||||
}
|
||||
|
||||
ItemStack[] clone = new ItemStack[source.length];
|
||||
for (int i = 0; i < source.length; i++) {
|
||||
clone[i] = cloneItem(source[i]);
|
||||
}
|
||||
return clone;
|
||||
}
|
||||
|
||||
private static ItemStack cloneItem(ItemStack item) {
|
||||
if (item == null || item.getType() == Material.AIR) {
|
||||
return new ItemStack(Material.AIR);
|
||||
}
|
||||
return item.clone();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user