Compare commits

...

10 Commits

Author SHA1 Message Date
elliot a8b88c399e Update client.yml for clarity 2 years ago
elliot fc7261f09b Bring to parity with parent 3 years ago
elliot 1a89a4cd13 Delete 'src/cx/sfy/LagAssist/MonTools.java' 3 years ago
elliot 569e31ca08 Add functionality to get map command 3 years ago
elliot c436e051da Update '.idea/workspace.xml' 3 years ago
elliot 475406b431 Delete '.idea/vcs.xml' 3 years ago
elliot e9211b1027 Delete '.idea/runConfigurations.xml' 3 years ago
elliot 6c7adf2e42 Improve map command- don't delete items 3 years ago
elliotnichols c87c59e99a Undoing 3 years ago
elliotnichols 3f3d6a4611 Test 3 years ago
  1. 6
      client.yml
  2. 444
      src/cx/sfy/LagAssist/MonTools.java

6
client.yml

@ -15,13 +15,11 @@
# It offers ways to hide some laggy features in minecraft and thus simplify the game # It offers ways to hide some laggy features in minecraft and thus simplify the game
# for the players, while the server still works as normally. # for the players, while the server still works as normally.
# #
# NOTE: THE CLIENT-SIDE TWEAKS SHOULD WORK ON 1.8-1.13.1, BUT SOME FUTURE VERSIONS
# MAY NOT WORK OUT OF THE BOX. PLEASE CONTACT US TO UPDATE THIS SYSTEM IF
# ANY PROBLEM ARISES.
# NOTE: THE CLIENT-SIDE TWEAKS ONLY WORKS ON 1.8-1.13.1
settings: settings:
# The client-side tweaks are currently experimental. They have been tested comprehensively, # The client-side tweaks are currently experimental. They have been tested comprehensively,
# but not against a large range of systems and minecraft versions. Please take care. # but not against a large range of systems and minecraft versions. Please take care.
enabled: false
enabled: false # Only enable on 1.8-1.13.1!
# Set the command that players will use to open the client-side optimizer. # Set the command that players will use to open the client-side optimizer.
command: "optimize" command: "optimize"
# Set the permission required for players to be able to use the client optimizer. # Set the permission required for players to be able to use the client optimizer.

444
src/cx/sfy/LagAssist/MonTools.java

