Re-implemented CompatibleMaterial + changed usages to XMaterial

This commit is contained in:
Christian Koop 2023-06-20 20:22:29 +02:00
parent d4fe43fd35
commit bac3c1b16e
No known key found for this signature in database
GPG Key ID: 89A8181384E010A3
56 changed files with 770 additions and 3774 deletions

View File

@ -119,6 +119,7 @@
<artifact>com.github.cryptomorin:XSeries</artifact>
<includes>
<include>com/cryptomorin/xseries/XMaterial*</include>
<include>com/cryptomorin/xseries/XBlock*</include>
</includes>
</filter>

View File

@ -1,6 +1,7 @@
package com.craftaro.core;
import com.craftaro.core.commands.CommandManager;
import com.craftaro.core.compatibility.ClientVersion;
import com.craftaro.core.core.LocaleModule;
import com.craftaro.core.core.PluginInfo;
import com.craftaro.core.core.PluginInfoModule;
@ -10,8 +11,7 @@ import com.craftaro.core.core.SongodaCoreLicenseCommand;
import com.craftaro.core.core.SongodaCoreUUIDCommand;
import com.craftaro.core.verification.CraftaroProductVerification;
import com.craftaro.core.verification.ProductVerificationStatus;
import com.craftaro.core.compatibility.ClientVersion;
import com.craftaro.core.compatibility.CompatibleMaterial;
import com.cryptomorin.xseries.XMaterial;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
@ -86,7 +86,7 @@ public class SongodaCore {
return !SongodaCore.class.getPackage().getName().equals(new String(new char[] {'c', 'o', 'm', '.', 'c', 'r', 'a', 'f', 't', 'a', 'r', 'o', '.', 'c', 'o', 'r', 'e'}));
}
public static void registerPlugin(JavaPlugin plugin, int pluginID, CompatibleMaterial icon) {
public static void registerPlugin(JavaPlugin plugin, int pluginID, XMaterial icon) {
registerPlugin(plugin, pluginID, icon == null ? "STONE" : icon.name(), CraftaroCoreConstants.getCoreVersion());
}

View File

@ -1,12 +1,12 @@
package com.craftaro.core;
import com.craftaro.core.configuration.Config;
import com.craftaro.core.database.DataManagerAbstract;
import com.craftaro.core.locale.Locale;
import com.craftaro.core.utils.Metrics;
import com.craftaro.core.verification.CraftaroProductVerification;
import com.craftaro.core.verification.ProductVerificationStatus;
import com.craftaro.core.compatibility.CompatibleMaterial;
import com.craftaro.core.database.DataManagerAbstract;
import com.cryptomorin.xseries.XMaterial;
import de.tr7zw.changeme.nbtapi.utils.MinecraftVersion;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
@ -102,7 +102,7 @@ public abstract class SongodaPlugin extends JavaPlugin {
ChatColor.YELLOW + "Run the command " + ChatColor.GOLD + "/craftaro license" + ChatColor.YELLOW + " and follow the instructions\n" +
ChatColor.RED + "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
this.licensePreventedPluginLoad = true;
SongodaCore.registerPlugin(this, CraftaroProductVerification.getProductId(), (CompatibleMaterial) null);
SongodaCore.registerPlugin(this, CraftaroProductVerification.getProductId(), (XMaterial) null);
getServer().getScheduler().scheduleSyncRepeatingTask(this, () -> {
String pluginName = getDescription().getName();

View File

@ -1,6 +1,6 @@
package com.craftaro.core.configuration;
import com.craftaro.core.compatibility.CompatibleMaterial;
import com.cryptomorin.xseries.XMaterial;
import org.bukkit.configuration.Configuration;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.InvalidConfigurationException;
@ -256,12 +256,12 @@ public class ConfigFileConfigurationAdapter extends FileConfiguration {
}
@Nullable
public CompatibleMaterial getMaterial(@NotNull String path) {
public XMaterial getMaterial(@NotNull String path) {
return config.getMaterial(path);
}
@Nullable
public CompatibleMaterial getMaterial(@NotNull String path, @Nullable CompatibleMaterial def) {
public XMaterial getMaterial(@NotNull String path, @Nullable XMaterial def) {
return config.getMaterial(path, def);
}

View File

@ -1,6 +1,7 @@
package com.craftaro.core.configuration;
import com.craftaro.core.compatibility.CompatibleMaterial;
import com.cryptomorin.xseries.XMaterial;
import org.bukkit.configuration.Configuration;
import org.bukkit.configuration.MemoryConfiguration;
import org.jetbrains.annotations.NotNull;
@ -714,18 +715,17 @@ public class ConfigSection extends MemoryConfiguration {
}
@Nullable
public CompatibleMaterial getMaterial(@NotNull String path) {
public XMaterial getMaterial(@NotNull String path) {
String val = getString(path);
return val != null ? CompatibleMaterial.getMaterial(val) : null;
return val != null ? CompatibleMaterial.getMaterial(val).orElse(null) : null;
}
@Nullable
public CompatibleMaterial getMaterial(@NotNull String path, @Nullable CompatibleMaterial def) {
public XMaterial getMaterial(@NotNull String path, @Nullable XMaterial def) {
String val = getString(path);
CompatibleMaterial mat = val != null ? CompatibleMaterial.getMaterial(val) : null;
XMaterial mat = val != null ? CompatibleMaterial.getMaterial(val).orElse(def) : null;
return mat != null ? mat : def;
}

View File

@ -2,10 +2,12 @@ package com.craftaro.core.configuration;
import com.craftaro.core.SongodaCore;
import com.craftaro.core.compatibility.CompatibleMaterial;
import com.cryptomorin.xseries.XMaterial;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.List;
import java.util.Optional;
import java.util.logging.Level;
public class ConfigSetting {
@ -109,27 +111,25 @@ public class ConfigSetting {
}
@NotNull
public CompatibleMaterial getMaterial() {
public XMaterial getMaterial() {
String val = config.getString(key);
CompatibleMaterial mat = CompatibleMaterial.getMaterial(config.getString(key));
Optional<XMaterial> mat = CompatibleMaterial.getMaterial(config.getString(key));
if (mat == null) {
if (!mat.isPresent()) {
SongodaCore.getLogger().log(Level.WARNING, String.format("Config value \"%s\" has an invalid material name: \"%s\"", key, val));
}
return mat != null ? mat : CompatibleMaterial.STONE;
return mat.orElse(XMaterial.STONE);
}
@NotNull
public CompatibleMaterial getMaterial(@NotNull CompatibleMaterial def) {
public XMaterial getMaterial(@NotNull XMaterial def) {
//return config.getMaterial(key, def);
String val = config.getString(key);
CompatibleMaterial mat = val != null ? CompatibleMaterial.getMaterial(val) : null;
Optional<XMaterial> mat = val != null ? CompatibleMaterial.getMaterial(val) : Optional.empty();
if (mat == null) {
if (!mat.isPresent()) {
SongodaCore.getLogger().log(Level.WARNING, String.format("Config value \"%s\" has an invalid material name: \"%s\"", key, val));
}
return mat != null ? mat : def;
return mat.orElse(def);
}
}

View File

@ -7,6 +7,7 @@ import com.craftaro.core.gui.GuiUtils;
import com.craftaro.core.gui.SimplePagedGui;
import com.craftaro.core.input.ChatPrompt;
import com.craftaro.core.utils.ItemUtils;
import com.cryptomorin.xseries.XMaterial;
import org.bukkit.ChatColor;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.MemoryConfiguration;
@ -22,7 +23,9 @@ import java.io.IOException;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;
import java.util.Optional;
import java.util.logging.Level;
/**
@ -51,7 +54,7 @@ public class ConfigEditorGui extends SimplePagedGui {
this.file = file;
this.config = config;
this.node = node;
this.blankItem = GuiUtils.getBorderItem(CompatibleMaterial.LIGHT_GRAY_STAINED_GLASS_PANE);
this.blankItem = GuiUtils.getBorderItem(XMaterial.LIGHT_GRAY_STAINED_GLASS_PANE);
if (!(parent instanceof ConfigEditorGui)) {
setOnClose((gui) -> save());
@ -68,10 +71,10 @@ public class ConfigEditorGui extends SimplePagedGui {
// decorate header
this.setTitle(ChatColor.DARK_BLUE + file);
this.setUseHeader(true);
headerBackItem = footerBackItem = GuiUtils.getBorderItem(CompatibleMaterial.GRAY_STAINED_GLASS_PANE.getItem());
headerBackItem = footerBackItem = GuiUtils.getBorderItem(XMaterial.GRAY_STAINED_GLASS_PANE.parseItem());
final String path = node.getCurrentPath();
this.setItem(4, configItem(CompatibleMaterial.FILLED_MAP, !path.isEmpty() ? path : file, config, !path.isEmpty() ? path : null, ChatColor.BLACK.toString()));
this.setButton(8, GuiUtils.createButtonItem(CompatibleMaterial.OAK_DOOR, "Exit"), (event) -> event.player.closeInventory());
this.setItem(4, configItem(XMaterial.FILLED_MAP, !path.isEmpty() ? path : file, config, !path.isEmpty() ? path : null, ChatColor.BLACK.toString()));
this.setButton(8, GuiUtils.createButtonItem(XMaterial.OAK_DOOR, "Exit"), (event) -> event.player.closeInventory());
// compile list of settings
for (String key : node.getKeys(false)) {
@ -86,7 +89,7 @@ public class ConfigEditorGui extends SimplePagedGui {
// next we need to display the config settings
int index = 9;
for (final String sectionKey : sections) {
setButton(index++, configItem(CompatibleMaterial.WRITABLE_BOOK, ChatColor.YELLOW + sectionKey, node, sectionKey, "Click to open this section"),
setButton(index++, configItem(XMaterial.WRITABLE_BOOK, ChatColor.YELLOW + sectionKey, node, sectionKey, "Click to open this section"),
(event) -> event.manager.showGUI(event.player, new ConfigEditorGui(player, plugin, this, file, config, node.getConfigurationSection(sectionKey))));
}
@ -99,7 +102,7 @@ public class ConfigEditorGui extends SimplePagedGui {
if (val instanceof Boolean) {
// toggle switch
setButton(index, configItem(CompatibleMaterial.LEVER, ChatColor.YELLOW + settingKey, node, settingKey, String.valueOf(val), "Click to toggle this setting"),
setButton(index, configItem(XMaterial.LEVER, ChatColor.YELLOW + settingKey, node, settingKey, String.valueOf(val), "Click to toggle this setting"),
(event) -> this.toggle(event.slot, settingKey));
if ((Boolean) val) {
@ -107,7 +110,7 @@ public class ConfigEditorGui extends SimplePagedGui {
}
} else if (isNumber(val)) {
// number dial
this.setButton(index, configItem(CompatibleMaterial.CLOCK, ChatColor.YELLOW + settingKey, node, settingKey, String.valueOf(val), "Click to edit this setting"),
this.setButton(index, configItem(XMaterial.CLOCK, ChatColor.YELLOW + settingKey, node, settingKey, String.valueOf(val), "Click to edit this setting"),
(event) -> {
event.gui.exit();
ChatPrompt.showPrompt(plugin, event.player, "Enter a new number value for " + settingKey + ":", response -> {
@ -123,14 +126,14 @@ public class ConfigEditorGui extends SimplePagedGui {
} else if (isMaterial(val)) {
// changing a block
// isMaterial is more of a guess, to be honest.
setButton(index, configItem(CompatibleMaterial.STONE, ChatColor.YELLOW + settingKey, node, settingKey, val.toString(), "Click to edit this setting"),
setButton(index, configItem(XMaterial.STONE, ChatColor.YELLOW + settingKey, node, settingKey, val.toString(), "Click to edit this setting"),
(event) -> {
SimplePagedGui paged = new SimplePagedGui(this);
paged.setTitle(ChatColor.BLUE + settingKey);
paged.setHeaderBackItem(headerBackItem).setFooterBackItem(footerBackItem).setDefaultItem(blankItem);
paged.setItem(4, configItem(CompatibleMaterial.FILLED_MAP, settingKey, node, settingKey, "Choose an item to change this value to"));
paged.setItem(4, configItem(XMaterial.FILLED_MAP, settingKey, node, settingKey, "Choose an item to change this value to"));
int i = 9;
for (CompatibleMaterial mat : CompatibleMaterial.getAllValidItemMaterials()) {
for (XMaterial mat : getAllValidMaterials()) {
try {
ItemStack buttonItem = GuiUtils.createButtonItem(mat, mat.name());
if (!buttonItem.getType().isItem()) continue;
@ -147,7 +150,7 @@ public class ConfigEditorGui extends SimplePagedGui {
});
} else if (val instanceof String) {
// changing a "string" value (or change to a feather for writing quill)
setButton(index, configItem(CompatibleMaterial.STRING, ChatColor.YELLOW + settingKey, node, settingKey, val.toString(), "Click to edit this setting"),
setButton(index, configItem(XMaterial.STRING, ChatColor.YELLOW + settingKey, node, settingKey, val.toString(), "Click to edit this setting"),
(event) -> {
event.gui.exit();
ChatPrompt.showPrompt(plugin, event.player, "Enter a new value for " + settingKey + ":", response -> {
@ -160,7 +163,7 @@ public class ConfigEditorGui extends SimplePagedGui {
});
});
} else if (val instanceof List) {
setButton(index, configItem(CompatibleMaterial.WRITABLE_BOOK, ChatColor.YELLOW + settingKey, node, settingKey, String.format("(%d values)", ((List<?>) val).size()), "Click to edit this setting"),
setButton(index, configItem(XMaterial.WRITABLE_BOOK, ChatColor.YELLOW + settingKey, node, settingKey, String.format("(%d values)", ((List<?>) val).size()), "Click to edit this setting"),
(event) ->
event.manager.showGUI(event.player, (new ConfigEditorListEditorGui(this, settingKey, (List) val)).setOnClose((gui) -> {
if (((ConfigEditorListEditorGui) gui.gui).saveChanges) {
@ -244,12 +247,12 @@ public class ConfigEditorGui extends SimplePagedGui {
}
void setMaterial(int clickCell, String path, ItemStack item) {
CompatibleMaterial mat = CompatibleMaterial.getMaterial(item);
Optional<XMaterial> mat = CompatibleMaterial.getMaterial(item.getType());
if (mat == null) {
node.set(path, CompatibleMaterial.STONE.name());
if (!mat.isPresent()) {
node.set(path, XMaterial.STONE.name());
} else {
node.set(path, mat.name());
node.set(path, mat.get().name());
}
updateValue(clickCell, path);
@ -293,13 +296,15 @@ public class ConfigEditorGui extends SimplePagedGui {
}
private boolean isMaterial(Object value) {
CompatibleMaterial m;
if (!(value instanceof String && value.toString().equals(value.toString().toUpperCase()))) {
return false;
}
return value instanceof String && value.toString().equals(value.toString().toUpperCase())
&& (m = CompatibleMaterial.getMaterial(value.toString())) != null && m.isValidItem();
Optional<XMaterial> material = CompatibleMaterial.getMaterial(value.toString());
return material.isPresent() && material.get().isSupported();
}
protected ItemStack configItem(CompatibleMaterial type, String name, ConfigurationSection node, String path, String def) {
protected ItemStack configItem(XMaterial type, String name, ConfigurationSection node, String path, String def) {
String[] info = null;
if (configSection_getCommentString != null) {
@ -316,7 +321,7 @@ public class ConfigEditorGui extends SimplePagedGui {
return GuiUtils.createButtonItem(type, name, info != null ? info : (def != null ? def.split("\n") : null));
}
protected ItemStack configItem(CompatibleMaterial type, String name, ConfigurationSection node, String path, String value, String def) {
protected ItemStack configItem(XMaterial type, String name, ConfigurationSection node, String path, String value, String def) {
if (value == null) {
value = "";
}
@ -335,4 +340,14 @@ public class ConfigEditorGui extends SimplePagedGui {
return GuiUtils.createButtonItem(type, name, info != null ? info : (def != null ? (value + "\n" + def).split("\n") : null));
}
private List<XMaterial> getAllValidMaterials() {
List<XMaterial> materials = new LinkedList<>();
for (XMaterial material : XMaterial.values()) {
if (material.isSupported()) {
materials.add(material);
}
}
return materials;
}
}

View File

@ -1,9 +1,9 @@
package com.craftaro.core.configuration.editor;
import com.craftaro.core.compatibility.CompatibleMaterial;
import com.craftaro.core.gui.GuiUtils;
import com.craftaro.core.gui.SimplePagedGui;
import com.craftaro.core.input.ChatPrompt;
import com.cryptomorin.xseries.XMaterial;
import org.bukkit.ChatColor;
import org.bukkit.event.inventory.ClickType;
@ -27,16 +27,16 @@ public class ConfigEditorListEditorGui extends SimplePagedGui {
headerBackItem = footerBackItem = current.getHeaderBackItem();
setTitle(ChatColor.DARK_BLUE + "String List Editor");
this.setUseHeader(true);
this.setItem(4, current.configItem(CompatibleMaterial.FILLED_MAP, key, current.getCurrentNode(), key, null));
this.setButton(8, GuiUtils.createButtonItem(CompatibleMaterial.OAK_DOOR, "Exit"), (event) -> event.player.closeInventory());
this.setItem(4, current.configItem(XMaterial.FILLED_MAP, key, current.getCurrentNode(), key, null));
this.setButton(8, GuiUtils.createButtonItem(XMaterial.OAK_DOOR, "Exit"), (event) -> event.player.closeInventory());
this.values = new ArrayList<>(val);
this.setButton(8, GuiUtils.createButtonItem(CompatibleMaterial.LAVA_BUCKET, ChatColor.RED + "Discard Changes"), (event) -> event.player.closeInventory());
this.setButton(0, GuiUtils.createButtonItem(CompatibleMaterial.REDSTONE, ChatColor.GREEN + "Save"), (event) -> {
this.setButton(8, GuiUtils.createButtonItem(XMaterial.LAVA_BUCKET, ChatColor.RED + "Discard Changes"), (event) -> event.player.closeInventory());
this.setButton(0, GuiUtils.createButtonItem(XMaterial.REDSTONE, ChatColor.GREEN + "Save"), (event) -> {
saveChanges = true;
event.player.closeInventory();
});
this.setButton(1, GuiUtils.createButtonItem(CompatibleMaterial.CHEST, ChatColor.BLUE + "Add Item"),
this.setButton(1, GuiUtils.createButtonItem(XMaterial.CHEST, ChatColor.BLUE + "Add Item"),
(event) -> {
event.gui.exit();
ChatPrompt.showPrompt(event.manager.getPlugin(), event.player, "Enter a new value to add:", response -> {
@ -70,7 +70,7 @@ public class ConfigEditorListEditorGui extends SimplePagedGui {
int i = 9;
for (String item : values) {
final int index = i - 9;
setButton(i++, GuiUtils.createButtonItem(CompatibleMaterial.PAPER, item, "Right-click to remove"), ClickType.RIGHT, (event) -> {
setButton(i++, GuiUtils.createButtonItem(XMaterial.PAPER, item, "Right-click to remove"), ClickType.RIGHT, (event) -> {
values.remove(index);
redraw();
});

View File

@ -1,11 +1,11 @@
package com.craftaro.core.configuration.editor;
import com.craftaro.core.SongodaPlugin;
import com.craftaro.core.compatibility.CompatibleMaterial;
import com.craftaro.core.configuration.Config;
import com.craftaro.core.gui.Gui;
import com.craftaro.core.gui.GuiUtils;
import com.craftaro.core.gui.SimplePagedGui;
import com.cryptomorin.xseries.XMaterial;
import org.bukkit.ChatColor;
import org.bukkit.configuration.MemoryConfiguration;
import org.bukkit.plugin.java.JavaPlugin;
@ -79,18 +79,18 @@ public class PluginConfigGui extends SimplePagedGui {
}
private void init() {
this.blankItem = GuiUtils.getBorderItem(CompatibleMaterial.LIGHT_GRAY_STAINED_GLASS_PANE);
this.blankItem = GuiUtils.getBorderItem(XMaterial.LIGHT_GRAY_STAINED_GLASS_PANE);
// decorate header
this.setTitle(ChatColor.DARK_BLUE + plugin.getName() + " Plugin Config");
this.setUseHeader(true);
headerBackItem = footerBackItem = GuiUtils.getBorderItem(CompatibleMaterial.GRAY_STAINED_GLASS_PANE.getItem());
this.setButton(8, GuiUtils.createButtonItem(CompatibleMaterial.OAK_DOOR, "Exit"), (event) -> event.player.closeInventory());
headerBackItem = footerBackItem = GuiUtils.getBorderItem(XMaterial.GRAY_STAINED_GLASS_PANE.parseItem());
this.setButton(8, GuiUtils.createButtonItem(XMaterial.OAK_DOOR, "Exit"), (event) -> event.player.closeInventory());
// List out all config files that this plugin has
int i = 9;
for (Map.Entry<String, MemoryConfiguration> config : configs.entrySet()) {
this.setButton(i++, GuiUtils.createButtonItem(CompatibleMaterial.BOOK, ChatColor.YELLOW + config.getKey(), "Click to edit this config"),
this.setButton(i++, GuiUtils.createButtonItem(XMaterial.BOOK, ChatColor.YELLOW + config.getKey(), "Click to edit this config"),
(event) -> event.manager.showGUI(event.player, new ConfigEditorGui(event.player, plugin, this, config.getKey(), config.getValue())));
}
}

View File

@ -1,7 +1,8 @@
package com.craftaro.core.core;
import com.craftaro.core.verification.ProductVerificationStatus;
import com.craftaro.core.compatibility.CompatibleMaterial;
import com.craftaro.core.verification.ProductVerificationStatus;
import com.cryptomorin.xseries.XMaterial;
import org.bukkit.plugin.java.JavaPlugin;
import org.json.simple.JSONObject;
@ -13,7 +14,7 @@ public final class PluginInfo {
protected final JavaPlugin javaPlugin;
protected final int songodaId;
protected final String coreIcon;
protected final CompatibleMaterial icon;
protected final XMaterial icon;
protected final String coreLibraryVersion;
public final ProductVerificationStatus verificationStatus;
@ -29,7 +30,7 @@ public final class PluginInfo {
this.javaPlugin = javaPlugin;
this.songodaId = songodaId;
this.coreIcon = icon;
this.icon = CompatibleMaterial.getMaterial(icon);
this.icon = CompatibleMaterial.getMaterial(icon).orElse(XMaterial.STONE);
this.coreLibraryVersion = coreLibraryVersion;
this.verificationStatus = verificationStatus;
}

View File

@ -1,10 +1,10 @@
package com.craftaro.core.core;
import com.craftaro.core.configuration.editor.PluginConfigGui;
import com.craftaro.core.gui.GuiUtils;
import com.craftaro.core.SongodaCore;
import com.craftaro.core.compatibility.CompatibleMaterial;
import com.craftaro.core.configuration.editor.PluginConfigGui;
import com.craftaro.core.gui.Gui;
import com.craftaro.core.gui.GuiUtils;
import com.cryptomorin.xseries.XMaterial;
import org.bukkit.ChatColor;
import org.bukkit.event.inventory.ClickType;
@ -24,7 +24,7 @@ final class SongodaCoreOverviewGUI extends Gui {
final PluginInfo plugin = plugins.get(i);
if (plugin.hasUpdate()) {
setButton(i, GuiUtils.createButtonItem(plugin.icon != null ? plugin.icon : CompatibleMaterial.STONE,
setButton(i, GuiUtils.createButtonItem(plugin.icon != null ? plugin.icon : XMaterial.STONE,
ChatColor.GOLD + plugin.getJavaPlugin().getName(),
ChatColor.GRAY + "Latest Version: " + plugin.getLatestVersion(),
ChatColor.GRAY + "Installed Version: " + plugin.getJavaPlugin().getDescription().getVersion(),
@ -42,7 +42,7 @@ final class SongodaCoreOverviewGUI extends Gui {
continue;
}
setButton(i, GuiUtils.createButtonItem(plugin.icon != null ? plugin.icon : CompatibleMaterial.STONE,
setButton(i, GuiUtils.createButtonItem(plugin.icon != null ? plugin.icon : XMaterial.STONE,
ChatColor.GOLD + plugin.getJavaPlugin().getName(),
ChatColor.GRAY + "Installed Version: " + plugin.getJavaPlugin().getDescription().getVersion(),
"",

View File

@ -2,9 +2,9 @@ package com.craftaro.core.gui;
import com.craftaro.core.gui.methods.Clickable;
import com.craftaro.core.nms.Nms;
import com.craftaro.core.compatibility.CompatibleMaterial;
import com.craftaro.core.nms.anvil.AnvilCore;
import com.craftaro.core.nms.anvil.CustomAnvil;
import com.cryptomorin.xseries.XMaterial;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.ClickType;
import org.bukkit.inventory.Inventory;
@ -108,7 +108,7 @@ public class AnvilGui extends Gui {
inventory.setItem(1, item);
} else if (!acceptsItems) {
item = GuiUtils.createButtonItem(CompatibleMaterial.PAPER, " ", " ");
item = GuiUtils.createButtonItem(XMaterial.PAPER, " ", " ");
cellItems.put(0, item);
inventory.setItem(0, item);

View File

@ -1,11 +1,12 @@
package com.craftaro.core.gui;
import com.craftaro.core.compatibility.CompatibleMaterial;
import com.craftaro.core.compatibility.ServerVersion;
import com.craftaro.core.configuration.Config;
import com.craftaro.core.configuration.ConfigSection;
import com.craftaro.core.gui.methods.Clickable;
import com.craftaro.core.utils.TextUtils;
import com.craftaro.core.compatibility.CompatibleMaterial;
import com.craftaro.core.compatibility.ServerVersion;
import com.cryptomorin.xseries.XMaterial;
import org.bukkit.Bukkit;
import org.bukkit.event.inventory.ClickType;
import org.bukkit.inventory.Inventory;
@ -49,7 +50,7 @@ public class CustomizableGui extends Gui {
config.load();
if (!config.isConfigurationSection("overrides")) {
config.setDefault("overrides.example.item", CompatibleMaterial.STONE.name(),
config.setDefault("overrides.example.item", XMaterial.STONE.name(),
"This is the icon material you would like to replace",
"the current material with.")
.setDefault("overrides.example.position", 5,
@ -92,19 +93,19 @@ public class CustomizableGui extends Gui {
section.getInt("col", -1),
section.getBoolean("mirrorrow", false),
section.getBoolean("mirrorcol", false),
section.isSet("item") ? CompatibleMaterial.getMaterial(section.getString("item")) : null);
section.isSet("item") ? CompatibleMaterial.getMaterial(section.getString("item")).get() : null);
} else {
customContent.addButton(section.getNodeKey(), section.getInt("row", -1),
section.getInt("col", -1),
section.getString("title", null),
section.isSet("lore") ? section.getStringList("lore") : null,
section.isSet("item") ? CompatibleMaterial.getMaterial(section.getString("item")) : null);
section.isSet("item") ? CompatibleMaterial.getMaterial(section.getString("item")).get() : null);
}
} else {
customContent.addButton(section.getNodeKey(), section.getString("position", "-1"),
section.getString("title", null),
section.isSet("lore") ? section.getStringList("lore") : null,
section.isSet("item") ? CompatibleMaterial.getMaterial(section.getString("item")) : null);
section.isSet("item") ? CompatibleMaterial.getMaterial(section.getString("item")).get() : null);
}
}
@ -475,7 +476,7 @@ public class CustomizableGui extends Gui {
}
@NotNull
public Gui updateItem(@NotNull String key, int row, int col, @NotNull CompatibleMaterial itemTo, @Nullable String title, @NotNull String... lore) {
public Gui updateItem(@NotNull String key, int row, int col, @NotNull XMaterial itemTo, @Nullable String title, @NotNull String... lore) {
if (customContent.isButtonDisabled(key)) {
return this;
}
@ -484,7 +485,7 @@ public class CustomizableGui extends Gui {
}
@NotNull
public Gui updateItem(@NotNull String key, int cell, @NotNull CompatibleMaterial itemTo, @Nullable String title, @Nullable String... lore) {
public Gui updateItem(@NotNull String key, int cell, @NotNull XMaterial itemTo, @Nullable String title, @Nullable String... lore) {
List<Integer> cells = Collections.singletonList(cell);
if (customContent.isButtonDisabled(key)) {
@ -531,7 +532,7 @@ public class CustomizableGui extends Gui {
}
@NotNull
public Gui updateItem(@NotNull String key, int row, int col, @NotNull CompatibleMaterial itemTo, @Nullable String title, @Nullable List<String> lore) {
public Gui updateItem(@NotNull String key, int row, int col, @NotNull XMaterial itemTo, @Nullable String title, @Nullable List<String> lore) {
if (customContent.isButtonDisabled(key)) {
return this;
}
@ -540,7 +541,7 @@ public class CustomizableGui extends Gui {
}
@NotNull
public Gui updateItem(@NotNull String key, int cell, @NotNull CompatibleMaterial itemTo, @Nullable String title, @Nullable List<String> lore) {
public Gui updateItem(@NotNull String key, int cell, @NotNull XMaterial itemTo, @Nullable String title, @Nullable List<String> lore) {
List<Integer> cells = Collections.singletonList(cell);
if (customContent.isButtonDisabled(key)) {
@ -826,9 +827,9 @@ public class CustomizableGui extends Gui {
private final String title;
private final List<String> lore;
private final CompatibleMaterial item;
private final XMaterial item;
public CustomButton(String key, List<Integer> positions, String title, List<String> lore, CompatibleMaterial item) {
public CustomButton(String key, List<Integer> positions, String title, List<String> lore, XMaterial item) {
this.key = key;
this.positions = positions;
this.row = -1;
@ -838,7 +839,7 @@ public class CustomizableGui extends Gui {
this.lore = lore;
}
public CustomButton(String key, int row, int col, String title, List<String> lore, CompatibleMaterial item) {
public CustomButton(String key, int row, int col, String title, List<String> lore, XMaterial item) {
this.key = key;
this.positions = null;
this.row = row;
@ -857,7 +858,7 @@ public class CustomizableGui extends Gui {
return false;
}
item.setType(this.item.getMaterial());
item.setType(this.item.parseMaterial());
if (ServerVersion.isServerVersionAtOrBelow(ServerVersion.V1_13)) {
item.setDurability(this.item.getData());
@ -869,7 +870,7 @@ public class CustomizableGui extends Gui {
}
public ItemStack createItem() {
ItemStack item = this.item.getItem();
ItemStack item = this.item.parseItem();
applyMeta(item);
return item;
@ -910,7 +911,7 @@ public class CustomizableGui extends Gui {
private final boolean mirrorRow;
private final boolean mirrorCol;
public MirrorFill(String key, int row, int col, boolean mirrorRow, boolean mirrorCol, CompatibleMaterial item) {
public MirrorFill(String key, int row, int col, boolean mirrorRow, boolean mirrorCol, XMaterial item) {
super(key, row, col, null, null, item);
this.mirrorRow = mirrorRow;
@ -954,7 +955,7 @@ public class CustomizableGui extends Gui {
return Collections.unmodifiableMap(customButtons);
}
public void addButton(String key, String position, String title, List<String> lore, CompatibleMaterial item) {
public void addButton(String key, String position, String title, List<String> lore, XMaterial item) {
List<Integer> positions = Arrays.stream(position.split(","))
.map(Integer::parseInt)
.collect(Collectors.toList());
@ -969,7 +970,7 @@ public class CustomizableGui extends Gui {
customizedButtons.put(key, customButton);
}
public void addButton(String key, int row, int col, String title, List<String> lore, CompatibleMaterial item) {
public void addButton(String key, int row, int col, String title, List<String> lore, XMaterial item) {
CustomButton customButton = new CustomButton(key, row, col, title, lore, item);
if (key.startsWith("custom_")) {
@ -980,7 +981,7 @@ public class CustomizableGui extends Gui {
customizedButtons.put(key, customButton);
}
public void addButton(String key, int row, int col, boolean mirrorRow, boolean mirrorCol, CompatibleMaterial item) {
public void addButton(String key, int row, int col, boolean mirrorRow, boolean mirrorCol, XMaterial item) {
MirrorFill mirrorFill = new MirrorFill(key, row, col, mirrorRow, mirrorCol, item);
if (key.startsWith("custom_")) {

View File

@ -8,7 +8,7 @@ import com.craftaro.core.gui.methods.Droppable;
import com.craftaro.core.gui.methods.Openable;
import com.craftaro.core.gui.methods.Pagable;
import com.craftaro.core.utils.ItemUtils;
import com.craftaro.core.compatibility.CompatibleMaterial;
import com.cryptomorin.xseries.XMaterial;
import org.bukkit.entity.HumanEntity;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.ClickType;
@ -461,12 +461,12 @@ public class DoubleGui extends Gui {
}
@Override
public DoubleGui updateItem(int row, int col, CompatibleMaterial itemTo, String title, String... lore) {
public DoubleGui updateItem(int row, int col, XMaterial itemTo, String title, String... lore) {
return (DoubleGui) super.updateItem(col + row * 9, itemTo, title, lore);
}
@Override
public DoubleGui updateItem(int cell, CompatibleMaterial itemTo, String title, String... lore) {
public DoubleGui updateItem(int cell, XMaterial itemTo, String title, String... lore) {
return (DoubleGui) super.updateItem(cell, itemTo, title, lore);
}
@ -481,12 +481,12 @@ public class DoubleGui extends Gui {
}
@Override
public DoubleGui updateItem(int row, int col, CompatibleMaterial itemTo, String title, List<String> lore) {
public DoubleGui updateItem(int row, int col, XMaterial itemTo, String title, List<String> lore) {
return (DoubleGui) super.updateItem(col + row * 9, itemTo, title, lore);
}
@Override
public DoubleGui updateItem(int cell, CompatibleMaterial itemTo, String title, List<String> lore) {
public DoubleGui updateItem(int cell, XMaterial itemTo, String title, List<String> lore) {
return (DoubleGui) super.updateItem(cell, itemTo, title, lore);
}

View File

@ -11,9 +11,9 @@ import com.craftaro.core.gui.methods.Droppable;
import com.craftaro.core.gui.methods.Openable;
import com.craftaro.core.gui.methods.Pagable;
import com.craftaro.core.utils.ItemUtils;
import com.craftaro.core.compatibility.CompatibleMaterial;
import com.craftaro.core.compatibility.CompatibleSound;
import com.craftaro.core.compatibility.ServerVersion;
import com.cryptomorin.xseries.XMaterial;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.ClickType;
@ -501,12 +501,12 @@ public class Gui {
}
@NotNull
public Gui updateItem(int row, int col, @NotNull CompatibleMaterial itemTo, @Nullable String title, @NotNull String... lore) {
public Gui updateItem(int row, int col, @NotNull XMaterial itemTo, @Nullable String title, @NotNull String... lore) {
return updateItem(col + row * inventoryType.columns, itemTo, title, lore);
}
@NotNull
public Gui updateItem(int cell, @NotNull CompatibleMaterial itemTo, @Nullable String title, @Nullable String... lore) {
public Gui updateItem(int cell, @NotNull XMaterial itemTo, @Nullable String title, @Nullable String... lore) {
ItemStack item = cellItems.get(cell);
if (item != null && item.getType() != Material.AIR) {
@ -533,12 +533,12 @@ public class Gui {
}
@NotNull
public Gui updateItem(int row, int col, @NotNull CompatibleMaterial itemTo, @Nullable String title, @Nullable List<String> lore) {
public Gui updateItem(int row, int col, @NotNull XMaterial itemTo, @Nullable String title, @Nullable List<String> lore) {
return updateItem(col + row * inventoryType.columns, itemTo, title, lore);
}
@NotNull
public Gui updateItem(int cell, @NotNull CompatibleMaterial itemTo, @Nullable String title, @Nullable List<String> lore) {
public Gui updateItem(int cell, @NotNull XMaterial itemTo, @Nullable String title, @Nullable List<String> lore) {
ItemStack item = cellItems.get(cell);
if (item != null && item.getType() != Material.AIR) {

View File

@ -1,8 +1,8 @@
package com.craftaro.core.gui;
import com.craftaro.core.compatibility.ClientVersion;
import com.craftaro.core.compatibility.CompatibleMaterial;
import com.craftaro.core.compatibility.ServerVersion;
import com.cryptomorin.xseries.XMaterial;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.entity.Player;
@ -123,14 +123,14 @@ public class GuiManager {
}
public void showPopup(Player player, String message) {
showPopup(player, message, CompatibleMaterial.NETHER_STAR, BackgroundType.ADVENTURE);
showPopup(player, message, XMaterial.NETHER_STAR, BackgroundType.ADVENTURE);
}
public void showPopup(Player player, String message, CompatibleMaterial icon) {
public void showPopup(Player player, String message, XMaterial icon) {
showPopup(player, message, icon, BackgroundType.ADVENTURE);
}
public void showPopup(Player player, String message, CompatibleMaterial icon, BackgroundType background) {
public void showPopup(Player player, String message, XMaterial icon, BackgroundType background) {
if (ClientVersion.getClientVersion(player).isAtLeast(ServerVersion.V1_12)) {
PopupMessage popup = new PopupMessage(plugin, icon, message, background);
popup.add();

View File

@ -1,6 +1,7 @@
package com.craftaro.core.gui;
import com.craftaro.core.compatibility.CompatibleMaterial;
import com.cryptomorin.xseries.XMaterial;
import org.bukkit.ChatColor;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
@ -12,7 +13,7 @@ import java.util.List;
public class GuiUtils {
public static ItemStack getBorderGlassItem() {
ItemStack glass = CompatibleMaterial.LIGHT_BLUE_STAINED_GLASS_PANE.getItem();
ItemStack glass = XMaterial.LIGHT_BLUE_STAINED_GLASS_PANE.parseItem();
ItemMeta glassmeta = glass.getItemMeta();
glassmeta.setDisplayName(ChatColor.BLACK.toString());
@ -30,8 +31,8 @@ public class GuiUtils {
return item;
}
public static ItemStack getBorderItem(CompatibleMaterial mat) {
ItemStack item = mat.getItem();
public static ItemStack getBorderItem(XMaterial mat) {
ItemStack item = mat.parseItem();
ItemMeta glassmeta = item.getItemMeta();
glassmeta.setDisplayName(ChatColor.BLACK.toString());
@ -98,8 +99,8 @@ public class GuiUtils {
return newLore;
}
public static ItemStack createButtonItem(CompatibleMaterial mat, String title, String... lore) {
ItemStack item = mat.getItem();
public static ItemStack createButtonItem(XMaterial mat, String title, String... lore) {
ItemStack item = mat.parseItem();
ItemMeta meta = item.getItemMeta();
if (meta != null) {
@ -117,8 +118,8 @@ public class GuiUtils {
return item;
}
public static ItemStack createButtonItem(CompatibleMaterial mat, int amount, String title, String... lore) {
ItemStack item = mat.getItem();
public static ItemStack createButtonItem(XMaterial mat, int amount, String title, String... lore) {
ItemStack item = mat.parseItem();
item.setAmount(amount);
ItemMeta meta = item.getItemMeta();
@ -157,8 +158,8 @@ public class GuiUtils {
return item;
}
public static ItemStack createButtonItem(CompatibleMaterial mat, String title, List<String> lore) {
ItemStack item = mat.getItem();
public static ItemStack createButtonItem(XMaterial mat, String title, List<String> lore) {
ItemStack item = mat.parseItem();
ItemMeta meta = item.getItemMeta();
if (meta != null) {
@ -176,8 +177,8 @@ public class GuiUtils {
return item;
}
public static ItemStack createButtonItem(CompatibleMaterial mat, int amount, String title, List<String> lore) {
ItemStack item = mat.getItem();
public static ItemStack createButtonItem(XMaterial mat, int amount, String title, List<String> lore) {
ItemStack item = mat.parseItem();
item.setAmount(amount);
ItemMeta meta = item.getItemMeta();
@ -216,8 +217,8 @@ public class GuiUtils {
return item;
}
public static ItemStack createButtonItem(CompatibleMaterial mat, String[] lore) {
ItemStack item = mat.getItem();
public static ItemStack createButtonItem(XMaterial mat, String[] lore) {
ItemStack item = mat.parseItem();
ItemMeta meta = item.getItemMeta();
if (meta != null) {
@ -236,8 +237,8 @@ public class GuiUtils {
return item;
}
public static ItemStack createButtonItem(CompatibleMaterial mat, int amount, String[] lore) {
ItemStack item = mat.getItem();
public static ItemStack createButtonItem(XMaterial mat, int amount, String[] lore) {
ItemStack item = mat.parseItem();
item.setAmount(amount);
ItemMeta meta = item.getItemMeta();
@ -278,8 +279,8 @@ public class GuiUtils {
return item;
}
public static ItemStack createButtonItem(CompatibleMaterial mat, List<String> lore) {
ItemStack item = mat.getItem();
public static ItemStack createButtonItem(XMaterial mat, List<String> lore) {
ItemStack item = mat.parseItem();
ItemMeta meta = item.getItemMeta();
if (meta != null) {
@ -298,8 +299,8 @@ public class GuiUtils {
return item;
}
public static ItemStack createButtonItem(CompatibleMaterial mat, int amount, List<String> lore) {
ItemStack item = mat.getItem();
public static ItemStack createButtonItem(XMaterial mat, int amount, List<String> lore) {
ItemStack item = mat.parseItem();
item.setAmount(amount);
ItemMeta meta = item.getItemMeta();
@ -400,9 +401,9 @@ public class GuiUtils {
return item;
}
public static ItemStack updateItem(ItemStack item, CompatibleMaterial matTo, String title, String... lore) {
if (!matTo.matches(item)) {
item = matTo.getItem();
public static ItemStack updateItem(ItemStack item, XMaterial matTo, String title, String... lore) {
if (!matTo.isSimilar(item)) {
item = matTo.parseItem();
}
ItemMeta meta = item.getItemMeta();
@ -423,7 +424,7 @@ public class GuiUtils {
}
public static ItemStack updateItem(ItemStack item, ItemStack to, String title, String... lore) {
if (!CompatibleMaterial.getMaterial(item).matches(to)) {
if (!CompatibleMaterial.getMaterial(item.getType()).get().isSimilar(to)) {
item = to.clone();
}
@ -462,9 +463,9 @@ public class GuiUtils {
return item;
}
public static ItemStack updateItem(ItemStack item, CompatibleMaterial matTo, String title, List<String> lore) {
if (!matTo.matches(item)) {
item = matTo.getItem();
public static ItemStack updateItem(ItemStack item, XMaterial matTo, String title, List<String> lore) {
if (!matTo.isSimilar(item)) {
item = matTo.parseItem();
}
ItemMeta meta = item.getItemMeta();
@ -485,7 +486,7 @@ public class GuiUtils {
}
public static ItemStack updateItem(ItemStack item, ItemStack to, String title, List<String> lore) {
if (!CompatibleMaterial.getMaterial(item).matches(to)) {
if (!CompatibleMaterial.getMaterial(item.getType()).get().isSimilar(to)) {
item = to.clone();
}

View File

@ -1,11 +1,11 @@
package com.craftaro.core.gui;
import com.craftaro.core.compatibility.ServerVersion;
import com.cryptomorin.xseries.XMaterial;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.craftaro.core.compatibility.CompatibleMaterial;
import com.craftaro.core.compatibility.ServerVersion;
import net.md_5.bungee.api.chat.TextComponent;
import net.md_5.bungee.chat.ComponentSerializer;
import org.bukkit.Bukkit;
@ -30,18 +30,18 @@ class PopupMessage {
final UUID id = UUID.randomUUID();
private final NamespacedKey key;
private final TextComponent title;
CompatibleMaterial icon;
XMaterial icon;
TriggerType trigger = TriggerType.IMPOSSIBLE;
FrameType frame = FrameType.GOAL; // TASK is the default
BackgroundType background = BackgroundType.ADVENTURE;
PopupMessage(Plugin source, CompatibleMaterial icon, String title) {
PopupMessage(Plugin source, XMaterial icon, String title) {
this.key = new NamespacedKey(source, "popup/" + id);
this.title = new TextComponent(title.length() < 74 ? title : (title.substring(0, 72) + "..."));
this.icon = icon;
}
PopupMessage(Plugin source, CompatibleMaterial icon, String title, BackgroundType background) {
PopupMessage(Plugin source, XMaterial icon, String title, BackgroundType background) {
this.key = new NamespacedKey(source, "popup/" + id);
this.title = new TextComponent(title.length() < 74 ? title : (title.substring(0, 72) + "..."));
this.icon = icon;
@ -54,9 +54,9 @@ class PopupMessage {
if (this.icon != null) {
JsonObject displayIcon = new JsonObject();
displayIcon.addProperty("item", "minecraft:" + this.icon.getMaterial().name().toLowerCase());
displayIcon.addProperty("item", "minecraft:" + this.icon.parseMaterial().name().toLowerCase());
if (this.icon.usesData()) {
if (this.icon.getData() != 0) {
displayIcon.addProperty("data", this.icon.getData());
}

View File

@ -2,7 +2,7 @@ package com.craftaro.core.gui;
import com.craftaro.core.gui.events.GuiClickEvent;
import com.craftaro.core.gui.methods.Clickable;
import com.craftaro.core.compatibility.CompatibleMaterial;
import com.cryptomorin.xseries.XMaterial;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.ClickType;
@ -30,8 +30,8 @@ public class SimplePagedGui extends Gui {
public SimplePagedGui(Gui parent) {
super(parent);
nextPage = GuiUtils.createButtonItem(CompatibleMaterial.ARROW, "Next Page");
prevPage = GuiUtils.createButtonItem(CompatibleMaterial.ARROW, "Previous Page");
nextPage = GuiUtils.createButtonItem(XMaterial.ARROW, "Next Page");
prevPage = GuiUtils.createButtonItem(XMaterial.ARROW, "Previous Page");
}
public SimplePagedGui setUseHeader(boolean useHeader) {

View File

@ -1,11 +1,11 @@
package com.craftaro.core.lootables.gui;
import com.craftaro.core.compatibility.CompatibleMaterial;
import com.craftaro.core.gui.AnvilGui;
import com.craftaro.core.gui.Gui;
import com.craftaro.core.gui.GuiUtils;
import com.craftaro.core.lootables.loot.Loot;
import com.craftaro.core.utils.TextUtils;
import com.cryptomorin.xseries.XMaterial;
import java.util.ArrayList;
import java.util.Collections;
@ -28,19 +28,19 @@ public abstract class AbstractGuiListEditor extends Gui {
public void paint() {
List<String> lore = getData() == null ? new ArrayList<>() : getData();
setButton(2, GuiUtils.createButtonItem(CompatibleMaterial.OAK_FENCE_GATE,
setButton(2, GuiUtils.createButtonItem(XMaterial.OAK_FENCE_GATE,
TextUtils.formatText("&cBack")),
(event) -> {
guiManager.showGUI(event.player, returnGui);
((GuiLootEditor) returnGui).paint();
});
setButton(6, GuiUtils.createButtonItem(CompatibleMaterial.OAK_FENCE_GATE,
setButton(6, GuiUtils.createButtonItem(XMaterial.OAK_FENCE_GATE,
TextUtils.formatText("&cBack")),
(event) -> {
guiManager.showGUI(event.player, returnGui);
((GuiLootEditor) returnGui).paint();
});
setButton(3, GuiUtils.createButtonItem(CompatibleMaterial.ARROW,
setButton(3, GuiUtils.createButtonItem(XMaterial.ARROW,
TextUtils.formatText("&aAdd new line")),
(event -> {
AnvilGui gui = new AnvilGui(event.player, this);
@ -57,13 +57,13 @@ public abstract class AbstractGuiListEditor extends Gui {
guiManager.showGUI(event.player, gui);
}));
setItem(4, GuiUtils.createButtonItem(CompatibleMaterial.WRITABLE_BOOK,
setItem(4, GuiUtils.createButtonItem(XMaterial.WRITABLE_BOOK,
TextUtils.formatText("&9Lore:"),
lore.isEmpty()
? TextUtils.formatText(Collections.singletonList("&cNo lore set..."))
: TextUtils.formatText(lore)));
setButton(5, GuiUtils.createButtonItem(CompatibleMaterial.ARROW,
setButton(5, GuiUtils.createButtonItem(XMaterial.ARROW,
TextUtils.formatText("&cRemove the last line")),
(event -> {
lore.remove(lore.size() - 1);

View File

@ -5,12 +5,14 @@ import com.craftaro.core.gui.Gui;
import com.craftaro.core.gui.GuiUtils;
import com.craftaro.core.lootables.loot.LootManager;
import com.craftaro.core.lootables.loot.Lootable;
import com.cryptomorin.xseries.XMaterial;
import org.bukkit.entity.EntityType;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
public class GuiEditor extends Gui {
private final LootManager lootManager;
@ -39,7 +41,7 @@ public class GuiEditor extends Gui {
this.pages = (int) Math.max(1, Math.ceil(itemCount / 36));
if (page != 1) {
setButton(5, 2, GuiUtils.createButtonItem(CompatibleMaterial.ARROW, "Back"),
setButton(5, 2, GuiUtils.createButtonItem(XMaterial.ARROW, "Back"),
(event) -> {
page--;
paint();
@ -47,7 +49,7 @@ public class GuiEditor extends Gui {
}
if (page != pages) {
setButton(5, 6, GuiUtils.createButtonItem(CompatibleMaterial.ARROW, "Next"),
setButton(5, 6, GuiUtils.createButtonItem(XMaterial.ARROW, "Next"),
(event) -> {
page++;
paint();
@ -76,15 +78,15 @@ public class GuiEditor extends Gui {
EntityType type = EntityType.fromName(key);
if (type != null) {
CompatibleMaterial material = CompatibleMaterial.getSpawnEgg(type);
Optional<XMaterial> material = CompatibleMaterial.getSpawnEgg(type);
if (material != null) {
stack = material.getItem();
if (material.isPresent()) {
stack = material.get().parseItem();
}
}
if (stack == null) {
stack = CompatibleMaterial.GHAST_SPAWN_EGG.getItem();
stack = XMaterial.GHAST_SPAWN_EGG.parseItem();
}
ItemMeta meta = stack.getItemMeta();

View File

@ -1,11 +1,11 @@
package com.craftaro.core.lootables.gui;
import com.craftaro.core.lootables.loot.Loot;
import com.craftaro.core.compatibility.CompatibleMaterial;
import com.craftaro.core.gui.AnvilGui;
import com.craftaro.core.gui.Gui;
import com.craftaro.core.gui.GuiUtils;
import com.craftaro.core.lootables.loot.Loot;
import com.craftaro.core.utils.TextUtils;
import com.cryptomorin.xseries.XMaterial;
import org.bukkit.enchantments.Enchantment;
import java.util.ArrayList;
@ -33,19 +33,19 @@ public class GuiEnchantEditor extends Gui {
public void paint() {
Map<String, Integer> lore = loot.getEnchants() == null ? new HashMap<>() : new HashMap<>(loot.getEnchants());
setButton(2, GuiUtils.createButtonItem(CompatibleMaterial.OAK_FENCE_GATE,
setButton(2, GuiUtils.createButtonItem(XMaterial.OAK_FENCE_GATE,
TextUtils.formatText("&cBack")),
(event) -> {
guiManager.showGUI(event.player, returnGui);
((GuiLootEditor) returnGui).paint();
});
setButton(6, GuiUtils.createButtonItem(CompatibleMaterial.OAK_FENCE_GATE,
setButton(6, GuiUtils.createButtonItem(XMaterial.OAK_FENCE_GATE,
TextUtils.formatText("&cBack")),
(event) -> {
guiManager.showGUI(event.player, returnGui);
((GuiLootEditor) returnGui).paint();
});
setButton(3, GuiUtils.createButtonItem(CompatibleMaterial.ARROW,
setButton(3, GuiUtils.createButtonItem(XMaterial.ARROW,
TextUtils.formatText("&aAdd new line")),
(event -> {
AnvilGui gui = new AnvilGui(event.player, this);
@ -82,14 +82,14 @@ public class GuiEnchantEditor extends Gui {
}
}
setItem(4, GuiUtils.createButtonItem(CompatibleMaterial.WRITABLE_BOOK,
setItem(4, GuiUtils.createButtonItem(XMaterial.WRITABLE_BOOK,
TextUtils.formatText("&7Enchant Override:"),
lore.isEmpty()
? TextUtils.formatText(Collections.singletonList("&cNo enchantments set..."))
: TextUtils.formatText(enchantments)));
String lastFinal = last;
setButton(5, GuiUtils.createButtonItem(CompatibleMaterial.ARROW,
setButton(5, GuiUtils.createButtonItem(XMaterial.ARROW,
TextUtils.formatText("&cRemove the last line")),
(event -> {
lore.remove(lastFinal);

View File

@ -1,13 +1,14 @@
package com.craftaro.core.lootables.gui;
import com.craftaro.core.lootables.loot.Loot;
import com.craftaro.core.lootables.loot.LootBuilder;
import com.craftaro.core.lootables.loot.LootManager;
import com.craftaro.core.compatibility.CompatibleMaterial;
import com.craftaro.core.gui.AnvilGui;
import com.craftaro.core.gui.Gui;
import com.craftaro.core.gui.GuiUtils;
import com.craftaro.core.lootables.loot.Loot;
import com.craftaro.core.lootables.loot.LootBuilder;
import com.craftaro.core.lootables.loot.LootManager;
import com.craftaro.core.utils.TextUtils;
import com.cryptomorin.xseries.XMaterial;
import org.bukkit.entity.EntityType;
import org.bukkit.event.inventory.ClickType;
import org.bukkit.inventory.ItemStack;
@ -46,10 +47,10 @@ public class GuiLootEditor extends Gui {
setActionForRange(0, 0, 5, 9, null);
setButton(8, GuiUtils.createButtonItem(CompatibleMaterial.OAK_DOOR, TextUtils.formatText("&cBack")),
setButton(8, GuiUtils.createButtonItem(XMaterial.OAK_DOOR, TextUtils.formatText("&cBack")),
(event) -> guiManager.showGUI(event.player, returnGui));
setButton(9, GuiUtils.createButtonItem(loot.getMaterial() == null ? CompatibleMaterial.BARRIER : loot.getMaterial(),
setButton(9, GuiUtils.createButtonItem(loot.getMaterial() == null ? XMaterial.BARRIER : loot.getMaterial(),
TextUtils.formatText("&7Current Material: &6" + (loot.getMaterial() != null
? loot.getMaterial().name() : "None")), TextUtils.formatText(
Arrays.asList("",
@ -57,12 +58,12 @@ public class GuiLootEditor extends Gui {
"&8the material in your hand.")
)), (event) -> {
ItemStack stack = event.player.getInventory().getItemInMainHand();
loot.setMaterial(CompatibleMaterial.getMaterial(stack));
loot.setMaterial(CompatibleMaterial.getMaterial(stack.getType()).get());
paint();
});
setButton(10, GuiUtils.createButtonItem(CompatibleMaterial.PAPER,
setButton(10, GuiUtils.createButtonItem(XMaterial.PAPER,
TextUtils.formatText("&7Name Override: &6" + (loot.getName() == null ? "None set" : loot.getName()))),
(event) -> {
AnvilGui gui = new AnvilGui(event.player, this);
@ -74,10 +75,10 @@ public class GuiLootEditor extends Gui {
}));
guiManager.showGUI(event.player, gui);
gui.setInput(GuiUtils.createButtonItem(CompatibleMaterial.PAPER, loot.getName()));
gui.setInput(GuiUtils.createButtonItem(XMaterial.PAPER, loot.getName()));
});
setButton(11, GuiUtils.createButtonItem(CompatibleMaterial.WRITABLE_BOOK,
setButton(11, GuiUtils.createButtonItem(XMaterial.WRITABLE_BOOK,
TextUtils.formatText("&7Lore Override:"),
TextUtils.formatText(loot.getLore() == null ? Collections.singletonList("&6None set") : loot.getLore())),
(event) -> guiManager.showGUI(event.player, new GuiLoreEditor(loot, this)));
@ -90,14 +91,14 @@ public class GuiLootEditor extends Gui {
}
}
setButton(12, GuiUtils.createButtonItem(CompatibleMaterial.ENCHANTED_BOOK,
setButton(12, GuiUtils.createButtonItem(XMaterial.ENCHANTED_BOOK,
TextUtils.formatText("&7Enchantments:"),
TextUtils.formatText(enchantments.isEmpty() ? Collections.singletonList("&6None set") : enchantments)),
(event) -> guiManager.showGUI(event.player, new GuiEnchantEditor(loot, this)));
setButton(13, GuiUtils.createButtonItem(
loot.getBurnedMaterial() == null
? CompatibleMaterial.FIRE_CHARGE
? XMaterial.FIRE_CHARGE
: loot.getBurnedMaterial(),
TextUtils.formatText("&7Current Burned Material: &6"
+ (loot.getBurnedMaterial() == null
@ -109,12 +110,12 @@ public class GuiLootEditor extends Gui {
)),
(event) -> {
ItemStack stack = event.player.getInventory().getItemInMainHand();
loot.setBurnedMaterial(CompatibleMaterial.getMaterial(stack));
loot.setBurnedMaterial(CompatibleMaterial.getMaterial(stack.getType()).get());
paint();
});
setButton(14, GuiUtils.createButtonItem(CompatibleMaterial.CLOCK,
setButton(14, GuiUtils.createButtonItem(XMaterial.CLOCK,
TextUtils.formatText("&7Chance: &6" + loot.getChance()),
TextUtils.formatText(
Arrays.asList("",
@ -131,11 +132,11 @@ public class GuiLootEditor extends Gui {
e.player.closeInventory();
});
gui.setInput(GuiUtils.createButtonItem(CompatibleMaterial.PAPER, String.valueOf(loot.getChance())));
gui.setInput(GuiUtils.createButtonItem(XMaterial.PAPER, String.valueOf(loot.getChance())));
guiManager.showGUI(event.player, gui);
});
setButton(15, GuiUtils.createButtonItem(CompatibleMaterial.REDSTONE,
setButton(15, GuiUtils.createButtonItem(XMaterial.REDSTONE,
TextUtils.formatText("&7Min Drop Amount: &6" + loot.getMin())),
(event) -> {
AnvilGui gui = new AnvilGui(event.player, this);
@ -147,12 +148,12 @@ public class GuiLootEditor extends Gui {
e.player.closeInventory();
});
gui.setInput(GuiUtils.createButtonItem(CompatibleMaterial.PAPER,
gui.setInput(GuiUtils.createButtonItem(XMaterial.PAPER,
String.valueOf(loot.getMin())));
guiManager.showGUI(event.player, gui);
});
setButton(16, GuiUtils.createButtonItem(CompatibleMaterial.GLOWSTONE_DUST,
setButton(16, GuiUtils.createButtonItem(XMaterial.GLOWSTONE_DUST,
TextUtils.formatText("&7Max Drop Amount: &6" + loot.getMax())),
(event) -> {
AnvilGui gui = new AnvilGui(event.player, this);
@ -164,11 +165,11 @@ public class GuiLootEditor extends Gui {
e.player.closeInventory();
});
gui.setInput(GuiUtils.createButtonItem(CompatibleMaterial.PAPER, String.valueOf(loot.getMax())));
gui.setInput(GuiUtils.createButtonItem(XMaterial.PAPER, String.valueOf(loot.getMax())));
guiManager.showGUI(event.player, gui);
});
setButton(17, GuiUtils.createButtonItem(CompatibleMaterial.REDSTONE,
setButton(17, GuiUtils.createButtonItem(XMaterial.REDSTONE,
TextUtils.formatText("&7Min Item Damage: &6" + loot.getDamageMin())),
(event) -> {
AnvilGui gui = new AnvilGui(event.player, this);
@ -179,11 +180,11 @@ public class GuiLootEditor extends Gui {
e.player.closeInventory();
});
gui.setInput(GuiUtils.createButtonItem(CompatibleMaterial.PAPER, String.valueOf(loot.getDamageMin())));
gui.setInput(GuiUtils.createButtonItem(XMaterial.PAPER, String.valueOf(loot.getDamageMin())));
guiManager.showGUI(event.player, gui);
});
setButton(18, GuiUtils.createButtonItem(CompatibleMaterial.GLOWSTONE_DUST,
setButton(18, GuiUtils.createButtonItem(XMaterial.GLOWSTONE_DUST,
TextUtils.formatText("&7Max Item Damage: &6" + loot.getDamageMax())),
(event) -> {
AnvilGui gui = new AnvilGui(event.player, this);
@ -194,11 +195,11 @@ public class GuiLootEditor extends Gui {
e.player.closeInventory();
});
gui.setInput(GuiUtils.createButtonItem(CompatibleMaterial.PAPER, String.valueOf(loot.getDamageMax())));
gui.setInput(GuiUtils.createButtonItem(XMaterial.PAPER, String.valueOf(loot.getDamageMax())));
guiManager.showGUI(event.player, gui);
});
setButton(19, GuiUtils.createButtonItem(CompatibleMaterial.CHEST,
setButton(19, GuiUtils.createButtonItem(XMaterial.CHEST,
TextUtils.formatText("&7Allow Looting Enchantment?: &6" + loot.isAllowLootingEnchant())),
(event) -> {
loot.setAllowLootingEnchant(!loot.isAllowLootingEnchant());
@ -207,7 +208,7 @@ public class GuiLootEditor extends Gui {
event.player.closeInventory();
});
setButton(20, GuiUtils.createButtonItem(CompatibleMaterial.REDSTONE,
setButton(20, GuiUtils.createButtonItem(XMaterial.REDSTONE,
TextUtils.formatText("&7Min Child Loot Min: &6" + loot.getChildDropCountMin())),
(event) -> {
AnvilGui gui = new AnvilGui(event.player, this);
@ -219,11 +220,11 @@ public class GuiLootEditor extends Gui {
e.player.closeInventory();
});
gui.setInput(GuiUtils.createButtonItem(CompatibleMaterial.PAPER, String.valueOf(loot.getChildDropCountMin())));
gui.setInput(GuiUtils.createButtonItem(XMaterial.PAPER, String.valueOf(loot.getChildDropCountMin())));
guiManager.showGUI(event.player, gui);
});
setButton(21, GuiUtils.createButtonItem(CompatibleMaterial.GLOWSTONE_DUST,
setButton(21, GuiUtils.createButtonItem(XMaterial.GLOWSTONE_DUST,
TextUtils.formatText("&7Min Child Loot Max: &6" + loot.getChildDropCountMax())),
(event) -> {
AnvilGui gui = new AnvilGui(event.player, this);
@ -235,7 +236,7 @@ public class GuiLootEditor extends Gui {
e.player.closeInventory();
});
gui.setInput(GuiUtils.createButtonItem(CompatibleMaterial.PAPER, String.valueOf(loot.getChildDropCountMax())));
gui.setInput(GuiUtils.createButtonItem(XMaterial.PAPER, String.valueOf(loot.getChildDropCountMax())));
guiManager.showGUI(event.player, gui);
});
@ -247,19 +248,18 @@ public class GuiLootEditor extends Gui {
}
}
setButton(22, GuiUtils.createButtonItem(CompatibleMaterial.ENCHANTED_BOOK,
setButton(22, GuiUtils.createButtonItem(XMaterial.ENCHANTED_BOOK,
TextUtils.formatText("&7Only Drop For:"),
TextUtils.formatText(entities)),
(event) -> guiManager.showGUI(event.player, new GuiEntityEditor(loot, this)));
setButton(4, 0, GuiUtils.createButtonItem(CompatibleMaterial.LIME_DYE, TextUtils.formatText("&aCreate new Child Loot")),
setButton(4, 0, GuiUtils.createButtonItem(XMaterial.LIME_DYE, TextUtils.formatText("&aCreate new Child Loot")),
(event -> {
AnvilGui gui = new AnvilGui(event.player, this);
gui.setAction((event1 -> {
try {
loot.addChildLoots(new LootBuilder().setMaterial(CompatibleMaterial
.valueOf(gui.getInputText().trim())).build());
loot.addChildLoots(new LootBuilder().setMaterial(XMaterial.valueOf(gui.getInputText().trim())).build());
} catch (IllegalArgumentException ignore) {
event.player.sendMessage("That is not a valid material.");
}
@ -275,7 +275,7 @@ public class GuiLootEditor extends Gui {
int i = 9 * 5;
for (Loot loot : loot.getChildLoot()) {
ItemStack item = loot.getMaterial() == null
? CompatibleMaterial.BARRIER.getItem()
? XMaterial.BARRIER.parseItem()
: GuiUtils.createButtonItem(loot.getMaterial(), null,
TextUtils.formatText("&6Left click &7to edit"),
TextUtils.formatText("&6Right click &7to destroy"));

View File

@ -1,6 +1,5 @@
package com.craftaro.core.lootables.gui;
import com.craftaro.core.compatibility.CompatibleMaterial;
import com.craftaro.core.gui.AnvilGui;
import com.craftaro.core.gui.Gui;
import com.craftaro.core.gui.GuiUtils;
@ -9,6 +8,7 @@ import com.craftaro.core.lootables.loot.LootBuilder;
import com.craftaro.core.lootables.loot.LootManager;
import com.craftaro.core.lootables.loot.Lootable;
import com.craftaro.core.utils.TextUtils;
import com.cryptomorin.xseries.XMaterial;
import org.bukkit.event.inventory.ClickType;
import org.bukkit.inventory.ItemStack;
@ -39,13 +39,12 @@ public class GuiLootableEditor extends Gui {
setActionForRange(0, 0, 5, 9, null);
setButton(0, GuiUtils.createButtonItem(CompatibleMaterial.LIME_DYE, TextUtils.formatText("&aCreate new Loot")),
setButton(0, GuiUtils.createButtonItem(XMaterial.LIME_DYE, TextUtils.formatText("&aCreate new Loot")),
(event -> {
AnvilGui gui = new AnvilGui(event.player, this);
gui.setAction((event1 -> {
try {
lootable.registerLoot(new LootBuilder().setMaterial(CompatibleMaterial
.valueOf(gui.getInputText().trim().toUpperCase())).build());
lootable.registerLoot(new LootBuilder().setMaterial(XMaterial.valueOf(gui.getInputText().trim().toUpperCase())).build());
} catch (IllegalArgumentException ex) {
event.player.sendMessage("That is not a valid material.");
}
@ -58,13 +57,13 @@ public class GuiLootableEditor extends Gui {
guiManager.showGUI(event.player, gui);
}));
setButton(8, GuiUtils.createButtonItem(CompatibleMaterial.OAK_DOOR, TextUtils.formatText("&cBack")),
setButton(8, GuiUtils.createButtonItem(XMaterial.OAK_DOOR, TextUtils.formatText("&cBack")),
(event -> guiManager.showGUI(event.player, returnGui)));
int i = 9;
for (Loot loot : lootable.getRegisteredLoot()) {
ItemStack item = loot.getMaterial() == null
? CompatibleMaterial.BARRIER.getItem()
? XMaterial.BARRIER.parseItem()
: GuiUtils.createButtonItem(loot.getMaterial(), null,
TextUtils.formatText("&6Left click &7to edit"),
TextUtils.formatText("&6Right click &7to destroy"));

View File

@ -1,9 +1,9 @@
package com.craftaro.core.lootables.loot;
import com.google.gson.annotations.SerializedName;
import com.craftaro.core.compatibility.CompatibleMaterial;
import com.craftaro.core.utils.ItemUtils;
import com.craftaro.core.utils.TextUtils;
import com.cryptomorin.xseries.XMaterial;
import com.google.gson.annotations.SerializedName;
import org.bukkit.Material;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.EntityType;
@ -29,7 +29,7 @@ public class Loot {
// Material used for this drop.
@SerializedName("Type")
private CompatibleMaterial material;
private XMaterial material;
// The override for the item name.
@SerializedName("Name")
@ -45,7 +45,7 @@ public class Loot {
// Material used if entity died on fire.
@SerializedName("Burned Type")
private CompatibleMaterial burnedMaterial = null;
private XMaterial burnedMaterial = null;
// Chance that this drop will take place.
@SerializedName("Chance")
@ -96,11 +96,11 @@ public class Loot {
// Should the entity be charged? (Only works on creepers)
private boolean requireCharged = false;
public CompatibleMaterial getMaterial() {
public XMaterial getMaterial() {
return material;
}
public void setMaterial(CompatibleMaterial material) {
public void setMaterial(XMaterial material) {
this.material = material;
}
@ -200,11 +200,11 @@ public class Loot {
return enchants == null ? null : Collections.unmodifiableMap(enchants);
}
public CompatibleMaterial getBurnedMaterial() {
public XMaterial getBurnedMaterial() {
return burnedMaterial;
}
public void setBurnedMaterial(CompatibleMaterial burnedMaterial) {
public void setBurnedMaterial(XMaterial burnedMaterial) {
this.burnedMaterial = burnedMaterial;
}

View File

@ -1,7 +1,7 @@
package com.craftaro.core.lootables.loot;
import com.craftaro.core.compatibility.CompatibleMaterial;
import com.craftaro.core.lootables.loot.objects.EnchantChance;
import com.cryptomorin.xseries.XMaterial;
import org.bukkit.entity.EntityType;
import java.util.Arrays;
@ -15,7 +15,7 @@ public final class LootBuilder {
this.loot = new Loot();
}
public LootBuilder setMaterial(CompatibleMaterial material) {
public LootBuilder setMaterial(XMaterial material) {
this.loot.setMaterial(material);
return this;
}
@ -52,7 +52,7 @@ public final class LootBuilder {
return this;
}
public LootBuilder setBurnedMaterial(CompatibleMaterial material) {
public LootBuilder setBurnedMaterial(XMaterial material) {
this.loot.setBurnedMaterial(material);
return this;
}

View File

@ -1,11 +1,11 @@
package com.craftaro.core.lootables.loot;
import com.craftaro.core.lootables.Lootables;
import com.craftaro.core.lootables.Modify;
import com.cryptomorin.xseries.XMaterial;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.stream.JsonReader;
import com.craftaro.core.compatibility.CompatibleMaterial;
import com.craftaro.core.lootables.Lootables;
import com.craftaro.core.lootables.Modify;
import org.bukkit.Bukkit;
import org.bukkit.entity.EntityType;
import org.bukkit.inventory.ItemStack;
@ -92,7 +92,7 @@ public class LootManager {
}
}
CompatibleMaterial material = loot.getMaterial();
XMaterial material = loot.getMaterial();
String command = loot.getCommand();
int xp = loot.getXp();
@ -107,9 +107,9 @@ public class LootManager {
if (material != null) {
ItemStack item = loot.getBurnedMaterial() != null &&
burning ? loot.getBurnedMaterial().getItem() : material.getItem();
burning ? loot.getBurnedMaterial().parseItem() : material.parseItem();
item.setAmount(amount);
ItemMeta meta = item.getItemMeta() == null ? Bukkit.getItemFactory().getItemMeta(loot.getMaterial().getMaterial())
ItemMeta meta = item.getItemMeta() == null ? Bukkit.getItemFactory().getItemMeta(loot.getMaterial().parseMaterial())
: item.getItemMeta();
if (loot.getName() != null) {

View File

@ -7,6 +7,8 @@ import com.craftaro.core.compatibility.ServerVersion;
import com.craftaro.core.nms.Nms;
import com.craftaro.core.nms.world.SWorld;
import com.craftaro.core.nms.world.WorldCore;
import com.cryptomorin.xseries.XBlock;
import com.cryptomorin.xseries.XMaterial;
import org.bukkit.Effect;
import org.bukkit.Location;
import org.bukkit.Material;
@ -18,6 +20,7 @@ import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.EnumSet;
import java.util.Optional;
import java.util.Set;
import java.util.logging.Level;
import java.util.logging.Logger;
@ -346,7 +349,7 @@ public class BlockUtils {
* @param loc The Location of the container
*
* @deprecated Use {@link WorldCore#updateAdjacentComparators(Block)}
* via {@link Nms#getImplementations()} instead.
* via {@link Nms#getImplementations()} instead.
*/
@Deprecated
public static void updateAdjacentComparators(Location loc) {
@ -463,8 +466,8 @@ public class BlockUtils {
* via {@link Nms#getImplementations()} instead.
*/
@Deprecated
public static void setBlockFast(World world, int x, int y, int z, CompatibleMaterial material, byte data) {
setBlockFast(world, x, y, z, material.getBlockMaterial(), data);
public static void setBlockFast(World world, int x, int y, int z, XMaterial material, byte data) {
setBlockFast(world, x, y, z, material.parseMaterial(), data);
}
/**
@ -483,12 +486,12 @@ public class BlockUtils {
return BlockUtilsModern._isCropFullyGrown(block);
}
CompatibleMaterial mat = CompatibleMaterial.getBlockMaterial(block.getType());
if (mat == null || !mat.isCrop()) {
Optional<XMaterial> mat = CompatibleMaterial.getMaterial(block.getType());
if (!mat.isPresent() || !XBlock.isCrop(mat.get())) {
return false;
}
return block.getData() >= (mat == CompatibleMaterial.BEETROOTS || mat == CompatibleMaterial.NETHER_WART ? 3 : 7);
return block.getData() >= (mat.get() == XMaterial.BEETROOTS || mat.get() == XMaterial.NETHER_WART ? 3 : 7);
}
/**
@ -507,13 +510,12 @@ public class BlockUtils {
return BlockUtilsModern._getMaxGrowthStage(block);
}
CompatibleMaterial mat = CompatibleMaterial.getBlockMaterial(block.getType());
if (mat == null || !mat.isCrop()) {
Optional<XMaterial> mat = CompatibleMaterial.getMaterial(block.getType());
if (!mat.isPresent() || !XBlock.isCrop(mat.get())) {
return -1;
}
return (mat == CompatibleMaterial.BEETROOTS
|| mat == CompatibleMaterial.NETHER_WART ? 3 : 7);
return (mat.get() == XMaterial.BEETROOTS || mat.get() == XMaterial.NETHER_WART ? 3 : 7);
}
/**
@ -532,12 +534,12 @@ public class BlockUtils {
return BlockUtilsModern._getMaxGrowthStage(material);
}
CompatibleMaterial mat = CompatibleMaterial.getBlockMaterial(material);
if (mat == null || !mat.isCrop()) {
Optional<XMaterial> mat = CompatibleMaterial.getMaterial(material);
if (!mat.isPresent() || XBlock.isCrop(mat.get())) {
return -1;
}
return (mat == CompatibleMaterial.BEETROOTS || mat == CompatibleMaterial.NETHER_WART ? 3 : 7);
return (mat.get() == XMaterial.BEETROOTS || mat.get() == XMaterial.NETHER_WART ? 3 : 7);
}
/**
@ -551,11 +553,10 @@ public class BlockUtils {
} else if (!useLegacy) {
BlockUtilsModern._setGrowthStage(block, stage);
} else {
CompatibleMaterial mat = CompatibleMaterial.getBlockMaterial(block.getType());
if (mat != null && mat.isCrop()) {
Optional<XMaterial> mat = CompatibleMaterial.getMaterial(block.getType());
if (mat.isPresent() && XBlock.isCrop(mat.get())) {
try {
legacySetBlockData.invoke(block, (byte) Math.max(0, Math.min(stage, (mat == CompatibleMaterial.BEETROOTS
|| mat == CompatibleMaterial.NETHER_WART ? 3 : 7))));
legacySetBlockData.invoke(block, (byte) Math.max(0, Math.min(stage, (mat.get() == XMaterial.BEETROOTS || mat.get() == XMaterial.NETHER_WART ? 3 : 7))));
} catch (Exception ex) {
Logger.getLogger(BlockUtils.class.getName()).log(Level.SEVERE, "Unexpected method error", ex);
}
@ -573,10 +574,9 @@ public class BlockUtils {
} else if (!useLegacy) {
BlockUtilsModern._incrementGrowthStage(block);
} else {
CompatibleMaterial mat = CompatibleMaterial.getBlockMaterial(block.getType());
Optional<XMaterial> mat = CompatibleMaterial.getMaterial(block.getType());
if (mat != null && mat.isCrop() &&
block.getData() < (mat == CompatibleMaterial.BEETROOTS || mat == CompatibleMaterial.NETHER_WART ? 3 : 7)) {
if (mat.isPresent() && XBlock.isCrop(mat.get()) && block.getData() < (mat.get() == XMaterial.BEETROOTS || mat.get() == XMaterial.NETHER_WART ? 3 : 7)) {
try {
legacySetBlockData.invoke(block, (byte) (block.getData() + 1));
} catch (Exception ex) {
@ -596,9 +596,9 @@ public class BlockUtils {
} else if (!useLegacy) {
BlockUtilsModern._resetGrowthStage(block);
} else {
CompatibleMaterial mat = CompatibleMaterial.getBlockMaterial(block.getType());
Optional<XMaterial> mat = CompatibleMaterial.getMaterial(block.getType());
if (mat != null && mat.isCrop()) {
if (mat.isPresent() && XBlock.isCrop(mat.get())) {
try {
legacySetBlockData.invoke(block, (byte) 0);
} catch (Exception ex) {

View File

@ -1,7 +1,7 @@
package com.craftaro.core.utils;
import com.craftaro.core.compatibility.ClassMapping;
import com.craftaro.core.compatibility.CompatibleMaterial;
import com.cryptomorin.xseries.XMaterial;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.LivingEntity;
@ -9,7 +9,6 @@ import org.bukkit.entity.LivingEntity;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
@ -106,7 +105,7 @@ public class EntityUtils {
return false;
}
public static List<CompatibleMaterial> getSpawnBlocks(EntityType type) {
public static List<XMaterial> getSpawnBlocks(EntityType type) {
switch (type.name()) {
case "PIG":
case "SHEEP":
@ -116,23 +115,27 @@ public class EntityUtils {
case "LLAMA":
case "HORSE":
case "CAT":
return new ArrayList<>(Collections.singletonList(CompatibleMaterial.GRASS_BLOCK));
return Collections.singletonList(XMaterial.GRASS_BLOCK);
case "MUSHROOM_COW":
return new ArrayList<>(Collections.singletonList(CompatibleMaterial.MYCELIUM));
return Collections.singletonList(XMaterial.MYCELIUM);
case "SQUID":
case "ELDER_GUARDIAN":
case "COD":
case "SALMON":
case "PUFFERFISH":
case "TROPICAL_FISH":
return new ArrayList<>(Collections.singletonList(CompatibleMaterial.WATER));
return Collections.singletonList(XMaterial.WATER);
case "OCELOT":
return new ArrayList<>(Arrays.asList(CompatibleMaterial.GRASS_BLOCK,
CompatibleMaterial.JUNGLE_LEAVES, CompatibleMaterial.ACACIA_LEAVES,
CompatibleMaterial.BIRCH_LEAVES, CompatibleMaterial.DARK_OAK_LEAVES,
CompatibleMaterial.OAK_LEAVES, CompatibleMaterial.SPRUCE_LEAVES));
return Arrays.asList(XMaterial.GRASS_BLOCK,
XMaterial.JUNGLE_LEAVES, XMaterial.ACACIA_LEAVES,
XMaterial.BIRCH_LEAVES, XMaterial.DARK_OAK_LEAVES,
XMaterial.OAK_LEAVES, XMaterial.SPRUCE_LEAVES);
default:
return new ArrayList<>(Collections.singletonList(CompatibleMaterial.AIR));
return Collections.singletonList(XMaterial.AIR);
}
}
}

View File

@ -5,6 +5,7 @@ import com.craftaro.core.compatibility.CompatibleHand;
import com.craftaro.core.compatibility.CompatibleMaterial;
import com.craftaro.core.compatibility.MethodMapping;
import com.craftaro.core.compatibility.ServerVersion;
import com.cryptomorin.xseries.XMaterial;
import com.mojang.authlib.GameProfile;
import com.mojang.authlib.properties.Property;
import org.apache.commons.lang3.StringUtils;
@ -33,6 +34,7 @@ import java.util.Arrays;
import java.util.Base64;
import java.util.Iterator;
import java.util.List;
import java.util.Optional;
import java.util.Random;
import java.util.UUID;
import java.util.concurrent.ThreadLocalRandom;
@ -332,7 +334,7 @@ public class ItemUtils {
}
public static ItemStack getPlayerSkull(OfflinePlayer player) {
ItemStack head = CompatibleMaterial.PLAYER_HEAD.getItem();
ItemStack head = XMaterial.PLAYER_HEAD.parseItem();
if (ServerVersion.isServerVersionBelow(ServerVersion.V1_8)) {
return head;
}
@ -351,7 +353,7 @@ public class ItemUtils {
}
public static void setHeadOwner(ItemStack head, OfflinePlayer player) {
if (ServerVersion.isServerVersionBelow(ServerVersion.V1_8) || !CompatibleMaterial.PLAYER_HEAD.matches(head)) {
if (ServerVersion.isServerVersionBelow(ServerVersion.V1_8) || !XMaterial.PLAYER_HEAD.isSimilar(head)) {
return;
}
@ -369,7 +371,7 @@ public class ItemUtils {
}
public static ItemStack getCustomHead(String signature, String texture) {
ItemStack skullItem = CompatibleMaterial.PLAYER_HEAD.getItem();
ItemStack skullItem = XMaterial.PLAYER_HEAD.parseItem();
if (ServerVersion.isServerVersionBelow(ServerVersion.V1_8)) {
return skullItem;
@ -433,7 +435,7 @@ public class ItemUtils {
}
public static String getSkullTexture(ItemStack item) {
if (!CompatibleMaterial.PLAYER_HEAD.matches(item) || ServerVersion.isServerVersionBelow(ServerVersion.V1_8)) {
if (!XMaterial.PLAYER_HEAD.isSimilar(item) || ServerVersion.isServerVersionBelow(ServerVersion.V1_8)) {
return null;
}
@ -489,9 +491,9 @@ public class ItemUtils {
* @return true if both items are of the same material
*/
public static boolean isSimilarMaterial(ItemStack is1, ItemStack is2) {
CompatibleMaterial mat1 = CompatibleMaterial.getMaterial(is1);
Optional<XMaterial> mat1 = CompatibleMaterial.getMaterial(is1.getType());
return mat1 != null && mat1 == CompatibleMaterial.getMaterial(is2);
return mat1.isPresent() && mat1 == CompatibleMaterial.getMaterial(is2.getType());
}
/**
@ -799,7 +801,7 @@ public class ItemUtils {
case "FURNACE": {
check = new boolean[3];
boolean isFuel = !item.getType().name().contains("LOG") && CompatibleMaterial.getMaterial(item.getType()).isFuel();
boolean isFuel = !item.getType().name().contains("LOG") && CompatibleMaterial.isFurnaceFuel(CompatibleMaterial.getMaterial(item.getType()).get());
// fuel is 2nd slot, input is first
if (isFuel) {
@ -1008,7 +1010,7 @@ public class ItemUtils {
case "FURNACE": {
check = new boolean[3];
boolean isFuel = !item.getType().name().contains("LOG") && CompatibleMaterial.getMaterial(item.getType()).isFuel();
boolean isFuel = !item.getType().name().contains("LOG") && CompatibleMaterial.isFurnaceFuel(CompatibleMaterial.getMaterial(item.getType()).get());
// fuel is 2nd slot, input is first
if (isFuel) {
check[1] = true;
@ -1083,41 +1085,41 @@ public class ItemUtils {
return false;
}
public static CompatibleMaterial getDyeColor(char color) {
public static XMaterial getDyeColor(char color) {
switch (color) {
case '0':
return CompatibleMaterial.BLACK_DYE;
return XMaterial.BLACK_DYE;
case '1':
return CompatibleMaterial.BLUE_DYE;
return XMaterial.BLUE_DYE;
case '2':
return CompatibleMaterial.GREEN_DYE;
return XMaterial.GREEN_DYE;
case '3':
return CompatibleMaterial.CYAN_DYE;
return XMaterial.CYAN_DYE;
case '4':
return CompatibleMaterial.BROWN_DYE;
return XMaterial.BROWN_DYE;
case '5':
return CompatibleMaterial.PURPLE_DYE;
return XMaterial.PURPLE_DYE;
case '6':
return CompatibleMaterial.ORANGE_DYE;
return XMaterial.ORANGE_DYE;
case '7':
return CompatibleMaterial.LIGHT_GRAY_DYE;
return XMaterial.LIGHT_GRAY_DYE;
case '8':
return CompatibleMaterial.GRAY_DYE;
return XMaterial.GRAY_DYE;
case 'a':
return CompatibleMaterial.LIME_DYE;
return XMaterial.LIME_DYE;
case 'b':
return CompatibleMaterial.LIGHT_BLUE_DYE;
return XMaterial.LIGHT_BLUE_DYE;
case 'c':
return CompatibleMaterial.RED_DYE;
return XMaterial.RED_DYE;
case 'd':
return CompatibleMaterial.MAGENTA_DYE;
return XMaterial.MAGENTA_DYE;
case 'e':
return CompatibleMaterial.YELLOW_DYE;
return XMaterial.YELLOW_DYE;
case 'f':
return CompatibleMaterial.WHITE_DYE;
return XMaterial.WHITE_DYE;
}
return CompatibleMaterial.STONE;
return XMaterial.STONE;
}
/**

View File

@ -1,10 +1,10 @@
package com.craftaro.core.world;
import com.craftaro.core.utils.EntityUtils;
import com.craftaro.core.compatibility.CompatibleMaterial;
import com.craftaro.core.hooks.EntityStackerManager;
import com.craftaro.core.nms.Nms;
import com.craftaro.core.nms.world.SpawnedEntity;
import com.craftaro.core.utils.EntityUtils;
import com.cryptomorin.xseries.XMaterial;
import org.bukkit.Location;
import org.bukkit.block.CreatureSpawner;
import org.bukkit.entity.EntityType;
@ -39,8 +39,7 @@ public class SSpawner {
*
* @return amount of entities spawned
*/
public int spawn(int amountToSpawn, String particle, Set<CompatibleMaterial> canSpawnOn, SpawnedEntity spawned,
EntityType... types) {
public int spawn(int amountToSpawn, String particle, Set<XMaterial> canSpawnOn, SpawnedEntity spawned, EntityType... types) {
if (this.location.getWorld() == null) {
return 0;
}

View File

@ -1,6 +1,6 @@
package com.craftaro.core.nms.world;
import com.craftaro.core.compatibility.CompatibleMaterial;
import com.cryptomorin.xseries.XMaterial;
import org.apache.commons.text.WordUtils;
import org.bukkit.Location;
import org.bukkit.entity.EntityType;
@ -11,8 +11,7 @@ import java.util.Set;
public interface SSpawner {
LivingEntity spawnEntity(EntityType type, Location spawnerLocation);
LivingEntity spawnEntity(EntityType type, String particleType, SpawnedEntity spawned,
Set<CompatibleMaterial> canSpawnOn);
LivingEntity spawnEntity(EntityType type, String particleType, SpawnedEntity spawned, Set<XMaterial> canSpawnOn);
default String translateName(EntityType type, boolean capital) {
return capital ? TypeTranslations.getUpperFromType(type) : TypeTranslations.getLowerFromType(type);

View File

@ -4,6 +4,7 @@ import com.craftaro.core.compatibility.CompatibleMaterial;
import com.craftaro.core.compatibility.CompatibleParticleHandler;
import com.craftaro.core.nms.world.SSpawner;
import com.craftaro.core.nms.world.SpawnedEntity;
import com.cryptomorin.xseries.XMaterial;
import net.minecraft.server.v1_10_R1.BlockPosition;
import net.minecraft.server.v1_10_R1.ChunkRegionLoader;
import net.minecraft.server.v1_10_R1.DifficultyDamageScaler;
@ -19,6 +20,7 @@ import org.bukkit.entity.EntityType;
import org.bukkit.entity.LivingEntity;
import org.bukkit.event.entity.CreatureSpawnEvent;
import java.util.Optional;
import java.util.Random;
import java.util.Set;
@ -35,21 +37,20 @@ public class SSpawnerImpl implements SSpawner {
}
@Override
public LivingEntity spawnEntity(EntityType type, String particleType, SpawnedEntity spawned,
Set<CompatibleMaterial> canSpawnOn) {
public LivingEntity spawnEntity(EntityType type, String particleType, SpawnedEntity spawned, Set<XMaterial> canSpawnOn) {
MobSpawnerData data = new MobSpawnerData();
NBTTagCompound compound = data.b();
compound.setString("id", translateName(type, true));
short spawnRange = 4;
for (int i = 0; i < 50; i++) {
WorldServer world = ((CraftWorld) spawnerLocation.getWorld()).getHandle();
for (int i = 0; i < 50; ++i) {
WorldServer world = ((CraftWorld) this.spawnerLocation.getWorld()).getHandle();
Random random = world.random;
double x = spawnerLocation.getX() + (random.nextDouble() - random.nextDouble()) * (double) spawnRange + 0.5D;
double y = spawnerLocation.getY() + random.nextInt(3) - 1;
double z = spawnerLocation.getZ() + (random.nextDouble() - random.nextDouble()) * (double) spawnRange + 0.5D;
double x = this.spawnerLocation.getX() + (random.nextDouble() - random.nextDouble()) * (double) spawnRange + 0.5D;
double y = this.spawnerLocation.getY() + random.nextInt(3) - 1;
double z = this.spawnerLocation.getZ() + (random.nextDouble() - random.nextDouble()) * (double) spawnRange + 0.5D;
Entity entity = ChunkRegionLoader.a(compound, world, x, y, z, false);
@ -63,7 +64,7 @@ public class SSpawnerImpl implements SSpawner {
EntityInsentient entityInsentient = (EntityInsentient) entity;
Location spot = new Location(spawnerLocation.getWorld(), x, y, z);
Location spot = new Location(this.spawnerLocation.getWorld(), x, y, z);
if (!canSpawn(entityInsentient, spot, canSpawnOn)) {
continue;
}
@ -96,29 +97,28 @@ public class SSpawnerImpl implements SSpawner {
return null;
}
private boolean canSpawn(EntityInsentient entityInsentient, Location location, Set<CompatibleMaterial> canSpawnOn) {
private boolean canSpawn(EntityInsentient entityInsentient, Location location, Set<XMaterial> canSpawnOn) {
if (!entityInsentient.canSpawn()) {
return false;
}
CompatibleMaterial spawnedIn = CompatibleMaterial.getMaterial(location.getBlock());
CompatibleMaterial spawnedOn = CompatibleMaterial.getMaterial(location.getBlock().getRelative(BlockFace.DOWN));
if (spawnedIn == null || spawnedOn == null) {
Optional<XMaterial> spawnedIn = CompatibleMaterial.getMaterial(location.getBlock().getType());
Optional<XMaterial> spawnedOn = CompatibleMaterial.getMaterial(location.getBlock().getRelative(BlockFace.DOWN).getType());
if (!spawnedIn.isPresent() || !spawnedOn.isPresent()) {
return false;
}
if (!spawnedIn.isAir() &&
spawnedIn != CompatibleMaterial.WATER &&
!spawnedIn.name().contains("PRESSURE") &&
!spawnedIn.name().contains("SLAB")) {
if (!CompatibleMaterial.isAir(spawnedIn.get()) &&
spawnedIn.get() != XMaterial.WATER &&
!spawnedIn.get().name().contains("PRESSURE") &&
!spawnedIn.get().name().contains("SLAB")) {
return false;
}
for (CompatibleMaterial material : canSpawnOn) {
for (XMaterial material : canSpawnOn) {
if (material == null) continue;
if (spawnedOn.equals(material) || material.isAir()) {
if (spawnedOn.get() == material || CompatibleMaterial.isAir(material)) {
return true;
}
}

View File

@ -4,6 +4,7 @@ import com.craftaro.core.compatibility.CompatibleMaterial;
import com.craftaro.core.compatibility.CompatibleParticleHandler;
import com.craftaro.core.nms.world.SSpawner;
import com.craftaro.core.nms.world.SpawnedEntity;
import com.cryptomorin.xseries.XMaterial;
import net.minecraft.server.v1_11_R1.BlockPosition;
import net.minecraft.server.v1_11_R1.ChunkRegionLoader;
import net.minecraft.server.v1_11_R1.DifficultyDamageScaler;
@ -19,6 +20,7 @@ import org.bukkit.entity.EntityType;
import org.bukkit.entity.LivingEntity;
import org.bukkit.event.entity.CreatureSpawnEvent;
import java.util.Optional;
import java.util.Random;
import java.util.Set;
@ -35,24 +37,26 @@ public class SSpawnerImpl implements SSpawner {
}
@Override
public LivingEntity spawnEntity(EntityType type, String particleType, SpawnedEntity spawned,
Set<CompatibleMaterial> canSpawnOn) {
public LivingEntity spawnEntity(EntityType type, String particleType, SpawnedEntity spawned, Set<XMaterial> canSpawnOn) {
MobSpawnerData data = new MobSpawnerData();
NBTTagCompound compound = data.b();
String name = type.name().toLowerCase().replace("snowman", "snow_golem")
String name = type
.name()
.toLowerCase()
.replace("snowman", "snow_golem")
.replace("mushroom_cow", "mooshroom")
.replace("iron_golem", "villager_golem");
compound.setString("id", "minecraft:" + name);
short spawnRange = 4;
for (int i = 0; i < 50; i++) {
WorldServer world = ((CraftWorld) spawnerLocation.getWorld()).getHandle();
for (int i = 0; i < 50; ++i) {
WorldServer world = ((CraftWorld) this.spawnerLocation.getWorld()).getHandle();
Random random = world.random;
double x = spawnerLocation.getX() + (random.nextDouble() - random.nextDouble()) * (double) spawnRange + 0.5D;
double y = spawnerLocation.getY() + random.nextInt(3) - 1;
double z = spawnerLocation.getZ() + (random.nextDouble() - random.nextDouble()) * (double) spawnRange + 0.5D;
double x = this.spawnerLocation.getX() + (random.nextDouble() - random.nextDouble()) * (double) spawnRange + 0.5D;
double y = this.spawnerLocation.getY() + random.nextInt(3) - 1;
double z = this.spawnerLocation.getZ() + (random.nextDouble() - random.nextDouble()) * (double) spawnRange + 0.5D;
Entity entity = ChunkRegionLoader.a(compound, world, x, y, z, false);
@ -66,7 +70,7 @@ public class SSpawnerImpl implements SSpawner {
EntityInsentient entityInsentient = (EntityInsentient) entity;
Location spot = new Location(spawnerLocation.getWorld(), x, y, z);
Location spot = new Location(this.spawnerLocation.getWorld(), x, y, z);
if (!canSpawn(entityInsentient, spot, canSpawnOn)) {
continue;
}
@ -99,29 +103,29 @@ public class SSpawnerImpl implements SSpawner {
return null;
}
private boolean canSpawn(EntityInsentient entityInsentient, Location location, Set<CompatibleMaterial> canSpawnOn) {
private boolean canSpawn(EntityInsentient entityInsentient, Location location, Set<XMaterial> canSpawnOn) {
if (!entityInsentient.canSpawn()) {
return false;
}
CompatibleMaterial spawnedIn = CompatibleMaterial.getMaterial(location.getBlock());
CompatibleMaterial spawnedOn = CompatibleMaterial.getMaterial(location.getBlock().getRelative(BlockFace.DOWN));
Optional<XMaterial> spawnedIn = CompatibleMaterial.getMaterial(location.getBlock().getType());
Optional<XMaterial> spawnedOn = CompatibleMaterial.getMaterial(location.getBlock().getRelative(BlockFace.DOWN).getType());
if (spawnedIn == null || spawnedOn == null) {
if (!spawnedIn.isPresent() || !spawnedOn.isPresent()) {
return false;
}
if (!spawnedIn.isAir() &&
spawnedIn != CompatibleMaterial.WATER &&
!spawnedIn.name().contains("PRESSURE") &&
!spawnedIn.name().contains("SLAB")) {
if (!CompatibleMaterial.isAir(spawnedIn.get()) &&
spawnedIn.get() != XMaterial.WATER &&
!spawnedIn.get().name().contains("PRESSURE") &&
!spawnedIn.get().name().contains("SLAB")) {
return false;
}
for (CompatibleMaterial material : canSpawnOn) {
for (XMaterial material : canSpawnOn) {
if (material == null) continue;
if (spawnedOn.equals(material) || material.isAir()) {
if (spawnedOn.get() == material || CompatibleMaterial.isAir(material)) {
return true;
}
}

View File

@ -4,6 +4,7 @@ import com.craftaro.core.compatibility.CompatibleMaterial;
import com.craftaro.core.compatibility.CompatibleParticleHandler;
import com.craftaro.core.nms.world.SSpawner;
import com.craftaro.core.nms.world.SpawnedEntity;
import com.cryptomorin.xseries.XMaterial;
import net.minecraft.server.v1_12_R1.BlockPosition;
import net.minecraft.server.v1_12_R1.ChunkRegionLoader;
import net.minecraft.server.v1_12_R1.DifficultyDamageScaler;
@ -19,6 +20,7 @@ import org.bukkit.entity.EntityType;
import org.bukkit.entity.LivingEntity;
import org.bukkit.event.entity.CreatureSpawnEvent;
import java.util.Optional;
import java.util.Random;
import java.util.Set;
@ -35,25 +37,27 @@ public class SSpawnerImpl implements SSpawner {
}
@Override
public LivingEntity spawnEntity(EntityType type, String particleType, SpawnedEntity spawned,
Set<CompatibleMaterial> canSpawnOn) {
public LivingEntity spawnEntity(EntityType type, String particleType, SpawnedEntity spawned, Set<XMaterial> canSpawnOn) {
MobSpawnerData data = new MobSpawnerData();
NBTTagCompound compound = data.b();
String name = type.name().toLowerCase().replace("snowman", "snow_golem")
String name = type
.name()
.toLowerCase()
.replace("snowman", "snow_golem")
.replace("mushroom_cow", "mooshroom")
.replace("iron_golem", "villager_golem");;
.replace("iron_golem", "villager_golem");
compound.setString("id", "minecraft:" + name);
short spawnRange = 4;
for (int i = 0; i < 50; i++) {
WorldServer world = ((CraftWorld) spawnerLocation.getWorld()).getHandle();
for (int i = 0; i < 50; ++i) {
WorldServer world = ((CraftWorld) this.spawnerLocation.getWorld()).getHandle();
Random random = world.random;
double x = spawnerLocation.getX() + (random.nextDouble() - random.nextDouble()) * (double) spawnRange + 0.5D;
double y = spawnerLocation.getY() + random.nextInt(3) - 1;
double z = spawnerLocation.getZ() + (random.nextDouble() - random.nextDouble()) * (double) spawnRange + 0.5D;
double x = this.spawnerLocation.getX() + (random.nextDouble() - random.nextDouble()) * (double) spawnRange + 0.5D;
double y = this.spawnerLocation.getY() + random.nextInt(3) - 1;
double z = this.spawnerLocation.getZ() + (random.nextDouble() - random.nextDouble()) * (double) spawnRange + 0.5D;
Entity entity = ChunkRegionLoader.a(compound, world, x, y, z, false);
@ -67,7 +71,7 @@ public class SSpawnerImpl implements SSpawner {
EntityInsentient entityInsentient = (EntityInsentient) entity;
Location spot = new Location(spawnerLocation.getWorld(), x, y, z);
Location spot = new Location(this.spawnerLocation.getWorld(), x, y, z);
if (!canSpawn(entityInsentient, spot, canSpawnOn)) {
continue;
}
@ -100,29 +104,29 @@ public class SSpawnerImpl implements SSpawner {
return null;
}
private boolean canSpawn(EntityInsentient entityInsentient, Location location, Set<CompatibleMaterial> canSpawnOn) {
private boolean canSpawn(EntityInsentient entityInsentient, Location location, Set<XMaterial> canSpawnOn) {
if (!entityInsentient.canSpawn()) {
return false;
}
CompatibleMaterial spawnedIn = CompatibleMaterial.getMaterial(location.getBlock());
CompatibleMaterial spawnedOn = CompatibleMaterial.getMaterial(location.getBlock().getRelative(BlockFace.DOWN));
Optional<XMaterial> spawnedIn = CompatibleMaterial.getMaterial(location.getBlock().getType());
Optional<XMaterial> spawnedOn = CompatibleMaterial.getMaterial(location.getBlock().getRelative(BlockFace.DOWN).getType());
if (spawnedIn == null || spawnedOn == null) {
if (!spawnedIn.isPresent() || !spawnedOn.isPresent()) {
return false;
}
if (!spawnedIn.isAir() &&
spawnedIn != CompatibleMaterial.WATER &&
!spawnedIn.name().contains("PRESSURE") &&
!spawnedIn.name().contains("SLAB")) {
if (!CompatibleMaterial.isAir(spawnedIn.get()) &&
spawnedIn.get() != XMaterial.WATER &&
!spawnedIn.get().name().contains("PRESSURE") &&
!spawnedIn.get().name().contains("SLAB")) {
return false;
}
for (CompatibleMaterial material : canSpawnOn) {
for (XMaterial material : canSpawnOn) {
if (material == null) continue;
if (spawnedOn.equals(material) || material.isAir()) {
if (spawnedOn.get() == material || CompatibleMaterial.isAir(material)) {
return true;
}
}

View File

@ -4,6 +4,7 @@ import com.craftaro.core.compatibility.CompatibleMaterial;
import com.craftaro.core.compatibility.CompatibleParticleHandler;
import com.craftaro.core.nms.world.SSpawner;
import com.craftaro.core.nms.world.SpawnedEntity;
import com.cryptomorin.xseries.XMaterial;
import net.minecraft.server.v1_13_R1.BlockPosition;
import net.minecraft.server.v1_13_R1.ChunkRegionLoader;
import net.minecraft.server.v1_13_R1.DifficultyDamageScaler;
@ -19,6 +20,7 @@ import org.bukkit.entity.EntityType;
import org.bukkit.entity.LivingEntity;
import org.bukkit.event.entity.CreatureSpawnEvent;
import java.util.Optional;
import java.util.Random;
import java.util.Set;
@ -35,8 +37,7 @@ public class SSpawnerImpl implements SSpawner {
}
@Override
public LivingEntity spawnEntity(EntityType type, String particleType, SpawnedEntity spawned,
Set<CompatibleMaterial> canSpawnOn) {
public LivingEntity spawnEntity(EntityType type, String particleType, SpawnedEntity spawned, Set<XMaterial> canSpawnOn) {
MobSpawnerData data = new MobSpawnerData();
NBTTagCompound compound = data.b();
@ -45,13 +46,13 @@ public class SSpawnerImpl implements SSpawner {
compound.setString("id", "minecraft:" + name);
short spawnRange = 4;
for (int i = 0; i < 50; i++) {
WorldServer world = ((CraftWorld) spawnerLocation.getWorld()).getHandle();
for (int i = 0; i < 50; ++i) {
WorldServer world = ((CraftWorld) this.spawnerLocation.getWorld()).getHandle();
Random random = world.random;
double x = spawnerLocation.getX() + (random.nextDouble() - random.nextDouble()) * (double) spawnRange + 0.5D;
double y = spawnerLocation.getY() + random.nextInt(3) - 1;
double z = spawnerLocation.getZ() + (random.nextDouble() - random.nextDouble()) * (double) spawnRange + 0.5D;
double x = this.spawnerLocation.getX() + (random.nextDouble() - random.nextDouble()) * (double) spawnRange + 0.5D;
double y = this.spawnerLocation.getY() + random.nextInt(3) - 1;
double z = this.spawnerLocation.getZ() + (random.nextDouble() - random.nextDouble()) * (double) spawnRange + 0.5D;
Entity entity = ChunkRegionLoader.a(compound, world, x, y, z, false);
@ -65,7 +66,7 @@ public class SSpawnerImpl implements SSpawner {
EntityInsentient entityInsentient = (EntityInsentient) entity;
Location spot = new Location(spawnerLocation.getWorld(), x, y, z);
Location spot = new Location(this.spawnerLocation.getWorld(), x, y, z);
if (!canSpawn(world, entityInsentient, spot, canSpawnOn)) {
continue;
}
@ -98,30 +99,29 @@ public class SSpawnerImpl implements SSpawner {
return null;
}
private boolean canSpawn(WorldServer world, EntityInsentient entityInsentient, Location location,
Set<CompatibleMaterial> canSpawnOn) {
private boolean canSpawn(WorldServer world, EntityInsentient entityInsentient, Location location, Set<XMaterial> canSpawnOn) {
if (!world.getCubes(entityInsentient, entityInsentient.getBoundingBox())) {
return false;
}
CompatibleMaterial spawnedIn = CompatibleMaterial.getMaterial(location.getBlock());
CompatibleMaterial spawnedOn = CompatibleMaterial.getMaterial(location.getBlock().getRelative(BlockFace.DOWN));
Optional<XMaterial> spawnedIn = CompatibleMaterial.getMaterial(location.getBlock().getType());
Optional<XMaterial> spawnedOn = CompatibleMaterial.getMaterial(location.getBlock().getRelative(BlockFace.DOWN).getType());
if (spawnedIn == null || spawnedOn == null) {
if (!spawnedIn.isPresent() || !spawnedOn.isPresent()) {
return false;
}
if (!spawnedIn.isAir() &&
spawnedIn != CompatibleMaterial.WATER &&
!spawnedIn.name().contains("PRESSURE") &&
!spawnedIn.name().contains("SLAB")) {
if (!CompatibleMaterial.isAir(spawnedIn.get()) &&
spawnedIn.get() != XMaterial.WATER &&
!spawnedIn.get().name().contains("PRESSURE") &&
!spawnedIn.get().name().contains("SLAB")) {
return false;
}
for (CompatibleMaterial material : canSpawnOn) {
for (XMaterial material : canSpawnOn) {
if (material == null) continue;
if (spawnedOn.equals(material) || material.isAir()) {
if (spawnedOn.get() == material || CompatibleMaterial.isAir(material)) {
return true;
}
}

View File

@ -4,6 +4,7 @@ import com.craftaro.core.compatibility.CompatibleMaterial;
import com.craftaro.core.compatibility.CompatibleParticleHandler;
import com.craftaro.core.nms.world.SSpawner;
import com.craftaro.core.nms.world.SpawnedEntity;
import com.cryptomorin.xseries.XMaterial;
import net.minecraft.server.v1_13_R2.BlockPosition;
import net.minecraft.server.v1_13_R2.ChunkRegionLoader;
import net.minecraft.server.v1_13_R2.DifficultyDamageScaler;
@ -19,6 +20,7 @@ import org.bukkit.entity.EntityType;
import org.bukkit.entity.LivingEntity;
import org.bukkit.event.entity.CreatureSpawnEvent;
import java.util.Optional;
import java.util.Random;
import java.util.Set;
@ -35,8 +37,7 @@ public class SSpawnerImpl implements SSpawner {
}
@Override
public LivingEntity spawnEntity(EntityType type, String particleType, SpawnedEntity spawned,
Set<CompatibleMaterial> canSpawnOn) {
public LivingEntity spawnEntity(EntityType type, String particleType, SpawnedEntity spawned, Set<XMaterial> canSpawnOn) {
MobSpawnerData data = new MobSpawnerData();
NBTTagCompound compound = data.b();
@ -45,13 +46,13 @@ public class SSpawnerImpl implements SSpawner {
compound.setString("id", "minecraft:" + name);
short spawnRange = 4;
for (int i = 0; i < 50; i++) {
WorldServer world = ((CraftWorld) spawnerLocation.getWorld()).getHandle();
for (int i = 0; i < 50; ++i) {
WorldServer world = ((CraftWorld) this.spawnerLocation.getWorld()).getHandle();
Random random = world.random;
double x = spawnerLocation.getX() + (random.nextDouble() - random.nextDouble()) * (double) spawnRange + 0.5D;
double y = spawnerLocation.getY() + random.nextInt(3) - 1;
double z = spawnerLocation.getZ() + (random.nextDouble() - random.nextDouble()) * (double) spawnRange + 0.5D;
double x = this.spawnerLocation.getX() + (random.nextDouble() - random.nextDouble()) * (double) spawnRange + 0.5D;
double y = this.spawnerLocation.getY() + random.nextInt(3) - 1;
double z = this.spawnerLocation.getZ() + (random.nextDouble() - random.nextDouble()) * (double) spawnRange + 0.5D;
Entity entity = ChunkRegionLoader.a(compound, world, x, y, z, false);
@ -65,7 +66,7 @@ public class SSpawnerImpl implements SSpawner {
EntityInsentient entityInsentient = (EntityInsentient) entity;
Location spot = new Location(spawnerLocation.getWorld(), x, y, z);
Location spot = new Location(this.spawnerLocation.getWorld(), x, y, z);
if (!canSpawn(world, entityInsentient, spot, canSpawnOn)) {
continue;
}
@ -98,30 +99,29 @@ public class SSpawnerImpl implements SSpawner {
return null;
}
private boolean canSpawn(WorldServer world, EntityInsentient entityInsentient, Location location,
Set<CompatibleMaterial> canSpawnOn) {
private boolean canSpawn(WorldServer world, EntityInsentient entityInsentient, Location location, Set<XMaterial> canSpawnOn) {
if (!world.getCubes(entityInsentient, entityInsentient.getBoundingBox())) {
return false;
}
CompatibleMaterial spawnedIn = CompatibleMaterial.getMaterial(location.getBlock());
CompatibleMaterial spawnedOn = CompatibleMaterial.getMaterial(location.getBlock().getRelative(BlockFace.DOWN));
Optional<XMaterial> spawnedIn = CompatibleMaterial.getMaterial(location.getBlock().getType());
Optional<XMaterial> spawnedOn = CompatibleMaterial.getMaterial(location.getBlock().getRelative(BlockFace.DOWN).getType());
if (spawnedIn == null || spawnedOn == null) {
if (!spawnedIn.isPresent() || !spawnedOn.isPresent()) {
return false;
}
if (!spawnedIn.isAir() &&
spawnedIn != CompatibleMaterial.WATER &&
!spawnedIn.name().contains("PRESSURE") &&
!spawnedIn.name().contains("SLAB")) {
if (!CompatibleMaterial.isAir(spawnedIn.get()) &&
spawnedIn.get() != XMaterial.WATER &&
!spawnedIn.get().name().contains("PRESSURE") &&
!spawnedIn.get().name().contains("SLAB")) {
return false;
}
for (CompatibleMaterial material : canSpawnOn) {
for (XMaterial material : canSpawnOn) {
if (material == null) continue;
if (spawnedOn.equals(material) || material.isAir()) {
if (spawnedOn.get() == material || CompatibleMaterial.isAir(material)) {
return true;
}
}

View File

@ -4,6 +4,7 @@ import com.craftaro.core.compatibility.CompatibleMaterial;
import com.craftaro.core.compatibility.CompatibleParticleHandler;
import com.craftaro.core.nms.world.SSpawner;
import com.craftaro.core.nms.world.SpawnedEntity;
import com.cryptomorin.xseries.XMaterial;
import net.minecraft.server.v1_14_R1.BlockPosition;
import net.minecraft.server.v1_14_R1.DifficultyDamageScaler;
import net.minecraft.server.v1_14_R1.Entity;
@ -37,24 +38,26 @@ public class SSpawnerImpl implements SSpawner {
}
@Override
public LivingEntity spawnEntity(EntityType type, String particleType, SpawnedEntity spawned,
Set<CompatibleMaterial> canSpawnOn) {
public LivingEntity spawnEntity(EntityType type, String particleType, SpawnedEntity spawned, Set<XMaterial> canSpawnOn) {
MobSpawnerData data = new MobSpawnerData();
NBTTagCompound compound = data.getEntity();
String name = type.name().toLowerCase().replace("snowman", "snow_golem")
String name = type
.name()
.toLowerCase()
.replace("snowman", "snow_golem")
.replace("mushroom_cow", "mooshroom");
compound.setString("id", "minecraft:" + name);
short spawnRange = 4;
for (int i = 0; i < 50; i++) {
for (int i = 0; i < 50; ++i) {
@SuppressWarnings("ConstantConditions")
WorldServer world = ((CraftWorld) spawnerLocation.getWorld()).getHandle();
WorldServer world = ((CraftWorld) this.spawnerLocation.getWorld()).getHandle();
Random random = world.getRandom();
double x = spawnerLocation.getX() + (random.nextDouble() - random.nextDouble()) * (double) spawnRange + 0.5D;
double y = spawnerLocation.getY() + random.nextInt(3) - 1;
double z = spawnerLocation.getZ() + (random.nextDouble() - random.nextDouble()) * (double) spawnRange + 0.5D;
double x = this.spawnerLocation.getX() + (random.nextDouble() - random.nextDouble()) * (double) spawnRange + 0.5D;
double y = this.spawnerLocation.getY() + random.nextInt(3) - 1;
double z = this.spawnerLocation.getZ() + (random.nextDouble() - random.nextDouble()) * (double) spawnRange + 0.5D;
Optional<Entity> optionalEntity = EntityTypes.a(compound, world);
if (!optionalEntity.isPresent()) continue;
@ -71,7 +74,7 @@ public class SSpawnerImpl implements SSpawner {
EntityInsentient entityInsentient = (EntityInsentient) entity;
Location spot = new Location(spawnerLocation.getWorld(), x, y, z);
Location spot = new Location(this.spawnerLocation.getWorld(), x, y, z);
if (!canSpawn(world, entityInsentient, spot, canSpawnOn)) {
continue;
}
@ -104,30 +107,29 @@ public class SSpawnerImpl implements SSpawner {
return null;
}
private boolean canSpawn(WorldServer world, EntityInsentient entityInsentient, Location location,
Set<CompatibleMaterial> canSpawnOn) {
private boolean canSpawn(WorldServer world, EntityInsentient entityInsentient, Location location, Set<XMaterial> canSpawnOn) {
if (!world.getCubes(entityInsentient, entityInsentient.getBoundingBox())) {
return false;
}
CompatibleMaterial spawnedIn = CompatibleMaterial.getMaterial(location.getBlock());
CompatibleMaterial spawnedOn = CompatibleMaterial.getMaterial(location.getBlock().getRelative(BlockFace.DOWN));
Optional<XMaterial> spawnedIn = CompatibleMaterial.getMaterial(location.getBlock().getType());
Optional<XMaterial> spawnedOn = CompatibleMaterial.getMaterial(location.getBlock().getRelative(BlockFace.DOWN).getType());
if (spawnedIn == null || spawnedOn == null) {
if (!spawnedIn.isPresent() || !spawnedOn.isPresent()) {
return false;
}
if (!spawnedIn.isAir() &&
spawnedIn != CompatibleMaterial.WATER &&
!spawnedIn.name().contains("PRESSURE") &&
!spawnedIn.name().contains("SLAB")) {
if (!CompatibleMaterial.isAir(spawnedIn.get()) &&
spawnedIn.get() != XMaterial.WATER &&
!spawnedIn.get().name().contains("PRESSURE") &&
!spawnedIn.get().name().contains("SLAB")) {
return false;
}
for (CompatibleMaterial material : canSpawnOn) {
for (XMaterial material : canSpawnOn) {
if (material == null) continue;
if (spawnedOn.equals(material) || material.isAir()) {
if (spawnedOn.get() == material || CompatibleMaterial.isAir(material)) {
return true;
}
}

View File

@ -4,6 +4,7 @@ import com.craftaro.core.compatibility.CompatibleMaterial;
import com.craftaro.core.compatibility.CompatibleParticleHandler;
import com.craftaro.core.nms.world.SSpawner;
import com.craftaro.core.nms.world.SpawnedEntity;
import com.cryptomorin.xseries.XMaterial;
import net.minecraft.server.v1_15_R1.BlockPosition;
import net.minecraft.server.v1_15_R1.DifficultyDamageScaler;
import net.minecraft.server.v1_15_R1.Entity;
@ -37,24 +38,26 @@ public class SSpawnerImpl implements SSpawner {
}
@Override
public LivingEntity spawnEntity(EntityType type, String particleType, SpawnedEntity spawned,
Set<CompatibleMaterial> canSpawnOn) {
public LivingEntity spawnEntity(EntityType type, String particleType, SpawnedEntity spawned, Set<XMaterial> canSpawnOn) {
MobSpawnerData data = new MobSpawnerData();
NBTTagCompound compound = data.getEntity();
String name = type.name().toLowerCase().replace("snowman", "snow_golem")
String name = type
.name()
.toLowerCase()
.replace("snowman", "snow_golem")
.replace("mushroom_cow", "mooshroom");
compound.setString("id", "minecraft:" + name);
short spawnRange = 4;
for (int i = 0; i < 50; i++) {
for (int i = 0; i < 50; ++i) {
@SuppressWarnings("ConstantConditions")
WorldServer world = ((CraftWorld) spawnerLocation.getWorld()).getHandle();
WorldServer world = ((CraftWorld) this.spawnerLocation.getWorld()).getHandle();
Random random = world.getRandom();
double x = spawnerLocation.getX() + (random.nextDouble() - random.nextDouble()) * (double) spawnRange + 0.5D;
double y = spawnerLocation.getY() + random.nextInt(3) - 1;
double z = spawnerLocation.getZ() + (random.nextDouble() - random.nextDouble()) * (double) spawnRange + 0.5D;
double x = this.spawnerLocation.getX() + (random.nextDouble() - random.nextDouble()) * (double) spawnRange + 0.5D;
double y = this.spawnerLocation.getY() + random.nextInt(3) - 1;
double z = this.spawnerLocation.getZ() + (random.nextDouble() - random.nextDouble()) * (double) spawnRange + 0.5D;
Optional<Entity> optionalEntity = EntityTypes.a(compound, world);
if (!optionalEntity.isPresent()) {
@ -73,7 +76,7 @@ public class SSpawnerImpl implements SSpawner {
EntityInsentient entityInsentient = (EntityInsentient) entity;
Location spot = new Location(spawnerLocation.getWorld(), x, y, z);
Location spot = new Location(this.spawnerLocation.getWorld(), x, y, z);
if (!canSpawn(world, entityInsentient, spot, canSpawnOn)) {
continue;
}
@ -106,30 +109,29 @@ public class SSpawnerImpl implements SSpawner {
return null;
}
private boolean canSpawn(WorldServer world, EntityInsentient entityInsentient, Location location,
Set<CompatibleMaterial> canSpawnOn) {
private boolean canSpawn(WorldServer world, EntityInsentient entityInsentient, Location location, Set<XMaterial> canSpawnOn) {
if (!world.getCubes(entityInsentient, entityInsentient.getBoundingBox())) {
return false;
}
CompatibleMaterial spawnedIn = CompatibleMaterial.getMaterial(location.getBlock());
CompatibleMaterial spawnedOn = CompatibleMaterial.getMaterial(location.getBlock().getRelative(BlockFace.DOWN));
Optional<XMaterial> spawnedIn = CompatibleMaterial.getMaterial(location.getBlock().getType());
Optional<XMaterial> spawnedOn = CompatibleMaterial.getMaterial(location.getBlock().getRelative(BlockFace.DOWN).getType());
if (spawnedIn == null || spawnedOn == null) {
if (!spawnedIn.isPresent() || !spawnedOn.isPresent()) {
return false;
}
if (!spawnedIn.isAir() &&
spawnedIn != CompatibleMaterial.WATER &&
!spawnedIn.name().contains("PRESSURE") &&
!spawnedIn.name().contains("SLAB")) {
if (!CompatibleMaterial.isAir(spawnedIn.get()) &&
spawnedIn.get() != XMaterial.WATER &&
!spawnedIn.get().name().contains("PRESSURE") &&
!spawnedIn.get().name().contains("SLAB")) {
return false;
}
for (CompatibleMaterial material : canSpawnOn) {
for (XMaterial material : canSpawnOn) {
if (material == null) continue;
if (spawnedOn.equals(material) || material.isAir()) {
if (spawnedOn.get() == material || CompatibleMaterial.isAir(material)) {
return true;
}
}

View File

@ -4,6 +4,7 @@ import com.craftaro.core.compatibility.CompatibleMaterial;
import com.craftaro.core.compatibility.CompatibleParticleHandler;
import com.craftaro.core.nms.world.SSpawner;
import com.craftaro.core.nms.world.SpawnedEntity;
import com.cryptomorin.xseries.XMaterial;
import net.minecraft.server.v1_16_R1.BlockPosition;
import net.minecraft.server.v1_16_R1.DifficultyDamageScaler;
import net.minecraft.server.v1_16_R1.Entity;
@ -37,8 +38,7 @@ public class SSpawnerImpl implements SSpawner {
}
@Override
public LivingEntity spawnEntity(EntityType type, String particleType, SpawnedEntity spawned,
Set<CompatibleMaterial> canSpawnOn) {
public LivingEntity spawnEntity(EntityType type, String particleType, SpawnedEntity spawned, Set<XMaterial> canSpawnOn) {
MobSpawnerData data = new MobSpawnerData();
NBTTagCompound compound = data.getEntity();
@ -47,14 +47,14 @@ public class SSpawnerImpl implements SSpawner {
compound.setString("id", "minecraft:" + name);
short spawnRange = 4;
for (int i = 0; i < 50; i++) {
for (int i = 0; i < 50; ++i) {
@SuppressWarnings("ConstantConditions")
WorldServer world = ((CraftWorld) spawnerLocation.getWorld()).getHandle();
WorldServer world = ((CraftWorld) this.spawnerLocation.getWorld()).getHandle();
Random random = world.getRandom();
double x = spawnerLocation.getX() + (random.nextDouble() - random.nextDouble()) * (double) spawnRange + 0.5D;
double y = spawnerLocation.getY() + random.nextInt(3) - 1;
double z = spawnerLocation.getZ() + (random.nextDouble() - random.nextDouble()) * (double) spawnRange + 0.5D;
double x = this.spawnerLocation.getX() + (random.nextDouble() - random.nextDouble()) * (double) spawnRange + 0.5D;
double y = this.spawnerLocation.getY() + random.nextInt(3) - 1;
double z = this.spawnerLocation.getZ() + (random.nextDouble() - random.nextDouble()) * (double) spawnRange + 0.5D;
Optional<Entity> optionalEntity = EntityTypes.a(compound, world);
if (!optionalEntity.isPresent()) {
@ -73,7 +73,7 @@ public class SSpawnerImpl implements SSpawner {
EntityInsentient entityInsentient = (EntityInsentient) entity;
Location spot = new Location(spawnerLocation.getWorld(), x, y, z);
Location spot = new Location(this.spawnerLocation.getWorld(), x, y, z);
if (!canSpawn(world, entityInsentient, spot, canSpawnOn)) {
continue;
}
@ -106,30 +106,29 @@ public class SSpawnerImpl implements SSpawner {
return null;
}
private boolean canSpawn(WorldServer world, EntityInsentient entityInsentient, Location location,
Set<CompatibleMaterial> canSpawnOn) {
private boolean canSpawn(WorldServer world, EntityInsentient entityInsentient, Location location, Set<XMaterial> canSpawnOn) {
if (!world.getCubes(entityInsentient, entityInsentient.getBoundingBox())) {
return false;
}
CompatibleMaterial spawnedIn = CompatibleMaterial.getMaterial(location.getBlock());
CompatibleMaterial spawnedOn = CompatibleMaterial.getMaterial(location.getBlock().getRelative(BlockFace.DOWN));
Optional<XMaterial> spawnedIn = CompatibleMaterial.getMaterial(location.getBlock().getType());
Optional<XMaterial> spawnedOn = CompatibleMaterial.getMaterial(location.getBlock().getRelative(BlockFace.DOWN).getType());
if (spawnedIn == null || spawnedOn == null) {
if (!spawnedIn.isPresent() || !spawnedOn.isPresent()) {
return false;
}
if (!spawnedIn.isAir() &&
spawnedIn != CompatibleMaterial.WATER &&
!spawnedIn.name().contains("PRESSURE") &&
!spawnedIn.name().contains("SLAB")) {
if (!CompatibleMaterial.isAir(spawnedIn.get()) &&
spawnedIn.get() != XMaterial.WATER &&
!spawnedIn.get().name().contains("PRESSURE") &&
!spawnedIn.get().name().contains("SLAB")) {
return false;
}
for (CompatibleMaterial material : canSpawnOn) {
for (XMaterial material : canSpawnOn) {
if (material == null) continue;
if (spawnedOn.equals(material) || material.isAir()) {
if (spawnedOn.get() == material || CompatibleMaterial.isAir(material)) {
return true;
}
}

View File

@ -4,6 +4,7 @@ import com.craftaro.core.compatibility.CompatibleMaterial;
import com.craftaro.core.compatibility.CompatibleParticleHandler;
import com.craftaro.core.nms.world.SSpawner;
import com.craftaro.core.nms.world.SpawnedEntity;
import com.cryptomorin.xseries.XMaterial;
import net.minecraft.server.v1_16_R2.BlockPosition;
import net.minecraft.server.v1_16_R2.DifficultyDamageScaler;
import net.minecraft.server.v1_16_R2.Entity;
@ -37,8 +38,7 @@ public class SSpawnerImpl implements SSpawner {
}
@Override
public LivingEntity spawnEntity(EntityType type, String particleType, SpawnedEntity spawned,
Set<CompatibleMaterial> canSpawnOn) {
public LivingEntity spawnEntity(EntityType type, String particleType, SpawnedEntity spawned, Set<XMaterial> canSpawnOn) {
MobSpawnerData data = new MobSpawnerData();
NBTTagCompound compound = data.getEntity();
@ -47,14 +47,14 @@ public class SSpawnerImpl implements SSpawner {
compound.setString("id", "minecraft:" + name);
short spawnRange = 4;
for (int i = 0; i < 50; i++) {
for (int i = 0; i < 50; ++i) {
@SuppressWarnings("ConstantConditions")
WorldServer world = ((CraftWorld) spawnerLocation.getWorld()).getHandle();
WorldServer world = ((CraftWorld) this.spawnerLocation.getWorld()).getHandle();
Random random = world.getRandom();
double x = spawnerLocation.getX() + (random.nextDouble() - random.nextDouble()) * (double) spawnRange + 0.5D;
double y = spawnerLocation.getY() + random.nextInt(3) - 1;
double z = spawnerLocation.getZ() + (random.nextDouble() - random.nextDouble()) * (double) spawnRange + 0.5D;
double x = this.spawnerLocation.getX() + (random.nextDouble() - random.nextDouble()) * (double) spawnRange + 0.5D;
double y = this.spawnerLocation.getY() + random.nextInt(3) - 1;
double z = this.spawnerLocation.getZ() + (random.nextDouble() - random.nextDouble()) * (double) spawnRange + 0.5D;
Optional<Entity> optionalEntity = EntityTypes.a(compound, world);
if (!optionalEntity.isPresent()) {
@ -73,7 +73,7 @@ public class SSpawnerImpl implements SSpawner {
EntityInsentient entityInsentient = (EntityInsentient) entity;
Location spot = new Location(spawnerLocation.getWorld(), x, y, z);
Location spot = new Location(this.spawnerLocation.getWorld(), x, y, z);
if (!canSpawn(world, entityInsentient, spot, canSpawnOn)) {
continue;
}
@ -106,30 +106,29 @@ public class SSpawnerImpl implements SSpawner {
return null;
}
private boolean canSpawn(WorldServer world, EntityInsentient entityInsentient, Location location,
Set<CompatibleMaterial> canSpawnOn) {
private boolean canSpawn(WorldServer world, EntityInsentient entityInsentient, Location location, Set<XMaterial> canSpawnOn) {
if (!world.getCubes(entityInsentient, entityInsentient.getBoundingBox())) {
return false;
}
CompatibleMaterial spawnedIn = CompatibleMaterial.getMaterial(location.getBlock());
CompatibleMaterial spawnedOn = CompatibleMaterial.getMaterial(location.getBlock().getRelative(BlockFace.DOWN));
Optional<XMaterial> spawnedIn = CompatibleMaterial.getMaterial(location.getBlock().getType());
Optional<XMaterial> spawnedOn = CompatibleMaterial.getMaterial(location.getBlock().getRelative(BlockFace.DOWN).getType());
if (spawnedIn == null || spawnedOn == null) {
if (!spawnedIn.isPresent() || !spawnedOn.isPresent()) {
return false;
}
if (!spawnedIn.isAir() &&
spawnedIn != CompatibleMaterial.WATER &&
!spawnedIn.name().contains("PRESSURE") &&
!spawnedIn.name().contains("SLAB")) {
if (!CompatibleMaterial.isAir(spawnedIn.get()) &&
spawnedIn.get() != XMaterial.WATER &&
!spawnedIn.get().name().contains("PRESSURE") &&
!spawnedIn.get().name().contains("SLAB")) {
return false;
}
for (CompatibleMaterial material : canSpawnOn) {
for (XMaterial material : canSpawnOn) {
if (material == null) continue;
if (spawnedOn.equals(material) || material.isAir()) {
if (spawnedOn.get() == material || CompatibleMaterial.isAir(material)) {
return true;
}
}

View File

@ -4,6 +4,7 @@ import com.craftaro.core.compatibility.CompatibleMaterial;
import com.craftaro.core.compatibility.CompatibleParticleHandler;
import com.craftaro.core.nms.world.SSpawner;
import com.craftaro.core.nms.world.SpawnedEntity;
import com.cryptomorin.xseries.XMaterial;
import net.minecraft.server.v1_16_R3.BlockPosition;
import net.minecraft.server.v1_16_R3.DifficultyDamageScaler;
import net.minecraft.server.v1_16_R3.Entity;
@ -37,8 +38,7 @@ public class SSpawnerImpl implements SSpawner {
}
@Override
public LivingEntity spawnEntity(EntityType type, String particleType, SpawnedEntity spawned,
Set<CompatibleMaterial> canSpawnOn) {
public LivingEntity spawnEntity(EntityType type, String particleType, SpawnedEntity spawned, Set<XMaterial> canSpawnOn) {
MobSpawnerData data = new MobSpawnerData();
NBTTagCompound compound = data.getEntity();
@ -47,14 +47,14 @@ public class SSpawnerImpl implements SSpawner {
compound.setString("id", "minecraft:" + name);
short spawnRange = 4;
for (int i = 0; i < 50; i++) {
for (int i = 0; i < 50; ++i) {
@SuppressWarnings("ConstantConditions")
WorldServer world = ((CraftWorld) spawnerLocation.getWorld()).getHandle();
WorldServer world = ((CraftWorld) this.spawnerLocation.getWorld()).getHandle();
Random random = world.getRandom();
double x = spawnerLocation.getX() + (random.nextDouble() - random.nextDouble()) * (double) spawnRange + 0.5D;
double y = spawnerLocation.getY() + random.nextInt(3) - 1;
double z = spawnerLocation.getZ() + (random.nextDouble() - random.nextDouble()) * (double) spawnRange + 0.5D;
double x = this.spawnerLocation.getX() + (random.nextDouble() - random.nextDouble()) * (double) spawnRange + 0.5D;
double y = this.spawnerLocation.getY() + random.nextInt(3) - 1;
double z = this.spawnerLocation.getZ() + (random.nextDouble() - random.nextDouble()) * (double) spawnRange + 0.5D;
Optional<Entity> optionalEntity = EntityTypes.a(compound, world);
if (!optionalEntity.isPresent()) {
@ -73,7 +73,7 @@ public class SSpawnerImpl implements SSpawner {
EntityInsentient entityInsentient = (EntityInsentient) entity;
Location spot = new Location(spawnerLocation.getWorld(), x, y, z);
Location spot = new Location(this.spawnerLocation.getWorld(), x, y, z);
if (!canSpawn(world, entityInsentient, spot, canSpawnOn)) {
continue;
}
@ -105,30 +105,29 @@ public class SSpawnerImpl implements SSpawner {
return null;
}
private boolean canSpawn(WorldServer world, EntityInsentient entityInsentient, Location location,
Set<CompatibleMaterial> canSpawnOn) {
private boolean canSpawn(WorldServer world, EntityInsentient entityInsentient, Location location, Set<XMaterial> canSpawnOn) {
if (!world.getCubes(entityInsentient, entityInsentient.getBoundingBox())) {
return false;
}
CompatibleMaterial spawnedIn = CompatibleMaterial.getMaterial(location.getBlock());
CompatibleMaterial spawnedOn = CompatibleMaterial.getMaterial(location.getBlock().getRelative(BlockFace.DOWN));
Optional<XMaterial> spawnedIn = CompatibleMaterial.getMaterial(location.getBlock().getType());
Optional<XMaterial> spawnedOn = CompatibleMaterial.getMaterial(location.getBlock().getRelative(BlockFace.DOWN).getType());
if (spawnedIn == null || spawnedOn == null) {
if (!spawnedIn.isPresent() || !spawnedOn.isPresent()) {
return false;
}
if (!spawnedIn.isAir() &&
spawnedIn != CompatibleMaterial.WATER &&
!spawnedIn.name().contains("PRESSURE") &&
!spawnedIn.name().contains("SLAB")) {
if (!CompatibleMaterial.isAir(spawnedIn.get()) &&
spawnedIn.get() != XMaterial.WATER &&
!spawnedIn.get().name().contains("PRESSURE") &&
!spawnedIn.get().name().contains("SLAB")) {
return false;
}
for (CompatibleMaterial material : canSpawnOn) {
for (XMaterial material : canSpawnOn) {
if (material == null) continue;
if (spawnedOn.equals(material) || material.isAir()) {
if (spawnedOn.get() == material || CompatibleMaterial.isAir(material)) {
return true;
}
}

View File

@ -4,6 +4,7 @@ import com.craftaro.core.compatibility.CompatibleMaterial;
import com.craftaro.core.compatibility.CompatibleParticleHandler;
import com.craftaro.core.nms.world.SSpawner;
import com.craftaro.core.nms.world.SpawnedEntity;
import com.cryptomorin.xseries.XMaterial;
import net.minecraft.core.BlockPosition;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.server.level.WorldServer;
@ -37,8 +38,7 @@ public class SSpawnerImpl implements SSpawner {
}
@Override
public LivingEntity spawnEntity(EntityType type, String particleType, SpawnedEntity spawned,
Set<CompatibleMaterial> canSpawnOn) {
public LivingEntity spawnEntity(EntityType type, String particleType, SpawnedEntity spawned, Set<XMaterial> canSpawnOn) {
MobSpawnerData data = new MobSpawnerData();
NBTTagCompound compound = data.getEntity();
@ -47,14 +47,14 @@ public class SSpawnerImpl implements SSpawner {
compound.setString("id", "minecraft:" + name);
short spawnRange = 4;
for (int i = 0; i < 50; i++) {
assert spawnerLocation.getWorld() != null;
WorldServer world = ((CraftWorld) spawnerLocation.getWorld()).getHandle();
for (int i = 0; i < 50; ++i) {
assert this.spawnerLocation.getWorld() != null;
WorldServer world = ((CraftWorld) this.spawnerLocation.getWorld()).getHandle();
Random random = world.getRandom();
double x = spawnerLocation.getX() + (random.nextDouble() - random.nextDouble()) * (double) spawnRange + 0.5D;
double y = spawnerLocation.getY() + random.nextInt(3) - 1;
double z = spawnerLocation.getZ() + (random.nextDouble() - random.nextDouble()) * (double) spawnRange + 0.5D;
double x = this.spawnerLocation.getX() + (random.nextDouble() - random.nextDouble()) * (double) spawnRange + 0.5D;
double y = this.spawnerLocation.getY() + random.nextInt(3) - 1;
double z = this.spawnerLocation.getZ() + (random.nextDouble() - random.nextDouble()) * (double) spawnRange + 0.5D;
Optional<Entity> optionalEntity = EntityTypes.a(compound, world);
if (optionalEntity.isEmpty()) continue;
@ -65,12 +65,11 @@ public class SSpawnerImpl implements SSpawner {
BlockPosition position = entity.getChunkCoordinates();
DifficultyDamageScaler damageScaler = world.getDamageScaler(position);
if (!(entity instanceof EntityInsentient)) {
if (!(entity instanceof EntityInsentient entityInsentient)) {
continue;
}
EntityInsentient entityInsentient = (EntityInsentient) entity;
Location spot = new Location(spawnerLocation.getWorld(), x, y, z);
Location spot = new Location(this.spawnerLocation.getWorld(), x, y, z);
if (!canSpawn(world, entityInsentient, spot, canSpawnOn)) {
continue;
@ -104,30 +103,29 @@ public class SSpawnerImpl implements SSpawner {
return null;
}
private boolean canSpawn(WorldServer world, EntityInsentient entityInsentient, Location location,
Set<CompatibleMaterial> canSpawnOn) {
private boolean canSpawn(WorldServer world, EntityInsentient entityInsentient, Location location, Set<XMaterial> canSpawnOn) {
if (!world.getCubes(entityInsentient, entityInsentient.getBoundingBox())) {
return false;
}
CompatibleMaterial spawnedIn = CompatibleMaterial.getMaterial(location.getBlock());
CompatibleMaterial spawnedOn = CompatibleMaterial.getMaterial(location.getBlock().getRelative(BlockFace.DOWN));
Optional<XMaterial> spawnedIn = CompatibleMaterial.getMaterial(location.getBlock().getType());
Optional<XMaterial> spawnedOn = CompatibleMaterial.getMaterial(location.getBlock().getRelative(BlockFace.DOWN).getType());
if (spawnedIn == null || spawnedOn == null) {
if (spawnedIn.isEmpty() || spawnedOn.isEmpty()) {
return false;
}
if (!spawnedIn.isAir() &&
spawnedIn != CompatibleMaterial.WATER &&
!spawnedIn.name().contains("PRESSURE") &&
!spawnedIn.name().contains("SLAB")) {
if (!CompatibleMaterial.isAir(spawnedIn.get()) &&
spawnedIn.get() != XMaterial.WATER &&
!spawnedIn.get().name().contains("PRESSURE") &&
!spawnedIn.get().name().contains("SLAB")) {
return false;
}
for (CompatibleMaterial material : canSpawnOn) {
for (XMaterial material : canSpawnOn) {
if (material == null) continue;
if (spawnedOn.equals(material) || material.isAir()) {
if (spawnedOn.get() == material || CompatibleMaterial.isAir(material)) {
return true;
}
}

View File

@ -4,6 +4,7 @@ import com.craftaro.core.compatibility.CompatibleMaterial;
import com.craftaro.core.compatibility.CompatibleParticleHandler;
import com.craftaro.core.nms.world.SSpawner;
import com.craftaro.core.nms.world.SpawnedEntity;
import com.cryptomorin.xseries.XMaterial;
import net.minecraft.core.BlockPos;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.server.level.ServerLevel;
@ -36,7 +37,7 @@ public class SSpawnerImpl implements SSpawner {
}
@Override
public LivingEntity spawnEntity(EntityType type, String particleType, SpawnedEntity spawned, Set<CompatibleMaterial> canSpawnOn) {
public LivingEntity spawnEntity(EntityType type, String particleType, SpawnedEntity spawned, Set<XMaterial> canSpawnOn) {
SpawnData data = new SpawnData();
CompoundTag compound = data.getEntityToSpawn();
@ -46,14 +47,14 @@ public class SSpawnerImpl implements SSpawner {
compound.putString("id", "minecraft:" + name);
short spawnRange = 4;
for (int i = 0; i < 50; i++) {
assert spawnerLocation.getWorld() != null;
ServerLevel world = ((CraftWorld) spawnerLocation.getWorld()).getHandle();
for (int i = 0; i < 50; ++i) {
assert this.spawnerLocation.getWorld() != null;
ServerLevel world = ((CraftWorld) this.spawnerLocation.getWorld()).getHandle();
Random random = world.getRandom();
double x = spawnerLocation.getX() + (random.nextDouble() - random.nextDouble()) * (double) spawnRange + 0.5D;
double y = spawnerLocation.getY() + random.nextInt(3) - 1;
double z = spawnerLocation.getZ() + (random.nextDouble() - random.nextDouble()) * (double) spawnRange + 0.5D;
double x = this.spawnerLocation.getX() + (random.nextDouble() - random.nextDouble()) * (double) spawnRange + 0.5D;
double y = this.spawnerLocation.getY() + random.nextInt(3) - 1;
double z = this.spawnerLocation.getZ() + (random.nextDouble() - random.nextDouble()) * (double) spawnRange + 0.5D;
Optional<Entity> optionalEntity = net.minecraft.world.entity.EntityType.create(compound, world);
if (optionalEntity.isEmpty()) continue;
@ -68,7 +69,7 @@ public class SSpawnerImpl implements SSpawner {
continue;
}
Location spot = new Location(spawnerLocation.getWorld(), x, y, z);
Location spot = new Location(this.spawnerLocation.getWorld(), x, y, z);
if (!canSpawn(world, entityInsentient, spot, canSpawnOn)) {
continue;
@ -102,29 +103,29 @@ public class SSpawnerImpl implements SSpawner {
return null;
}
private boolean canSpawn(ServerLevel world, Mob entityInsentient, Location location, Set<CompatibleMaterial> canSpawnOn) {
private boolean canSpawn(ServerLevel world, Mob entityInsentient, Location location, Set<XMaterial> canSpawnOn) {
if (!world.noCollision(entityInsentient, entityInsentient.getBoundingBox())) {
return false;
}
CompatibleMaterial spawnedIn = CompatibleMaterial.getMaterial(location.getBlock());
CompatibleMaterial spawnedOn = CompatibleMaterial.getMaterial(location.getBlock().getRelative(BlockFace.DOWN));
Optional<XMaterial> spawnedIn = CompatibleMaterial.getMaterial(location.getBlock().getType());
Optional<XMaterial> spawnedOn = CompatibleMaterial.getMaterial(location.getBlock().getRelative(BlockFace.DOWN).getType());
if (spawnedIn == null || spawnedOn == null) {
if (spawnedIn.isEmpty() || spawnedOn.isEmpty()) {
return false;
}
if (!spawnedIn.isAir() &&
spawnedIn != CompatibleMaterial.WATER &&
!spawnedIn.name().contains("PRESSURE") &&
!spawnedIn.name().contains("SLAB")) {
if (!CompatibleMaterial.isAir(spawnedIn.get()) &&
spawnedIn.get() != XMaterial.WATER &&
!spawnedIn.get().name().contains("PRESSURE") &&
!spawnedIn.get().name().contains("SLAB")) {
return false;
}
for (CompatibleMaterial material : canSpawnOn) {
for (XMaterial material : canSpawnOn) {
if (material == null) continue;
if (spawnedOn.equals(material) || material.isAir()) {
if (spawnedOn.get() == material || CompatibleMaterial.isAir(material)) {
return true;
}
}

View File

@ -4,6 +4,7 @@ import com.craftaro.core.compatibility.CompatibleMaterial;
import com.craftaro.core.compatibility.CompatibleParticleHandler;
import com.craftaro.core.nms.world.SSpawner;
import com.craftaro.core.nms.world.SpawnedEntity;
import com.cryptomorin.xseries.XMaterial;
import net.minecraft.core.BlockPos;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.server.level.ServerLevel;
@ -36,7 +37,7 @@ public class SSpawnerImpl implements SSpawner {
}
@Override
public LivingEntity spawnEntity(EntityType type, String particleType, SpawnedEntity spawned, Set<CompatibleMaterial> canSpawnOn) {
public LivingEntity spawnEntity(EntityType type, String particleType, SpawnedEntity spawned, Set<XMaterial> canSpawnOn) {
SpawnData data = new SpawnData();
CompoundTag compound = data.getEntityToSpawn();
@ -46,14 +47,14 @@ public class SSpawnerImpl implements SSpawner {
compound.putString("id", "minecraft:" + name);
short spawnRange = 4;
for (int i = 0; i < 50; i++) {
assert spawnerLocation.getWorld() != null;
ServerLevel world = ((CraftWorld) spawnerLocation.getWorld()).getHandle();
for (int i = 0; i < 50; ++i) {
assert this.spawnerLocation.getWorld() != null;
ServerLevel world = ((CraftWorld) this.spawnerLocation.getWorld()).getHandle();
Random random = world.getRandom();
double x = spawnerLocation.getX() + (random.nextDouble() - random.nextDouble()) * (double) spawnRange + 0.5D;
double y = spawnerLocation.getY() + random.nextInt(3) - 1;
double z = spawnerLocation.getZ() + (random.nextDouble() - random.nextDouble()) * (double) spawnRange + 0.5D;
double x = this.spawnerLocation.getX() + (random.nextDouble() - random.nextDouble()) * (double) spawnRange + 0.5D;
double y = this.spawnerLocation.getY() + random.nextInt(3) - 1;
double z = this.spawnerLocation.getZ() + (random.nextDouble() - random.nextDouble()) * (double) spawnRange + 0.5D;
Optional<Entity> optionalEntity = net.minecraft.world.entity.EntityType.create(compound, world);
if (optionalEntity.isEmpty()) continue;
@ -68,7 +69,7 @@ public class SSpawnerImpl implements SSpawner {
continue;
}
Location spot = new Location(spawnerLocation.getWorld(), x, y, z);
Location spot = new Location(this.spawnerLocation.getWorld(), x, y, z);
if (!canSpawn(world, entityInsentient, spot, canSpawnOn)) {
continue;
@ -101,29 +102,29 @@ public class SSpawnerImpl implements SSpawner {
return null;
}
private boolean canSpawn(ServerLevel world, Mob entityInsentient, Location location, Set<CompatibleMaterial> canSpawnOn) {
private boolean canSpawn(ServerLevel world, Mob entityInsentient, Location location, Set<XMaterial> canSpawnOn) {
if (!world.noCollision(entityInsentient, entityInsentient.getBoundingBox())) {
return false;
}
CompatibleMaterial spawnedIn = CompatibleMaterial.getMaterial(location.getBlock());
CompatibleMaterial spawnedOn = CompatibleMaterial.getMaterial(location.getBlock().getRelative(BlockFace.DOWN));
Optional<XMaterial> spawnedIn = CompatibleMaterial.getMaterial(location.getBlock().getType());
Optional<XMaterial> spawnedOn = CompatibleMaterial.getMaterial(location.getBlock().getRelative(BlockFace.DOWN).getType());
if (spawnedIn == null || spawnedOn == null) {
if (spawnedIn.isEmpty() || spawnedOn.isEmpty()) {
return false;
}
if (!spawnedIn.isAir() &&
spawnedIn != CompatibleMaterial.WATER &&
!spawnedIn.name().contains("PRESSURE") &&
!spawnedIn.name().contains("SLAB")) {
if (!CompatibleMaterial.isAir(spawnedIn.get()) &&
spawnedIn.get() != XMaterial.WATER &&
!spawnedIn.get().name().contains("PRESSURE") &&
!spawnedIn.get().name().contains("SLAB")) {
return false;
}
for (CompatibleMaterial material : canSpawnOn) {
for (XMaterial material : canSpawnOn) {
if (material == null) continue;
if (spawnedOn.equals(material) || material.isAir()) {
if (spawnedOn.get() == material || CompatibleMaterial.isAir(material)) {
return true;
}
}

View File

@ -4,6 +4,7 @@ import com.craftaro.core.compatibility.CompatibleMaterial;
import com.craftaro.core.compatibility.CompatibleParticleHandler;
import com.craftaro.core.nms.world.SSpawner;
import com.craftaro.core.nms.world.SpawnedEntity;
import com.cryptomorin.xseries.XMaterial;
import net.minecraft.core.BlockPos;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.server.level.ServerLevel;
@ -36,7 +37,7 @@ public class SSpawnerImpl implements SSpawner {
}
@Override
public LivingEntity spawnEntity(EntityType type, String particleType, SpawnedEntity spawned, Set<CompatibleMaterial> canSpawnOn) {
public LivingEntity spawnEntity(EntityType type, String particleType, SpawnedEntity spawned, Set<XMaterial> canSpawnOn) {
SpawnData data = new SpawnData();
CompoundTag compound = data.getEntityToSpawn();
@ -46,13 +47,13 @@ public class SSpawnerImpl implements SSpawner {
short spawnRange = 4;
for (int i = 0; i < 50; i++) {
assert spawnerLocation.getWorld() != null;
ServerLevel world = ((CraftWorld) spawnerLocation.getWorld()).getHandle();
assert this.spawnerLocation.getWorld() != null;
ServerLevel world = ((CraftWorld) this.spawnerLocation.getWorld()).getHandle();
RandomSource random = world.getRandom();
double x = spawnerLocation.getX() + (random.nextDouble() - random.nextDouble()) * (double) spawnRange + 0.5D;
double y = spawnerLocation.getY() + random.nextInt(3) - 1;
double z = spawnerLocation.getZ() + (random.nextDouble() - random.nextDouble()) * (double) spawnRange + 0.5D;
double x = this.spawnerLocation.getX() + (random.nextDouble() - random.nextDouble()) * (double) spawnRange + 0.5D;
double y = this.spawnerLocation.getY() + random.nextInt(3) - 1;
double z = this.spawnerLocation.getZ() + (random.nextDouble() - random.nextDouble()) * (double) spawnRange + 0.5D;
Optional<Entity> optionalEntity = net.minecraft.world.entity.EntityType.create(compound, world);
if (optionalEntity.isEmpty()) continue;
@ -67,7 +68,7 @@ public class SSpawnerImpl implements SSpawner {
continue;
}
Location spot = new Location(spawnerLocation.getWorld(), x, y, z);
Location spot = new Location(this.spawnerLocation.getWorld(), x, y, z);
if (!canSpawn(world, entityInsentient, spot, canSpawnOn)) {
continue;
@ -100,29 +101,29 @@ public class SSpawnerImpl implements SSpawner {
return null;
}
private boolean canSpawn(ServerLevel world, Mob entityInsentient, Location location, Set<CompatibleMaterial> canSpawnOn) {
private boolean canSpawn(ServerLevel world, Mob entityInsentient, Location location, Set<XMaterial> canSpawnOn) {
if (!world.noCollision(entityInsentient, entityInsentient.getBoundingBox())) {
return false;
}
CompatibleMaterial spawnedIn = CompatibleMaterial.getMaterial(location.getBlock());
CompatibleMaterial spawnedOn = CompatibleMaterial.getMaterial(location.getBlock().getRelative(BlockFace.DOWN));
Optional<XMaterial> spawnedIn = CompatibleMaterial.getMaterial(location.getBlock().getType());
Optional<XMaterial> spawnedOn = CompatibleMaterial.getMaterial(location.getBlock().getRelative(BlockFace.DOWN).getType());
if (spawnedIn == null || spawnedOn == null) {
if (spawnedIn.isEmpty() || spawnedOn.isEmpty()) {
return false;
}
if (!spawnedIn.isAir() &&
spawnedIn != CompatibleMaterial.WATER &&
!spawnedIn.name().contains("PRESSURE") &&
!spawnedIn.name().contains("SLAB")) {
if (!CompatibleMaterial.isAir(spawnedIn.get()) &&
spawnedIn.get() != XMaterial.WATER &&
!spawnedIn.get().name().contains("PRESSURE") &&
!spawnedIn.get().name().contains("SLAB")) {
return false;
}
for (CompatibleMaterial material : canSpawnOn) {
for (XMaterial material : canSpawnOn) {
if (material == null) continue;
if (spawnedOn.equals(material) || material.isAir()) {
if (spawnedOn.get() == material || CompatibleMaterial.isAir(material)) {
return true;
}
}

View File

@ -4,6 +4,7 @@ import com.craftaro.core.compatibility.CompatibleMaterial;
import com.craftaro.core.compatibility.CompatibleParticleHandler;
import com.craftaro.core.nms.world.SSpawner;
import com.craftaro.core.nms.world.SpawnedEntity;
import com.cryptomorin.xseries.XMaterial;
import net.minecraft.core.BlockPos;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.server.level.ServerLevel;
@ -36,7 +37,7 @@ public class SSpawnerImpl implements SSpawner {
}
@Override
public LivingEntity spawnEntity(EntityType type, String particleType, SpawnedEntity spawned, Set<CompatibleMaterial> canSpawnOn) {
public LivingEntity spawnEntity(EntityType type, String particleType, SpawnedEntity spawned, Set<XMaterial> canSpawnOn) {
SpawnData data = new SpawnData();
CompoundTag compound = data.getEntityToSpawn();
@ -45,14 +46,14 @@ public class SSpawnerImpl implements SSpawner {
compound.putString("id", "minecraft:" + name);
short spawnRange = 4;
for (int i = 0; i < 50; i++) {
assert spawnerLocation.getWorld() != null;
ServerLevel world = ((CraftWorld) spawnerLocation.getWorld()).getHandle();
for (int i = 0; i < 50; ++i) {
assert this.spawnerLocation.getWorld() != null;
ServerLevel world = ((CraftWorld) this.spawnerLocation.getWorld()).getHandle();
RandomSource random = world.getRandom();
double x = spawnerLocation.getX() + (random.nextDouble() - random.nextDouble()) * (double) spawnRange + 0.5D;
double y = spawnerLocation.getY() + random.nextInt(3) - 1;
double z = spawnerLocation.getZ() + (random.nextDouble() - random.nextDouble()) * (double) spawnRange + 0.5D;
double x = this.spawnerLocation.getX() + (random.nextDouble() - random.nextDouble()) * (double) spawnRange + 0.5D;
double y = this.spawnerLocation.getY() + random.nextInt(3) - 1;
double z = this.spawnerLocation.getZ() + (random.nextDouble() - random.nextDouble()) * (double) spawnRange + 0.5D;
Optional<Entity> optionalEntity = net.minecraft.world.entity.EntityType.create(compound, world);
if (optionalEntity.isEmpty()) continue;
@ -67,7 +68,7 @@ public class SSpawnerImpl implements SSpawner {
continue;
}
Location spot = new Location(spawnerLocation.getWorld(), x, y, z);
Location spot = new Location(this.spawnerLocation.getWorld(), x, y, z);
if (!canSpawn(world, entityInsentient, spot, canSpawnOn)) {
continue;
@ -100,29 +101,29 @@ public class SSpawnerImpl implements SSpawner {
return null;
}
private boolean canSpawn(ServerLevel world, Mob entityInsentient, Location location, Set<CompatibleMaterial> canSpawnOn) {
private boolean canSpawn(ServerLevel world, Mob entityInsentient, Location location, Set<XMaterial> canSpawnOn) {
if (!world.noCollision(entityInsentient, entityInsentient.getBoundingBox())) {
return false;
}
CompatibleMaterial spawnedIn = CompatibleMaterial.getMaterial(location.getBlock());
CompatibleMaterial spawnedOn = CompatibleMaterial.getMaterial(location.getBlock().getRelative(BlockFace.DOWN));
Optional<XMaterial> spawnedIn = CompatibleMaterial.getMaterial(location.getBlock().getType());
Optional<XMaterial> spawnedOn = CompatibleMaterial.getMaterial(location.getBlock().getRelative(BlockFace.DOWN).getType());
if (spawnedIn == null || spawnedOn == null) {
if (spawnedIn.isEmpty() || spawnedOn.isEmpty()) {
return false;
}
if (!spawnedIn.isAir() &&
spawnedIn != CompatibleMaterial.WATER &&
!spawnedIn.name().contains("PRESSURE") &&
!spawnedIn.name().contains("SLAB")) {
if (!CompatibleMaterial.isAir(spawnedIn.get()) &&
spawnedIn.get() != XMaterial.WATER &&
!spawnedIn.get().name().contains("PRESSURE") &&
!spawnedIn.get().name().contains("SLAB")) {
return false;
}
for (CompatibleMaterial material : canSpawnOn) {
for (XMaterial material : canSpawnOn) {
if (material == null) continue;
if (spawnedOn.equals(material) || material.isAir()) {
if (spawnedOn.get() == material || CompatibleMaterial.isAir(material)) {
return true;
}
}

View File

@ -4,6 +4,7 @@ import com.craftaro.core.compatibility.CompatibleMaterial;
import com.craftaro.core.compatibility.CompatibleParticleHandler;
import com.craftaro.core.nms.world.SSpawner;
import com.craftaro.core.nms.world.SpawnedEntity;
import com.cryptomorin.xseries.XMaterial;
import net.minecraft.core.BlockPos;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.server.level.ServerLevel;
@ -36,7 +37,7 @@ public class SSpawnerImpl implements SSpawner {
}
@Override
public LivingEntity spawnEntity(EntityType type, String particleType, SpawnedEntity spawned, Set<CompatibleMaterial> canSpawnOn) {
public LivingEntity spawnEntity(EntityType type, String particleType, SpawnedEntity spawned, Set<XMaterial> canSpawnOn) {
SpawnData data = new SpawnData();
CompoundTag compound = data.getEntityToSpawn();
@ -45,14 +46,14 @@ public class SSpawnerImpl implements SSpawner {
compound.putString("id", "minecraft:" + name);
short spawnRange = 4;
for (int i = 0; i < 50; i++) {
assert spawnerLocation.getWorld() != null;
ServerLevel world = ((CraftWorld) spawnerLocation.getWorld()).getHandle();
for (int i = 0; i < 50; ++i) {
assert this.spawnerLocation.getWorld() != null;
ServerLevel world = ((CraftWorld) this.spawnerLocation.getWorld()).getHandle();
RandomSource random = world.getRandom();
double x = spawnerLocation.getX() + (random.nextDouble() - random.nextDouble()) * (double) spawnRange + 0.5D;
double y = spawnerLocation.getY() + random.nextInt(3) - 1;
double z = spawnerLocation.getZ() + (random.nextDouble() - random.nextDouble()) * (double) spawnRange + 0.5D;
double x = this.spawnerLocation.getX() + (random.nextDouble() - random.nextDouble()) * (double) spawnRange + 0.5D;
double y = this.spawnerLocation.getY() + random.nextInt(3) - 1;
double z = this.spawnerLocation.getZ() + (random.nextDouble() - random.nextDouble()) * (double) spawnRange + 0.5D;
Optional<Entity> optionalEntity = net.minecraft.world.entity.EntityType.create(compound, world);
if (optionalEntity.isEmpty()) continue;
@ -67,7 +68,7 @@ public class SSpawnerImpl implements SSpawner {
continue;
}
Location spot = new Location(spawnerLocation.getWorld(), x, y, z);
Location spot = new Location(this.spawnerLocation.getWorld(), x, y, z);
if (!canSpawn(world, entityInsentient, spot, canSpawnOn)) {
continue;
@ -100,29 +101,29 @@ public class SSpawnerImpl implements SSpawner {
return null;
}
private boolean canSpawn(ServerLevel world, Mob entityInsentient, Location location, Set<CompatibleMaterial> canSpawnOn) {
private boolean canSpawn(ServerLevel world, Mob entityInsentient, Location location, Set<XMaterial> canSpawnOn) {
if (!world.noCollision(entityInsentient, entityInsentient.getBoundingBox())) {
return false;
}
CompatibleMaterial spawnedIn = CompatibleMaterial.getMaterial(location.getBlock());
CompatibleMaterial spawnedOn = CompatibleMaterial.getMaterial(location.getBlock().getRelative(BlockFace.DOWN));
Optional<XMaterial> spawnedIn = CompatibleMaterial.getMaterial(location.getBlock().getType());
Optional<XMaterial> spawnedOn = CompatibleMaterial.getMaterial(location.getBlock().getRelative(BlockFace.DOWN).getType());
if (spawnedIn == null || spawnedOn == null) {
if (spawnedIn.isEmpty() || spawnedOn.isEmpty()) {
return false;
}
if (!spawnedIn.isAir() &&
spawnedIn != CompatibleMaterial.WATER &&
!spawnedIn.name().contains("PRESSURE") &&
!spawnedIn.name().contains("SLAB")) {
if (!CompatibleMaterial.isAir(spawnedIn.get()) &&
spawnedIn.get() != XMaterial.WATER &&
!spawnedIn.get().name().contains("PRESSURE") &&
!spawnedIn.get().name().contains("SLAB")) {
return false;
}
for (CompatibleMaterial material : canSpawnOn) {
for (XMaterial material : canSpawnOn) {
if (material == null) continue;
if (spawnedOn.equals(material) || material.isAir()) {
if (spawnedOn.get() == material || CompatibleMaterial.isAir(material)) {
return true;
}
}

View File

@ -4,6 +4,7 @@ import com.craftaro.core.compatibility.CompatibleMaterial;
import com.craftaro.core.compatibility.CompatibleParticleHandler;
import com.craftaro.core.nms.world.SSpawner;
import com.craftaro.core.nms.world.SpawnedEntity;
import com.cryptomorin.xseries.XMaterial;
import net.minecraft.core.BlockPos;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.server.level.ServerLevel;
@ -36,7 +37,7 @@ public class SSpawnerImpl implements SSpawner {
}
@Override
public LivingEntity spawnEntity(EntityType type, String particleType, SpawnedEntity spawned, Set<CompatibleMaterial> canSpawnOn) {
public LivingEntity spawnEntity(EntityType type, String particleType, SpawnedEntity spawned, Set<XMaterial> canSpawnOn) {
SpawnData data = new SpawnData();
CompoundTag compound = data.getEntityToSpawn();
@ -45,7 +46,7 @@ public class SSpawnerImpl implements SSpawner {
compound.putString("id", "minecraft:" + name);
short spawnRange = 4;
for (int i = 0; i < 50; i++) {
for (int i = 0; i < 50; ++i) {
assert this.spawnerLocation.getWorld() != null;
ServerLevel world = ((CraftWorld) this.spawnerLocation.getWorld()).getHandle();
@ -100,29 +101,29 @@ public class SSpawnerImpl implements SSpawner {
return null;
}
private boolean canSpawn(ServerLevel world, Mob entityInsentient, Location location, Set<CompatibleMaterial> canSpawnOn) {
private boolean canSpawn(ServerLevel world, Mob entityInsentient, Location location, Set<XMaterial> canSpawnOn) {
if (!world.noCollision(entityInsentient, entityInsentient.getBoundingBox())) {
return false;
}
CompatibleMaterial spawnedIn = CompatibleMaterial.getMaterial(location.getBlock());
CompatibleMaterial spawnedOn = CompatibleMaterial.getMaterial(location.getBlock().getRelative(BlockFace.DOWN));
Optional<XMaterial> spawnedIn = CompatibleMaterial.getMaterial(location.getBlock().getType());
Optional<XMaterial> spawnedOn = CompatibleMaterial.getMaterial(location.getBlock().getRelative(BlockFace.DOWN).getType());
if (spawnedIn == null || spawnedOn == null) {
if (spawnedIn.isEmpty() || spawnedOn.isEmpty()) {
return false;
}
if (!spawnedIn.isAir() &&
spawnedIn != CompatibleMaterial.WATER &&
!spawnedIn.name().contains("PRESSURE") &&
!spawnedIn.name().contains("SLAB")) {
if (!CompatibleMaterial.isAir(spawnedIn.get()) &&
spawnedIn.get() != XMaterial.WATER &&
!spawnedIn.get().name().contains("PRESSURE") &&
!spawnedIn.get().name().contains("SLAB")) {
return false;
}
for (CompatibleMaterial material : canSpawnOn) {
for (XMaterial material : canSpawnOn) {
if (material == null) continue;
if (spawnedOn == material || material.isAir()) {
if (spawnedOn.get() == material || CompatibleMaterial.isAir(material)) {
return true;
}
}

View File

@ -4,6 +4,7 @@ import com.craftaro.core.compatibility.CompatibleMaterial;
import com.craftaro.core.compatibility.CompatibleParticleHandler;
import com.craftaro.core.nms.world.SSpawner;
import com.craftaro.core.nms.world.SpawnedEntity;
import com.cryptomorin.xseries.XMaterial;
import net.minecraft.core.BlockPos;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.server.level.ServerLevel;
@ -36,16 +37,19 @@ public class SSpawnerImpl implements SSpawner {
}
@Override
public LivingEntity spawnEntity(EntityType type, String particleType, SpawnedEntity spawned, Set<CompatibleMaterial> canSpawnOn) {
public LivingEntity spawnEntity(EntityType type, String particleType, SpawnedEntity spawned, Set<XMaterial> canSpawnOn) {
SpawnData data = new SpawnData();
CompoundTag compound = data.getEntityToSpawn();
String name = type.name().toLowerCase().replace("snowman", "snow_golem")
String name = type
.name()
.toLowerCase()
.replace("snowman", "snow_golem")
.replace("mushroom_cow", "mooshroom");
compound.putString("id", "minecraft:" + name);
short spawnRange = 4;
for (int i = 0; i < 50; i++) {
for (int i = 0; i < 50; ++i) {
assert this.spawnerLocation.getWorld() != null;
ServerLevel world = ((CraftWorld) this.spawnerLocation.getWorld()).getHandle();
@ -100,29 +104,29 @@ public class SSpawnerImpl implements SSpawner {
return null;
}
private boolean canSpawn(ServerLevel world, Mob entityInsentient, Location location, Set<CompatibleMaterial> canSpawnOn) {
private boolean canSpawn(ServerLevel world, Mob entityInsentient, Location location, Set<XMaterial> canSpawnOn) {
if (!world.noCollision(entityInsentient, entityInsentient.getBoundingBox())) {
return false;
}
CompatibleMaterial spawnedIn = CompatibleMaterial.getMaterial(location.getBlock());
CompatibleMaterial spawnedOn = CompatibleMaterial.getMaterial(location.getBlock().getRelative(BlockFace.DOWN));
Optional<XMaterial> spawnedIn = CompatibleMaterial.getMaterial(location.getBlock().getType());
Optional<XMaterial> spawnedOn = CompatibleMaterial.getMaterial(location.getBlock().getRelative(BlockFace.DOWN).getType());
if (spawnedIn == null || spawnedOn == null) {
if (spawnedIn.isEmpty() || spawnedOn.isEmpty()) {
return false;
}
if (!spawnedIn.isAir() &&
spawnedIn != CompatibleMaterial.WATER &&
!spawnedIn.name().contains("PRESSURE") &&
!spawnedIn.name().contains("SLAB")) {
if (!CompatibleMaterial.isAir(spawnedIn.get()) &&
spawnedIn.get() != XMaterial.WATER &&
!spawnedIn.get().name().contains("PRESSURE") &&
!spawnedIn.get().name().contains("SLAB")) {
return false;
}
for (CompatibleMaterial material : canSpawnOn) {
for (XMaterial material : canSpawnOn) {
if (material == null) continue;
if (spawnedOn == material || material.isAir()) {
if (spawnedOn.get() == material || CompatibleMaterial.isAir(material)) {
return true;
}
}

View File

@ -4,6 +4,7 @@ import com.craftaro.core.compatibility.CompatibleMaterial;
import com.craftaro.core.compatibility.CompatibleParticleHandler;
import com.craftaro.core.nms.world.SSpawner;
import com.craftaro.core.nms.world.SpawnedEntity;
import com.cryptomorin.xseries.XMaterial;
import net.minecraft.server.v1_8_R1.BlockPosition;
import net.minecraft.server.v1_8_R1.DifficultyDamageScaler;
import net.minecraft.server.v1_8_R1.Entity;
@ -17,6 +18,7 @@ import org.bukkit.entity.EntityType;
import org.bukkit.entity.LivingEntity;
import org.bukkit.event.entity.CreatureSpawnEvent;
import java.util.Optional;
import java.util.Random;
import java.util.Set;
@ -33,16 +35,15 @@ public class SSpawnerImpl implements SSpawner {
}
@Override
public LivingEntity spawnEntity(EntityType type, String particleType, SpawnedEntity spawned,
Set<CompatibleMaterial> canSpawnOn) {
public LivingEntity spawnEntity(EntityType type, String particleType, SpawnedEntity spawned, Set<XMaterial> canSpawnOn) {
short spawnRange = 4;
for (int i = 0; i < 50; i++) {
WorldServer world = ((CraftWorld) spawnerLocation.getWorld()).getHandle();
for (int i = 0; i < 50; ++i) {
WorldServer world = ((CraftWorld) this.spawnerLocation.getWorld()).getHandle();
Random random = world.random;
double x = spawnerLocation.getX() + (random.nextDouble() - random.nextDouble()) * (double) spawnRange + 0.5D;
double y = spawnerLocation.getY() + random.nextInt(3) - 1;
double z = spawnerLocation.getZ() + (random.nextDouble() - random.nextDouble()) * (double) spawnRange + 0.5D;
double x = this.spawnerLocation.getX() + (random.nextDouble() - random.nextDouble()) * (double) spawnRange + 0.5D;
double y = this.spawnerLocation.getY() + random.nextInt(3) - 1;
double z = this.spawnerLocation.getZ() + (random.nextDouble() - random.nextDouble()) * (double) spawnRange + 0.5D;
Entity entity = EntityTypes.createEntityByName(translateName(type, true), world);
entity.setPositionRotation(x, y, z, 360.0F, 0.0F);
@ -56,7 +57,7 @@ public class SSpawnerImpl implements SSpawner {
EntityInsentient entityInsentient = (EntityInsentient) entity;
Location spot = new Location(spawnerLocation.getWorld(), x, y, z);
Location spot = new Location(this.spawnerLocation.getWorld(), x, y, z);
if (!canSpawn(entityInsentient, spot, canSpawnOn)) {
continue;
}
@ -89,29 +90,29 @@ public class SSpawnerImpl implements SSpawner {
return null;
}
private boolean canSpawn(EntityInsentient entityInsentient, Location location, Set<CompatibleMaterial> canSpawnOn) {
private boolean canSpawn(EntityInsentient entityInsentient, Location location, Set<XMaterial> canSpawnOn) {
if (!entityInsentient.canSpawn()) {
return false;
}
CompatibleMaterial spawnedIn = CompatibleMaterial.getMaterial(location.getBlock());
CompatibleMaterial spawnedOn = CompatibleMaterial.getMaterial(location.getBlock().getRelative(BlockFace.DOWN));
Optional<XMaterial> spawnedIn = CompatibleMaterial.getMaterial(location.getBlock().getType());
Optional<XMaterial> spawnedOn = CompatibleMaterial.getMaterial(location.getBlock().getRelative(BlockFace.DOWN).getType());
if (spawnedIn == null || spawnedOn == null) {
if (!spawnedIn.isPresent() || !spawnedOn.isPresent()) {
return false;
}
if (!spawnedIn.isAir() &&
spawnedIn != CompatibleMaterial.WATER &&
!spawnedIn.name().contains("PRESSURE") &&
!spawnedIn.name().contains("SLAB")) {
if (!CompatibleMaterial.isAir(spawnedIn.get()) &&
spawnedIn.get() != XMaterial.WATER &&
!spawnedIn.get().name().contains("PRESSURE") &&
!spawnedIn.get().name().contains("SLAB")) {
return false;
}
for (CompatibleMaterial material : canSpawnOn) {
for (XMaterial material : canSpawnOn) {
if (material == null) continue;
if (spawnedOn.equals(material) || material.isAir()) {
if (spawnedOn.get() == material || CompatibleMaterial.isAir(material)) {
return true;
}
}

View File

@ -4,6 +4,7 @@ import com.craftaro.core.compatibility.CompatibleMaterial;
import com.craftaro.core.compatibility.CompatibleParticleHandler;
import com.craftaro.core.nms.world.SSpawner;
import com.craftaro.core.nms.world.SpawnedEntity;
import com.cryptomorin.xseries.XMaterial;
import net.minecraft.server.v1_8_R2.BlockPosition;
import net.minecraft.server.v1_8_R2.DifficultyDamageScaler;
import net.minecraft.server.v1_8_R2.Entity;
@ -17,6 +18,7 @@ import org.bukkit.entity.EntityType;
import org.bukkit.entity.LivingEntity;
import org.bukkit.event.entity.CreatureSpawnEvent;
import java.util.Optional;
import java.util.Random;
import java.util.Set;
@ -33,16 +35,15 @@ public class SSpawnerImpl implements SSpawner {
}
@Override
public LivingEntity spawnEntity(EntityType type, String particleType, SpawnedEntity spawned,
Set<CompatibleMaterial> canSpawnOn) {
public LivingEntity spawnEntity(EntityType type, String particleType, SpawnedEntity spawned, Set<XMaterial> canSpawnOn) {
short spawnRange = 4;
for (int i = 0; i < 50; i++) {
WorldServer world = ((CraftWorld) spawnerLocation.getWorld()).getHandle();
for (int i = 0; i < 50; ++i) {
WorldServer world = ((CraftWorld) this.spawnerLocation.getWorld()).getHandle();
Random random = world.random;
double x = spawnerLocation.getX() + (random.nextDouble() - random.nextDouble()) * (double) spawnRange + 0.5D;
double y = spawnerLocation.getY() + random.nextInt(3) - 1;
double z = spawnerLocation.getZ() + (random.nextDouble() - random.nextDouble()) * (double) spawnRange + 0.5D;
double x = this.spawnerLocation.getX() + (random.nextDouble() - random.nextDouble()) * (double) spawnRange + 0.5D;
double y = this.spawnerLocation.getY() + random.nextInt(3) - 1;
double z = this.spawnerLocation.getZ() + (random.nextDouble() - random.nextDouble()) * (double) spawnRange + 0.5D;
Entity entity = EntityTypes.createEntityByName(translateName(type, true), world);
entity.setPositionRotation(x, y, z, 360.0F, 0.0F);
@ -56,7 +57,7 @@ public class SSpawnerImpl implements SSpawner {
EntityInsentient entityInsentient = (EntityInsentient) entity;
Location spot = new Location(spawnerLocation.getWorld(), x, y, z);
Location spot = new Location(this.spawnerLocation.getWorld(), x, y, z);
if (!canSpawn(entityInsentient, spot, canSpawnOn)) {
continue;
}
@ -89,29 +90,29 @@ public class SSpawnerImpl implements SSpawner {
return null;
}
private boolean canSpawn(EntityInsentient entityInsentient, Location location, Set<CompatibleMaterial> canSpawnOn) {
private boolean canSpawn(EntityInsentient entityInsentient, Location location, Set<XMaterial> canSpawnOn) {
if (!entityInsentient.canSpawn()) {
return false;
}
CompatibleMaterial spawnedIn = CompatibleMaterial.getMaterial(location.getBlock());
CompatibleMaterial spawnedOn = CompatibleMaterial.getMaterial(location.getBlock().getRelative(BlockFace.DOWN));
Optional<XMaterial> spawnedIn = CompatibleMaterial.getMaterial(location.getBlock().getType());
Optional<XMaterial> spawnedOn = CompatibleMaterial.getMaterial(location.getBlock().getRelative(BlockFace.DOWN).getType());
if (spawnedIn == null || spawnedOn == null) {
if (!spawnedIn.isPresent() || !spawnedOn.isPresent()) {
return false;
}
if (!spawnedIn.isAir() &&
spawnedIn != CompatibleMaterial.WATER &&
!spawnedIn.name().contains("PRESSURE") &&
!spawnedIn.name().contains("SLAB")) {
if (!CompatibleMaterial.isAir(spawnedIn.get()) &&
spawnedIn.get() != XMaterial.WATER &&
!spawnedIn.get().name().contains("PRESSURE") &&
!spawnedIn.get().name().contains("SLAB")) {
return false;
}
for (CompatibleMaterial material : canSpawnOn) {
for (XMaterial material : canSpawnOn) {
if (material == null) continue;
if (spawnedOn.equals(material) || material.isAir()) {
if (spawnedOn.get() == material || CompatibleMaterial.isAir(material)) {
return true;
}
}

View File

@ -4,6 +4,7 @@ import com.craftaro.core.compatibility.CompatibleMaterial;
import com.craftaro.core.compatibility.CompatibleParticleHandler;
import com.craftaro.core.nms.world.SSpawner;
import com.craftaro.core.nms.world.SpawnedEntity;
import com.cryptomorin.xseries.XMaterial;
import net.minecraft.server.v1_8_R3.BlockPosition;
import net.minecraft.server.v1_8_R3.DifficultyDamageScaler;
import net.minecraft.server.v1_8_R3.Entity;
@ -17,6 +18,7 @@ import org.bukkit.entity.EntityType;
import org.bukkit.entity.LivingEntity;
import org.bukkit.event.entity.CreatureSpawnEvent;
import java.util.Optional;
import java.util.Random;
import java.util.Set;
@ -33,16 +35,15 @@ public class SSpawnerImpl implements SSpawner {
}
@Override
public LivingEntity spawnEntity(EntityType type, String particleType, SpawnedEntity spawned,
Set<CompatibleMaterial> canSpawnOn) {
public LivingEntity spawnEntity(EntityType type, String particleType, SpawnedEntity spawned, Set<XMaterial> canSpawnOn) {
short spawnRange = 4;
for (int i = 0; i < 50; i++) {
WorldServer world = ((CraftWorld) spawnerLocation.getWorld()).getHandle();
for (int i = 0; i < 50; ++i) {
WorldServer world = ((CraftWorld) this.spawnerLocation.getWorld()).getHandle();
Random random = world.random;
double x = spawnerLocation.getX() + (random.nextDouble() - random.nextDouble()) * (double) spawnRange + 0.5D;
double y = spawnerLocation.getY() + random.nextInt(3) - 1;
double z = spawnerLocation.getZ() + (random.nextDouble() - random.nextDouble()) * (double) spawnRange + 0.5D;
double x = this.spawnerLocation.getX() + (random.nextDouble() - random.nextDouble()) * (double) spawnRange + 0.5D;
double y = this.spawnerLocation.getY() + random.nextInt(3) - 1;
double z = this.spawnerLocation.getZ() + (random.nextDouble() - random.nextDouble()) * (double) spawnRange + 0.5D;
Entity entity = EntityTypes.createEntityByName(translateName(type, true), world);
entity.setPositionRotation(x, y, z, 360.0F, 0.0F);
@ -56,7 +57,7 @@ public class SSpawnerImpl implements SSpawner {
EntityInsentient entityInsentient = (EntityInsentient) entity;
Location spot = new Location(spawnerLocation.getWorld(), x, y, z);
Location spot = new Location(this.spawnerLocation.getWorld(), x, y, z);
if (!canSpawn(entityInsentient, spot, canSpawnOn))
continue;
@ -88,29 +89,29 @@ public class SSpawnerImpl implements SSpawner {
return null;
}
private boolean canSpawn(EntityInsentient entityInsentient, Location location, Set<CompatibleMaterial> canSpawnOn) {
private boolean canSpawn(EntityInsentient entityInsentient, Location location, Set<XMaterial> canSpawnOn) {
if (!entityInsentient.canSpawn()) {
return false;
}
CompatibleMaterial spawnedIn = CompatibleMaterial.getMaterial(location.getBlock());
CompatibleMaterial spawnedOn = CompatibleMaterial.getMaterial(location.getBlock().getRelative(BlockFace.DOWN));
Optional<XMaterial> spawnedIn = CompatibleMaterial.getMaterial(location.getBlock().getType());
Optional<XMaterial> spawnedOn = CompatibleMaterial.getMaterial(location.getBlock().getRelative(BlockFace.DOWN).getType());
if (spawnedIn == null || spawnedOn == null) {
if (!spawnedIn.isPresent() || !spawnedOn.isPresent()) {
return false;
}
if (!spawnedIn.isAir() &&
spawnedIn != CompatibleMaterial.WATER &&
!spawnedIn.name().contains("PRESSURE") &&
!spawnedIn.name().contains("SLAB")) {
if (!CompatibleMaterial.isAir(spawnedIn.get()) &&
spawnedIn.get() != XMaterial.WATER &&
!spawnedIn.get().name().contains("PRESSURE") &&
!spawnedIn.get().name().contains("SLAB")) {
return false;
}
for (CompatibleMaterial material : canSpawnOn) {
for (XMaterial material : canSpawnOn) {
if (material == null) continue;
if (spawnedOn.equals(material) || material.isAir()) {
if (spawnedOn.get() == material || CompatibleMaterial.isAir(material)) {
return true;
}
}

View File

@ -4,6 +4,7 @@ import com.craftaro.core.compatibility.CompatibleMaterial;
import com.craftaro.core.compatibility.CompatibleParticleHandler;
import com.craftaro.core.nms.world.SSpawner;
import com.craftaro.core.nms.world.SpawnedEntity;
import com.cryptomorin.xseries.XMaterial;
import net.minecraft.server.v1_9_R1.BlockPosition;
import net.minecraft.server.v1_9_R1.ChunkRegionLoader;
import net.minecraft.server.v1_9_R1.DifficultyDamageScaler;
@ -19,6 +20,7 @@ import org.bukkit.entity.EntityType;
import org.bukkit.entity.LivingEntity;
import org.bukkit.event.entity.CreatureSpawnEvent;
import java.util.Optional;
import java.util.Random;
import java.util.Set;
@ -35,21 +37,20 @@ public class SSpawnerImpl implements SSpawner {
}
@Override
public LivingEntity spawnEntity(EntityType type, String particleType, SpawnedEntity spawned,
Set<CompatibleMaterial> canSpawnOn) {
public LivingEntity spawnEntity(EntityType type, String particleType, SpawnedEntity spawned, Set<XMaterial> canSpawnOn) {
MobSpawnerData data = new MobSpawnerData();
NBTTagCompound compound = data.b();
compound.setString("id", translateName(type, true));
short spawnRange = 4;
for (int i = 0; i < 50; i++) {
WorldServer world = ((CraftWorld) spawnerLocation.getWorld()).getHandle();
for (int i = 0; i < 50; ++i) {
WorldServer world = ((CraftWorld) this.spawnerLocation.getWorld()).getHandle();
Random random = world.random;
double x = spawnerLocation.getX() + (random.nextDouble() - random.nextDouble()) * (double) spawnRange + 0.5D;
double y = spawnerLocation.getY() + random.nextInt(3) - 1;
double z = spawnerLocation.getZ() + (random.nextDouble() - random.nextDouble()) * (double) spawnRange + 0.5D;
double x = this.spawnerLocation.getX() + (random.nextDouble() - random.nextDouble()) * (double) spawnRange + 0.5D;
double y = this.spawnerLocation.getY() + random.nextInt(3) - 1;
double z = this.spawnerLocation.getZ() + (random.nextDouble() - random.nextDouble()) * (double) spawnRange + 0.5D;
Entity entity = ChunkRegionLoader.a(compound, world, x, y, z, false);
@ -62,7 +63,7 @@ public class SSpawnerImpl implements SSpawner {
EntityInsentient entityInsentient = (EntityInsentient) entity;
Location spot = new Location(spawnerLocation.getWorld(), x, y, z);
Location spot = new Location(this.spawnerLocation.getWorld(), x, y, z);
if (!canSpawn(entityInsentient, spot, canSpawnOn)) {
continue;
}
@ -94,29 +95,29 @@ public class SSpawnerImpl implements SSpawner {
return null;
}
private boolean canSpawn(EntityInsentient entityInsentient, Location location, Set<CompatibleMaterial> canSpawnOn) {
private boolean canSpawn(EntityInsentient entityInsentient, Location location, Set<XMaterial> canSpawnOn) {
if (!entityInsentient.canSpawn()) {
return false;
}
CompatibleMaterial spawnedIn = CompatibleMaterial.getMaterial(location.getBlock());
CompatibleMaterial spawnedOn = CompatibleMaterial.getMaterial(location.getBlock().getRelative(BlockFace.DOWN));
Optional<XMaterial> spawnedIn = CompatibleMaterial.getMaterial(location.getBlock().getType());
Optional<XMaterial> spawnedOn = CompatibleMaterial.getMaterial(location.getBlock().getRelative(BlockFace.DOWN).getType());
if (spawnedIn == null || spawnedOn == null) {
if (!spawnedIn.isPresent() || !spawnedOn.isPresent()) {
return false;
}
if (!spawnedIn.isAir() &&
spawnedIn != CompatibleMaterial.WATER &&
!spawnedIn.name().contains("PRESSURE") &&
!spawnedIn.name().contains("SLAB")) {
if (!CompatibleMaterial.isAir(spawnedIn.get()) &&
spawnedIn.get() != XMaterial.WATER &&
!spawnedIn.get().name().contains("PRESSURE") &&
!spawnedIn.get().name().contains("SLAB")) {
return false;
}
for (CompatibleMaterial material : canSpawnOn) {
for (XMaterial material : canSpawnOn) {
if (material == null) continue;
if (spawnedOn.equals(material) || material.isAir()) {
if (spawnedOn.get() == material || CompatibleMaterial.isAir(material)) {
return true;
}
}

View File

@ -4,6 +4,7 @@ import com.craftaro.core.compatibility.CompatibleMaterial;
import com.craftaro.core.compatibility.CompatibleParticleHandler;
import com.craftaro.core.nms.world.SSpawner;
import com.craftaro.core.nms.world.SpawnedEntity;
import com.cryptomorin.xseries.XMaterial;
import net.minecraft.server.v1_9_R2.BlockPosition;
import net.minecraft.server.v1_9_R2.ChunkRegionLoader;
import net.minecraft.server.v1_9_R2.DifficultyDamageScaler;
@ -19,6 +20,7 @@ import org.bukkit.entity.EntityType;
import org.bukkit.entity.LivingEntity;
import org.bukkit.event.entity.CreatureSpawnEvent;
import java.util.Optional;
import java.util.Random;
import java.util.Set;
@ -35,21 +37,20 @@ public class SSpawnerImpl implements SSpawner {
}
@Override
public LivingEntity spawnEntity(EntityType type, String particleType, SpawnedEntity spawned,
Set<CompatibleMaterial> canSpawnOn) {
public LivingEntity spawnEntity(EntityType type, String particleType, SpawnedEntity spawned, Set<XMaterial> canSpawnOn) {
MobSpawnerData data = new MobSpawnerData();
NBTTagCompound compound = data.b();
compound.setString("id", translateName(type, true));
short spawnRange = 4;
for (int i = 0; i < 50; i++) {
WorldServer world = ((CraftWorld) spawnerLocation.getWorld()).getHandle();
for (int i = 0; i < 50; ++i) {
WorldServer world = ((CraftWorld) this.spawnerLocation.getWorld()).getHandle();
Random random = world.random;
double x = spawnerLocation.getX() + (random.nextDouble() - random.nextDouble()) * (double) spawnRange + 0.5D;
double y = spawnerLocation.getY() + random.nextInt(3) - 1;
double z = spawnerLocation.getZ() + (random.nextDouble() - random.nextDouble()) * (double) spawnRange + 0.5D;
double x = this.spawnerLocation.getX() + (random.nextDouble() - random.nextDouble()) * (double) spawnRange + 0.5D;
double y = this.spawnerLocation.getY() + random.nextInt(3) - 1;
double z = this.spawnerLocation.getZ() + (random.nextDouble() - random.nextDouble()) * (double) spawnRange + 0.5D;
Entity entity = ChunkRegionLoader.a(compound, world, x, y, z, false);
@ -63,7 +64,7 @@ public class SSpawnerImpl implements SSpawner {
EntityInsentient entityInsentient = (EntityInsentient) entity;
Location spot = new Location(spawnerLocation.getWorld(), x, y, z);
Location spot = new Location(this.spawnerLocation.getWorld(), x, y, z);
if (!canSpawn(entityInsentient, spot, canSpawnOn)) {
continue;
}
@ -96,29 +97,29 @@ public class SSpawnerImpl implements SSpawner {
return null;
}
private boolean canSpawn(EntityInsentient entityInsentient, Location location, Set<CompatibleMaterial> canSpawnOn) {
private boolean canSpawn(EntityInsentient entityInsentient, Location location, Set<XMaterial> canSpawnOn) {
if (!entityInsentient.canSpawn()) {
return false;
}
CompatibleMaterial spawnedIn = CompatibleMaterial.getMaterial(location.getBlock());
CompatibleMaterial spawnedOn = CompatibleMaterial.getMaterial(location.getBlock().getRelative(BlockFace.DOWN));
Optional<XMaterial> spawnedIn = CompatibleMaterial.getMaterial(location.getBlock().getType());
Optional<XMaterial> spawnedOn = CompatibleMaterial.getMaterial(location.getBlock().getRelative(BlockFace.DOWN).getType());
if (spawnedIn == null || spawnedOn == null) {
if (!spawnedIn.isPresent() || !spawnedOn.isPresent()) {
return false;
}
if (!spawnedIn.isAir() &&
spawnedIn != CompatibleMaterial.WATER &&
!spawnedIn.name().contains("PRESSURE") &&
!spawnedIn.name().contains("SLAB")) {
if (!CompatibleMaterial.isAir(spawnedIn.get()) &&
spawnedIn.get() != XMaterial.WATER &&
!spawnedIn.get().name().contains("PRESSURE") &&
!spawnedIn.get().name().contains("SLAB")) {
return false;
}
for (CompatibleMaterial material : canSpawnOn) {
for (XMaterial material : canSpawnOn) {
if (material == null) continue;
if (spawnedOn.equals(material) || material.isAir()) {
if (spawnedOn.get() == material || CompatibleMaterial.isAir(material)) {
return true;
}
}