1
0
mirror of https://github.com/Zrips/Jobs.git synced 2024-11-22 18:45:44 +01:00

Entity type recognition fix

This commit is contained in:
Zrips 2024-10-17 14:35:39 +03:00
parent 4a2862281b
commit 08f8fe807c
3 changed files with 63 additions and 52 deletions

View File

@ -32,6 +32,7 @@ import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.EntityType;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.EnchantmentStorageMeta;
@ -410,7 +411,7 @@ public class ConfigManager {
cfg.addComment(pt + ".Brew", "Brewing miscellaneous items");
generate(cfg, pt + ".Brew.nether_stalk");
generate(cfg, pt + ".Brew.redstone");
cfg.addComment(pt + ".Brush", "Brushing blocks and getting items from them");
generate(cfg, pt + ".Brush.suspicious_sand");
generate(cfg, pt + ".Brush.suspicious_gravel");
@ -810,10 +811,10 @@ public class ConfigManager {
Jobs.getExploreManager().setExploreEnabled();
Jobs.getExploreManager().setPlayerAmount(amount);
Jobs.getChunkExplorationManager().setExploreEnabled();
Jobs.getChunkExplorationManager().setPlayerAmount(amount);
Jobs.getChunkExplorationManager().setPlayerAmount(amount);
} else if (actionType == ActionType.CRAFT) {
if (myKey.startsWith("!")) {
type = myKey.substring(1, myKey.length());
@ -840,12 +841,12 @@ public class ConfigManager {
meta = "ALL";
// case for ":all" identifier
type = (actionType == ActionType.SHEAR && myKey.startsWith("color")) ? "color" : CMIMaterial.getGeneralMaterialName(type);
CMIEntityType entity = CMIEntityType.get(type);
if (entity != null) {
type = entity.toString();
}
type = entity.toString();
}
}
if (actionType == ActionType.TNTBREAK)

View File

@ -39,6 +39,7 @@ import com.gamingmesh.jobs.actions.EnchantActionInfo;
import com.gamingmesh.jobs.container.JobsWorld;
import net.Zrips.CMILib.Enchants.CMIEnchantment;
import net.Zrips.CMILib.Entities.CMIEntityType;
import net.Zrips.CMILib.Items.CMIMaterial;
import net.Zrips.CMILib.Version.Version;
@ -88,6 +89,9 @@ public final class Util {
public static String getRealType(Entity entity) {
if (Version.isCurrentEqualOrHigher(Version.v1_11_R1)) {
CMIEntityType ctype = CMIEntityType.get(entity);
if (ctype != null)
return ctype.toString();
return entity.getType().name();
}

View File

@ -5,106 +5,112 @@ import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.block.Block;
import net.Zrips.CMILib.Container.CMIWorld;
public class blockLoc {
private int x;
private int y;
private int z;
private World w;
private String worldName = null;
private boolean disabled = false;
public blockLoc(String loc) {
fromString(loc);
fromString(loc);
}
public blockLoc(Location loc) {
x = loc.getBlockX();
y = loc.getBlockY();
z = loc.getBlockZ();
w = loc.getWorld();
x = loc.getBlockX();
y = loc.getBlockY();
z = loc.getBlockZ();
w = loc.getWorld();
}
public String getWorldName() {
return w != null ? w.getName() : "__";
return w != null ? w.getName() : worldName != null ? worldName : "__";
}
public void setX(int x) {
this.x = x;
this.x = x;
}
public void setY(int y) {
this.y = y;
this.y = y;
}
public void setZ(int z) {
this.z = z;
this.z = z;
}
@Override
public String toString() {
return (w == null ? getWorldName() : w.getName()) + ":" + x + ":" + y + ":" + z;
return getWorldName() + ":" + x + ":" + y + ":" + z;
}
public String toVectorString() {
return x + ":" + y + ":" + z;
return x + ":" + y + ":" + z;
}
public boolean fromString(String loc) {
String[] split = loc.split(":", 4);
if (split.length == 0) {
return false;
}
String[] split = loc.split(":", 4);
if (split.length == 0) {
return false;
}
World w = Bukkit.getWorld(split[0]);
if (w == null)
return false;
this.w = w;
World w = CMIWorld.getWorld(split[0]);
if (w != null)
this.w = w;
else
this.worldName = split[0];
if (split.length < 4) {
return false;
}
if (split.length < 4) {
return false;
}
try {
x = Integer.parseInt(split[1]);
y = Integer.parseInt(split[2]);
z = Integer.parseInt(split[3]);
return true;
} catch (NumberFormatException e) {
return false;
}
try {
x = Integer.parseInt(split[1]);
y = Integer.parseInt(split[2]);
z = Integer.parseInt(split[3]);
return true;
} catch (NumberFormatException e) {
return false;
}
}
public Block getBlock() {
Location loc = getLocation();
return loc == null ? null : loc.getBlock();
Location loc = getLocation();
return loc == null ? null : loc.getBlock();
}
public Location getLocation() {
if (getWorldName() == null && w == null)
return null;
if (getWorldName() == null && w == null)
return null;
// Make sure cached world is loaded
World w = this.w == null ? Bukkit.getWorld(getWorldName()) : Bukkit.getWorld(this.w.getName());
if (w == null)
return null;
// Make sure cached world is loaded
World w = this.w == null ? Bukkit.getWorld(getWorldName()) : Bukkit.getWorld(this.w.getName());
if (w == null)
return null;
this.w = w;
this.w = w;
return new Location(w, x, y, z);
return new Location(w, x, y, z);
}
public boolean isDisabled() {
return disabled;
return disabled;
}
public void setDisabled(boolean disabled) {
this.disabled = disabled;
this.disabled = disabled;
}
public World getWorld() {
return w;
if (w == null && worldName != null)
w = CMIWorld.getWorld(worldName);
return w;
}
public void setWorld(World world) {
this.w = world;
this.w = world;
}
}