Browse Source

Added min-stack, spawn reasons to stacker.

master
Stefatorus 3 years ago
parent
commit
541e9aa456
  1. 2
      plugin.yml
  2. 16
      server.yml
  3. 4
      src/cx/sfy/LagAssist/Main.java
  4. 4
      src/cx/sfy/LagAssist/client/ClientMain.java
  5. 34
      src/cx/sfy/LagAssist/client/ClientPacket.java
  6. 1
      src/cx/sfy/LagAssist/microfeatures/AdvertRunner.java
  7. 61
      src/cx/sfy/LagAssist/stacker/StackChunk.java
  8. 35
      src/cx/sfy/LagAssist/stacker/StackManager.java

2
plugin.yml

@ -1,6 +1,6 @@
name: LagAssist
author: Stefatorus
version: 2.24.2
version: 2.25.0
api-version: 1.13
description: LagAssist is an advanced anti-lag solution that allows server owners find and remove lag using multiple advanced and efficient methods.
main: cx.sfy.LagAssist.Main

16
server.yml

@ -78,6 +78,11 @@ smart-stacker:
tag-visibility: true
# Size is required if you want stacking to work.
tag-format: "&f{type} &cx{size}"
# What spawn reasons should be allowed for mob stacking.
# Use ALL to allow all mobs to stack, or alternatively use any value from here:
# VALUES: https://hub.spigotmc.org/javadocs/spigot/org/bukkit/event/entity/CreatureSpawnEvent.SpawnReason.html
spawn-reasons:
- "ALL"
# What entity types you want to be stackable.
stackable:
# - "SKELETON"
@ -105,6 +110,15 @@ smart-stacker:
# What's the highest amount a stack can get to? Since there's a limit of 1 stack per
# split, it's useful to keep this higher.
max-stack: 500
# The min-stack feature allows you how many mobs should be in a split before attempting to stack them.
# This can help retain some vanilla behaviour, but will have a negative effect on performance. Due to
# popular demand, it was added as the overall stacker should STILL be better performance wise than the
# alternatives, but don't set a min stack size if performance is your key concern.
#
# (!) To still have a good performance impact, LagAssist uses caching, which may result in the actually
# mob counts that are checked to stack to slightly differ. This should not be very noticeable.
#
min-stack: 0
# This section deals with custom handling for damage for stacked mobs.
damage:
# What damage causes should be multiplied by the stack count.
@ -764,4 +778,4 @@ hooks:
# What message should show up to players that get paid. %amount% for paid amount.
message: "&c&lLag&f&lAssist &e» &fYou were paid %amount% in the paywave."
# This allows the system to update the config if the plugin is updated.
version: 30
version: 31

4
src/cx/sfy/LagAssist/Main.java

