vector exceptions handled

This commit is contained in:
batchprogrammer314
2021-07-09 15:49:10 -05:00
parent 0f86796f96
commit 7bd2e50afd
6 changed files with 123 additions and 14 deletions

View File

@@ -1,14 +1,21 @@
package net.nuggetmc.ai.utils;
import net.nuggetmc.ai.PlayerAI;
import net.nuggetmc.ai.bot.Bot;
import net.nuggetmc.ai.bot.agent.BotAgent;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.ArmorStand;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import java.beans.Statement;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Set;
public class Debugger {
@@ -58,6 +65,84 @@ public class Debugger {
return list.toArray();
}
public void t(String content) {
Object[] obj = buildObjects(content);
if (obj.length != 1 || obj[0] instanceof Boolean) {
print("Invalid arguments!");
return;
}
PlayerUtils.setAllTargetable(Boolean.parseBoolean((String) obj[0]));
String var = "PlayerUtils.allTargetable";
if (PlayerUtils.getAllTargetable()) {
print(var + " is now " + ChatColor.GREEN + "TRUE" + ChatColor.RESET + ".");
} else {
print(var + " is now " + ChatColor.RED + "FALSE" + ChatColor.RESET + ".");
}
}
public void hideNametags(String content) { // this works for some reason
Set<Bot> bots = PlayerAI.getInstance().getManager().fetch();
for (Bot bot : bots) {
Location loc = bot.getLocation();
World world = loc.getWorld();
if (world == null) continue;
loc.setX(loc.getBlockX());
loc.setY(loc.getBlockY());
loc.setZ(loc.getBlockZ());
loc.add(0.5, 0.5, 0.5);
ArmorStand seat = (ArmorStand) world.spawnEntity(loc, EntityType.ARMOR_STAND);
seat.setVisible(false);
seat.setSmall(true);
bot.getBukkitEntity().setPassenger(seat);
}
}
public void sit(String content) {
Set<Bot> bots = PlayerAI.getInstance().getManager().fetch();
for (Bot bot : bots) {
Location loc = bot.getLocation();
World world = loc.getWorld();
if (world == null) continue;
loc.setX(loc.getBlockX());
loc.setY(loc.getBlockY());
loc.setZ(loc.getBlockZ());
loc.add(0.5, -1.5, 0.5);
ArmorStand seat = (ArmorStand) world.spawnEntity(loc, EntityType.ARMOR_STAND);
seat.setVisible(false);
seat.setGravity(false);
seat.setSmall(true);
seat.addPassenger(bot.getBukkitEntity());
}
}
public void look(String content) {
if (!(sender instanceof Player)) {
print("Unspecified player.");
return;
}
Player player = (Player) sender;
for (Bot bot : PlayerAI.getInstance().getManager().fetch()) {
bot.faceLocation(player.getEyeLocation());
}
}
public void printObj(String content) {
if (content.isEmpty()) {
print("null");

View File

@@ -45,4 +45,10 @@ public class MathUtils {
return false;
}
}
public static void clean(Vector vector) {
if (!NumberConversions.isFinite(vector.getX())) vector.setX(0);
if (!NumberConversions.isFinite(vector.getY())) vector.setY(0);
if (!NumberConversions.isFinite(vector.getZ())) vector.setZ(0);
}
}

View File

@@ -11,10 +11,12 @@ import java.util.Map;
public class MojangAPI {
private static final boolean CACHE_ENABLED = false;
private static final Map<String, String[]> CACHE = new HashMap<>();
public static String[] getSkin(String name) {
if (CACHE.containsKey(name)) {
if (CACHE_ENABLED && CACHE.containsKey(name)) {
return CACHE.get(name);
}

View File

@@ -4,7 +4,17 @@ import org.bukkit.GameMode;
public class PlayerUtils {
public static boolean isVulnerableGamemode(GameMode mode) {
return mode == GameMode.SURVIVAL || mode == GameMode.ADVENTURE;
public static boolean allTargetable;
public static boolean isTargetable(GameMode mode) {
return allTargetable || mode == GameMode.SURVIVAL || mode == GameMode.ADVENTURE;
}
public static void setAllTargetable(boolean b) {
allTargetable = b;
}
public static boolean getAllTargetable() {
return allTargetable;
}
}