@ -1,222 +1,222 @@
package cx.sfy.LagAssist;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.World;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerItemHeldEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.PlayerInventory;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.map.MapView;
import cx.sfy.LagAssist.maps.TpsRender;
import cx.sfy.LagAssist.minebench.SpecsGetter;
import cx.sfy.LagAssist.packets.Reflection;
import cx.sfy.LagAssist.utils.VersionMgr;
public class MonTools implements Listener {
public static ItemStack mapitem = VersionMgr.getMap();
public static ItemMeta mapitemmeta = mapitem.getItemMeta();
public static List<UUID> actionmon = new ArrayList<UUID>();
public static List<UUID> mapusers = new ArrayList<UUID>();
private static DecimalFormat format = new DecimalFormat("#0.00");
private static String stbmsg = Main.config.getString("stats-bar.message");
private static int stbinterv = Main.config.getInt("stats-bar.tps-interval");
private static int stbshowdl = Main.config.getInt("stats-bar.show-delay");
public static void Enabler(boolean reload) {
if (!reload) {
Main.p.getServer().getPluginManager().registerEvents(new MonTools(), Main.p);
}
Bukkit.getLogger().info(" §e[§a✔§e] §fMapVisualizer.");
mapitemmeta.setDisplayName("§c§lLag§f§lAssist §e§lMonitor");
mapitem.setItemMeta(mapitemmeta);
int mapid = VersionMgr.getMapId(mapitem);
MapView view = Reflection.getMapView(mapid);
if (view != null) {
view.getRenderers().clear();
view.addRenderer(new TpsRender());
}
StatsBar();
}
public static void StatsBar() {
Bukkit.getScheduler().runTaskTimer(Main.p, () -> {
if (actionmon.size() == 0) {
return;
}
boolean found = false;
for (int i = 0; i<actionmon.size();i++) {
if (Bukkit.getPlayer(actionmon.get(i)) != null) {
found = true;
break;
}
}
if (!found) {
return;
}
double tpsraw = (ExactTPS.getTPS(10) > 20) ? 20 : ExactTPS.getTPS(stbinterv);
String chunks = String.valueOf(getChunkCount());
String ents = String.valueOf(getEntCount());
Bukkit.getScheduler().runTaskAsynchronously(Main.p, () -> {
if (actionmon.isEmpty()) {
return;
}
String tps;
if (tpsraw > 18) {
tps = "§a" + format.format(tpsraw);
} else if (tpsraw > 15) {
tps = "§e" + format.format(tpsraw);
} else {
tps = "§c" + format.format(tpsraw);
}
String s = ChatColor.translateAlternateColorCodes('&',
stbmsg.replaceAll("\\{TPS\\}", tps)
.replaceAll("\\{MEM\\}", format.format(SpecsGetter.FreeRam() / 1024))
.replaceAll("\\{CHKS\\}", chunks)
.replaceAll("\\{ENT\\}", ents));
for (UUID u : actionmon) {
Player p = Bukkit.getPlayer(u);
if (p == null) {
continue;
}
Reflection.sendAction(p, s);
}
});
}, stbshowdl, stbshowdl);
}
public static int getEntCount() {
int lng = 0;
for (World w : Bukkit.getWorlds()) {
lng += w.getEntities().size();
}
return lng;
}
public static int getChunkCount() {
int lng = 0;
for (World w : Bukkit.getWorlds()) {
lng += w.getLoadedChunks().length;
}
return lng;
}
@EventHandler
public void onSlotChange(PlayerItemHeldEvent e) {
Player p = e.getPlayer();
ItemStack old = p.getInventory().getItem(e.getPreviousSlot());
ItemStack nw = p.getInventory().getItem(e.getNewSlot());
if (runNew(nw, p)) {
return;
}
runOld(old, p);
}
// @EventHandler(priority = EventPriority.LOWEST)
// public void onMapLoad(MapInitializeEvent e) {
// Main.p.getLogger().warning("0");
// MapView view = e.getMap();
//
// if (Reflection.getMapId(e.get) != Data.getMapId()) {
// return;
// }
//
// Main.p.getLogger().warning("1");
//
// view.addRenderer(new TpsRender());
// }
public static void giveMap(Player p) {
PlayerInventory inv = p.getInventory();
int slot = inv.getHeldItemSlot();
inv.setItem(slot, MonTools.mapitem);
UUID UUID = p.getUniqueId();
if (!mapusers.contains(UUID)) {
mapusers.add(UUID);
}
}
private static void runOld(ItemStack old, Player p) {
if (old == null) {
return;
}
if (!old.hasItemMeta()) {
return;
}
ItemMeta ometa = old.getItemMeta();
if (!ometa.hasDisplayName()) {
return;
}
if (ometa.getDisplayName() != mapitemmeta.getDisplayName()) {
return;
}
UUID UUID = p.getUniqueId();
if (!mapusers.contains(UUID)) {
mapusers.add(UUID);
}
}
private static boolean runNew(ItemStack nw, Player p) {
if (!p.hasPermission("lagassist.use")) {
return false;
}
if (nw == null) {
return false;
}
if (!nw.hasItemMeta()) {
return false;
}
ItemMeta nwmeta = nw.getItemMeta();
if (!nwmeta.hasDisplayName()) {
return false;
}
if (nwmeta.getDisplayName() != mapitemmeta.getDisplayName()) {
return false;
}
UUID UUID = p.getUniqueId();
if (!mapusers.contains(UUID)) {
mapusers.add(UUID);
}
return true;
}
}
package cx.sfy.LagAssist;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.World;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerItemHeldEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.PlayerInventory;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.map.MapView;
import cx.sfy.LagAssist.maps.TpsRender;
import cx.sfy.LagAssist.minebench.SpecsGetter;
import cx.sfy.LagAssist.packets.Reflection;
import cx.sfy.LagAssist.utils.VersionMgr;
public class MonTools implements Listener {
public static ItemStack mapitem = VersionMgr.getMap();
public static ItemMeta mapitemmeta = mapitem.getItemMeta();
public static List<UUID> actionmon = new ArrayList<UUID>();
public static List<UUID> mapusers = new ArrayList<UUID>();
private static DecimalFormat format = new DecimalFormat("#0.00");
private static String stbmsg = Main.config.getString("stats-bar.message");
private static int stbinterv = Main.config.getInt("stats-bar.tps-interval");
private static int stbshowdl = Main.config.getInt("stats-bar.show-delay");
public static void Enabler(boolean reload) {
if (!reload) {
Main.p.getServer().getPluginManager().registerEvents(new MonTools(), Main.p);
}
Bukkit.getLogger().info(" §e[§a✔§e] §fMapVisualizer.");
mapitemmeta.setDisplayName("§c§lLag§f§lAssist §e§lMonitor");
mapitem.setItemMeta(mapitemmeta);
int mapid = VersionMgr.getMapId(mapitem);
MapView view = Reflection.getMapView(mapid);
if (view != null) {
view.getRenderers().clear();
view.addRenderer(new TpsRender());
}
StatsBar();
}
public static void StatsBar() {
Bukkit.getScheduler().runTaskTimer(Main.p, () -> {
if (actionmon.size() == 0) {
return;
}
boolean found = false;
for (int i = 0; i<actionmon.size();i++) {
if (Bukkit.getPlayer(actionmon.get(i)) != null) {
found = true;
break;
}
}
if (!found) {
return;
}
double tpsraw = (ExactTPS.getTPS(10) > 20) ? 20 : ExactTPS.getTPS(stbinterv);
String chunks = String.valueOf(getChunkCount());
String ents = String.valueOf(getEntCount());
Bukkit.getScheduler().runTaskAsynchronously(Main.p, () -> {
if (actionmon.isEmpty()) {
return;
}
String tps;
if (tpsraw > 18) {
tps = "§a" + format.format(tpsraw);
} else if (tpsraw > 15) {
tps = "§e" + format.format(tpsraw);
} else {
tps = "§c" + format.format(tpsraw);
}
String s = ChatColor.translateAlternateColorCodes('&',
stbmsg.replaceAll("\\{TPS\\}", tps)
.replaceAll("\\{MEM\\}", format.format(SpecsGetter.FreeRam() / 1024))
.replaceAll("\\{CHKS\\}", chunks)
.replaceAll("\\{ENT\\}", ents));
for (UUID u : actionmon) {
Player p = Bukkit.getPlayer(u);
if (p == null) {
continue;
}
Reflection.sendAction(p, s);
}
});
}, stbshowdl, stbshowdl);
}
public static int getEntCount() {
int lng = 0;
for (World w : Bukkit.getWorlds()) {
lng += w.getEntities().size();
}
return lng;
}
public static int getChunkCount() {
int lng = 0;
for (World w : Bukkit.getWorlds()) {
lng += w.getLoadedChunks().length;
}
return lng;
}
@EventHandler
public void onSlotChange(PlayerItemHeldEvent e) {
Player p = e.getPlayer();
ItemStack old = p.getInventory().getItem(e.getPreviousSlot());
ItemStack nw = p.getInventory().getItem(e.getNewSlot());
if (runNew(nw, p)) {
return;
}
runOld(old, p);
}
// @EventHandler(priority = EventPriority.LOWEST)
// public void onMapLoad(MapInitializeEvent e) {
// Main.p.getLogger().warning("0");
// MapView view = e.getMap();
//
// if (Reflection.getMapId(e.get) != Data.getMapId()) {
// return;
// }
//
// Main.p.getLogger().warning("1");
//
// view.addRenderer(new TpsRender());
// }
public static void giveMap(Player p) {
PlayerInventory inv = p.getInventory();
int slot = inv.getHeldItemSlot();
inv.setItem(slot, MonTools.mapitem);
UUID UUID = p.getUniqueId();
if (!mapusers.contains(UUID)) {
mapusers.add(UUID);
}
}
private static void runOld(ItemStack old, Player p) {
if (old == null) {
return;
}
if (!old.hasItemMeta()) {
return;
}
ItemMeta ometa = old.getItemMeta();
if (!ometa.hasDisplayName()) {
return;
}
if (ometa.getDisplayName() != mapitemmeta.getDisplayName()) {
return;
}
UUID UUID = p.getUniqueId();
if (!mapusers.contains(UUID)) {
mapusers.add(UUID);
}
}
private static boolean runNew(ItemStack nw, Player p) {
if (!p.hasPermission("lagassist.use")) {
return false;
}
if (nw == null) {
return false;
}
if (!nw.hasItemMeta()) {
return false;
}
ItemMeta nwmeta = nw.getItemMeta();
if (!nwmeta.hasDisplayName()) {
return false;
}
if (nwmeta.getDisplayName() != mapitemmeta.getDisplayName()) {
return false;
}
UUID UUID = p.getUniqueId();
if (!mapusers.contains(UUID)) {
mapusers.add(UUID);
}
return true;
}
}

Loading…
Cancel
Save