Merge branch 'development' into feature/new-improved-database-system

# Conflicts:
#	Core/pom.xml
#	Core/src/main/java/com/craftaro/core/SongodaPlugin.java
This commit is contained in:
ceze88 2023-06-28 11:58:09 +02:00
commit 5d9cab5613
143 changed files with 2733 additions and 4533 deletions

View File

@ -19,5 +19,5 @@ runs:
- uses: SpraxDev/Action-SpigotMC@v4
with:
versions: 1.18.1, 1.18.2, 1.19, 1.19.2, 1.19.3, 1.19.4, 1.20
versions: 1.18.1, 1.18.2, 1.19, 1.19.2, 1.19.3, 1.19.4, 1.20.1
remapped: true

View File

@ -45,6 +45,7 @@ jobs:
append_snapshot: ${{ github.ref_type == 'tag' && 'false' || 'true' }}
version: ${{ github.ref_type == 'tag' && github.ref_name || '' }}
increment_version: ${{ github.ref_type == 'tag' && '' || 'patch' }}
increment_version_only_if_not_snapshot_version: ${{ github.ref == 'refs/heads/development' && 'true' || 'false' }}
- name: Build with Maven
run: mvn -B -Duser.name="GitHub Actions on $GITHUB_REPOSITORY (id=$GITHUB_RUN_ID)" -DskipTests clean package

View File

@ -12,6 +12,13 @@
</parent>
<artifactId>CraftaroCore-Compatibility</artifactId>
<repositories>
<repository>
<id>ViaVersion</id>
<url>https://repo.viaversion.com/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>org.spigotmc</groupId>
@ -23,7 +30,7 @@
<dependency>
<groupId>com.viaversion</groupId>
<artifactId>viaversion-api</artifactId>
<version>4.0.1</version>
<version>4.7.0</version>
<scope>provided</scope>
</dependency>
@ -33,5 +40,12 @@
<version>4.29</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.github.cryptomorin</groupId>
<artifactId>XSeries</artifactId>
<version>9.4.0</version>
<scope>compile</scope>
</dependency>
</dependencies>
</project>

View File

