Update stats

This commit is contained in:
libraryaddict 2017-06-23 04:14:19 +12:00
parent 27230d5148
commit 06ce2d0e02
12 changed files with 1365 additions and 1024 deletions

View File

@ -256,6 +256,7 @@ public class DisguiseAPI {
for (String observer : ((TargetedDisguise) disguise).getObservers()) {
((TargetedDisguise) disguise).removePlayer(observer);
}
disguiseEntity(entity, disguise);
}

View File

@ -4,6 +4,7 @@ import java.io.File;
import java.util.HashMap;
import java.util.Map.Entry;
import me.libraryaddict.disguise.utilities.LibsPremium;
import me.libraryaddict.disguise.utilities.TranslateType;
import org.bukkit.Bukkit;
import org.bukkit.configuration.ConfigurationSection;
@ -156,7 +157,8 @@ public class DisguiseConfig {
setNameAboveHeadAlwaysVisible(config.getBoolean("NameAboveHeadAlwaysVisible"));
setModifyBoundingBox(config.getBoolean("ModifyBoundingBox"));
setMonstersIgnoreDisguises(config.getBoolean("MonstersIgnoreDisguises"));
setDisguiseBlownWhenAttacking(config.getBoolean("BlowDisguises", config.getBoolean("BlowDisguisesWhenAttacking")));
setDisguiseBlownWhenAttacking(
config.getBoolean("BlowDisguises", config.getBoolean("BlowDisguisesWhenAttacking")));
setDisguiseBlownWhenAttacked(config.getBoolean("BlowDisguisesWhenAttacked"));
setKeepDisguiseOnPlayerDeath(config.getBoolean("KeepDisguises.PlayerDeath"));
setMiscDisguisesForLivingEnabled(config.getBoolean("MiscDisguisesForLiving"));
@ -186,6 +188,10 @@ public class DisguiseConfig {
setSaveEntityDisguises(config.getBoolean("SaveDisguises.Entities"));
setUseTranslations(config.getBoolean("Translations"));
if (!LibsPremium.isPremium() && (isSavePlayerDisguises() || isSaveEntityDisguises())) {
System.out.println("[LibsDisguises] You must purchase the plugin to use saved disguises!");
}
try {
String option = config.getString("SelfDisguisesScoreboard", DisguisePushing.MODIFY_SCOREBOARD.name())
.toUpperCase();

View File

@ -8,10 +8,7 @@ import com.comphenix.protocol.wrappers.EnumWrappers.PlayerInfoAction;
import com.comphenix.protocol.wrappers.PlayerInfoData;
import com.comphenix.protocol.wrappers.WrappedChatComponent;
import com.comphenix.protocol.wrappers.WrappedGameProfile;
import me.libraryaddict.disguise.disguisetypes.Disguise;
import me.libraryaddict.disguise.disguisetypes.DisguiseType;
import me.libraryaddict.disguise.disguisetypes.PlayerDisguise;
import me.libraryaddict.disguise.disguisetypes.TargetedDisguise;
import me.libraryaddict.disguise.disguisetypes.*;
import me.libraryaddict.disguise.disguisetypes.watchers.LivingWatcher;
import me.libraryaddict.disguise.utilities.DisguiseParser;
import me.libraryaddict.disguise.utilities.DisguiseParser.DisguiseParseException;
@ -111,6 +108,8 @@ public class DisguiseListener implements Listener {
if (disguises.length <= 0)
continue;
DisguiseUtilities.resetPluginTimer();
for (Disguise disguise : disguises) {
disguise.setEntity(entity);
disguise.startDisguise();
@ -248,6 +247,8 @@ public class DisguiseListener implements Listener {
if (disguises.length <= 0)
continue;
DisguiseUtilities.resetPluginTimer();
for (Disguise disguise : disguises) {
disguise.setEntity(entity);
disguise.startDisguise();
@ -266,6 +267,8 @@ public class DisguiseListener implements Listener {
if (disguises.length <= 0)
continue;
DisguiseUtilities.resetPluginTimer();
for (Disguise disguise : disguises) {
disguise.setEntity(entity);
disguise.startDisguise();
@ -297,6 +300,10 @@ public class DisguiseListener implements Listener {
if (DisguiseConfig.isSavePlayerDisguises()) {
Disguise[] disguises = DisguiseUtilities.getSavedDisguises(p.getUniqueId(), true);
if (disguises.length > 0) {
DisguiseUtilities.resetPluginTimer();
}
for (Disguise disguise : disguises) {
disguise.setEntity(p);
disguise.startDisguise();
@ -311,26 +318,6 @@ public class DisguiseListener implements Listener {
if (!targetedDisguise.canSee(p))
continue;
// Don't need this as we have a packet listener doing that for us
/*if (targetedDisguise.isPlayerHiddenInTab() && targetedDisguise.getEntity() instanceof Player) {
try {
PacketContainer addTab = new PacketContainer(PacketType.Play.Server.PLAYER_INFO);
Player player = (Player) targetedDisguise.getEntity();
addTab.getPlayerInfoAction().write(0, PlayerInfoAction.REMOVE_PLAYER);
addTab.getPlayerInfoDataLists()
.write(0,
Arrays.asList(new PlayerInfoData(ReflectionManager.getGameProfile(player), 0,
NativeGameMode.SURVIVAL,
WrappedChatComponent.fromText(player.getDisplayName()))));
ProtocolLibrary.getProtocolManager().sendServerPacket(p, addTab);
}
catch (InvocationTargetException e) {
e.printStackTrace();
}
}*/
if (!(targetedDisguise instanceof PlayerDisguise))
continue;

View File

@ -1,48 +1,24 @@
package me.libraryaddict.disguise;
import java.io.File;
import java.io.IOException;
import java.lang.reflect.Field;
import java.util.ArrayList;
import com.comphenix.protocol.reflect.FieldAccessException;
import com.comphenix.protocol.wrappers.WrappedDataWatcher;
import com.comphenix.protocol.wrappers.WrappedWatchableObject;
import me.libraryaddict.disguise.commands.*;
import me.libraryaddict.disguise.disguisetypes.*;
import me.libraryaddict.disguise.disguisetypes.watchers.*;
import me.libraryaddict.disguise.utilities.*;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.PluginCommand;
import org.bukkit.command.TabCompleter;
import org.bukkit.entity.Ageable;
import org.bukkit.entity.Creature;
import org.bukkit.entity.Damageable;
import org.bukkit.entity.Entity;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Tameable;
import org.bukkit.entity.Zombie;
import org.bukkit.entity.*;
import org.bukkit.plugin.java.JavaPlugin;
import com.comphenix.protocol.reflect.FieldAccessException;
import com.comphenix.protocol.wrappers.WrappedDataWatcher;
import com.comphenix.protocol.wrappers.WrappedWatchableObject;
import me.libraryaddict.disguise.commands.DisguiseCloneCommand;
import me.libraryaddict.disguise.commands.DisguiseCommand;
import me.libraryaddict.disguise.commands.DisguiseEntityCommand;
import me.libraryaddict.disguise.commands.DisguiseHelpCommand;
import me.libraryaddict.disguise.commands.DisguiseModifyCommand;
import me.libraryaddict.disguise.commands.DisguiseModifyEntityCommand;
import me.libraryaddict.disguise.commands.DisguiseModifyPlayerCommand;
import me.libraryaddict.disguise.commands.DisguiseModifyRadiusCommand;
import me.libraryaddict.disguise.commands.DisguisePlayerCommand;
import me.libraryaddict.disguise.commands.DisguiseRadiusCommand;
import me.libraryaddict.disguise.commands.DisguiseViewSelfCommand;
import me.libraryaddict.disguise.commands.LibsDisguisesCommand;
import me.libraryaddict.disguise.commands.UndisguiseCommand;
import me.libraryaddict.disguise.commands.UndisguiseEntityCommand;
import me.libraryaddict.disguise.commands.UndisguisePlayerCommand;
import me.libraryaddict.disguise.commands.UndisguiseRadiusCommand;
import me.libraryaddict.disguise.disguisetypes.DisguiseType;
import me.libraryaddict.disguise.disguisetypes.FlagWatcher;
import me.libraryaddict.disguise.disguisetypes.MetaIndex;
import java.io.File;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
public class LibsDisguises extends JavaPlugin {
private static LibsDisguises instance;
@ -50,16 +26,6 @@ public class LibsDisguises extends JavaPlugin {
@Override
public void onEnable() {
try {
Class.forName("com.comphenix.protocol.wrappers.Vector3F").getName();
}
catch (Exception ex) {
System.err.println("[LibsDisguises] Lib's Disguises failed to startup, outdated ProtocolLib!");
System.err.println(
"[LibsDisguises] You need to update ProtocolLib, please try this build http://ci.dmulloy2.net/job/ProtocolLib/lastStableBuild/artifact/modules/ProtocolLib/target/ProtocolLib.jar");
return;
}
instance = this;
saveDefaultConfig();
@ -100,13 +66,114 @@ public class LibsDisguises extends JavaPlugin {
registerCommand("disguisemodifyradius",
new DisguiseModifyRadiusCommand(getConfig().getInt("DisguiseRadiusMax")));
try {
infectWithMetrics();
}
private void infectWithMetrics() {
Metrics metrics = new Metrics(this);
metrics.start();
final String premium = LibsPremium.isPremium() ?
getDescription().getVersion().contains("SNAPSHOT") ? "Paid Builds" : "Paid Plugin" : "Free Builds";
metrics.addCustomChart(new Metrics.SimplePie("premium") {
@Override
public String getValue() {
return premium;
}
catch (IOException e) {
// Don't print error
});
metrics.addCustomChart(new Metrics.SimplePie("translations") {
@Override
public String getValue() {
return LibsPremium.isPremium() && DisguiseConfig.isUseTranslations() ? "Yes" : "No";
}
});
metrics.addCustomChart(new Metrics.SimplePie("custom_disguises") {
@Override
public String getValue() {
HashMap map = DisguiseConfig.getCustomDisguises();
return map.size() + (map.containsKey("libraryaddict") ? -1 : 0) > 0 ? "Yes" : "No";
}
});
metrics.addCustomChart(new Metrics.MultiLineChart("disguised_entities") {
@Override
public HashMap<String, Integer> getValues(HashMap<String, Integer> hashMap) {
for (HashSet<TargetedDisguise> list : DisguiseUtilities.getDisguises().values()) {
for (Disguise disg : list) {
if (disg.getEntity() == null || !disg.isDisguiseInUse())
continue;
String name = disg.getEntity().getType().name();
hashMap.put(name, hashMap.containsKey(name) ? hashMap.get(name) + 1 : 1);
}
}
return hashMap;
}
});
metrics.addCustomChart(new Metrics.MultiLineChart("disguises_used") {
@Override
public HashMap<String, Integer> getValues(HashMap<String, Integer> hashMap) {
for (HashSet<TargetedDisguise> list : DisguiseUtilities.getDisguises().values()) {
for (Disguise disg : list) {
if (disg.getEntity() == null || !disg.isDisguiseInUse())
continue;
String name = disg.getType().name();
hashMap.put(name, hashMap.containsKey(name) ? hashMap.get(name) + 1 : 1);
}
}
return hashMap;
}
});
metrics.addCustomChart(new Metrics.SimplePie("disguised_with_commands") {
@Override
public String getValue() {
return DisguiseUtilities.isCommandsUsed() ? "Yes" : "No";
}
});
metrics.addCustomChart(new Metrics.SimplePie("disguised_with_plugins") {
@Override
public String getValue() {
return DisguiseUtilities.isPluginsUsed() ? "Yes" : "No";
}
});
metrics.addCustomChart(new Metrics.SimplePie("using_disguises") {
@Override
public String getValue() {
return !DisguiseUtilities.getDisguises().isEmpty() ? "Yes" : "No";
}
});
metrics.addCustomChart(new Metrics.SimplePie("self_disguises") {
@Override
public String getValue() {
return DisguiseConfig.isViewDisguises() ? "Yes" : "No";
}
});
metrics.addCustomChart(new Metrics.SimplePie("spigot") {
@Override
public String getValue() {
try {
Class.forName("org.spigotmc.SpigotConfig");
return "Yes";
}
catch (Exception ex) {
return "No";
}
}
});
}
@Override

View File

@ -71,8 +71,6 @@ public abstract class Disguise {
/**
* Seems I do this method so I can make cleaner constructors on disguises..
*
* @param newType The disguise
*/
protected void createDisguise() {
if (getType().getEntityType() == null) {
@ -234,7 +232,8 @@ public abstract class Disguise {
int newFacing = (((int) loc.getYaw() + 720 + 45) / 90) % 4;
if (loc.getBlockX() != blockX || loc.getBlockY() != blockY || loc.getBlockZ() != blockZ || newFacing != facing) {
if (loc.getBlockX() != blockX || loc.getBlockY() != blockY || loc
.getBlockZ() != blockZ || newFacing != facing) {
blockX = loc.getBlockX();
blockY = loc.getBlockY();
blockZ = loc.getBlockZ();
@ -260,7 +259,8 @@ public abstract class Disguise {
// If the entity doesn't have velocity changes already - You know. I really can't wrap my head about the
// if statement.
// But it doesn't seem to do anything wrong..
if (vector.getY() != 0 && !(vector.getY() < 0 && alwaysSendVelocity && getEntity().isOnGround())) {
if (vector.getY() != 0 && !(vector.getY() < 0 && alwaysSendVelocity && getEntity()
.isOnGround())) {
return;
}
@ -268,7 +268,8 @@ public abstract class Disguise {
if (getType() != DisguiseType.EXPERIENCE_ORB || !getEntity().isOnGround()) {
PacketContainer lookPacket = null;
if (getType() == DisguiseType.WITHER_SKULL && DisguiseConfig.isWitherSkullPacketsEnabled()) {
if (getType() == DisguiseType.WITHER_SKULL && DisguiseConfig
.isWitherSkullPacketsEnabled()) {
lookPacket = new PacketContainer(Server.ENTITY_LOOK);
StructureModifier<Object> mods = lookPacket.getModifier();
@ -277,8 +278,8 @@ public abstract class Disguise {
mods.write(4, PacketsManager.getYaw(getType(), getEntity().getType(),
(byte) Math.floor(loc.getYaw() * 256.0F / 360.0F)));
mods.write(5,
PacketsManager.getPitch(getType(), DisguiseType.getType(getEntity().getType()),
mods.write(5, PacketsManager
.getPitch(getType(), DisguiseType.getType(getEntity().getType()),
(byte) Math.floor(loc.getPitch() * 256.0F / 360.0F)));
if (isSelfDisguiseVisible() && getEntity() instanceof Player) {
@ -287,8 +288,8 @@ public abstract class Disguise {
selfLookPacket.getIntegers().write(0, DisguiseAPI.getSelfDisguiseId());
try {
ProtocolLibrary.getProtocolManager().sendServerPacket((Player) getEntity(),
selfLookPacket, false);
ProtocolLibrary.getProtocolManager()
.sendServerPacket((Player) getEntity(), selfLookPacket, false);
}
catch (InvocationTargetException e) {
e.printStackTrace();
@ -319,12 +320,12 @@ public abstract class Disguise {
(int) (8000D * (vectorY * ReflectionManager.getPing(player)) * 0.069D));
if (lookPacket != null && player != getEntity()) {
ProtocolLibrary.getProtocolManager().sendServerPacket(player, lookPacket,
false);
ProtocolLibrary.getProtocolManager()
.sendServerPacket(player, lookPacket, false);
}
ProtocolLibrary.getProtocolManager().sendServerPacket(player,
velocityPacket.shallowClone(), false);
ProtocolLibrary.getProtocolManager()
.sendServerPacket(player, velocityPacket.shallowClone(), false);
}
}
catch (Exception e) {
@ -348,8 +349,8 @@ public abstract class Disguise {
selfPacket.getModifier().write(0, DisguiseAPI.getSelfDisguiseId());
try {
ProtocolLibrary.getProtocolManager().sendServerPacket((Player) getEntity(),
selfPacket, false);
ProtocolLibrary.getProtocolManager()
.sendServerPacket((Player) getEntity(), selfPacket, false);
}
catch (InvocationTargetException e) {
e.printStackTrace();
@ -683,8 +684,8 @@ public abstract class Disguise {
*/
private void setupWatcher() {
ArrayList<MetaIndex> disguiseFlags = MetaIndex.getFlags(getType().getWatcherClass());
ArrayList<MetaIndex> entityFlags = MetaIndex.getFlags(
DisguiseType.getType(getEntity().getType()).getWatcherClass());
ArrayList<MetaIndex> entityFlags = MetaIndex
.getFlags(DisguiseType.getType(getEntity().getType()).getWatcherClass());
for (MetaIndex flag : entityFlags) {
if (disguiseFlags.contains(flag))
@ -736,7 +737,8 @@ public abstract class Disguise {
public Disguise setWatcher(FlagWatcher newWatcher) {
if (!getType().getWatcherClass().isInstance(newWatcher)) {
throw new IllegalArgumentException(
newWatcher.getClass().getSimpleName() + " is not a instance of " + getType().getWatcherClass().getSimpleName() + " for DisguiseType " + getType().name());
newWatcher.getClass().getSimpleName() + " is not a instance of " + getType().getWatcherClass()
.getSimpleName() + " for DisguiseType " + getType().name());
}
watcher = newWatcher;
@ -749,15 +751,21 @@ public abstract class Disguise {
}
public boolean startDisguise() {
if (!isDisguiseInUse()) {
if (isDisguiseInUse()) {
return false;
}
if (getEntity() == null) {
throw new RuntimeException("No entity is assigned to this disguise!");
}
DisguiseUtilities.setPluginsUsed();
// Fire a disguise event
DisguiseEvent event = new DisguiseEvent(entity, this);
Bukkit.getPluginManager().callEvent(event);
Bukkit.getPluginManager().
callEvent(event);
// If they cancelled this disguise event. No idea why.
// Just return.
@ -771,7 +779,9 @@ public abstract class Disguise {
createRunnable();
}
task = Bukkit.getScheduler().runTaskTimer(LibsDisguises.getInstance(), velocityRunnable, 1, 1);
task = Bukkit.getScheduler().
runTaskTimer(LibsDisguises.getInstance(), velocityRunnable, 1, 1);
if (this instanceof PlayerDisguise) {
PlayerDisguise disguise = (PlayerDisguise) this;
@ -808,7 +818,8 @@ public abstract class Disguise {
DisguiseUtilities.refreshTrackers((TargetedDisguise) this);
// If he is a player, then self disguise himself
Bukkit.getScheduler().scheduleSyncDelayedTask(LibsDisguises.getInstance(), new Runnable() {
Bukkit.getScheduler().
scheduleSyncDelayedTask(LibsDisguises.getInstance(), new Runnable() {
@Override
public void run() {
DisguiseUtilities.setupFakeDisguise(Disguise.this);
@ -838,9 +849,6 @@ public abstract class Disguise {
return true;
}
return false;
}
public boolean stopDisguise() {
return removeDisguise();
}

View File

@ -453,6 +453,10 @@ public class DisguiseParser {
*/
public static Disguise parseDisguise(CommandSender sender, String permNode, String[] args,
HashMap<DisguisePerm, HashMap<ArrayList<String>, Boolean>> permissionMap) throws DisguiseParseException, IllegalAccessException, InvocationTargetException {
if (sender instanceof Player) {
DisguiseUtilities.setCommandsUsed();
}
if (permissionMap.isEmpty()) {
throw new DisguiseParseException(LibsMsg.NO_PERM);
}

View File

@ -74,6 +74,33 @@ public class DisguiseUtilities {
"plugins/LibsDisguises/SavedDisguises");
private static Gson gson;
private static BackwardMethods methods;
private static boolean pluginsUsed, commandsUsed;
private static long libsDisguisesCalled;
public static void setPluginsUsed() {
if (libsDisguisesCalled > System.currentTimeMillis()) {
return;
}
pluginsUsed = true;
}
public static void resetPluginTimer() {
libsDisguisesCalled = System.currentTimeMillis() + 100;
}
public static void setCommandsUsed() {
resetPluginTimer();
commandsUsed = true;
}
public static boolean isPluginsUsed() {
return pluginsUsed;
}
public static boolean isCommandsUsed() {
return commandsUsed;
}
public static void saveDisguises() {
for (HashSet<TargetedDisguise> list : disguisesInUse.values()) {

File diff suppressed because it is too large Load Diff

View File

@ -33,6 +33,10 @@ public enum TranslateType {
type.reload();
}
if (!LibsPremium.isPremium() && DisguiseConfig.isUseTranslations()) {
System.out.println("[LibsDisguises] You must purchase the plugin to use translations!");
}
TranslateFiller.fillConfigs();
}

View File

@ -15,14 +15,18 @@ public class BackwardsSupport {
public static BackwardMethods getMethods() {
try {
String version = ReflectionManager.getBukkitVersion();
Class<? extends BackwardMethods> methods = BackwardMethods.class;
if (LibsPremium.isPremium()) {
if (version.equals("v1_11_R1")) {
return setupMetadata(Version_1_11.class);
}
methods = Version_1_11.class;
}
return setupMetadata(BackwardMethods.class);
if (!LibsPremium.isPremium() && methods != BackwardMethods.class) {
System.out.println("[LibsDisguises] You must purchase the plugin to use backwards compatibility!");
methods = BackwardMethods.class;
}
return setupMetadata(methods);
}
catch (Exception e) {
e.printStackTrace();