@ -56,7 +56,7 @@ public class Main extends JavaPlugin implements Listener {
p = this;
file = new File(getDataFolder(), "server.yml");
config = Others.getConfig(file, 29);
config = Others.getConfig(file, 31);
paper = VersionMgr.isPaper();
@ -106,7 +106,7 @@ public class Main extends JavaPlugin implements Listener {
}
public static void ReloadPlugin(CommandSender s) {
config = Others.getConfig(file, 29);
config = Others.getConfig(file, 31);
Bukkit.getLogger().info(Main.PREFIX + "Reloading Systems:");
EnableClasses(true);

4
src/cx/sfy/LagAssist/client/ClientMain.java

@ -15,6 +15,7 @@ import cx.sfy.LagAssist.cmd.ClientCmdListener;
import cx.sfy.LagAssist.gui.DataGUI;
import cx.sfy.LagAssist.packets.Reflection;
import cx.sfy.LagAssist.utils.Others;
import cx.sfy.LagAssist.utils.VersionMgr;
import net.md_5.bungee.api.ChatColor;
public class ClientMain implements Listener {
@ -79,7 +80,8 @@ public class ClientMain implements Listener {
Reflection.getCommandMap().register(Main.p.getDescription().getName(), cmd);
Main.p.getCommand(ClientMain.command).setExecutor(new ClientCmdListener());
Bukkit.getLogger().info(" §e[§a✔§e] §fClient Optimizer.");
Bukkit.getLogger().info(" §e[§a✔§e] §fClient Optimizer. " + (VersionMgr.isV_17Plus() ? " EXPERIMENTAL SUPPORT 1.17+" : ""));
}

34
src/cx/sfy/LagAssist/client/ClientPacket.java

@ -1,8 +1,8 @@
package cx.sfy.LagAssist.client;
import java.util.ArrayList;
import java.util.UUID;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
@ -26,39 +26,42 @@ public class ClientPacket {
}
try {
String name = msg.getClass().getSimpleName().toLowerCase();
String entitytype = null;
if (name.equals("packetplayoutspawnentity")
&& (ClientGUI.isOn(ToggleState.TNT, p) || ClientGUI.isOn(ToggleState.SAND, p))) {
Entity ent;
if (VersionMgr.isV1_8()) {
int x = ((int) Reflection.getFieldValue(msg, "b")) / 32;
int y = ((int) Reflection.getFieldValue(msg, "c")) / 32;
int z = ((int) Reflection.getFieldValue(msg, "d")) / 32;
Location loc = new Location(p.getWorld(), x, y, z);
ent = Reflection.getEntity(loc);
entitytype = Reflection.getEntity(loc).getType().toString();
} else if (VersionMgr.isV1_17()) {
UUID u = (UUID) Reflection.getFieldValue(msg, "d");
ent = Bukkit.getEntity(u);
} if (VersionMgr.isNewMaterials()) {
Object entitytypes = Reflection.getFieldValue(msg, "m");
entitytypes = Reflection.getFieldValue(entitytypes, "bv");
entitytype = entitytypes == null ? "unknown" : entitytypes.toString();
} else if (VersionMgr.isNewMaterials()) {
// TODO: SYNC METHOD FIX MAY CAUSE MAJOR LAG!
UUID u = (UUID) Reflection.getFieldValue(msg, "b");
ent = Bukkit.getEntity(u);
entitytype = getEntityAsync(p, u).getType().toString().toUpperCase();
} else {
double x = ((double) Reflection.getFieldValue(msg, "c"));
double y = ((double) Reflection.getFieldValue(msg, "d"));
double z = ((double) Reflection.getFieldValue(msg, "e"));
Location loc = new Location(p.getWorld(), x, y, z);
ent = Reflection.getEntity(loc);
entitytype = Reflection.getEntity(loc).getType().toString();
}
if (ent == null) {
if (entitytype == null) {
return false;
}
String type = ent.getType().toString();
if (type == "PRIMED_TNT") {
if (entitytype.contains("tnt")) {
return ClientGUI.isOn(ToggleState.TNT, p);
} else if (type == "FALLING_BLOCK") {
} else if (entitytype.contains("falling_block")) {
return ClientGUI.isOn(ToggleState.SAND, p);
}
} else if (name.equals("packetplayoutworldparticles")) {
@ -85,4 +88,11 @@ public class ClientPacket {
}
private static Entity getEntityAsync(Player p, UUID u) {
for (Entity ent : new ArrayList<>(p.getWorld().getEntities())) {
if (ent.getUniqueId() == u) return ent;
}
return null;
}
}

1
src/cx/sfy/LagAssist/microfeatures/AdvertRunner.java

@ -10,7 +10,6 @@ import org.bukkit.plugin.messaging.PluginMessageListener;
import cx.sfy.LagAssist.Data;
import cx.sfy.LagAssist.Main;
import cx.sfy.LagAssist.utils.Chat;
import net.minecraft.server.v1_12_R1.AdvancementProgress.a;
public class AdvertRunner implements Listener, PluginMessageListener {

61
src/cx/sfy/LagAssist/stacker/StackChunk.java

@ -2,8 +2,10 @@ package cx.sfy.LagAssist.stacker;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@ -17,6 +19,7 @@ import org.bukkit.entity.EntityType;
import org.bukkit.entity.LivingEntity;
import org.bukkit.event.entity.EntityDeathEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.metadata.FixedMetadataValue;
import cx.sfy.LagAssist.Main;
import cx.sfy.LagAssist.utils.MathUtils;
@ -31,7 +34,7 @@ public class StackChunk {
public static String regexpat = "";
private static int splits = 8;
private Map<EntityType, ArrayList<Entity>>[] ents;
private Map<EntityType, HashSet<Entity>>[] ents;
public static void Enabler() {
splits = Main.config.getInt("smart-stacker.technical.splits");
@ -43,10 +46,10 @@ public class StackChunk {
@SuppressWarnings("unchecked")
public StackChunk(Chunk chk) {
ents = (Map<EntityType, ArrayList<Entity>>[]) new HashMap[256 / splits];
ents = (Map<EntityType, HashSet<Entity>>[]) new HashMap[256 / splits];
for (int i = 0; i < 256 / splits; i++) {
ents[i] = new HashMap<EntityType, ArrayList<Entity>>();
ents[i] = new HashMap<EntityType, HashSet<Entity>>();
}
}
@ -116,25 +119,28 @@ public class StackChunk {
return consumed;
}
private static Entity getMatch(Map<EntityType, ArrayList<Entity>> ents, Location loc, EntityType type,
private static Entity getMatch(Map<EntityType, HashSet<Entity>> ents, Location loc, EntityType type,
Entity optional) {
if (!ents.containsKey(type)) {
ents.put(type, new ArrayList<Entity>());
ents.put(type, new HashSet<Entity>());
}
List<Entity> list = ents.get(type);
Set<Entity> list = ents.get(type);
Entity ideal = null;
if (optional == null) {
if (list.isEmpty()) {
if (list.isEmpty() || isUnderMinimum(list)) {
ideal = loc.getWorld().spawnEntity(loc, type);
list.add(ideal);
return ideal;
} else {
return list.get(0);
return list.iterator().next();
}
} else if (isUnderMinimum(list)) {
list.add(optional);
return optional;
}
for (Entity ent : list) {
@ -146,6 +152,7 @@ public class StackChunk {
list.add(optional);
return optional;
}
public static int getStack(Entity ent) {
@ -157,6 +164,10 @@ public class StackChunk {
return 0;
}
if (ent.hasMetadata("lagassist.stacksize")) {
return ent.getMetadata("lagassist.stacksize").get(0).asInt();
}
String name = ent.getCustomName();
if (name == null) {
@ -185,6 +196,7 @@ public class StackChunk {
String formatted = nameformat.replace("{type}", Others.firstHighcase(ent.getType().toString()))
.replace("{size}", "" + Math.min(size, Main.config.getInt("smart-stacker.technical.max-stack")));
ent.setMetadata("lagassist.stacksize", new FixedMetadataValue(Main.p, size));
ent.setCustomName(formatted);
ent.setCustomNameVisible(Main.config.getBoolean("smart-stacker.gameplay.tag-visibility"));
}
@ -225,7 +237,7 @@ public class StackChunk {
}
for (StackChunk chk : chunks.values()) {
for (int i = 0; i < splits; i++) {
for (List<Entity> elist : chk.ents[i].values()) {
for (Set<Entity> elist : chk.ents[i].values()) {
for (Entity ent : elist) {
ent.remove();
}
@ -270,8 +282,8 @@ public class StackChunk {
return;
}
for (Map<EntityType, ArrayList<Entity>> m : stack.ents) {
for (ArrayList<Entity> types : m.values()) {
for (Map<EntityType, HashSet<Entity>> m : stack.ents) {
for (HashSet<Entity> types : m.values()) {
for (Entity ent : types) {
ent.remove();
}
@ -280,7 +292,32 @@ public class StackChunk {
chunks.remove(chk);
}
/*
* Implement min stack feature in beta.
*
* TODO: TEST FUNCTIONALITY
*/
protected static boolean isUnderMinimum(Set<Entity> ents) {
int minstack = Main.config.getInt("smart-stacker.technical.min-stack");
if (minstack <= 1) {
return false;
}
int stacktotal = getStackTotal(ents);
return minstack > 0 && stacktotal < minstack;
}
private static int getStackTotal(Set<Entity> ents) {
int total = 0;
for (Entity ent : ents) {
total += getStack(ent);
}
return total;
}
// Setting clean to true makes it force it;
@ -291,7 +328,7 @@ public class StackChunk {
StackChunk stchk = chunks.get(chk);
if (!stchk.ents[split].containsKey(ent)) {
if (!stchk.ents[split].containsKey(ent) || isUnderMinimum(stchk.ents[split].get(ent))) {
return;
}

35
src/cx/sfy/LagAssist/stacker/StackManager.java

@ -13,6 +13,7 @@ import org.bukkit.event.Cancellable;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.CreatureSpawnEvent;
import org.bukkit.event.entity.EntityDeathEvent;
import org.bukkit.event.entity.EntitySpawnEvent;
import org.bukkit.event.inventory.PrepareAnvilEvent;
@ -20,6 +21,7 @@ import org.bukkit.event.world.ChunkLoadEvent;
import org.bukkit.event.world.ChunkUnloadEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.metadata.FixedMetadataValue;
import cx.sfy.LagAssist.Main;
import cx.sfy.LagAssist.stacker.StackMonitor.SplitChangeEvent;
@ -61,6 +63,23 @@ public class StackManager implements Listener {
StackChunk.runShutdown();
}
@EventHandler(priority = EventPriority.LOW)
public void onCreatureSpawn(CreatureSpawnEvent e) {
if (e.isCancelled()) {
return;
}
if (!smartstacker) {
return;
}
if (WorldMgr.isBlacklisted(e.getLocation().getWorld())) {
return;
}
e.getEntity().setMetadata("lagassist.spawnreason", new FixedMetadataValue(Main.p, e.getSpawnReason()));
}
@EventHandler(priority = EventPriority.HIGH)
public void onSpawn(EntitySpawnEvent e) {
@ -81,12 +100,12 @@ public class StackManager implements Listener {
return;
}
Entity ent = e.getEntity();
if (!Main.config.getBoolean("smart-stacker.checks.spawn-check")) {
return;
}
Entity ent = e.getEntity();
// if (!(ent instanceof LivingEntity)) {
// return;
// }
@ -256,11 +275,19 @@ public class StackManager implements Listener {
return false;
}
if (StackChunk.getStack(ent) < 0) {
if (!Main.config.getStringList("smart-stacker.gameplay.stackable").contains(ent.getType().toString().toUpperCase())) {
return false;
}
String spawnreason = ent.hasMetadata("lagassist.spawnreason") ? ent.getMetadata("lagassist.spawnreason").get(0).value().toString().toUpperCase() : "UNKNOWN";
if(!(Main.config.getStringList("smart-stacker.gameplay.spawn-reasons").contains("ALL") || Main.config.getStringList("smart-stacker.gameplay.spawn-reasons").contains(spawnreason))) {
return false;
}
if (!Main.config.getStringList("smart-stacker.gameplay.stackable").contains(ent.getType().toString().toUpperCase())) {
int stacksize = StackChunk.getStack(ent);
if (stacksize < 0) {
return false;
}

Loading…
Cancel
Save