@ -58,8 +58,8 @@ public enum ClassMapping {
private final String packageName;
private final String className;
ClassMapping(String packageName) {
this(null, packageName);
ClassMapping(String className) {
this(null, className);
}
ClassMapping(String packageName, String className) {
@ -72,17 +72,17 @@ public enum ClassMapping {
}
public Class<?> getClazz(String sub) {
String name = sub == null ? className : className + "$" + sub;
String name = sub == null ? this.className : this.className + "$" + sub;
try {
if (className.startsWith("Craft")) {
if (this.className.startsWith("Craft")) {
return Class.forName("org.bukkit.craftbukkit." + ServerVersion.getServerVersionString()
+ (packageName == null ? "" : "." + packageName) + "." + name);
+ (this.packageName == null ? "" : "." + this.packageName) + "." + name);
}
return Class.forName("net.minecraft." + (
ServerVersion.isServerVersionAtLeast(ServerVersion.V1_17) && packageName != null
? packageName : "server." + ServerVersion.getServerVersionString()) + "." + name);
ServerVersion.isServerVersionAtLeast(ServerVersion.V1_17) && this.packageName != null
? this.packageName : "server." + ServerVersion.getServerVersionString()) + "." + name);
} catch (ClassNotFoundException ex) {
ex.printStackTrace();
}

View File

@ -13,7 +13,7 @@ import java.util.UUID;
* NOTE: this is automatically initialized through SongodaCore
*/
public class ClientVersion {
static HashMap<UUID, ServerVersion> players = new HashMap<>();
private static final HashMap<UUID, ServerVersion> players = new HashMap<>();
/**
* Check to see what client version this player is connected to the server
@ -103,9 +103,19 @@ public class ClientVersion {
case 755:
case 756:
return ServerVersion.V1_17;
case 757:
case 758:
return ServerVersion.V1_18;
case 759:
case 760:
case 761:
case 762:
return ServerVersion.V1_19;
case 763:
return ServerVersion.V1_20;
default:
return version > 756 ? ServerVersion.getServerVersion() : ServerVersion.UNKNOWN;
return version > 763 ? ServerVersion.getServerVersion() : ServerVersion.UNKNOWN;
}
}

View File

@ -165,7 +165,7 @@ public enum CompatibleBiome {
}
CompatibleBiome() {
versions.add(v(ServerVersion.UNKNOWN, name()));
this.versions.add(v(ServerVersion.UNKNOWN, name()));
}
CompatibleBiome(ServerVersion version, Version... versions) {
@ -178,12 +178,12 @@ public enum CompatibleBiome {
}
public List<Version> getVersions() {
return new LinkedList<>(versions);
return new LinkedList<>(this.versions);
}
public Biome getBiome() {
try {
for (Version version : versions) {
for (Version version : this.versions) {
if (ServerVersion.isServerVersionAtLeast(version.version)) {
return Biome.valueOf(version.biome);
}

View File

@ -1,6 +1,7 @@
package com.craftaro.core.compatibility;
import org.bukkit.entity.Player;
import org.bukkit.entity.LivingEntity;
import org.bukkit.inventory.EntityEquipment;
import org.bukkit.inventory.EquipmentSlot;
import org.bukkit.inventory.ItemStack;
@ -46,62 +47,66 @@ public enum CompatibleHand {
}
/**
* Use up whatever item the player is holding in their main hand
* Use up whatever item the player is holding in their hand
*
* @param player player to grab item from
* @param entity entity to grab item from
*/
public void takeItem(Player player) {
takeItem(player, 1);
public void takeItem(LivingEntity entity) {
takeItem(entity, 1);
}
/**
* Use up whatever item the player is holding in their main hand
* Use up whatever item the player is holding in their hand
*
* @param player player to grab item from
* @param entity entity to grab item from
* @param amount number of items to use up
*/
public void takeItem(Player player, int amount) {
public void takeItem(LivingEntity entity, int amount) {
ItemStack item = this == CompatibleHand.MAIN_HAND
? player.getInventory().getItemInHand() : player.getInventory().getItemInOffHand();
? entity.getEquipment().getItemInHand() : entity.getEquipment().getItemInOffHand();
int result = item.getAmount() - amount;
item.setAmount(result);
if (this == CompatibleHand.MAIN_HAND) {
player.setItemInHand(result > 0 ? item : null);
entity.getEquipment().setItemInHand(result > 0 ? item : null);
return;
}
player.getInventory().setItemInOffHand(result > 0 ? item : null);
entity.getEquipment().setItemInOffHand(result > 0 ? item : null);
}
/**
* Get item in the selected hand
*
* @param player the player to get the item from
* @param entity The entity to get the item from
*
* @return the item
* @return The item or null
*/
public ItemStack getItem(Player player) {
if (this == MAIN_HAND) {
return player.getItemInHand();
public ItemStack getItem(LivingEntity entity) {
EntityEquipment equipment = entity.getEquipment();
if (equipment == null) {
return null;
}
return player.getInventory().getItemInOffHand();
if (this == MAIN_HAND) {
return equipment.getItemInMainHand();
}
return equipment.getItemInOffHand();
}
/**
* Set the item in the selected hand
*
* @param player the player to set the item of
* @param item the item to set
* @param entity The entity to set the item of
* @param item The item to set
*/
public void setItem(Player player, ItemStack item) {
public void setItem(LivingEntity entity, ItemStack item) {
if (this == MAIN_HAND) {
player.setItemInHand(item);
entity.getEquipment().setItemInHand(item);
return;
}
player.getInventory().setItemInOffHand(item);
entity.getEquipment().setItemInOffHand(item);
}
}

View File

@ -124,7 +124,7 @@ public class CompatibleParticleHandler {
final boolean compatibilityMode;
final LegacyParticleEffects.Type compatibleEffect;
final Object particle;
final static Map<String, ParticleType> map = new HashMap<>();
static final Map<String, ParticleType> map = new HashMap<>();
static {
for (ParticleType t : values()) {

View File

@ -1,5 +1,6 @@
package com.craftaro.core.compatibility;
import com.cryptomorin.xseries.XSound;
import org.bukkit.Location;
import org.bukkit.Sound;
import org.bukkit.World;
@ -7,7 +8,6 @@ import org.bukkit.entity.Player;
/**
* TODO: Probably recode to be similar to CompatibleMaterial
*
* Sounds that are compatible with server versions 1.7+ <br>
* TODO: This needs work.
* Finished 1.8, finished 1.9 blocks, resume with 1.9 entities<br>
@ -15,7 +15,10 @@ import org.bukkit.entity.Player;
* sounds were renamed. New sounds have been added by different versions, as
* well. The intent of this class is to provide either the correct sound or a
* near equivalent for the current server.
*
* @deprecated Use {@link XSound} instead.
*/
@Deprecated
public enum CompatibleSound {
// some of these values are missing an API value...
// would using the raw strings be better?
@ -1358,19 +1361,19 @@ public enum CompatibleSound {
if (DEBUG && find == null) {
System.err.println("Sound for " + name() + " not found!");
}
sound = find;
compatibilityMode = find == null;
this.sound = find;
this.compatibilityMode = find == null;
}
// if the sound only ever changed from 1.8 -> 1.9
CompatibleSound(String compatibility_18) {
try {
compatibilityMode = false;
this.compatibilityMode = false;
if (ServerVersion.isServerVersionBelow(ServerVersion.V1_9)) {
sound = Sound.valueOf(compatibility_18);
this.sound = Sound.valueOf(compatibility_18);
} else {
sound = Sound.valueOf(name());
this.sound = Sound.valueOf(name());
}
} catch (Exception ex) {
System.err.println("ERROR loading " + name());
@ -1382,8 +1385,8 @@ public enum CompatibleSound {
try {
for (Version v : versions) {
if (v.sound != null && ServerVersion.isServerVersionAtLeast(v.version)) {
sound = Sound.valueOf(v.sound);
compatibilityMode = v.compatibilityMode;
this.sound = Sound.valueOf(v.sound);
this.compatibilityMode = v.compatibilityMode;
return;
}
}
@ -1404,28 +1407,28 @@ public enum CompatibleSound {
}
}
sound = find;
compatibilityMode = find == null;
this.sound = find;
this.compatibilityMode = find == null;
}
CompatibleSound(ServerVersion minVersion, Version... versions) {
try {
if (ServerVersion.isServerVersionAtLeast(minVersion)) {
// should be good to use this sound
sound = Sound.valueOf(name());
this.sound = Sound.valueOf(name());
} else {
for (Version v : versions) {
if (v.sound != null && ServerVersion.isServerVersionAtLeast(v.version)) {
sound = Sound.valueOf(v.sound);
compatibilityMode = v.compatibilityMode;
this.sound = Sound.valueOf(v.sound);
this.compatibilityMode = v.compatibilityMode;
return;
}
}
sound = null;
this.sound = null;
}
compatibilityMode = false;
this.compatibilityMode = false;
} catch (Exception ex) {
System.err.println("ERROR loading " + name() + " (" + minVersion + ")");
for (Version v : versions) {
@ -1443,7 +1446,7 @@ public enum CompatibleSound {
* @return Either the matching sound or a similar sound
*/
public Sound getSound() {
return sound != null ? sound : UI_BUTTON_CLICK.sound;
return this.sound != null ? this.sound : UI_BUTTON_CLICK.sound;
}
/**
@ -1507,7 +1510,7 @@ public enum CompatibleSound {
* @return Returns false if we are using a different sound.
*/
public boolean usesCompatibility() {
return !compatibilityMode;
return !this.compatibilityMode;
}
private static Version v(String sound) {

View File

@ -809,41 +809,41 @@ public enum LegacyMaterialAnalouge {
this.compatibleData = compatData;
if (ServerVersion.isServerVersionBelow(versionLessThan)) {
if (legacyMinimumVersion != null && ServerVersion.isServerVersionBelow(legacyMinimumVersion)) {
if (this.legacyMinimumVersion != null && ServerVersion.isServerVersionBelow(this.legacyMinimumVersion)) {
// fallback material not available, so use its fallback
material = Material.getMaterial(compatibleMaterial);
data = compatibleData;
} else if (modernMaterial == null || ServerVersion.isServerVersionBelow(ServerVersion.V1_13)) {
this.material = Material.getMaterial(this.compatibleMaterial);
this.data = this.compatibleData;
} else if (this.modernMaterial == null || ServerVersion.isServerVersionBelow(ServerVersion.V1_13)) {
// use legacy material if on legacy
material = Material.getMaterial(legacyMaterial);
data = legacyData;
this.material = Material.getMaterial(legacyMaterial);
this.data = legacyData;
} else {
material = Material.getMaterial(modernMaterial);
data = null;
this.material = Material.getMaterial(this.modernMaterial);
this.data = null;
}
} else {
material = null;
data = null;
this.material = null;
this.data = null;
}
}
public Material getMaterial() {
return material;
return this.material;
}
public boolean usesData() {
return data != null;
return this.data != null;
}
public byte getData() {
return data == null ? 0 : data;
return this.data == null ? 0 : this.data;
}
public ItemStack getItem() {
if (material == null) {
if (this.material == null) {
return null;
}
return data != null ? new ItemStack(material, 1, data) : new ItemStack(material);
return this.data != null ? new ItemStack(this.material, 1, this.data) : new ItemStack(this.material);
}
}

View File

@ -52,8 +52,8 @@ public enum LegacyMaterialBlockType {
final String alternateBlockMaterialName;
final Material blockMaterial, alternateBlockMaterial;
final boolean requiresData; // some blocks require data to render properly (double blocks)
final static Map<String, LegacyMaterialBlockType> lookupTable = new HashMap<>();
final static Map<String, LegacyMaterialBlockType> reverseLookupTable = new HashMap<>();
static final Map<String, LegacyMaterialBlockType> lookupTable = new HashMap<>();
static final Map<String, LegacyMaterialBlockType> reverseLookupTable = new HashMap<>();
static {
for (LegacyMaterialBlockType t : values()) {
@ -85,29 +85,29 @@ public enum LegacyMaterialBlockType {
this.blockMaterialName = blockMaterial;
this.alternateBlockMaterialName = alternateMaterial;
this.requiresData = requiresData;
this.blockMaterial = Material.getMaterial(blockMaterialName);
this.alternateBlockMaterial = Material.getMaterial(alternateBlockMaterialName);
this.blockMaterial = Material.getMaterial(this.blockMaterialName);
this.alternateBlockMaterial = Material.getMaterial(this.alternateBlockMaterialName);
this.blockData = data;
}
public String getBlockMaterialName() {
return blockMaterialName;
return this.blockMaterialName;
}
public String getAlternateMaterialName() {
return alternateBlockMaterialName;
return this.alternateBlockMaterialName;
}
public Material getBlockMaterial() {
return blockMaterial;
return this.blockMaterial;
}
public Material getAlternateBlockMaterial() {
return alternateBlockMaterial;
return this.alternateBlockMaterial;
}
public boolean requiresData() {
return requiresData;
return this.requiresData;
}
public static LegacyMaterialBlockType getMaterial(String lookup) {

View File

@ -15,7 +15,6 @@ import java.util.logging.Logger;
/**
* Particle effects for servers 1.8 and below
*
* TODO: Needs a recode, this class should not have any advanced logic like NMS magic
*/
public class LegacyParticleEffects {
@ -177,7 +176,7 @@ public class LegacyParticleEffects {
}
final int rangeSquared = 256; // apparently there is no way to override this (unless to make smaller, of course)
// collect a list of players to send this packet to
List<Player> sendTo = new ArrayList();
List<Player> sendTo = new ArrayList<>();
if (localOnly == null) {
for (Player p : l.getWorld().getPlayers()) {
if (p.getLocation().distanceSquared(l) <= rangeSquared) {

View File

@ -3,15 +3,12 @@ package com.craftaro.core.compatibility;
import org.bukkit.potion.PotionEffectType;
import java.util.HashMap;
import java.util.Random;
public class LegacyPotionEffects {
private LegacyPotionEffects() {
}
protected final static Random rand = new Random();
private final static HashMap<Integer, String> potionEffectNames = new HashMap<Integer, String>() {
private static final HashMap<Integer, String> potionEffectNames = new HashMap<Integer, String>() {
{
put(PotionEffectType.SPEED.getId(), "Speed");
put(PotionEffectType.SLOW.getId(), "Slowness");

View File

@ -109,43 +109,43 @@ public enum MethodMapping {
public Method getMethod(Class<?> clazz) {
try {
String methodName = _1_18;
String methodName = this._1_18;
switch (ServerVersion.getServerVersion()) {
case V1_14:
if (_1_14 != null) {
methodName = _1_14;
if (this._1_14 != null) {
methodName = this._1_14;
}
break;
case V1_17:
if (_1_17 != null) {
methodName = _1_17;
if (this._1_17 != null) {
methodName = this._1_17;
}
break;
case V1_18:
if (_1_18_2 != null) {
methodName = _1_18_2;
if (this._1_18_2 != null) {
methodName = this._1_18_2;
}
break;
case V1_19:
if (_1_19 != null) {
methodName = _1_19;
if (this._1_19 != null) {
methodName = this._1_19;
}
break;
}
try {
Method method = clazz.getMethod(methodName, parameters);
Method method = clazz.getMethod(methodName, this.parameters);
method.setAccessible(true);
return method;
} catch (NullPointerException | NoSuchMethodException ex) {
if (saneFallback != null && !saneFallback.equals(methodName)) {
if (this.saneFallback != null && !this.saneFallback.equals(methodName)) {
try {
Method method = clazz.getMethod(saneFallback, parameters);
Method method = clazz.getMethod(this.saneFallback, this.parameters);
method.setAccessible(true);
return method;

View File

@ -5,7 +5,7 @@ import org.bukkit.Bukkit;
public enum ServerProject {
UNKNOWN, CRAFTBUKKIT, SPIGOT, PAPER, TACO, GLOWSTONE, MOCK_BUKKIT;
private final static ServerProject serverProject = checkProject();
private static final ServerProject serverProject = checkProject();
private static ServerProject checkProject() {
String serverPath = Bukkit.getServer().getClass().getName();

View File

@ -4,12 +4,12 @@ import org.apache.commons.lang3.ArrayUtils;
import org.bukkit.Bukkit;
public enum ServerVersion {
UNKNOWN, V1_7, V1_8, V1_9, V1_10, V1_11, V1_12, V1_13, V1_14, V1_15, V1_16, V1_17, V1_18, V1_19, V1_20, V1_21;
UNKNOWN, V1_7, V1_8, V1_9, V1_10, V1_11, V1_12, V1_13, V1_14, V1_15, V1_16, V1_17, V1_18, V1_19, V1_20, V1_21, V1_22, V1_23;
private final static String serverPackageVersion;
private final static String serverReleaseVersion;
private final static ServerVersion serverVersion;
private final static boolean isMocked;
private static final String serverPackageVersion;
private static final String serverReleaseVersion;
private static final ServerVersion serverVersion;
private static final boolean isMocked;
static {
if (Bukkit.getServer() != null) {

View File

@ -35,7 +35,7 @@
<injections>
<injection>
<value>${project.version}</value>
<pointCut>com.craftaro.core.SongodaCoreConstants.getCoreVersion</pointCut>
<pointCut>com.craftaro.core.CraftaroCoreConstants.getCoreVersion</pointCut>
</injection>
</injections>
</configuration>
@ -60,7 +60,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.3.0</version>
<version>3.5.0</version>
<executions>
<execution>
@ -81,6 +81,7 @@
<include>com.zaxxer:HikariCP</include>
<include>de.tr7zw:item-nbt-api</include>
<include>net.kyori:*</include>
<include>com.github.cryptomorin:XSeries</include>
<include>org.apache.commons:commons-lang3</include>
<include>org.apache.commons:commons-text</include>
<include>org.jooq:jooq</include>
@ -130,7 +131,26 @@
<pattern>org.h2</pattern>
<shadedPattern>com.craftaro.core.third_party.org.h2</shadedPattern>
</relocation>
<relocation>
<pattern>com.cryptomorin.xseries</pattern>
<shadedPattern>com.craftaro.core.third_party.com.cryptomorin.xseries</shadedPattern>
</relocation>
</relocations>
<filters>
<filter>
<artifact>*:*</artifact>
<excludes>
<exclude>META-INF/INDEX.LIST</exclude>
<exclude>META-INF/*.SF</exclude>
<exclude>META-INF/*.DSA</exclude>
<exclude>META-INF/*.RSA</exclude>
<exclude>**/LICENSE*</exclude>
<exclude>**/NOTICE*</exclude>
</excludes>
</filter>
</filters>
</configuration>
</execution>
</executions>
@ -151,6 +171,7 @@
</dependencyManagement>
<dependencies>
<!--suppress VulnerableLibrariesLocal -->
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot</artifactId>
@ -176,7 +197,7 @@
<dependency>
<groupId>de.tr7zw</groupId>
<artifactId>item-nbt-api</artifactId>
<version>2.11.2</version>
<version>2.11.3</version>
<scope>compile</scope>
</dependency>

View File

@ -7,8 +7,8 @@ package com.craftaro.core;
* <p>
* <b>!! Manually changing the values in this class has to be considered a breaking change. !!</b>
*/
public class SongodaCoreConstants {
private SongodaCoreConstants() {
public class CraftaroCoreConstants {
private CraftaroCoreConstants() {
throw new IllegalStateException("Utility class");
}
@ -17,10 +17,10 @@ public class SongodaCoreConstants {
}
public static String getProjectName() {
return "SongodaCore";
return "CraftaroCore";
}
public static String getGitHubProjectUrl() {
return "https://github.com/craftaro/SongodaCore";
return "https://github.com/craftaro/CraftaroCore";
}
}

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;
@ -46,7 +46,7 @@ import java.util.logging.Level;
import java.util.logging.Logger;
public class SongodaCore {
private static final Logger logger = Logger.getLogger(SongodaCoreConstants.getProjectName());
private static final Logger logger = Logger.getLogger(CraftaroCoreConstants.getProjectName());
/**
* Whenever we make a major change to the core GUI, updater,
@ -59,10 +59,10 @@ public class SongodaCore {
/**
* @since coreRevision 6
* @deprecated Is being replaced by {@link SongodaCoreConstants#getCoreVersion()} which is automatically kept up to date.
* @deprecated Is being replaced by {@link CraftaroCoreConstants#getCoreVersion()} which is automatically kept up to date.
*/
@Deprecated
private static final String coreVersion = SongodaCoreConstants.getCoreVersion();
private static final String coreVersion = CraftaroCoreConstants.getCoreVersion();
/**
* This is specific to the website api
@ -83,11 +83,11 @@ public class SongodaCore {
public static boolean hasShading() {
// sneaky hack to check the package name since maven tries to re-shade all references to the package string
return !SongodaCore.class.getPackage().getName().equals(new String(new char[] {'c', 'o', 'm', '.', 's', 'o', 'n', 'g', 'o', 'd', 'a', '.', 'c', 'o', 'r', 'e'}));
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) {
registerPlugin(plugin, pluginID, icon == null ? "STONE" : icon.name(), SongodaCoreConstants.getCoreVersion());
public static void registerPlugin(JavaPlugin plugin, int pluginID, XMaterial icon) {
registerPlugin(plugin, pluginID, icon == null ? "STONE" : icon.name(), CraftaroCoreConstants.getCoreVersion());
}
public static void registerPlugin(JavaPlugin plugin, int pluginID, String icon) {
@ -182,31 +182,31 @@ public class SongodaCore {
}
SongodaCore() {
commandManager = null;
this.commandManager = null;
}
SongodaCore(JavaPlugin javaPlugin) {
piggybackedPlugin = javaPlugin;
commandManager = new CommandManager(piggybackedPlugin);
loginListener = new EventListener();
this.piggybackedPlugin = javaPlugin;
this.commandManager = new CommandManager(this.piggybackedPlugin);
this.loginListener = new EventListener();
}
private void init() {
shadingListener = new ShadedEventListener();
commandManager.registerCommandDynamically(new SongodaCoreCommand())
this.shadingListener = new ShadedEventListener();
this.commandManager.registerCommandDynamically(new SongodaCoreCommand())
.addSubCommands(new SongodaCoreDiagCommand(), new SongodaCoreUUIDCommand(), new SongodaCoreLicenseCommand());
Bukkit.getPluginManager().registerEvents(loginListener, piggybackedPlugin);
Bukkit.getPluginManager().registerEvents(shadingListener, piggybackedPlugin);
Bukkit.getPluginManager().registerEvents(this.loginListener, this.piggybackedPlugin);
Bukkit.getPluginManager().registerEvents(this.shadingListener, this.piggybackedPlugin);
// we aggressively want to own this command
tasks.add(Bukkit.getScheduler().runTaskLaterAsynchronously(piggybackedPlugin, () ->
CommandManager.registerCommandDynamically(piggybackedPlugin, "songoda", commandManager, commandManager),
this.tasks.add(Bukkit.getScheduler().runTaskLaterAsynchronously(this.piggybackedPlugin, () ->
CommandManager.registerCommandDynamically(this.piggybackedPlugin, "songoda", this.commandManager, this.commandManager),
10 * 60));
tasks.add(Bukkit.getScheduler().runTaskLaterAsynchronously(piggybackedPlugin, () ->
CommandManager.registerCommandDynamically(piggybackedPlugin, "songoda", commandManager, commandManager),
this.tasks.add(Bukkit.getScheduler().runTaskLaterAsynchronously(this.piggybackedPlugin, () ->
CommandManager.registerCommandDynamically(this.piggybackedPlugin, "songoda", this.commandManager, this.commandManager),
20 * 60));
tasks.add(Bukkit.getScheduler().runTaskLaterAsynchronously(piggybackedPlugin, () ->
CommandManager.registerCommandDynamically(piggybackedPlugin, "songoda", commandManager, commandManager),
this.tasks.add(Bukkit.getScheduler().runTaskLaterAsynchronously(this.piggybackedPlugin, () ->
CommandManager.registerCommandDynamically(this.piggybackedPlugin, "songoda", this.commandManager, this.commandManager),
20 * 60 * 2));
}
@ -216,17 +216,17 @@ public class SongodaCore {
private void destroy() {
Bukkit.getServicesManager().unregister(SongodaCore.class, INSTANCE);
tasks.stream().filter(Objects::nonNull)
this.tasks.stream().filter(Objects::nonNull)
.forEach(task -> Bukkit.getScheduler().cancelTask(task.getTaskId()));
HandlerList.unregisterAll(loginListener);
HandlerList.unregisterAll(this.loginListener);
if (!hasShading()) {
HandlerList.unregisterAll(shadingListener);
HandlerList.unregisterAll(this.shadingListener);
}
registeredPlugins.clear();
commandManager = null;
loginListener = null;
this.commandManager = null;
this.loginListener = null;
}
private ArrayList<BukkitTask> tasks = new ArrayList<>();
@ -247,7 +247,7 @@ public class SongodaCore {
// don't forget to check for language pack updates ;)
info.addModule(new LocaleModule());
registeredPlugins.add(info);
tasks.add(Bukkit.getScheduler().runTaskLaterAsynchronously(plugin, () -> update(info), 60L));
this.tasks.add(Bukkit.getScheduler().runTaskLaterAsynchronously(plugin, () -> update(info), 60L));
}
/**
@ -300,7 +300,7 @@ public class SongodaCore {
}
public static String getVersion() {
return SongodaCoreConstants.getCoreVersion();
return CraftaroCoreConstants.getCoreVersion();
}
/**
@ -316,7 +316,7 @@ public class SongodaCore {
*/
@Deprecated
public static String getCoreLibraryVersion() {
return SongodaCoreConstants.getCoreVersion();
return CraftaroCoreConstants.getCoreVersion();
}
public static int getCoreMajorVersion() {
@ -337,7 +337,7 @@ public class SongodaCore {
}
public static String getPrefix() {
return "[" + SongodaCoreConstants.getProjectName() + "] ";
return "[" + CraftaroCoreConstants.getProjectName() + "] ";
}
public static Logger getLogger() {
@ -361,34 +361,34 @@ public class SongodaCore {
boolean proto = false;
ShadedEventListener() {
via = Bukkit.getPluginManager().isPluginEnabled("ViaVersion");
this.via = Bukkit.getPluginManager().isPluginEnabled("ViaVersion");
if (via) {
if (this.via) {
Bukkit.getOnlinePlayers().forEach(p -> ClientVersion.onLoginVia(p, getHijackedPlugin()));
return;
}
proto = Bukkit.getPluginManager().isPluginEnabled("ProtocolSupport");
if (proto) {
this.proto = Bukkit.getPluginManager().isPluginEnabled("ProtocolSupport");
if (this.proto) {
Bukkit.getOnlinePlayers().forEach(p -> ClientVersion.onLoginProtocol(p, getHijackedPlugin()));
}
}
@EventHandler
void onLogin(PlayerLoginEvent event) {
if (via) {
if (this.via) {
ClientVersion.onLoginVia(event.getPlayer(), getHijackedPlugin());
return;
}
if (proto) {
if (this.proto) {
ClientVersion.onLoginProtocol(event.getPlayer(), getHijackedPlugin());
}
}
@EventHandler
void onLogout(PlayerQuitEvent event) {
if (via) {
if (this.via) {
ClientVersion.onLogout(event.getPlayer());
}
}
@ -396,9 +396,9 @@ public class SongodaCore {
@EventHandler
void onEnable(PluginEnableEvent event) {
// technically shouldn't have online players here, but idk
if (!via && (via = event.getPlugin().getName().equals("ViaVersion"))) {
if (!this.via && (this.via = event.getPlugin().getName().equals("ViaVersion"))) {
Bukkit.getOnlinePlayers().forEach(p -> ClientVersion.onLoginVia(p, getHijackedPlugin()));
} else if (!proto && (proto = event.getPlugin().getName().equals("ProtocolSupport"))) {
} else if (!this.proto && (this.proto = event.getPlugin().getName().equals("ProtocolSupport"))) {
Bukkit.getOnlinePlayers().forEach(p -> ClientVersion.onLoginProtocol(p, getHijackedPlugin()));
}
}
@ -413,13 +413,13 @@ public class SongodaCore {
// don't spam players with update checks
long now = System.currentTimeMillis();
Long last = lastCheck.get(player.getUniqueId());
Long last = this.lastCheck.get(player.getUniqueId());
if (last != null && now - 10000 < last) {
return;
}
lastCheck.put(player.getUniqueId(), now);
this.lastCheck.put(player.getUniqueId(), now);
// is this player good to revieve update notices?
if (!event.getPlayer().isOp() && !player.hasPermission("songoda.updatecheck")) return;
@ -441,19 +441,19 @@ public class SongodaCore {
registeredPlugins.remove(pi);
}
if (event.getPlugin() == piggybackedPlugin) {
if (event.getPlugin() == SongodaCore.this.piggybackedPlugin) {
// uh-oh! Abandon ship!!
Bukkit.getServicesManager().unregisterAll(piggybackedPlugin);
Bukkit.getServicesManager().unregisterAll(SongodaCore.this.piggybackedPlugin);
// can we move somewhere else?
if ((pi = registeredPlugins.stream().findFirst().orElse(null)) != null) {
// move ourselves to this plugin
piggybackedPlugin = pi.getJavaPlugin();
SongodaCore.this.piggybackedPlugin = pi.getJavaPlugin();
Bukkit.getServicesManager().register(SongodaCore.class, INSTANCE, piggybackedPlugin, ServicePriority.Normal);
Bukkit.getPluginManager().registerEvents(loginListener, piggybackedPlugin);
Bukkit.getPluginManager().registerEvents(shadingListener, piggybackedPlugin);
CommandManager.registerCommandDynamically(piggybackedPlugin, "songoda", commandManager, commandManager);
Bukkit.getServicesManager().register(SongodaCore.class, INSTANCE, SongodaCore.this.piggybackedPlugin, ServicePriority.Normal);
Bukkit.getPluginManager().registerEvents(SongodaCore.this.loginListener, SongodaCore.this.piggybackedPlugin);
Bukkit.getPluginManager().registerEvents(SongodaCore.this.shadingListener, SongodaCore.this.piggybackedPlugin);
CommandManager.registerCommandDynamically(SongodaCore.this.piggybackedPlugin, "songoda", SongodaCore.this.commandManager, SongodaCore.this.commandManager);
}
}
}

View File

@ -1,6 +1,5 @@
package com.craftaro.core;
import com.craftaro.core.compatibility.CompatibleMaterial;
import com.craftaro.core.configuration.Config;
import com.craftaro.core.database.DataManager;
import com.craftaro.core.database.DataMigration;
@ -9,6 +8,7 @@ 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.cryptomorin.xseries.XMaterial;
import de.tr7zw.changeme.nbtapi.utils.MinecraftVersion;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
@ -20,6 +20,7 @@ import java.io.File;
import java.sql.Connection;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.TimeUnit;
import java.util.logging.Level;
public abstract class SongodaPlugin extends JavaPlugin {
@ -35,7 +36,6 @@ public abstract class SongodaPlugin extends JavaPlugin {
static {
/* NBT-API */
MinecraftVersion.getLogger().setLevel(Level.WARNING);
MinecraftVersion.disableUpdateCheck();
// Disable tips and logo for Jooq
System.setProperty("org.jooq.no-tips", "true");
System.setProperty("org.jooq.no-logo", "true");
@ -63,22 +63,22 @@ public abstract class SongodaPlugin extends JavaPlugin {
@Override
public FileConfiguration getConfig() {
return config.getFileConfig();
return this.config.getFileConfig();
}
public Config getCoreConfig() {
return config;
return this.config;
}
@Override
public void reloadConfig() {
config.load();
this.config.load();
onConfigReload();
}
@Override
public void saveConfig() {
config.save();
this.config.save();
}
@Override
@ -111,7 +111,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,12 +1,12 @@
package com.craftaro.core.chat;
import com.craftaro.core.compatibility.ClassMapping;
import com.craftaro.core.compatibility.ServerVersion;
import com.craftaro.core.nms.Nms;
import com.craftaro.core.utils.TextUtils;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonObject;
import com.craftaro.core.compatibility.ClassMapping;
import com.craftaro.core.compatibility.ServerVersion;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;

View File

@ -1,9 +1,9 @@
package com.craftaro.core.chat;
import com.craftaro.core.utils.ColorUtils;
import com.craftaro.core.compatibility.ServerVersion;
import com.craftaro.core.utils.ColorUtils;
import java.awt.*;
import java.awt.Color;
public class ColorContainer {
private ColorCode colorCode;
@ -24,26 +24,26 @@ public class ColorContainer {
}
public ColorCode getColorCode() {
return colorCode;
return this.colorCode;
}
public String getHexCode() {
return hexCode;
return this.hexCode;
}
public ColorCode getColor() {
if (colorCode != null) {
return colorCode;
if (this.colorCode != null) {
return this.colorCode;
}
if (hexCode == null) {
if (this.hexCode == null) {
return null;
}
java.awt.Color jColor = new Color(
Integer.valueOf(hexCode.substring(0, 2), 16),
Integer.valueOf(hexCode.substring(2, 4), 16),
Integer.valueOf(hexCode.substring(4, 6), 16));
Integer.valueOf(this.hexCode.substring(0, 2), 16),
Integer.valueOf(this.hexCode.substring(2, 4), 16),
Integer.valueOf(this.hexCode.substring(4, 6), 16));
return ColorUtils.fromRGB(jColor.getRed(), jColor.getGreen(), jColor.getBlue());
}

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);
}
}
@ -112,30 +113,30 @@ public class CustomizableGui extends Gui {
customContent.disableButton(disabled);
}
} else {
customContent = loadedGuis.get(guiKey);
this.customContent = loadedGuis.get(guiKey);
}
setPrivateDefaultAction(event -> {
if (event.clickType == ClickType.SHIFT_RIGHT) {
activationCount++;
this.activationCount++;
}
if (activationCount >= 8 && event.player.hasPermission("songoda.admin")) {
if (this.activationCount >= 8 && event.player.hasPermission("songoda.admin")) {
showGuiKeys = !showGuiKeys;
activationCount = 0;
this.activationCount = 0;
event.player.sendMessage("Gui keys " + (showGuiKeys ? "enabled" : "disabled") + ".");
}
});
if (customContent.isButtonCustomized("__DEFAULT__")) {
blankItem = GuiUtils.getBorderItem(customContent.getCustomizedButton("__DEFAULT__").item);
if (this.customContent.isButtonCustomized("__DEFAULT__")) {
this.blankItem = GuiUtils.getBorderItem(this.customContent.getCustomizedButton("__DEFAULT__").item);
}
}
@NotNull
public Gui setRows(int rows) {
int customRows = customContent.getRows();
int customRows = this.customContent.getRows();
return super.setRows(customRows != -1 ? customRows : rows);
}
@ -153,13 +154,13 @@ public class CustomizableGui extends Gui {
}
private void applyCustomItems() {
for (CustomButton customButton : customContent.getCustomButtons().values()) {
for (CustomButton customButton : this.customContent.getCustomButtons().values()) {
if (customButton instanceof MirrorFill) {
applyCustomItem(customButton);
}
}
for (CustomButton customButton : customContent.getCustomButtons().values()) {
for (CustomButton customButton : this.customContent.getCustomButtons().values()) {
if (!(customButton instanceof MirrorFill)) {
applyCustomItem(customButton);
}
@ -190,7 +191,7 @@ public class CustomizableGui extends Gui {
applyShowGuiKeys("__DEFAULT__", item);
if (customContent.isButtonCustomized("__DEFAULT__")) {
if (this.customContent.isButtonCustomized("__DEFAULT__")) {
return this;
}
@ -201,14 +202,14 @@ public class CustomizableGui extends Gui {
public Gui setItem(@NotNull String key, int cell, @Nullable ItemStack item) {
List<Integer> cells = Collections.singletonList(cell);
if (customContent.isButtonDisabled(key)) {
if (this.customContent.isButtonDisabled(key)) {
return this;
}
applyShowGuiKeys(key, item);
if (customContent.isButtonCustomized(key)) {
CustomButton btn = customContent.getCustomizedButton(key);
if (this.customContent.isButtonCustomized(key)) {
CustomButton btn = this.customContent.getCustomizedButton(key);
cells = btn.applyPosition(cell);
btn.applyItem(item);
}
@ -222,21 +223,21 @@ public class CustomizableGui extends Gui {
@NotNull
public Gui setItem(@NotNull String key, int row, int col, @Nullable ItemStack item) {
final int cell = col + row * inventoryType.columns;
final int cell = col + row * this.inventoryType.columns;
return setItem(key, cell, item);
}
public Gui mirrorFill(@NotNull String key, int row, int col, boolean mirrorRow, boolean mirrorCol, @NotNull ItemStack item) {
if (customContent.isButtonDisabled(key)) {
if (this.customContent.isButtonDisabled(key)) {
return this;
}
ItemStack newItem = item.clone();
boolean isShow = applyShowGuiKeys(key, newItem);
if (customContent.isButtonCustomized(key)) {
CustomButton btn = customContent.getCustomizedButton(key);
if (this.customContent.isButtonCustomized(key)) {
CustomButton btn = this.customContent.getCustomizedButton(key);
row = btn.applyPositionRow(row);
col = btn.applyPositionCol(col);
@ -258,12 +259,12 @@ public class CustomizableGui extends Gui {
public Gui highlightItem(@NotNull String key, int cell) {
List<Integer> cells = Collections.singletonList(cell);
if (customContent.isButtonDisabled(key)) {
if (this.customContent.isButtonDisabled(key)) {
return this;
}
if (customContent.isButtonCustomized(key)) {
cells = customContent.getCustomizedButton(key).applyPosition(cell);
if (this.customContent.isButtonCustomized(key)) {
cells = this.customContent.getCustomizedButton(key).applyPosition(cell);
}
for (int c : cells) {
@ -275,11 +276,11 @@ public class CustomizableGui extends Gui {
@NotNull
public Gui highlightItem(@NotNull String key, int row, int col) {
if (customContent.isButtonDisabled(key)) {
if (this.customContent.isButtonDisabled(key)) {
return this;
}
final int cell = col + row * inventoryType.columns;
final int cell = col + row * this.inventoryType.columns;
return highlightItem(key, cell);
}
@ -288,12 +289,12 @@ public class CustomizableGui extends Gui {
public Gui removeHighlight(@NotNull String key, int cell) {
List<Integer> cells = Collections.singletonList(cell);
if (customContent.isButtonDisabled(key)) {
if (this.customContent.isButtonDisabled(key)) {
return this;
}
if (customContent.isButtonCustomized(key)) {
cells = customContent.getCustomizedButton(key).applyPosition(cell);
if (this.customContent.isButtonCustomized(key)) {
cells = this.customContent.getCustomizedButton(key).applyPosition(cell);
}
for (int c : cells) {
@ -305,34 +306,34 @@ public class CustomizableGui extends Gui {
@NotNull
public Gui removeHighlight(@NotNull String key, int row, int col) {
if (customContent.isButtonDisabled(key)) {
if (this.customContent.isButtonDisabled(key)) {
return this;
}
final int cell = col + row * inventoryType.columns;
final int cell = col + row * this.inventoryType.columns;
return removeHighlight(key, cell);
}
@NotNull
public Gui updateItemLore(@NotNull String key, int row, int col, @NotNull String... lore) {
if (customContent.isButtonDisabled(key)) {
if (this.customContent.isButtonDisabled(key)) {
return this;
}
return updateItemLore(key, col + row * inventoryType.columns, lore);
return updateItemLore(key, col + row * this.inventoryType.columns, lore);
}
@NotNull
public Gui updateItemLore(@NotNull String key, int cell, @NotNull String... lore) {
List<Integer> cells = Collections.singletonList(cell);
if (customContent.isButtonDisabled(key)) {
if (this.customContent.isButtonDisabled(key)) {
return this;
}
if (customContent.isButtonCustomized(key)) {
cells = customContent.getCustomizedButton(key).applyPosition(cell);
if (this.customContent.isButtonCustomized(key)) {
cells = this.customContent.getCustomizedButton(key).applyPosition(cell);
}
for (int c : cells) {
@ -344,23 +345,23 @@ public class CustomizableGui extends Gui {
@NotNull
public Gui updateItemLore(@NotNull String key, int row, int col, @Nullable List<String> lore) {
if (customContent.isButtonDisabled(key)) {
if (this.customContent.isButtonDisabled(key)) {
return this;
}
return updateItemLore(key, col + row * inventoryType.columns, lore);
return updateItemLore(key, col + row * this.inventoryType.columns, lore);
}
@NotNull
public Gui updateItemLore(@NotNull String key, int cell, @Nullable List<String> lore) {
List<Integer> cells = Collections.singletonList(cell);
if (customContent.isButtonDisabled(key)) {
if (this.customContent.isButtonDisabled(key)) {
return this;
}
if (customContent.isButtonCustomized(key)) {
cells = customContent.getCustomizedButton(key).applyPosition(cell);
if (this.customContent.isButtonCustomized(key)) {
cells = this.customContent.getCustomizedButton(key).applyPosition(cell);
}
for (int c : cells) {
@ -372,23 +373,23 @@ public class CustomizableGui extends Gui {
@NotNull
public Gui updateItemName(@NotNull String key, int row, int col, @Nullable String name) {
if (customContent.isButtonDisabled(key)) {
if (this.customContent.isButtonDisabled(key)) {
return this;
}
return updateItemName(key, col + row * inventoryType.columns, name);
return updateItemName(key, col + row * this.inventoryType.columns, name);
}
@NotNull
public Gui updateItemName(@NotNull String key, int cell, @Nullable String name) {
List<Integer> cells = Collections.singletonList(cell);
if (customContent.isButtonDisabled(key)) {
if (this.customContent.isButtonDisabled(key)) {
return this;
}
if (customContent.isButtonCustomized(key)) {
cells = customContent.getCustomizedButton(key).applyPosition(cell);
if (this.customContent.isButtonCustomized(key)) {
cells = this.customContent.getCustomizedButton(key).applyPosition(cell);
}
for (int c : cells) {
@ -400,16 +401,16 @@ public class CustomizableGui extends Gui {
@NotNull
public Gui updateItem(@NotNull String key, int row, int col, @Nullable String name, @NotNull String... lore) {
if (customContent.isButtonDisabled(key)) {
if (this.customContent.isButtonDisabled(key)) {
return this;
}
return updateItem(key, col + row * inventoryType.columns, name, lore);
return updateItem(key, col + row * this.inventoryType.columns, name, lore);
}
@NotNull
public Gui updateItem(@NotNull String key, int cell, @Nullable String name, @NotNull String... lore) {
if (customContent.isButtonDisabled(key)) {
if (this.customContent.isButtonDisabled(key)) {
return this;
}
@ -418,25 +419,25 @@ public class CustomizableGui extends Gui {
@NotNull
public Gui updateItem(@NotNull String key, int row, int col, @Nullable String name, @Nullable List<String> lore) {
if (customContent.isButtonDisabled(key)) {
if (this.customContent.isButtonDisabled(key)) {
return this;
}
return updateItem(key, col + row * inventoryType.columns, name, lore);
return updateItem(key, col + row * this.inventoryType.columns, name, lore);
}
@NotNull
public Gui updateItem(@NotNull String key, int cell, @NotNull String name, @Nullable List<String> lore) {
List<Integer> cells = Collections.singletonList(cell);
if (customContent.isButtonDisabled(key)) {
if (this.customContent.isButtonDisabled(key)) {
return this;
}
lore = applyShowGuiKeys(key, lore);
if (customContent.isButtonCustomized(key)) {
cells = customContent.getCustomizedButton(key).applyPosition(cell);
if (this.customContent.isButtonCustomized(key)) {
cells = this.customContent.getCustomizedButton(key).applyPosition(cell);
}
for (int c : cells) {
@ -448,23 +449,23 @@ public class CustomizableGui extends Gui {
@NotNull
public Gui updateItem(@NotNull String key, int row, int col, @NotNull ItemStack itemTo, @Nullable String title, @NotNull String... lore) {
if (customContent.isButtonDisabled(key)) {
if (this.customContent.isButtonDisabled(key)) {
return this;
}
return updateItem(key, col + row * inventoryType.columns, itemTo, title, lore);
return updateItem(key, col + row * this.inventoryType.columns, itemTo, title, lore);
}
@NotNull
public Gui updateItem(@NotNull String key, int cell, @NotNull ItemStack itemTo, @Nullable String title, @NotNull String... lore) {
List<Integer> cells = Collections.singletonList(cell);
if (customContent.isButtonDisabled(key)) {
if (this.customContent.isButtonDisabled(key)) {
return this;
}
if (customContent.isButtonCustomized(key)) {
cells = customContent.getCustomizedButton(key).applyPosition(cell);
if (this.customContent.isButtonCustomized(key)) {
cells = this.customContent.getCustomizedButton(key).applyPosition(cell);
}
for (int c : cells) {
@ -475,24 +476,24 @@ 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) {
if (customContent.isButtonDisabled(key)) {
public Gui updateItem(@NotNull String key, int row, int col, @NotNull XMaterial itemTo, @Nullable String title, @NotNull String... lore) {
if (this.customContent.isButtonDisabled(key)) {
return this;
}
return updateItem(key, col + row * inventoryType.columns, itemTo, title, lore);
return updateItem(key, col + row * this.inventoryType.columns, itemTo, title, lore);
}
@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)) {
if (this.customContent.isButtonDisabled(key)) {
return this;
}
if (customContent.isButtonCustomized(key)) {
cells = customContent.getCustomizedButton(key).applyPosition(cell);
if (this.customContent.isButtonCustomized(key)) {
cells = this.customContent.getCustomizedButton(key).applyPosition(cell);
}
for (int c : cells) {
@ -504,23 +505,23 @@ public class CustomizableGui extends Gui {
@NotNull
public Gui updateItem(@NotNull String key, int row, int col, @NotNull ItemStack itemTo, @Nullable String title, @Nullable List<String> lore) {
if (customContent.isButtonDisabled(key)) {
if (this.customContent.isButtonDisabled(key)) {
return this;
}
return updateItem(key, col + row * inventoryType.columns, itemTo, title, lore);
return updateItem(key, col + row * this.inventoryType.columns, itemTo, title, lore);
}
@NotNull
public Gui updateItem(@NotNull String key, int cell, @NotNull ItemStack itemTo, @Nullable String title, @Nullable List<String> lore) {
List<Integer> cells = Collections.singletonList(cell);
if (customContent.isButtonDisabled(key)) {
if (this.customContent.isButtonDisabled(key)) {
return this;
}
if (customContent.isButtonCustomized(key)) {
cells = customContent.getCustomizedButton(key).applyPosition(cell);
if (this.customContent.isButtonCustomized(key)) {
cells = this.customContent.getCustomizedButton(key).applyPosition(cell);
}
for (int c : cells) {
@ -531,24 +532,24 @@ 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) {
if (customContent.isButtonDisabled(key)) {
public Gui updateItem(@NotNull String key, int row, int col, @NotNull XMaterial itemTo, @Nullable String title, @Nullable List<String> lore) {
if (this.customContent.isButtonDisabled(key)) {
return this;
}
return updateItem(key, col + row * inventoryType.columns, itemTo, title, lore);
return updateItem(key, col + row * this.inventoryType.columns, itemTo, title, lore);
}
@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)) {
if (this.customContent.isButtonDisabled(key)) {
return this;
}
if (customContent.isButtonCustomized(key)) {
cells = customContent.getCustomizedButton(key).applyPosition(cell);
if (this.customContent.isButtonCustomized(key)) {
cells = this.customContent.getCustomizedButton(key).applyPosition(cell);
}
for (int c : cells) {
@ -560,7 +561,7 @@ public class CustomizableGui extends Gui {
@NotNull
public Gui setAction(@NotNull String key, int cell, @Nullable Clickable action) {
if (customContent.isButtonDisabled(key)) {
if (this.customContent.isButtonDisabled(key)) {
return this;
}
@ -571,18 +572,18 @@ public class CustomizableGui extends Gui {
@NotNull
public Gui setAction(@NotNull String key, int row, int col, @Nullable Clickable action) {
if (customContent.isButtonDisabled(key)) {
if (this.customContent.isButtonDisabled(key)) {
return this;
}
setConditional(key, col + row * inventoryType.columns, null, action);
setConditional(key, col + row * this.inventoryType.columns, null, action);
return this;
}
@NotNull
public Gui setAction(@NotNull String key, int cell, @Nullable ClickType type, @Nullable Clickable action) {
if (customContent.isButtonDisabled(key)) {
if (this.customContent.isButtonDisabled(key)) {
return this;
}
@ -593,11 +594,11 @@ public class CustomizableGui extends Gui {
@NotNull
public Gui setAction(@NotNull String key, int row, int col, @Nullable ClickType type, @Nullable Clickable action) {
if (customContent.isButtonDisabled(key)) {
if (this.customContent.isButtonDisabled(key)) {
return this;
}
setConditional(key, col + row * inventoryType.columns, type, action);
setConditional(key, col + row * this.inventoryType.columns, type, action);
return this;
}
@ -606,12 +607,12 @@ public class CustomizableGui extends Gui {
public Gui clearActions(@NotNull String key, int cell) {
List<Integer> cells = Collections.singletonList(cell);
if (customContent.isButtonDisabled(key)) {
if (this.customContent.isButtonDisabled(key)) {
return this;
}
if (customContent.isButtonCustomized(key)) {
cells = customContent.getCustomizedButton(key).applyPosition(cell);
if (this.customContent.isButtonCustomized(key)) {
cells = this.customContent.getCustomizedButton(key).applyPosition(cell);
}
for (int c : cells) {
@ -623,25 +624,25 @@ public class CustomizableGui extends Gui {
@NotNull
public Gui clearActions(@NotNull String key, int row, int col) {
if (customContent.isButtonDisabled(key)) {
if (this.customContent.isButtonDisabled(key)) {
return this;
}
return clearActions(key, col + row * inventoryType.columns);
return clearActions(key, col + row * this.inventoryType.columns);
}
@NotNull
public Gui setButton(@NotNull String key, int cell, ItemStack item, @Nullable Clickable action) {
List<Integer> cells = Collections.singletonList(cell);
if (customContent.isButtonDisabled(key)) {
if (this.customContent.isButtonDisabled(key)) {
return this;
}
applyShowGuiKeys(key, item);
if (customContent.isButtonCustomized(key)) {
CustomButton btn = customContent.getCustomizedButton(key);
if (this.customContent.isButtonCustomized(key)) {
CustomButton btn = this.customContent.getCustomizedButton(key);
cells = btn.applyPosition(cell);
btn.applyItem(item);
}
@ -656,25 +657,25 @@ public class CustomizableGui extends Gui {
@NotNull
public Gui setButton(@NotNull String key, int row, int col, @Nullable ItemStack item, @Nullable Clickable action) {
if (customContent.isButtonDisabled(key)) {
if (this.customContent.isButtonDisabled(key)) {
return this;
}
return setButton(key, col + row * inventoryType.columns, item, action);
return setButton(key, col + row * this.inventoryType.columns, item, action);
}
@NotNull
public Gui setButton(@NotNull String key, int cell, @Nullable ItemStack item, @Nullable ClickType type, @Nullable Clickable action) {
List<Integer> cells = Collections.singletonList(cell);
if (customContent.isButtonDisabled(key)) {
if (this.customContent.isButtonDisabled(key)) {
return this;
}
applyShowGuiKeys(key, item);
if (customContent.isButtonCustomized(key)) {
CustomButton btn = customContent.getCustomizedButton(key);
if (this.customContent.isButtonCustomized(key)) {
CustomButton btn = this.customContent.getCustomizedButton(key);
cells = btn.applyPosition(cell);
btn.applyItem(item);
}
@ -688,22 +689,22 @@ public class CustomizableGui extends Gui {
@NotNull
public Gui setButton(@NotNull String key, int row, int col, @Nullable ItemStack item, @Nullable ClickType type, @Nullable Clickable action) {
if (customContent.isButtonDisabled(key)) {
if (this.customContent.isButtonDisabled(key)) {
return this;
}
return setButton(key, col + row + inventoryType.columns, item, type, action);
return setButton(key, col + row + this.inventoryType.columns, item, type, action);
}
protected void setConditional(@NotNull String key, int cell, @Nullable ClickType type, @Nullable Clickable action) {
List<Integer> cells = Collections.singletonList(cell);
if (customContent.isButtonDisabled(key)) {
if (this.customContent.isButtonDisabled(key)) {
return;
}
if (customContent.isButtonCustomized(key)) {
cells = customContent.getCustomizedButton(key).applyPosition(cell);
if (this.customContent.isButtonCustomized(key)) {
cells = this.customContent.getCustomizedButton(key).applyPosition(cell);
}
for (int c : cells) {
@ -714,8 +715,8 @@ public class CustomizableGui extends Gui {
public Gui setNextPage(ItemStack item) {
applyShowGuiKeys("__NEXT__", item);
if (customContent.isButtonCustomized("__NEXT__")) {
customContent.getCustomizedButton("__NEXT__").applyItem(item);
if (this.customContent.isButtonCustomized("__NEXT__")) {
this.customContent.getCustomizedButton("__NEXT__").applyItem(item);
}
return super.setNextPage(item);
@ -724,8 +725,8 @@ public class CustomizableGui extends Gui {
public Gui setPrevPage(ItemStack item) {
applyShowGuiKeys("__PREV__", item);
if (customContent.isButtonCustomized("__PREV__")) {
customContent.getCustomizedButton("__PREV__").applyItem(item);
if (this.customContent.isButtonCustomized("__PREV__")) {
this.customContent.getCustomizedButton("__PREV__").applyItem(item);
}
return super.setPrevPage(item);
@ -737,8 +738,8 @@ public class CustomizableGui extends Gui {
applyShowGuiKeys("__NEXT__", item);
if (customContent.isButtonCustomized("__NEXT__")) {
CustomButton btn = customContent.getCustomizedButton("__NEXT__");
if (this.customContent.isButtonCustomized("__NEXT__")) {
CustomButton btn = this.customContent.getCustomizedButton("__NEXT__");
cells = btn.applyPosition(cell);
btn.applyItem(item);
}
@ -754,7 +755,7 @@ public class CustomizableGui extends Gui {
public Gui setNextPage(int row, int col, @NotNull ItemStack item) {
applyShowGuiKeys("__NEXT__", item);
return setNextPage(col + row * inventoryType.columns, item);
return setNextPage(col + row * this.inventoryType.columns, item);
}
@NotNull
@ -763,8 +764,8 @@ public class CustomizableGui extends Gui {
applyShowGuiKeys("__PREV__", item);
if (customContent.isButtonCustomized("__PREV__")) {
CustomButton btn = customContent.getCustomizedButton("__PREV__");
if (this.customContent.isButtonCustomized("__PREV__")) {
CustomButton btn = this.customContent.getCustomizedButton("__PREV__");
cells = btn.applyPosition(cell);
btn.applyItem(item);
}
@ -780,7 +781,7 @@ public class CustomizableGui extends Gui {
public Gui setPrevPage(int row, int col, @NotNull ItemStack item) {
applyShowGuiKeys("__PREV__", item);
return setPrevPage(col + row * inventoryType.columns, item);
return setPrevPage(col + row * this.inventoryType.columns, item);
}
private boolean applyShowGuiKeys(String key, ItemStack item) {
@ -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;
@ -849,7 +850,7 @@ public class CustomizableGui extends Gui {
}
public String getKey() {
return key;
return this.key;
}
public boolean applyItem(ItemStack item) {
@ -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;
@ -878,23 +879,23 @@ public class CustomizableGui extends Gui {
private void applyMeta(ItemStack item) {
ItemMeta meta = item.getItemMeta();
if (title != null) {
meta.setDisplayName(TextUtils.formatText(title));
if (this.title != null) {
meta.setDisplayName(TextUtils.formatText(this.title));
}
if (lore != null) {
meta.setLore(TextUtils.formatText(lore));
if (this.lore != null) {
meta.setLore(TextUtils.formatText(this.lore));
}
item.setItemMeta(meta);
}
public List<Integer> applyPosition(int cell) {
if (row != -1 && col != -1) {
return Collections.singletonList(col + row * inventoryType.columns);
if (this.row != -1 && this.col != -1) {
return Collections.singletonList(this.col + this.row * CustomizableGui.this.inventoryType.columns);
}
return positions == null ? Collections.singletonList(cell) : positions;
return this.positions == null ? Collections.singletonList(cell) : this.positions;
}
public int applyPositionRow(int row) {
@ -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;
@ -918,11 +919,11 @@ public class CustomizableGui extends Gui {
}
public boolean isMirrorRow() {
return mirrorRow;
return this.mirrorRow;
}
public boolean isMirrorCol() {
return mirrorCol;
return this.mirrorCol;
}
}
@ -939,22 +940,22 @@ public class CustomizableGui extends Gui {
}
public String getGuiKey() {
return guiKey;
return this.guiKey;
}
public CustomButton getCustomizedButton(String key) {
return customizedButtons.get(key);
return this.customizedButtons.get(key);
}
public CustomButton getCustomButton(String key) {
return customizedButtons.get(key);
return this.customizedButtons.get(key);
}
public Map<String, CustomButton> getCustomButtons() {
return Collections.unmodifiableMap(customButtons);
return Collections.unmodifiableMap(this.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());
@ -962,49 +963,49 @@ public class CustomizableGui extends Gui {
CustomButton customButton = new CustomButton(key, positions, title, lore, item);
if (key.startsWith("custom_")) {
customButtons.put(key, customButton);
this.customButtons.put(key, customButton);
return;
}
customizedButtons.put(key, customButton);
this.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_")) {
customButtons.put(key, customButton);
this.customButtons.put(key, customButton);
return;
}
customizedButtons.put(key, customButton);
this.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_")) {
customButtons.put(key, mirrorFill);
this.customButtons.put(key, mirrorFill);
return;
}
customizedButtons.put(key, mirrorFill);
this.customizedButtons.put(key, mirrorFill);
}
public boolean isButtonCustomized(String key) {
return customizedButtons.containsKey(key);
return this.customizedButtons.containsKey(key);
}
public void disableButton(String button) {
disabledButtons.add(button);
this.disabledButtons.add(button);
}
public boolean isButtonDisabled(String button) {
return disabledButtons.contains(button);
return this.disabledButtons.contains(button);
}
public int getRows() {
return rows;
return this.rows;
}
public void setRows(int rows) {

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;
@ -32,31 +32,31 @@ public class DoubleGui extends Gui {
public DoubleGui() {
super(GuiType.STANDARD);
allowDropItems = false;
this.allowDropItems = false;
}
public DoubleGui(GuiType type) {
super(type);
allowDropItems = false;
this.allowDropItems = false;
}
public DoubleGui(int rows) {
super(rows);
allowDropItems = false;
this.allowDropItems = false;
}
public DoubleGui(int rows, Gui parent) {
super(rows, parent);
allowDropItems = false;
this.allowDropItems = false;
}
public DoubleGui(Gui parent) {
super(parent);
allowDropItems = false;
this.allowDropItems = false;
}
public int getPlayerRows() {
return playerRows;
return this.playerRows;
}
// 9 -> 0 -> 54
@ -78,29 +78,29 @@ public class DoubleGui extends Gui {
}
public DoubleGui setPlayerUnlocked(int cell) {
unlockedCells.put(invOffset(cell), true);
this.unlockedCells.put(invOffset(cell), true);
return this;
}
public DoubleGui setPlayerUnlocked(int row, int col) {
unlockedCells.put(invOffset(col + row * 9), true);
this.unlockedCells.put(invOffset(col + row * 9), true);
return this;
}
public DoubleGui setPlayerUnlocked(int cell, boolean open) {
unlockedCells.put(invOffset(cell), open);
this.unlockedCells.put(invOffset(cell), open);
return this;
}
public DoubleGui setPlayerUnlocked(int row, int col, boolean open) {
unlockedCells.put(invOffset(col + row * 9), open);
this.unlockedCells.put(invOffset(col + row * 9), open);
return this;
}
public DoubleGui setPlayerUnlockedRange(int cellFirst, int cellLast) {
final int last = invOffset(cellLast);
for (int cell = invOffset(cellFirst); cell <= last; ++cell) {
unlockedCells.put(cell, true);
this.unlockedCells.put(cell, true);
}
return this;
}
@ -109,7 +109,7 @@ public class DoubleGui extends Gui {
final int last = invOffset(cellLast);
for (int cell = invOffset(cellFirst); cell <= last; ++cell) {
unlockedCells.put(cell, open);
this.unlockedCells.put(cell, open);
}
return this;
@ -119,7 +119,7 @@ public class DoubleGui extends Gui {
final int last = invOffset(cellColLast + cellRowLast * 9);
for (int cell = invOffset(cellColFirst + cellRowFirst * 9); cell <= last; ++cell) {
unlockedCells.put(cell, true);
this.unlockedCells.put(cell, true);
}
return this;
@ -129,19 +129,19 @@ public class DoubleGui extends Gui {
final int last = invOffset(cellColLast + cellRowLast * 9);
for (int cell = invOffset(cellColFirst + cellRowFirst * 9); cell <= last; ++cell) {
unlockedCells.put(cell, open);
this.unlockedCells.put(cell, open);
}
return this;
}
public DoubleGui setPlayerItem(int cell, ItemStack item) {
cellItems.put(invOffset(cell), item);
this.cellItems.put(invOffset(cell), item);
if (open && cell >= 0 && cell < 36) {
if (this.open && cell >= 0 && cell < 36) {
cell = cell >= 27 ? cell - 27 : cell + 9;
for (HumanEntity e : inventory.getViewers()) {
for (HumanEntity e : this.inventory.getViewers()) {
e.getInventory().setItem(cell, item);
}
}
@ -151,12 +151,12 @@ public class DoubleGui extends Gui {
public DoubleGui setPlayerItem(int row, int col, ItemStack item) {
int cell = col + row * 9;
cellItems.put(invOffset(cell), item);
this.cellItems.put(invOffset(cell), item);
if (open && cell >= 0 && cell < 36) {
if (this.open && cell >= 0 && cell < 36) {
cell = cell >= 27 ? cell - 27 : cell + 9;
for (HumanEntity e : inventory.getViewers()) {
for (HumanEntity e : this.inventory.getViewers()) {
e.getInventory().setItem(cell, item);
}
}
@ -166,7 +166,7 @@ public class DoubleGui extends Gui {
public DoubleGui highlightPlayerItem(int cell) {
final int invCell = invOffset(cell);
ItemStack item = cellItems.get(invCell);
ItemStack item = this.cellItems.get(invCell);
if (item != null) {
setPlayerItem(cell, ItemUtils.addGlow(item));
@ -179,7 +179,7 @@ public class DoubleGui extends Gui {
final int cell = col + row * 9;
final int invCell = invOffset(cell);
ItemStack item = cellItems.get(invCell);
ItemStack item = this.cellItems.get(invCell);
if (item != null) {
setPlayerItem(cell, ItemUtils.addGlow(item));
}
@ -244,13 +244,13 @@ public class DoubleGui extends Gui {
}
public DoubleGui clearPlayerActions(int cell) {
conditionalButtons.remove(invOffset(cell));
this.conditionalButtons.remove(invOffset(cell));
return this;
}
public DoubleGui clearPlayerActions(int row, int col) {
final int cell = invOffset(col + row * 9);
conditionalButtons.remove(cell);
this.conditionalButtons.remove(cell);
return this;
}
@ -290,7 +290,7 @@ public class DoubleGui extends Gui {
@Override
protected boolean onClickPlayerInventory(GuiManager manager, Player player, Inventory openInv, InventoryClickEvent event) {
final int cell = event.getSlot(), offsetCell = clickOffset(cell);
Map<ClickType, Clickable> conditionals = conditionalButtons.get(offsetCell);
Map<ClickType, Clickable> conditionals = this.conditionalButtons.get(offsetCell);
Clickable button;
if (conditionals != null
@ -301,15 +301,15 @@ public class DoubleGui extends Gui {
return false;
}
event.setCancelled(unlockedCells.entrySet().stream().noneMatch(e -> offsetCell == e.getKey() && e.getValue()));
event.setCancelled(this.unlockedCells.entrySet().stream().noneMatch(e -> offsetCell == e.getKey() && e.getValue()));
return true;
}
@Override
protected boolean onClickOutside(GuiManager manager, Player player, InventoryClickEvent event) {
if (dropper != null) {
return dropper.onDrop(new GuiDropItemEvent(manager, this, player, event));
if (this.dropper != null) {
return this.dropper.onDrop(new GuiDropItemEvent(manager, this, player, event));
}
// do not allow by default
@ -319,7 +319,7 @@ public class DoubleGui extends Gui {
@Override
public void onOpen(GuiManager manager, Player player) {
// replace the player's inventory
if (startStashed) {
if (this.startStashed) {
stashItems(player);
}
@ -337,15 +337,15 @@ public class DoubleGui extends Gui {
}
protected void restoreStash(Player player) {
if (stash.containsKey(player)) {
player.getInventory().setContents(stash.remove(player));
if (this.stash.containsKey(player)) {
player.getInventory().setContents(this.stash.remove(player));
player.updateInventory();
}
}
protected void stashItems(Player player) {
if (!stash.containsKey(player)) {
stash.put(player, player.getInventory().getContents().clone());
if (!this.stash.containsKey(player)) {
this.stash.put(player, player.getInventory().getContents().clone());
player.getInventory().clear();
}
}
@ -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

@ -1,5 +1,6 @@
package com.craftaro.core.gui;
import com.craftaro.core.compatibility.ServerVersion;
import com.craftaro.core.gui.events.GuiClickEvent;
import com.craftaro.core.gui.events.GuiCloseEvent;
import com.craftaro.core.gui.events.GuiDropItemEvent;
@ -11,9 +12,8 @@ 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 com.cryptomorin.xseries.XSound;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.ClickType;
@ -50,7 +50,7 @@ public class Gui {
protected ItemStack nextPageItem, prevPageItem;
protected ItemStack nextPage, prevPage;
protected Gui parent = null;
protected static ItemStack AIR = new ItemStack(Material.AIR);
protected static final ItemStack AIR = new ItemStack(Material.AIR);
protected GuiManager guiManager;
protected boolean open = false;
@ -60,7 +60,7 @@ public class Gui {
protected Closable closer = null;
protected Droppable dropper = null;
protected Pagable pager = null;
protected CompatibleSound defaultSound = CompatibleSound.UI_BUTTON_CLICK;
protected XSound defaultSound = XSound.UI_BUTTON_CLICK;
public Gui() {
this.rows = 3;
@ -69,6 +69,7 @@ public class Gui {
public Gui(@NotNull GuiType type) {
this.inventoryType = type;
switch (type) {
case HOPPER:
case DISPENSER:
@ -95,11 +96,11 @@ public class Gui {
@NotNull
public List<Player> getPlayers() {
if (inventory == null) {
if (this.inventory == null) {
return Collections.emptyList();
}
return inventory.getViewers().stream()
return this.inventory.getViewers().stream()
.filter(Player.class::isInstance)
.map(Player.class::cast)
.collect(Collectors.toList());
@ -107,15 +108,15 @@ public class Gui {
public boolean isOpen() {
// double check
if (inventory != null && inventory.getViewers().isEmpty()) {
open = false;
if (this.inventory != null && this.inventory.getViewers().isEmpty()) {
this.open = false;
}
return open;
return this.open;
}
public boolean getAcceptsItems() {
return acceptsItems;
return this.acceptsItems;
}
public Gui setAcceptsItems(boolean acceptsItems) {
@ -128,7 +129,7 @@ public class Gui {
* will be cleared
*/
public boolean getAllowDrops() {
return allowDropItems;
return this.allowDropItems;
}
/**
@ -141,7 +142,7 @@ public class Gui {
}
public boolean getAllowClose() {
return allowClose;
return this.allowClose;
}
public Gui setAllowClose(boolean allow) {
@ -154,10 +155,10 @@ public class Gui {
* GUIs
*/
public void exit() {
allowClose = true;
open = false;
this.allowClose = true;
this.open = false;
inventory.getViewers().stream()
this.inventory.getViewers().stream()
.filter(Player.class::isInstance)
.map(Player.class::cast)
.collect(Collectors.toList())
@ -168,9 +169,9 @@ public class Gui {
* Close the GUI as if the player closed it normally
*/
public void close() {
allowClose = true;
this.allowClose = true;
inventory.getViewers().stream()
this.inventory.getViewers().stream()
.filter(Player.class::isInstance)
.map(Player.class::cast)
.collect(Collectors.toList())
@ -179,19 +180,19 @@ public class Gui {
@NotNull
public GuiType getType() {
return inventoryType;
return this.inventoryType;
}
@NotNull
public Gui setUnlocked(int cell) {
unlockedCells.put(cell, true);
this.unlockedCells.put(cell, true);
return this;
}
@NotNull
public Gui setUnlocked(int row, int col) {
final int cell = col + row * inventoryType.columns;
unlockedCells.put(cell, true);
final int cell = col + row * this.inventoryType.columns;
this.unlockedCells.put(cell, true);
return this;
}
@ -199,7 +200,7 @@ public class Gui {
@NotNull
public Gui setUnlockedRange(int cellFirst, int cellLast) {
for (int cell = cellFirst; cell <= cellLast; ++cell) {
unlockedCells.put(cell, true);
this.unlockedCells.put(cell, true);
}
return this;
@ -208,7 +209,7 @@ public class Gui {
@NotNull
public Gui setUnlockedRange(int cellFirst, int cellLast, boolean open) {
for (int cell = cellFirst; cell <= cellLast; ++cell) {
unlockedCells.put(cell, open);
this.unlockedCells.put(cell, open);
}
return this;
@ -216,10 +217,10 @@ public class Gui {
@NotNull
public Gui setUnlockedRange(int cellRowFirst, int cellColFirst, int cellRowLast, int cellColLast) {
final int last = cellColLast + cellRowLast * inventoryType.columns;
final int last = cellColLast + cellRowLast * this.inventoryType.columns;
for (int cell = cellColFirst + cellRowFirst * inventoryType.columns; cell <= last; ++cell) {
unlockedCells.put(cell, true);
for (int cell = cellColFirst + cellRowFirst * this.inventoryType.columns; cell <= last; ++cell) {
this.unlockedCells.put(cell, true);
}
return this;
@ -227,10 +228,10 @@ public class Gui {
@NotNull
public Gui setUnlockedRange(int cellRowFirst, int cellColFirst, int cellRowLast, int cellColLast, boolean open) {
final int last = cellColLast + cellRowLast * inventoryType.columns;
final int last = cellColLast + cellRowLast * this.inventoryType.columns;
for (int cell = cellColFirst + cellRowFirst * inventoryType.columns; cell <= last; ++cell) {
unlockedCells.put(cell, open);
for (int cell = cellColFirst + cellRowFirst * this.inventoryType.columns; cell <= last; ++cell) {
this.unlockedCells.put(cell, open);
}
return this;
@ -238,14 +239,14 @@ public class Gui {
@NotNull
public Gui setUnlocked(int cell, boolean open) {
unlockedCells.put(cell, open);
this.unlockedCells.put(cell, open);
return this;
}
@NotNull
public Gui setUnlocked(int row, int col, boolean open) {
final int cell = col + row * inventoryType.columns;
unlockedCells.put(cell, open);
final int cell = col + row * this.inventoryType.columns;
this.unlockedCells.put(cell, open);
return this;
}
@ -259,19 +260,19 @@ public class Gui {
if (!title.equals(this.title)) {
this.title = title;
if (inventory != null) {
if (this.inventory != null) {
// update active inventory
List<Player> toUpdate = getPlayers();
boolean isAllowClose = allowClose;
boolean isAllowClose = this.allowClose;
exit();
Inventory oldInv = inventory;
Inventory oldInv = this.inventory;
createInventory();
inventory.setContents(oldInv.getContents());
this.inventory.setContents(oldInv.getContents());
toUpdate.forEach(player -> player.openInventory(inventory));
toUpdate.forEach(player -> player.openInventory(this.inventory));
allowClose = isAllowClose;
this.allowClose = isAllowClose;
}
}
@ -279,12 +280,12 @@ public class Gui {
}
public int getRows() {
return rows;
return this.rows;
}
@NotNull
public Gui setRows(int rows) {
switch (inventoryType) {
switch (this.inventoryType) {
case HOPPER:
case DISPENSER:
break;
@ -298,53 +299,53 @@ public class Gui {
@NotNull
public Gui setDefaultAction(@Nullable Clickable action) {
defaultClicker = action;
this.defaultClicker = action;
return this;
}
@NotNull
protected Gui setPrivateDefaultAction(@Nullable Clickable action) {
privateDefaultClicker = action;
this.privateDefaultClicker = action;
return this;
}
@NotNull
public Gui setDefaultItem(@Nullable ItemStack item) {
blankItem = item;
this.blankItem = item;
return this;
}
@Nullable
public ItemStack getDefaultItem() {
return blankItem;
return this.blankItem;
}
@Nullable
public ItemStack getItem(int cell) {
if (inventory != null && unlockedCells.getOrDefault(cell, false)) {
return inventory.getItem(cell);
if (this.inventory != null && this.unlockedCells.getOrDefault(cell, false)) {
return this.inventory.getItem(cell);
}
return cellItems.get(cell);
return this.cellItems.get(cell);
}
@Nullable
public ItemStack getItem(int row, int col) {
final int cell = col + row * inventoryType.columns;
final int cell = col + row * this.inventoryType.columns;
if (inventory != null && unlockedCells.getOrDefault(cell, false)) {
return inventory.getItem(cell);
if (this.inventory != null && this.unlockedCells.getOrDefault(cell, false)) {
return this.inventory.getItem(cell);
}
return cellItems.get(cell);
return this.cellItems.get(cell);
}
@NotNull
public Gui setItem(int cell, @Nullable ItemStack item) {
cellItems.put(cell, item);
this.cellItems.put(cell, item);
if (inventory != null && cell >= 0 && cell < inventory.getSize()) {
inventory.setItem(cell, item);
if (this.inventory != null && cell >= 0 && cell < this.inventory.getSize()) {
this.inventory.setItem(cell, item);
}
return this;
@ -352,7 +353,7 @@ public class Gui {
@NotNull
public Gui setItem(int row, int col, @Nullable ItemStack item) {
final int cell = col + row * inventoryType.columns;
final int cell = col + row * this.inventoryType.columns;
return setItem(cell, item);
}
@ -361,7 +362,7 @@ public class Gui {
setItem(row, col, item);
if (mirrorRow) {
setItem(rows - row - 1, col, item);
setItem(this.rows - row - 1, col, item);
}
if (mirrorCol) {
@ -369,7 +370,7 @@ public class Gui {
}
if (mirrorRow && mirrorCol) {
setItem(rows - row - 1, 8 - col, item);
setItem(this.rows - row - 1, 8 - col, item);
}
return this;
@ -377,7 +378,7 @@ public class Gui {
@NotNull
public Gui highlightItem(int cell) {
ItemStack item = cellItems.get(cell);
ItemStack item = this.cellItems.get(cell);
if (item != null && item.getType() != Material.AIR) {
setItem(cell, ItemUtils.addGlow(item));
@ -388,14 +389,14 @@ public class Gui {
@NotNull
public Gui highlightItem(int row, int col) {
final int cell = col + row * inventoryType.columns;
final int cell = col + row * this.inventoryType.columns;
return highlightItem(cell);
}
@NotNull
public Gui removeHighlight(int cell) {
ItemStack item = cellItems.get(cell);
ItemStack item = this.cellItems.get(cell);
if (item != null && item.getType() != Material.AIR) {
setItem(cell, ItemUtils.removeGlow(item));
@ -406,18 +407,18 @@ public class Gui {
@NotNull
public Gui removeHighlight(int row, int col) {
final int cell = col + row * inventoryType.columns;
final int cell = col + row * this.inventoryType.columns;
return removeHighlight(cell);
}
@NotNull
public Gui updateItemLore(int row, int col, @NotNull String... lore) {
return updateItemLore(col + row * inventoryType.columns, lore);
return updateItemLore(col + row * this.inventoryType.columns, lore);
}
@NotNull
public Gui updateItemLore(int cell, @NotNull String... lore) {
ItemStack item = cellItems.get(cell);
ItemStack item = this.cellItems.get(cell);
if (item != null && item.getType() != Material.AIR) {
setItem(cell, GuiUtils.updateItemLore(item, lore));
@ -428,12 +429,12 @@ public class Gui {
@NotNull
public Gui updateItemLore(int row, int col, @Nullable List<String> lore) {
return updateItemLore(col + row * inventoryType.columns, lore);
return updateItemLore(col + row * this.inventoryType.columns, lore);
}
@NotNull
public Gui updateItemLore(int cell, @Nullable List<String> lore) {
ItemStack item = cellItems.get(cell);
ItemStack item = this.cellItems.get(cell);
if (item != null && item.getType() != Material.AIR) {
setItem(cell, GuiUtils.updateItemLore(item, lore));
@ -444,12 +445,12 @@ public class Gui {
@NotNull
public Gui updateItemName(int row, int col, @Nullable String name) {
return updateItemName(col + row * inventoryType.columns, name);
return updateItemName(col + row * this.inventoryType.columns, name);
}
@NotNull
public Gui updateItemName(int cell, @Nullable String name) {
ItemStack item = cellItems.get(cell);
ItemStack item = this.cellItems.get(cell);
if (item != null && item.getType() != Material.AIR) {
setItem(cell, GuiUtils.updateItemName(item, name));
@ -460,7 +461,7 @@ public class Gui {
@NotNull
public Gui updateItem(int row, int col, @Nullable String name, @NotNull String... lore) {
return updateItem(col + row * inventoryType.columns, name, lore);
return updateItem(col + row * this.inventoryType.columns, name, lore);
}
@NotNull
@ -470,12 +471,12 @@ public class Gui {
@NotNull
public Gui updateItem(int row, int col, @Nullable String name, @Nullable List<String> lore) {
return updateItem(col + row * inventoryType.columns, name, lore);
return updateItem(col + row * this.inventoryType.columns, name, lore);
}
@NotNull
public Gui updateItem(int cell, @NotNull String name, @Nullable List<String> lore) {
ItemStack item = cellItems.get(cell);
ItemStack item = this.cellItems.get(cell);
if (item != null && item.getType() != Material.AIR) {
setItem(cell, GuiUtils.updateItem(item, name, lore));
@ -486,12 +487,12 @@ public class Gui {
@NotNull
public Gui updateItem(int row, int col, @NotNull ItemStack itemTo, @Nullable String title, @NotNull String... lore) {
return updateItem(col + row * inventoryType.columns, itemTo, title, lore);
return updateItem(col + row * this.inventoryType.columns, itemTo, title, lore);
}
@NotNull
public Gui updateItem(int cell, @NotNull ItemStack itemTo, @Nullable String title, @NotNull String... lore) {
ItemStack item = cellItems.get(cell);
ItemStack item = this.cellItems.get(cell);
if (item != null && item.getType() != Material.AIR) {
setItem(cell, GuiUtils.updateItem(item, itemTo, title, lore));
@ -501,13 +502,13 @@ public class Gui {
}
@NotNull
public Gui updateItem(int row, int col, @NotNull CompatibleMaterial itemTo, @Nullable String title, @NotNull String... lore) {
return updateItem(col + row * inventoryType.columns, itemTo, title, lore);
public Gui updateItem(int row, int col, @NotNull XMaterial itemTo, @Nullable String title, @NotNull String... lore) {
return updateItem(col + row * this.inventoryType.columns, itemTo, title, lore);
}
@NotNull
public Gui updateItem(int cell, @NotNull CompatibleMaterial itemTo, @Nullable String title, @Nullable String... lore) {
ItemStack item = cellItems.get(cell);
public Gui updateItem(int cell, @NotNull XMaterial itemTo, @Nullable String title, @Nullable String... lore) {
ItemStack item = this.cellItems.get(cell);
if (item != null && item.getType() != Material.AIR) {
setItem(cell, GuiUtils.updateItem(item, itemTo, title, lore));
@ -518,12 +519,12 @@ public class Gui {
@NotNull
public Gui updateItem(int row, int col, @NotNull ItemStack itemTo, @Nullable String title, @Nullable List<String> lore) {
return updateItem(col + row * inventoryType.columns, itemTo, title, lore);
return updateItem(col + row * this.inventoryType.columns, itemTo, title, lore);
}
@NotNull
public Gui updateItem(int cell, @NotNull ItemStack itemTo, @Nullable String title, @Nullable List<String> lore) {
ItemStack item = cellItems.get(cell);
ItemStack item = this.cellItems.get(cell);
if (item != null && item.getType() != Material.AIR) {
setItem(cell, GuiUtils.updateItem(item, itemTo, title, lore));
@ -533,13 +534,13 @@ public class Gui {
}
@NotNull
public Gui updateItem(int row, int col, @NotNull CompatibleMaterial itemTo, @Nullable String title, @Nullable List<String> lore) {
return updateItem(col + row * inventoryType.columns, itemTo, title, lore);
public Gui updateItem(int row, int col, @NotNull XMaterial itemTo, @Nullable String title, @Nullable List<String> lore) {
return updateItem(col + row * this.inventoryType.columns, itemTo, title, lore);
}
@NotNull
public Gui updateItem(int cell, @NotNull CompatibleMaterial itemTo, @Nullable String title, @Nullable List<String> lore) {
ItemStack item = cellItems.get(cell);
public Gui updateItem(int cell, @NotNull XMaterial itemTo, @Nullable String title, @Nullable List<String> lore) {
ItemStack item = this.cellItems.get(cell);
if (item != null && item.getType() != Material.AIR) {
setItem(cell, GuiUtils.updateItem(item, itemTo, title, lore));
@ -556,7 +557,7 @@ public class Gui {
@NotNull
public Gui setAction(int row, int col, @Nullable Clickable action) {
setConditional(col + row * inventoryType.columns, null, action);
setConditional(col + row * this.inventoryType.columns, null, action);
return this;
}
@ -568,7 +569,7 @@ public class Gui {
@NotNull
public Gui setAction(int row, int col, @Nullable ClickType type, @Nullable Clickable action) {
setConditional(col + row * inventoryType.columns, type, action);
setConditional(col + row * this.inventoryType.columns, type, action);
return this;
}
@ -583,9 +584,9 @@ public class Gui {
@NotNull
public Gui setActionForRange(int cellRowFirst, int cellColFirst, int cellRowLast, int cellColLast, @Nullable Clickable action) {
final int last = cellColLast + cellRowLast * inventoryType.columns;
final int last = cellColLast + cellRowLast * this.inventoryType.columns;
for (int cell = cellColFirst + cellRowFirst * inventoryType.columns; cell <= last; ++cell) {
for (int cell = cellColFirst + cellRowFirst * this.inventoryType.columns; cell <= last; ++cell) {
setConditional(cell, null, action);
}
@ -603,9 +604,9 @@ public class Gui {
@NotNull
public Gui setActionForRange(int cellRowFirst, int cellColFirst, int cellRowLast, int cellColLast, @Nullable ClickType type, @Nullable Clickable action) {
final int last = cellColLast + cellRowLast * inventoryType.columns;
final int last = cellColLast + cellRowLast * this.inventoryType.columns;
for (int cell = cellColFirst + cellRowFirst * inventoryType.columns; cell <= last; ++cell) {
for (int cell = cellColFirst + cellRowFirst * this.inventoryType.columns; cell <= last; ++cell) {
setConditional(cell, type, action);
}
@ -614,13 +615,13 @@ public class Gui {
@NotNull
public Gui clearActions(int cell) {
conditionalButtons.remove(cell);
this.conditionalButtons.remove(cell);
return this;
}
@NotNull
public Gui clearActions(int row, int col) {
return clearActions(col + row * inventoryType.columns);
return clearActions(col + row * this.inventoryType.columns);
}
@NotNull
@ -633,7 +634,7 @@ public class Gui {
@NotNull
public Gui setButton(int row, int col, @Nullable ItemStack item, @Nullable Clickable action) {
final int cell = col + row * inventoryType.columns;
final int cell = col + row * this.inventoryType.columns;
setItem(cell, item);
setConditional(cell, null, action);
@ -651,7 +652,7 @@ public class Gui {
@NotNull
public Gui setButton(int row, int col, @Nullable ItemStack item, @Nullable ClickType type, @Nullable Clickable action) {
final int cell = col + row * inventoryType.columns;
final int cell = col + row * this.inventoryType.columns;
setItem(cell, item);
setConditional(cell, type, action);
@ -660,62 +661,62 @@ public class Gui {
}
protected void setConditional(int cell, @Nullable ClickType type, @Nullable Clickable action) {
Map<ClickType, Clickable> conditionals = conditionalButtons.computeIfAbsent(cell, k -> new HashMap<>());
Map<ClickType, Clickable> conditionals = this.conditionalButtons.computeIfAbsent(cell, k -> new HashMap<>());
conditionals.put(type, action);
}
@NotNull
public Gui setOnOpen(@Nullable Openable action) {
opener = action;
this.opener = action;
return this;
}
@NotNull
public Gui setOnClose(@Nullable Closable action) {
closer = action;
this.closer = action;
return this;
}
@NotNull
public Gui setOnDrop(@Nullable Droppable action) {
dropper = action;
this.dropper = action;
return this;
}
@NotNull
public Gui setOnPage(@Nullable Pagable action) {
pager = action;
this.pager = action;
return this;
}
public Gui setNextPage(ItemStack item) {
nextPage = item;
this.nextPage = item;
return this;
}
public Gui setPrevPage(ItemStack item) {
prevPage = item;
this.prevPage = item;
return this;
}
public void reset() {
if (inventory != null) {
inventory.clear();
if (this.inventory != null) {
this.inventory.clear();
}
setActionForRange(0, 53, null);
cellItems.clear();
this.cellItems.clear();
update();
}
@NotNull
public Gui setNextPage(int cell, @NotNull ItemStack item) {
nextPageItem = cellItems.get(cell);
nextPageIndex = cell;
nextPage = item;
this.nextPageItem = this.cellItems.get(cell);
this.nextPageIndex = cell;
this.nextPage = item;
if (page < pages) {
setButton(nextPageIndex, nextPage, ClickType.LEFT, (event) -> this.nextPage());
if (this.page < this.pages) {
setButton(this.nextPageIndex, this.nextPage, ClickType.LEFT, (event) -> this.nextPage());
}
return this;
@ -723,17 +724,17 @@ public class Gui {
@NotNull
public Gui setNextPage(int row, int col, @NotNull ItemStack item) {
return setNextPage(col + row * inventoryType.columns, item);
return setNextPage(col + row * this.inventoryType.columns, item);
}
@NotNull
public Gui setPrevPage(int cell, @NotNull ItemStack item) {
prevPageItem = cellItems.get(cell);
prevPageIndex = cell;
prevPage = item;
this.prevPageItem = this.cellItems.get(cell);
this.prevPageIndex = cell;
this.prevPage = item;
if (page > 1) {
setButton(prevPageIndex, prevPage, ClickType.LEFT, (event) -> this.prevPage());
if (this.page > 1) {
setButton(this.prevPageIndex, this.prevPage, ClickType.LEFT, (event) -> this.prevPage());
}
return this;
@ -741,23 +742,23 @@ public class Gui {
@NotNull
public Gui setPrevPage(int row, int col, @NotNull ItemStack item) {
return setPrevPage(col + row * inventoryType.columns, item);
return setPrevPage(col + row * this.inventoryType.columns, item);
}
public void setPages(int pages) {
this.pages = Math.max(1, pages);
if (page > pages) {
if (this.page > pages) {
setPage(pages);
}
}
public void setPage(int page) {
int lastPage = this.page;
this.page = Math.max(1, Math.min(pages, page));
this.page = Math.max(1, Math.min(this.pages, page));
if (pager != null && this.page != lastPage) {
pager.onPageChange(new GuiPageEvent(this, guiManager, lastPage, page));
if (this.pager != null && this.page != lastPage) {
this.pager.onPageChange(new GuiPageEvent(this, this.guiManager, lastPage, page));
// page markers
updatePageNavigation();
@ -765,11 +766,11 @@ public class Gui {
}
public void changePage(int direction) {
int lastPage = page;
this.page = Math.max(1, Math.min(pages, page + direction));
int lastPage = this.page;
this.page = Math.max(1, Math.min(this.pages, this.page + direction));
if (pager != null && this.page != lastPage) {
pager.onPageChange(new GuiPageEvent(this, guiManager, lastPage, page));
if (this.pager != null && this.page != lastPage) {
this.pager.onPageChange(new GuiPageEvent(this, this.guiManager, lastPage, this.page));
// page markers
updatePageNavigation();
@ -777,13 +778,13 @@ public class Gui {
}
public void nextPage() {
if (page < pages) {
int lastPage = page;
++page;
if (this.page < this.pages) {
int lastPage = this.page;
++this.page;
// page switch events
if (pager != null) {
pager.onPageChange(new GuiPageEvent(this, guiManager, lastPage, page));
if (this.pager != null) {
this.pager.onPageChange(new GuiPageEvent(this, this.guiManager, lastPage, this.page));
// page markers
updatePageNavigation();
@ -796,12 +797,12 @@ public class Gui {
}
public void prevPage() {
if (page > 1) {
int lastPage = page;
--page;
if (this.page > 1) {
int lastPage = this.page;
--this.page;
if (pager != null) {
pager.onPageChange(new GuiPageEvent(this, guiManager, lastPage, page));
if (this.pager != null) {
this.pager.onPageChange(new GuiPageEvent(this, this.guiManager, lastPage, this.page));
// page markers
updatePageNavigation();
@ -814,75 +815,75 @@ public class Gui {
}
protected void updatePageNavigation() {
if (prevPage != null) {
if (page > 1) {
this.setButton(prevPageIndex, prevPage, ClickType.LEFT, (event) -> this.prevPage());
if (this.prevPage != null) {
if (this.page > 1) {
this.setButton(this.prevPageIndex, this.prevPage, ClickType.LEFT, (event) -> this.prevPage());
} else {
this.setItem(prevPageIndex, prevPageItem);
this.clearActions(prevPageIndex);
this.setItem(this.prevPageIndex, this.prevPageItem);
this.clearActions(this.prevPageIndex);
}
}
if (nextPage != null) {
if (pages > 1 && page != pages) {
this.setButton(nextPageIndex, nextPage, ClickType.LEFT, (event) -> this.nextPage());
if (this.nextPage != null) {
if (this.pages > 1 && this.page != this.pages) {
this.setButton(this.nextPageIndex, this.nextPage, ClickType.LEFT, (event) -> this.nextPage());
} else {
this.setItem(nextPageIndex, nextPageItem);
this.clearActions(nextPageIndex);
this.setItem(this.nextPageIndex, this.nextPageItem);
this.clearActions(this.nextPageIndex);
}
}
}
@NotNull
protected Inventory getOrCreateInventory(@NotNull GuiManager manager) {
return inventory != null ? inventory : generateInventory(manager);
return this.inventory != null ? this.inventory : generateInventory(manager);
}
@NotNull
protected Inventory generateInventory(@NotNull GuiManager manager) {
this.guiManager = manager;
final int cells = rows * inventoryType.columns;
final int cells = this.rows * this.inventoryType.columns;
createInventory();
for (int i = 0; i < cells; ++i) {
final ItemStack item = cellItems.get(i);
inventory.setItem(i, item != null ? item : (unlockedCells.getOrDefault(i, false) ? AIR : blankItem));
final ItemStack item = this.cellItems.get(i);
this.inventory.setItem(i, item != null ? item : (this.unlockedCells.getOrDefault(i, false) ? AIR : this.blankItem));
}
return inventory;
return this.inventory;
}
protected void createInventory() {
final InventoryType t = inventoryType == null ? InventoryType.CHEST : inventoryType.type;
final InventoryType t = this.inventoryType == null ? InventoryType.CHEST : this.inventoryType.type;
switch (t) {
case DISPENSER:
case HOPPER:
inventory = new GuiHolder(guiManager, this).newInventory(t,
title == null ? "" : trimTitle(title));
this.inventory = new GuiHolder(this.guiManager, this).newInventory(t,
this.title == null ? "" : trimTitle(this.title));
break;
default:
inventory = new GuiHolder(guiManager, this).newInventory(rows * 9,
title == null ? "" : trimTitle(title));
this.inventory = new GuiHolder(this.guiManager, this).newInventory(this.rows * 9,
this.title == null ? "" : trimTitle(this.title));
break;
}
}
@Nullable
public Gui getParent() {
return parent;
return this.parent;
}
public void update() {
if (inventory == null) {
if (this.inventory == null) {
return;
}
final int cells = rows * inventoryType.columns;
final int cells = this.rows * this.inventoryType.columns;
for (int i = 0; i < cells; ++i) {
final ItemStack item = cellItems.get(i);
inventory.setItem(i, item != null ? item : (unlockedCells.getOrDefault(i, false) ? AIR : blankItem));
final ItemStack item = this.cellItems.get(i);
this.inventory.setItem(i, item != null ? item : (this.unlockedCells.getOrDefault(i, false) ? AIR : this.blankItem));
}
}
@ -899,12 +900,12 @@ public class Gui {
}
protected boolean onClickOutside(@NotNull GuiManager manager, @NotNull Player player, @NotNull InventoryClickEvent event) {
return dropper == null || dropper.onDrop(new GuiDropItemEvent(manager, this, player, event));
return this.dropper == null || this.dropper.onDrop(new GuiDropItemEvent(manager, this, player, event));
}
protected boolean onClick(@NotNull GuiManager manager, @NotNull Player player, @NotNull Inventory inventory, @NotNull InventoryClickEvent event) {
final int cell = event.getSlot();
Map<ClickType, Clickable> conditionals = conditionalButtons.get(cell);
Map<ClickType, Clickable> conditionals = this.conditionalButtons.get(cell);
Clickable button;
if (conditionals != null
@ -912,14 +913,14 @@ public class Gui {
button.onClick(new GuiClickEvent(manager, this, player, event, cell, true));
} else {
// no event for this button
if (defaultClicker != null) {
if (this.defaultClicker != null) {
// this is a default action, not a triggered action
defaultClicker.onClick(new GuiClickEvent(manager, this, player, event, cell, true));
this.defaultClicker.onClick(new GuiClickEvent(manager, this, player, event, cell, true));
}
if (privateDefaultClicker != null) {
if (this.privateDefaultClicker != null) {
// this is a private default action, not a triggered action
privateDefaultClicker.onClick(new GuiClickEvent(manager, this, player, event, cell, true));
this.privateDefaultClicker.onClick(new GuiClickEvent(manager, this, player, event, cell, true));
}
return false;
@ -934,36 +935,36 @@ public class Gui {
}
public void onOpen(@NotNull GuiManager manager, @NotNull Player player) {
open = true;
guiManager = manager;
this.open = true;
this.guiManager = manager;
if (opener != null) {
opener.onOpen(new GuiOpenEvent(manager, this, player));
if (this.opener != null) {
this.opener.onOpen(new GuiOpenEvent(manager, this, player));
}
}
public void onClose(@NotNull GuiManager manager, @NotNull Player player) {
if (!allowClose) {
if (!this.allowClose) {
manager.showGUI(player, this);
return;
}
boolean showParent = open && parent != null;
boolean showParent = this.open && this.parent != null;
if (closer != null) {
closer.onClose(new GuiCloseEvent(manager, this, player));
if (this.closer != null) {
this.closer.onClose(new GuiCloseEvent(manager, this, player));
}
if (showParent) {
manager.showGUI(player, parent);
manager.showGUI(player, this.parent);
}
}
public CompatibleSound getDefaultSound() {
return defaultSound;
public XSound getDefaultSound() {
return this.defaultSound;
}
public void setDefaultSound(CompatibleSound sound) {
defaultSound = sound;
public void setDefaultSound(XSound sound) {
this.defaultSound = sound;
}
}

View File

@ -4,6 +4,7 @@ import org.bukkit.Bukkit;
import org.bukkit.event.inventory.InventoryType;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.InventoryHolder;
import org.jetbrains.annotations.NotNull;
/**
* Internal class for marking an inventory as a GUI inventory
@ -18,12 +19,12 @@ class GuiHolder implements InventoryHolder {
}
@Override
public Inventory getInventory() {
return gui.inventory;
public @NotNull Inventory getInventory() {
return this.gui.inventory;
}
public Gui getGUI() {
return gui;
return this.gui;
}
public Inventory newInventory(int size, String title) {

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;
@ -43,17 +43,17 @@ public class GuiManager {
}
public Plugin getPlugin() {
return plugin;
return this.plugin;
}
/**
* Initialize the GUI handlers
*/
public void init() {
Bukkit.getPluginManager().registerEvents(listener, plugin);
Bukkit.getPluginManager().registerEvents(this.listener, this.plugin);
initialized = true;
shutdown = false;
this.initialized = true;
this.shutdown = false;
}
/**
@ -62,7 +62,7 @@ public class GuiManager {
* @return true if the owning plugin has shutdown
*/
public boolean isClosed() {
return shutdown;
return this.shutdown;
}
/**
@ -72,20 +72,20 @@ public class GuiManager {
* @param gui GUI to use
*/
public void showGUI(Player player, Gui gui) {
if (shutdown) {
if (!plugin.isEnabled()) {
if (this.shutdown) {
if (!this.plugin.isEnabled()) {
return;
}
// recover if reloaded without calling init manually
init();
} else if (!initialized) {
} else if (!this.initialized) {
init();
}
if (gui instanceof AnvilGui) {
// bukkit throws a fit now if you try to set anvil stuff asynchronously
Gui openInv = openInventories.get(player);
Gui openInv = this.openInventories.get(player);
if (openInv != null) {
openInv.open = false;
@ -95,15 +95,15 @@ public class GuiManager {
((AnvilGui) gui).open();
gui.onOpen(this, player);
synchronized (lock) {
openInventories.put(player, gui);
synchronized (this.lock) {
this.openInventories.put(player, gui);
}
return;
}
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
Gui openInv = openInventories.get(player);
Bukkit.getScheduler().runTaskAsynchronously(this.plugin, () -> {
Gui openInv = this.openInventories.get(player);
if (openInv != null) {
openInv.open = false;
@ -111,32 +111,32 @@ public class GuiManager {
Inventory inv = gui.getOrCreateInventory(this);
Bukkit.getScheduler().runTask(plugin, () -> {
Bukkit.getScheduler().runTask(this.plugin, () -> {
player.openInventory(inv);
gui.onOpen(this, player);
synchronized (lock) {
openInventories.put(player, gui);
synchronized (this.lock) {
this.openInventories.put(player, gui);
}
});
});
}
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);
PopupMessage popup = new PopupMessage(this.plugin, icon, message, background);
popup.add();
popup.grant(player);
Bukkit.getScheduler().runTaskLaterAsynchronously(plugin, () -> {
Bukkit.getScheduler().runTaskLaterAsynchronously(this.plugin, () -> {
popup.revoke(player);
popup.remove();
}, 70);
@ -156,13 +156,13 @@ public class GuiManager {
* Close all active GUIs
*/
public void closeAll() {
synchronized (lock) {
openInventories.entrySet().stream()
synchronized (this.lock) {
this.openInventories.entrySet().stream()
.filter(e -> e.getKey().getOpenInventory().getTopInventory().getHolder() instanceof GuiHolder)
.collect(Collectors.toList()) // to prevent concurrency exceptions
.forEach(e -> e.getKey().closeInventory());
openInventories.clear();
this.openInventories.clear();
}
}
@ -182,7 +182,7 @@ public class GuiManager {
Inventory openInv = event.getInventory();
Gui gui;
if (openInv.getHolder() != null && openInv.getHolder() instanceof GuiHolder
&& ((GuiHolder) openInv.getHolder()).manager.uuid.equals(manager.uuid)) {
&& ((GuiHolder) openInv.getHolder()).manager.uuid.equals(this.manager.uuid)) {
gui = ((GuiHolder) openInv.getHolder()).getGUI();
if (event.getRawSlots().stream()
@ -205,7 +205,7 @@ public class GuiManager {
Gui gui;
if (openInv.getHolder() != null && openInv.getHolder() instanceof GuiHolder &&
((GuiHolder) openInv.getHolder()).manager.uuid.equals(manager.uuid)) {
((GuiHolder) openInv.getHolder()).manager.uuid.equals(this.manager.uuid)) {
gui = ((GuiHolder) openInv.getHolder()).getGUI();
if (event.getClick() == ClickType.DOUBLE_CLICK) {
@ -228,7 +228,7 @@ public class GuiManager {
}
if (event.getSlotType() == SlotType.OUTSIDE) {
if (!gui.onClickOutside(manager, player, event)) {
if (!gui.onClickOutside(this.manager, player, event)) {
event.setCancelled(true);
}
} // did we click the gui or in the user's inventory?
@ -237,13 +237,13 @@ public class GuiManager {
event.setCancelled(gui.unlockedCells.entrySet().stream().noneMatch(e -> event.getSlot() == e.getKey() && e.getValue()));
// process button press
if (gui.onClick(manager, player, openInv, event)) {
player.playSound(player.getLocation(), gui.getDefaultSound().getSound(), 1F, 1F);
if (gui.onClick(this.manager, player, openInv, event)) {
gui.getDefaultSound().play(player);
}
} else {
// Player clicked in the bottom inventory while GUI is open
if (gui.onClickPlayerInventory(manager, player, openInv, event)) {
player.playSound(player.getLocation(), gui.getDefaultSound().getSound(), 1F, 1F);
if (gui.onClickPlayerInventory(this.manager, player, openInv, event)) {
gui.getDefaultSound().play(player);
} else if (!gui.acceptsItems || event.getAction() == InventoryAction.MOVE_TO_OTHER_INVENTORY) {
event.setCancelled(true);
@ -260,7 +260,7 @@ public class GuiManager {
Inventory openInv = event.getInventory();
if (openInv.getHolder() != null && openInv.getHolder() instanceof GuiHolder &&
((GuiHolder) openInv.getHolder()).manager.uuid.equals(manager.uuid)) {
((GuiHolder) openInv.getHolder()).manager.uuid.equals(this.manager.uuid)) {
Gui gui = ((GuiHolder) openInv.getHolder()).getGUI();
if (gui instanceof AnvilGui) {
@ -277,23 +277,23 @@ public class GuiManager {
player.setItemOnCursor(null);
}
if (manager.shutdown) {
gui.onClose(manager, player);
if (this.manager.shutdown) {
gui.onClose(this.manager, player);
} else {
Bukkit.getScheduler().runTaskLater(manager.plugin, () -> gui.onClose(manager, player), 1);
Bukkit.getScheduler().runTaskLater(this.manager.plugin, () -> gui.onClose(this.manager, player), 1);
}
manager.openInventories.remove(player);
this.manager.openInventories.remove(player);
}
}
@EventHandler
void onDisable(PluginDisableEvent event) {
if (event.getPlugin() == manager.plugin) {
if (event.getPlugin() == this.manager.plugin) {
// uh-oh! Abandon ship!!
manager.shutdown = true;
manager.closeAll();
manager.initialized = false;
this.manager.shutdown = true;
this.manager.closeAll();
this.manager.initialized = false;
}
}
}

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,19 +30,19 @@ 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) {
this.key = new NamespacedKey(source, "popup/" + id);
PopupMessage(Plugin source, XMaterial icon, String title) {
this.key = new NamespacedKey(source, "popup/" + this.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) {
this.key = new NamespacedKey(source, "popup/" + id);
PopupMessage(Plugin source, XMaterial icon, String title, BackgroundType background) {
this.key = new NamespacedKey(source, "popup/" + this.id);
this.title = new TextComponent(title.length() < 74 ? title : (title.substring(0, 72) + "..."));
this.icon = icon;
this.background = background;
@ -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());
}
@ -64,7 +64,7 @@ class PopupMessage {
}
advDisplay.add("title", gson.fromJson(ComponentSerializer.toString(this.title), JsonElement.class));
advDisplay.addProperty("background", background.key);
advDisplay.addProperty("background", this.background.key);
advDisplay.addProperty("description", "");
advDisplay.addProperty("frame", this.frame.id);
advDisplay.addProperty("announce_to_chat", false);
@ -110,11 +110,11 @@ class PopupMessage {
}
protected void add() {
if (!registeredMessages.contains(id)) {
registeredMessages.add(id);
if (!registeredMessages.contains(this.id)) {
registeredMessages.add(this.id);
try {
Bukkit.getUnsafe().loadAdvancement(key, getJSON());
Bukkit.getUnsafe().loadAdvancement(this.key, getJSON());
} catch (IllegalArgumentException ex) {
Bukkit.getLogger().warning("Failed to create popup advancement!");
}
@ -122,14 +122,14 @@ class PopupMessage {
}
protected void remove() {
if (registeredMessages.contains(id)) {
registeredMessages.remove(id);
Bukkit.getUnsafe().removeAdvancement(key);
if (registeredMessages.contains(this.id)) {
registeredMessages.remove(this.id);
Bukkit.getUnsafe().removeAdvancement(this.key);
}
}
public Advancement getAdvancement() {
return Bukkit.getAdvancement(key);
return Bukkit.getAdvancement(this.key);
}
public enum FrameType {
@ -140,7 +140,7 @@ class PopupMessage {
final String id;
FrameType() {
id = name().toLowerCase();
this.id = name().toLowerCase();
}
}
@ -192,7 +192,7 @@ class PopupMessage {
}
public String getKey() {
return key;
return this.key;
}
}
}

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");
this.nextPage = GuiUtils.createButtonItem(XMaterial.ARROW, "Next Page");
this.prevPage = GuiUtils.createButtonItem(XMaterial.ARROW, "Previous Page");
}
public SimplePagedGui setUseHeader(boolean useHeader) {
@ -40,7 +40,7 @@ public class SimplePagedGui extends Gui {
}
public ItemStack getHeaderBackItem() {
return headerBackItem;
return this.headerBackItem;
}
public SimplePagedGui setHeaderBackItem(ItemStack headerBackItem) {
@ -49,7 +49,7 @@ public class SimplePagedGui extends Gui {
}
public ItemStack getFooterBackItem() {
return footerBackItem;
return this.footerBackItem;
}
public SimplePagedGui setFooterBackItem(ItemStack footerBackItem) {
@ -65,11 +65,11 @@ public class SimplePagedGui extends Gui {
@Override
public SimplePagedGui setItem(int cell, ItemStack item) {
// set the cell relative to the current page
int cellIndex = cell < 0 ? cell : (page == 1 || (useHeader && cell < 9) ? cell : (cell + (page - 1) * (rowsPerPage * 9)));
int cellIndex = cell < 0 ? cell : (this.page == 1 || (this.useHeader && cell < 9) ? cell : (cell + (this.page - 1) * (this.rowsPerPage * 9)));
cellItems.put(cellIndex, item);
if (open && cell >= 0 && cell < inventory.getSize()) {
inventory.setItem(cell, item);
this.cellItems.put(cellIndex, item);
if (this.open && cell >= 0 && cell < this.inventory.getSize()) {
this.inventory.setItem(cell, item);
}
return this;
@ -77,27 +77,27 @@ public class SimplePagedGui extends Gui {
@Override
public void nextPage() {
if (page < pages) {
++page;
if (this.page < this.pages) {
++this.page;
showPage();
}
}
@Override
public void prevPage() {
if (page > 1) {
--page;
if (this.page > 1) {
--this.page;
showPage();
}
}
public void showPage() {
int startCell = useHeader ? 9 : 0;
int cellIndex = startCell + (page - 1) * (rowsPerPage * 9);
int startCell = this.useHeader ? 9 : 0;
int cellIndex = startCell + (this.page - 1) * (this.rowsPerPage * 9);
for (int i = startCell; i < (rows - 1) * 9; ++i) {
final ItemStack item = cellItems.get(cellIndex++);
inventory.setItem(i, item != null ? item : blankItem);
for (int i = startCell; i < (this.rows - 1) * 9; ++i) {
final ItemStack item = this.cellItems.get(cellIndex++);
this.inventory.setItem(i, item != null ? item : this.blankItem);
}
// page markers
@ -106,26 +106,26 @@ public class SimplePagedGui extends Gui {
@Override
protected void updatePageNavigation() {
if (page > 1) {
inventory.setItem(inventory.getSize() - prevPageIndex, prevPage);
if (this.page > 1) {
this.inventory.setItem(this.inventory.getSize() - this.prevPageIndex, this.prevPage);
this.setButton(-prevPageIndex, prevPage, ClickType.LEFT, (event) -> this.prevPage());
this.setButton(-this.prevPageIndex, this.prevPage, ClickType.LEFT, (event) -> this.prevPage());
} else {
inventory.setItem(inventory.getSize() - prevPageIndex, footerBackItem != null ? footerBackItem : blankItem);
this.inventory.setItem(this.inventory.getSize() - this.prevPageIndex, this.footerBackItem != null ? this.footerBackItem : this.blankItem);
this.setItem(-prevPageIndex, null);
this.clearActions(-prevPageIndex);
this.setItem(-this.prevPageIndex, null);
this.clearActions(-this.prevPageIndex);
}
if (pages > 1 && page != pages) {
inventory.setItem(inventory.getSize() - nextPageIndex, nextPage);
if (this.pages > 1 && this.page != this.pages) {
this.inventory.setItem(this.inventory.getSize() - this.nextPageIndex, this.nextPage);
this.setButton(-nextPageIndex, nextPage, ClickType.LEFT, (event) -> this.nextPage());
this.setButton(-this.nextPageIndex, this.nextPage, ClickType.LEFT, (event) -> this.nextPage());
} else {
inventory.setItem(inventory.getSize() - nextPageIndex, footerBackItem != null ? footerBackItem : blankItem);
this.inventory.setItem(this.inventory.getSize() - this.nextPageIndex, this.footerBackItem != null ? this.footerBackItem : this.blankItem);
this.setItem(-nextPageIndex, null);
this.clearActions(-nextPageIndex);
this.setItem(-this.nextPageIndex, null);
this.clearActions(-this.nextPageIndex);
}
}
@ -134,65 +134,65 @@ public class SimplePagedGui extends Gui {
this.guiManager = manager;
// calculate pages here
rowsPerPage = useHeader ? 4 : 5;
maxCellSlot = this.cellItems.keySet().stream().max(Integer::compare).orElse(0) + 1;
int maxRows = (int) Math.ceil(maxCellSlot / 9.);
pages = (int) Math.max(1, Math.ceil(maxRows / (double) rowsPerPage));
this.setRows(maxRows + (useHeader ? 1 : 0));
this.rowsPerPage = this.useHeader ? 4 : 5;
this.maxCellSlot = this.cellItems.keySet().stream().max(Integer::compare).orElse(0) + 1;
int maxRows = (int) Math.ceil(this.maxCellSlot / 9.);
this.pages = (int) Math.max(1, Math.ceil(maxRows / (double) this.rowsPerPage));
this.setRows(maxRows + (this.useHeader ? 1 : 0));
// create inventory view
createInventory();
// populate and return the display inventory
setPage(Math.min(page, pages));
setPage(Math.min(this.page, this.pages));
update();
return inventory;
return this.inventory;
}
@Override
protected void createInventory() {
final int cells = rows * 9;
final int cells = this.rows * 9;
inventory = Bukkit.getServer().createInventory(new GuiHolder(guiManager, this), cells,
title == null ? "" : trimTitle(title));
this.inventory = Bukkit.getServer().createInventory(new GuiHolder(this.guiManager, this), cells,
this.title == null ? "" : trimTitle(this.title));
}
@Override
public void update() {
if (inventory == null) {
if (this.inventory == null) {
return;
}
// calculate pages here
rowsPerPage = useHeader ? 4 : 5;
maxCellSlot = (this.cellItems.isEmpty() ? 0 : this.cellItems.keySet().stream().max(Integer::compare).get()) + 1;
int maxRows = Math.max((useHeader ? 1 : 0), (int) Math.ceil(maxCellSlot / 9.));
pages = (int) Math.ceil(maxRows / rowsPerPage);
this.rowsPerPage = this.useHeader ? 4 : 5;
this.maxCellSlot = (this.cellItems.isEmpty() ? 0 : this.cellItems.keySet().stream().max(Integer::compare).get()) + 1;
int maxRows = Math.max((this.useHeader ? 1 : 0), (int) Math.ceil(this.maxCellSlot / 9.));
this.pages = (int) Math.ceil(maxRows / this.rowsPerPage);
// create a new inventory if needed
List<Player> toUpdate = null;
if (Math.min(54, (maxRows + (useHeader ? 1 : 0)) * 9) != inventory.getSize()) {
if (Math.min(54, (maxRows + (this.useHeader ? 1 : 0)) * 9) != this.inventory.getSize()) {
toUpdate = getPlayers();
this.setRows(maxRows + (useHeader ? 1 : 0));
this.setRows(maxRows + (this.useHeader ? 1 : 0));
createInventory();
}
// populate header
if (useHeader) {
if (this.useHeader) {
for (int i = 0; i < 9; ++i) {
final ItemStack item = cellItems.get(i);
final ItemStack item = this.cellItems.get(i);
inventory.setItem(i, item != null ? item : (headerBackItem != null ? headerBackItem : blankItem));
this.inventory.setItem(i, item != null ? item : (this.headerBackItem != null ? this.headerBackItem : this.blankItem));
}
}
// last row is dedicated to pagation
final int cells = rows * 9;
final int cells = this.rows * 9;
for (int i = cells - 9; i < cells; ++i) {
inventory.setItem(i, footerBackItem != null ? footerBackItem : blankItem);
this.inventory.setItem(i, this.footerBackItem != null ? this.footerBackItem : this.blankItem);
}
// fill out the rest of the page
@ -202,7 +202,7 @@ public class SimplePagedGui extends Gui {
if (toUpdate != null) {
// whoopsie!
exit();
toUpdate.forEach(player -> guiManager.showGUI(player, this));
toUpdate.forEach(player -> this.guiManager.showGUI(player, this));
}
}
@ -211,14 +211,14 @@ public class SimplePagedGui extends Gui {
int cell = event.getSlot();
Map<ClickType, Clickable> conditionals;
if (useHeader && cell < 9) {
conditionals = conditionalButtons.get(cell);
} else if (cell >= (rows - 1) * 9) {
if (this.useHeader && cell < 9) {
conditionals = this.conditionalButtons.get(cell);
} else if (cell >= (this.rows - 1) * 9) {
// footer row
conditionals = conditionalButtons.get(cell - (rows * 9));
conditionals = this.conditionalButtons.get(cell - (this.rows * 9));
} else {
int cellIndex = page == 1 ? cell : cell + (page - 1) * rowsPerPage * 9;
conditionals = conditionalButtons.get(cellIndex);
int cellIndex = this.page == 1 ? cell : cell + (this.page - 1) * this.rowsPerPage * 9;
conditionals = this.conditionalButtons.get(cellIndex);
}
Clickable button;

View File

@ -47,7 +47,7 @@ public class DecentHologramsHolograms extends Holograms {
DecentHologramsAPI.get().getHologramManager().removeHologram(id);
}
ourHolograms.remove(id);
this.ourHolograms.remove(id);
}
@Override
@ -68,7 +68,7 @@ public class DecentHologramsHolograms extends Holograms {
@Override
public void removeAllHolograms() {
for (String id : ourHolograms) {
for (String id : this.ourHolograms) {
Hologram hologram = DHAPI.getHologram(id);
if (hologram != null) {
@ -77,7 +77,7 @@ public class DecentHologramsHolograms extends Holograms {
}
}
ourHolograms.clear();
this.ourHolograms.clear();
}
@Override
@ -93,6 +93,6 @@ public class DecentHologramsHolograms extends Holograms {
}
DHAPI.createHologram(id, location, lines);
ourHolograms.add(id);
this.ourHolograms.add(id);
}
}

View File

@ -20,7 +20,7 @@ public class HologramsHolograms extends Holograms {
public HologramsHolograms(Plugin plugin) {
super(plugin);
hologramPlugin = (HologramPlugin) Bukkit.getPluginManager().getPlugin("Holograms");
this.hologramPlugin = (HologramPlugin) Bukkit.getPluginManager().getPlugin("Holograms");
}
@Override
@ -30,7 +30,7 @@ public class HologramsHolograms extends Holograms {
@Override
public boolean isEnabled() {
return hologramPlugin.isEnabled();
return this.hologramPlugin.isEnabled();
}
@Override
@ -45,38 +45,38 @@ public class HologramsHolograms extends Holograms {
@Override
public void removeHologram(String id) {
Hologram hologram = hologramPlugin.getHologramManager().getHologram(id);
Hologram hologram = this.hologramPlugin.getHologramManager().getHologram(id);
if (hologram != null) {
hologram.despawn();
hologramPlugin.getHologramManager().removeActiveHologram(hologram);
this.hologramPlugin.getHologramManager().removeActiveHologram(hologram);
}
ourHolograms.remove(id);
this.ourHolograms.remove(id);
}
@Override
public void removeAllHolograms() {
for (String id : ourHolograms) {
Hologram hologram = hologramPlugin.getHologramManager().getHologram(id);
for (String id : this.ourHolograms) {
Hologram hologram = this.hologramPlugin.getHologramManager().getHologram(id);
if (hologram != null) {
hologram.despawn();
hologramPlugin.getHologramManager().removeActiveHologram(hologram);
this.hologramPlugin.getHologramManager().removeActiveHologram(hologram);
}
}
ourHolograms.clear();
this.ourHolograms.clear();
}
@Override
public boolean isHologramLoaded(String id) {
return hologramPlugin.getHologramManager().getHologram(id) != null;
return this.hologramPlugin.getHologramManager().getHologram(id) != null;
}
@Override
public void updateHologram(String id, List<String> lines) {
Hologram hologram = hologramPlugin.getHologramManager().getHologram(id);
Hologram hologram = this.hologramPlugin.getHologramManager().getHologram(id);
if (hologram != null) {
hologram.spawn();
@ -118,8 +118,8 @@ public class HologramsHolograms extends Holograms {
hologram.addLine(new TextLine(hologram, line));
}
hologramPlugin.getHologramManager().addActiveHologram(hologram);
this.hologramPlugin.getHologramManager().addActiveHologram(hologram);
ourHolograms.add(id);
this.ourHolograms.add(id);
}
}

View File

@ -45,7 +45,7 @@ public class HolographicDisplaysHolograms extends Holograms {
@Override
public void removeHologram(String id) {
Hologram hologram = holograms.remove(id);
Hologram hologram = this.holograms.remove(id);
if (hologram != null) {
hologram.delete();
}
@ -62,7 +62,7 @@ public class HolographicDisplaysHolograms extends Holograms {
String id = entry.getKey();
List<String> lines = entry.getValue();
Hologram hologram = holograms.get(id);
Hologram hologram = this.holograms.get(id);
// only update if there is a change to the text
boolean isChanged = lines.size() != hologram.size();
@ -70,7 +70,7 @@ public class HolographicDisplaysHolograms extends Holograms {
if (!isChanged) {
// double-check the lines
for (int i = 0; !isChanged && i < lines.size(); ++i) {
isChanged = !hologram.getLine(i).toString().equals(String.format(textLineFormat, lines.get(i)));
isChanged = !hologram.getLine(i).toString().equals(String.format(this.textLineFormat, lines.get(i)));
}
}
@ -85,27 +85,27 @@ public class HolographicDisplaysHolograms extends Holograms {
}
private void createAt(String id, Location location, List<String> lines) {
if (holograms.containsKey(id)) {
if (this.holograms.containsKey(id)) {
return;
}
location = fixLocation(location);
Hologram hologram = HologramsAPI.createHologram(plugin, location);
Hologram hologram = HologramsAPI.createHologram(this.plugin, location);
for (String line : lines) {
hologram.appendTextLine(line);
}
holograms.put(id, hologram);
this.holograms.put(id, hologram);
}
@Override
public void removeAllHolograms() {
holograms.values().forEach(Hologram::delete);
this.holograms.values().forEach(Hologram::delete);
}
@Override
public boolean isHologramLoaded(String id) {
return holograms.get(id) != null;
return this.holograms.get(id) != null;
}
}

View File

@ -1,6 +1,6 @@
package com.craftaro.core.http;
import com.craftaro.core.SongodaCoreConstants;
import com.craftaro.core.CraftaroCoreConstants;
import org.jetbrains.annotations.NotNull;
import java.io.IOException;
@ -36,9 +36,9 @@ public class SimpleHttpClient implements HttpClient {
}
private static String generateUserAgent() {
String projectName = SongodaCoreConstants.getProjectName();
String version = SongodaCoreConstants.getCoreVersion();
String projectUrl = SongodaCoreConstants.getGitHubProjectUrl();
String projectName = CraftaroCoreConstants.getProjectName();
String version = CraftaroCoreConstants.getCoreVersion();
String projectUrl = CraftaroCoreConstants.getGitHubProjectUrl();
return projectName + "/" + version + " (+" + projectUrl + ")";
}

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

@ -11,15 +11,15 @@ public class Eval {
}
private void nextChar() {
ch = (++pos < toParse.length()) ? toParse.charAt(pos) : -1;
this.ch = (++this.pos < this.toParse.length()) ? this.toParse.charAt(this.pos) : -1;
}
private boolean eat(int charToEat) {
while (ch == ' ') {
while (this.ch == ' ') {
nextChar();
}
if (ch == charToEat) {
if (this.ch == charToEat) {
nextChar();
return true;
}
@ -31,8 +31,8 @@ public class Eval {
nextChar();
double x = parseExpression();
if (pos < toParse.length()) {
throw new RuntimeException(warningMessage + "Unexpected: '" + (char) ch + "' at position " + pos + " in '" + this.toParse + "'");
if (this.pos < this.toParse.length()) {
throw new RuntimeException(this.warningMessage + "Unexpected: '" + (char) this.ch + "' at position " + this.pos + " in '" + this.toParse + "'");
}
return x;
@ -85,18 +85,18 @@ public class Eval {
if (eat('(')) { // parentheses
x = parseExpression();
eat(')');
} else if ((ch >= '0' && ch <= '9') || ch == '.') { // numbers
while ((ch >= '0' && ch <= '9') || ch == '.') {
} else if ((this.ch >= '0' && this.ch <= '9') || this.ch == '.') { // numbers
while ((this.ch >= '0' && this.ch <= '9') || this.ch == '.') {
nextChar();
}
x = Double.parseDouble(toParse.substring(startPos, this.pos));
} else if (ch >= 'a' && ch <= 'z') { // functions
while (ch >= 'a' && ch <= 'z') {
x = Double.parseDouble(this.toParse.substring(startPos, this.pos));
} else if (this.ch >= 'a' && this.ch <= 'z') { // functions
while (this.ch >= 'a' && this.ch <= 'z') {
nextChar();
}
String func = toParse.substring(startPos, this.pos);
String func = this.toParse.substring(startPos, this.pos);
x = parseFactor();
switch (func) {
@ -113,10 +113,10 @@ public class Eval {
x = Math.tan(Math.toRadians(x));
break;
default:
throw new RuntimeException(warningMessage + "Unknown function: " + func);
throw new RuntimeException(this.warningMessage + "Unknown function: " + func);
}
} else {
throw new RuntimeException(warningMessage + "Unexpected: " + (char) ch);
throw new RuntimeException(this.warningMessage + "Unexpected: " + (char) this.ch);
}
if (eat('^')) {

View File

@ -1,6 +1,6 @@
package com.craftaro.core.math;
import com.craftaro.core.SongodaCoreConstants;
import com.craftaro.core.CraftaroCoreConstants;
import java.util.HashMap;
import java.util.Map;
@ -9,7 +9,7 @@ public class MathUtils {
private static final Map<String, Double> cache = new HashMap<>();
public static double eval(String toParse) {
return eval(toParse, SongodaCoreConstants.getProjectName() + " Eval Engine");
return eval(toParse, CraftaroCoreConstants.getProjectName() + " Eval Engine");
}
public static double eval(String toParse, String warningMessage) {

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

@ -7,7 +7,7 @@ import java.util.Map;
import java.util.TreeMap;
public class ColorUtils {
private static Map<ColorCode, ColorSet<Integer, Integer, Integer>> colorMap = new HashMap<>();
private static final Map<ColorCode, ColorSet<Integer, Integer, Integer>> colorMap = new HashMap<>();
static {
colorMap.put(ColorCode.BLACK, new ColorSet<>(0, 0, 0));
@ -40,15 +40,15 @@ public class ColorUtils {
}
public R getRed() {
return red;
return this.red;
}
public G getGreen() {
return green;
return this.green;
}
public B getBlue() {
return blue;
return this.blue;
}
}

View File

@ -1,18 +1,22 @@
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;
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;
/**
* @deprecated Use {@link com.craftaro.core.nms.entity.NmsEntity} instead
*/
@Deprecated
public class EntityUtils {
private static Class<?> clazzEntityInsentient, clazzEntity, clazzCraftEntity;
@ -41,6 +45,10 @@ public class EntityUtils {
}
}
/**
* @deprecated Use {@link com.craftaro.core.nms.entity.NmsEntity#setMobAware(Entity, boolean)} instead
*/
@Deprecated
public static void setUnaware(LivingEntity entity) {
try {
setUnaware(methodGetHandle.invoke(clazzCraftEntity.cast(entity)));
@ -49,6 +57,10 @@ public class EntityUtils {
}
}
/**
* @deprecated Use {@link com.craftaro.core.nms.entity.NmsEntity#setMobAware(Entity, boolean)} instead
*/
@Deprecated
public static void setUnaware(Object entity) {
try {
if (aware != null) {
@ -61,6 +73,10 @@ public class EntityUtils {
}
}
/**
* @deprecated Use {@link com.craftaro.core.nms.entity.NmsEntity#isAware(Entity)} instead
*/
@Deprecated
public static boolean isAware(LivingEntity entity) {
try {
return isAware(methodGetHandle.invoke(clazzCraftEntity.cast(entity)));
@ -71,6 +87,10 @@ public class EntityUtils {
return false;
}
/**
* @deprecated Use {@link com.craftaro.core.nms.entity.NmsEntity#isAware(Entity)} instead
*/
@Deprecated
public static boolean isAware(Object entity) {
try {
if (aware != null) {
@ -85,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":
@ -95,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

@ -13,7 +13,10 @@ import java.util.List;
/**
* Class based off of https://gist.github.com/graywolf336/8153678
*
* @deprecated Will be moved into a more appropriate package and refactored.
*/
@Deprecated
public class ItemSerializer {
/**
* A method to serialize an {@link ItemStack} list to Base64 String.

View File

@ -1,12 +1,13 @@
package com.craftaro.core.utils;
import com.mojang.authlib.GameProfile;
import com.mojang.authlib.properties.Property;
import com.craftaro.core.compatibility.ClassMapping;
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;
import org.bukkit.Bukkit;
import org.bukkit.Material;
@ -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;
@ -42,7 +44,10 @@ import java.util.stream.Stream;
/**
* This class uses some Minecraft code and also Paper API
*
* @deprecated Needs to be re-implemented without ClassMapping usage etc. and moved into a more appropriate package
*/
@Deprecated
public class ItemUtils {
static boolean can_getI18NDisplayName = true;
@ -329,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;
}
@ -348,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;
}
@ -366,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;
@ -430,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;
}
@ -486,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());
}
/**
@ -796,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) {
@ -1005,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;
@ -1080,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

@ -36,7 +36,10 @@ import java.util.zip.GZIPOutputStream;
* bStats collects some data for plugin authors.
* <p>
* Check out https://bStats.org/ to learn more about bStats!
*
* @deprecated Replace with latest version of bStats
*/
@Deprecated
@SuppressWarnings({"WeakerAccess", "unused"})
public class Metrics {
static {

View File

@ -7,6 +7,10 @@ import org.bukkit.entity.Player;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
/**
* @deprecated Use {@link com.craftaro.core.nms.Nms} instead
*/
@Deprecated
public class NMSUtils {
/**
* @deprecated Use {@link ClassMapping} instead

View File

@ -4,10 +4,19 @@ import java.text.DecimalFormat;
import java.text.DecimalFormatSymbols;
public class NumberUtils {
/**
* @deprecated This method does not take the plugin's configured locale into account.
* Additionally, the currencySymbol's position is not configurable in this method.
*/
@Deprecated
public static String formatEconomy(char currencySymbol, double number) {
return currencySymbol + formatNumber(number);
}
/**
* @deprecated This method does not take the plugin's configured locale into account.
*/
@Deprecated
public static String formatNumber(double number) {
DecimalFormat decimalFormatter = new DecimalFormat(number == Math.ceil(number) ? "#,###" : "#,###.00");
@ -21,6 +30,10 @@ public class NumberUtils {
return decimalFormatter.format(number);
}
/**
* @deprecated Should be re-implemented as {@code formatWithSiPrefix} and take the plugin's configured locale into account.
*/
@Deprecated
public static String formatWithSuffix(long count) {
if (count < 1000) {
return String.valueOf(count);
@ -33,19 +46,19 @@ public class NumberUtils {
}
public static boolean isInt(String number) {
if (number == null || number.equals("")) {
return false;
}
try {
Integer.parseInt(number);
return true;
} catch (NumberFormatException ignore) {
}
return false;
}
/**
* @deprecated This allows floating point numbers and negative/positive numbers.
* Should be re-implemented as {@code isNumber} if needed.
*/
@Deprecated
public static boolean isNumeric(String s) {
if (s == null || s.equals("")) {
return false;

View File

@ -12,13 +12,11 @@ import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.Set;
import java.util.concurrent.ThreadLocalRandom;
import java.util.stream.Collectors;
public class PlayerUtils {
static Random random = new Random();
public static void sendMessages(Player player, String... messages) {
for (String message : messages) {
player.sendMessage(message);
@ -26,9 +24,7 @@ public class PlayerUtils {
}
public static void sendMessages(Player player, List<String> messages) {
for (String message : messages) {
player.sendMessage(message);
}
sendMessages(player, messages.toArray(new String[0]));
}
/**
@ -39,7 +35,10 @@ public class PlayerUtils {
* start with this
*
* @return list of player names that are "visible" to the player
*
* @deprecated This method has a strong use-case for Command related code and should be reimplemented there
*/
@Deprecated
public static List<String> getVisiblePlayerNames(CommandSender sender, String startingWith) {
Player player = sender instanceof Player ? (Player) sender : null;
final String startsWith = startingWith == null || startingWith.isEmpty() ? null : startingWith.toLowerCase();
@ -60,7 +59,10 @@ public class PlayerUtils {
* start with this
*
* @return list of player names that are "visible" to the player
*
* @deprecated This method has a strong use-case for Command related code and should be reimplemented there
*/
@Deprecated
public static List<String> getVisiblePlayerDisplayNames(CommandSender sender, String startingWith) {
Player player = sender instanceof Player ? (Player) sender : null;
final String startsWith = startingWith == null || startingWith.isEmpty() ? null : startingWith.replaceAll("[^a-zA-Z]", "").toLowerCase();
@ -81,7 +83,10 @@ public class PlayerUtils {
* start with this
*
* @return list of players that are "visible" to the player
*
* @deprecated This method has a strong use-case for Command related code and should be reimplemented there
*/
@Deprecated
public static List<Player> getVisiblePlayers(CommandSender sender, String startingWith) {
Player player = sender instanceof Player ? (Player) sender : null;
final String startsWith = startingWith == null || startingWith.isEmpty() ? null : startingWith.toLowerCase();
@ -101,7 +106,10 @@ public class PlayerUtils {
* @param startsWith All names returned must start with this input string
*
* @return List of matching player IGN
*
* @deprecated This method has a strong use-case for Command related code and should be reimplemented there
*/
@Deprecated
public static List<String> getAllPlayers(CommandSender us, String startsWith) {
final String arg = startsWith.toLowerCase();
@ -118,7 +126,10 @@ public class PlayerUtils {
* @param startsWith All names returned must start with this input string
*
* @return List of matching player display names
*
* @deprecated This method has a strong use-case for Command related code and should be reimplemented there
*/
@Deprecated
public static List<String> getAllPlayersDisplay(CommandSender us, String startsWith) {
// FIXME: Why do we need that regex? It just breaks the startsWith check
// + the DisplayName comparison is not made lower case
@ -137,7 +148,10 @@ public class PlayerUtils {
* @param player player to search for
*
* @return Player that closest matches the input name, or null if none found
*
* @deprecated This method has a strong use-case for Command related code and should probably be reimplemented there
*/
@Deprecated
public static Player findPlayer(String player) {
Player found = Bukkit.getServer().getPlayer(player);
@ -181,7 +195,7 @@ public class PlayerUtils {
final Iterator<? extends Player> alli = all.iterator();
int pick = random.nextInt(all.size());
int pick = ThreadLocalRandom.current().nextInt(all.size());
for (; pick > 0; --pick) {
alli.next();
@ -230,6 +244,10 @@ public class PlayerUtils {
}
}
/**
* @deprecated The method should be moved to a more appropriate class
*/
@Deprecated
public static int getNumberFromPermission(Player player, String permission, int def) {
final Set<PermissionAttachmentInfo> permissions = player.getEffectivePermissions();

View File

@ -29,6 +29,11 @@ import java.util.logging.Level;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
/**
* @deprecated The class is not used in the Core and existing usages in plugins should be re-implemented in the Core for
* better stability between game versions.
*/
@Deprecated
public class ReflectionUtils {
public final static double JAVA_VERSION = getVersion();
private static String system_os = System.getProperty("os.name").toLowerCase();

View File

@ -2,19 +2,23 @@ package com.craftaro.core.utils;
import org.bukkit.block.BlockFace;
/**
* @deprecated No replacement available
*/
@Deprecated
public class RotationUtils {
public static float faceToYaw(BlockFace face) {
switch (face) {
case NORTH:
return 180F;
case EAST:
return -90F;
case SOUTH:
return 0F;
return -90;
case WEST:
return 90F;
return 90;
case NORTH:
return 180;
case SOUTH:
default:
return 0F;
return 0;
}
}

View File

@ -1,9 +1,9 @@
package com.craftaro.core.world;
import com.craftaro.core.compatibility.CompatibleHand;
import com.craftaro.core.compatibility.CompatibleSound;
import com.craftaro.core.compatibility.ServerVersion;
import com.craftaro.core.nms.Nms;
import com.cryptomorin.xseries.XSound;
import org.bukkit.Bukkit;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.Player;
@ -23,7 +23,7 @@ public class SItemStack {
public SItemStack(CompatibleHand hand, Player player) {
this.item = hand.getItem(player);
this.sItem = Nms.getImplementations().getWorld().getItemStack(item);
this.sItem = Nms.getImplementations().getWorld().getItemStack(this.item);
}
public ItemStack addDamage(Player player, int damage) {
@ -37,24 +37,24 @@ public class SItemStack {
* @param damage the amount of damage to apply to the item
*/
public ItemStack addDamage(Player player, int damage, boolean respectVanillaUnbreakingEnchantments) {
if (item == null) {
if (this.item == null) {
return null;
}
if (item.getItemMeta() == null) {
return item;
if (this.item.getItemMeta() == null) {
return this.item;
}
int maxDurability = item.getType().getMaxDurability();
int maxDurability = this.item.getType().getMaxDurability();
int durability;
if (ServerVersion.isServerVersionBelow(ServerVersion.V1_11)
? Nms.getImplementations().getNbt().of(item).has("Unbreakable")
: item.getItemMeta().isUnbreakable()) {
return item;
? Nms.getImplementations().getNbt().of(this.item).has("Unbreakable")
: this.item.getItemMeta().isUnbreakable()) {
return this.item;
} else if (ServerVersion.isServerVersionAtLeast(ServerVersion.V1_13)) {
// ItemStack.setDurability(short) still works in 1.13-1.14, but use these methods now
ItemMeta meta = item.getItemMeta();
ItemMeta meta = this.item.getItemMeta();
if (meta instanceof Damageable) {
Damageable damageable = ((Damageable) meta);
@ -63,25 +63,25 @@ public class SItemStack {
}
damageable.setDamage(((Damageable) meta).getDamage() + damage);
item.setItemMeta(meta);
this.item.setItemMeta(meta);
durability = damageable.getDamage();
} else {
return item;
return this.item;
}
} else {
if (respectVanillaUnbreakingEnchantments) {
damage = shouldApplyDamage(item.getEnchantmentLevel(Enchantment.DURABILITY), damage);
damage = shouldApplyDamage(this.item.getEnchantmentLevel(Enchantment.DURABILITY), damage);
}
item.setDurability((short) Math.max(0, item.getDurability() + damage));
durability = item.getDurability();
this.item.setDurability((short) Math.max(0, this.item.getDurability() + damage));
durability = this.item.getDurability();
}
if (durability >= maxDurability && player != null) {
destroy(player);
}
return item;
return this.item;
}
public void destroy(Player player) {
@ -89,15 +89,15 @@ public class SItemStack {
}
public void destroy(Player player, int amount) {
PlayerItemBreakEvent breakEvent = new PlayerItemBreakEvent(player, item);
PlayerItemBreakEvent breakEvent = new PlayerItemBreakEvent(player, this.item);
Bukkit.getServer().getPluginManager().callEvent(breakEvent);
sItem.breakItem(player, amount);
CompatibleSound.ENTITY_ITEM_BREAK.play(player);
this.sItem.breakItem(player, amount);
XSound.ENTITY_ITEM_BREAK.play(player);
}
public ItemStack getItem() {
return item;
return this.item;
}
private static int shouldApplyDamage(int unbreakingEnchantLevel, int damageAmount) {

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,9 +39,8 @@ public class SSpawner {
*
* @return amount of entities spawned
*/
public int spawn(int amountToSpawn, String particle, Set<CompatibleMaterial> canSpawnOn, SpawnedEntity spawned,
EntityType... types) {
if (location.getWorld() == null) {
public int spawn(int amountToSpawn, String particle, Set<XMaterial> canSpawnOn, SpawnedEntity spawned, EntityType... types) {
if (this.location.getWorld() == null) {
return 0;
}
@ -60,7 +59,7 @@ public class SSpawner {
int amountSpawned = 0;
while (spawnCountUsed-- > 0) {
EntityType type = types[ThreadLocalRandom.current().nextInt(types.length)];
LivingEntity entity = sSpawner.spawnEntity(type, particle, spawned, canSpawnOn);
LivingEntity entity = this.sSpawner.spawnEntity(type, particle, spawned, canSpawnOn);
if (entity != null) {
// If this entity is indeed stackable then spawn a single stack with the desired stack size.
@ -79,6 +78,6 @@ public class SSpawner {
}
public Location getLocation() {
return location;
return this.location;
}
}

View File

@ -29,13 +29,13 @@ public class SWorld {
public List<LivingEntity> getLivingEntities() {
if (ServerVersion.isServerVersionBelow(ServerVersion.V1_17)) {
return world.getLivingEntities();
return this.world.getLivingEntities();
}
return sWorld.getLivingEntities();
return this.sWorld.getLivingEntities();
}
public World getWorld() {
return world;
return this.world;
}
}

View File

@ -9,7 +9,7 @@ import java.util.regex.Pattern;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
class SongodaCoreConstantsTest {
class CraftaroCoreConstantsTest {
// Pattern is from https://semver.org/#is-there-a-suggested-regular-expression-regex-to-check-a-semver-string
private static final Pattern VERSION_PATTERN = Pattern.compile("^(0|[1-9]\\d*)\\.(0|[1-9]\\d*)\\.(0|[1-9]\\d*)(?:-((?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\\.(?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\\+([0-9a-zA-Z-]+(?:\\.[0-9a-zA-Z-]+)*))?$");
@ -19,18 +19,18 @@ class SongodaCoreConstantsTest {
throw new TestSkippedException("Skipping test because it requires the TESTS_RUN_WITH_MAVEN environment variable to be set to true");
}
String coreVersion = SongodaCoreConstants.getCoreVersion();
String coreVersion = CraftaroCoreConstants.getCoreVersion();
assertTrue(VERSION_PATTERN.matcher(coreVersion).matches(), "Version string is not a valid semver string: " + coreVersion);
}
@Test
void getProjectName() {
assertFalse(SongodaCoreConstants.getProjectName().isEmpty());
assertFalse(CraftaroCoreConstants.getProjectName().isEmpty());
}
@Test
void getGitHubProjectUrl() {
assertFalse(SongodaCoreConstants.getGitHubProjectUrl().isEmpty());
assertFalse(CraftaroCoreConstants.getGitHubProjectUrl().isEmpty());
}
}

View File

@ -2,12 +2,15 @@ package com.craftaro.core.nms;
import com.craftaro.core.nms.anvil.AnvilCore;
import com.craftaro.core.nms.entity.NMSPlayer;
import com.craftaro.core.nms.entity.NmsEntity;
import com.craftaro.core.nms.nbt.NBTCore;
import com.craftaro.core.nms.world.NmsWorldBorder;
import com.craftaro.core.nms.world.WorldCore;
import com.craftaro.core.nms.nbt.NBTCore;
import org.jetbrains.annotations.NotNull;
public interface NmsImplementations {
@NotNull NmsEntity getEntity();
@NotNull NMSPlayer getPlayer();
@NotNull WorldCore getWorld();

View File

@ -0,0 +1,11 @@
package com.craftaro.core.nms.entity;
import org.bukkit.entity.Entity;
public interface NmsEntity {
boolean isMob(Entity entity);
void setMobAware(Entity entity, boolean aware);
boolean isAware(Entity entity);
}

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

@ -1,19 +1,22 @@
package com.craftaro.core.nms.v1_10_R1;
import com.craftaro.core.nms.NmsImplementations;
import com.craftaro.core.nms.entity.NMSPlayer;
import com.craftaro.core.nms.entity.NmsEntity;
import com.craftaro.core.nms.nbt.NBTCore;
import com.craftaro.core.nms.v1_10_R1.anvil.AnvilCore;
import com.craftaro.core.nms.v1_10_R1.entity.NMSPlayerImpl;
import com.craftaro.core.nms.v1_10_R1.entity.NmsEntityImpl;
import com.craftaro.core.nms.v1_10_R1.nbt.NBTCoreImpl;
import com.craftaro.core.nms.v1_10_R1.world.NmsWorldBorderImpl;
import com.craftaro.core.nms.v1_10_R1.world.WorldCoreImpl;
import com.craftaro.core.nms.NmsImplementations;
import com.craftaro.core.nms.entity.NMSPlayer;
import com.craftaro.core.nms.nbt.NBTCore;
import com.craftaro.core.nms.world.NmsWorldBorder;
import com.craftaro.core.nms.world.WorldCore;
import org.jetbrains.annotations.NotNull;
@SuppressWarnings("unused")
public class NmsImplementationsImpl implements NmsImplementations {
private final NmsEntity entity;
private final NMSPlayer player;
private final WorldCore world;
private final NmsWorldBorder worldBorder;
@ -21,6 +24,7 @@ public class NmsImplementationsImpl implements NmsImplementations {
private final NBTCore nbt;
public NmsImplementationsImpl() {
this.entity = new NmsEntityImpl();
this.player = new NMSPlayerImpl();
this.world = new WorldCoreImpl();
this.worldBorder = new NmsWorldBorderImpl();
@ -28,6 +32,11 @@ public class NmsImplementationsImpl implements NmsImplementations {
this.nbt = new NBTCoreImpl();
}
@Override
public @NotNull NmsEntity getEntity() {
return this.entity;
}
@Override
public @NotNull NMSPlayer getPlayer() {
return this.player;

View File

@ -0,0 +1,33 @@
package com.craftaro.core.nms.v1_10_R1.entity;
import com.craftaro.core.nms.entity.NmsEntity;
import net.minecraft.server.v1_10_R1.Entity;
import net.minecraft.server.v1_10_R1.EntityInsentient;
import org.bukkit.craftbukkit.v1_10_R1.entity.CraftEntity;
public class NmsEntityImpl implements NmsEntity {
@Override
public boolean isMob(org.bukkit.entity.Entity entity) {
return ((CraftEntity) entity).getHandle() instanceof EntityInsentient;
}
@Override
public void setMobAware(org.bukkit.entity.Entity entity, boolean aware) {
if (!isMob(entity)) {
throw new IllegalArgumentException("Entity is not a mob and cannot be set aware");
}
Entity nmsEntity = ((CraftEntity) entity).getHandle();
nmsEntity.fromMobSpawner = aware;
}
@Override
public boolean isAware(org.bukkit.entity.Entity entity) {
Entity nmsEntity = ((CraftEntity) entity).getHandle();
if (nmsEntity instanceof EntityInsentient) {
return nmsEntity.fromMobSpawner;
}
return false;
}
}

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

@ -1,19 +1,22 @@
package com.craftaro.core.nms.v1_11_R1;
import com.craftaro.core.nms.NmsImplementations;
import com.craftaro.core.nms.entity.NMSPlayer;
import com.craftaro.core.nms.entity.NmsEntity;
import com.craftaro.core.nms.nbt.NBTCore;
import com.craftaro.core.nms.v1_11_R1.anvil.AnvilCore;
import com.craftaro.core.nms.v1_11_R1.entity.NMSPlayerImpl;
import com.craftaro.core.nms.v1_11_R1.entity.NmsEntityImpl;
import com.craftaro.core.nms.v1_11_R1.nbt.NBTCoreImpl;
import com.craftaro.core.nms.v1_11_R1.world.NmsWorldBorderImpl;
import com.craftaro.core.nms.v1_11_R1.world.WorldCoreImpl;
import com.craftaro.core.nms.NmsImplementations;
import com.craftaro.core.nms.entity.NMSPlayer;
import com.craftaro.core.nms.nbt.NBTCore;
import com.craftaro.core.nms.world.NmsWorldBorder;
import com.craftaro.core.nms.world.WorldCore;
import org.jetbrains.annotations.NotNull;
@SuppressWarnings("unused")
public class NmsImplementationsImpl implements NmsImplementations {
private final NmsEntity entity;
private final NMSPlayer player;
private final WorldCore world;
private final NmsWorldBorder worldBorder;
@ -21,6 +24,7 @@ public class NmsImplementationsImpl implements NmsImplementations {
private final NBTCore nbt;
public NmsImplementationsImpl() {
this.entity = new NmsEntityImpl();
this.player = new NMSPlayerImpl();
this.world = new WorldCoreImpl();
this.worldBorder = new NmsWorldBorderImpl();
@ -28,6 +32,11 @@ public class NmsImplementationsImpl implements NmsImplementations {
this.nbt = new NBTCoreImpl();
}
@Override
public @NotNull NmsEntity getEntity() {
return this.entity;
}
@Override
public @NotNull NMSPlayer getPlayer() {
return this.player;

View File

@ -0,0 +1,33 @@
package com.craftaro.core.nms.v1_11_R1.entity;
import com.craftaro.core.nms.entity.NmsEntity;
import net.minecraft.server.v1_11_R1.Entity;
import net.minecraft.server.v1_11_R1.EntityInsentient;
import org.bukkit.craftbukkit.v1_11_R1.entity.CraftEntity;
public class NmsEntityImpl implements NmsEntity {
@Override
public boolean isMob(org.bukkit.entity.Entity entity) {
return ((CraftEntity) entity).getHandle() instanceof EntityInsentient;
}
@Override
public void setMobAware(org.bukkit.entity.Entity entity, boolean aware) {
if (!isMob(entity)) {
throw new IllegalArgumentException("Entity is not a mob and cannot be set aware");
}
Entity nmsEntity = ((CraftEntity) entity).getHandle();
nmsEntity.fromMobSpawner = aware;
}
@Override
public boolean isAware(org.bukkit.entity.Entity entity) {
Entity nmsEntity = ((CraftEntity) entity).getHandle();
if (nmsEntity instanceof EntityInsentient) {
return nmsEntity.fromMobSpawner;
}
return false;
}
}

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

@ -1,19 +1,22 @@
package com.craftaro.core.nms.v1_12_R1;
import com.craftaro.core.nms.v1_12_R1.anvil.AnvilCore;
import com.craftaro.core.nms.v1_12_R1.entity.NMSPlayerImpl;
import com.craftaro.core.nms.v1_12_R1.world.NmsWorldBorderImpl;
import com.craftaro.core.nms.v1_12_R1.world.WorldCoreImpl;
import com.craftaro.core.nms.NmsImplementations;
import com.craftaro.core.nms.entity.NMSPlayer;
import com.craftaro.core.nms.entity.NmsEntity;
import com.craftaro.core.nms.nbt.NBTCore;
import com.craftaro.core.nms.v1_12_R1.anvil.AnvilCore;
import com.craftaro.core.nms.v1_12_R1.entity.NMSPlayerImpl;
import com.craftaro.core.nms.v1_12_R1.entity.NmsEntityImpl;
import com.craftaro.core.nms.v1_12_R1.nbt.NBTCoreImpl;
import com.craftaro.core.nms.v1_12_R1.world.NmsWorldBorderImpl;
import com.craftaro.core.nms.v1_12_R1.world.WorldCoreImpl;
import com.craftaro.core.nms.world.NmsWorldBorder;
import com.craftaro.core.nms.world.WorldCore;
import org.jetbrains.annotations.NotNull;
@SuppressWarnings("unused")
public class NmsImplementationsImpl implements NmsImplementations {
private final NmsEntity entity;
private final NMSPlayer player;
private final WorldCore world;
private final NmsWorldBorder worldBorder;
@ -21,6 +24,7 @@ public class NmsImplementationsImpl implements NmsImplementations {
private final NBTCore nbt;
public NmsImplementationsImpl() {
this.entity = new NmsEntityImpl();
this.player = new NMSPlayerImpl();
this.world = new WorldCoreImpl();
this.worldBorder = new NmsWorldBorderImpl();
@ -28,6 +32,11 @@ public class NmsImplementationsImpl implements NmsImplementations {
this.nbt = new NBTCoreImpl();
}
@Override
public @NotNull NmsEntity getEntity() {
return this.entity;
}
@Override
public @NotNull NMSPlayer getPlayer() {
return this.player;

View File

@ -0,0 +1,33 @@
package com.craftaro.core.nms.v1_12_R1.entity;
import com.craftaro.core.nms.entity.NmsEntity;
import net.minecraft.server.v1_12_R1.Entity;
import net.minecraft.server.v1_12_R1.EntityInsentient;
import org.bukkit.craftbukkit.v1_12_R1.entity.CraftEntity;
public class NmsEntityImpl implements NmsEntity {
@Override
public boolean isMob(org.bukkit.entity.Entity entity) {
return ((CraftEntity) entity).getHandle() instanceof EntityInsentient;
}
@Override
public void setMobAware(org.bukkit.entity.Entity entity, boolean aware) {
if (!isMob(entity)) {
throw new IllegalArgumentException("Entity is not a mob and cannot be set aware");
}
Entity nmsEntity = ((CraftEntity) entity).getHandle();
nmsEntity.fromMobSpawner = aware;
}
@Override
public boolean isAware(org.bukkit.entity.Entity entity) {
Entity nmsEntity = ((CraftEntity) entity).getHandle();
if (nmsEntity instanceof EntityInsentient) {
return nmsEntity.fromMobSpawner;
}
return false;
}
}

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

@ -1,19 +1,22 @@
package com.craftaro.core.nms.v1_13_R1;
import com.craftaro.core.nms.NmsImplementations;
import com.craftaro.core.nms.entity.NMSPlayer;
import com.craftaro.core.nms.entity.NmsEntity;
import com.craftaro.core.nms.nbt.NBTCore;
import com.craftaro.core.nms.v1_13_R1.anvil.AnvilCore;
import com.craftaro.core.nms.v1_13_R1.entity.NMSPlayerImpl;
import com.craftaro.core.nms.v1_13_R1.entity.NmsEntityImpl;
import com.craftaro.core.nms.v1_13_R1.nbt.NBTCoreImpl;
import com.craftaro.core.nms.v1_13_R1.world.NmsWorldBorderImpl;
import com.craftaro.core.nms.v1_13_R1.world.WorldCoreImpl;
import com.craftaro.core.nms.NmsImplementations;
import com.craftaro.core.nms.entity.NMSPlayer;
import com.craftaro.core.nms.nbt.NBTCore;
import com.craftaro.core.nms.world.NmsWorldBorder;
import com.craftaro.core.nms.world.WorldCore;
import org.jetbrains.annotations.NotNull;
@SuppressWarnings("unused")
public class NmsImplementationsImpl implements NmsImplementations {
private final NmsEntity entity;
private final NMSPlayer player;
private final WorldCore world;
private final NmsWorldBorder worldBorder;
@ -21,6 +24,7 @@ public class NmsImplementationsImpl implements NmsImplementations {
private final NBTCore nbt;
public NmsImplementationsImpl() {
this.entity = new NmsEntityImpl();
this.player = new NMSPlayerImpl();
this.world = new WorldCoreImpl();
this.worldBorder = new NmsWorldBorderImpl();
@ -28,6 +32,11 @@ public class NmsImplementationsImpl implements NmsImplementations {
this.nbt = new NBTCoreImpl();
}
@Override
public @NotNull NmsEntity getEntity() {
return this.entity;
}
@Override
public @NotNull NMSPlayer getPlayer() {
return this.player;

View File

@ -0,0 +1,33 @@
package com.craftaro.core.nms.v1_13_R1.entity;
import com.craftaro.core.nms.entity.NmsEntity;
import net.minecraft.server.v1_13_R1.Entity;
import net.minecraft.server.v1_13_R1.EntityInsentient;
import org.bukkit.craftbukkit.v1_13_R1.entity.CraftEntity;
public class NmsEntityImpl implements NmsEntity {
@Override
public boolean isMob(org.bukkit.entity.Entity entity) {
return ((CraftEntity) entity).getHandle() instanceof EntityInsentient;
}
@Override
public void setMobAware(org.bukkit.entity.Entity entity, boolean aware) {
if (!isMob(entity)) {
throw new IllegalArgumentException("Entity is not a mob and cannot be set aware");
}
Entity nmsEntity = ((CraftEntity) entity).getHandle();
nmsEntity.fromMobSpawner = aware;
}
@Override
public boolean isAware(org.bukkit.entity.Entity entity) {
Entity nmsEntity = ((CraftEntity) entity).getHandle();
if (nmsEntity instanceof EntityInsentient) {
return nmsEntity.fromMobSpawner;
}
return false;
}
}

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

@ -1,19 +1,22 @@
package com.craftaro.core.nms.v1_13_R2;
import com.craftaro.core.nms.NmsImplementations;
import com.craftaro.core.nms.entity.NMSPlayer;
import com.craftaro.core.nms.entity.NmsEntity;
import com.craftaro.core.nms.nbt.NBTCore;
import com.craftaro.core.nms.v1_13_R2.anvil.AnvilCore;
import com.craftaro.core.nms.v1_13_R2.entity.NMSPlayerImpl;
import com.craftaro.core.nms.v1_13_R2.entity.NmsEntityImpl;
import com.craftaro.core.nms.v1_13_R2.nbt.NBTCoreImpl;
import com.craftaro.core.nms.v1_13_R2.world.NmsWorldBorderImpl;
import com.craftaro.core.nms.v1_13_R2.world.WorldCoreImpl;
import com.craftaro.core.nms.NmsImplementations;
import com.craftaro.core.nms.entity.NMSPlayer;
import com.craftaro.core.nms.nbt.NBTCore;
import com.craftaro.core.nms.world.NmsWorldBorder;
import com.craftaro.core.nms.world.WorldCore;
import org.jetbrains.annotations.NotNull;
@SuppressWarnings("unused")
public class NmsImplementationsImpl implements NmsImplementations {
private final NmsEntity entity;
private final NMSPlayer player;
private final WorldCore world;
private final NmsWorldBorder worldBorder;
@ -21,6 +24,7 @@ public class NmsImplementationsImpl implements NmsImplementations {
private final NBTCore nbt;
public NmsImplementationsImpl() {
this.entity = new NmsEntityImpl();
this.player = new NMSPlayerImpl();
this.world = new WorldCoreImpl();
this.worldBorder = new NmsWorldBorderImpl();
@ -28,6 +32,11 @@ public class NmsImplementationsImpl implements NmsImplementations {
this.nbt = new NBTCoreImpl();
}
@Override
public @NotNull NmsEntity getEntity() {
return this.entity;
}
@Override
public @NotNull NMSPlayer getPlayer() {
return this.player;

View File

@ -0,0 +1,33 @@
package com.craftaro.core.nms.v1_13_R2.entity;
import com.craftaro.core.nms.entity.NmsEntity;
import net.minecraft.server.v1_13_R2.Entity;
import net.minecraft.server.v1_13_R2.EntityInsentient;
import org.bukkit.craftbukkit.v1_13_R2.entity.CraftEntity;
public class NmsEntityImpl implements NmsEntity {
@Override
public boolean isMob(org.bukkit.entity.Entity entity) {
return ((CraftEntity) entity).getHandle() instanceof EntityInsentient;
}
@Override
public void setMobAware(org.bukkit.entity.Entity entity, boolean aware) {
if (!isMob(entity)) {
throw new IllegalArgumentException("Entity is not a mob and cannot be set aware");
}
Entity nmsEntity = ((CraftEntity) entity).getHandle();
nmsEntity.fromMobSpawner = aware;
}
@Override
public boolean isAware(org.bukkit.entity.Entity entity) {
Entity nmsEntity = ((CraftEntity) entity).getHandle();
if (nmsEntity instanceof EntityInsentient) {
return nmsEntity.fromMobSpawner;
}
return false;
}
}

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

@ -1,19 +1,22 @@
package com.craftaro.core.nms.v1_14_R1;
import com.craftaro.core.nms.v1_14_R1.anvil.AnvilCore;
import com.craftaro.core.nms.v1_14_R1.entity.NMSPlayerImpl;
import com.craftaro.core.nms.v1_14_R1.world.NmsWorldBorderImpl;
import com.craftaro.core.nms.v1_14_R1.world.WorldCoreImpl;
import com.craftaro.core.nms.NmsImplementations;
import com.craftaro.core.nms.entity.NMSPlayer;
import com.craftaro.core.nms.entity.NmsEntity;
import com.craftaro.core.nms.nbt.NBTCore;
import com.craftaro.core.nms.v1_14_R1.anvil.AnvilCore;
import com.craftaro.core.nms.v1_14_R1.entity.NMSPlayerImpl;
import com.craftaro.core.nms.v1_14_R1.entity.NmsEntityImpl;
import com.craftaro.core.nms.v1_14_R1.nbt.NBTCoreImpl;
import com.craftaro.core.nms.v1_14_R1.world.NmsWorldBorderImpl;
import com.craftaro.core.nms.v1_14_R1.world.WorldCoreImpl;
import com.craftaro.core.nms.world.NmsWorldBorder;
import com.craftaro.core.nms.world.WorldCore;
import org.jetbrains.annotations.NotNull;
@SuppressWarnings("unused")
public class NmsImplementationsImpl implements NmsImplementations {
private final NmsEntity entity;
private final NMSPlayer player;
private final WorldCore world;
private final NmsWorldBorder worldBorder;
@ -21,6 +24,7 @@ public class NmsImplementationsImpl implements NmsImplementations {
private final NBTCore nbt;
public NmsImplementationsImpl() {
this.entity = new NmsEntityImpl();
this.player = new NMSPlayerImpl();
this.world = new WorldCoreImpl();
this.worldBorder = new NmsWorldBorderImpl();
@ -28,6 +32,11 @@ public class NmsImplementationsImpl implements NmsImplementations {
this.nbt = new NBTCoreImpl();
}
@Override
public @NotNull NmsEntity getEntity() {
return this.entity;
}
@Override
public @NotNull NMSPlayer getPlayer() {
return this.player;

View File

@ -0,0 +1,33 @@
package com.craftaro.core.nms.v1_14_R1.entity;
import com.craftaro.core.nms.entity.NmsEntity;
import net.minecraft.server.v1_14_R1.Entity;
import net.minecraft.server.v1_14_R1.EntityInsentient;
import org.bukkit.craftbukkit.v1_14_R1.entity.CraftEntity;
public class NmsEntityImpl implements NmsEntity {
@Override
public boolean isMob(org.bukkit.entity.Entity entity) {
return ((CraftEntity) entity).getHandle() instanceof EntityInsentient;
}
@Override
public void setMobAware(org.bukkit.entity.Entity entity, boolean aware) {
if (!isMob(entity)) {
throw new IllegalArgumentException("Entity is not a mob and cannot be set aware");
}
Entity nmsEntity = ((CraftEntity) entity).getHandle();
nmsEntity.fromMobSpawner = aware;
}
@Override
public boolean isAware(org.bukkit.entity.Entity entity) {
Entity nmsEntity = ((CraftEntity) entity).getHandle();
if (nmsEntity instanceof EntityInsentient) {
return nmsEntity.fromMobSpawner;
}
return false;
}
}

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

@ -1,19 +1,22 @@
package com.craftaro.core.nms.v1_15_R1;
import com.craftaro.core.nms.v1_15_R1.anvil.AnvilCore;
import com.craftaro.core.nms.v1_15_R1.entity.NMSPlayerImpl;
import com.craftaro.core.nms.v1_15_R1.world.NmsWorldBorderImpl;
import com.craftaro.core.nms.v1_15_R1.world.WorldCoreImpl;
import com.craftaro.core.nms.NmsImplementations;
import com.craftaro.core.nms.entity.NMSPlayer;
import com.craftaro.core.nms.entity.NmsEntity;
import com.craftaro.core.nms.nbt.NBTCore;
import com.craftaro.core.nms.v1_15_R1.anvil.AnvilCore;
import com.craftaro.core.nms.v1_15_R1.entity.NMSPlayerImpl;
import com.craftaro.core.nms.v1_15_R1.entity.NmsEntityImpl;
import com.craftaro.core.nms.v1_15_R1.nbt.NBTCoreImpl;
import com.craftaro.core.nms.v1_15_R1.world.NmsWorldBorderImpl;
import com.craftaro.core.nms.v1_15_R1.world.WorldCoreImpl;
import com.craftaro.core.nms.world.NmsWorldBorder;
import com.craftaro.core.nms.world.WorldCore;
import org.jetbrains.annotations.NotNull;
@SuppressWarnings("unused")
public class NmsImplementationsImpl implements NmsImplementations {
private final NmsEntity entity;
private final NMSPlayer player;
private final WorldCore world;
private final NmsWorldBorder worldBorder;
@ -21,6 +24,7 @@ public class NmsImplementationsImpl implements NmsImplementations {
private final NBTCore nbt;
public NmsImplementationsImpl() {
this.entity = new NmsEntityImpl();
this.player = new NMSPlayerImpl();
this.world = new WorldCoreImpl();
this.worldBorder = new NmsWorldBorderImpl();
@ -28,6 +32,11 @@ public class NmsImplementationsImpl implements NmsImplementations {
this.nbt = new NBTCoreImpl();
}
@Override
public @NotNull NmsEntity getEntity() {
return this.entity;
}
@Override
public @NotNull NMSPlayer getPlayer() {
return this.player;

View File

@ -0,0 +1,33 @@
package com.craftaro.core.nms.v1_15_R1.entity;
import com.craftaro.core.nms.entity.NmsEntity;
import net.minecraft.server.v1_15_R1.Entity;
import net.minecraft.server.v1_15_R1.EntityInsentient;
import org.bukkit.craftbukkit.v1_15_R1.entity.CraftEntity;
public class NmsEntityImpl implements NmsEntity {
@Override
public boolean isMob(org.bukkit.entity.Entity entity) {
return ((CraftEntity) entity).getHandle() instanceof EntityInsentient;
}
@Override
public void setMobAware(org.bukkit.entity.Entity entity, boolean aware) {
if (!isMob(entity)) {
throw new IllegalArgumentException("Entity is not a mob and cannot be set aware");
}
Entity nmsEntity = ((CraftEntity) entity).getHandle();
nmsEntity.fromMobSpawner = aware;
}
@Override
public boolean isAware(org.bukkit.entity.Entity entity) {
Entity nmsEntity = ((CraftEntity) entity).getHandle();
if (nmsEntity instanceof EntityInsentient) {
return nmsEntity.fromMobSpawner;
}
return false;
}
}

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

@ -1,19 +1,22 @@
package com.craftaro.core.nms.v1_16_R1;
import com.craftaro.core.nms.NmsImplementations;
import com.craftaro.core.nms.entity.NMSPlayer;
import com.craftaro.core.nms.entity.NmsEntity;
import com.craftaro.core.nms.nbt.NBTCore;
import com.craftaro.core.nms.v1_16_R1.anvil.AnvilCore;
import com.craftaro.core.nms.v1_16_R1.entity.NMSPlayerImpl;
import com.craftaro.core.nms.v1_16_R1.entity.NmsEntityImpl;
import com.craftaro.core.nms.v1_16_R1.nbt.NBTCoreImpl;
import com.craftaro.core.nms.v1_16_R1.world.NmsWorldBorderImpl;
import com.craftaro.core.nms.v1_16_R1.world.WorldCoreImpl;
import com.craftaro.core.nms.NmsImplementations;
import com.craftaro.core.nms.entity.NMSPlayer;
import com.craftaro.core.nms.nbt.NBTCore;
import com.craftaro.core.nms.world.NmsWorldBorder;
import com.craftaro.core.nms.world.WorldCore;
import org.jetbrains.annotations.NotNull;
@SuppressWarnings("unused")
public class NmsImplementationsImpl implements NmsImplementations {
private final NmsEntity entity;
private final NMSPlayer player;
private final WorldCore world;
private final NmsWorldBorder worldBorder;
@ -21,6 +24,7 @@ public class NmsImplementationsImpl implements NmsImplementations {
private final NBTCore nbt;
public NmsImplementationsImpl() {
this.entity = new NmsEntityImpl();
this.player = new NMSPlayerImpl();
this.world = new WorldCoreImpl();
this.worldBorder = new NmsWorldBorderImpl();
@ -28,6 +32,11 @@ public class NmsImplementationsImpl implements NmsImplementations {
this.nbt = new NBTCoreImpl();
}
@Override
public @NotNull NmsEntity getEntity() {
return this.entity;
}
@Override
public @NotNull NMSPlayer getPlayer() {
return this.player;

View File

@ -0,0 +1,33 @@
package com.craftaro.core.nms.v1_16_R1.entity;
import com.craftaro.core.nms.entity.NmsEntity;
import net.minecraft.server.v1_16_R1.Entity;
import net.minecraft.server.v1_16_R1.EntityInsentient;
import org.bukkit.craftbukkit.v1_16_R1.entity.CraftEntity;
public class NmsEntityImpl implements NmsEntity {
@Override
public boolean isMob(org.bukkit.entity.Entity entity) {
return ((CraftEntity) entity).getHandle() instanceof EntityInsentient;
}
@Override
public void setMobAware(org.bukkit.entity.Entity entity, boolean aware) {
if (!isMob(entity)) {
throw new IllegalArgumentException("Entity is not a mob and cannot be set aware");
}
Entity nmsEntity = ((CraftEntity) entity).getHandle();
((EntityInsentient) nmsEntity).aware = aware;
}
@Override
public boolean isAware(org.bukkit.entity.Entity entity) {
Entity nmsEntity = ((CraftEntity) entity).getHandle();
if (nmsEntity instanceof EntityInsentient) {
return ((EntityInsentient) nmsEntity).aware;
}
return false;
}
}

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

@ -1,19 +1,22 @@
package com.craftaro.core.nms.v1_16_R2;
import com.craftaro.core.nms.NmsImplementations;
import com.craftaro.core.nms.entity.NMSPlayer;
import com.craftaro.core.nms.entity.NmsEntity;
import com.craftaro.core.nms.nbt.NBTCore;
import com.craftaro.core.nms.v1_16_R2.anvil.AnvilCore;
import com.craftaro.core.nms.v1_16_R2.entity.NMSPlayerImpl;
import com.craftaro.core.nms.v1_16_R2.entity.NmsEntityImpl;
import com.craftaro.core.nms.v1_16_R2.nbt.NBTCoreImpl;
import com.craftaro.core.nms.v1_16_R2.world.NmsWorldBorderImpl;
import com.craftaro.core.nms.v1_16_R2.world.WorldCoreImpl;
import com.craftaro.core.nms.NmsImplementations;
import com.craftaro.core.nms.entity.NMSPlayer;
import com.craftaro.core.nms.nbt.NBTCore;
import com.craftaro.core.nms.world.NmsWorldBorder;
import com.craftaro.core.nms.world.WorldCore;
import org.jetbrains.annotations.NotNull;
@SuppressWarnings("unused")
public class NmsImplementationsImpl implements NmsImplementations {
private final NmsEntity entity;
private final NMSPlayer player;
private final WorldCore world;
private final NmsWorldBorder worldBorder;
@ -21,6 +24,7 @@ public class NmsImplementationsImpl implements NmsImplementations {
private final NBTCore nbt;
public NmsImplementationsImpl() {
this.entity = new NmsEntityImpl();
this.player = new NMSPlayerImpl();
this.world = new WorldCoreImpl();
this.worldBorder = new NmsWorldBorderImpl();
@ -28,6 +32,11 @@ public class NmsImplementationsImpl implements NmsImplementations {
this.nbt = new NBTCoreImpl();
}
@Override
public @NotNull NmsEntity getEntity() {
return this.entity;
}
@Override
public @NotNull NMSPlayer getPlayer() {
return this.player;

View File

@ -0,0 +1,33 @@
package com.craftaro.core.nms.v1_16_R2.entity;
import com.craftaro.core.nms.entity.NmsEntity;
import net.minecraft.server.v1_16_R2.Entity;
import net.minecraft.server.v1_16_R2.EntityInsentient;
import org.bukkit.craftbukkit.v1_16_R2.entity.CraftEntity;
public class NmsEntityImpl implements NmsEntity {
@Override
public boolean isMob(org.bukkit.entity.Entity entity) {
return ((CraftEntity) entity).getHandle() instanceof EntityInsentient;
}
@Override
public void setMobAware(org.bukkit.entity.Entity entity, boolean aware) {
if (!isMob(entity)) {
throw new IllegalArgumentException("Entity is not a mob and cannot be set aware");
}
Entity nmsEntity = ((CraftEntity) entity).getHandle();
((EntityInsentient) nmsEntity).aware = aware;
}
@Override
public boolean isAware(org.bukkit.entity.Entity entity) {
Entity nmsEntity = ((CraftEntity) entity).getHandle();
if (nmsEntity instanceof EntityInsentient) {
return ((EntityInsentient) nmsEntity).aware;
}
return false;
}
}

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

@ -1,19 +1,22 @@
package com.craftaro.core.nms.v1_16_R3;
import com.craftaro.core.nms.NmsImplementations;
import com.craftaro.core.nms.entity.NMSPlayer;
import com.craftaro.core.nms.entity.NmsEntity;
import com.craftaro.core.nms.nbt.NBTCore;
import com.craftaro.core.nms.v1_16_R3.anvil.AnvilCore;
import com.craftaro.core.nms.v1_16_R3.entity.NMSPlayerImpl;
import com.craftaro.core.nms.v1_16_R3.entity.NmsEntityImpl;
import com.craftaro.core.nms.v1_16_R3.nbt.NBTCoreImpl;
import com.craftaro.core.nms.v1_16_R3.world.NmsWorldBorderImpl;
import com.craftaro.core.nms.v1_16_R3.world.WorldCoreImpl;
import com.craftaro.core.nms.NmsImplementations;
import com.craftaro.core.nms.entity.NMSPlayer;
import com.craftaro.core.nms.nbt.NBTCore;
import com.craftaro.core.nms.world.NmsWorldBorder;
import com.craftaro.core.nms.world.WorldCore;
import org.jetbrains.annotations.NotNull;
@SuppressWarnings("unused")
public class NmsImplementationsImpl implements NmsImplementations {
private final NmsEntity entity;
private final NMSPlayer player;
private final WorldCore world;
private final NmsWorldBorder worldBorder;
@ -21,6 +24,7 @@ public class NmsImplementationsImpl implements NmsImplementations {
private final NBTCore nbt;
public NmsImplementationsImpl() {
this.entity = new NmsEntityImpl();
this.player = new NMSPlayerImpl();
this.world = new WorldCoreImpl();
this.worldBorder = new NmsWorldBorderImpl();
@ -28,6 +32,11 @@ public class NmsImplementationsImpl implements NmsImplementations {
this.nbt = new NBTCoreImpl();
}
@Override
public @NotNull NmsEntity getEntity() {
return this.entity;
}
@Override
public @NotNull NMSPlayer getPlayer() {
return this.player;

Some files were not shown because too many files have changed in this diff Show More