Merge remote-tracking branch 'origin/master'

This commit is contained in:
Dewy REDACTED 2020-04-05 23:12:28 +01:00
commit 08d21f8adb
4 changed files with 140 additions and 7 deletions

View File

@ -2,8 +2,7 @@
if [[ "$TRAVIS_PULL_REQUEST" == "true" ]]; then exit 0; else echo "">/dev/null; fi
CUR_VER="$(cat ./scripts/curVer)"
CUR_VER="${CUR_VER:1}"
CUR_VER="$(tail -c +2 ./scripts/curVer)"
COMMIT_TRIM="${TRAVIS_COMMIT::7}"
COMMIT_MSG="$TRAVIS_COMMIT_MESSAGE"

View File

@ -23,8 +23,11 @@ import net.minecraft.util.EnumHand;
public class AutoNametag extends Module {
private Setting<Mode> modeSetting = register(Settings.e("Mode", Mode.WITHER));
private Setting<Float> range = register(Settings.floatBuilder("Range").withMinimum(2.0f).withValue(3.5f).withMaximum(10.0f).build());
private Setting<Boolean> autoSlot = register(Settings.b("Auto Slot", true));
private Setting<Boolean> debug = register(Settings.b("Debug", false));
private String currentName = "";
public void onUpdate() {
useNameTag();
}
@ -34,7 +37,7 @@ public class AutoNametag extends Module {
for (Entity w : mc.world.getLoadedEntityList()) {
switch (modeSetting.getValue()) {
case WITHER:
if (w instanceof EntityWither && !w.hasCustomName()) {
if (w instanceof EntityWither && !w.getDisplayName().getUnformattedText().equals(currentName)) {
final EntityWither wither = (EntityWither) w;
if (mc.player.getDistance(wither) <= range.getValue()) {
if (debug.getValue())
@ -45,7 +48,7 @@ public class AutoNametag extends Module {
}
return;
case ANY:
if (w instanceof EntityMob || w instanceof EntityAnimal && !w.hasCustomName()) {
if (w instanceof EntityMob || w instanceof EntityAnimal && !w.getDisplayName().getUnformattedText().equals(currentName)) {
if (mc.player.getDistance(w) <= range.getValue()) {
if (debug.getValue())
Command.sendChatMessage("Found unnamed " + w.getDisplayName().getUnformattedText());
@ -55,16 +58,20 @@ public class AutoNametag extends Module {
}
}
}
mc.player.inventory.currentItem = originalSlot;
if (autoSlot.getValue()) mc.player.inventory.currentItem = originalSlot;
}
private void selectNameTags() {
if (!autoSlot.getValue()) return;
int tagSlot = -1;
for (int i = 0; i < 9; i++) {
ItemStack stack = mc.player.inventory.getStackInSlot(i);
if (stack == ItemStack.EMPTY || stack.getItem() instanceof ItemBlock) continue;
Item tag = stack.getItem();
if (tag instanceof ItemNameTag) tagSlot = i;
if (tag instanceof ItemNameTag) {
tagSlot = i;
currentName = stack.getDisplayName();
}
}
if (tagSlot == -1) {

View File

@ -0,0 +1,127 @@
package me.zeroeightsix.kami.module.modules.render;
import me.zeroeightsix.kami.command.Command;
import me.zeroeightsix.kami.module.Module;
import me.zeroeightsix.kami.setting.Setting;
import me.zeroeightsix.kami.setting.Settings;
import me.zeroeightsix.kami.util.EntityUtil;
import net.minecraft.entity.Entity;
import net.minecraft.entity.passive.AbstractHorse;
import net.minecraft.entity.passive.EntityTameable;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
/**
* I see you also watch FitMC :eyes:
* @author cookiedragon234
* Taken from Backdoored 1.8.2 source
*
* UUID to username method and caching methods added by S-B99
*/
@Module.Info(name = "MobOwner", description = "Displays the owner of tamed mobs", category = Module.Category.RENDER)
public class MobOwner extends Module {
private Setting<Integer> requestTime = register(Settings.integerBuilder("Cache Reset").withMinimum(10).withValue(20).build());
private Setting<Boolean> debug = register(Settings.b("Debug", true));
/* First String is your key / uuid, second String is the value / username */
private Map<String, String> cachedUUIDs = new HashMap<String, String>(){{ }};
private int apiRequests = 0;
private String invalidText = "Offline or invalid UUID!";
/**
* @author S-B99
*/
private String getUsername(String uuid) {
for (Map.Entry<String, String> entries : cachedUUIDs.entrySet()) {
if (entries.getKey().equalsIgnoreCase(uuid)) {
return entries.getValue();
}
}
try {
if (apiRequests > 10) {
return "Too many API requests";
}
cachedUUIDs.put(uuid, Objects.requireNonNull(EntityUtil.getNameFromUUID(uuid)).replace("\"", ""));
apiRequests++;
} catch (IllegalStateException illegal) { /* this means the json parsing failed meaning the UUID is invalid or you're offline */
cachedUUIDs.put(uuid, invalidText);
}
/* Run this again to reduce the amount of requests made to the Mojang API */
for (Map.Entry<String, String> entries : cachedUUIDs.entrySet()) {
if (entries.getKey().equalsIgnoreCase(uuid)) {
return entries.getValue();
}
}
return invalidText;
}
/* Periodically try to re-request invalid UUIDs */
private static long startTime = 0;
private void resetCache() {
if (startTime == 0) startTime = System.currentTimeMillis();
if (startTime + (requestTime.getValue() * 1000) <= System.currentTimeMillis()) { // 1 requestTime = 1 second = 1000 ms
startTime = System.currentTimeMillis();
for (Map.Entry<String, String> entries : cachedUUIDs.entrySet()) {
if (entries.getKey().equalsIgnoreCase(invalidText)) {
cachedUUIDs.clear();
if (debug.getValue()) Command.sendChatMessage(getChatName() + "Reset cached UUIDs list!");
return;
}
}
}
}
/* Super safe method to limit requests to the Mojang API in case you load more then 10 different UUIDs */
private static long startTime1 = 0;
private void resetRequests() {
if (startTime1 == 0) startTime1 = System.currentTimeMillis();
if (startTime1 + (10 * 1000) <= System.currentTimeMillis()) { // 10 seconds
startTime1 = System.currentTimeMillis();
if (apiRequests >= 2) {
apiRequests = 0;
if (debug.getValue()) Command.sendChatMessage(getChatName() + "Reset API requests counter!");
}
}
}
public void onUpdate() {
resetRequests();
resetCache();
for (final Entity entity : MobOwner.mc.world.loadedEntityList) {
/* Non Horse types, such as wolves */
if (entity instanceof EntityTameable) {
final EntityTameable entityTameable = (EntityTameable) entity;
if (entityTameable.isTamed() && entityTameable.getOwner() != null) {
entityTameable.setAlwaysRenderNameTag(true);
entityTameable.setCustomNameTag("Owner: " + entityTameable.getOwner().getDisplayName().getFormattedText());
}
}
if (entity instanceof AbstractHorse) {
final AbstractHorse abstractHorse = (AbstractHorse) entity;
if (!abstractHorse.isTame() || abstractHorse.getOwnerUniqueId() == null) {
continue;
}
abstractHorse.setAlwaysRenderNameTag(true);
abstractHorse.setCustomNameTag("Owner: " + getUsername(abstractHorse.getOwnerUniqueId().toString()));
}
}
}
public void onDisable() {
cachedUUIDs.clear();
for (final Entity entity : MobOwner.mc.world.loadedEntityList) {
if (!(entity instanceof EntityTameable)) {
if (!(entity instanceof AbstractHorse)) {
continue;
}
}
try {
entity.setAlwaysRenderNameTag(false);
}
catch (Exception ignored) {}
}
}
}

View File

@ -22,7 +22,7 @@ public class MessageDetectionHelper {
}
public static boolean isDirectOther(boolean directSent, String message) {
return directSent && Pattern.compile("to .+:", Pattern.CASE_INSENSITIVE).matcher(message).find();
return directSent && Pattern.compile("to [0-9A-Za-z_]+:", Pattern.CASE_INSENSITIVE).matcher(message).find();
}
public static boolean isQueue(boolean queue, String message) {