mirror of
https://github.com/songoda/SongodaCore.git
synced 2024-11-30 14:03:23 +01:00
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:
commit
5d9cab5613
@ -19,5 +19,5 @@ runs:
|
|||||||
|
|
||||||
- uses: SpraxDev/Action-SpigotMC@v4
|
- uses: SpraxDev/Action-SpigotMC@v4
|
||||||
with:
|
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
|
remapped: true
|
||||||
|
1
.github/workflows/build.yml
vendored
1
.github/workflows/build.yml
vendored
@ -45,6 +45,7 @@ jobs:
|
|||||||
append_snapshot: ${{ github.ref_type == 'tag' && 'false' || 'true' }}
|
append_snapshot: ${{ github.ref_type == 'tag' && 'false' || 'true' }}
|
||||||
version: ${{ github.ref_type == 'tag' && github.ref_name || '' }}
|
version: ${{ github.ref_type == 'tag' && github.ref_name || '' }}
|
||||||
increment_version: ${{ github.ref_type == 'tag' && '' || 'patch' }}
|
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
|
- name: Build with Maven
|
||||||
run: mvn -B -Duser.name="GitHub Actions on $GITHUB_REPOSITORY (id=$GITHUB_RUN_ID)" -DskipTests clean package
|
run: mvn -B -Duser.name="GitHub Actions on $GITHUB_REPOSITORY (id=$GITHUB_RUN_ID)" -DskipTests clean package
|
||||||
|
@ -12,6 +12,13 @@
|
|||||||
</parent>
|
</parent>
|
||||||
<artifactId>CraftaroCore-Compatibility</artifactId>
|
<artifactId>CraftaroCore-Compatibility</artifactId>
|
||||||
|
|
||||||
|
<repositories>
|
||||||
|
<repository>
|
||||||
|
<id>ViaVersion</id>
|
||||||
|
<url>https://repo.viaversion.com/</url>
|
||||||
|
</repository>
|
||||||
|
</repositories>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.spigotmc</groupId>
|
<groupId>org.spigotmc</groupId>
|
||||||
@ -23,7 +30,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.viaversion</groupId>
|
<groupId>com.viaversion</groupId>
|
||||||
<artifactId>viaversion-api</artifactId>
|
<artifactId>viaversion-api</artifactId>
|
||||||
<version>4.0.1</version>
|
<version>4.7.0</version>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
@ -33,5 +40,12 @@
|
|||||||
<version>4.29</version>
|
<version>4.29</version>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.github.cryptomorin</groupId>
|
||||||
|
<artifactId>XSeries</artifactId>
|
||||||
|
<version>9.4.0</version>
|
||||||
|
<scope>compile</scope>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</project>
|
</project>
|
||||||
|
@ -58,8 +58,8 @@ public enum ClassMapping {
|
|||||||
private final String packageName;
|
private final String packageName;
|
||||||
private final String className;
|
private final String className;
|
||||||
|
|
||||||
ClassMapping(String packageName) {
|
ClassMapping(String className) {
|
||||||
this(null, packageName);
|
this(null, className);
|
||||||
}
|
}
|
||||||
|
|
||||||
ClassMapping(String packageName, String className) {
|
ClassMapping(String packageName, String className) {
|
||||||
@ -72,17 +72,17 @@ public enum ClassMapping {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Class<?> getClazz(String sub) {
|
public Class<?> getClazz(String sub) {
|
||||||
String name = sub == null ? className : className + "$" + sub;
|
String name = sub == null ? this.className : this.className + "$" + sub;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (className.startsWith("Craft")) {
|
if (this.className.startsWith("Craft")) {
|
||||||
return Class.forName("org.bukkit.craftbukkit." + ServerVersion.getServerVersionString()
|
return Class.forName("org.bukkit.craftbukkit." + ServerVersion.getServerVersionString()
|
||||||
+ (packageName == null ? "" : "." + packageName) + "." + name);
|
+ (this.packageName == null ? "" : "." + this.packageName) + "." + name);
|
||||||
}
|
}
|
||||||
|
|
||||||
return Class.forName("net.minecraft." + (
|
return Class.forName("net.minecraft." + (
|
||||||
ServerVersion.isServerVersionAtLeast(ServerVersion.V1_17) && packageName != null
|
ServerVersion.isServerVersionAtLeast(ServerVersion.V1_17) && this.packageName != null
|
||||||
? packageName : "server." + ServerVersion.getServerVersionString()) + "." + name);
|
? this.packageName : "server." + ServerVersion.getServerVersionString()) + "." + name);
|
||||||
} catch (ClassNotFoundException ex) {
|
} catch (ClassNotFoundException ex) {
|
||||||
ex.printStackTrace();
|
ex.printStackTrace();
|
||||||
}
|
}
|
||||||
|
@ -13,7 +13,7 @@ import java.util.UUID;
|
|||||||
* NOTE: this is automatically initialized through SongodaCore
|
* NOTE: this is automatically initialized through SongodaCore
|
||||||
*/
|
*/
|
||||||
public class ClientVersion {
|
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
|
* Check to see what client version this player is connected to the server
|
||||||
@ -103,9 +103,19 @@ public class ClientVersion {
|
|||||||
case 755:
|
case 755:
|
||||||
case 756:
|
case 756:
|
||||||
return ServerVersion.V1_17;
|
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:
|
default:
|
||||||
return version > 756 ? ServerVersion.getServerVersion() : ServerVersion.UNKNOWN;
|
return version > 763 ? ServerVersion.getServerVersion() : ServerVersion.UNKNOWN;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -165,7 +165,7 @@ public enum CompatibleBiome {
|
|||||||
}
|
}
|
||||||
|
|
||||||
CompatibleBiome() {
|
CompatibleBiome() {
|
||||||
versions.add(v(ServerVersion.UNKNOWN, name()));
|
this.versions.add(v(ServerVersion.UNKNOWN, name()));
|
||||||
}
|
}
|
||||||
|
|
||||||
CompatibleBiome(ServerVersion version, Version... versions) {
|
CompatibleBiome(ServerVersion version, Version... versions) {
|
||||||
@ -178,12 +178,12 @@ public enum CompatibleBiome {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public List<Version> getVersions() {
|
public List<Version> getVersions() {
|
||||||
return new LinkedList<>(versions);
|
return new LinkedList<>(this.versions);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Biome getBiome() {
|
public Biome getBiome() {
|
||||||
try {
|
try {
|
||||||
for (Version version : versions) {
|
for (Version version : this.versions) {
|
||||||
if (ServerVersion.isServerVersionAtLeast(version.version)) {
|
if (ServerVersion.isServerVersionAtLeast(version.version)) {
|
||||||
return Biome.valueOf(version.biome);
|
return Biome.valueOf(version.biome);
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package com.craftaro.core.compatibility;
|
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.EquipmentSlot;
|
||||||
import org.bukkit.inventory.ItemStack;
|
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) {
|
public void takeItem(LivingEntity entity) {
|
||||||
takeItem(player, 1);
|
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
|
* @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
|
ItemStack item = this == CompatibleHand.MAIN_HAND
|
||||||
? player.getInventory().getItemInHand() : player.getInventory().getItemInOffHand();
|
? entity.getEquipment().getItemInHand() : entity.getEquipment().getItemInOffHand();
|
||||||
|
|
||||||
int result = item.getAmount() - amount;
|
int result = item.getAmount() - amount;
|
||||||
item.setAmount(result);
|
item.setAmount(result);
|
||||||
|
|
||||||
if (this == CompatibleHand.MAIN_HAND) {
|
if (this == CompatibleHand.MAIN_HAND) {
|
||||||
player.setItemInHand(result > 0 ? item : null);
|
entity.getEquipment().setItemInHand(result > 0 ? item : null);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
player.getInventory().setItemInOffHand(result > 0 ? item : null);
|
entity.getEquipment().setItemInOffHand(result > 0 ? item : null);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get item in the selected hand
|
* 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) {
|
public ItemStack getItem(LivingEntity entity) {
|
||||||
if (this == MAIN_HAND) {
|
EntityEquipment equipment = entity.getEquipment();
|
||||||
return player.getItemInHand();
|
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
|
* Set the item in the selected hand
|
||||||
*
|
*
|
||||||
* @param player the player to set the item of
|
* @param entity The entity to set the item of
|
||||||
* @param item the item to set
|
* @param item The item to set
|
||||||
*/
|
*/
|
||||||
public void setItem(Player player, ItemStack item) {
|
public void setItem(LivingEntity entity, ItemStack item) {
|
||||||
if (this == MAIN_HAND) {
|
if (this == MAIN_HAND) {
|
||||||
player.setItemInHand(item);
|
entity.getEquipment().setItemInHand(item);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
player.getInventory().setItemInOffHand(item);
|
entity.getEquipment().setItemInOffHand(item);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -124,7 +124,7 @@ public class CompatibleParticleHandler {
|
|||||||
final boolean compatibilityMode;
|
final boolean compatibilityMode;
|
||||||
final LegacyParticleEffects.Type compatibleEffect;
|
final LegacyParticleEffects.Type compatibleEffect;
|
||||||
final Object particle;
|
final Object particle;
|
||||||
final static Map<String, ParticleType> map = new HashMap<>();
|
static final Map<String, ParticleType> map = new HashMap<>();
|
||||||
|
|
||||||
static {
|
static {
|
||||||
for (ParticleType t : values()) {
|
for (ParticleType t : values()) {
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package com.craftaro.core.compatibility;
|
package com.craftaro.core.compatibility;
|
||||||
|
|
||||||
|
import com.cryptomorin.xseries.XSound;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.Sound;
|
import org.bukkit.Sound;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
@ -7,7 +8,6 @@ import org.bukkit.entity.Player;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* TODO: Probably recode to be similar to CompatibleMaterial
|
* TODO: Probably recode to be similar to CompatibleMaterial
|
||||||
*
|
|
||||||
* Sounds that are compatible with server versions 1.7+ <br>
|
* Sounds that are compatible with server versions 1.7+ <br>
|
||||||
* TODO: This needs work.
|
* TODO: This needs work.
|
||||||
* Finished 1.8, finished 1.9 blocks, resume with 1.9 entities<br>
|
* 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
|
* 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
|
* well. The intent of this class is to provide either the correct sound or a
|
||||||
* near equivalent for the current server.
|
* near equivalent for the current server.
|
||||||
|
*
|
||||||
|
* @deprecated Use {@link XSound} instead.
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
public enum CompatibleSound {
|
public enum CompatibleSound {
|
||||||
// some of these values are missing an API value...
|
// some of these values are missing an API value...
|
||||||
// would using the raw strings be better?
|
// would using the raw strings be better?
|
||||||
@ -1358,19 +1361,19 @@ public enum CompatibleSound {
|
|||||||
if (DEBUG && find == null) {
|
if (DEBUG && find == null) {
|
||||||
System.err.println("Sound for " + name() + " not found!");
|
System.err.println("Sound for " + name() + " not found!");
|
||||||
}
|
}
|
||||||
sound = find;
|
this.sound = find;
|
||||||
compatibilityMode = find == null;
|
this.compatibilityMode = find == null;
|
||||||
}
|
}
|
||||||
|
|
||||||
// if the sound only ever changed from 1.8 -> 1.9
|
// if the sound only ever changed from 1.8 -> 1.9
|
||||||
CompatibleSound(String compatibility_18) {
|
CompatibleSound(String compatibility_18) {
|
||||||
try {
|
try {
|
||||||
compatibilityMode = false;
|
this.compatibilityMode = false;
|
||||||
|
|
||||||
if (ServerVersion.isServerVersionBelow(ServerVersion.V1_9)) {
|
if (ServerVersion.isServerVersionBelow(ServerVersion.V1_9)) {
|
||||||
sound = Sound.valueOf(compatibility_18);
|
this.sound = Sound.valueOf(compatibility_18);
|
||||||
} else {
|
} else {
|
||||||
sound = Sound.valueOf(name());
|
this.sound = Sound.valueOf(name());
|
||||||
}
|
}
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
System.err.println("ERROR loading " + name());
|
System.err.println("ERROR loading " + name());
|
||||||
@ -1382,8 +1385,8 @@ public enum CompatibleSound {
|
|||||||
try {
|
try {
|
||||||
for (Version v : versions) {
|
for (Version v : versions) {
|
||||||
if (v.sound != null && ServerVersion.isServerVersionAtLeast(v.version)) {
|
if (v.sound != null && ServerVersion.isServerVersionAtLeast(v.version)) {
|
||||||
sound = Sound.valueOf(v.sound);
|
this.sound = Sound.valueOf(v.sound);
|
||||||
compatibilityMode = v.compatibilityMode;
|
this.compatibilityMode = v.compatibilityMode;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1404,28 +1407,28 @@ public enum CompatibleSound {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
sound = find;
|
this.sound = find;
|
||||||
compatibilityMode = find == null;
|
this.compatibilityMode = find == null;
|
||||||
}
|
}
|
||||||
|
|
||||||
CompatibleSound(ServerVersion minVersion, Version... versions) {
|
CompatibleSound(ServerVersion minVersion, Version... versions) {
|
||||||
try {
|
try {
|
||||||
if (ServerVersion.isServerVersionAtLeast(minVersion)) {
|
if (ServerVersion.isServerVersionAtLeast(minVersion)) {
|
||||||
// should be good to use this sound
|
// should be good to use this sound
|
||||||
sound = Sound.valueOf(name());
|
this.sound = Sound.valueOf(name());
|
||||||
} else {
|
} else {
|
||||||
for (Version v : versions) {
|
for (Version v : versions) {
|
||||||
if (v.sound != null && ServerVersion.isServerVersionAtLeast(v.version)) {
|
if (v.sound != null && ServerVersion.isServerVersionAtLeast(v.version)) {
|
||||||
sound = Sound.valueOf(v.sound);
|
this.sound = Sound.valueOf(v.sound);
|
||||||
compatibilityMode = v.compatibilityMode;
|
this.compatibilityMode = v.compatibilityMode;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
sound = null;
|
this.sound = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
compatibilityMode = false;
|
this.compatibilityMode = false;
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
System.err.println("ERROR loading " + name() + " (" + minVersion + ")");
|
System.err.println("ERROR loading " + name() + " (" + minVersion + ")");
|
||||||
for (Version v : versions) {
|
for (Version v : versions) {
|
||||||
@ -1443,7 +1446,7 @@ public enum CompatibleSound {
|
|||||||
* @return Either the matching sound or a similar sound
|
* @return Either the matching sound or a similar sound
|
||||||
*/
|
*/
|
||||||
public Sound getSound() {
|
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.
|
* @return Returns false if we are using a different sound.
|
||||||
*/
|
*/
|
||||||
public boolean usesCompatibility() {
|
public boolean usesCompatibility() {
|
||||||
return !compatibilityMode;
|
return !this.compatibilityMode;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Version v(String sound) {
|
private static Version v(String sound) {
|
||||||
|
@ -809,41 +809,41 @@ public enum LegacyMaterialAnalouge {
|
|||||||
this.compatibleData = compatData;
|
this.compatibleData = compatData;
|
||||||
|
|
||||||
if (ServerVersion.isServerVersionBelow(versionLessThan)) {
|
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
|
// fallback material not available, so use its fallback
|
||||||
material = Material.getMaterial(compatibleMaterial);
|
this.material = Material.getMaterial(this.compatibleMaterial);
|
||||||
data = compatibleData;
|
this.data = this.compatibleData;
|
||||||
} else if (modernMaterial == null || ServerVersion.isServerVersionBelow(ServerVersion.V1_13)) {
|
} else if (this.modernMaterial == null || ServerVersion.isServerVersionBelow(ServerVersion.V1_13)) {
|
||||||
// use legacy material if on legacy
|
// use legacy material if on legacy
|
||||||
material = Material.getMaterial(legacyMaterial);
|
this.material = Material.getMaterial(legacyMaterial);
|
||||||
data = legacyData;
|
this.data = legacyData;
|
||||||
} else {
|
} else {
|
||||||
material = Material.getMaterial(modernMaterial);
|
this.material = Material.getMaterial(this.modernMaterial);
|
||||||
data = null;
|
this.data = null;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
material = null;
|
this.material = null;
|
||||||
data = null;
|
this.data = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Material getMaterial() {
|
public Material getMaterial() {
|
||||||
return material;
|
return this.material;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean usesData() {
|
public boolean usesData() {
|
||||||
return data != null;
|
return this.data != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public byte getData() {
|
public byte getData() {
|
||||||
return data == null ? 0 : data;
|
return this.data == null ? 0 : this.data;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ItemStack getItem() {
|
public ItemStack getItem() {
|
||||||
if (material == null) {
|
if (this.material == null) {
|
||||||
return 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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -52,8 +52,8 @@ public enum LegacyMaterialBlockType {
|
|||||||
final String alternateBlockMaterialName;
|
final String alternateBlockMaterialName;
|
||||||
final Material blockMaterial, alternateBlockMaterial;
|
final Material blockMaterial, alternateBlockMaterial;
|
||||||
final boolean requiresData; // some blocks require data to render properly (double blocks)
|
final boolean requiresData; // some blocks require data to render properly (double blocks)
|
||||||
final static Map<String, LegacyMaterialBlockType> lookupTable = new HashMap<>();
|
static final Map<String, LegacyMaterialBlockType> lookupTable = new HashMap<>();
|
||||||
final static Map<String, LegacyMaterialBlockType> reverseLookupTable = new HashMap<>();
|
static final Map<String, LegacyMaterialBlockType> reverseLookupTable = new HashMap<>();
|
||||||
|
|
||||||
static {
|
static {
|
||||||
for (LegacyMaterialBlockType t : values()) {
|
for (LegacyMaterialBlockType t : values()) {
|
||||||
@ -85,29 +85,29 @@ public enum LegacyMaterialBlockType {
|
|||||||
this.blockMaterialName = blockMaterial;
|
this.blockMaterialName = blockMaterial;
|
||||||
this.alternateBlockMaterialName = alternateMaterial;
|
this.alternateBlockMaterialName = alternateMaterial;
|
||||||
this.requiresData = requiresData;
|
this.requiresData = requiresData;
|
||||||
this.blockMaterial = Material.getMaterial(blockMaterialName);
|
this.blockMaterial = Material.getMaterial(this.blockMaterialName);
|
||||||
this.alternateBlockMaterial = Material.getMaterial(alternateBlockMaterialName);
|
this.alternateBlockMaterial = Material.getMaterial(this.alternateBlockMaterialName);
|
||||||
this.blockData = data;
|
this.blockData = data;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getBlockMaterialName() {
|
public String getBlockMaterialName() {
|
||||||
return blockMaterialName;
|
return this.blockMaterialName;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getAlternateMaterialName() {
|
public String getAlternateMaterialName() {
|
||||||
return alternateBlockMaterialName;
|
return this.alternateBlockMaterialName;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Material getBlockMaterial() {
|
public Material getBlockMaterial() {
|
||||||
return blockMaterial;
|
return this.blockMaterial;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Material getAlternateBlockMaterial() {
|
public Material getAlternateBlockMaterial() {
|
||||||
return alternateBlockMaterial;
|
return this.alternateBlockMaterial;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean requiresData() {
|
public boolean requiresData() {
|
||||||
return requiresData;
|
return this.requiresData;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static LegacyMaterialBlockType getMaterial(String lookup) {
|
public static LegacyMaterialBlockType getMaterial(String lookup) {
|
||||||
|
@ -15,7 +15,6 @@ import java.util.logging.Logger;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Particle effects for servers 1.8 and below
|
* Particle effects for servers 1.8 and below
|
||||||
*
|
|
||||||
* TODO: Needs a recode, this class should not have any advanced logic like NMS magic
|
* TODO: Needs a recode, this class should not have any advanced logic like NMS magic
|
||||||
*/
|
*/
|
||||||
public class LegacyParticleEffects {
|
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)
|
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
|
// collect a list of players to send this packet to
|
||||||
List<Player> sendTo = new ArrayList();
|
List<Player> sendTo = new ArrayList<>();
|
||||||
if (localOnly == null) {
|
if (localOnly == null) {
|
||||||
for (Player p : l.getWorld().getPlayers()) {
|
for (Player p : l.getWorld().getPlayers()) {
|
||||||
if (p.getLocation().distanceSquared(l) <= rangeSquared) {
|
if (p.getLocation().distanceSquared(l) <= rangeSquared) {
|
||||||
|
@ -3,15 +3,12 @@ package com.craftaro.core.compatibility;
|
|||||||
import org.bukkit.potion.PotionEffectType;
|
import org.bukkit.potion.PotionEffectType;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Random;
|
|
||||||
|
|
||||||
public class LegacyPotionEffects {
|
public class LegacyPotionEffects {
|
||||||
private LegacyPotionEffects() {
|
private LegacyPotionEffects() {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected final static Random rand = new Random();
|
private static final HashMap<Integer, String> potionEffectNames = new HashMap<Integer, String>() {
|
||||||
|
|
||||||
private final static HashMap<Integer, String> potionEffectNames = new HashMap<Integer, String>() {
|
|
||||||
{
|
{
|
||||||
put(PotionEffectType.SPEED.getId(), "Speed");
|
put(PotionEffectType.SPEED.getId(), "Speed");
|
||||||
put(PotionEffectType.SLOW.getId(), "Slowness");
|
put(PotionEffectType.SLOW.getId(), "Slowness");
|
||||||
|
@ -109,43 +109,43 @@ public enum MethodMapping {
|
|||||||
|
|
||||||
public Method getMethod(Class<?> clazz) {
|
public Method getMethod(Class<?> clazz) {
|
||||||
try {
|
try {
|
||||||
String methodName = _1_18;
|
String methodName = this._1_18;
|
||||||
switch (ServerVersion.getServerVersion()) {
|
switch (ServerVersion.getServerVersion()) {
|
||||||
case V1_14:
|
case V1_14:
|
||||||
if (_1_14 != null) {
|
if (this._1_14 != null) {
|
||||||
methodName = _1_14;
|
methodName = this._1_14;
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case V1_17:
|
case V1_17:
|
||||||
if (_1_17 != null) {
|
if (this._1_17 != null) {
|
||||||
methodName = _1_17;
|
methodName = this._1_17;
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case V1_18:
|
case V1_18:
|
||||||
if (_1_18_2 != null) {
|
if (this._1_18_2 != null) {
|
||||||
methodName = _1_18_2;
|
methodName = this._1_18_2;
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case V1_19:
|
case V1_19:
|
||||||
if (_1_19 != null) {
|
if (this._1_19 != null) {
|
||||||
methodName = _1_19;
|
methodName = this._1_19;
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Method method = clazz.getMethod(methodName, parameters);
|
Method method = clazz.getMethod(methodName, this.parameters);
|
||||||
method.setAccessible(true);
|
method.setAccessible(true);
|
||||||
|
|
||||||
return method;
|
return method;
|
||||||
} catch (NullPointerException | NoSuchMethodException ex) {
|
} catch (NullPointerException | NoSuchMethodException ex) {
|
||||||
if (saneFallback != null && !saneFallback.equals(methodName)) {
|
if (this.saneFallback != null && !this.saneFallback.equals(methodName)) {
|
||||||
try {
|
try {
|
||||||
Method method = clazz.getMethod(saneFallback, parameters);
|
Method method = clazz.getMethod(this.saneFallback, this.parameters);
|
||||||
method.setAccessible(true);
|
method.setAccessible(true);
|
||||||
|
|
||||||
return method;
|
return method;
|
||||||
|
@ -5,7 +5,7 @@ import org.bukkit.Bukkit;
|
|||||||
|
|
||||||
public enum ServerProject {
|
public enum ServerProject {
|
||||||
UNKNOWN, CRAFTBUKKIT, SPIGOT, PAPER, TACO, GLOWSTONE, MOCK_BUKKIT;
|
UNKNOWN, CRAFTBUKKIT, SPIGOT, PAPER, TACO, GLOWSTONE, MOCK_BUKKIT;
|
||||||
private final static ServerProject serverProject = checkProject();
|
private static final ServerProject serverProject = checkProject();
|
||||||
|
|
||||||
private static ServerProject checkProject() {
|
private static ServerProject checkProject() {
|
||||||
String serverPath = Bukkit.getServer().getClass().getName();
|
String serverPath = Bukkit.getServer().getClass().getName();
|
||||||
|
@ -4,12 +4,12 @@ import org.apache.commons.lang3.ArrayUtils;
|
|||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
|
|
||||||
public enum ServerVersion {
|
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 static final String serverPackageVersion;
|
||||||
private final static String serverReleaseVersion;
|
private static final String serverReleaseVersion;
|
||||||
private final static ServerVersion serverVersion;
|
private static final ServerVersion serverVersion;
|
||||||
private final static boolean isMocked;
|
private static final boolean isMocked;
|
||||||
|
|
||||||
static {
|
static {
|
||||||
if (Bukkit.getServer() != null) {
|
if (Bukkit.getServer() != null) {
|
||||||
|
27
Core/pom.xml
27
Core/pom.xml
@ -35,7 +35,7 @@
|
|||||||
<injections>
|
<injections>
|
||||||
<injection>
|
<injection>
|
||||||
<value>${project.version}</value>
|
<value>${project.version}</value>
|
||||||
<pointCut>com.craftaro.core.SongodaCoreConstants.getCoreVersion</pointCut>
|
<pointCut>com.craftaro.core.CraftaroCoreConstants.getCoreVersion</pointCut>
|
||||||
</injection>
|
</injection>
|
||||||
</injections>
|
</injections>
|
||||||
</configuration>
|
</configuration>
|
||||||
@ -60,7 +60,7 @@
|
|||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-shade-plugin</artifactId>
|
<artifactId>maven-shade-plugin</artifactId>
|
||||||
<version>3.3.0</version>
|
<version>3.5.0</version>
|
||||||
|
|
||||||
<executions>
|
<executions>
|
||||||
<execution>
|
<execution>
|
||||||
@ -81,6 +81,7 @@
|
|||||||
<include>com.zaxxer:HikariCP</include>
|
<include>com.zaxxer:HikariCP</include>
|
||||||
<include>de.tr7zw:item-nbt-api</include>
|
<include>de.tr7zw:item-nbt-api</include>
|
||||||
<include>net.kyori:*</include>
|
<include>net.kyori:*</include>
|
||||||
|
<include>com.github.cryptomorin:XSeries</include>
|
||||||
<include>org.apache.commons:commons-lang3</include>
|
<include>org.apache.commons:commons-lang3</include>
|
||||||
<include>org.apache.commons:commons-text</include>
|
<include>org.apache.commons:commons-text</include>
|
||||||
<include>org.jooq:jooq</include>
|
<include>org.jooq:jooq</include>
|
||||||
@ -130,7 +131,26 @@
|
|||||||
<pattern>org.h2</pattern>
|
<pattern>org.h2</pattern>
|
||||||
<shadedPattern>com.craftaro.core.third_party.org.h2</shadedPattern>
|
<shadedPattern>com.craftaro.core.third_party.org.h2</shadedPattern>
|
||||||
</relocation>
|
</relocation>
|
||||||
|
|
||||||
|
<relocation>
|
||||||
|
<pattern>com.cryptomorin.xseries</pattern>
|
||||||
|
<shadedPattern>com.craftaro.core.third_party.com.cryptomorin.xseries</shadedPattern>
|
||||||
|
</relocation>
|
||||||
</relocations>
|
</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>
|
</configuration>
|
||||||
</execution>
|
</execution>
|
||||||
</executions>
|
</executions>
|
||||||
@ -151,6 +171,7 @@
|
|||||||
</dependencyManagement>
|
</dependencyManagement>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
<!--suppress VulnerableLibrariesLocal -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.spigotmc</groupId>
|
<groupId>org.spigotmc</groupId>
|
||||||
<artifactId>spigot</artifactId>
|
<artifactId>spigot</artifactId>
|
||||||
@ -176,7 +197,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>de.tr7zw</groupId>
|
<groupId>de.tr7zw</groupId>
|
||||||
<artifactId>item-nbt-api</artifactId>
|
<artifactId>item-nbt-api</artifactId>
|
||||||
<version>2.11.2</version>
|
<version>2.11.3</version>
|
||||||
<scope>compile</scope>
|
<scope>compile</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
@ -7,8 +7,8 @@ package com.craftaro.core;
|
|||||||
* <p>
|
* <p>
|
||||||
* <b>!! Manually changing the values in this class has to be considered a breaking change. !!</b>
|
* <b>!! Manually changing the values in this class has to be considered a breaking change. !!</b>
|
||||||
*/
|
*/
|
||||||
public class SongodaCoreConstants {
|
public class CraftaroCoreConstants {
|
||||||
private SongodaCoreConstants() {
|
private CraftaroCoreConstants() {
|
||||||
throw new IllegalStateException("Utility class");
|
throw new IllegalStateException("Utility class");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -17,10 +17,10 @@ public class SongodaCoreConstants {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static String getProjectName() {
|
public static String getProjectName() {
|
||||||
return "SongodaCore";
|
return "CraftaroCore";
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getGitHubProjectUrl() {
|
public static String getGitHubProjectUrl() {
|
||||||
return "https://github.com/craftaro/SongodaCore";
|
return "https://github.com/craftaro/CraftaroCore";
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,6 +1,7 @@
|
|||||||
package com.craftaro.core;
|
package com.craftaro.core;
|
||||||
|
|
||||||
import com.craftaro.core.commands.CommandManager;
|
import com.craftaro.core.commands.CommandManager;
|
||||||
|
import com.craftaro.core.compatibility.ClientVersion;
|
||||||
import com.craftaro.core.core.LocaleModule;
|
import com.craftaro.core.core.LocaleModule;
|
||||||
import com.craftaro.core.core.PluginInfo;
|
import com.craftaro.core.core.PluginInfo;
|
||||||
import com.craftaro.core.core.PluginInfoModule;
|
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.core.SongodaCoreUUIDCommand;
|
||||||
import com.craftaro.core.verification.CraftaroProductVerification;
|
import com.craftaro.core.verification.CraftaroProductVerification;
|
||||||
import com.craftaro.core.verification.ProductVerificationStatus;
|
import com.craftaro.core.verification.ProductVerificationStatus;
|
||||||
import com.craftaro.core.compatibility.ClientVersion;
|
import com.cryptomorin.xseries.XMaterial;
|
||||||
import com.craftaro.core.compatibility.CompatibleMaterial;
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
@ -46,7 +46,7 @@ import java.util.logging.Level;
|
|||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
public class SongodaCore {
|
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,
|
* Whenever we make a major change to the core GUI, updater,
|
||||||
@ -59,10 +59,10 @@ public class SongodaCore {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @since coreRevision 6
|
* @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
|
@Deprecated
|
||||||
private static final String coreVersion = SongodaCoreConstants.getCoreVersion();
|
private static final String coreVersion = CraftaroCoreConstants.getCoreVersion();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This is specific to the website api
|
* This is specific to the website api
|
||||||
@ -83,11 +83,11 @@ public class SongodaCore {
|
|||||||
|
|
||||||
public static boolean hasShading() {
|
public static boolean hasShading() {
|
||||||
// sneaky hack to check the package name since maven tries to re-shade all references to the package string
|
// 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) {
|
public static void registerPlugin(JavaPlugin plugin, int pluginID, XMaterial icon) {
|
||||||
registerPlugin(plugin, pluginID, icon == null ? "STONE" : icon.name(), SongodaCoreConstants.getCoreVersion());
|
registerPlugin(plugin, pluginID, icon == null ? "STONE" : icon.name(), CraftaroCoreConstants.getCoreVersion());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void registerPlugin(JavaPlugin plugin, int pluginID, String icon) {
|
public static void registerPlugin(JavaPlugin plugin, int pluginID, String icon) {
|
||||||
@ -182,31 +182,31 @@ public class SongodaCore {
|
|||||||
}
|
}
|
||||||
|
|
||||||
SongodaCore() {
|
SongodaCore() {
|
||||||
commandManager = null;
|
this.commandManager = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
SongodaCore(JavaPlugin javaPlugin) {
|
SongodaCore(JavaPlugin javaPlugin) {
|
||||||
piggybackedPlugin = javaPlugin;
|
this.piggybackedPlugin = javaPlugin;
|
||||||
commandManager = new CommandManager(piggybackedPlugin);
|
this.commandManager = new CommandManager(this.piggybackedPlugin);
|
||||||
loginListener = new EventListener();
|
this.loginListener = new EventListener();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void init() {
|
private void init() {
|
||||||
shadingListener = new ShadedEventListener();
|
this.shadingListener = new ShadedEventListener();
|
||||||
commandManager.registerCommandDynamically(new SongodaCoreCommand())
|
this.commandManager.registerCommandDynamically(new SongodaCoreCommand())
|
||||||
.addSubCommands(new SongodaCoreDiagCommand(), new SongodaCoreUUIDCommand(), new SongodaCoreLicenseCommand());
|
.addSubCommands(new SongodaCoreDiagCommand(), new SongodaCoreUUIDCommand(), new SongodaCoreLicenseCommand());
|
||||||
Bukkit.getPluginManager().registerEvents(loginListener, piggybackedPlugin);
|
Bukkit.getPluginManager().registerEvents(this.loginListener, this.piggybackedPlugin);
|
||||||
Bukkit.getPluginManager().registerEvents(shadingListener, piggybackedPlugin);
|
Bukkit.getPluginManager().registerEvents(this.shadingListener, this.piggybackedPlugin);
|
||||||
|
|
||||||
// we aggressively want to own this command
|
// we aggressively want to own this command
|
||||||
tasks.add(Bukkit.getScheduler().runTaskLaterAsynchronously(piggybackedPlugin, () ->
|
this.tasks.add(Bukkit.getScheduler().runTaskLaterAsynchronously(this.piggybackedPlugin, () ->
|
||||||
CommandManager.registerCommandDynamically(piggybackedPlugin, "songoda", commandManager, commandManager),
|
CommandManager.registerCommandDynamically(this.piggybackedPlugin, "songoda", this.commandManager, this.commandManager),
|
||||||
10 * 60));
|
10 * 60));
|
||||||
tasks.add(Bukkit.getScheduler().runTaskLaterAsynchronously(piggybackedPlugin, () ->
|
this.tasks.add(Bukkit.getScheduler().runTaskLaterAsynchronously(this.piggybackedPlugin, () ->
|
||||||
CommandManager.registerCommandDynamically(piggybackedPlugin, "songoda", commandManager, commandManager),
|
CommandManager.registerCommandDynamically(this.piggybackedPlugin, "songoda", this.commandManager, this.commandManager),
|
||||||
20 * 60));
|
20 * 60));
|
||||||
tasks.add(Bukkit.getScheduler().runTaskLaterAsynchronously(piggybackedPlugin, () ->
|
this.tasks.add(Bukkit.getScheduler().runTaskLaterAsynchronously(this.piggybackedPlugin, () ->
|
||||||
CommandManager.registerCommandDynamically(piggybackedPlugin, "songoda", commandManager, commandManager),
|
CommandManager.registerCommandDynamically(this.piggybackedPlugin, "songoda", this.commandManager, this.commandManager),
|
||||||
20 * 60 * 2));
|
20 * 60 * 2));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -216,17 +216,17 @@ public class SongodaCore {
|
|||||||
private void destroy() {
|
private void destroy() {
|
||||||
Bukkit.getServicesManager().unregister(SongodaCore.class, INSTANCE);
|
Bukkit.getServicesManager().unregister(SongodaCore.class, INSTANCE);
|
||||||
|
|
||||||
tasks.stream().filter(Objects::nonNull)
|
this.tasks.stream().filter(Objects::nonNull)
|
||||||
.forEach(task -> Bukkit.getScheduler().cancelTask(task.getTaskId()));
|
.forEach(task -> Bukkit.getScheduler().cancelTask(task.getTaskId()));
|
||||||
|
|
||||||
HandlerList.unregisterAll(loginListener);
|
HandlerList.unregisterAll(this.loginListener);
|
||||||
if (!hasShading()) {
|
if (!hasShading()) {
|
||||||
HandlerList.unregisterAll(shadingListener);
|
HandlerList.unregisterAll(this.shadingListener);
|
||||||
}
|
}
|
||||||
|
|
||||||
registeredPlugins.clear();
|
registeredPlugins.clear();
|
||||||
commandManager = null;
|
this.commandManager = null;
|
||||||
loginListener = null;
|
this.loginListener = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private ArrayList<BukkitTask> tasks = new ArrayList<>();
|
private ArrayList<BukkitTask> tasks = new ArrayList<>();
|
||||||
@ -247,7 +247,7 @@ public class SongodaCore {
|
|||||||
// don't forget to check for language pack updates ;)
|
// don't forget to check for language pack updates ;)
|
||||||
info.addModule(new LocaleModule());
|
info.addModule(new LocaleModule());
|
||||||
registeredPlugins.add(info);
|
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() {
|
public static String getVersion() {
|
||||||
return SongodaCoreConstants.getCoreVersion();
|
return CraftaroCoreConstants.getCoreVersion();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -316,7 +316,7 @@ public class SongodaCore {
|
|||||||
*/
|
*/
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public static String getCoreLibraryVersion() {
|
public static String getCoreLibraryVersion() {
|
||||||
return SongodaCoreConstants.getCoreVersion();
|
return CraftaroCoreConstants.getCoreVersion();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int getCoreMajorVersion() {
|
public static int getCoreMajorVersion() {
|
||||||
@ -337,7 +337,7 @@ public class SongodaCore {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static String getPrefix() {
|
public static String getPrefix() {
|
||||||
return "[" + SongodaCoreConstants.getProjectName() + "] ";
|
return "[" + CraftaroCoreConstants.getProjectName() + "] ";
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Logger getLogger() {
|
public static Logger getLogger() {
|
||||||
@ -361,34 +361,34 @@ public class SongodaCore {
|
|||||||
boolean proto = false;
|
boolean proto = false;
|
||||||
|
|
||||||
ShadedEventListener() {
|
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()));
|
Bukkit.getOnlinePlayers().forEach(p -> ClientVersion.onLoginVia(p, getHijackedPlugin()));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
proto = Bukkit.getPluginManager().isPluginEnabled("ProtocolSupport");
|
this.proto = Bukkit.getPluginManager().isPluginEnabled("ProtocolSupport");
|
||||||
if (proto) {
|
if (this.proto) {
|
||||||
Bukkit.getOnlinePlayers().forEach(p -> ClientVersion.onLoginProtocol(p, getHijackedPlugin()));
|
Bukkit.getOnlinePlayers().forEach(p -> ClientVersion.onLoginProtocol(p, getHijackedPlugin()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
void onLogin(PlayerLoginEvent event) {
|
void onLogin(PlayerLoginEvent event) {
|
||||||
if (via) {
|
if (this.via) {
|
||||||
ClientVersion.onLoginVia(event.getPlayer(), getHijackedPlugin());
|
ClientVersion.onLoginVia(event.getPlayer(), getHijackedPlugin());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (proto) {
|
if (this.proto) {
|
||||||
ClientVersion.onLoginProtocol(event.getPlayer(), getHijackedPlugin());
|
ClientVersion.onLoginProtocol(event.getPlayer(), getHijackedPlugin());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
void onLogout(PlayerQuitEvent event) {
|
void onLogout(PlayerQuitEvent event) {
|
||||||
if (via) {
|
if (this.via) {
|
||||||
ClientVersion.onLogout(event.getPlayer());
|
ClientVersion.onLogout(event.getPlayer());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -396,9 +396,9 @@ public class SongodaCore {
|
|||||||
@EventHandler
|
@EventHandler
|
||||||
void onEnable(PluginEnableEvent event) {
|
void onEnable(PluginEnableEvent event) {
|
||||||
// technically shouldn't have online players here, but idk
|
// 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()));
|
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()));
|
Bukkit.getOnlinePlayers().forEach(p -> ClientVersion.onLoginProtocol(p, getHijackedPlugin()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -413,13 +413,13 @@ public class SongodaCore {
|
|||||||
|
|
||||||
// don't spam players with update checks
|
// don't spam players with update checks
|
||||||
long now = System.currentTimeMillis();
|
long now = System.currentTimeMillis();
|
||||||
Long last = lastCheck.get(player.getUniqueId());
|
Long last = this.lastCheck.get(player.getUniqueId());
|
||||||
|
|
||||||
if (last != null && now - 10000 < last) {
|
if (last != null && now - 10000 < last) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
lastCheck.put(player.getUniqueId(), now);
|
this.lastCheck.put(player.getUniqueId(), now);
|
||||||
|
|
||||||
// is this player good to revieve update notices?
|
// is this player good to revieve update notices?
|
||||||
if (!event.getPlayer().isOp() && !player.hasPermission("songoda.updatecheck")) return;
|
if (!event.getPlayer().isOp() && !player.hasPermission("songoda.updatecheck")) return;
|
||||||
@ -441,19 +441,19 @@ public class SongodaCore {
|
|||||||
registeredPlugins.remove(pi);
|
registeredPlugins.remove(pi);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (event.getPlugin() == piggybackedPlugin) {
|
if (event.getPlugin() == SongodaCore.this.piggybackedPlugin) {
|
||||||
// uh-oh! Abandon ship!!
|
// uh-oh! Abandon ship!!
|
||||||
Bukkit.getServicesManager().unregisterAll(piggybackedPlugin);
|
Bukkit.getServicesManager().unregisterAll(SongodaCore.this.piggybackedPlugin);
|
||||||
|
|
||||||
// can we move somewhere else?
|
// can we move somewhere else?
|
||||||
if ((pi = registeredPlugins.stream().findFirst().orElse(null)) != null) {
|
if ((pi = registeredPlugins.stream().findFirst().orElse(null)) != null) {
|
||||||
// move ourselves to this plugin
|
// move ourselves to this plugin
|
||||||
piggybackedPlugin = pi.getJavaPlugin();
|
SongodaCore.this.piggybackedPlugin = pi.getJavaPlugin();
|
||||||
|
|
||||||
Bukkit.getServicesManager().register(SongodaCore.class, INSTANCE, piggybackedPlugin, ServicePriority.Normal);
|
Bukkit.getServicesManager().register(SongodaCore.class, INSTANCE, SongodaCore.this.piggybackedPlugin, ServicePriority.Normal);
|
||||||
Bukkit.getPluginManager().registerEvents(loginListener, piggybackedPlugin);
|
Bukkit.getPluginManager().registerEvents(SongodaCore.this.loginListener, SongodaCore.this.piggybackedPlugin);
|
||||||
Bukkit.getPluginManager().registerEvents(shadingListener, piggybackedPlugin);
|
Bukkit.getPluginManager().registerEvents(SongodaCore.this.shadingListener, SongodaCore.this.piggybackedPlugin);
|
||||||
CommandManager.registerCommandDynamically(piggybackedPlugin, "songoda", commandManager, commandManager);
|
CommandManager.registerCommandDynamically(SongodaCore.this.piggybackedPlugin, "songoda", SongodaCore.this.commandManager, SongodaCore.this.commandManager);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
package com.craftaro.core;
|
package com.craftaro.core;
|
||||||
|
|
||||||
import com.craftaro.core.compatibility.CompatibleMaterial;
|
|
||||||
import com.craftaro.core.configuration.Config;
|
import com.craftaro.core.configuration.Config;
|
||||||
import com.craftaro.core.database.DataManager;
|
import com.craftaro.core.database.DataManager;
|
||||||
import com.craftaro.core.database.DataMigration;
|
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.utils.Metrics;
|
||||||
import com.craftaro.core.verification.CraftaroProductVerification;
|
import com.craftaro.core.verification.CraftaroProductVerification;
|
||||||
import com.craftaro.core.verification.ProductVerificationStatus;
|
import com.craftaro.core.verification.ProductVerificationStatus;
|
||||||
|
import com.cryptomorin.xseries.XMaterial;
|
||||||
import de.tr7zw.changeme.nbtapi.utils.MinecraftVersion;
|
import de.tr7zw.changeme.nbtapi.utils.MinecraftVersion;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
@ -20,6 +20,7 @@ import java.io.File;
|
|||||||
import java.sql.Connection;
|
import java.sql.Connection;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
|
|
||||||
public abstract class SongodaPlugin extends JavaPlugin {
|
public abstract class SongodaPlugin extends JavaPlugin {
|
||||||
@ -35,7 +36,6 @@ public abstract class SongodaPlugin extends JavaPlugin {
|
|||||||
static {
|
static {
|
||||||
/* NBT-API */
|
/* NBT-API */
|
||||||
MinecraftVersion.getLogger().setLevel(Level.WARNING);
|
MinecraftVersion.getLogger().setLevel(Level.WARNING);
|
||||||
MinecraftVersion.disableUpdateCheck();
|
|
||||||
// Disable tips and logo for Jooq
|
// Disable tips and logo for Jooq
|
||||||
System.setProperty("org.jooq.no-tips", "true");
|
System.setProperty("org.jooq.no-tips", "true");
|
||||||
System.setProperty("org.jooq.no-logo", "true");
|
System.setProperty("org.jooq.no-logo", "true");
|
||||||
@ -63,22 +63,22 @@ public abstract class SongodaPlugin extends JavaPlugin {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public FileConfiguration getConfig() {
|
public FileConfiguration getConfig() {
|
||||||
return config.getFileConfig();
|
return this.config.getFileConfig();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Config getCoreConfig() {
|
public Config getCoreConfig() {
|
||||||
return config;
|
return this.config;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void reloadConfig() {
|
public void reloadConfig() {
|
||||||
config.load();
|
this.config.load();
|
||||||
onConfigReload();
|
onConfigReload();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void saveConfig() {
|
public void saveConfig() {
|
||||||
config.save();
|
this.config.save();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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.YELLOW + "Run the command " + ChatColor.GOLD + "/craftaro license" + ChatColor.YELLOW + " and follow the instructions\n" +
|
||||||
ChatColor.RED + "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
|
ChatColor.RED + "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
|
||||||
this.licensePreventedPluginLoad = true;
|
this.licensePreventedPluginLoad = true;
|
||||||
SongodaCore.registerPlugin(this, CraftaroProductVerification.getProductId(), (CompatibleMaterial) null);
|
SongodaCore.registerPlugin(this, CraftaroProductVerification.getProductId(), (XMaterial) null);
|
||||||
|
|
||||||
getServer().getScheduler().scheduleSyncRepeatingTask(this, () -> {
|
getServer().getScheduler().scheduleSyncRepeatingTask(this, () -> {
|
||||||
String pluginName = getDescription().getName();
|
String pluginName = getDescription().getName();
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
package com.craftaro.core.chat;
|
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.nms.Nms;
|
||||||
import com.craftaro.core.utils.TextUtils;
|
import com.craftaro.core.utils.TextUtils;
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
import com.google.gson.GsonBuilder;
|
import com.google.gson.GsonBuilder;
|
||||||
import com.google.gson.JsonObject;
|
import com.google.gson.JsonObject;
|
||||||
import com.craftaro.core.compatibility.ClassMapping;
|
|
||||||
import com.craftaro.core.compatibility.ServerVersion;
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
package com.craftaro.core.chat;
|
package com.craftaro.core.chat;
|
||||||
|
|
||||||
import com.craftaro.core.utils.ColorUtils;
|
|
||||||
import com.craftaro.core.compatibility.ServerVersion;
|
import com.craftaro.core.compatibility.ServerVersion;
|
||||||
|
import com.craftaro.core.utils.ColorUtils;
|
||||||
|
|
||||||
import java.awt.*;
|
import java.awt.Color;
|
||||||
|
|
||||||
public class ColorContainer {
|
public class ColorContainer {
|
||||||
private ColorCode colorCode;
|
private ColorCode colorCode;
|
||||||
@ -24,26 +24,26 @@ public class ColorContainer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public ColorCode getColorCode() {
|
public ColorCode getColorCode() {
|
||||||
return colorCode;
|
return this.colorCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getHexCode() {
|
public String getHexCode() {
|
||||||
return hexCode;
|
return this.hexCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ColorCode getColor() {
|
public ColorCode getColor() {
|
||||||
if (colorCode != null) {
|
if (this.colorCode != null) {
|
||||||
return colorCode;
|
return this.colorCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (hexCode == null) {
|
if (this.hexCode == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
java.awt.Color jColor = new Color(
|
java.awt.Color jColor = new Color(
|
||||||
Integer.valueOf(hexCode.substring(0, 2), 16),
|
Integer.valueOf(this.hexCode.substring(0, 2), 16),
|
||||||
Integer.valueOf(hexCode.substring(2, 4), 16),
|
Integer.valueOf(this.hexCode.substring(2, 4), 16),
|
||||||
Integer.valueOf(hexCode.substring(4, 6), 16));
|
Integer.valueOf(this.hexCode.substring(4, 6), 16));
|
||||||
|
|
||||||
return ColorUtils.fromRGB(jColor.getRed(), jColor.getGreen(), jColor.getBlue());
|
return ColorUtils.fromRGB(jColor.getRed(), jColor.getGreen(), jColor.getBlue());
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
package com.craftaro.core.configuration;
|
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.Configuration;
|
||||||
import org.bukkit.configuration.ConfigurationSection;
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
import org.bukkit.configuration.InvalidConfigurationException;
|
import org.bukkit.configuration.InvalidConfigurationException;
|
||||||
@ -256,12 +256,12 @@ public class ConfigFileConfigurationAdapter extends FileConfiguration {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public CompatibleMaterial getMaterial(@NotNull String path) {
|
public XMaterial getMaterial(@NotNull String path) {
|
||||||
return config.getMaterial(path);
|
return config.getMaterial(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public CompatibleMaterial getMaterial(@NotNull String path, @Nullable CompatibleMaterial def) {
|
public XMaterial getMaterial(@NotNull String path, @Nullable XMaterial def) {
|
||||||
return config.getMaterial(path, def);
|
return config.getMaterial(path, def);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package com.craftaro.core.configuration;
|
package com.craftaro.core.configuration;
|
||||||
|
|
||||||
import com.craftaro.core.compatibility.CompatibleMaterial;
|
import com.craftaro.core.compatibility.CompatibleMaterial;
|
||||||
|
import com.cryptomorin.xseries.XMaterial;
|
||||||
import org.bukkit.configuration.Configuration;
|
import org.bukkit.configuration.Configuration;
|
||||||
import org.bukkit.configuration.MemoryConfiguration;
|
import org.bukkit.configuration.MemoryConfiguration;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
@ -714,18 +715,17 @@ public class ConfigSection extends MemoryConfiguration {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public CompatibleMaterial getMaterial(@NotNull String path) {
|
public XMaterial getMaterial(@NotNull String path) {
|
||||||
String val = getString(path);
|
String val = getString(path);
|
||||||
|
|
||||||
return val != null ? CompatibleMaterial.getMaterial(val) : null;
|
return val != null ? CompatibleMaterial.getMaterial(val).orElse(null) : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public CompatibleMaterial getMaterial(@NotNull String path, @Nullable CompatibleMaterial def) {
|
public XMaterial getMaterial(@NotNull String path, @Nullable XMaterial def) {
|
||||||
String val = getString(path);
|
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;
|
return mat != null ? mat : def;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,10 +2,12 @@ package com.craftaro.core.configuration;
|
|||||||
|
|
||||||
import com.craftaro.core.SongodaCore;
|
import com.craftaro.core.SongodaCore;
|
||||||
import com.craftaro.core.compatibility.CompatibleMaterial;
|
import com.craftaro.core.compatibility.CompatibleMaterial;
|
||||||
|
import com.cryptomorin.xseries.XMaterial;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
|
|
||||||
public class ConfigSetting {
|
public class ConfigSetting {
|
||||||
@ -109,27 +111,25 @@ public class ConfigSetting {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public CompatibleMaterial getMaterial() {
|
public XMaterial getMaterial() {
|
||||||
String val = config.getString(key);
|
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));
|
SongodaCore.getLogger().log(Level.WARNING, String.format("Config value \"%s\" has an invalid material name: \"%s\"", key, val));
|
||||||
}
|
}
|
||||||
|
return mat.orElse(XMaterial.STONE);
|
||||||
return mat != null ? mat : CompatibleMaterial.STONE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public CompatibleMaterial getMaterial(@NotNull CompatibleMaterial def) {
|
public XMaterial getMaterial(@NotNull XMaterial def) {
|
||||||
//return config.getMaterial(key, def);
|
//return config.getMaterial(key, def);
|
||||||
String val = config.getString(key);
|
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));
|
SongodaCore.getLogger().log(Level.WARNING, String.format("Config value \"%s\" has an invalid material name: \"%s\"", key, val));
|
||||||
}
|
}
|
||||||
|
return mat.orElse(def);
|
||||||
return mat != null ? mat : def;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,6 +7,7 @@ import com.craftaro.core.gui.GuiUtils;
|
|||||||
import com.craftaro.core.gui.SimplePagedGui;
|
import com.craftaro.core.gui.SimplePagedGui;
|
||||||
import com.craftaro.core.input.ChatPrompt;
|
import com.craftaro.core.input.ChatPrompt;
|
||||||
import com.craftaro.core.utils.ItemUtils;
|
import com.craftaro.core.utils.ItemUtils;
|
||||||
|
import com.cryptomorin.xseries.XMaterial;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.configuration.ConfigurationSection;
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
import org.bukkit.configuration.MemoryConfiguration;
|
import org.bukkit.configuration.MemoryConfiguration;
|
||||||
@ -22,7 +23,9 @@ import java.io.IOException;
|
|||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -51,7 +54,7 @@ public class ConfigEditorGui extends SimplePagedGui {
|
|||||||
this.file = file;
|
this.file = file;
|
||||||
this.config = config;
|
this.config = config;
|
||||||
this.node = node;
|
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)) {
|
if (!(parent instanceof ConfigEditorGui)) {
|
||||||
setOnClose((gui) -> save());
|
setOnClose((gui) -> save());
|
||||||
@ -68,10 +71,10 @@ public class ConfigEditorGui extends SimplePagedGui {
|
|||||||
// decorate header
|
// decorate header
|
||||||
this.setTitle(ChatColor.DARK_BLUE + file);
|
this.setTitle(ChatColor.DARK_BLUE + file);
|
||||||
this.setUseHeader(true);
|
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();
|
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.setItem(4, configItem(XMaterial.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.setButton(8, GuiUtils.createButtonItem(XMaterial.OAK_DOOR, "Exit"), (event) -> event.player.closeInventory());
|
||||||
|
|
||||||
// compile list of settings
|
// compile list of settings
|
||||||
for (String key : node.getKeys(false)) {
|
for (String key : node.getKeys(false)) {
|
||||||
@ -86,7 +89,7 @@ public class ConfigEditorGui extends SimplePagedGui {
|
|||||||
// next we need to display the config settings
|
// next we need to display the config settings
|
||||||
int index = 9;
|
int index = 9;
|
||||||
for (final String sectionKey : sections) {
|
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))));
|
(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) {
|
if (val instanceof Boolean) {
|
||||||
// toggle switch
|
// 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));
|
(event) -> this.toggle(event.slot, settingKey));
|
||||||
|
|
||||||
if ((Boolean) val) {
|
if ((Boolean) val) {
|
||||||
@ -107,7 +110,7 @@ public class ConfigEditorGui extends SimplePagedGui {
|
|||||||
}
|
}
|
||||||
} else if (isNumber(val)) {
|
} else if (isNumber(val)) {
|
||||||
// number dial
|
// 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) -> {
|
||||||
event.gui.exit();
|
event.gui.exit();
|
||||||
ChatPrompt.showPrompt(plugin, event.player, "Enter a new number value for " + settingKey + ":", response -> {
|
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)) {
|
} else if (isMaterial(val)) {
|
||||||
// changing a block
|
// changing a block
|
||||||
// isMaterial is more of a guess, to be honest.
|
// 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) -> {
|
(event) -> {
|
||||||
SimplePagedGui paged = new SimplePagedGui(this);
|
SimplePagedGui paged = new SimplePagedGui(this);
|
||||||
paged.setTitle(ChatColor.BLUE + settingKey);
|
paged.setTitle(ChatColor.BLUE + settingKey);
|
||||||
paged.setHeaderBackItem(headerBackItem).setFooterBackItem(footerBackItem).setDefaultItem(blankItem);
|
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;
|
int i = 9;
|
||||||
for (CompatibleMaterial mat : CompatibleMaterial.getAllValidItemMaterials()) {
|
for (XMaterial mat : getAllValidMaterials()) {
|
||||||
try {
|
try {
|
||||||
ItemStack buttonItem = GuiUtils.createButtonItem(mat, mat.name());
|
ItemStack buttonItem = GuiUtils.createButtonItem(mat, mat.name());
|
||||||
if (!buttonItem.getType().isItem()) continue;
|
if (!buttonItem.getType().isItem()) continue;
|
||||||
@ -147,7 +150,7 @@ public class ConfigEditorGui extends SimplePagedGui {
|
|||||||
});
|
});
|
||||||
} else if (val instanceof String) {
|
} else if (val instanceof String) {
|
||||||
// changing a "string" value (or change to a feather for writing quill)
|
// 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) -> {
|
||||||
event.gui.exit();
|
event.gui.exit();
|
||||||
ChatPrompt.showPrompt(plugin, event.player, "Enter a new value for " + settingKey + ":", response -> {
|
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) {
|
} 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) ->
|
||||||
event.manager.showGUI(event.player, (new ConfigEditorListEditorGui(this, settingKey, (List) val)).setOnClose((gui) -> {
|
event.manager.showGUI(event.player, (new ConfigEditorListEditorGui(this, settingKey, (List) val)).setOnClose((gui) -> {
|
||||||
if (((ConfigEditorListEditorGui) gui.gui).saveChanges) {
|
if (((ConfigEditorListEditorGui) gui.gui).saveChanges) {
|
||||||
@ -244,12 +247,12 @@ public class ConfigEditorGui extends SimplePagedGui {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void setMaterial(int clickCell, String path, ItemStack item) {
|
void setMaterial(int clickCell, String path, ItemStack item) {
|
||||||
CompatibleMaterial mat = CompatibleMaterial.getMaterial(item);
|
Optional<XMaterial> mat = CompatibleMaterial.getMaterial(item.getType());
|
||||||
|
|
||||||
if (mat == null) {
|
if (!mat.isPresent()) {
|
||||||
node.set(path, CompatibleMaterial.STONE.name());
|
node.set(path, XMaterial.STONE.name());
|
||||||
} else {
|
} else {
|
||||||
node.set(path, mat.name());
|
node.set(path, mat.get().name());
|
||||||
}
|
}
|
||||||
|
|
||||||
updateValue(clickCell, path);
|
updateValue(clickCell, path);
|
||||||
@ -293,13 +296,15 @@ public class ConfigEditorGui extends SimplePagedGui {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private boolean isMaterial(Object value) {
|
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())
|
Optional<XMaterial> material = CompatibleMaterial.getMaterial(value.toString());
|
||||||
&& (m = CompatibleMaterial.getMaterial(value.toString())) != null && m.isValidItem();
|
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;
|
String[] info = null;
|
||||||
|
|
||||||
if (configSection_getCommentString != 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));
|
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) {
|
if (value == null) {
|
||||||
value = "";
|
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));
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
package com.craftaro.core.configuration.editor;
|
package com.craftaro.core.configuration.editor;
|
||||||
|
|
||||||
import com.craftaro.core.compatibility.CompatibleMaterial;
|
|
||||||
import com.craftaro.core.gui.GuiUtils;
|
import com.craftaro.core.gui.GuiUtils;
|
||||||
import com.craftaro.core.gui.SimplePagedGui;
|
import com.craftaro.core.gui.SimplePagedGui;
|
||||||
import com.craftaro.core.input.ChatPrompt;
|
import com.craftaro.core.input.ChatPrompt;
|
||||||
|
import com.cryptomorin.xseries.XMaterial;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.event.inventory.ClickType;
|
import org.bukkit.event.inventory.ClickType;
|
||||||
|
|
||||||
@ -27,16 +27,16 @@ public class ConfigEditorListEditorGui extends SimplePagedGui {
|
|||||||
headerBackItem = footerBackItem = current.getHeaderBackItem();
|
headerBackItem = footerBackItem = current.getHeaderBackItem();
|
||||||
setTitle(ChatColor.DARK_BLUE + "String List Editor");
|
setTitle(ChatColor.DARK_BLUE + "String List Editor");
|
||||||
this.setUseHeader(true);
|
this.setUseHeader(true);
|
||||||
this.setItem(4, current.configItem(CompatibleMaterial.FILLED_MAP, key, current.getCurrentNode(), key, null));
|
this.setItem(4, current.configItem(XMaterial.FILLED_MAP, key, current.getCurrentNode(), key, null));
|
||||||
this.setButton(8, GuiUtils.createButtonItem(CompatibleMaterial.OAK_DOOR, "Exit"), (event) -> event.player.closeInventory());
|
this.setButton(8, GuiUtils.createButtonItem(XMaterial.OAK_DOOR, "Exit"), (event) -> event.player.closeInventory());
|
||||||
this.values = new ArrayList<>(val);
|
this.values = new ArrayList<>(val);
|
||||||
|
|
||||||
this.setButton(8, GuiUtils.createButtonItem(CompatibleMaterial.LAVA_BUCKET, ChatColor.RED + "Discard Changes"), (event) -> event.player.closeInventory());
|
this.setButton(8, GuiUtils.createButtonItem(XMaterial.LAVA_BUCKET, ChatColor.RED + "Discard Changes"), (event) -> event.player.closeInventory());
|
||||||
this.setButton(0, GuiUtils.createButtonItem(CompatibleMaterial.REDSTONE, ChatColor.GREEN + "Save"), (event) -> {
|
this.setButton(0, GuiUtils.createButtonItem(XMaterial.REDSTONE, ChatColor.GREEN + "Save"), (event) -> {
|
||||||
saveChanges = true;
|
saveChanges = true;
|
||||||
event.player.closeInventory();
|
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) -> {
|
||||||
event.gui.exit();
|
event.gui.exit();
|
||||||
ChatPrompt.showPrompt(event.manager.getPlugin(), event.player, "Enter a new value to add:", response -> {
|
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;
|
int i = 9;
|
||||||
for (String item : values) {
|
for (String item : values) {
|
||||||
final int index = i - 9;
|
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);
|
values.remove(index);
|
||||||
redraw();
|
redraw();
|
||||||
});
|
});
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
package com.craftaro.core.configuration.editor;
|
package com.craftaro.core.configuration.editor;
|
||||||
|
|
||||||
import com.craftaro.core.SongodaPlugin;
|
import com.craftaro.core.SongodaPlugin;
|
||||||
import com.craftaro.core.compatibility.CompatibleMaterial;
|
|
||||||
import com.craftaro.core.configuration.Config;
|
import com.craftaro.core.configuration.Config;
|
||||||
import com.craftaro.core.gui.Gui;
|
import com.craftaro.core.gui.Gui;
|
||||||
import com.craftaro.core.gui.GuiUtils;
|
import com.craftaro.core.gui.GuiUtils;
|
||||||
import com.craftaro.core.gui.SimplePagedGui;
|
import com.craftaro.core.gui.SimplePagedGui;
|
||||||
|
import com.cryptomorin.xseries.XMaterial;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.configuration.MemoryConfiguration;
|
import org.bukkit.configuration.MemoryConfiguration;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
@ -79,18 +79,18 @@ public class PluginConfigGui extends SimplePagedGui {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void init() {
|
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
|
// decorate header
|
||||||
this.setTitle(ChatColor.DARK_BLUE + plugin.getName() + " Plugin Config");
|
this.setTitle(ChatColor.DARK_BLUE + plugin.getName() + " Plugin Config");
|
||||||
this.setUseHeader(true);
|
this.setUseHeader(true);
|
||||||
headerBackItem = footerBackItem = GuiUtils.getBorderItem(CompatibleMaterial.GRAY_STAINED_GLASS_PANE.getItem());
|
headerBackItem = footerBackItem = GuiUtils.getBorderItem(XMaterial.GRAY_STAINED_GLASS_PANE.parseItem());
|
||||||
this.setButton(8, GuiUtils.createButtonItem(CompatibleMaterial.OAK_DOOR, "Exit"), (event) -> event.player.closeInventory());
|
this.setButton(8, GuiUtils.createButtonItem(XMaterial.OAK_DOOR, "Exit"), (event) -> event.player.closeInventory());
|
||||||
|
|
||||||
// List out all config files that this plugin has
|
// List out all config files that this plugin has
|
||||||
int i = 9;
|
int i = 9;
|
||||||
for (Map.Entry<String, MemoryConfiguration> config : configs.entrySet()) {
|
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())));
|
(event) -> event.manager.showGUI(event.player, new ConfigEditorGui(event.player, plugin, this, config.getKey(), config.getValue())));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,8 @@
|
|||||||
package com.craftaro.core.core;
|
package com.craftaro.core.core;
|
||||||
|
|
||||||
import com.craftaro.core.verification.ProductVerificationStatus;
|
|
||||||
import com.craftaro.core.compatibility.CompatibleMaterial;
|
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.bukkit.plugin.java.JavaPlugin;
|
||||||
import org.json.simple.JSONObject;
|
import org.json.simple.JSONObject;
|
||||||
|
|
||||||
@ -13,7 +14,7 @@ public final class PluginInfo {
|
|||||||
protected final JavaPlugin javaPlugin;
|
protected final JavaPlugin javaPlugin;
|
||||||
protected final int songodaId;
|
protected final int songodaId;
|
||||||
protected final String coreIcon;
|
protected final String coreIcon;
|
||||||
protected final CompatibleMaterial icon;
|
protected final XMaterial icon;
|
||||||
protected final String coreLibraryVersion;
|
protected final String coreLibraryVersion;
|
||||||
public final ProductVerificationStatus verificationStatus;
|
public final ProductVerificationStatus verificationStatus;
|
||||||
|
|
||||||
@ -29,7 +30,7 @@ public final class PluginInfo {
|
|||||||
this.javaPlugin = javaPlugin;
|
this.javaPlugin = javaPlugin;
|
||||||
this.songodaId = songodaId;
|
this.songodaId = songodaId;
|
||||||
this.coreIcon = icon;
|
this.coreIcon = icon;
|
||||||
this.icon = CompatibleMaterial.getMaterial(icon);
|
this.icon = CompatibleMaterial.getMaterial(icon).orElse(XMaterial.STONE);
|
||||||
this.coreLibraryVersion = coreLibraryVersion;
|
this.coreLibraryVersion = coreLibraryVersion;
|
||||||
this.verificationStatus = verificationStatus;
|
this.verificationStatus = verificationStatus;
|
||||||
}
|
}
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
package com.craftaro.core.core;
|
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.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.Gui;
|
||||||
|
import com.craftaro.core.gui.GuiUtils;
|
||||||
|
import com.cryptomorin.xseries.XMaterial;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.event.inventory.ClickType;
|
import org.bukkit.event.inventory.ClickType;
|
||||||
|
|
||||||
@ -24,7 +24,7 @@ final class SongodaCoreOverviewGUI extends Gui {
|
|||||||
final PluginInfo plugin = plugins.get(i);
|
final PluginInfo plugin = plugins.get(i);
|
||||||
|
|
||||||
if (plugin.hasUpdate()) {
|
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.GOLD + plugin.getJavaPlugin().getName(),
|
||||||
ChatColor.GRAY + "Latest Version: " + plugin.getLatestVersion(),
|
ChatColor.GRAY + "Latest Version: " + plugin.getLatestVersion(),
|
||||||
ChatColor.GRAY + "Installed Version: " + plugin.getJavaPlugin().getDescription().getVersion(),
|
ChatColor.GRAY + "Installed Version: " + plugin.getJavaPlugin().getDescription().getVersion(),
|
||||||
@ -42,7 +42,7 @@ final class SongodaCoreOverviewGUI extends Gui {
|
|||||||
continue;
|
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.GOLD + plugin.getJavaPlugin().getName(),
|
||||||
ChatColor.GRAY + "Installed Version: " + plugin.getJavaPlugin().getDescription().getVersion(),
|
ChatColor.GRAY + "Installed Version: " + plugin.getJavaPlugin().getDescription().getVersion(),
|
||||||
"",
|
"",
|
||||||
|
@ -2,9 +2,9 @@ package com.craftaro.core.gui;
|
|||||||
|
|
||||||
import com.craftaro.core.gui.methods.Clickable;
|
import com.craftaro.core.gui.methods.Clickable;
|
||||||
import com.craftaro.core.nms.Nms;
|
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.AnvilCore;
|
||||||
import com.craftaro.core.nms.anvil.CustomAnvil;
|
import com.craftaro.core.nms.anvil.CustomAnvil;
|
||||||
|
import com.cryptomorin.xseries.XMaterial;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.inventory.ClickType;
|
import org.bukkit.event.inventory.ClickType;
|
||||||
import org.bukkit.inventory.Inventory;
|
import org.bukkit.inventory.Inventory;
|
||||||
@ -108,7 +108,7 @@ public class AnvilGui extends Gui {
|
|||||||
|
|
||||||
inventory.setItem(1, item);
|
inventory.setItem(1, item);
|
||||||
} else if (!acceptsItems) {
|
} else if (!acceptsItems) {
|
||||||
item = GuiUtils.createButtonItem(CompatibleMaterial.PAPER, " ", " ");
|
item = GuiUtils.createButtonItem(XMaterial.PAPER, " ", " ");
|
||||||
|
|
||||||
cellItems.put(0, item);
|
cellItems.put(0, item);
|
||||||
inventory.setItem(0, item);
|
inventory.setItem(0, item);
|
||||||
|
@ -1,11 +1,12 @@
|
|||||||
package com.craftaro.core.gui;
|
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.Config;
|
||||||
import com.craftaro.core.configuration.ConfigSection;
|
import com.craftaro.core.configuration.ConfigSection;
|
||||||
import com.craftaro.core.gui.methods.Clickable;
|
import com.craftaro.core.gui.methods.Clickable;
|
||||||
import com.craftaro.core.utils.TextUtils;
|
import com.craftaro.core.utils.TextUtils;
|
||||||
import com.craftaro.core.compatibility.CompatibleMaterial;
|
import com.cryptomorin.xseries.XMaterial;
|
||||||
import com.craftaro.core.compatibility.ServerVersion;
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.event.inventory.ClickType;
|
import org.bukkit.event.inventory.ClickType;
|
||||||
import org.bukkit.inventory.Inventory;
|
import org.bukkit.inventory.Inventory;
|
||||||
@ -49,7 +50,7 @@ public class CustomizableGui extends Gui {
|
|||||||
config.load();
|
config.load();
|
||||||
|
|
||||||
if (!config.isConfigurationSection("overrides")) {
|
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",
|
"This is the icon material you would like to replace",
|
||||||
"the current material with.")
|
"the current material with.")
|
||||||
.setDefault("overrides.example.position", 5,
|
.setDefault("overrides.example.position", 5,
|
||||||
@ -92,19 +93,19 @@ public class CustomizableGui extends Gui {
|
|||||||
section.getInt("col", -1),
|
section.getInt("col", -1),
|
||||||
section.getBoolean("mirrorrow", false),
|
section.getBoolean("mirrorrow", false),
|
||||||
section.getBoolean("mirrorcol", 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 {
|
} else {
|
||||||
customContent.addButton(section.getNodeKey(), section.getInt("row", -1),
|
customContent.addButton(section.getNodeKey(), section.getInt("row", -1),
|
||||||
section.getInt("col", -1),
|
section.getInt("col", -1),
|
||||||
section.getString("title", null),
|
section.getString("title", null),
|
||||||
section.isSet("lore") ? section.getStringList("lore") : 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 {
|
} else {
|
||||||
customContent.addButton(section.getNodeKey(), section.getString("position", "-1"),
|
customContent.addButton(section.getNodeKey(), section.getString("position", "-1"),
|
||||||
section.getString("title", null),
|
section.getString("title", null),
|
||||||
section.isSet("lore") ? section.getStringList("lore") : 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);
|
customContent.disableButton(disabled);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
customContent = loadedGuis.get(guiKey);
|
this.customContent = loadedGuis.get(guiKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
setPrivateDefaultAction(event -> {
|
setPrivateDefaultAction(event -> {
|
||||||
if (event.clickType == ClickType.SHIFT_RIGHT) {
|
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;
|
showGuiKeys = !showGuiKeys;
|
||||||
activationCount = 0;
|
this.activationCount = 0;
|
||||||
|
|
||||||
event.player.sendMessage("Gui keys " + (showGuiKeys ? "enabled" : "disabled") + ".");
|
event.player.sendMessage("Gui keys " + (showGuiKeys ? "enabled" : "disabled") + ".");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
if (customContent.isButtonCustomized("__DEFAULT__")) {
|
if (this.customContent.isButtonCustomized("__DEFAULT__")) {
|
||||||
blankItem = GuiUtils.getBorderItem(customContent.getCustomizedButton("__DEFAULT__").item);
|
this.blankItem = GuiUtils.getBorderItem(this.customContent.getCustomizedButton("__DEFAULT__").item);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public Gui setRows(int rows) {
|
public Gui setRows(int rows) {
|
||||||
int customRows = customContent.getRows();
|
int customRows = this.customContent.getRows();
|
||||||
|
|
||||||
return super.setRows(customRows != -1 ? customRows : rows);
|
return super.setRows(customRows != -1 ? customRows : rows);
|
||||||
}
|
}
|
||||||
@ -153,13 +154,13 @@ public class CustomizableGui extends Gui {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void applyCustomItems() {
|
private void applyCustomItems() {
|
||||||
for (CustomButton customButton : customContent.getCustomButtons().values()) {
|
for (CustomButton customButton : this.customContent.getCustomButtons().values()) {
|
||||||
if (customButton instanceof MirrorFill) {
|
if (customButton instanceof MirrorFill) {
|
||||||
applyCustomItem(customButton);
|
applyCustomItem(customButton);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (CustomButton customButton : customContent.getCustomButtons().values()) {
|
for (CustomButton customButton : this.customContent.getCustomButtons().values()) {
|
||||||
if (!(customButton instanceof MirrorFill)) {
|
if (!(customButton instanceof MirrorFill)) {
|
||||||
applyCustomItem(customButton);
|
applyCustomItem(customButton);
|
||||||
}
|
}
|
||||||
@ -190,7 +191,7 @@ public class CustomizableGui extends Gui {
|
|||||||
|
|
||||||
applyShowGuiKeys("__DEFAULT__", item);
|
applyShowGuiKeys("__DEFAULT__", item);
|
||||||
|
|
||||||
if (customContent.isButtonCustomized("__DEFAULT__")) {
|
if (this.customContent.isButtonCustomized("__DEFAULT__")) {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -201,14 +202,14 @@ public class CustomizableGui extends Gui {
|
|||||||
public Gui setItem(@NotNull String key, int cell, @Nullable ItemStack item) {
|
public Gui setItem(@NotNull String key, int cell, @Nullable ItemStack item) {
|
||||||
List<Integer> cells = Collections.singletonList(cell);
|
List<Integer> cells = Collections.singletonList(cell);
|
||||||
|
|
||||||
if (customContent.isButtonDisabled(key)) {
|
if (this.customContent.isButtonDisabled(key)) {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
applyShowGuiKeys(key, item);
|
applyShowGuiKeys(key, item);
|
||||||
|
|
||||||
if (customContent.isButtonCustomized(key)) {
|
if (this.customContent.isButtonCustomized(key)) {
|
||||||
CustomButton btn = customContent.getCustomizedButton(key);
|
CustomButton btn = this.customContent.getCustomizedButton(key);
|
||||||
cells = btn.applyPosition(cell);
|
cells = btn.applyPosition(cell);
|
||||||
btn.applyItem(item);
|
btn.applyItem(item);
|
||||||
}
|
}
|
||||||
@ -222,21 +223,21 @@ public class CustomizableGui extends Gui {
|
|||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public Gui setItem(@NotNull String key, int row, int col, @Nullable ItemStack item) {
|
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);
|
return setItem(key, cell, item);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Gui mirrorFill(@NotNull String key, int row, int col, boolean mirrorRow, boolean mirrorCol, @NotNull ItemStack 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;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
ItemStack newItem = item.clone();
|
ItemStack newItem = item.clone();
|
||||||
boolean isShow = applyShowGuiKeys(key, newItem);
|
boolean isShow = applyShowGuiKeys(key, newItem);
|
||||||
|
|
||||||
if (customContent.isButtonCustomized(key)) {
|
if (this.customContent.isButtonCustomized(key)) {
|
||||||
CustomButton btn = customContent.getCustomizedButton(key);
|
CustomButton btn = this.customContent.getCustomizedButton(key);
|
||||||
row = btn.applyPositionRow(row);
|
row = btn.applyPositionRow(row);
|
||||||
col = btn.applyPositionCol(col);
|
col = btn.applyPositionCol(col);
|
||||||
|
|
||||||
@ -258,12 +259,12 @@ public class CustomizableGui extends Gui {
|
|||||||
public Gui highlightItem(@NotNull String key, int cell) {
|
public Gui highlightItem(@NotNull String key, int cell) {
|
||||||
List<Integer> cells = Collections.singletonList(cell);
|
List<Integer> cells = Collections.singletonList(cell);
|
||||||
|
|
||||||
if (customContent.isButtonDisabled(key)) {
|
if (this.customContent.isButtonDisabled(key)) {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (customContent.isButtonCustomized(key)) {
|
if (this.customContent.isButtonCustomized(key)) {
|
||||||
cells = customContent.getCustomizedButton(key).applyPosition(cell);
|
cells = this.customContent.getCustomizedButton(key).applyPosition(cell);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int c : cells) {
|
for (int c : cells) {
|
||||||
@ -275,11 +276,11 @@ public class CustomizableGui extends Gui {
|
|||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public Gui highlightItem(@NotNull String key, int row, int col) {
|
public Gui highlightItem(@NotNull String key, int row, int col) {
|
||||||
if (customContent.isButtonDisabled(key)) {
|
if (this.customContent.isButtonDisabled(key)) {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
final int cell = col + row * inventoryType.columns;
|
final int cell = col + row * this.inventoryType.columns;
|
||||||
|
|
||||||
return highlightItem(key, cell);
|
return highlightItem(key, cell);
|
||||||
}
|
}
|
||||||
@ -288,12 +289,12 @@ public class CustomizableGui extends Gui {
|
|||||||
public Gui removeHighlight(@NotNull String key, int cell) {
|
public Gui removeHighlight(@NotNull String key, int cell) {
|
||||||
List<Integer> cells = Collections.singletonList(cell);
|
List<Integer> cells = Collections.singletonList(cell);
|
||||||
|
|
||||||
if (customContent.isButtonDisabled(key)) {
|
if (this.customContent.isButtonDisabled(key)) {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (customContent.isButtonCustomized(key)) {
|
if (this.customContent.isButtonCustomized(key)) {
|
||||||
cells = customContent.getCustomizedButton(key).applyPosition(cell);
|
cells = this.customContent.getCustomizedButton(key).applyPosition(cell);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int c : cells) {
|
for (int c : cells) {
|
||||||
@ -305,34 +306,34 @@ public class CustomizableGui extends Gui {
|
|||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public Gui removeHighlight(@NotNull String key, int row, int col) {
|
public Gui removeHighlight(@NotNull String key, int row, int col) {
|
||||||
if (customContent.isButtonDisabled(key)) {
|
if (this.customContent.isButtonDisabled(key)) {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
final int cell = col + row * inventoryType.columns;
|
final int cell = col + row * this.inventoryType.columns;
|
||||||
|
|
||||||
return removeHighlight(key, cell);
|
return removeHighlight(key, cell);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public Gui updateItemLore(@NotNull String key, int row, int col, @NotNull String... lore) {
|
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 this;
|
||||||
}
|
}
|
||||||
|
|
||||||
return updateItemLore(key, col + row * inventoryType.columns, lore);
|
return updateItemLore(key, col + row * this.inventoryType.columns, lore);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public Gui updateItemLore(@NotNull String key, int cell, @NotNull String... lore) {
|
public Gui updateItemLore(@NotNull String key, int cell, @NotNull String... lore) {
|
||||||
List<Integer> cells = Collections.singletonList(cell);
|
List<Integer> cells = Collections.singletonList(cell);
|
||||||
|
|
||||||
if (customContent.isButtonDisabled(key)) {
|
if (this.customContent.isButtonDisabled(key)) {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (customContent.isButtonCustomized(key)) {
|
if (this.customContent.isButtonCustomized(key)) {
|
||||||
cells = customContent.getCustomizedButton(key).applyPosition(cell);
|
cells = this.customContent.getCustomizedButton(key).applyPosition(cell);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int c : cells) {
|
for (int c : cells) {
|
||||||
@ -344,23 +345,23 @@ public class CustomizableGui extends Gui {
|
|||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public Gui updateItemLore(@NotNull String key, int row, int col, @Nullable List<String> lore) {
|
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 this;
|
||||||
}
|
}
|
||||||
|
|
||||||
return updateItemLore(key, col + row * inventoryType.columns, lore);
|
return updateItemLore(key, col + row * this.inventoryType.columns, lore);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public Gui updateItemLore(@NotNull String key, int cell, @Nullable List<String> lore) {
|
public Gui updateItemLore(@NotNull String key, int cell, @Nullable List<String> lore) {
|
||||||
List<Integer> cells = Collections.singletonList(cell);
|
List<Integer> cells = Collections.singletonList(cell);
|
||||||
|
|
||||||
if (customContent.isButtonDisabled(key)) {
|
if (this.customContent.isButtonDisabled(key)) {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (customContent.isButtonCustomized(key)) {
|
if (this.customContent.isButtonCustomized(key)) {
|
||||||
cells = customContent.getCustomizedButton(key).applyPosition(cell);
|
cells = this.customContent.getCustomizedButton(key).applyPosition(cell);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int c : cells) {
|
for (int c : cells) {
|
||||||
@ -372,23 +373,23 @@ public class CustomizableGui extends Gui {
|
|||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public Gui updateItemName(@NotNull String key, int row, int col, @Nullable String name) {
|
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 this;
|
||||||
}
|
}
|
||||||
|
|
||||||
return updateItemName(key, col + row * inventoryType.columns, name);
|
return updateItemName(key, col + row * this.inventoryType.columns, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public Gui updateItemName(@NotNull String key, int cell, @Nullable String name) {
|
public Gui updateItemName(@NotNull String key, int cell, @Nullable String name) {
|
||||||
List<Integer> cells = Collections.singletonList(cell);
|
List<Integer> cells = Collections.singletonList(cell);
|
||||||
|
|
||||||
if (customContent.isButtonDisabled(key)) {
|
if (this.customContent.isButtonDisabled(key)) {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (customContent.isButtonCustomized(key)) {
|
if (this.customContent.isButtonCustomized(key)) {
|
||||||
cells = customContent.getCustomizedButton(key).applyPosition(cell);
|
cells = this.customContent.getCustomizedButton(key).applyPosition(cell);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int c : cells) {
|
for (int c : cells) {
|
||||||
@ -400,16 +401,16 @@ public class CustomizableGui extends Gui {
|
|||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public Gui updateItem(@NotNull String key, int row, int col, @Nullable String name, @NotNull String... lore) {
|
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 this;
|
||||||
}
|
}
|
||||||
|
|
||||||
return updateItem(key, col + row * inventoryType.columns, name, lore);
|
return updateItem(key, col + row * this.inventoryType.columns, name, lore);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public Gui updateItem(@NotNull String key, int cell, @Nullable String name, @NotNull String... lore) {
|
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;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -418,25 +419,25 @@ public class CustomizableGui extends Gui {
|
|||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public Gui updateItem(@NotNull String key, int row, int col, @Nullable String name, @Nullable List<String> lore) {
|
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 this;
|
||||||
}
|
}
|
||||||
|
|
||||||
return updateItem(key, col + row * inventoryType.columns, name, lore);
|
return updateItem(key, col + row * this.inventoryType.columns, name, lore);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public Gui updateItem(@NotNull String key, int cell, @NotNull String name, @Nullable List<String> lore) {
|
public Gui updateItem(@NotNull String key, int cell, @NotNull String name, @Nullable List<String> lore) {
|
||||||
List<Integer> cells = Collections.singletonList(cell);
|
List<Integer> cells = Collections.singletonList(cell);
|
||||||
|
|
||||||
if (customContent.isButtonDisabled(key)) {
|
if (this.customContent.isButtonDisabled(key)) {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
lore = applyShowGuiKeys(key, lore);
|
lore = applyShowGuiKeys(key, lore);
|
||||||
|
|
||||||
if (customContent.isButtonCustomized(key)) {
|
if (this.customContent.isButtonCustomized(key)) {
|
||||||
cells = customContent.getCustomizedButton(key).applyPosition(cell);
|
cells = this.customContent.getCustomizedButton(key).applyPosition(cell);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int c : cells) {
|
for (int c : cells) {
|
||||||
@ -448,23 +449,23 @@ public class CustomizableGui extends Gui {
|
|||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public Gui updateItem(@NotNull String key, int row, int col, @NotNull ItemStack itemTo, @Nullable String title, @NotNull String... lore) {
|
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 this;
|
||||||
}
|
}
|
||||||
|
|
||||||
return updateItem(key, col + row * inventoryType.columns, itemTo, title, lore);
|
return updateItem(key, col + row * this.inventoryType.columns, itemTo, title, lore);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public Gui updateItem(@NotNull String key, int cell, @NotNull ItemStack itemTo, @Nullable String title, @NotNull String... lore) {
|
public Gui updateItem(@NotNull String key, int cell, @NotNull ItemStack itemTo, @Nullable String title, @NotNull String... lore) {
|
||||||
List<Integer> cells = Collections.singletonList(cell);
|
List<Integer> cells = Collections.singletonList(cell);
|
||||||
|
|
||||||
if (customContent.isButtonDisabled(key)) {
|
if (this.customContent.isButtonDisabled(key)) {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (customContent.isButtonCustomized(key)) {
|
if (this.customContent.isButtonCustomized(key)) {
|
||||||
cells = customContent.getCustomizedButton(key).applyPosition(cell);
|
cells = this.customContent.getCustomizedButton(key).applyPosition(cell);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int c : cells) {
|
for (int c : cells) {
|
||||||
@ -475,24 +476,24 @@ public class CustomizableGui extends Gui {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public Gui updateItem(@NotNull String key, int row, int col, @NotNull CompatibleMaterial itemTo, @Nullable String title, @NotNull String... lore) {
|
public Gui updateItem(@NotNull String key, int row, int col, @NotNull XMaterial itemTo, @Nullable String title, @NotNull String... lore) {
|
||||||
if (customContent.isButtonDisabled(key)) {
|
if (this.customContent.isButtonDisabled(key)) {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
return updateItem(key, col + row * inventoryType.columns, itemTo, title, lore);
|
return updateItem(key, col + row * this.inventoryType.columns, itemTo, title, lore);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@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);
|
List<Integer> cells = Collections.singletonList(cell);
|
||||||
|
|
||||||
if (customContent.isButtonDisabled(key)) {
|
if (this.customContent.isButtonDisabled(key)) {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (customContent.isButtonCustomized(key)) {
|
if (this.customContent.isButtonCustomized(key)) {
|
||||||
cells = customContent.getCustomizedButton(key).applyPosition(cell);
|
cells = this.customContent.getCustomizedButton(key).applyPosition(cell);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int c : cells) {
|
for (int c : cells) {
|
||||||
@ -504,23 +505,23 @@ public class CustomizableGui extends Gui {
|
|||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public Gui updateItem(@NotNull String key, int row, int col, @NotNull ItemStack itemTo, @Nullable String title, @Nullable List<String> lore) {
|
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 this;
|
||||||
}
|
}
|
||||||
|
|
||||||
return updateItem(key, col + row * inventoryType.columns, itemTo, title, lore);
|
return updateItem(key, col + row * this.inventoryType.columns, itemTo, title, lore);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public Gui updateItem(@NotNull String key, int cell, @NotNull ItemStack itemTo, @Nullable String title, @Nullable List<String> lore) {
|
public Gui updateItem(@NotNull String key, int cell, @NotNull ItemStack itemTo, @Nullable String title, @Nullable List<String> lore) {
|
||||||
List<Integer> cells = Collections.singletonList(cell);
|
List<Integer> cells = Collections.singletonList(cell);
|
||||||
|
|
||||||
if (customContent.isButtonDisabled(key)) {
|
if (this.customContent.isButtonDisabled(key)) {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (customContent.isButtonCustomized(key)) {
|
if (this.customContent.isButtonCustomized(key)) {
|
||||||
cells = customContent.getCustomizedButton(key).applyPosition(cell);
|
cells = this.customContent.getCustomizedButton(key).applyPosition(cell);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int c : cells) {
|
for (int c : cells) {
|
||||||
@ -531,24 +532,24 @@ public class CustomizableGui extends Gui {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public Gui updateItem(@NotNull String key, int row, int col, @NotNull CompatibleMaterial itemTo, @Nullable String title, @Nullable List<String> lore) {
|
public Gui updateItem(@NotNull String key, int row, int col, @NotNull XMaterial itemTo, @Nullable String title, @Nullable List<String> lore) {
|
||||||
if (customContent.isButtonDisabled(key)) {
|
if (this.customContent.isButtonDisabled(key)) {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
return updateItem(key, col + row * inventoryType.columns, itemTo, title, lore);
|
return updateItem(key, col + row * this.inventoryType.columns, itemTo, title, lore);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@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);
|
List<Integer> cells = Collections.singletonList(cell);
|
||||||
|
|
||||||
if (customContent.isButtonDisabled(key)) {
|
if (this.customContent.isButtonDisabled(key)) {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (customContent.isButtonCustomized(key)) {
|
if (this.customContent.isButtonCustomized(key)) {
|
||||||
cells = customContent.getCustomizedButton(key).applyPosition(cell);
|
cells = this.customContent.getCustomizedButton(key).applyPosition(cell);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int c : cells) {
|
for (int c : cells) {
|
||||||
@ -560,7 +561,7 @@ public class CustomizableGui extends Gui {
|
|||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public Gui setAction(@NotNull String key, int cell, @Nullable Clickable action) {
|
public Gui setAction(@NotNull String key, int cell, @Nullable Clickable action) {
|
||||||
if (customContent.isButtonDisabled(key)) {
|
if (this.customContent.isButtonDisabled(key)) {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -571,18 +572,18 @@ public class CustomizableGui extends Gui {
|
|||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public Gui setAction(@NotNull String key, int row, int col, @Nullable Clickable action) {
|
public Gui setAction(@NotNull String key, int row, int col, @Nullable Clickable action) {
|
||||||
if (customContent.isButtonDisabled(key)) {
|
if (this.customContent.isButtonDisabled(key)) {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
setConditional(key, col + row * inventoryType.columns, null, action);
|
setConditional(key, col + row * this.inventoryType.columns, null, action);
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public Gui setAction(@NotNull String key, int cell, @Nullable ClickType type, @Nullable Clickable action) {
|
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;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -593,11 +594,11 @@ public class CustomizableGui extends Gui {
|
|||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public Gui setAction(@NotNull String key, int row, int col, @Nullable ClickType type, @Nullable Clickable action) {
|
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;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
setConditional(key, col + row * inventoryType.columns, type, action);
|
setConditional(key, col + row * this.inventoryType.columns, type, action);
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
@ -606,12 +607,12 @@ public class CustomizableGui extends Gui {
|
|||||||
public Gui clearActions(@NotNull String key, int cell) {
|
public Gui clearActions(@NotNull String key, int cell) {
|
||||||
List<Integer> cells = Collections.singletonList(cell);
|
List<Integer> cells = Collections.singletonList(cell);
|
||||||
|
|
||||||
if (customContent.isButtonDisabled(key)) {
|
if (this.customContent.isButtonDisabled(key)) {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (customContent.isButtonCustomized(key)) {
|
if (this.customContent.isButtonCustomized(key)) {
|
||||||
cells = customContent.getCustomizedButton(key).applyPosition(cell);
|
cells = this.customContent.getCustomizedButton(key).applyPosition(cell);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int c : cells) {
|
for (int c : cells) {
|
||||||
@ -623,25 +624,25 @@ public class CustomizableGui extends Gui {
|
|||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public Gui clearActions(@NotNull String key, int row, int col) {
|
public Gui clearActions(@NotNull String key, int row, int col) {
|
||||||
if (customContent.isButtonDisabled(key)) {
|
if (this.customContent.isButtonDisabled(key)) {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
return clearActions(key, col + row * inventoryType.columns);
|
return clearActions(key, col + row * this.inventoryType.columns);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public Gui setButton(@NotNull String key, int cell, ItemStack item, @Nullable Clickable action) {
|
public Gui setButton(@NotNull String key, int cell, ItemStack item, @Nullable Clickable action) {
|
||||||
List<Integer> cells = Collections.singletonList(cell);
|
List<Integer> cells = Collections.singletonList(cell);
|
||||||
|
|
||||||
if (customContent.isButtonDisabled(key)) {
|
if (this.customContent.isButtonDisabled(key)) {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
applyShowGuiKeys(key, item);
|
applyShowGuiKeys(key, item);
|
||||||
|
|
||||||
if (customContent.isButtonCustomized(key)) {
|
if (this.customContent.isButtonCustomized(key)) {
|
||||||
CustomButton btn = customContent.getCustomizedButton(key);
|
CustomButton btn = this.customContent.getCustomizedButton(key);
|
||||||
cells = btn.applyPosition(cell);
|
cells = btn.applyPosition(cell);
|
||||||
btn.applyItem(item);
|
btn.applyItem(item);
|
||||||
}
|
}
|
||||||
@ -656,25 +657,25 @@ public class CustomizableGui extends Gui {
|
|||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public Gui setButton(@NotNull String key, int row, int col, @Nullable ItemStack item, @Nullable Clickable action) {
|
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 this;
|
||||||
}
|
}
|
||||||
|
|
||||||
return setButton(key, col + row * inventoryType.columns, item, action);
|
return setButton(key, col + row * this.inventoryType.columns, item, action);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public Gui setButton(@NotNull String key, int cell, @Nullable ItemStack item, @Nullable ClickType type, @Nullable Clickable action) {
|
public Gui setButton(@NotNull String key, int cell, @Nullable ItemStack item, @Nullable ClickType type, @Nullable Clickable action) {
|
||||||
List<Integer> cells = Collections.singletonList(cell);
|
List<Integer> cells = Collections.singletonList(cell);
|
||||||
|
|
||||||
if (customContent.isButtonDisabled(key)) {
|
if (this.customContent.isButtonDisabled(key)) {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
applyShowGuiKeys(key, item);
|
applyShowGuiKeys(key, item);
|
||||||
|
|
||||||
if (customContent.isButtonCustomized(key)) {
|
if (this.customContent.isButtonCustomized(key)) {
|
||||||
CustomButton btn = customContent.getCustomizedButton(key);
|
CustomButton btn = this.customContent.getCustomizedButton(key);
|
||||||
cells = btn.applyPosition(cell);
|
cells = btn.applyPosition(cell);
|
||||||
btn.applyItem(item);
|
btn.applyItem(item);
|
||||||
}
|
}
|
||||||
@ -688,22 +689,22 @@ public class CustomizableGui extends Gui {
|
|||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public Gui setButton(@NotNull String key, int row, int col, @Nullable ItemStack item, @Nullable ClickType type, @Nullable Clickable action) {
|
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 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) {
|
protected void setConditional(@NotNull String key, int cell, @Nullable ClickType type, @Nullable Clickable action) {
|
||||||
List<Integer> cells = Collections.singletonList(cell);
|
List<Integer> cells = Collections.singletonList(cell);
|
||||||
|
|
||||||
if (customContent.isButtonDisabled(key)) {
|
if (this.customContent.isButtonDisabled(key)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (customContent.isButtonCustomized(key)) {
|
if (this.customContent.isButtonCustomized(key)) {
|
||||||
cells = customContent.getCustomizedButton(key).applyPosition(cell);
|
cells = this.customContent.getCustomizedButton(key).applyPosition(cell);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int c : cells) {
|
for (int c : cells) {
|
||||||
@ -714,8 +715,8 @@ public class CustomizableGui extends Gui {
|
|||||||
public Gui setNextPage(ItemStack item) {
|
public Gui setNextPage(ItemStack item) {
|
||||||
applyShowGuiKeys("__NEXT__", item);
|
applyShowGuiKeys("__NEXT__", item);
|
||||||
|
|
||||||
if (customContent.isButtonCustomized("__NEXT__")) {
|
if (this.customContent.isButtonCustomized("__NEXT__")) {
|
||||||
customContent.getCustomizedButton("__NEXT__").applyItem(item);
|
this.customContent.getCustomizedButton("__NEXT__").applyItem(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
return super.setNextPage(item);
|
return super.setNextPage(item);
|
||||||
@ -724,8 +725,8 @@ public class CustomizableGui extends Gui {
|
|||||||
public Gui setPrevPage(ItemStack item) {
|
public Gui setPrevPage(ItemStack item) {
|
||||||
applyShowGuiKeys("__PREV__", item);
|
applyShowGuiKeys("__PREV__", item);
|
||||||
|
|
||||||
if (customContent.isButtonCustomized("__PREV__")) {
|
if (this.customContent.isButtonCustomized("__PREV__")) {
|
||||||
customContent.getCustomizedButton("__PREV__").applyItem(item);
|
this.customContent.getCustomizedButton("__PREV__").applyItem(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
return super.setPrevPage(item);
|
return super.setPrevPage(item);
|
||||||
@ -737,8 +738,8 @@ public class CustomizableGui extends Gui {
|
|||||||
|
|
||||||
applyShowGuiKeys("__NEXT__", item);
|
applyShowGuiKeys("__NEXT__", item);
|
||||||
|
|
||||||
if (customContent.isButtonCustomized("__NEXT__")) {
|
if (this.customContent.isButtonCustomized("__NEXT__")) {
|
||||||
CustomButton btn = customContent.getCustomizedButton("__NEXT__");
|
CustomButton btn = this.customContent.getCustomizedButton("__NEXT__");
|
||||||
cells = btn.applyPosition(cell);
|
cells = btn.applyPosition(cell);
|
||||||
btn.applyItem(item);
|
btn.applyItem(item);
|
||||||
}
|
}
|
||||||
@ -754,7 +755,7 @@ public class CustomizableGui extends Gui {
|
|||||||
public Gui setNextPage(int row, int col, @NotNull ItemStack item) {
|
public Gui setNextPage(int row, int col, @NotNull ItemStack item) {
|
||||||
applyShowGuiKeys("__NEXT__", item);
|
applyShowGuiKeys("__NEXT__", item);
|
||||||
|
|
||||||
return setNextPage(col + row * inventoryType.columns, item);
|
return setNextPage(col + row * this.inventoryType.columns, item);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@ -763,8 +764,8 @@ public class CustomizableGui extends Gui {
|
|||||||
|
|
||||||
applyShowGuiKeys("__PREV__", item);
|
applyShowGuiKeys("__PREV__", item);
|
||||||
|
|
||||||
if (customContent.isButtonCustomized("__PREV__")) {
|
if (this.customContent.isButtonCustomized("__PREV__")) {
|
||||||
CustomButton btn = customContent.getCustomizedButton("__PREV__");
|
CustomButton btn = this.customContent.getCustomizedButton("__PREV__");
|
||||||
cells = btn.applyPosition(cell);
|
cells = btn.applyPosition(cell);
|
||||||
btn.applyItem(item);
|
btn.applyItem(item);
|
||||||
}
|
}
|
||||||
@ -780,7 +781,7 @@ public class CustomizableGui extends Gui {
|
|||||||
public Gui setPrevPage(int row, int col, @NotNull ItemStack item) {
|
public Gui setPrevPage(int row, int col, @NotNull ItemStack item) {
|
||||||
applyShowGuiKeys("__PREV__", 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) {
|
private boolean applyShowGuiKeys(String key, ItemStack item) {
|
||||||
@ -826,9 +827,9 @@ public class CustomizableGui extends Gui {
|
|||||||
private final String title;
|
private final String title;
|
||||||
private final List<String> lore;
|
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.key = key;
|
||||||
this.positions = positions;
|
this.positions = positions;
|
||||||
this.row = -1;
|
this.row = -1;
|
||||||
@ -838,7 +839,7 @@ public class CustomizableGui extends Gui {
|
|||||||
this.lore = lore;
|
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.key = key;
|
||||||
this.positions = null;
|
this.positions = null;
|
||||||
this.row = row;
|
this.row = row;
|
||||||
@ -849,7 +850,7 @@ public class CustomizableGui extends Gui {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public String getKey() {
|
public String getKey() {
|
||||||
return key;
|
return this.key;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean applyItem(ItemStack item) {
|
public boolean applyItem(ItemStack item) {
|
||||||
@ -857,7 +858,7 @@ public class CustomizableGui extends Gui {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
item.setType(this.item.getMaterial());
|
item.setType(this.item.parseMaterial());
|
||||||
|
|
||||||
if (ServerVersion.isServerVersionAtOrBelow(ServerVersion.V1_13)) {
|
if (ServerVersion.isServerVersionAtOrBelow(ServerVersion.V1_13)) {
|
||||||
item.setDurability(this.item.getData());
|
item.setDurability(this.item.getData());
|
||||||
@ -869,7 +870,7 @@ public class CustomizableGui extends Gui {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public ItemStack createItem() {
|
public ItemStack createItem() {
|
||||||
ItemStack item = this.item.getItem();
|
ItemStack item = this.item.parseItem();
|
||||||
applyMeta(item);
|
applyMeta(item);
|
||||||
|
|
||||||
return item;
|
return item;
|
||||||
@ -878,23 +879,23 @@ public class CustomizableGui extends Gui {
|
|||||||
private void applyMeta(ItemStack item) {
|
private void applyMeta(ItemStack item) {
|
||||||
ItemMeta meta = item.getItemMeta();
|
ItemMeta meta = item.getItemMeta();
|
||||||
|
|
||||||
if (title != null) {
|
if (this.title != null) {
|
||||||
meta.setDisplayName(TextUtils.formatText(title));
|
meta.setDisplayName(TextUtils.formatText(this.title));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (lore != null) {
|
if (this.lore != null) {
|
||||||
meta.setLore(TextUtils.formatText(lore));
|
meta.setLore(TextUtils.formatText(this.lore));
|
||||||
}
|
}
|
||||||
|
|
||||||
item.setItemMeta(meta);
|
item.setItemMeta(meta);
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Integer> applyPosition(int cell) {
|
public List<Integer> applyPosition(int cell) {
|
||||||
if (row != -1 && col != -1) {
|
if (this.row != -1 && this.col != -1) {
|
||||||
return Collections.singletonList(col + row * inventoryType.columns);
|
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) {
|
public int applyPositionRow(int row) {
|
||||||
@ -910,7 +911,7 @@ public class CustomizableGui extends Gui {
|
|||||||
private final boolean mirrorRow;
|
private final boolean mirrorRow;
|
||||||
private final boolean mirrorCol;
|
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);
|
super(key, row, col, null, null, item);
|
||||||
|
|
||||||
this.mirrorRow = mirrorRow;
|
this.mirrorRow = mirrorRow;
|
||||||
@ -918,11 +919,11 @@ public class CustomizableGui extends Gui {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean isMirrorRow() {
|
public boolean isMirrorRow() {
|
||||||
return mirrorRow;
|
return this.mirrorRow;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isMirrorCol() {
|
public boolean isMirrorCol() {
|
||||||
return mirrorCol;
|
return this.mirrorCol;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -939,22 +940,22 @@ public class CustomizableGui extends Gui {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public String getGuiKey() {
|
public String getGuiKey() {
|
||||||
return guiKey;
|
return this.guiKey;
|
||||||
}
|
}
|
||||||
|
|
||||||
public CustomButton getCustomizedButton(String key) {
|
public CustomButton getCustomizedButton(String key) {
|
||||||
return customizedButtons.get(key);
|
return this.customizedButtons.get(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
public CustomButton getCustomButton(String key) {
|
public CustomButton getCustomButton(String key) {
|
||||||
return customizedButtons.get(key);
|
return this.customizedButtons.get(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Map<String, CustomButton> getCustomButtons() {
|
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(","))
|
List<Integer> positions = Arrays.stream(position.split(","))
|
||||||
.map(Integer::parseInt)
|
.map(Integer::parseInt)
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
@ -962,49 +963,49 @@ public class CustomizableGui extends Gui {
|
|||||||
CustomButton customButton = new CustomButton(key, positions, title, lore, item);
|
CustomButton customButton = new CustomButton(key, positions, title, lore, item);
|
||||||
|
|
||||||
if (key.startsWith("custom_")) {
|
if (key.startsWith("custom_")) {
|
||||||
customButtons.put(key, customButton);
|
this.customButtons.put(key, customButton);
|
||||||
return;
|
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);
|
CustomButton customButton = new CustomButton(key, row, col, title, lore, item);
|
||||||
|
|
||||||
if (key.startsWith("custom_")) {
|
if (key.startsWith("custom_")) {
|
||||||
customButtons.put(key, customButton);
|
this.customButtons.put(key, customButton);
|
||||||
return;
|
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);
|
MirrorFill mirrorFill = new MirrorFill(key, row, col, mirrorRow, mirrorCol, item);
|
||||||
|
|
||||||
if (key.startsWith("custom_")) {
|
if (key.startsWith("custom_")) {
|
||||||
customButtons.put(key, mirrorFill);
|
this.customButtons.put(key, mirrorFill);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
customizedButtons.put(key, mirrorFill);
|
this.customizedButtons.put(key, mirrorFill);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isButtonCustomized(String key) {
|
public boolean isButtonCustomized(String key) {
|
||||||
return customizedButtons.containsKey(key);
|
return this.customizedButtons.containsKey(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void disableButton(String button) {
|
public void disableButton(String button) {
|
||||||
disabledButtons.add(button);
|
this.disabledButtons.add(button);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isButtonDisabled(String button) {
|
public boolean isButtonDisabled(String button) {
|
||||||
return disabledButtons.contains(button);
|
return this.disabledButtons.contains(button);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getRows() {
|
public int getRows() {
|
||||||
return rows;
|
return this.rows;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setRows(int rows) {
|
public void setRows(int rows) {
|
||||||
|
@ -8,7 +8,7 @@ import com.craftaro.core.gui.methods.Droppable;
|
|||||||
import com.craftaro.core.gui.methods.Openable;
|
import com.craftaro.core.gui.methods.Openable;
|
||||||
import com.craftaro.core.gui.methods.Pagable;
|
import com.craftaro.core.gui.methods.Pagable;
|
||||||
import com.craftaro.core.utils.ItemUtils;
|
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.HumanEntity;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.inventory.ClickType;
|
import org.bukkit.event.inventory.ClickType;
|
||||||
@ -32,31 +32,31 @@ public class DoubleGui extends Gui {
|
|||||||
|
|
||||||
public DoubleGui() {
|
public DoubleGui() {
|
||||||
super(GuiType.STANDARD);
|
super(GuiType.STANDARD);
|
||||||
allowDropItems = false;
|
this.allowDropItems = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public DoubleGui(GuiType type) {
|
public DoubleGui(GuiType type) {
|
||||||
super(type);
|
super(type);
|
||||||
allowDropItems = false;
|
this.allowDropItems = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public DoubleGui(int rows) {
|
public DoubleGui(int rows) {
|
||||||
super(rows);
|
super(rows);
|
||||||
allowDropItems = false;
|
this.allowDropItems = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public DoubleGui(int rows, Gui parent) {
|
public DoubleGui(int rows, Gui parent) {
|
||||||
super(rows, parent);
|
super(rows, parent);
|
||||||
allowDropItems = false;
|
this.allowDropItems = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public DoubleGui(Gui parent) {
|
public DoubleGui(Gui parent) {
|
||||||
super(parent);
|
super(parent);
|
||||||
allowDropItems = false;
|
this.allowDropItems = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getPlayerRows() {
|
public int getPlayerRows() {
|
||||||
return playerRows;
|
return this.playerRows;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 9 -> 0 -> 54
|
// 9 -> 0 -> 54
|
||||||
@ -78,29 +78,29 @@ public class DoubleGui extends Gui {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public DoubleGui setPlayerUnlocked(int cell) {
|
public DoubleGui setPlayerUnlocked(int cell) {
|
||||||
unlockedCells.put(invOffset(cell), true);
|
this.unlockedCells.put(invOffset(cell), true);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public DoubleGui setPlayerUnlocked(int row, int col) {
|
public DoubleGui setPlayerUnlocked(int row, int col) {
|
||||||
unlockedCells.put(invOffset(col + row * 9), true);
|
this.unlockedCells.put(invOffset(col + row * 9), true);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public DoubleGui setPlayerUnlocked(int cell, boolean open) {
|
public DoubleGui setPlayerUnlocked(int cell, boolean open) {
|
||||||
unlockedCells.put(invOffset(cell), open);
|
this.unlockedCells.put(invOffset(cell), open);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public DoubleGui setPlayerUnlocked(int row, int col, boolean open) {
|
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;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public DoubleGui setPlayerUnlockedRange(int cellFirst, int cellLast) {
|
public DoubleGui setPlayerUnlockedRange(int cellFirst, int cellLast) {
|
||||||
final int last = invOffset(cellLast);
|
final int last = invOffset(cellLast);
|
||||||
for (int cell = invOffset(cellFirst); cell <= last; ++cell) {
|
for (int cell = invOffset(cellFirst); cell <= last; ++cell) {
|
||||||
unlockedCells.put(cell, true);
|
this.unlockedCells.put(cell, true);
|
||||||
}
|
}
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
@ -109,7 +109,7 @@ public class DoubleGui extends Gui {
|
|||||||
final int last = invOffset(cellLast);
|
final int last = invOffset(cellLast);
|
||||||
|
|
||||||
for (int cell = invOffset(cellFirst); cell <= last; ++cell) {
|
for (int cell = invOffset(cellFirst); cell <= last; ++cell) {
|
||||||
unlockedCells.put(cell, open);
|
this.unlockedCells.put(cell, open);
|
||||||
}
|
}
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
@ -119,7 +119,7 @@ public class DoubleGui extends Gui {
|
|||||||
final int last = invOffset(cellColLast + cellRowLast * 9);
|
final int last = invOffset(cellColLast + cellRowLast * 9);
|
||||||
|
|
||||||
for (int cell = invOffset(cellColFirst + cellRowFirst * 9); cell <= last; ++cell) {
|
for (int cell = invOffset(cellColFirst + cellRowFirst * 9); cell <= last; ++cell) {
|
||||||
unlockedCells.put(cell, true);
|
this.unlockedCells.put(cell, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
@ -129,19 +129,19 @@ public class DoubleGui extends Gui {
|
|||||||
final int last = invOffset(cellColLast + cellRowLast * 9);
|
final int last = invOffset(cellColLast + cellRowLast * 9);
|
||||||
|
|
||||||
for (int cell = invOffset(cellColFirst + cellRowFirst * 9); cell <= last; ++cell) {
|
for (int cell = invOffset(cellColFirst + cellRowFirst * 9); cell <= last; ++cell) {
|
||||||
unlockedCells.put(cell, open);
|
this.unlockedCells.put(cell, open);
|
||||||
}
|
}
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public DoubleGui setPlayerItem(int cell, ItemStack item) {
|
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;
|
cell = cell >= 27 ? cell - 27 : cell + 9;
|
||||||
|
|
||||||
for (HumanEntity e : inventory.getViewers()) {
|
for (HumanEntity e : this.inventory.getViewers()) {
|
||||||
e.getInventory().setItem(cell, item);
|
e.getInventory().setItem(cell, item);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -151,12 +151,12 @@ public class DoubleGui extends Gui {
|
|||||||
|
|
||||||
public DoubleGui setPlayerItem(int row, int col, ItemStack item) {
|
public DoubleGui setPlayerItem(int row, int col, ItemStack item) {
|
||||||
int cell = col + row * 9;
|
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;
|
cell = cell >= 27 ? cell - 27 : cell + 9;
|
||||||
|
|
||||||
for (HumanEntity e : inventory.getViewers()) {
|
for (HumanEntity e : this.inventory.getViewers()) {
|
||||||
e.getInventory().setItem(cell, item);
|
e.getInventory().setItem(cell, item);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -166,7 +166,7 @@ public class DoubleGui extends Gui {
|
|||||||
|
|
||||||
public DoubleGui highlightPlayerItem(int cell) {
|
public DoubleGui highlightPlayerItem(int cell) {
|
||||||
final int invCell = invOffset(cell);
|
final int invCell = invOffset(cell);
|
||||||
ItemStack item = cellItems.get(invCell);
|
ItemStack item = this.cellItems.get(invCell);
|
||||||
|
|
||||||
if (item != null) {
|
if (item != null) {
|
||||||
setPlayerItem(cell, ItemUtils.addGlow(item));
|
setPlayerItem(cell, ItemUtils.addGlow(item));
|
||||||
@ -179,7 +179,7 @@ public class DoubleGui extends Gui {
|
|||||||
final int cell = col + row * 9;
|
final int cell = col + row * 9;
|
||||||
final int invCell = invOffset(cell);
|
final int invCell = invOffset(cell);
|
||||||
|
|
||||||
ItemStack item = cellItems.get(invCell);
|
ItemStack item = this.cellItems.get(invCell);
|
||||||
if (item != null) {
|
if (item != null) {
|
||||||
setPlayerItem(cell, ItemUtils.addGlow(item));
|
setPlayerItem(cell, ItemUtils.addGlow(item));
|
||||||
}
|
}
|
||||||
@ -244,13 +244,13 @@ public class DoubleGui extends Gui {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public DoubleGui clearPlayerActions(int cell) {
|
public DoubleGui clearPlayerActions(int cell) {
|
||||||
conditionalButtons.remove(invOffset(cell));
|
this.conditionalButtons.remove(invOffset(cell));
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public DoubleGui clearPlayerActions(int row, int col) {
|
public DoubleGui clearPlayerActions(int row, int col) {
|
||||||
final int cell = invOffset(col + row * 9);
|
final int cell = invOffset(col + row * 9);
|
||||||
conditionalButtons.remove(cell);
|
this.conditionalButtons.remove(cell);
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
@ -290,7 +290,7 @@ public class DoubleGui extends Gui {
|
|||||||
@Override
|
@Override
|
||||||
protected boolean onClickPlayerInventory(GuiManager manager, Player player, Inventory openInv, InventoryClickEvent event) {
|
protected boolean onClickPlayerInventory(GuiManager manager, Player player, Inventory openInv, InventoryClickEvent event) {
|
||||||
final int cell = event.getSlot(), offsetCell = clickOffset(cell);
|
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;
|
Clickable button;
|
||||||
|
|
||||||
if (conditionals != null
|
if (conditionals != null
|
||||||
@ -301,15 +301,15 @@ public class DoubleGui extends Gui {
|
|||||||
return false;
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected boolean onClickOutside(GuiManager manager, Player player, InventoryClickEvent event) {
|
protected boolean onClickOutside(GuiManager manager, Player player, InventoryClickEvent event) {
|
||||||
if (dropper != null) {
|
if (this.dropper != null) {
|
||||||
return dropper.onDrop(new GuiDropItemEvent(manager, this, player, event));
|
return this.dropper.onDrop(new GuiDropItemEvent(manager, this, player, event));
|
||||||
}
|
}
|
||||||
|
|
||||||
// do not allow by default
|
// do not allow by default
|
||||||
@ -319,7 +319,7 @@ public class DoubleGui extends Gui {
|
|||||||
@Override
|
@Override
|
||||||
public void onOpen(GuiManager manager, Player player) {
|
public void onOpen(GuiManager manager, Player player) {
|
||||||
// replace the player's inventory
|
// replace the player's inventory
|
||||||
if (startStashed) {
|
if (this.startStashed) {
|
||||||
stashItems(player);
|
stashItems(player);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -337,15 +337,15 @@ public class DoubleGui extends Gui {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected void restoreStash(Player player) {
|
protected void restoreStash(Player player) {
|
||||||
if (stash.containsKey(player)) {
|
if (this.stash.containsKey(player)) {
|
||||||
player.getInventory().setContents(stash.remove(player));
|
player.getInventory().setContents(this.stash.remove(player));
|
||||||
player.updateInventory();
|
player.updateInventory();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void stashItems(Player player) {
|
protected void stashItems(Player player) {
|
||||||
if (!stash.containsKey(player)) {
|
if (!this.stash.containsKey(player)) {
|
||||||
stash.put(player, player.getInventory().getContents().clone());
|
this.stash.put(player, player.getInventory().getContents().clone());
|
||||||
player.getInventory().clear();
|
player.getInventory().clear();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -461,12 +461,12 @@ public class DoubleGui extends Gui {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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);
|
return (DoubleGui) super.updateItem(col + row * 9, itemTo, title, lore);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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);
|
return (DoubleGui) super.updateItem(cell, itemTo, title, lore);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -481,12 +481,12 @@ public class DoubleGui extends Gui {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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);
|
return (DoubleGui) super.updateItem(col + row * 9, itemTo, title, lore);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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);
|
return (DoubleGui) super.updateItem(cell, itemTo, title, lore);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package com.craftaro.core.gui;
|
package com.craftaro.core.gui;
|
||||||
|
|
||||||
|
import com.craftaro.core.compatibility.ServerVersion;
|
||||||
import com.craftaro.core.gui.events.GuiClickEvent;
|
import com.craftaro.core.gui.events.GuiClickEvent;
|
||||||
import com.craftaro.core.gui.events.GuiCloseEvent;
|
import com.craftaro.core.gui.events.GuiCloseEvent;
|
||||||
import com.craftaro.core.gui.events.GuiDropItemEvent;
|
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.Openable;
|
||||||
import com.craftaro.core.gui.methods.Pagable;
|
import com.craftaro.core.gui.methods.Pagable;
|
||||||
import com.craftaro.core.utils.ItemUtils;
|
import com.craftaro.core.utils.ItemUtils;
|
||||||
import com.craftaro.core.compatibility.CompatibleMaterial;
|
import com.cryptomorin.xseries.XMaterial;
|
||||||
import com.craftaro.core.compatibility.CompatibleSound;
|
import com.cryptomorin.xseries.XSound;
|
||||||
import com.craftaro.core.compatibility.ServerVersion;
|
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.inventory.ClickType;
|
import org.bukkit.event.inventory.ClickType;
|
||||||
@ -50,7 +50,7 @@ public class Gui {
|
|||||||
protected ItemStack nextPageItem, prevPageItem;
|
protected ItemStack nextPageItem, prevPageItem;
|
||||||
protected ItemStack nextPage, prevPage;
|
protected ItemStack nextPage, prevPage;
|
||||||
protected Gui parent = null;
|
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 GuiManager guiManager;
|
||||||
protected boolean open = false;
|
protected boolean open = false;
|
||||||
@ -60,7 +60,7 @@ public class Gui {
|
|||||||
protected Closable closer = null;
|
protected Closable closer = null;
|
||||||
protected Droppable dropper = null;
|
protected Droppable dropper = null;
|
||||||
protected Pagable pager = null;
|
protected Pagable pager = null;
|
||||||
protected CompatibleSound defaultSound = CompatibleSound.UI_BUTTON_CLICK;
|
protected XSound defaultSound = XSound.UI_BUTTON_CLICK;
|
||||||
|
|
||||||
public Gui() {
|
public Gui() {
|
||||||
this.rows = 3;
|
this.rows = 3;
|
||||||
@ -69,6 +69,7 @@ public class Gui {
|
|||||||
public Gui(@NotNull GuiType type) {
|
public Gui(@NotNull GuiType type) {
|
||||||
this.inventoryType = type;
|
this.inventoryType = type;
|
||||||
|
|
||||||
|
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case HOPPER:
|
case HOPPER:
|
||||||
case DISPENSER:
|
case DISPENSER:
|
||||||
@ -95,11 +96,11 @@ public class Gui {
|
|||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public List<Player> getPlayers() {
|
public List<Player> getPlayers() {
|
||||||
if (inventory == null) {
|
if (this.inventory == null) {
|
||||||
return Collections.emptyList();
|
return Collections.emptyList();
|
||||||
}
|
}
|
||||||
|
|
||||||
return inventory.getViewers().stream()
|
return this.inventory.getViewers().stream()
|
||||||
.filter(Player.class::isInstance)
|
.filter(Player.class::isInstance)
|
||||||
.map(Player.class::cast)
|
.map(Player.class::cast)
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
@ -107,15 +108,15 @@ public class Gui {
|
|||||||
|
|
||||||
public boolean isOpen() {
|
public boolean isOpen() {
|
||||||
// double check
|
// double check
|
||||||
if (inventory != null && inventory.getViewers().isEmpty()) {
|
if (this.inventory != null && this.inventory.getViewers().isEmpty()) {
|
||||||
open = false;
|
this.open = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return open;
|
return this.open;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean getAcceptsItems() {
|
public boolean getAcceptsItems() {
|
||||||
return acceptsItems;
|
return this.acceptsItems;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Gui setAcceptsItems(boolean acceptsItems) {
|
public Gui setAcceptsItems(boolean acceptsItems) {
|
||||||
@ -128,7 +129,7 @@ public class Gui {
|
|||||||
* will be cleared
|
* will be cleared
|
||||||
*/
|
*/
|
||||||
public boolean getAllowDrops() {
|
public boolean getAllowDrops() {
|
||||||
return allowDropItems;
|
return this.allowDropItems;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -141,7 +142,7 @@ public class Gui {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean getAllowClose() {
|
public boolean getAllowClose() {
|
||||||
return allowClose;
|
return this.allowClose;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Gui setAllowClose(boolean allow) {
|
public Gui setAllowClose(boolean allow) {
|
||||||
@ -154,10 +155,10 @@ public class Gui {
|
|||||||
* GUIs
|
* GUIs
|
||||||
*/
|
*/
|
||||||
public void exit() {
|
public void exit() {
|
||||||
allowClose = true;
|
this.allowClose = true;
|
||||||
open = false;
|
this.open = false;
|
||||||
|
|
||||||
inventory.getViewers().stream()
|
this.inventory.getViewers().stream()
|
||||||
.filter(Player.class::isInstance)
|
.filter(Player.class::isInstance)
|
||||||
.map(Player.class::cast)
|
.map(Player.class::cast)
|
||||||
.collect(Collectors.toList())
|
.collect(Collectors.toList())
|
||||||
@ -168,9 +169,9 @@ public class Gui {
|
|||||||
* Close the GUI as if the player closed it normally
|
* Close the GUI as if the player closed it normally
|
||||||
*/
|
*/
|
||||||
public void close() {
|
public void close() {
|
||||||
allowClose = true;
|
this.allowClose = true;
|
||||||
|
|
||||||
inventory.getViewers().stream()
|
this.inventory.getViewers().stream()
|
||||||
.filter(Player.class::isInstance)
|
.filter(Player.class::isInstance)
|
||||||
.map(Player.class::cast)
|
.map(Player.class::cast)
|
||||||
.collect(Collectors.toList())
|
.collect(Collectors.toList())
|
||||||
@ -179,19 +180,19 @@ public class Gui {
|
|||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public GuiType getType() {
|
public GuiType getType() {
|
||||||
return inventoryType;
|
return this.inventoryType;
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public Gui setUnlocked(int cell) {
|
public Gui setUnlocked(int cell) {
|
||||||
unlockedCells.put(cell, true);
|
this.unlockedCells.put(cell, true);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public Gui setUnlocked(int row, int col) {
|
public Gui setUnlocked(int row, int col) {
|
||||||
final int cell = col + row * inventoryType.columns;
|
final int cell = col + row * this.inventoryType.columns;
|
||||||
unlockedCells.put(cell, true);
|
this.unlockedCells.put(cell, true);
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
@ -199,7 +200,7 @@ public class Gui {
|
|||||||
@NotNull
|
@NotNull
|
||||||
public Gui setUnlockedRange(int cellFirst, int cellLast) {
|
public Gui setUnlockedRange(int cellFirst, int cellLast) {
|
||||||
for (int cell = cellFirst; cell <= cellLast; ++cell) {
|
for (int cell = cellFirst; cell <= cellLast; ++cell) {
|
||||||
unlockedCells.put(cell, true);
|
this.unlockedCells.put(cell, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
@ -208,7 +209,7 @@ public class Gui {
|
|||||||
@NotNull
|
@NotNull
|
||||||
public Gui setUnlockedRange(int cellFirst, int cellLast, boolean open) {
|
public Gui setUnlockedRange(int cellFirst, int cellLast, boolean open) {
|
||||||
for (int cell = cellFirst; cell <= cellLast; ++cell) {
|
for (int cell = cellFirst; cell <= cellLast; ++cell) {
|
||||||
unlockedCells.put(cell, open);
|
this.unlockedCells.put(cell, open);
|
||||||
}
|
}
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
@ -216,10 +217,10 @@ public class Gui {
|
|||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public Gui setUnlockedRange(int cellRowFirst, int cellColFirst, int cellRowLast, int cellColLast) {
|
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) {
|
for (int cell = cellColFirst + cellRowFirst * this.inventoryType.columns; cell <= last; ++cell) {
|
||||||
unlockedCells.put(cell, true);
|
this.unlockedCells.put(cell, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
@ -227,10 +228,10 @@ public class Gui {
|
|||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public Gui setUnlockedRange(int cellRowFirst, int cellColFirst, int cellRowLast, int cellColLast, boolean open) {
|
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) {
|
for (int cell = cellColFirst + cellRowFirst * this.inventoryType.columns; cell <= last; ++cell) {
|
||||||
unlockedCells.put(cell, open);
|
this.unlockedCells.put(cell, open);
|
||||||
}
|
}
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
@ -238,14 +239,14 @@ public class Gui {
|
|||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public Gui setUnlocked(int cell, boolean open) {
|
public Gui setUnlocked(int cell, boolean open) {
|
||||||
unlockedCells.put(cell, open);
|
this.unlockedCells.put(cell, open);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public Gui setUnlocked(int row, int col, boolean open) {
|
public Gui setUnlocked(int row, int col, boolean open) {
|
||||||
final int cell = col + row * inventoryType.columns;
|
final int cell = col + row * this.inventoryType.columns;
|
||||||
unlockedCells.put(cell, open);
|
this.unlockedCells.put(cell, open);
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
@ -259,19 +260,19 @@ public class Gui {
|
|||||||
if (!title.equals(this.title)) {
|
if (!title.equals(this.title)) {
|
||||||
this.title = title;
|
this.title = title;
|
||||||
|
|
||||||
if (inventory != null) {
|
if (this.inventory != null) {
|
||||||
// update active inventory
|
// update active inventory
|
||||||
List<Player> toUpdate = getPlayers();
|
List<Player> toUpdate = getPlayers();
|
||||||
boolean isAllowClose = allowClose;
|
boolean isAllowClose = this.allowClose;
|
||||||
exit();
|
exit();
|
||||||
|
|
||||||
Inventory oldInv = inventory;
|
Inventory oldInv = this.inventory;
|
||||||
createInventory();
|
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() {
|
public int getRows() {
|
||||||
return rows;
|
return this.rows;
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public Gui setRows(int rows) {
|
public Gui setRows(int rows) {
|
||||||
switch (inventoryType) {
|
switch (this.inventoryType) {
|
||||||
case HOPPER:
|
case HOPPER:
|
||||||
case DISPENSER:
|
case DISPENSER:
|
||||||
break;
|
break;
|
||||||
@ -298,53 +299,53 @@ public class Gui {
|
|||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public Gui setDefaultAction(@Nullable Clickable action) {
|
public Gui setDefaultAction(@Nullable Clickable action) {
|
||||||
defaultClicker = action;
|
this.defaultClicker = action;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
protected Gui setPrivateDefaultAction(@Nullable Clickable action) {
|
protected Gui setPrivateDefaultAction(@Nullable Clickable action) {
|
||||||
privateDefaultClicker = action;
|
this.privateDefaultClicker = action;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public Gui setDefaultItem(@Nullable ItemStack item) {
|
public Gui setDefaultItem(@Nullable ItemStack item) {
|
||||||
blankItem = item;
|
this.blankItem = item;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public ItemStack getDefaultItem() {
|
public ItemStack getDefaultItem() {
|
||||||
return blankItem;
|
return this.blankItem;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public ItemStack getItem(int cell) {
|
public ItemStack getItem(int cell) {
|
||||||
if (inventory != null && unlockedCells.getOrDefault(cell, false)) {
|
if (this.inventory != null && this.unlockedCells.getOrDefault(cell, false)) {
|
||||||
return inventory.getItem(cell);
|
return this.inventory.getItem(cell);
|
||||||
}
|
}
|
||||||
|
|
||||||
return cellItems.get(cell);
|
return this.cellItems.get(cell);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public ItemStack getItem(int row, int col) {
|
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)) {
|
if (this.inventory != null && this.unlockedCells.getOrDefault(cell, false)) {
|
||||||
return inventory.getItem(cell);
|
return this.inventory.getItem(cell);
|
||||||
}
|
}
|
||||||
|
|
||||||
return cellItems.get(cell);
|
return this.cellItems.get(cell);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public Gui setItem(int cell, @Nullable ItemStack item) {
|
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()) {
|
if (this.inventory != null && cell >= 0 && cell < this.inventory.getSize()) {
|
||||||
inventory.setItem(cell, item);
|
this.inventory.setItem(cell, item);
|
||||||
}
|
}
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
@ -352,7 +353,7 @@ public class Gui {
|
|||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public Gui setItem(int row, int col, @Nullable ItemStack item) {
|
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);
|
return setItem(cell, item);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -361,7 +362,7 @@ public class Gui {
|
|||||||
setItem(row, col, item);
|
setItem(row, col, item);
|
||||||
|
|
||||||
if (mirrorRow) {
|
if (mirrorRow) {
|
||||||
setItem(rows - row - 1, col, item);
|
setItem(this.rows - row - 1, col, item);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mirrorCol) {
|
if (mirrorCol) {
|
||||||
@ -369,7 +370,7 @@ public class Gui {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (mirrorRow && mirrorCol) {
|
if (mirrorRow && mirrorCol) {
|
||||||
setItem(rows - row - 1, 8 - col, item);
|
setItem(this.rows - row - 1, 8 - col, item);
|
||||||
}
|
}
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
@ -377,7 +378,7 @@ public class Gui {
|
|||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public Gui highlightItem(int cell) {
|
public Gui highlightItem(int cell) {
|
||||||
ItemStack item = cellItems.get(cell);
|
ItemStack item = this.cellItems.get(cell);
|
||||||
|
|
||||||
if (item != null && item.getType() != Material.AIR) {
|
if (item != null && item.getType() != Material.AIR) {
|
||||||
setItem(cell, ItemUtils.addGlow(item));
|
setItem(cell, ItemUtils.addGlow(item));
|
||||||
@ -388,14 +389,14 @@ public class Gui {
|
|||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public Gui highlightItem(int row, int col) {
|
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);
|
return highlightItem(cell);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public Gui removeHighlight(int cell) {
|
public Gui removeHighlight(int cell) {
|
||||||
ItemStack item = cellItems.get(cell);
|
ItemStack item = this.cellItems.get(cell);
|
||||||
|
|
||||||
if (item != null && item.getType() != Material.AIR) {
|
if (item != null && item.getType() != Material.AIR) {
|
||||||
setItem(cell, ItemUtils.removeGlow(item));
|
setItem(cell, ItemUtils.removeGlow(item));
|
||||||
@ -406,18 +407,18 @@ public class Gui {
|
|||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public Gui removeHighlight(int row, int col) {
|
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);
|
return removeHighlight(cell);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public Gui updateItemLore(int row, int col, @NotNull String... lore) {
|
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
|
@NotNull
|
||||||
public Gui updateItemLore(int cell, @NotNull String... lore) {
|
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) {
|
if (item != null && item.getType() != Material.AIR) {
|
||||||
setItem(cell, GuiUtils.updateItemLore(item, lore));
|
setItem(cell, GuiUtils.updateItemLore(item, lore));
|
||||||
@ -428,12 +429,12 @@ public class Gui {
|
|||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public Gui updateItemLore(int row, int col, @Nullable List<String> lore) {
|
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
|
@NotNull
|
||||||
public Gui updateItemLore(int cell, @Nullable List<String> lore) {
|
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) {
|
if (item != null && item.getType() != Material.AIR) {
|
||||||
setItem(cell, GuiUtils.updateItemLore(item, lore));
|
setItem(cell, GuiUtils.updateItemLore(item, lore));
|
||||||
@ -444,12 +445,12 @@ public class Gui {
|
|||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public Gui updateItemName(int row, int col, @Nullable String name) {
|
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
|
@NotNull
|
||||||
public Gui updateItemName(int cell, @Nullable String name) {
|
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) {
|
if (item != null && item.getType() != Material.AIR) {
|
||||||
setItem(cell, GuiUtils.updateItemName(item, name));
|
setItem(cell, GuiUtils.updateItemName(item, name));
|
||||||
@ -460,7 +461,7 @@ public class Gui {
|
|||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public Gui updateItem(int row, int col, @Nullable String name, @NotNull String... lore) {
|
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
|
@NotNull
|
||||||
@ -470,12 +471,12 @@ public class Gui {
|
|||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public Gui updateItem(int row, int col, @Nullable String name, @Nullable List<String> lore) {
|
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
|
@NotNull
|
||||||
public Gui updateItem(int cell, @NotNull String name, @Nullable List<String> lore) {
|
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) {
|
if (item != null && item.getType() != Material.AIR) {
|
||||||
setItem(cell, GuiUtils.updateItem(item, name, lore));
|
setItem(cell, GuiUtils.updateItem(item, name, lore));
|
||||||
@ -486,12 +487,12 @@ public class Gui {
|
|||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public Gui updateItem(int row, int col, @NotNull ItemStack itemTo, @Nullable String title, @NotNull String... lore) {
|
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
|
@NotNull
|
||||||
public Gui updateItem(int cell, @NotNull ItemStack itemTo, @Nullable String title, @NotNull String... lore) {
|
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) {
|
if (item != null && item.getType() != Material.AIR) {
|
||||||
setItem(cell, GuiUtils.updateItem(item, itemTo, title, lore));
|
setItem(cell, GuiUtils.updateItem(item, itemTo, title, lore));
|
||||||
@ -501,13 +502,13 @@ public class Gui {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public Gui updateItem(int row, int col, @NotNull CompatibleMaterial itemTo, @Nullable String title, @NotNull String... lore) {
|
public Gui updateItem(int row, int col, @NotNull XMaterial itemTo, @Nullable String title, @NotNull String... lore) {
|
||||||
return updateItem(col + row * inventoryType.columns, itemTo, title, lore);
|
return updateItem(col + row * this.inventoryType.columns, itemTo, title, lore);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public Gui updateItem(int cell, @NotNull CompatibleMaterial itemTo, @Nullable String title, @Nullable String... lore) {
|
public Gui updateItem(int cell, @NotNull XMaterial itemTo, @Nullable String title, @Nullable String... lore) {
|
||||||
ItemStack item = cellItems.get(cell);
|
ItemStack item = this.cellItems.get(cell);
|
||||||
|
|
||||||
if (item != null && item.getType() != Material.AIR) {
|
if (item != null && item.getType() != Material.AIR) {
|
||||||
setItem(cell, GuiUtils.updateItem(item, itemTo, title, lore));
|
setItem(cell, GuiUtils.updateItem(item, itemTo, title, lore));
|
||||||
@ -518,12 +519,12 @@ public class Gui {
|
|||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public Gui updateItem(int row, int col, @NotNull ItemStack itemTo, @Nullable String title, @Nullable List<String> lore) {
|
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
|
@NotNull
|
||||||
public Gui updateItem(int cell, @NotNull ItemStack itemTo, @Nullable String title, @Nullable List<String> lore) {
|
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) {
|
if (item != null && item.getType() != Material.AIR) {
|
||||||
setItem(cell, GuiUtils.updateItem(item, itemTo, title, lore));
|
setItem(cell, GuiUtils.updateItem(item, itemTo, title, lore));
|
||||||
@ -533,13 +534,13 @@ public class Gui {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public Gui updateItem(int row, int col, @NotNull CompatibleMaterial itemTo, @Nullable String title, @Nullable List<String> lore) {
|
public Gui updateItem(int row, int col, @NotNull XMaterial itemTo, @Nullable String title, @Nullable List<String> lore) {
|
||||||
return updateItem(col + row * inventoryType.columns, itemTo, title, lore);
|
return updateItem(col + row * this.inventoryType.columns, itemTo, title, lore);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public Gui updateItem(int cell, @NotNull CompatibleMaterial itemTo, @Nullable String title, @Nullable List<String> lore) {
|
public Gui updateItem(int cell, @NotNull XMaterial itemTo, @Nullable String title, @Nullable List<String> lore) {
|
||||||
ItemStack item = cellItems.get(cell);
|
ItemStack item = this.cellItems.get(cell);
|
||||||
|
|
||||||
if (item != null && item.getType() != Material.AIR) {
|
if (item != null && item.getType() != Material.AIR) {
|
||||||
setItem(cell, GuiUtils.updateItem(item, itemTo, title, lore));
|
setItem(cell, GuiUtils.updateItem(item, itemTo, title, lore));
|
||||||
@ -556,7 +557,7 @@ public class Gui {
|
|||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public Gui setAction(int row, int col, @Nullable Clickable action) {
|
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;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -568,7 +569,7 @@ public class Gui {
|
|||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public Gui setAction(int row, int col, @Nullable ClickType type, @Nullable Clickable action) {
|
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;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -583,9 +584,9 @@ public class Gui {
|
|||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public Gui setActionForRange(int cellRowFirst, int cellColFirst, int cellRowLast, int cellColLast, @Nullable Clickable action) {
|
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);
|
setConditional(cell, null, action);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -603,9 +604,9 @@ public class Gui {
|
|||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public Gui setActionForRange(int cellRowFirst, int cellColFirst, int cellRowLast, int cellColLast, @Nullable ClickType type, @Nullable Clickable action) {
|
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);
|
setConditional(cell, type, action);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -614,13 +615,13 @@ public class Gui {
|
|||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public Gui clearActions(int cell) {
|
public Gui clearActions(int cell) {
|
||||||
conditionalButtons.remove(cell);
|
this.conditionalButtons.remove(cell);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public Gui clearActions(int row, int col) {
|
public Gui clearActions(int row, int col) {
|
||||||
return clearActions(col + row * inventoryType.columns);
|
return clearActions(col + row * this.inventoryType.columns);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@ -633,7 +634,7 @@ public class Gui {
|
|||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public Gui setButton(int row, int col, @Nullable ItemStack item, @Nullable Clickable action) {
|
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);
|
setItem(cell, item);
|
||||||
setConditional(cell, null, action);
|
setConditional(cell, null, action);
|
||||||
@ -651,7 +652,7 @@ public class Gui {
|
|||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public Gui setButton(int row, int col, @Nullable ItemStack item, @Nullable ClickType type, @Nullable Clickable action) {
|
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);
|
setItem(cell, item);
|
||||||
setConditional(cell, type, action);
|
setConditional(cell, type, action);
|
||||||
@ -660,62 +661,62 @@ public class Gui {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected void setConditional(int cell, @Nullable ClickType type, @Nullable Clickable action) {
|
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);
|
conditionals.put(type, action);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public Gui setOnOpen(@Nullable Openable action) {
|
public Gui setOnOpen(@Nullable Openable action) {
|
||||||
opener = action;
|
this.opener = action;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public Gui setOnClose(@Nullable Closable action) {
|
public Gui setOnClose(@Nullable Closable action) {
|
||||||
closer = action;
|
this.closer = action;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public Gui setOnDrop(@Nullable Droppable action) {
|
public Gui setOnDrop(@Nullable Droppable action) {
|
||||||
dropper = action;
|
this.dropper = action;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public Gui setOnPage(@Nullable Pagable action) {
|
public Gui setOnPage(@Nullable Pagable action) {
|
||||||
pager = action;
|
this.pager = action;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Gui setNextPage(ItemStack item) {
|
public Gui setNextPage(ItemStack item) {
|
||||||
nextPage = item;
|
this.nextPage = item;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Gui setPrevPage(ItemStack item) {
|
public Gui setPrevPage(ItemStack item) {
|
||||||
prevPage = item;
|
this.prevPage = item;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void reset() {
|
public void reset() {
|
||||||
if (inventory != null) {
|
if (this.inventory != null) {
|
||||||
inventory.clear();
|
this.inventory.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
setActionForRange(0, 53, null);
|
setActionForRange(0, 53, null);
|
||||||
cellItems.clear();
|
this.cellItems.clear();
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public Gui setNextPage(int cell, @NotNull ItemStack item) {
|
public Gui setNextPage(int cell, @NotNull ItemStack item) {
|
||||||
nextPageItem = cellItems.get(cell);
|
this.nextPageItem = this.cellItems.get(cell);
|
||||||
nextPageIndex = cell;
|
this.nextPageIndex = cell;
|
||||||
nextPage = item;
|
this.nextPage = item;
|
||||||
|
|
||||||
if (page < pages) {
|
if (this.page < this.pages) {
|
||||||
setButton(nextPageIndex, nextPage, ClickType.LEFT, (event) -> this.nextPage());
|
setButton(this.nextPageIndex, this.nextPage, ClickType.LEFT, (event) -> this.nextPage());
|
||||||
}
|
}
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
@ -723,17 +724,17 @@ public class Gui {
|
|||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public Gui setNextPage(int row, int col, @NotNull ItemStack item) {
|
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
|
@NotNull
|
||||||
public Gui setPrevPage(int cell, @NotNull ItemStack item) {
|
public Gui setPrevPage(int cell, @NotNull ItemStack item) {
|
||||||
prevPageItem = cellItems.get(cell);
|
this.prevPageItem = this.cellItems.get(cell);
|
||||||
prevPageIndex = cell;
|
this.prevPageIndex = cell;
|
||||||
prevPage = item;
|
this.prevPage = item;
|
||||||
|
|
||||||
if (page > 1) {
|
if (this.page > 1) {
|
||||||
setButton(prevPageIndex, prevPage, ClickType.LEFT, (event) -> this.prevPage());
|
setButton(this.prevPageIndex, this.prevPage, ClickType.LEFT, (event) -> this.prevPage());
|
||||||
}
|
}
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
@ -741,23 +742,23 @@ public class Gui {
|
|||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public Gui setPrevPage(int row, int col, @NotNull ItemStack item) {
|
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) {
|
public void setPages(int pages) {
|
||||||
this.pages = Math.max(1, pages);
|
this.pages = Math.max(1, pages);
|
||||||
|
|
||||||
if (page > pages) {
|
if (this.page > pages) {
|
||||||
setPage(pages);
|
setPage(pages);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setPage(int page) {
|
public void setPage(int page) {
|
||||||
int lastPage = this.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) {
|
if (this.pager != null && this.page != lastPage) {
|
||||||
pager.onPageChange(new GuiPageEvent(this, guiManager, lastPage, page));
|
this.pager.onPageChange(new GuiPageEvent(this, this.guiManager, lastPage, page));
|
||||||
|
|
||||||
// page markers
|
// page markers
|
||||||
updatePageNavigation();
|
updatePageNavigation();
|
||||||
@ -765,11 +766,11 @@ public class Gui {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void changePage(int direction) {
|
public void changePage(int direction) {
|
||||||
int lastPage = page;
|
int lastPage = this.page;
|
||||||
this.page = Math.max(1, Math.min(pages, page + direction));
|
this.page = Math.max(1, Math.min(this.pages, this.page + direction));
|
||||||
|
|
||||||
if (pager != null && this.page != lastPage) {
|
if (this.pager != null && this.page != lastPage) {
|
||||||
pager.onPageChange(new GuiPageEvent(this, guiManager, lastPage, page));
|
this.pager.onPageChange(new GuiPageEvent(this, this.guiManager, lastPage, this.page));
|
||||||
|
|
||||||
// page markers
|
// page markers
|
||||||
updatePageNavigation();
|
updatePageNavigation();
|
||||||
@ -777,13 +778,13 @@ public class Gui {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void nextPage() {
|
public void nextPage() {
|
||||||
if (page < pages) {
|
if (this.page < this.pages) {
|
||||||
int lastPage = page;
|
int lastPage = this.page;
|
||||||
++page;
|
++this.page;
|
||||||
|
|
||||||
// page switch events
|
// page switch events
|
||||||
if (pager != null) {
|
if (this.pager != null) {
|
||||||
pager.onPageChange(new GuiPageEvent(this, guiManager, lastPage, page));
|
this.pager.onPageChange(new GuiPageEvent(this, this.guiManager, lastPage, this.page));
|
||||||
|
|
||||||
// page markers
|
// page markers
|
||||||
updatePageNavigation();
|
updatePageNavigation();
|
||||||
@ -796,12 +797,12 @@ public class Gui {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void prevPage() {
|
public void prevPage() {
|
||||||
if (page > 1) {
|
if (this.page > 1) {
|
||||||
int lastPage = page;
|
int lastPage = this.page;
|
||||||
--page;
|
--this.page;
|
||||||
|
|
||||||
if (pager != null) {
|
if (this.pager != null) {
|
||||||
pager.onPageChange(new GuiPageEvent(this, guiManager, lastPage, page));
|
this.pager.onPageChange(new GuiPageEvent(this, this.guiManager, lastPage, this.page));
|
||||||
|
|
||||||
// page markers
|
// page markers
|
||||||
updatePageNavigation();
|
updatePageNavigation();
|
||||||
@ -814,75 +815,75 @@ public class Gui {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected void updatePageNavigation() {
|
protected void updatePageNavigation() {
|
||||||
if (prevPage != null) {
|
if (this.prevPage != null) {
|
||||||
if (page > 1) {
|
if (this.page > 1) {
|
||||||
this.setButton(prevPageIndex, prevPage, ClickType.LEFT, (event) -> this.prevPage());
|
this.setButton(this.prevPageIndex, this.prevPage, ClickType.LEFT, (event) -> this.prevPage());
|
||||||
} else {
|
} else {
|
||||||
this.setItem(prevPageIndex, prevPageItem);
|
this.setItem(this.prevPageIndex, this.prevPageItem);
|
||||||
this.clearActions(prevPageIndex);
|
this.clearActions(this.prevPageIndex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (nextPage != null) {
|
if (this.nextPage != null) {
|
||||||
if (pages > 1 && page != pages) {
|
if (this.pages > 1 && this.page != this.pages) {
|
||||||
this.setButton(nextPageIndex, nextPage, ClickType.LEFT, (event) -> this.nextPage());
|
this.setButton(this.nextPageIndex, this.nextPage, ClickType.LEFT, (event) -> this.nextPage());
|
||||||
} else {
|
} else {
|
||||||
this.setItem(nextPageIndex, nextPageItem);
|
this.setItem(this.nextPageIndex, this.nextPageItem);
|
||||||
this.clearActions(nextPageIndex);
|
this.clearActions(this.nextPageIndex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
protected Inventory getOrCreateInventory(@NotNull GuiManager manager) {
|
protected Inventory getOrCreateInventory(@NotNull GuiManager manager) {
|
||||||
return inventory != null ? inventory : generateInventory(manager);
|
return this.inventory != null ? this.inventory : generateInventory(manager);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
protected Inventory generateInventory(@NotNull GuiManager manager) {
|
protected Inventory generateInventory(@NotNull GuiManager manager) {
|
||||||
this.guiManager = manager;
|
this.guiManager = manager;
|
||||||
final int cells = rows * inventoryType.columns;
|
final int cells = this.rows * this.inventoryType.columns;
|
||||||
|
|
||||||
createInventory();
|
createInventory();
|
||||||
|
|
||||||
for (int i = 0; i < cells; ++i) {
|
for (int i = 0; i < cells; ++i) {
|
||||||
final ItemStack item = cellItems.get(i);
|
final ItemStack item = this.cellItems.get(i);
|
||||||
inventory.setItem(i, item != null ? item : (unlockedCells.getOrDefault(i, false) ? AIR : blankItem));
|
this.inventory.setItem(i, item != null ? item : (this.unlockedCells.getOrDefault(i, false) ? AIR : this.blankItem));
|
||||||
}
|
}
|
||||||
|
|
||||||
return inventory;
|
return this.inventory;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void createInventory() {
|
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) {
|
switch (t) {
|
||||||
case DISPENSER:
|
case DISPENSER:
|
||||||
case HOPPER:
|
case HOPPER:
|
||||||
inventory = new GuiHolder(guiManager, this).newInventory(t,
|
this.inventory = new GuiHolder(this.guiManager, this).newInventory(t,
|
||||||
title == null ? "" : trimTitle(title));
|
this.title == null ? "" : trimTitle(this.title));
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
inventory = new GuiHolder(guiManager, this).newInventory(rows * 9,
|
this.inventory = new GuiHolder(this.guiManager, this).newInventory(this.rows * 9,
|
||||||
title == null ? "" : trimTitle(title));
|
this.title == null ? "" : trimTitle(this.title));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public Gui getParent() {
|
public Gui getParent() {
|
||||||
return parent;
|
return this.parent;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void update() {
|
public void update() {
|
||||||
if (inventory == null) {
|
if (this.inventory == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
final int cells = rows * inventoryType.columns;
|
final int cells = this.rows * this.inventoryType.columns;
|
||||||
for (int i = 0; i < cells; ++i) {
|
for (int i = 0; i < cells; ++i) {
|
||||||
final ItemStack item = cellItems.get(i);
|
final ItemStack item = this.cellItems.get(i);
|
||||||
inventory.setItem(i, item != null ? item : (unlockedCells.getOrDefault(i, false) ? AIR : blankItem));
|
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) {
|
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) {
|
protected boolean onClick(@NotNull GuiManager manager, @NotNull Player player, @NotNull Inventory inventory, @NotNull InventoryClickEvent event) {
|
||||||
final int cell = event.getSlot();
|
final int cell = event.getSlot();
|
||||||
Map<ClickType, Clickable> conditionals = conditionalButtons.get(cell);
|
Map<ClickType, Clickable> conditionals = this.conditionalButtons.get(cell);
|
||||||
|
|
||||||
Clickable button;
|
Clickable button;
|
||||||
if (conditionals != null
|
if (conditionals != null
|
||||||
@ -912,14 +913,14 @@ public class Gui {
|
|||||||
button.onClick(new GuiClickEvent(manager, this, player, event, cell, true));
|
button.onClick(new GuiClickEvent(manager, this, player, event, cell, true));
|
||||||
} else {
|
} else {
|
||||||
// no event for this button
|
// no event for this button
|
||||||
if (defaultClicker != null) {
|
if (this.defaultClicker != null) {
|
||||||
// this is a default action, not a triggered action
|
// 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
|
// 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;
|
return false;
|
||||||
@ -934,36 +935,36 @@ public class Gui {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void onOpen(@NotNull GuiManager manager, @NotNull Player player) {
|
public void onOpen(@NotNull GuiManager manager, @NotNull Player player) {
|
||||||
open = true;
|
this.open = true;
|
||||||
guiManager = manager;
|
this.guiManager = manager;
|
||||||
|
|
||||||
if (opener != null) {
|
if (this.opener != null) {
|
||||||
opener.onOpen(new GuiOpenEvent(manager, this, player));
|
this.opener.onOpen(new GuiOpenEvent(manager, this, player));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onClose(@NotNull GuiManager manager, @NotNull Player player) {
|
public void onClose(@NotNull GuiManager manager, @NotNull Player player) {
|
||||||
if (!allowClose) {
|
if (!this.allowClose) {
|
||||||
manager.showGUI(player, this);
|
manager.showGUI(player, this);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean showParent = open && parent != null;
|
boolean showParent = this.open && this.parent != null;
|
||||||
|
|
||||||
if (closer != null) {
|
if (this.closer != null) {
|
||||||
closer.onClose(new GuiCloseEvent(manager, this, player));
|
this.closer.onClose(new GuiCloseEvent(manager, this, player));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (showParent) {
|
if (showParent) {
|
||||||
manager.showGUI(player, parent);
|
manager.showGUI(player, this.parent);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public CompatibleSound getDefaultSound() {
|
public XSound getDefaultSound() {
|
||||||
return defaultSound;
|
return this.defaultSound;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setDefaultSound(CompatibleSound sound) {
|
public void setDefaultSound(XSound sound) {
|
||||||
defaultSound = sound;
|
this.defaultSound = sound;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,7 @@ import org.bukkit.Bukkit;
|
|||||||
import org.bukkit.event.inventory.InventoryType;
|
import org.bukkit.event.inventory.InventoryType;
|
||||||
import org.bukkit.inventory.Inventory;
|
import org.bukkit.inventory.Inventory;
|
||||||
import org.bukkit.inventory.InventoryHolder;
|
import org.bukkit.inventory.InventoryHolder;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Internal class for marking an inventory as a GUI inventory
|
* Internal class for marking an inventory as a GUI inventory
|
||||||
@ -18,12 +19,12 @@ class GuiHolder implements InventoryHolder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Inventory getInventory() {
|
public @NotNull Inventory getInventory() {
|
||||||
return gui.inventory;
|
return this.gui.inventory;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Gui getGUI() {
|
public Gui getGUI() {
|
||||||
return gui;
|
return this.gui;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Inventory newInventory(int size, String title) {
|
public Inventory newInventory(int size, String title) {
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
package com.craftaro.core.gui;
|
package com.craftaro.core.gui;
|
||||||
|
|
||||||
import com.craftaro.core.compatibility.ClientVersion;
|
import com.craftaro.core.compatibility.ClientVersion;
|
||||||
import com.craftaro.core.compatibility.CompatibleMaterial;
|
|
||||||
import com.craftaro.core.compatibility.ServerVersion;
|
import com.craftaro.core.compatibility.ServerVersion;
|
||||||
|
import com.cryptomorin.xseries.XMaterial;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
@ -43,17 +43,17 @@ public class GuiManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Plugin getPlugin() {
|
public Plugin getPlugin() {
|
||||||
return plugin;
|
return this.plugin;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initialize the GUI handlers
|
* Initialize the GUI handlers
|
||||||
*/
|
*/
|
||||||
public void init() {
|
public void init() {
|
||||||
Bukkit.getPluginManager().registerEvents(listener, plugin);
|
Bukkit.getPluginManager().registerEvents(this.listener, this.plugin);
|
||||||
|
|
||||||
initialized = true;
|
this.initialized = true;
|
||||||
shutdown = false;
|
this.shutdown = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -62,7 +62,7 @@ public class GuiManager {
|
|||||||
* @return true if the owning plugin has shutdown
|
* @return true if the owning plugin has shutdown
|
||||||
*/
|
*/
|
||||||
public boolean isClosed() {
|
public boolean isClosed() {
|
||||||
return shutdown;
|
return this.shutdown;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -72,20 +72,20 @@ public class GuiManager {
|
|||||||
* @param gui GUI to use
|
* @param gui GUI to use
|
||||||
*/
|
*/
|
||||||
public void showGUI(Player player, Gui gui) {
|
public void showGUI(Player player, Gui gui) {
|
||||||
if (shutdown) {
|
if (this.shutdown) {
|
||||||
if (!plugin.isEnabled()) {
|
if (!this.plugin.isEnabled()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// recover if reloaded without calling init manually
|
// recover if reloaded without calling init manually
|
||||||
init();
|
init();
|
||||||
} else if (!initialized) {
|
} else if (!this.initialized) {
|
||||||
init();
|
init();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (gui instanceof AnvilGui) {
|
if (gui instanceof AnvilGui) {
|
||||||
// bukkit throws a fit now if you try to set anvil stuff asynchronously
|
// 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) {
|
if (openInv != null) {
|
||||||
openInv.open = false;
|
openInv.open = false;
|
||||||
@ -95,15 +95,15 @@ public class GuiManager {
|
|||||||
((AnvilGui) gui).open();
|
((AnvilGui) gui).open();
|
||||||
gui.onOpen(this, player);
|
gui.onOpen(this, player);
|
||||||
|
|
||||||
synchronized (lock) {
|
synchronized (this.lock) {
|
||||||
openInventories.put(player, gui);
|
this.openInventories.put(player, gui);
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
|
Bukkit.getScheduler().runTaskAsynchronously(this.plugin, () -> {
|
||||||
Gui openInv = openInventories.get(player);
|
Gui openInv = this.openInventories.get(player);
|
||||||
|
|
||||||
if (openInv != null) {
|
if (openInv != null) {
|
||||||
openInv.open = false;
|
openInv.open = false;
|
||||||
@ -111,32 +111,32 @@ public class GuiManager {
|
|||||||
|
|
||||||
Inventory inv = gui.getOrCreateInventory(this);
|
Inventory inv = gui.getOrCreateInventory(this);
|
||||||
|
|
||||||
Bukkit.getScheduler().runTask(plugin, () -> {
|
Bukkit.getScheduler().runTask(this.plugin, () -> {
|
||||||
player.openInventory(inv);
|
player.openInventory(inv);
|
||||||
gui.onOpen(this, player);
|
gui.onOpen(this, player);
|
||||||
|
|
||||||
synchronized (lock) {
|
synchronized (this.lock) {
|
||||||
openInventories.put(player, gui);
|
this.openInventories.put(player, gui);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public void showPopup(Player player, String message) {
|
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);
|
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)) {
|
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.add();
|
||||||
popup.grant(player);
|
popup.grant(player);
|
||||||
|
|
||||||
Bukkit.getScheduler().runTaskLaterAsynchronously(plugin, () -> {
|
Bukkit.getScheduler().runTaskLaterAsynchronously(this.plugin, () -> {
|
||||||
popup.revoke(player);
|
popup.revoke(player);
|
||||||
popup.remove();
|
popup.remove();
|
||||||
}, 70);
|
}, 70);
|
||||||
@ -156,13 +156,13 @@ public class GuiManager {
|
|||||||
* Close all active GUIs
|
* Close all active GUIs
|
||||||
*/
|
*/
|
||||||
public void closeAll() {
|
public void closeAll() {
|
||||||
synchronized (lock) {
|
synchronized (this.lock) {
|
||||||
openInventories.entrySet().stream()
|
this.openInventories.entrySet().stream()
|
||||||
.filter(e -> e.getKey().getOpenInventory().getTopInventory().getHolder() instanceof GuiHolder)
|
.filter(e -> e.getKey().getOpenInventory().getTopInventory().getHolder() instanceof GuiHolder)
|
||||||
.collect(Collectors.toList()) // to prevent concurrency exceptions
|
.collect(Collectors.toList()) // to prevent concurrency exceptions
|
||||||
.forEach(e -> e.getKey().closeInventory());
|
.forEach(e -> e.getKey().closeInventory());
|
||||||
|
|
||||||
openInventories.clear();
|
this.openInventories.clear();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -182,7 +182,7 @@ public class GuiManager {
|
|||||||
Inventory openInv = event.getInventory();
|
Inventory openInv = event.getInventory();
|
||||||
Gui gui;
|
Gui gui;
|
||||||
if (openInv.getHolder() != null && openInv.getHolder() instanceof GuiHolder
|
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();
|
gui = ((GuiHolder) openInv.getHolder()).getGUI();
|
||||||
|
|
||||||
if (event.getRawSlots().stream()
|
if (event.getRawSlots().stream()
|
||||||
@ -205,7 +205,7 @@ public class GuiManager {
|
|||||||
|
|
||||||
Gui gui;
|
Gui gui;
|
||||||
if (openInv.getHolder() != null && openInv.getHolder() instanceof GuiHolder &&
|
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();
|
gui = ((GuiHolder) openInv.getHolder()).getGUI();
|
||||||
|
|
||||||
if (event.getClick() == ClickType.DOUBLE_CLICK) {
|
if (event.getClick() == ClickType.DOUBLE_CLICK) {
|
||||||
@ -228,7 +228,7 @@ public class GuiManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (event.getSlotType() == SlotType.OUTSIDE) {
|
if (event.getSlotType() == SlotType.OUTSIDE) {
|
||||||
if (!gui.onClickOutside(manager, player, event)) {
|
if (!gui.onClickOutside(this.manager, player, event)) {
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
}
|
}
|
||||||
} // did we click the gui or in the user's inventory?
|
} // 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()));
|
event.setCancelled(gui.unlockedCells.entrySet().stream().noneMatch(e -> event.getSlot() == e.getKey() && e.getValue()));
|
||||||
|
|
||||||
// process button press
|
// process button press
|
||||||
if (gui.onClick(manager, player, openInv, event)) {
|
if (gui.onClick(this.manager, player, openInv, event)) {
|
||||||
player.playSound(player.getLocation(), gui.getDefaultSound().getSound(), 1F, 1F);
|
gui.getDefaultSound().play(player);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Player clicked in the bottom inventory while GUI is open
|
// Player clicked in the bottom inventory while GUI is open
|
||||||
if (gui.onClickPlayerInventory(manager, player, openInv, event)) {
|
if (gui.onClickPlayerInventory(this.manager, player, openInv, event)) {
|
||||||
player.playSound(player.getLocation(), gui.getDefaultSound().getSound(), 1F, 1F);
|
gui.getDefaultSound().play(player);
|
||||||
} else if (!gui.acceptsItems || event.getAction() == InventoryAction.MOVE_TO_OTHER_INVENTORY) {
|
} else if (!gui.acceptsItems || event.getAction() == InventoryAction.MOVE_TO_OTHER_INVENTORY) {
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
|
|
||||||
@ -260,7 +260,7 @@ public class GuiManager {
|
|||||||
Inventory openInv = event.getInventory();
|
Inventory openInv = event.getInventory();
|
||||||
|
|
||||||
if (openInv.getHolder() != null && openInv.getHolder() instanceof GuiHolder &&
|
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();
|
Gui gui = ((GuiHolder) openInv.getHolder()).getGUI();
|
||||||
|
|
||||||
if (gui instanceof AnvilGui) {
|
if (gui instanceof AnvilGui) {
|
||||||
@ -277,23 +277,23 @@ public class GuiManager {
|
|||||||
player.setItemOnCursor(null);
|
player.setItemOnCursor(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (manager.shutdown) {
|
if (this.manager.shutdown) {
|
||||||
gui.onClose(manager, player);
|
gui.onClose(this.manager, player);
|
||||||
} else {
|
} 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
|
@EventHandler
|
||||||
void onDisable(PluginDisableEvent event) {
|
void onDisable(PluginDisableEvent event) {
|
||||||
if (event.getPlugin() == manager.plugin) {
|
if (event.getPlugin() == this.manager.plugin) {
|
||||||
// uh-oh! Abandon ship!!
|
// uh-oh! Abandon ship!!
|
||||||
manager.shutdown = true;
|
this.manager.shutdown = true;
|
||||||
manager.closeAll();
|
this.manager.closeAll();
|
||||||
manager.initialized = false;
|
this.manager.initialized = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package com.craftaro.core.gui;
|
package com.craftaro.core.gui;
|
||||||
|
|
||||||
import com.craftaro.core.compatibility.CompatibleMaterial;
|
import com.craftaro.core.compatibility.CompatibleMaterial;
|
||||||
|
import com.cryptomorin.xseries.XMaterial;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.bukkit.inventory.meta.ItemMeta;
|
import org.bukkit.inventory.meta.ItemMeta;
|
||||||
@ -12,7 +13,7 @@ import java.util.List;
|
|||||||
|
|
||||||
public class GuiUtils {
|
public class GuiUtils {
|
||||||
public static ItemStack getBorderGlassItem() {
|
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();
|
ItemMeta glassmeta = glass.getItemMeta();
|
||||||
|
|
||||||
glassmeta.setDisplayName(ChatColor.BLACK.toString());
|
glassmeta.setDisplayName(ChatColor.BLACK.toString());
|
||||||
@ -30,8 +31,8 @@ public class GuiUtils {
|
|||||||
return item;
|
return item;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ItemStack getBorderItem(CompatibleMaterial mat) {
|
public static ItemStack getBorderItem(XMaterial mat) {
|
||||||
ItemStack item = mat.getItem();
|
ItemStack item = mat.parseItem();
|
||||||
ItemMeta glassmeta = item.getItemMeta();
|
ItemMeta glassmeta = item.getItemMeta();
|
||||||
|
|
||||||
glassmeta.setDisplayName(ChatColor.BLACK.toString());
|
glassmeta.setDisplayName(ChatColor.BLACK.toString());
|
||||||
@ -98,8 +99,8 @@ public class GuiUtils {
|
|||||||
return newLore;
|
return newLore;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ItemStack createButtonItem(CompatibleMaterial mat, String title, String... lore) {
|
public static ItemStack createButtonItem(XMaterial mat, String title, String... lore) {
|
||||||
ItemStack item = mat.getItem();
|
ItemStack item = mat.parseItem();
|
||||||
ItemMeta meta = item.getItemMeta();
|
ItemMeta meta = item.getItemMeta();
|
||||||
|
|
||||||
if (meta != null) {
|
if (meta != null) {
|
||||||
@ -117,8 +118,8 @@ public class GuiUtils {
|
|||||||
return item;
|
return item;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ItemStack createButtonItem(CompatibleMaterial mat, int amount, String title, String... lore) {
|
public static ItemStack createButtonItem(XMaterial mat, int amount, String title, String... lore) {
|
||||||
ItemStack item = mat.getItem();
|
ItemStack item = mat.parseItem();
|
||||||
item.setAmount(amount);
|
item.setAmount(amount);
|
||||||
|
|
||||||
ItemMeta meta = item.getItemMeta();
|
ItemMeta meta = item.getItemMeta();
|
||||||
@ -157,8 +158,8 @@ public class GuiUtils {
|
|||||||
return item;
|
return item;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ItemStack createButtonItem(CompatibleMaterial mat, String title, List<String> lore) {
|
public static ItemStack createButtonItem(XMaterial mat, String title, List<String> lore) {
|
||||||
ItemStack item = mat.getItem();
|
ItemStack item = mat.parseItem();
|
||||||
ItemMeta meta = item.getItemMeta();
|
ItemMeta meta = item.getItemMeta();
|
||||||
|
|
||||||
if (meta != null) {
|
if (meta != null) {
|
||||||
@ -176,8 +177,8 @@ public class GuiUtils {
|
|||||||
return item;
|
return item;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ItemStack createButtonItem(CompatibleMaterial mat, int amount, String title, List<String> lore) {
|
public static ItemStack createButtonItem(XMaterial mat, int amount, String title, List<String> lore) {
|
||||||
ItemStack item = mat.getItem();
|
ItemStack item = mat.parseItem();
|
||||||
item.setAmount(amount);
|
item.setAmount(amount);
|
||||||
|
|
||||||
ItemMeta meta = item.getItemMeta();
|
ItemMeta meta = item.getItemMeta();
|
||||||
@ -216,8 +217,8 @@ public class GuiUtils {
|
|||||||
return item;
|
return item;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ItemStack createButtonItem(CompatibleMaterial mat, String[] lore) {
|
public static ItemStack createButtonItem(XMaterial mat, String[] lore) {
|
||||||
ItemStack item = mat.getItem();
|
ItemStack item = mat.parseItem();
|
||||||
ItemMeta meta = item.getItemMeta();
|
ItemMeta meta = item.getItemMeta();
|
||||||
|
|
||||||
if (meta != null) {
|
if (meta != null) {
|
||||||
@ -236,8 +237,8 @@ public class GuiUtils {
|
|||||||
return item;
|
return item;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ItemStack createButtonItem(CompatibleMaterial mat, int amount, String[] lore) {
|
public static ItemStack createButtonItem(XMaterial mat, int amount, String[] lore) {
|
||||||
ItemStack item = mat.getItem();
|
ItemStack item = mat.parseItem();
|
||||||
item.setAmount(amount);
|
item.setAmount(amount);
|
||||||
|
|
||||||
ItemMeta meta = item.getItemMeta();
|
ItemMeta meta = item.getItemMeta();
|
||||||
@ -278,8 +279,8 @@ public class GuiUtils {
|
|||||||
return item;
|
return item;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ItemStack createButtonItem(CompatibleMaterial mat, List<String> lore) {
|
public static ItemStack createButtonItem(XMaterial mat, List<String> lore) {
|
||||||
ItemStack item = mat.getItem();
|
ItemStack item = mat.parseItem();
|
||||||
ItemMeta meta = item.getItemMeta();
|
ItemMeta meta = item.getItemMeta();
|
||||||
|
|
||||||
if (meta != null) {
|
if (meta != null) {
|
||||||
@ -298,8 +299,8 @@ public class GuiUtils {
|
|||||||
return item;
|
return item;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ItemStack createButtonItem(CompatibleMaterial mat, int amount, List<String> lore) {
|
public static ItemStack createButtonItem(XMaterial mat, int amount, List<String> lore) {
|
||||||
ItemStack item = mat.getItem();
|
ItemStack item = mat.parseItem();
|
||||||
item.setAmount(amount);
|
item.setAmount(amount);
|
||||||
ItemMeta meta = item.getItemMeta();
|
ItemMeta meta = item.getItemMeta();
|
||||||
|
|
||||||
@ -400,9 +401,9 @@ public class GuiUtils {
|
|||||||
return item;
|
return item;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ItemStack updateItem(ItemStack item, CompatibleMaterial matTo, String title, String... lore) {
|
public static ItemStack updateItem(ItemStack item, XMaterial matTo, String title, String... lore) {
|
||||||
if (!matTo.matches(item)) {
|
if (!matTo.isSimilar(item)) {
|
||||||
item = matTo.getItem();
|
item = matTo.parseItem();
|
||||||
}
|
}
|
||||||
|
|
||||||
ItemMeta meta = item.getItemMeta();
|
ItemMeta meta = item.getItemMeta();
|
||||||
@ -423,7 +424,7 @@ public class GuiUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static ItemStack updateItem(ItemStack item, ItemStack to, String title, String... lore) {
|
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();
|
item = to.clone();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -462,9 +463,9 @@ public class GuiUtils {
|
|||||||
return item;
|
return item;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ItemStack updateItem(ItemStack item, CompatibleMaterial matTo, String title, List<String> lore) {
|
public static ItemStack updateItem(ItemStack item, XMaterial matTo, String title, List<String> lore) {
|
||||||
if (!matTo.matches(item)) {
|
if (!matTo.isSimilar(item)) {
|
||||||
item = matTo.getItem();
|
item = matTo.parseItem();
|
||||||
}
|
}
|
||||||
|
|
||||||
ItemMeta meta = item.getItemMeta();
|
ItemMeta meta = item.getItemMeta();
|
||||||
@ -485,7 +486,7 @@ public class GuiUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static ItemStack updateItem(ItemStack item, ItemStack to, String title, List<String> lore) {
|
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();
|
item = to.clone();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
package com.craftaro.core.gui;
|
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.Gson;
|
||||||
import com.google.gson.GsonBuilder;
|
import com.google.gson.GsonBuilder;
|
||||||
import com.google.gson.JsonElement;
|
import com.google.gson.JsonElement;
|
||||||
import com.google.gson.JsonObject;
|
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.api.chat.TextComponent;
|
||||||
import net.md_5.bungee.chat.ComponentSerializer;
|
import net.md_5.bungee.chat.ComponentSerializer;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
@ -30,19 +30,19 @@ class PopupMessage {
|
|||||||
final UUID id = UUID.randomUUID();
|
final UUID id = UUID.randomUUID();
|
||||||
private final NamespacedKey key;
|
private final NamespacedKey key;
|
||||||
private final TextComponent title;
|
private final TextComponent title;
|
||||||
CompatibleMaterial icon;
|
XMaterial icon;
|
||||||
TriggerType trigger = TriggerType.IMPOSSIBLE;
|
TriggerType trigger = TriggerType.IMPOSSIBLE;
|
||||||
FrameType frame = FrameType.GOAL; // TASK is the default
|
FrameType frame = FrameType.GOAL; // TASK is the default
|
||||||
BackgroundType background = BackgroundType.ADVENTURE;
|
BackgroundType background = BackgroundType.ADVENTURE;
|
||||||
|
|
||||||
PopupMessage(Plugin source, CompatibleMaterial icon, String title) {
|
PopupMessage(Plugin source, XMaterial icon, String title) {
|
||||||
this.key = new NamespacedKey(source, "popup/" + id);
|
this.key = new NamespacedKey(source, "popup/" + this.id);
|
||||||
this.title = new TextComponent(title.length() < 74 ? title : (title.substring(0, 72) + "..."));
|
this.title = new TextComponent(title.length() < 74 ? title : (title.substring(0, 72) + "..."));
|
||||||
this.icon = icon;
|
this.icon = icon;
|
||||||
}
|
}
|
||||||
|
|
||||||
PopupMessage(Plugin source, CompatibleMaterial icon, String title, BackgroundType background) {
|
PopupMessage(Plugin source, XMaterial icon, String title, BackgroundType background) {
|
||||||
this.key = new NamespacedKey(source, "popup/" + id);
|
this.key = new NamespacedKey(source, "popup/" + this.id);
|
||||||
this.title = new TextComponent(title.length() < 74 ? title : (title.substring(0, 72) + "..."));
|
this.title = new TextComponent(title.length() < 74 ? title : (title.substring(0, 72) + "..."));
|
||||||
this.icon = icon;
|
this.icon = icon;
|
||||||
this.background = background;
|
this.background = background;
|
||||||
@ -54,9 +54,9 @@ class PopupMessage {
|
|||||||
|
|
||||||
if (this.icon != null) {
|
if (this.icon != null) {
|
||||||
JsonObject displayIcon = new JsonObject();
|
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());
|
displayIcon.addProperty("data", this.icon.getData());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -64,7 +64,7 @@ class PopupMessage {
|
|||||||
}
|
}
|
||||||
|
|
||||||
advDisplay.add("title", gson.fromJson(ComponentSerializer.toString(this.title), JsonElement.class));
|
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("description", "");
|
||||||
advDisplay.addProperty("frame", this.frame.id);
|
advDisplay.addProperty("frame", this.frame.id);
|
||||||
advDisplay.addProperty("announce_to_chat", false);
|
advDisplay.addProperty("announce_to_chat", false);
|
||||||
@ -110,11 +110,11 @@ class PopupMessage {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected void add() {
|
protected void add() {
|
||||||
if (!registeredMessages.contains(id)) {
|
if (!registeredMessages.contains(this.id)) {
|
||||||
registeredMessages.add(id);
|
registeredMessages.add(this.id);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Bukkit.getUnsafe().loadAdvancement(key, getJSON());
|
Bukkit.getUnsafe().loadAdvancement(this.key, getJSON());
|
||||||
} catch (IllegalArgumentException ex) {
|
} catch (IllegalArgumentException ex) {
|
||||||
Bukkit.getLogger().warning("Failed to create popup advancement!");
|
Bukkit.getLogger().warning("Failed to create popup advancement!");
|
||||||
}
|
}
|
||||||
@ -122,14 +122,14 @@ class PopupMessage {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected void remove() {
|
protected void remove() {
|
||||||
if (registeredMessages.contains(id)) {
|
if (registeredMessages.contains(this.id)) {
|
||||||
registeredMessages.remove(id);
|
registeredMessages.remove(this.id);
|
||||||
Bukkit.getUnsafe().removeAdvancement(key);
|
Bukkit.getUnsafe().removeAdvancement(this.key);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Advancement getAdvancement() {
|
public Advancement getAdvancement() {
|
||||||
return Bukkit.getAdvancement(key);
|
return Bukkit.getAdvancement(this.key);
|
||||||
}
|
}
|
||||||
|
|
||||||
public enum FrameType {
|
public enum FrameType {
|
||||||
@ -140,7 +140,7 @@ class PopupMessage {
|
|||||||
final String id;
|
final String id;
|
||||||
|
|
||||||
FrameType() {
|
FrameType() {
|
||||||
id = name().toLowerCase();
|
this.id = name().toLowerCase();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -192,7 +192,7 @@ class PopupMessage {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public String getKey() {
|
public String getKey() {
|
||||||
return key;
|
return this.key;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,7 @@ package com.craftaro.core.gui;
|
|||||||
|
|
||||||
import com.craftaro.core.gui.events.GuiClickEvent;
|
import com.craftaro.core.gui.events.GuiClickEvent;
|
||||||
import com.craftaro.core.gui.methods.Clickable;
|
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.Bukkit;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.inventory.ClickType;
|
import org.bukkit.event.inventory.ClickType;
|
||||||
@ -30,8 +30,8 @@ public class SimplePagedGui extends Gui {
|
|||||||
public SimplePagedGui(Gui parent) {
|
public SimplePagedGui(Gui parent) {
|
||||||
super(parent);
|
super(parent);
|
||||||
|
|
||||||
nextPage = GuiUtils.createButtonItem(CompatibleMaterial.ARROW, "Next Page");
|
this.nextPage = GuiUtils.createButtonItem(XMaterial.ARROW, "Next Page");
|
||||||
prevPage = GuiUtils.createButtonItem(CompatibleMaterial.ARROW, "Previous Page");
|
this.prevPage = GuiUtils.createButtonItem(XMaterial.ARROW, "Previous Page");
|
||||||
}
|
}
|
||||||
|
|
||||||
public SimplePagedGui setUseHeader(boolean useHeader) {
|
public SimplePagedGui setUseHeader(boolean useHeader) {
|
||||||
@ -40,7 +40,7 @@ public class SimplePagedGui extends Gui {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public ItemStack getHeaderBackItem() {
|
public ItemStack getHeaderBackItem() {
|
||||||
return headerBackItem;
|
return this.headerBackItem;
|
||||||
}
|
}
|
||||||
|
|
||||||
public SimplePagedGui setHeaderBackItem(ItemStack headerBackItem) {
|
public SimplePagedGui setHeaderBackItem(ItemStack headerBackItem) {
|
||||||
@ -49,7 +49,7 @@ public class SimplePagedGui extends Gui {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public ItemStack getFooterBackItem() {
|
public ItemStack getFooterBackItem() {
|
||||||
return footerBackItem;
|
return this.footerBackItem;
|
||||||
}
|
}
|
||||||
|
|
||||||
public SimplePagedGui setFooterBackItem(ItemStack footerBackItem) {
|
public SimplePagedGui setFooterBackItem(ItemStack footerBackItem) {
|
||||||
@ -65,11 +65,11 @@ public class SimplePagedGui extends Gui {
|
|||||||
@Override
|
@Override
|
||||||
public SimplePagedGui setItem(int cell, ItemStack item) {
|
public SimplePagedGui setItem(int cell, ItemStack item) {
|
||||||
// set the cell relative to the current page
|
// 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);
|
this.cellItems.put(cellIndex, item);
|
||||||
if (open && cell >= 0 && cell < inventory.getSize()) {
|
if (this.open && cell >= 0 && cell < this.inventory.getSize()) {
|
||||||
inventory.setItem(cell, item);
|
this.inventory.setItem(cell, item);
|
||||||
}
|
}
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
@ -77,27 +77,27 @@ public class SimplePagedGui extends Gui {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void nextPage() {
|
public void nextPage() {
|
||||||
if (page < pages) {
|
if (this.page < this.pages) {
|
||||||
++page;
|
++this.page;
|
||||||
showPage();
|
showPage();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void prevPage() {
|
public void prevPage() {
|
||||||
if (page > 1) {
|
if (this.page > 1) {
|
||||||
--page;
|
--this.page;
|
||||||
showPage();
|
showPage();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void showPage() {
|
public void showPage() {
|
||||||
int startCell = useHeader ? 9 : 0;
|
int startCell = this.useHeader ? 9 : 0;
|
||||||
int cellIndex = startCell + (page - 1) * (rowsPerPage * 9);
|
int cellIndex = startCell + (this.page - 1) * (this.rowsPerPage * 9);
|
||||||
|
|
||||||
for (int i = startCell; i < (rows - 1) * 9; ++i) {
|
for (int i = startCell; i < (this.rows - 1) * 9; ++i) {
|
||||||
final ItemStack item = cellItems.get(cellIndex++);
|
final ItemStack item = this.cellItems.get(cellIndex++);
|
||||||
inventory.setItem(i, item != null ? item : blankItem);
|
this.inventory.setItem(i, item != null ? item : this.blankItem);
|
||||||
}
|
}
|
||||||
|
|
||||||
// page markers
|
// page markers
|
||||||
@ -106,26 +106,26 @@ public class SimplePagedGui extends Gui {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void updatePageNavigation() {
|
protected void updatePageNavigation() {
|
||||||
if (page > 1) {
|
if (this.page > 1) {
|
||||||
inventory.setItem(inventory.getSize() - prevPageIndex, prevPage);
|
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 {
|
} 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.setItem(-this.prevPageIndex, null);
|
||||||
this.clearActions(-prevPageIndex);
|
this.clearActions(-this.prevPageIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pages > 1 && page != pages) {
|
if (this.pages > 1 && this.page != this.pages) {
|
||||||
inventory.setItem(inventory.getSize() - nextPageIndex, nextPage);
|
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 {
|
} 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.setItem(-this.nextPageIndex, null);
|
||||||
this.clearActions(-nextPageIndex);
|
this.clearActions(-this.nextPageIndex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -134,65 +134,65 @@ public class SimplePagedGui extends Gui {
|
|||||||
this.guiManager = manager;
|
this.guiManager = manager;
|
||||||
|
|
||||||
// calculate pages here
|
// calculate pages here
|
||||||
rowsPerPage = useHeader ? 4 : 5;
|
this.rowsPerPage = this.useHeader ? 4 : 5;
|
||||||
maxCellSlot = this.cellItems.keySet().stream().max(Integer::compare).orElse(0) + 1;
|
this.maxCellSlot = this.cellItems.keySet().stream().max(Integer::compare).orElse(0) + 1;
|
||||||
int maxRows = (int) Math.ceil(maxCellSlot / 9.);
|
int maxRows = (int) Math.ceil(this.maxCellSlot / 9.);
|
||||||
pages = (int) Math.max(1, Math.ceil(maxRows / (double) rowsPerPage));
|
this.pages = (int) Math.max(1, Math.ceil(maxRows / (double) this.rowsPerPage));
|
||||||
this.setRows(maxRows + (useHeader ? 1 : 0));
|
this.setRows(maxRows + (this.useHeader ? 1 : 0));
|
||||||
|
|
||||||
// create inventory view
|
// create inventory view
|
||||||
createInventory();
|
createInventory();
|
||||||
|
|
||||||
// populate and return the display inventory
|
// populate and return the display inventory
|
||||||
setPage(Math.min(page, pages));
|
setPage(Math.min(this.page, this.pages));
|
||||||
update();
|
update();
|
||||||
|
|
||||||
return inventory;
|
return this.inventory;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void createInventory() {
|
protected void createInventory() {
|
||||||
final int cells = rows * 9;
|
final int cells = this.rows * 9;
|
||||||
|
|
||||||
inventory = Bukkit.getServer().createInventory(new GuiHolder(guiManager, this), cells,
|
this.inventory = Bukkit.getServer().createInventory(new GuiHolder(this.guiManager, this), cells,
|
||||||
title == null ? "" : trimTitle(title));
|
this.title == null ? "" : trimTitle(this.title));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void update() {
|
public void update() {
|
||||||
if (inventory == null) {
|
if (this.inventory == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// calculate pages here
|
// calculate pages here
|
||||||
rowsPerPage = useHeader ? 4 : 5;
|
this.rowsPerPage = this.useHeader ? 4 : 5;
|
||||||
maxCellSlot = (this.cellItems.isEmpty() ? 0 : this.cellItems.keySet().stream().max(Integer::compare).get()) + 1;
|
this.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.));
|
int maxRows = Math.max((this.useHeader ? 1 : 0), (int) Math.ceil(this.maxCellSlot / 9.));
|
||||||
pages = (int) Math.ceil(maxRows / rowsPerPage);
|
this.pages = (int) Math.ceil(maxRows / this.rowsPerPage);
|
||||||
|
|
||||||
// create a new inventory if needed
|
// create a new inventory if needed
|
||||||
List<Player> toUpdate = null;
|
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();
|
toUpdate = getPlayers();
|
||||||
|
|
||||||
this.setRows(maxRows + (useHeader ? 1 : 0));
|
this.setRows(maxRows + (this.useHeader ? 1 : 0));
|
||||||
|
|
||||||
createInventory();
|
createInventory();
|
||||||
}
|
}
|
||||||
|
|
||||||
// populate header
|
// populate header
|
||||||
if (useHeader) {
|
if (this.useHeader) {
|
||||||
for (int i = 0; i < 9; ++i) {
|
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
|
// 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) {
|
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
|
// fill out the rest of the page
|
||||||
@ -202,7 +202,7 @@ public class SimplePagedGui extends Gui {
|
|||||||
if (toUpdate != null) {
|
if (toUpdate != null) {
|
||||||
// whoopsie!
|
// whoopsie!
|
||||||
exit();
|
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();
|
int cell = event.getSlot();
|
||||||
Map<ClickType, Clickable> conditionals;
|
Map<ClickType, Clickable> conditionals;
|
||||||
|
|
||||||
if (useHeader && cell < 9) {
|
if (this.useHeader && cell < 9) {
|
||||||
conditionals = conditionalButtons.get(cell);
|
conditionals = this.conditionalButtons.get(cell);
|
||||||
} else if (cell >= (rows - 1) * 9) {
|
} else if (cell >= (this.rows - 1) * 9) {
|
||||||
// footer row
|
// footer row
|
||||||
conditionals = conditionalButtons.get(cell - (rows * 9));
|
conditionals = this.conditionalButtons.get(cell - (this.rows * 9));
|
||||||
} else {
|
} else {
|
||||||
int cellIndex = page == 1 ? cell : cell + (page - 1) * rowsPerPage * 9;
|
int cellIndex = this.page == 1 ? cell : cell + (this.page - 1) * this.rowsPerPage * 9;
|
||||||
conditionals = conditionalButtons.get(cellIndex);
|
conditionals = this.conditionalButtons.get(cellIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
Clickable button;
|
Clickable button;
|
||||||
|
@ -47,7 +47,7 @@ public class DecentHologramsHolograms extends Holograms {
|
|||||||
DecentHologramsAPI.get().getHologramManager().removeHologram(id);
|
DecentHologramsAPI.get().getHologramManager().removeHologram(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
ourHolograms.remove(id);
|
this.ourHolograms.remove(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -68,7 +68,7 @@ public class DecentHologramsHolograms extends Holograms {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void removeAllHolograms() {
|
public void removeAllHolograms() {
|
||||||
for (String id : ourHolograms) {
|
for (String id : this.ourHolograms) {
|
||||||
Hologram hologram = DHAPI.getHologram(id);
|
Hologram hologram = DHAPI.getHologram(id);
|
||||||
|
|
||||||
if (hologram != null) {
|
if (hologram != null) {
|
||||||
@ -77,7 +77,7 @@ public class DecentHologramsHolograms extends Holograms {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ourHolograms.clear();
|
this.ourHolograms.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -93,6 +93,6 @@ public class DecentHologramsHolograms extends Holograms {
|
|||||||
}
|
}
|
||||||
|
|
||||||
DHAPI.createHologram(id, location, lines);
|
DHAPI.createHologram(id, location, lines);
|
||||||
ourHolograms.add(id);
|
this.ourHolograms.add(id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,7 @@ public class HologramsHolograms extends Holograms {
|
|||||||
public HologramsHolograms(Plugin plugin) {
|
public HologramsHolograms(Plugin plugin) {
|
||||||
super(plugin);
|
super(plugin);
|
||||||
|
|
||||||
hologramPlugin = (HologramPlugin) Bukkit.getPluginManager().getPlugin("Holograms");
|
this.hologramPlugin = (HologramPlugin) Bukkit.getPluginManager().getPlugin("Holograms");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -30,7 +30,7 @@ public class HologramsHolograms extends Holograms {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isEnabled() {
|
public boolean isEnabled() {
|
||||||
return hologramPlugin.isEnabled();
|
return this.hologramPlugin.isEnabled();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -45,38 +45,38 @@ public class HologramsHolograms extends Holograms {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void removeHologram(String id) {
|
public void removeHologram(String id) {
|
||||||
Hologram hologram = hologramPlugin.getHologramManager().getHologram(id);
|
Hologram hologram = this.hologramPlugin.getHologramManager().getHologram(id);
|
||||||
|
|
||||||
if (hologram != null) {
|
if (hologram != null) {
|
||||||
hologram.despawn();
|
hologram.despawn();
|
||||||
hologramPlugin.getHologramManager().removeActiveHologram(hologram);
|
this.hologramPlugin.getHologramManager().removeActiveHologram(hologram);
|
||||||
}
|
}
|
||||||
|
|
||||||
ourHolograms.remove(id);
|
this.ourHolograms.remove(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void removeAllHolograms() {
|
public void removeAllHolograms() {
|
||||||
for (String id : ourHolograms) {
|
for (String id : this.ourHolograms) {
|
||||||
Hologram hologram = hologramPlugin.getHologramManager().getHologram(id);
|
Hologram hologram = this.hologramPlugin.getHologramManager().getHologram(id);
|
||||||
|
|
||||||
if (hologram != null) {
|
if (hologram != null) {
|
||||||
hologram.despawn();
|
hologram.despawn();
|
||||||
hologramPlugin.getHologramManager().removeActiveHologram(hologram);
|
this.hologramPlugin.getHologramManager().removeActiveHologram(hologram);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ourHolograms.clear();
|
this.ourHolograms.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isHologramLoaded(String id) {
|
public boolean isHologramLoaded(String id) {
|
||||||
return hologramPlugin.getHologramManager().getHologram(id) != null;
|
return this.hologramPlugin.getHologramManager().getHologram(id) != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateHologram(String id, List<String> lines) {
|
public void updateHologram(String id, List<String> lines) {
|
||||||
Hologram hologram = hologramPlugin.getHologramManager().getHologram(id);
|
Hologram hologram = this.hologramPlugin.getHologramManager().getHologram(id);
|
||||||
|
|
||||||
if (hologram != null) {
|
if (hologram != null) {
|
||||||
hologram.spawn();
|
hologram.spawn();
|
||||||
@ -118,8 +118,8 @@ public class HologramsHolograms extends Holograms {
|
|||||||
hologram.addLine(new TextLine(hologram, line));
|
hologram.addLine(new TextLine(hologram, line));
|
||||||
}
|
}
|
||||||
|
|
||||||
hologramPlugin.getHologramManager().addActiveHologram(hologram);
|
this.hologramPlugin.getHologramManager().addActiveHologram(hologram);
|
||||||
|
|
||||||
ourHolograms.add(id);
|
this.ourHolograms.add(id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -45,7 +45,7 @@ public class HolographicDisplaysHolograms extends Holograms {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void removeHologram(String id) {
|
public void removeHologram(String id) {
|
||||||
Hologram hologram = holograms.remove(id);
|
Hologram hologram = this.holograms.remove(id);
|
||||||
if (hologram != null) {
|
if (hologram != null) {
|
||||||
hologram.delete();
|
hologram.delete();
|
||||||
}
|
}
|
||||||
@ -62,7 +62,7 @@ public class HolographicDisplaysHolograms extends Holograms {
|
|||||||
String id = entry.getKey();
|
String id = entry.getKey();
|
||||||
List<String> lines = entry.getValue();
|
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
|
// only update if there is a change to the text
|
||||||
boolean isChanged = lines.size() != hologram.size();
|
boolean isChanged = lines.size() != hologram.size();
|
||||||
@ -70,7 +70,7 @@ public class HolographicDisplaysHolograms extends Holograms {
|
|||||||
if (!isChanged) {
|
if (!isChanged) {
|
||||||
// double-check the lines
|
// double-check the lines
|
||||||
for (int i = 0; !isChanged && i < lines.size(); ++i) {
|
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) {
|
private void createAt(String id, Location location, List<String> lines) {
|
||||||
if (holograms.containsKey(id)) {
|
if (this.holograms.containsKey(id)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
location = fixLocation(location);
|
location = fixLocation(location);
|
||||||
Hologram hologram = HologramsAPI.createHologram(plugin, location);
|
Hologram hologram = HologramsAPI.createHologram(this.plugin, location);
|
||||||
|
|
||||||
for (String line : lines) {
|
for (String line : lines) {
|
||||||
hologram.appendTextLine(line);
|
hologram.appendTextLine(line);
|
||||||
}
|
}
|
||||||
|
|
||||||
holograms.put(id, hologram);
|
this.holograms.put(id, hologram);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void removeAllHolograms() {
|
public void removeAllHolograms() {
|
||||||
holograms.values().forEach(Hologram::delete);
|
this.holograms.values().forEach(Hologram::delete);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isHologramLoaded(String id) {
|
public boolean isHologramLoaded(String id) {
|
||||||
return holograms.get(id) != null;
|
return this.holograms.get(id) != null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
package com.craftaro.core.http;
|
package com.craftaro.core.http;
|
||||||
|
|
||||||
import com.craftaro.core.SongodaCoreConstants;
|
import com.craftaro.core.CraftaroCoreConstants;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@ -36,9 +36,9 @@ public class SimpleHttpClient implements HttpClient {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static String generateUserAgent() {
|
private static String generateUserAgent() {
|
||||||
String projectName = SongodaCoreConstants.getProjectName();
|
String projectName = CraftaroCoreConstants.getProjectName();
|
||||||
String version = SongodaCoreConstants.getCoreVersion();
|
String version = CraftaroCoreConstants.getCoreVersion();
|
||||||
String projectUrl = SongodaCoreConstants.getGitHubProjectUrl();
|
String projectUrl = CraftaroCoreConstants.getGitHubProjectUrl();
|
||||||
|
|
||||||
return projectName + "/" + version + " (+" + projectUrl + ")";
|
return projectName + "/" + version + " (+" + projectUrl + ")";
|
||||||
}
|
}
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
package com.craftaro.core.lootables.gui;
|
package com.craftaro.core.lootables.gui;
|
||||||
|
|
||||||
import com.craftaro.core.compatibility.CompatibleMaterial;
|
|
||||||
import com.craftaro.core.gui.AnvilGui;
|
import com.craftaro.core.gui.AnvilGui;
|
||||||
import com.craftaro.core.gui.Gui;
|
import com.craftaro.core.gui.Gui;
|
||||||
import com.craftaro.core.gui.GuiUtils;
|
import com.craftaro.core.gui.GuiUtils;
|
||||||
import com.craftaro.core.lootables.loot.Loot;
|
import com.craftaro.core.lootables.loot.Loot;
|
||||||
import com.craftaro.core.utils.TextUtils;
|
import com.craftaro.core.utils.TextUtils;
|
||||||
|
import com.cryptomorin.xseries.XMaterial;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
@ -28,19 +28,19 @@ public abstract class AbstractGuiListEditor extends Gui {
|
|||||||
public void paint() {
|
public void paint() {
|
||||||
List<String> lore = getData() == null ? new ArrayList<>() : getData();
|
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")),
|
TextUtils.formatText("&cBack")),
|
||||||
(event) -> {
|
(event) -> {
|
||||||
guiManager.showGUI(event.player, returnGui);
|
guiManager.showGUI(event.player, returnGui);
|
||||||
((GuiLootEditor) returnGui).paint();
|
((GuiLootEditor) returnGui).paint();
|
||||||
});
|
});
|
||||||
setButton(6, GuiUtils.createButtonItem(CompatibleMaterial.OAK_FENCE_GATE,
|
setButton(6, GuiUtils.createButtonItem(XMaterial.OAK_FENCE_GATE,
|
||||||
TextUtils.formatText("&cBack")),
|
TextUtils.formatText("&cBack")),
|
||||||
(event) -> {
|
(event) -> {
|
||||||
guiManager.showGUI(event.player, returnGui);
|
guiManager.showGUI(event.player, returnGui);
|
||||||
((GuiLootEditor) returnGui).paint();
|
((GuiLootEditor) returnGui).paint();
|
||||||
});
|
});
|
||||||
setButton(3, GuiUtils.createButtonItem(CompatibleMaterial.ARROW,
|
setButton(3, GuiUtils.createButtonItem(XMaterial.ARROW,
|
||||||
TextUtils.formatText("&aAdd new line")),
|
TextUtils.formatText("&aAdd new line")),
|
||||||
(event -> {
|
(event -> {
|
||||||
AnvilGui gui = new AnvilGui(event.player, this);
|
AnvilGui gui = new AnvilGui(event.player, this);
|
||||||
@ -57,13 +57,13 @@ public abstract class AbstractGuiListEditor extends Gui {
|
|||||||
guiManager.showGUI(event.player, gui);
|
guiManager.showGUI(event.player, gui);
|
||||||
}));
|
}));
|
||||||
|
|
||||||
setItem(4, GuiUtils.createButtonItem(CompatibleMaterial.WRITABLE_BOOK,
|
setItem(4, GuiUtils.createButtonItem(XMaterial.WRITABLE_BOOK,
|
||||||
TextUtils.formatText("&9Lore:"),
|
TextUtils.formatText("&9Lore:"),
|
||||||
lore.isEmpty()
|
lore.isEmpty()
|
||||||
? TextUtils.formatText(Collections.singletonList("&cNo lore set..."))
|
? TextUtils.formatText(Collections.singletonList("&cNo lore set..."))
|
||||||
: TextUtils.formatText(lore)));
|
: TextUtils.formatText(lore)));
|
||||||
|
|
||||||
setButton(5, GuiUtils.createButtonItem(CompatibleMaterial.ARROW,
|
setButton(5, GuiUtils.createButtonItem(XMaterial.ARROW,
|
||||||
TextUtils.formatText("&cRemove the last line")),
|
TextUtils.formatText("&cRemove the last line")),
|
||||||
(event -> {
|
(event -> {
|
||||||
lore.remove(lore.size() - 1);
|
lore.remove(lore.size() - 1);
|
||||||
|
@ -5,12 +5,14 @@ import com.craftaro.core.gui.Gui;
|
|||||||
import com.craftaro.core.gui.GuiUtils;
|
import com.craftaro.core.gui.GuiUtils;
|
||||||
import com.craftaro.core.lootables.loot.LootManager;
|
import com.craftaro.core.lootables.loot.LootManager;
|
||||||
import com.craftaro.core.lootables.loot.Lootable;
|
import com.craftaro.core.lootables.loot.Lootable;
|
||||||
|
import com.cryptomorin.xseries.XMaterial;
|
||||||
import org.bukkit.entity.EntityType;
|
import org.bukkit.entity.EntityType;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.bukkit.inventory.meta.ItemMeta;
|
import org.bukkit.inventory.meta.ItemMeta;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
public class GuiEditor extends Gui {
|
public class GuiEditor extends Gui {
|
||||||
private final LootManager lootManager;
|
private final LootManager lootManager;
|
||||||
@ -39,7 +41,7 @@ public class GuiEditor extends Gui {
|
|||||||
this.pages = (int) Math.max(1, Math.ceil(itemCount / 36));
|
this.pages = (int) Math.max(1, Math.ceil(itemCount / 36));
|
||||||
|
|
||||||
if (page != 1) {
|
if (page != 1) {
|
||||||
setButton(5, 2, GuiUtils.createButtonItem(CompatibleMaterial.ARROW, "Back"),
|
setButton(5, 2, GuiUtils.createButtonItem(XMaterial.ARROW, "Back"),
|
||||||
(event) -> {
|
(event) -> {
|
||||||
page--;
|
page--;
|
||||||
paint();
|
paint();
|
||||||
@ -47,7 +49,7 @@ public class GuiEditor extends Gui {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (page != pages) {
|
if (page != pages) {
|
||||||
setButton(5, 6, GuiUtils.createButtonItem(CompatibleMaterial.ARROW, "Next"),
|
setButton(5, 6, GuiUtils.createButtonItem(XMaterial.ARROW, "Next"),
|
||||||
(event) -> {
|
(event) -> {
|
||||||
page++;
|
page++;
|
||||||
paint();
|
paint();
|
||||||
@ -76,15 +78,15 @@ public class GuiEditor extends Gui {
|
|||||||
EntityType type = EntityType.fromName(key);
|
EntityType type = EntityType.fromName(key);
|
||||||
|
|
||||||
if (type != null) {
|
if (type != null) {
|
||||||
CompatibleMaterial material = CompatibleMaterial.getSpawnEgg(type);
|
Optional<XMaterial> material = CompatibleMaterial.getSpawnEgg(type);
|
||||||
|
|
||||||
if (material != null) {
|
if (material.isPresent()) {
|
||||||
stack = material.getItem();
|
stack = material.get().parseItem();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (stack == null) {
|
if (stack == null) {
|
||||||
stack = CompatibleMaterial.GHAST_SPAWN_EGG.getItem();
|
stack = XMaterial.GHAST_SPAWN_EGG.parseItem();
|
||||||
}
|
}
|
||||||
|
|
||||||
ItemMeta meta = stack.getItemMeta();
|
ItemMeta meta = stack.getItemMeta();
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
package com.craftaro.core.lootables.gui;
|
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.AnvilGui;
|
||||||
import com.craftaro.core.gui.Gui;
|
import com.craftaro.core.gui.Gui;
|
||||||
import com.craftaro.core.gui.GuiUtils;
|
import com.craftaro.core.gui.GuiUtils;
|
||||||
|
import com.craftaro.core.lootables.loot.Loot;
|
||||||
import com.craftaro.core.utils.TextUtils;
|
import com.craftaro.core.utils.TextUtils;
|
||||||
|
import com.cryptomorin.xseries.XMaterial;
|
||||||
import org.bukkit.enchantments.Enchantment;
|
import org.bukkit.enchantments.Enchantment;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@ -33,19 +33,19 @@ public class GuiEnchantEditor extends Gui {
|
|||||||
public void paint() {
|
public void paint() {
|
||||||
Map<String, Integer> lore = loot.getEnchants() == null ? new HashMap<>() : new HashMap<>(loot.getEnchants());
|
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")),
|
TextUtils.formatText("&cBack")),
|
||||||
(event) -> {
|
(event) -> {
|
||||||
guiManager.showGUI(event.player, returnGui);
|
guiManager.showGUI(event.player, returnGui);
|
||||||
((GuiLootEditor) returnGui).paint();
|
((GuiLootEditor) returnGui).paint();
|
||||||
});
|
});
|
||||||
setButton(6, GuiUtils.createButtonItem(CompatibleMaterial.OAK_FENCE_GATE,
|
setButton(6, GuiUtils.createButtonItem(XMaterial.OAK_FENCE_GATE,
|
||||||
TextUtils.formatText("&cBack")),
|
TextUtils.formatText("&cBack")),
|
||||||
(event) -> {
|
(event) -> {
|
||||||
guiManager.showGUI(event.player, returnGui);
|
guiManager.showGUI(event.player, returnGui);
|
||||||
((GuiLootEditor) returnGui).paint();
|
((GuiLootEditor) returnGui).paint();
|
||||||
});
|
});
|
||||||
setButton(3, GuiUtils.createButtonItem(CompatibleMaterial.ARROW,
|
setButton(3, GuiUtils.createButtonItem(XMaterial.ARROW,
|
||||||
TextUtils.formatText("&aAdd new line")),
|
TextUtils.formatText("&aAdd new line")),
|
||||||
(event -> {
|
(event -> {
|
||||||
AnvilGui gui = new AnvilGui(event.player, this);
|
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:"),
|
TextUtils.formatText("&7Enchant Override:"),
|
||||||
lore.isEmpty()
|
lore.isEmpty()
|
||||||
? TextUtils.formatText(Collections.singletonList("&cNo enchantments set..."))
|
? TextUtils.formatText(Collections.singletonList("&cNo enchantments set..."))
|
||||||
: TextUtils.formatText(enchantments)));
|
: TextUtils.formatText(enchantments)));
|
||||||
|
|
||||||
String lastFinal = last;
|
String lastFinal = last;
|
||||||
setButton(5, GuiUtils.createButtonItem(CompatibleMaterial.ARROW,
|
setButton(5, GuiUtils.createButtonItem(XMaterial.ARROW,
|
||||||
TextUtils.formatText("&cRemove the last line")),
|
TextUtils.formatText("&cRemove the last line")),
|
||||||
(event -> {
|
(event -> {
|
||||||
lore.remove(lastFinal);
|
lore.remove(lastFinal);
|
||||||
|
@ -1,13 +1,14 @@
|
|||||||
package com.craftaro.core.lootables.gui;
|
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.compatibility.CompatibleMaterial;
|
||||||
import com.craftaro.core.gui.AnvilGui;
|
import com.craftaro.core.gui.AnvilGui;
|
||||||
import com.craftaro.core.gui.Gui;
|
import com.craftaro.core.gui.Gui;
|
||||||
import com.craftaro.core.gui.GuiUtils;
|
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.craftaro.core.utils.TextUtils;
|
||||||
|
import com.cryptomorin.xseries.XMaterial;
|
||||||
import org.bukkit.entity.EntityType;
|
import org.bukkit.entity.EntityType;
|
||||||
import org.bukkit.event.inventory.ClickType;
|
import org.bukkit.event.inventory.ClickType;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
@ -46,10 +47,10 @@ public class GuiLootEditor extends Gui {
|
|||||||
|
|
||||||
setActionForRange(0, 0, 5, 9, null);
|
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));
|
(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
|
TextUtils.formatText("&7Current Material: &6" + (loot.getMaterial() != null
|
||||||
? loot.getMaterial().name() : "None")), TextUtils.formatText(
|
? loot.getMaterial().name() : "None")), TextUtils.formatText(
|
||||||
Arrays.asList("",
|
Arrays.asList("",
|
||||||
@ -57,12 +58,12 @@ public class GuiLootEditor extends Gui {
|
|||||||
"&8the material in your hand.")
|
"&8the material in your hand.")
|
||||||
)), (event) -> {
|
)), (event) -> {
|
||||||
ItemStack stack = event.player.getInventory().getItemInMainHand();
|
ItemStack stack = event.player.getInventory().getItemInMainHand();
|
||||||
loot.setMaterial(CompatibleMaterial.getMaterial(stack));
|
loot.setMaterial(CompatibleMaterial.getMaterial(stack.getType()).get());
|
||||||
|
|
||||||
paint();
|
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()))),
|
TextUtils.formatText("&7Name Override: &6" + (loot.getName() == null ? "None set" : loot.getName()))),
|
||||||
(event) -> {
|
(event) -> {
|
||||||
AnvilGui gui = new AnvilGui(event.player, this);
|
AnvilGui gui = new AnvilGui(event.player, this);
|
||||||
@ -74,10 +75,10 @@ public class GuiLootEditor extends Gui {
|
|||||||
}));
|
}));
|
||||||
|
|
||||||
guiManager.showGUI(event.player, 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("&7Lore Override:"),
|
||||||
TextUtils.formatText(loot.getLore() == null ? Collections.singletonList("&6None set") : loot.getLore())),
|
TextUtils.formatText(loot.getLore() == null ? Collections.singletonList("&6None set") : loot.getLore())),
|
||||||
(event) -> guiManager.showGUI(event.player, new GuiLoreEditor(loot, this)));
|
(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("&7Enchantments:"),
|
||||||
TextUtils.formatText(enchantments.isEmpty() ? Collections.singletonList("&6None set") : enchantments)),
|
TextUtils.formatText(enchantments.isEmpty() ? Collections.singletonList("&6None set") : enchantments)),
|
||||||
(event) -> guiManager.showGUI(event.player, new GuiEnchantEditor(loot, this)));
|
(event) -> guiManager.showGUI(event.player, new GuiEnchantEditor(loot, this)));
|
||||||
|
|
||||||
setButton(13, GuiUtils.createButtonItem(
|
setButton(13, GuiUtils.createButtonItem(
|
||||||
loot.getBurnedMaterial() == null
|
loot.getBurnedMaterial() == null
|
||||||
? CompatibleMaterial.FIRE_CHARGE
|
? XMaterial.FIRE_CHARGE
|
||||||
: loot.getBurnedMaterial(),
|
: loot.getBurnedMaterial(),
|
||||||
TextUtils.formatText("&7Current Burned Material: &6"
|
TextUtils.formatText("&7Current Burned Material: &6"
|
||||||
+ (loot.getBurnedMaterial() == null
|
+ (loot.getBurnedMaterial() == null
|
||||||
@ -109,12 +110,12 @@ public class GuiLootEditor extends Gui {
|
|||||||
)),
|
)),
|
||||||
(event) -> {
|
(event) -> {
|
||||||
ItemStack stack = event.player.getInventory().getItemInMainHand();
|
ItemStack stack = event.player.getInventory().getItemInMainHand();
|
||||||
loot.setBurnedMaterial(CompatibleMaterial.getMaterial(stack));
|
loot.setBurnedMaterial(CompatibleMaterial.getMaterial(stack.getType()).get());
|
||||||
|
|
||||||
paint();
|
paint();
|
||||||
});
|
});
|
||||||
|
|
||||||
setButton(14, GuiUtils.createButtonItem(CompatibleMaterial.CLOCK,
|
setButton(14, GuiUtils.createButtonItem(XMaterial.CLOCK,
|
||||||
TextUtils.formatText("&7Chance: &6" + loot.getChance()),
|
TextUtils.formatText("&7Chance: &6" + loot.getChance()),
|
||||||
TextUtils.formatText(
|
TextUtils.formatText(
|
||||||
Arrays.asList("",
|
Arrays.asList("",
|
||||||
@ -131,11 +132,11 @@ public class GuiLootEditor extends Gui {
|
|||||||
e.player.closeInventory();
|
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);
|
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())),
|
TextUtils.formatText("&7Min Drop Amount: &6" + loot.getMin())),
|
||||||
(event) -> {
|
(event) -> {
|
||||||
AnvilGui gui = new AnvilGui(event.player, this);
|
AnvilGui gui = new AnvilGui(event.player, this);
|
||||||
@ -147,12 +148,12 @@ public class GuiLootEditor extends Gui {
|
|||||||
e.player.closeInventory();
|
e.player.closeInventory();
|
||||||
});
|
});
|
||||||
|
|
||||||
gui.setInput(GuiUtils.createButtonItem(CompatibleMaterial.PAPER,
|
gui.setInput(GuiUtils.createButtonItem(XMaterial.PAPER,
|
||||||
String.valueOf(loot.getMin())));
|
String.valueOf(loot.getMin())));
|
||||||
guiManager.showGUI(event.player, gui);
|
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())),
|
TextUtils.formatText("&7Max Drop Amount: &6" + loot.getMax())),
|
||||||
(event) -> {
|
(event) -> {
|
||||||
AnvilGui gui = new AnvilGui(event.player, this);
|
AnvilGui gui = new AnvilGui(event.player, this);
|
||||||
@ -164,11 +165,11 @@ public class GuiLootEditor extends Gui {
|
|||||||
e.player.closeInventory();
|
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);
|
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())),
|
TextUtils.formatText("&7Min Item Damage: &6" + loot.getDamageMin())),
|
||||||
(event) -> {
|
(event) -> {
|
||||||
AnvilGui gui = new AnvilGui(event.player, this);
|
AnvilGui gui = new AnvilGui(event.player, this);
|
||||||
@ -179,11 +180,11 @@ public class GuiLootEditor extends Gui {
|
|||||||
e.player.closeInventory();
|
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);
|
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())),
|
TextUtils.formatText("&7Max Item Damage: &6" + loot.getDamageMax())),
|
||||||
(event) -> {
|
(event) -> {
|
||||||
AnvilGui gui = new AnvilGui(event.player, this);
|
AnvilGui gui = new AnvilGui(event.player, this);
|
||||||
@ -194,11 +195,11 @@ public class GuiLootEditor extends Gui {
|
|||||||
e.player.closeInventory();
|
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);
|
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())),
|
TextUtils.formatText("&7Allow Looting Enchantment?: &6" + loot.isAllowLootingEnchant())),
|
||||||
(event) -> {
|
(event) -> {
|
||||||
loot.setAllowLootingEnchant(!loot.isAllowLootingEnchant());
|
loot.setAllowLootingEnchant(!loot.isAllowLootingEnchant());
|
||||||
@ -207,7 +208,7 @@ public class GuiLootEditor extends Gui {
|
|||||||
event.player.closeInventory();
|
event.player.closeInventory();
|
||||||
});
|
});
|
||||||
|
|
||||||
setButton(20, GuiUtils.createButtonItem(CompatibleMaterial.REDSTONE,
|
setButton(20, GuiUtils.createButtonItem(XMaterial.REDSTONE,
|
||||||
TextUtils.formatText("&7Min Child Loot Min: &6" + loot.getChildDropCountMin())),
|
TextUtils.formatText("&7Min Child Loot Min: &6" + loot.getChildDropCountMin())),
|
||||||
(event) -> {
|
(event) -> {
|
||||||
AnvilGui gui = new AnvilGui(event.player, this);
|
AnvilGui gui = new AnvilGui(event.player, this);
|
||||||
@ -219,11 +220,11 @@ public class GuiLootEditor extends Gui {
|
|||||||
e.player.closeInventory();
|
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);
|
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())),
|
TextUtils.formatText("&7Min Child Loot Max: &6" + loot.getChildDropCountMax())),
|
||||||
(event) -> {
|
(event) -> {
|
||||||
AnvilGui gui = new AnvilGui(event.player, this);
|
AnvilGui gui = new AnvilGui(event.player, this);
|
||||||
@ -235,7 +236,7 @@ public class GuiLootEditor extends Gui {
|
|||||||
e.player.closeInventory();
|
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);
|
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("&7Only Drop For:"),
|
||||||
TextUtils.formatText(entities)),
|
TextUtils.formatText(entities)),
|
||||||
(event) -> guiManager.showGUI(event.player, new GuiEntityEditor(loot, this)));
|
(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 -> {
|
(event -> {
|
||||||
AnvilGui gui = new AnvilGui(event.player, this);
|
AnvilGui gui = new AnvilGui(event.player, this);
|
||||||
|
|
||||||
gui.setAction((event1 -> {
|
gui.setAction((event1 -> {
|
||||||
try {
|
try {
|
||||||
loot.addChildLoots(new LootBuilder().setMaterial(CompatibleMaterial
|
loot.addChildLoots(new LootBuilder().setMaterial(XMaterial.valueOf(gui.getInputText().trim())).build());
|
||||||
.valueOf(gui.getInputText().trim())).build());
|
|
||||||
} catch (IllegalArgumentException ignore) {
|
} catch (IllegalArgumentException ignore) {
|
||||||
event.player.sendMessage("That is not a valid material.");
|
event.player.sendMessage("That is not a valid material.");
|
||||||
}
|
}
|
||||||
@ -275,7 +275,7 @@ public class GuiLootEditor extends Gui {
|
|||||||
int i = 9 * 5;
|
int i = 9 * 5;
|
||||||
for (Loot loot : loot.getChildLoot()) {
|
for (Loot loot : loot.getChildLoot()) {
|
||||||
ItemStack item = loot.getMaterial() == null
|
ItemStack item = loot.getMaterial() == null
|
||||||
? CompatibleMaterial.BARRIER.getItem()
|
? XMaterial.BARRIER.parseItem()
|
||||||
: GuiUtils.createButtonItem(loot.getMaterial(), null,
|
: GuiUtils.createButtonItem(loot.getMaterial(), null,
|
||||||
TextUtils.formatText("&6Left click &7to edit"),
|
TextUtils.formatText("&6Left click &7to edit"),
|
||||||
TextUtils.formatText("&6Right click &7to destroy"));
|
TextUtils.formatText("&6Right click &7to destroy"));
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
package com.craftaro.core.lootables.gui;
|
package com.craftaro.core.lootables.gui;
|
||||||
|
|
||||||
import com.craftaro.core.compatibility.CompatibleMaterial;
|
|
||||||
import com.craftaro.core.gui.AnvilGui;
|
import com.craftaro.core.gui.AnvilGui;
|
||||||
import com.craftaro.core.gui.Gui;
|
import com.craftaro.core.gui.Gui;
|
||||||
import com.craftaro.core.gui.GuiUtils;
|
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.LootManager;
|
||||||
import com.craftaro.core.lootables.loot.Lootable;
|
import com.craftaro.core.lootables.loot.Lootable;
|
||||||
import com.craftaro.core.utils.TextUtils;
|
import com.craftaro.core.utils.TextUtils;
|
||||||
|
import com.cryptomorin.xseries.XMaterial;
|
||||||
import org.bukkit.event.inventory.ClickType;
|
import org.bukkit.event.inventory.ClickType;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
@ -39,13 +39,12 @@ public class GuiLootableEditor extends Gui {
|
|||||||
|
|
||||||
setActionForRange(0, 0, 5, 9, null);
|
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 -> {
|
(event -> {
|
||||||
AnvilGui gui = new AnvilGui(event.player, this);
|
AnvilGui gui = new AnvilGui(event.player, this);
|
||||||
gui.setAction((event1 -> {
|
gui.setAction((event1 -> {
|
||||||
try {
|
try {
|
||||||
lootable.registerLoot(new LootBuilder().setMaterial(CompatibleMaterial
|
lootable.registerLoot(new LootBuilder().setMaterial(XMaterial.valueOf(gui.getInputText().trim().toUpperCase())).build());
|
||||||
.valueOf(gui.getInputText().trim().toUpperCase())).build());
|
|
||||||
} catch (IllegalArgumentException ex) {
|
} catch (IllegalArgumentException ex) {
|
||||||
event.player.sendMessage("That is not a valid material.");
|
event.player.sendMessage("That is not a valid material.");
|
||||||
}
|
}
|
||||||
@ -58,13 +57,13 @@ public class GuiLootableEditor extends Gui {
|
|||||||
guiManager.showGUI(event.player, 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)));
|
(event -> guiManager.showGUI(event.player, returnGui)));
|
||||||
|
|
||||||
int i = 9;
|
int i = 9;
|
||||||
for (Loot loot : lootable.getRegisteredLoot()) {
|
for (Loot loot : lootable.getRegisteredLoot()) {
|
||||||
ItemStack item = loot.getMaterial() == null
|
ItemStack item = loot.getMaterial() == null
|
||||||
? CompatibleMaterial.BARRIER.getItem()
|
? XMaterial.BARRIER.parseItem()
|
||||||
: GuiUtils.createButtonItem(loot.getMaterial(), null,
|
: GuiUtils.createButtonItem(loot.getMaterial(), null,
|
||||||
TextUtils.formatText("&6Left click &7to edit"),
|
TextUtils.formatText("&6Left click &7to edit"),
|
||||||
TextUtils.formatText("&6Right click &7to destroy"));
|
TextUtils.formatText("&6Right click &7to destroy"));
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
package com.craftaro.core.lootables.loot;
|
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.ItemUtils;
|
||||||
import com.craftaro.core.utils.TextUtils;
|
import com.craftaro.core.utils.TextUtils;
|
||||||
|
import com.cryptomorin.xseries.XMaterial;
|
||||||
|
import com.google.gson.annotations.SerializedName;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.enchantments.Enchantment;
|
import org.bukkit.enchantments.Enchantment;
|
||||||
import org.bukkit.entity.EntityType;
|
import org.bukkit.entity.EntityType;
|
||||||
@ -29,7 +29,7 @@ public class Loot {
|
|||||||
|
|
||||||
// Material used for this drop.
|
// Material used for this drop.
|
||||||
@SerializedName("Type")
|
@SerializedName("Type")
|
||||||
private CompatibleMaterial material;
|
private XMaterial material;
|
||||||
|
|
||||||
// The override for the item name.
|
// The override for the item name.
|
||||||
@SerializedName("Name")
|
@SerializedName("Name")
|
||||||
@ -45,7 +45,7 @@ public class Loot {
|
|||||||
|
|
||||||
// Material used if entity died on fire.
|
// Material used if entity died on fire.
|
||||||
@SerializedName("Burned Type")
|
@SerializedName("Burned Type")
|
||||||
private CompatibleMaterial burnedMaterial = null;
|
private XMaterial burnedMaterial = null;
|
||||||
|
|
||||||
// Chance that this drop will take place.
|
// Chance that this drop will take place.
|
||||||
@SerializedName("Chance")
|
@SerializedName("Chance")
|
||||||
@ -96,11 +96,11 @@ public class Loot {
|
|||||||
// Should the entity be charged? (Only works on creepers)
|
// Should the entity be charged? (Only works on creepers)
|
||||||
private boolean requireCharged = false;
|
private boolean requireCharged = false;
|
||||||
|
|
||||||
public CompatibleMaterial getMaterial() {
|
public XMaterial getMaterial() {
|
||||||
return material;
|
return material;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setMaterial(CompatibleMaterial material) {
|
public void setMaterial(XMaterial material) {
|
||||||
this.material = material;
|
this.material = material;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -200,11 +200,11 @@ public class Loot {
|
|||||||
return enchants == null ? null : Collections.unmodifiableMap(enchants);
|
return enchants == null ? null : Collections.unmodifiableMap(enchants);
|
||||||
}
|
}
|
||||||
|
|
||||||
public CompatibleMaterial getBurnedMaterial() {
|
public XMaterial getBurnedMaterial() {
|
||||||
return burnedMaterial;
|
return burnedMaterial;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setBurnedMaterial(CompatibleMaterial burnedMaterial) {
|
public void setBurnedMaterial(XMaterial burnedMaterial) {
|
||||||
this.burnedMaterial = burnedMaterial;
|
this.burnedMaterial = burnedMaterial;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
package com.craftaro.core.lootables.loot;
|
package com.craftaro.core.lootables.loot;
|
||||||
|
|
||||||
import com.craftaro.core.compatibility.CompatibleMaterial;
|
|
||||||
import com.craftaro.core.lootables.loot.objects.EnchantChance;
|
import com.craftaro.core.lootables.loot.objects.EnchantChance;
|
||||||
|
import com.cryptomorin.xseries.XMaterial;
|
||||||
import org.bukkit.entity.EntityType;
|
import org.bukkit.entity.EntityType;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
@ -15,7 +15,7 @@ public final class LootBuilder {
|
|||||||
this.loot = new Loot();
|
this.loot = new Loot();
|
||||||
}
|
}
|
||||||
|
|
||||||
public LootBuilder setMaterial(CompatibleMaterial material) {
|
public LootBuilder setMaterial(XMaterial material) {
|
||||||
this.loot.setMaterial(material);
|
this.loot.setMaterial(material);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
@ -52,7 +52,7 @@ public final class LootBuilder {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public LootBuilder setBurnedMaterial(CompatibleMaterial material) {
|
public LootBuilder setBurnedMaterial(XMaterial material) {
|
||||||
this.loot.setBurnedMaterial(material);
|
this.loot.setBurnedMaterial(material);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
package com.craftaro.core.lootables.loot;
|
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.Gson;
|
||||||
import com.google.gson.GsonBuilder;
|
import com.google.gson.GsonBuilder;
|
||||||
import com.google.gson.stream.JsonReader;
|
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.Bukkit;
|
||||||
import org.bukkit.entity.EntityType;
|
import org.bukkit.entity.EntityType;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
@ -92,7 +92,7 @@ public class LootManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
CompatibleMaterial material = loot.getMaterial();
|
XMaterial material = loot.getMaterial();
|
||||||
String command = loot.getCommand();
|
String command = loot.getCommand();
|
||||||
int xp = loot.getXp();
|
int xp = loot.getXp();
|
||||||
|
|
||||||
@ -107,9 +107,9 @@ public class LootManager {
|
|||||||
|
|
||||||
if (material != null) {
|
if (material != null) {
|
||||||
ItemStack item = loot.getBurnedMaterial() != null &&
|
ItemStack item = loot.getBurnedMaterial() != null &&
|
||||||
burning ? loot.getBurnedMaterial().getItem() : material.getItem();
|
burning ? loot.getBurnedMaterial().parseItem() : material.parseItem();
|
||||||
item.setAmount(amount);
|
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();
|
: item.getItemMeta();
|
||||||
|
|
||||||
if (loot.getName() != null) {
|
if (loot.getName() != null) {
|
||||||
|
@ -11,15 +11,15 @@ public class Eval {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void nextChar() {
|
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) {
|
private boolean eat(int charToEat) {
|
||||||
while (ch == ' ') {
|
while (this.ch == ' ') {
|
||||||
nextChar();
|
nextChar();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ch == charToEat) {
|
if (this.ch == charToEat) {
|
||||||
nextChar();
|
nextChar();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -31,8 +31,8 @@ public class Eval {
|
|||||||
nextChar();
|
nextChar();
|
||||||
|
|
||||||
double x = parseExpression();
|
double x = parseExpression();
|
||||||
if (pos < toParse.length()) {
|
if (this.pos < this.toParse.length()) {
|
||||||
throw new RuntimeException(warningMessage + "Unexpected: '" + (char) ch + "' at position " + pos + " in '" + this.toParse + "'");
|
throw new RuntimeException(this.warningMessage + "Unexpected: '" + (char) this.ch + "' at position " + this.pos + " in '" + this.toParse + "'");
|
||||||
}
|
}
|
||||||
|
|
||||||
return x;
|
return x;
|
||||||
@ -85,18 +85,18 @@ public class Eval {
|
|||||||
if (eat('(')) { // parentheses
|
if (eat('(')) { // parentheses
|
||||||
x = parseExpression();
|
x = parseExpression();
|
||||||
eat(')');
|
eat(')');
|
||||||
} else if ((ch >= '0' && ch <= '9') || ch == '.') { // numbers
|
} else if ((this.ch >= '0' && this.ch <= '9') || this.ch == '.') { // numbers
|
||||||
while ((ch >= '0' && ch <= '9') || ch == '.') {
|
while ((this.ch >= '0' && this.ch <= '9') || this.ch == '.') {
|
||||||
nextChar();
|
nextChar();
|
||||||
}
|
}
|
||||||
|
|
||||||
x = Double.parseDouble(toParse.substring(startPos, this.pos));
|
x = Double.parseDouble(this.toParse.substring(startPos, this.pos));
|
||||||
} else if (ch >= 'a' && ch <= 'z') { // functions
|
} else if (this.ch >= 'a' && this.ch <= 'z') { // functions
|
||||||
while (ch >= 'a' && ch <= 'z') {
|
while (this.ch >= 'a' && this.ch <= 'z') {
|
||||||
nextChar();
|
nextChar();
|
||||||
}
|
}
|
||||||
|
|
||||||
String func = toParse.substring(startPos, this.pos);
|
String func = this.toParse.substring(startPos, this.pos);
|
||||||
x = parseFactor();
|
x = parseFactor();
|
||||||
|
|
||||||
switch (func) {
|
switch (func) {
|
||||||
@ -113,10 +113,10 @@ public class Eval {
|
|||||||
x = Math.tan(Math.toRadians(x));
|
x = Math.tan(Math.toRadians(x));
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
throw new RuntimeException(warningMessage + "Unknown function: " + func);
|
throw new RuntimeException(this.warningMessage + "Unknown function: " + func);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
throw new RuntimeException(warningMessage + "Unexpected: " + (char) ch);
|
throw new RuntimeException(this.warningMessage + "Unexpected: " + (char) this.ch);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (eat('^')) {
|
if (eat('^')) {
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
package com.craftaro.core.math;
|
package com.craftaro.core.math;
|
||||||
|
|
||||||
import com.craftaro.core.SongodaCoreConstants;
|
import com.craftaro.core.CraftaroCoreConstants;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@ -9,7 +9,7 @@ public class MathUtils {
|
|||||||
private static final Map<String, Double> cache = new HashMap<>();
|
private static final Map<String, Double> cache = new HashMap<>();
|
||||||
|
|
||||||
public static double eval(String toParse) {
|
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) {
|
public static double eval(String toParse, String warningMessage) {
|
||||||
|
@ -7,6 +7,8 @@ import com.craftaro.core.compatibility.ServerVersion;
|
|||||||
import com.craftaro.core.nms.Nms;
|
import com.craftaro.core.nms.Nms;
|
||||||
import com.craftaro.core.nms.world.SWorld;
|
import com.craftaro.core.nms.world.SWorld;
|
||||||
import com.craftaro.core.nms.world.WorldCore;
|
import com.craftaro.core.nms.world.WorldCore;
|
||||||
|
import com.cryptomorin.xseries.XBlock;
|
||||||
|
import com.cryptomorin.xseries.XMaterial;
|
||||||
import org.bukkit.Effect;
|
import org.bukkit.Effect;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
@ -18,6 +20,7 @@ import java.lang.reflect.Constructor;
|
|||||||
import java.lang.reflect.InvocationTargetException;
|
import java.lang.reflect.InvocationTargetException;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.util.EnumSet;
|
import java.util.EnumSet;
|
||||||
|
import java.util.Optional;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
@ -346,7 +349,7 @@ public class BlockUtils {
|
|||||||
* @param loc The Location of the container
|
* @param loc The Location of the container
|
||||||
*
|
*
|
||||||
* @deprecated Use {@link WorldCore#updateAdjacentComparators(Block)}
|
* @deprecated Use {@link WorldCore#updateAdjacentComparators(Block)}
|
||||||
* via {@link Nms#getImplementations()} instead.
|
* via {@link Nms#getImplementations()} instead.
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public static void updateAdjacentComparators(Location loc) {
|
public static void updateAdjacentComparators(Location loc) {
|
||||||
@ -463,8 +466,8 @@ public class BlockUtils {
|
|||||||
* via {@link Nms#getImplementations()} instead.
|
* via {@link Nms#getImplementations()} instead.
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public static void setBlockFast(World world, int x, int y, int z, CompatibleMaterial material, byte data) {
|
public static void setBlockFast(World world, int x, int y, int z, XMaterial material, byte data) {
|
||||||
setBlockFast(world, x, y, z, material.getBlockMaterial(), data);
|
setBlockFast(world, x, y, z, material.parseMaterial(), data);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -483,12 +486,12 @@ public class BlockUtils {
|
|||||||
return BlockUtilsModern._isCropFullyGrown(block);
|
return BlockUtilsModern._isCropFullyGrown(block);
|
||||||
}
|
}
|
||||||
|
|
||||||
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())) {
|
||||||
return false;
|
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);
|
return BlockUtilsModern._getMaxGrowthStage(block);
|
||||||
}
|
}
|
||||||
|
|
||||||
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())) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
return (mat == CompatibleMaterial.BEETROOTS
|
return (mat.get() == XMaterial.BEETROOTS || mat.get() == XMaterial.NETHER_WART ? 3 : 7);
|
||||||
|| mat == CompatibleMaterial.NETHER_WART ? 3 : 7);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -532,12 +534,12 @@ public class BlockUtils {
|
|||||||
return BlockUtilsModern._getMaxGrowthStage(material);
|
return BlockUtilsModern._getMaxGrowthStage(material);
|
||||||
}
|
}
|
||||||
|
|
||||||
CompatibleMaterial mat = CompatibleMaterial.getBlockMaterial(material);
|
Optional<XMaterial> mat = CompatibleMaterial.getMaterial(material);
|
||||||
if (mat == null || !mat.isCrop()) {
|
if (!mat.isPresent() || XBlock.isCrop(mat.get())) {
|
||||||
return -1;
|
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) {
|
} else if (!useLegacy) {
|
||||||
BlockUtilsModern._setGrowthStage(block, stage);
|
BlockUtilsModern._setGrowthStage(block, stage);
|
||||||
} else {
|
} 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 {
|
try {
|
||||||
legacySetBlockData.invoke(block, (byte) Math.max(0, Math.min(stage, (mat == CompatibleMaterial.BEETROOTS
|
legacySetBlockData.invoke(block, (byte) Math.max(0, Math.min(stage, (mat.get() == XMaterial.BEETROOTS || mat.get() == XMaterial.NETHER_WART ? 3 : 7))));
|
||||||
|| mat == CompatibleMaterial.NETHER_WART ? 3 : 7))));
|
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
Logger.getLogger(BlockUtils.class.getName()).log(Level.SEVERE, "Unexpected method error", ex);
|
Logger.getLogger(BlockUtils.class.getName()).log(Level.SEVERE, "Unexpected method error", ex);
|
||||||
}
|
}
|
||||||
@ -573,10 +574,9 @@ public class BlockUtils {
|
|||||||
} else if (!useLegacy) {
|
} else if (!useLegacy) {
|
||||||
BlockUtilsModern._incrementGrowthStage(block);
|
BlockUtilsModern._incrementGrowthStage(block);
|
||||||
} else {
|
} 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()) && block.getData() < (mat.get() == XMaterial.BEETROOTS || mat.get() == XMaterial.NETHER_WART ? 3 : 7)) {
|
||||||
block.getData() < (mat == CompatibleMaterial.BEETROOTS || mat == CompatibleMaterial.NETHER_WART ? 3 : 7)) {
|
|
||||||
try {
|
try {
|
||||||
legacySetBlockData.invoke(block, (byte) (block.getData() + 1));
|
legacySetBlockData.invoke(block, (byte) (block.getData() + 1));
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
@ -596,9 +596,9 @@ public class BlockUtils {
|
|||||||
} else if (!useLegacy) {
|
} else if (!useLegacy) {
|
||||||
BlockUtilsModern._resetGrowthStage(block);
|
BlockUtilsModern._resetGrowthStage(block);
|
||||||
} else {
|
} 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 {
|
try {
|
||||||
legacySetBlockData.invoke(block, (byte) 0);
|
legacySetBlockData.invoke(block, (byte) 0);
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
|
@ -7,7 +7,7 @@ import java.util.Map;
|
|||||||
import java.util.TreeMap;
|
import java.util.TreeMap;
|
||||||
|
|
||||||
public class ColorUtils {
|
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 {
|
static {
|
||||||
colorMap.put(ColorCode.BLACK, new ColorSet<>(0, 0, 0));
|
colorMap.put(ColorCode.BLACK, new ColorSet<>(0, 0, 0));
|
||||||
@ -40,15 +40,15 @@ public class ColorUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public R getRed() {
|
public R getRed() {
|
||||||
return red;
|
return this.red;
|
||||||
}
|
}
|
||||||
|
|
||||||
public G getGreen() {
|
public G getGreen() {
|
||||||
return green;
|
return this.green;
|
||||||
}
|
}
|
||||||
|
|
||||||
public B getBlue() {
|
public B getBlue() {
|
||||||
return blue;
|
return this.blue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,18 +1,22 @@
|
|||||||
package com.craftaro.core.utils;
|
package com.craftaro.core.utils;
|
||||||
|
|
||||||
import com.craftaro.core.compatibility.ClassMapping;
|
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.EntityType;
|
||||||
import org.bukkit.entity.LivingEntity;
|
import org.bukkit.entity.LivingEntity;
|
||||||
|
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
import java.lang.reflect.InvocationTargetException;
|
import java.lang.reflect.InvocationTargetException;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @deprecated Use {@link com.craftaro.core.nms.entity.NmsEntity} instead
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
public class EntityUtils {
|
public class EntityUtils {
|
||||||
private static Class<?> clazzEntityInsentient, clazzEntity, clazzCraftEntity;
|
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) {
|
public static void setUnaware(LivingEntity entity) {
|
||||||
try {
|
try {
|
||||||
setUnaware(methodGetHandle.invoke(clazzCraftEntity.cast(entity)));
|
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) {
|
public static void setUnaware(Object entity) {
|
||||||
try {
|
try {
|
||||||
if (aware != null) {
|
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) {
|
public static boolean isAware(LivingEntity entity) {
|
||||||
try {
|
try {
|
||||||
return isAware(methodGetHandle.invoke(clazzCraftEntity.cast(entity)));
|
return isAware(methodGetHandle.invoke(clazzCraftEntity.cast(entity)));
|
||||||
@ -71,6 +87,10 @@ public class EntityUtils {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @deprecated Use {@link com.craftaro.core.nms.entity.NmsEntity#isAware(Entity)} instead
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
public static boolean isAware(Object entity) {
|
public static boolean isAware(Object entity) {
|
||||||
try {
|
try {
|
||||||
if (aware != null) {
|
if (aware != null) {
|
||||||
@ -85,7 +105,7 @@ public class EntityUtils {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<CompatibleMaterial> getSpawnBlocks(EntityType type) {
|
public static List<XMaterial> getSpawnBlocks(EntityType type) {
|
||||||
switch (type.name()) {
|
switch (type.name()) {
|
||||||
case "PIG":
|
case "PIG":
|
||||||
case "SHEEP":
|
case "SHEEP":
|
||||||
@ -95,23 +115,27 @@ public class EntityUtils {
|
|||||||
case "LLAMA":
|
case "LLAMA":
|
||||||
case "HORSE":
|
case "HORSE":
|
||||||
case "CAT":
|
case "CAT":
|
||||||
return new ArrayList<>(Collections.singletonList(CompatibleMaterial.GRASS_BLOCK));
|
return Collections.singletonList(XMaterial.GRASS_BLOCK);
|
||||||
|
|
||||||
case "MUSHROOM_COW":
|
case "MUSHROOM_COW":
|
||||||
return new ArrayList<>(Collections.singletonList(CompatibleMaterial.MYCELIUM));
|
return Collections.singletonList(XMaterial.MYCELIUM);
|
||||||
|
|
||||||
case "SQUID":
|
case "SQUID":
|
||||||
case "ELDER_GUARDIAN":
|
case "ELDER_GUARDIAN":
|
||||||
case "COD":
|
case "COD":
|
||||||
case "SALMON":
|
case "SALMON":
|
||||||
case "PUFFERFISH":
|
case "PUFFERFISH":
|
||||||
case "TROPICAL_FISH":
|
case "TROPICAL_FISH":
|
||||||
return new ArrayList<>(Collections.singletonList(CompatibleMaterial.WATER));
|
return Collections.singletonList(XMaterial.WATER);
|
||||||
|
|
||||||
case "OCELOT":
|
case "OCELOT":
|
||||||
return new ArrayList<>(Arrays.asList(CompatibleMaterial.GRASS_BLOCK,
|
return Arrays.asList(XMaterial.GRASS_BLOCK,
|
||||||
CompatibleMaterial.JUNGLE_LEAVES, CompatibleMaterial.ACACIA_LEAVES,
|
XMaterial.JUNGLE_LEAVES, XMaterial.ACACIA_LEAVES,
|
||||||
CompatibleMaterial.BIRCH_LEAVES, CompatibleMaterial.DARK_OAK_LEAVES,
|
XMaterial.BIRCH_LEAVES, XMaterial.DARK_OAK_LEAVES,
|
||||||
CompatibleMaterial.OAK_LEAVES, CompatibleMaterial.SPRUCE_LEAVES));
|
XMaterial.OAK_LEAVES, XMaterial.SPRUCE_LEAVES);
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return new ArrayList<>(Collections.singletonList(CompatibleMaterial.AIR));
|
return Collections.singletonList(XMaterial.AIR);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -13,7 +13,10 @@ import java.util.List;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Class based off of https://gist.github.com/graywolf336/8153678
|
* 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 {
|
public class ItemSerializer {
|
||||||
/**
|
/**
|
||||||
* A method to serialize an {@link ItemStack} list to Base64 String.
|
* A method to serialize an {@link ItemStack} list to Base64 String.
|
||||||
|
@ -1,12 +1,13 @@
|
|||||||
package com.craftaro.core.utils;
|
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.ClassMapping;
|
||||||
import com.craftaro.core.compatibility.CompatibleHand;
|
import com.craftaro.core.compatibility.CompatibleHand;
|
||||||
import com.craftaro.core.compatibility.CompatibleMaterial;
|
import com.craftaro.core.compatibility.CompatibleMaterial;
|
||||||
import com.craftaro.core.compatibility.MethodMapping;
|
import com.craftaro.core.compatibility.MethodMapping;
|
||||||
import com.craftaro.core.compatibility.ServerVersion;
|
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.apache.commons.lang3.StringUtils;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
@ -33,6 +34,7 @@ import java.util.Arrays;
|
|||||||
import java.util.Base64;
|
import java.util.Base64;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.concurrent.ThreadLocalRandom;
|
import java.util.concurrent.ThreadLocalRandom;
|
||||||
@ -42,7 +44,10 @@ import java.util.stream.Stream;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* This class uses some Minecraft code and also Paper API
|
* 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 {
|
public class ItemUtils {
|
||||||
static boolean can_getI18NDisplayName = true;
|
static boolean can_getI18NDisplayName = true;
|
||||||
|
|
||||||
@ -329,7 +334,7 @@ public class ItemUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static ItemStack getPlayerSkull(OfflinePlayer player) {
|
public static ItemStack getPlayerSkull(OfflinePlayer player) {
|
||||||
ItemStack head = CompatibleMaterial.PLAYER_HEAD.getItem();
|
ItemStack head = XMaterial.PLAYER_HEAD.parseItem();
|
||||||
if (ServerVersion.isServerVersionBelow(ServerVersion.V1_8)) {
|
if (ServerVersion.isServerVersionBelow(ServerVersion.V1_8)) {
|
||||||
return head;
|
return head;
|
||||||
}
|
}
|
||||||
@ -348,7 +353,7 @@ public class ItemUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void setHeadOwner(ItemStack head, OfflinePlayer player) {
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -366,7 +371,7 @@ public class ItemUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static ItemStack getCustomHead(String signature, String texture) {
|
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)) {
|
if (ServerVersion.isServerVersionBelow(ServerVersion.V1_8)) {
|
||||||
return skullItem;
|
return skullItem;
|
||||||
@ -430,7 +435,7 @@ public class ItemUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static String getSkullTexture(ItemStack item) {
|
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;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -486,9 +491,9 @@ public class ItemUtils {
|
|||||||
* @return true if both items are of the same material
|
* @return true if both items are of the same material
|
||||||
*/
|
*/
|
||||||
public static boolean isSimilarMaterial(ItemStack is1, ItemStack is2) {
|
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": {
|
case "FURNACE": {
|
||||||
check = new boolean[3];
|
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
|
// fuel is 2nd slot, input is first
|
||||||
if (isFuel) {
|
if (isFuel) {
|
||||||
@ -1005,7 +1010,7 @@ public class ItemUtils {
|
|||||||
case "FURNACE": {
|
case "FURNACE": {
|
||||||
check = new boolean[3];
|
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
|
// fuel is 2nd slot, input is first
|
||||||
if (isFuel) {
|
if (isFuel) {
|
||||||
check[1] = true;
|
check[1] = true;
|
||||||
@ -1080,41 +1085,41 @@ public class ItemUtils {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static CompatibleMaterial getDyeColor(char color) {
|
public static XMaterial getDyeColor(char color) {
|
||||||
switch (color) {
|
switch (color) {
|
||||||
case '0':
|
case '0':
|
||||||
return CompatibleMaterial.BLACK_DYE;
|
return XMaterial.BLACK_DYE;
|
||||||
case '1':
|
case '1':
|
||||||
return CompatibleMaterial.BLUE_DYE;
|
return XMaterial.BLUE_DYE;
|
||||||
case '2':
|
case '2':
|
||||||
return CompatibleMaterial.GREEN_DYE;
|
return XMaterial.GREEN_DYE;
|
||||||
case '3':
|
case '3':
|
||||||
return CompatibleMaterial.CYAN_DYE;
|
return XMaterial.CYAN_DYE;
|
||||||
case '4':
|
case '4':
|
||||||
return CompatibleMaterial.BROWN_DYE;
|
return XMaterial.BROWN_DYE;
|
||||||
case '5':
|
case '5':
|
||||||
return CompatibleMaterial.PURPLE_DYE;
|
return XMaterial.PURPLE_DYE;
|
||||||
case '6':
|
case '6':
|
||||||
return CompatibleMaterial.ORANGE_DYE;
|
return XMaterial.ORANGE_DYE;
|
||||||
case '7':
|
case '7':
|
||||||
return CompatibleMaterial.LIGHT_GRAY_DYE;
|
return XMaterial.LIGHT_GRAY_DYE;
|
||||||
case '8':
|
case '8':
|
||||||
return CompatibleMaterial.GRAY_DYE;
|
return XMaterial.GRAY_DYE;
|
||||||
case 'a':
|
case 'a':
|
||||||
return CompatibleMaterial.LIME_DYE;
|
return XMaterial.LIME_DYE;
|
||||||
case 'b':
|
case 'b':
|
||||||
return CompatibleMaterial.LIGHT_BLUE_DYE;
|
return XMaterial.LIGHT_BLUE_DYE;
|
||||||
case 'c':
|
case 'c':
|
||||||
return CompatibleMaterial.RED_DYE;
|
return XMaterial.RED_DYE;
|
||||||
case 'd':
|
case 'd':
|
||||||
return CompatibleMaterial.MAGENTA_DYE;
|
return XMaterial.MAGENTA_DYE;
|
||||||
case 'e':
|
case 'e':
|
||||||
return CompatibleMaterial.YELLOW_DYE;
|
return XMaterial.YELLOW_DYE;
|
||||||
case 'f':
|
case 'f':
|
||||||
return CompatibleMaterial.WHITE_DYE;
|
return XMaterial.WHITE_DYE;
|
||||||
}
|
}
|
||||||
|
|
||||||
return CompatibleMaterial.STONE;
|
return XMaterial.STONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -36,7 +36,10 @@ import java.util.zip.GZIPOutputStream;
|
|||||||
* bStats collects some data for plugin authors.
|
* bStats collects some data for plugin authors.
|
||||||
* <p>
|
* <p>
|
||||||
* Check out https://bStats.org/ to learn more about bStats!
|
* Check out https://bStats.org/ to learn more about bStats!
|
||||||
|
*
|
||||||
|
* @deprecated Replace with latest version of bStats
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
@SuppressWarnings({"WeakerAccess", "unused"})
|
@SuppressWarnings({"WeakerAccess", "unused"})
|
||||||
public class Metrics {
|
public class Metrics {
|
||||||
static {
|
static {
|
||||||
|
@ -7,6 +7,10 @@ import org.bukkit.entity.Player;
|
|||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @deprecated Use {@link com.craftaro.core.nms.Nms} instead
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
public class NMSUtils {
|
public class NMSUtils {
|
||||||
/**
|
/**
|
||||||
* @deprecated Use {@link ClassMapping} instead
|
* @deprecated Use {@link ClassMapping} instead
|
||||||
|
@ -4,10 +4,19 @@ import java.text.DecimalFormat;
|
|||||||
import java.text.DecimalFormatSymbols;
|
import java.text.DecimalFormatSymbols;
|
||||||
|
|
||||||
public class NumberUtils {
|
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) {
|
public static String formatEconomy(char currencySymbol, double number) {
|
||||||
return currencySymbol + formatNumber(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) {
|
public static String formatNumber(double number) {
|
||||||
DecimalFormat decimalFormatter = new DecimalFormat(number == Math.ceil(number) ? "#,###" : "#,###.00");
|
DecimalFormat decimalFormatter = new DecimalFormat(number == Math.ceil(number) ? "#,###" : "#,###.00");
|
||||||
|
|
||||||
@ -21,6 +30,10 @@ public class NumberUtils {
|
|||||||
return decimalFormatter.format(number);
|
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) {
|
public static String formatWithSuffix(long count) {
|
||||||
if (count < 1000) {
|
if (count < 1000) {
|
||||||
return String.valueOf(count);
|
return String.valueOf(count);
|
||||||
@ -33,19 +46,19 @@ public class NumberUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isInt(String number) {
|
public static boolean isInt(String number) {
|
||||||
if (number == null || number.equals("")) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Integer.parseInt(number);
|
Integer.parseInt(number);
|
||||||
return true;
|
return true;
|
||||||
} catch (NumberFormatException ignore) {
|
} catch (NumberFormatException ignore) {
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
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) {
|
public static boolean isNumeric(String s) {
|
||||||
if (s == null || s.equals("")) {
|
if (s == null || s.equals("")) {
|
||||||
return false;
|
return false;
|
||||||
|
@ -12,13 +12,11 @@ import java.util.Collection;
|
|||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Random;
|
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
import java.util.concurrent.ThreadLocalRandom;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public class PlayerUtils {
|
public class PlayerUtils {
|
||||||
static Random random = new Random();
|
|
||||||
|
|
||||||
public static void sendMessages(Player player, String... messages) {
|
public static void sendMessages(Player player, String... messages) {
|
||||||
for (String message : messages) {
|
for (String message : messages) {
|
||||||
player.sendMessage(message);
|
player.sendMessage(message);
|
||||||
@ -26,9 +24,7 @@ public class PlayerUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void sendMessages(Player player, List<String> messages) {
|
public static void sendMessages(Player player, List<String> messages) {
|
||||||
for (String message : messages) {
|
sendMessages(player, messages.toArray(new String[0]));
|
||||||
player.sendMessage(message);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -39,7 +35,10 @@ public class PlayerUtils {
|
|||||||
* start with this
|
* start with this
|
||||||
*
|
*
|
||||||
* @return list of player names that are "visible" to the player
|
* @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) {
|
public static List<String> getVisiblePlayerNames(CommandSender sender, String startingWith) {
|
||||||
Player player = sender instanceof Player ? (Player) sender : null;
|
Player player = sender instanceof Player ? (Player) sender : null;
|
||||||
final String startsWith = startingWith == null || startingWith.isEmpty() ? null : startingWith.toLowerCase();
|
final String startsWith = startingWith == null || startingWith.isEmpty() ? null : startingWith.toLowerCase();
|
||||||
@ -60,7 +59,10 @@ public class PlayerUtils {
|
|||||||
* start with this
|
* start with this
|
||||||
*
|
*
|
||||||
* @return list of player names that are "visible" to the player
|
* @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) {
|
public static List<String> getVisiblePlayerDisplayNames(CommandSender sender, String startingWith) {
|
||||||
Player player = sender instanceof Player ? (Player) sender : null;
|
Player player = sender instanceof Player ? (Player) sender : null;
|
||||||
final String startsWith = startingWith == null || startingWith.isEmpty() ? null : startingWith.replaceAll("[^a-zA-Z]", "").toLowerCase();
|
final String startsWith = startingWith == null || startingWith.isEmpty() ? null : startingWith.replaceAll("[^a-zA-Z]", "").toLowerCase();
|
||||||
@ -81,7 +83,10 @@ public class PlayerUtils {
|
|||||||
* start with this
|
* start with this
|
||||||
*
|
*
|
||||||
* @return list of players that are "visible" to the player
|
* @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) {
|
public static List<Player> getVisiblePlayers(CommandSender sender, String startingWith) {
|
||||||
Player player = sender instanceof Player ? (Player) sender : null;
|
Player player = sender instanceof Player ? (Player) sender : null;
|
||||||
final String startsWith = startingWith == null || startingWith.isEmpty() ? null : startingWith.toLowerCase();
|
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
|
* @param startsWith All names returned must start with this input string
|
||||||
*
|
*
|
||||||
* @return List of matching player IGN
|
* @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) {
|
public static List<String> getAllPlayers(CommandSender us, String startsWith) {
|
||||||
final String arg = startsWith.toLowerCase();
|
final String arg = startsWith.toLowerCase();
|
||||||
|
|
||||||
@ -118,7 +126,10 @@ public class PlayerUtils {
|
|||||||
* @param startsWith All names returned must start with this input string
|
* @param startsWith All names returned must start with this input string
|
||||||
*
|
*
|
||||||
* @return List of matching player display names
|
* @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) {
|
public static List<String> getAllPlayersDisplay(CommandSender us, String startsWith) {
|
||||||
// FIXME: Why do we need that regex? It just breaks the startsWith check
|
// FIXME: Why do we need that regex? It just breaks the startsWith check
|
||||||
// + the DisplayName comparison is not made lower case
|
// + the DisplayName comparison is not made lower case
|
||||||
@ -137,7 +148,10 @@ public class PlayerUtils {
|
|||||||
* @param player player to search for
|
* @param player player to search for
|
||||||
*
|
*
|
||||||
* @return Player that closest matches the input name, or null if none found
|
* @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) {
|
public static Player findPlayer(String player) {
|
||||||
Player found = Bukkit.getServer().getPlayer(player);
|
Player found = Bukkit.getServer().getPlayer(player);
|
||||||
|
|
||||||
@ -181,7 +195,7 @@ public class PlayerUtils {
|
|||||||
|
|
||||||
final Iterator<? extends Player> alli = all.iterator();
|
final Iterator<? extends Player> alli = all.iterator();
|
||||||
|
|
||||||
int pick = random.nextInt(all.size());
|
int pick = ThreadLocalRandom.current().nextInt(all.size());
|
||||||
|
|
||||||
for (; pick > 0; --pick) {
|
for (; pick > 0; --pick) {
|
||||||
alli.next();
|
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) {
|
public static int getNumberFromPermission(Player player, String permission, int def) {
|
||||||
final Set<PermissionAttachmentInfo> permissions = player.getEffectivePermissions();
|
final Set<PermissionAttachmentInfo> permissions = player.getEffectivePermissions();
|
||||||
|
|
||||||
|
@ -29,6 +29,11 @@ import java.util.logging.Level;
|
|||||||
import java.util.zip.ZipEntry;
|
import java.util.zip.ZipEntry;
|
||||||
import java.util.zip.ZipInputStream;
|
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 class ReflectionUtils {
|
||||||
public final static double JAVA_VERSION = getVersion();
|
public final static double JAVA_VERSION = getVersion();
|
||||||
private static String system_os = System.getProperty("os.name").toLowerCase();
|
private static String system_os = System.getProperty("os.name").toLowerCase();
|
||||||
|
@ -2,19 +2,23 @@ package com.craftaro.core.utils;
|
|||||||
|
|
||||||
import org.bukkit.block.BlockFace;
|
import org.bukkit.block.BlockFace;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @deprecated No replacement available
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
public class RotationUtils {
|
public class RotationUtils {
|
||||||
public static float faceToYaw(BlockFace face) {
|
public static float faceToYaw(BlockFace face) {
|
||||||
switch (face) {
|
switch (face) {
|
||||||
case NORTH:
|
|
||||||
return 180F;
|
|
||||||
case EAST:
|
case EAST:
|
||||||
return -90F;
|
return -90;
|
||||||
case SOUTH:
|
|
||||||
return 0F;
|
|
||||||
case WEST:
|
case WEST:
|
||||||
return 90F;
|
return 90;
|
||||||
|
case NORTH:
|
||||||
|
return 180;
|
||||||
|
|
||||||
|
case SOUTH:
|
||||||
default:
|
default:
|
||||||
return 0F;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
package com.craftaro.core.world;
|
package com.craftaro.core.world;
|
||||||
|
|
||||||
import com.craftaro.core.compatibility.CompatibleHand;
|
import com.craftaro.core.compatibility.CompatibleHand;
|
||||||
import com.craftaro.core.compatibility.CompatibleSound;
|
|
||||||
import com.craftaro.core.compatibility.ServerVersion;
|
import com.craftaro.core.compatibility.ServerVersion;
|
||||||
import com.craftaro.core.nms.Nms;
|
import com.craftaro.core.nms.Nms;
|
||||||
|
import com.cryptomorin.xseries.XSound;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.enchantments.Enchantment;
|
import org.bukkit.enchantments.Enchantment;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
@ -23,7 +23,7 @@ public class SItemStack {
|
|||||||
|
|
||||||
public SItemStack(CompatibleHand hand, Player player) {
|
public SItemStack(CompatibleHand hand, Player player) {
|
||||||
this.item = hand.getItem(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) {
|
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
|
* @param damage the amount of damage to apply to the item
|
||||||
*/
|
*/
|
||||||
public ItemStack addDamage(Player player, int damage, boolean respectVanillaUnbreakingEnchantments) {
|
public ItemStack addDamage(Player player, int damage, boolean respectVanillaUnbreakingEnchantments) {
|
||||||
if (item == null) {
|
if (this.item == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (item.getItemMeta() == null) {
|
if (this.item.getItemMeta() == null) {
|
||||||
return item;
|
return this.item;
|
||||||
}
|
}
|
||||||
|
|
||||||
int maxDurability = item.getType().getMaxDurability();
|
int maxDurability = this.item.getType().getMaxDurability();
|
||||||
int durability;
|
int durability;
|
||||||
|
|
||||||
if (ServerVersion.isServerVersionBelow(ServerVersion.V1_11)
|
if (ServerVersion.isServerVersionBelow(ServerVersion.V1_11)
|
||||||
? Nms.getImplementations().getNbt().of(item).has("Unbreakable")
|
? Nms.getImplementations().getNbt().of(this.item).has("Unbreakable")
|
||||||
: item.getItemMeta().isUnbreakable()) {
|
: this.item.getItemMeta().isUnbreakable()) {
|
||||||
return item;
|
return this.item;
|
||||||
} else if (ServerVersion.isServerVersionAtLeast(ServerVersion.V1_13)) {
|
} else if (ServerVersion.isServerVersionAtLeast(ServerVersion.V1_13)) {
|
||||||
// ItemStack.setDurability(short) still works in 1.13-1.14, but use these methods now
|
// 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) {
|
if (meta instanceof Damageable) {
|
||||||
Damageable damageable = ((Damageable) meta);
|
Damageable damageable = ((Damageable) meta);
|
||||||
|
|
||||||
@ -63,25 +63,25 @@ public class SItemStack {
|
|||||||
}
|
}
|
||||||
|
|
||||||
damageable.setDamage(((Damageable) meta).getDamage() + damage);
|
damageable.setDamage(((Damageable) meta).getDamage() + damage);
|
||||||
item.setItemMeta(meta);
|
this.item.setItemMeta(meta);
|
||||||
durability = damageable.getDamage();
|
durability = damageable.getDamage();
|
||||||
} else {
|
} else {
|
||||||
return item;
|
return this.item;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (respectVanillaUnbreakingEnchantments) {
|
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));
|
this.item.setDurability((short) Math.max(0, this.item.getDurability() + damage));
|
||||||
durability = item.getDurability();
|
durability = this.item.getDurability();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (durability >= maxDurability && player != null) {
|
if (durability >= maxDurability && player != null) {
|
||||||
destroy(player);
|
destroy(player);
|
||||||
}
|
}
|
||||||
|
|
||||||
return item;
|
return this.item;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void destroy(Player player) {
|
public void destroy(Player player) {
|
||||||
@ -89,15 +89,15 @@ public class SItemStack {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void destroy(Player player, int amount) {
|
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);
|
Bukkit.getServer().getPluginManager().callEvent(breakEvent);
|
||||||
|
|
||||||
sItem.breakItem(player, amount);
|
this.sItem.breakItem(player, amount);
|
||||||
CompatibleSound.ENTITY_ITEM_BREAK.play(player);
|
XSound.ENTITY_ITEM_BREAK.play(player);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ItemStack getItem() {
|
public ItemStack getItem() {
|
||||||
return item;
|
return this.item;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static int shouldApplyDamage(int unbreakingEnchantLevel, int damageAmount) {
|
private static int shouldApplyDamage(int unbreakingEnchantLevel, int damageAmount) {
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
package com.craftaro.core.world;
|
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.hooks.EntityStackerManager;
|
||||||
import com.craftaro.core.nms.Nms;
|
import com.craftaro.core.nms.Nms;
|
||||||
import com.craftaro.core.nms.world.SpawnedEntity;
|
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.Location;
|
||||||
import org.bukkit.block.CreatureSpawner;
|
import org.bukkit.block.CreatureSpawner;
|
||||||
import org.bukkit.entity.EntityType;
|
import org.bukkit.entity.EntityType;
|
||||||
@ -39,9 +39,8 @@ public class SSpawner {
|
|||||||
*
|
*
|
||||||
* @return amount of entities spawned
|
* @return amount of entities spawned
|
||||||
*/
|
*/
|
||||||
public int spawn(int amountToSpawn, String particle, Set<CompatibleMaterial> canSpawnOn, SpawnedEntity spawned,
|
public int spawn(int amountToSpawn, String particle, Set<XMaterial> canSpawnOn, SpawnedEntity spawned, EntityType... types) {
|
||||||
EntityType... types) {
|
if (this.location.getWorld() == null) {
|
||||||
if (location.getWorld() == null) {
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -60,7 +59,7 @@ public class SSpawner {
|
|||||||
int amountSpawned = 0;
|
int amountSpawned = 0;
|
||||||
while (spawnCountUsed-- > 0) {
|
while (spawnCountUsed-- > 0) {
|
||||||
EntityType type = types[ThreadLocalRandom.current().nextInt(types.length)];
|
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 (entity != null) {
|
||||||
// If this entity is indeed stackable then spawn a single stack with the desired stack size.
|
// 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() {
|
public Location getLocation() {
|
||||||
return location;
|
return this.location;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -29,13 +29,13 @@ public class SWorld {
|
|||||||
|
|
||||||
public List<LivingEntity> getLivingEntities() {
|
public List<LivingEntity> getLivingEntities() {
|
||||||
if (ServerVersion.isServerVersionBelow(ServerVersion.V1_17)) {
|
if (ServerVersion.isServerVersionBelow(ServerVersion.V1_17)) {
|
||||||
return world.getLivingEntities();
|
return this.world.getLivingEntities();
|
||||||
}
|
}
|
||||||
|
|
||||||
return sWorld.getLivingEntities();
|
return this.sWorld.getLivingEntities();
|
||||||
}
|
}
|
||||||
|
|
||||||
public World getWorld() {
|
public World getWorld() {
|
||||||
return world;
|
return this.world;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -9,7 +9,7 @@ import java.util.regex.Pattern;
|
|||||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
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
|
// 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-]+)*))?$");
|
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");
|
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);
|
assertTrue(VERSION_PATTERN.matcher(coreVersion).matches(), "Version string is not a valid semver string: " + coreVersion);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void getProjectName() {
|
void getProjectName() {
|
||||||
assertFalse(SongodaCoreConstants.getProjectName().isEmpty());
|
assertFalse(CraftaroCoreConstants.getProjectName().isEmpty());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void getGitHubProjectUrl() {
|
void getGitHubProjectUrl() {
|
||||||
assertFalse(SongodaCoreConstants.getGitHubProjectUrl().isEmpty());
|
assertFalse(CraftaroCoreConstants.getGitHubProjectUrl().isEmpty());
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -2,12 +2,15 @@ package com.craftaro.core.nms;
|
|||||||
|
|
||||||
import com.craftaro.core.nms.anvil.AnvilCore;
|
import com.craftaro.core.nms.anvil.AnvilCore;
|
||||||
import com.craftaro.core.nms.entity.NMSPlayer;
|
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.NmsWorldBorder;
|
||||||
import com.craftaro.core.nms.world.WorldCore;
|
import com.craftaro.core.nms.world.WorldCore;
|
||||||
import com.craftaro.core.nms.nbt.NBTCore;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
public interface NmsImplementations {
|
public interface NmsImplementations {
|
||||||
|
@NotNull NmsEntity getEntity();
|
||||||
|
|
||||||
@NotNull NMSPlayer getPlayer();
|
@NotNull NMSPlayer getPlayer();
|
||||||
|
|
||||||
@NotNull WorldCore getWorld();
|
@NotNull WorldCore getWorld();
|
||||||
|
@ -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);
|
||||||
|
}
|
@ -1,6 +1,6 @@
|
|||||||
package com.craftaro.core.nms.world;
|
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.apache.commons.text.WordUtils;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.entity.EntityType;
|
import org.bukkit.entity.EntityType;
|
||||||
@ -11,8 +11,7 @@ import java.util.Set;
|
|||||||
public interface SSpawner {
|
public interface SSpawner {
|
||||||
LivingEntity spawnEntity(EntityType type, Location spawnerLocation);
|
LivingEntity spawnEntity(EntityType type, Location spawnerLocation);
|
||||||
|
|
||||||
LivingEntity spawnEntity(EntityType type, String particleType, SpawnedEntity spawned,
|
LivingEntity spawnEntity(EntityType type, String particleType, SpawnedEntity spawned, Set<XMaterial> canSpawnOn);
|
||||||
Set<CompatibleMaterial> canSpawnOn);
|
|
||||||
|
|
||||||
default String translateName(EntityType type, boolean capital) {
|
default String translateName(EntityType type, boolean capital) {
|
||||||
return capital ? TypeTranslations.getUpperFromType(type) : TypeTranslations.getLowerFromType(type);
|
return capital ? TypeTranslations.getUpperFromType(type) : TypeTranslations.getLowerFromType(type);
|
||||||
|
@ -1,19 +1,22 @@
|
|||||||
package com.craftaro.core.nms.v1_10_R1;
|
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.anvil.AnvilCore;
|
||||||
import com.craftaro.core.nms.v1_10_R1.entity.NMSPlayerImpl;
|
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.nbt.NBTCoreImpl;
|
||||||
import com.craftaro.core.nms.v1_10_R1.world.NmsWorldBorderImpl;
|
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.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.NmsWorldBorder;
|
||||||
import com.craftaro.core.nms.world.WorldCore;
|
import com.craftaro.core.nms.world.WorldCore;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
public class NmsImplementationsImpl implements NmsImplementations {
|
public class NmsImplementationsImpl implements NmsImplementations {
|
||||||
|
private final NmsEntity entity;
|
||||||
private final NMSPlayer player;
|
private final NMSPlayer player;
|
||||||
private final WorldCore world;
|
private final WorldCore world;
|
||||||
private final NmsWorldBorder worldBorder;
|
private final NmsWorldBorder worldBorder;
|
||||||
@ -21,6 +24,7 @@ public class NmsImplementationsImpl implements NmsImplementations {
|
|||||||
private final NBTCore nbt;
|
private final NBTCore nbt;
|
||||||
|
|
||||||
public NmsImplementationsImpl() {
|
public NmsImplementationsImpl() {
|
||||||
|
this.entity = new NmsEntityImpl();
|
||||||
this.player = new NMSPlayerImpl();
|
this.player = new NMSPlayerImpl();
|
||||||
this.world = new WorldCoreImpl();
|
this.world = new WorldCoreImpl();
|
||||||
this.worldBorder = new NmsWorldBorderImpl();
|
this.worldBorder = new NmsWorldBorderImpl();
|
||||||
@ -28,6 +32,11 @@ public class NmsImplementationsImpl implements NmsImplementations {
|
|||||||
this.nbt = new NBTCoreImpl();
|
this.nbt = new NBTCoreImpl();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @NotNull NmsEntity getEntity() {
|
||||||
|
return this.entity;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @NotNull NMSPlayer getPlayer() {
|
public @NotNull NMSPlayer getPlayer() {
|
||||||
return this.player;
|
return this.player;
|
||||||
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
@ -4,6 +4,7 @@ import com.craftaro.core.compatibility.CompatibleMaterial;
|
|||||||
import com.craftaro.core.compatibility.CompatibleParticleHandler;
|
import com.craftaro.core.compatibility.CompatibleParticleHandler;
|
||||||
import com.craftaro.core.nms.world.SSpawner;
|
import com.craftaro.core.nms.world.SSpawner;
|
||||||
import com.craftaro.core.nms.world.SpawnedEntity;
|
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.BlockPosition;
|
||||||
import net.minecraft.server.v1_10_R1.ChunkRegionLoader;
|
import net.minecraft.server.v1_10_R1.ChunkRegionLoader;
|
||||||
import net.minecraft.server.v1_10_R1.DifficultyDamageScaler;
|
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.entity.LivingEntity;
|
||||||
import org.bukkit.event.entity.CreatureSpawnEvent;
|
import org.bukkit.event.entity.CreatureSpawnEvent;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
@ -35,21 +37,20 @@ public class SSpawnerImpl implements SSpawner {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public LivingEntity spawnEntity(EntityType type, String particleType, SpawnedEntity spawned,
|
public LivingEntity spawnEntity(EntityType type, String particleType, SpawnedEntity spawned, Set<XMaterial> canSpawnOn) {
|
||||||
Set<CompatibleMaterial> canSpawnOn) {
|
|
||||||
MobSpawnerData data = new MobSpawnerData();
|
MobSpawnerData data = new MobSpawnerData();
|
||||||
NBTTagCompound compound = data.b();
|
NBTTagCompound compound = data.b();
|
||||||
|
|
||||||
compound.setString("id", translateName(type, true));
|
compound.setString("id", translateName(type, true));
|
||||||
|
|
||||||
short spawnRange = 4;
|
short spawnRange = 4;
|
||||||
for (int i = 0; i < 50; i++) {
|
for (int i = 0; i < 50; ++i) {
|
||||||
WorldServer world = ((CraftWorld) spawnerLocation.getWorld()).getHandle();
|
WorldServer world = ((CraftWorld) this.spawnerLocation.getWorld()).getHandle();
|
||||||
|
|
||||||
Random random = world.random;
|
Random random = world.random;
|
||||||
double x = spawnerLocation.getX() + (random.nextDouble() - random.nextDouble()) * (double) spawnRange + 0.5D;
|
double x = this.spawnerLocation.getX() + (random.nextDouble() - random.nextDouble()) * (double) spawnRange + 0.5D;
|
||||||
double y = spawnerLocation.getY() + random.nextInt(3) - 1;
|
double y = this.spawnerLocation.getY() + random.nextInt(3) - 1;
|
||||||
double z = spawnerLocation.getZ() + (random.nextDouble() - random.nextDouble()) * (double) spawnRange + 0.5D;
|
double z = this.spawnerLocation.getZ() + (random.nextDouble() - random.nextDouble()) * (double) spawnRange + 0.5D;
|
||||||
|
|
||||||
Entity entity = ChunkRegionLoader.a(compound, world, x, y, z, false);
|
Entity entity = ChunkRegionLoader.a(compound, world, x, y, z, false);
|
||||||
|
|
||||||
@ -63,7 +64,7 @@ public class SSpawnerImpl implements SSpawner {
|
|||||||
|
|
||||||
EntityInsentient entityInsentient = (EntityInsentient) entity;
|
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)) {
|
if (!canSpawn(entityInsentient, spot, canSpawnOn)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -96,29 +97,28 @@ public class SSpawnerImpl implements SSpawner {
|
|||||||
return null;
|
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()) {
|
if (!entityInsentient.canSpawn()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
CompatibleMaterial spawnedIn = CompatibleMaterial.getMaterial(location.getBlock());
|
Optional<XMaterial> spawnedIn = CompatibleMaterial.getMaterial(location.getBlock().getType());
|
||||||
CompatibleMaterial spawnedOn = CompatibleMaterial.getMaterial(location.getBlock().getRelative(BlockFace.DOWN));
|
Optional<XMaterial> spawnedOn = CompatibleMaterial.getMaterial(location.getBlock().getRelative(BlockFace.DOWN).getType());
|
||||||
|
if (!spawnedIn.isPresent() || !spawnedOn.isPresent()) {
|
||||||
if (spawnedIn == null || spawnedOn == null) {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!spawnedIn.isAir() &&
|
if (!CompatibleMaterial.isAir(spawnedIn.get()) &&
|
||||||
spawnedIn != CompatibleMaterial.WATER &&
|
spawnedIn.get() != XMaterial.WATER &&
|
||||||
!spawnedIn.name().contains("PRESSURE") &&
|
!spawnedIn.get().name().contains("PRESSURE") &&
|
||||||
!spawnedIn.name().contains("SLAB")) {
|
!spawnedIn.get().name().contains("SLAB")) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (CompatibleMaterial material : canSpawnOn) {
|
for (XMaterial material : canSpawnOn) {
|
||||||
if (material == null) continue;
|
if (material == null) continue;
|
||||||
|
|
||||||
if (spawnedOn.equals(material) || material.isAir()) {
|
if (spawnedOn.get() == material || CompatibleMaterial.isAir(material)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,19 +1,22 @@
|
|||||||
package com.craftaro.core.nms.v1_11_R1;
|
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.anvil.AnvilCore;
|
||||||
import com.craftaro.core.nms.v1_11_R1.entity.NMSPlayerImpl;
|
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.nbt.NBTCoreImpl;
|
||||||
import com.craftaro.core.nms.v1_11_R1.world.NmsWorldBorderImpl;
|
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.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.NmsWorldBorder;
|
||||||
import com.craftaro.core.nms.world.WorldCore;
|
import com.craftaro.core.nms.world.WorldCore;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
public class NmsImplementationsImpl implements NmsImplementations {
|
public class NmsImplementationsImpl implements NmsImplementations {
|
||||||
|
private final NmsEntity entity;
|
||||||
private final NMSPlayer player;
|
private final NMSPlayer player;
|
||||||
private final WorldCore world;
|
private final WorldCore world;
|
||||||
private final NmsWorldBorder worldBorder;
|
private final NmsWorldBorder worldBorder;
|
||||||
@ -21,6 +24,7 @@ public class NmsImplementationsImpl implements NmsImplementations {
|
|||||||
private final NBTCore nbt;
|
private final NBTCore nbt;
|
||||||
|
|
||||||
public NmsImplementationsImpl() {
|
public NmsImplementationsImpl() {
|
||||||
|
this.entity = new NmsEntityImpl();
|
||||||
this.player = new NMSPlayerImpl();
|
this.player = new NMSPlayerImpl();
|
||||||
this.world = new WorldCoreImpl();
|
this.world = new WorldCoreImpl();
|
||||||
this.worldBorder = new NmsWorldBorderImpl();
|
this.worldBorder = new NmsWorldBorderImpl();
|
||||||
@ -28,6 +32,11 @@ public class NmsImplementationsImpl implements NmsImplementations {
|
|||||||
this.nbt = new NBTCoreImpl();
|
this.nbt = new NBTCoreImpl();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @NotNull NmsEntity getEntity() {
|
||||||
|
return this.entity;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @NotNull NMSPlayer getPlayer() {
|
public @NotNull NMSPlayer getPlayer() {
|
||||||
return this.player;
|
return this.player;
|
||||||
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
@ -4,6 +4,7 @@ import com.craftaro.core.compatibility.CompatibleMaterial;
|
|||||||
import com.craftaro.core.compatibility.CompatibleParticleHandler;
|
import com.craftaro.core.compatibility.CompatibleParticleHandler;
|
||||||
import com.craftaro.core.nms.world.SSpawner;
|
import com.craftaro.core.nms.world.SSpawner;
|
||||||
import com.craftaro.core.nms.world.SpawnedEntity;
|
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.BlockPosition;
|
||||||
import net.minecraft.server.v1_11_R1.ChunkRegionLoader;
|
import net.minecraft.server.v1_11_R1.ChunkRegionLoader;
|
||||||
import net.minecraft.server.v1_11_R1.DifficultyDamageScaler;
|
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.entity.LivingEntity;
|
||||||
import org.bukkit.event.entity.CreatureSpawnEvent;
|
import org.bukkit.event.entity.CreatureSpawnEvent;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
@ -35,24 +37,26 @@ public class SSpawnerImpl implements SSpawner {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public LivingEntity spawnEntity(EntityType type, String particleType, SpawnedEntity spawned,
|
public LivingEntity spawnEntity(EntityType type, String particleType, SpawnedEntity spawned, Set<XMaterial> canSpawnOn) {
|
||||||
Set<CompatibleMaterial> canSpawnOn) {
|
|
||||||
MobSpawnerData data = new MobSpawnerData();
|
MobSpawnerData data = new MobSpawnerData();
|
||||||
NBTTagCompound compound = data.b();
|
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("mushroom_cow", "mooshroom")
|
||||||
.replace("iron_golem", "villager_golem");
|
.replace("iron_golem", "villager_golem");
|
||||||
compound.setString("id", "minecraft:" + name);
|
compound.setString("id", "minecraft:" + name);
|
||||||
|
|
||||||
short spawnRange = 4;
|
short spawnRange = 4;
|
||||||
for (int i = 0; i < 50; i++) {
|
for (int i = 0; i < 50; ++i) {
|
||||||
WorldServer world = ((CraftWorld) spawnerLocation.getWorld()).getHandle();
|
WorldServer world = ((CraftWorld) this.spawnerLocation.getWorld()).getHandle();
|
||||||
|
|
||||||
Random random = world.random;
|
Random random = world.random;
|
||||||
double x = spawnerLocation.getX() + (random.nextDouble() - random.nextDouble()) * (double) spawnRange + 0.5D;
|
double x = this.spawnerLocation.getX() + (random.nextDouble() - random.nextDouble()) * (double) spawnRange + 0.5D;
|
||||||
double y = spawnerLocation.getY() + random.nextInt(3) - 1;
|
double y = this.spawnerLocation.getY() + random.nextInt(3) - 1;
|
||||||
double z = spawnerLocation.getZ() + (random.nextDouble() - random.nextDouble()) * (double) spawnRange + 0.5D;
|
double z = this.spawnerLocation.getZ() + (random.nextDouble() - random.nextDouble()) * (double) spawnRange + 0.5D;
|
||||||
|
|
||||||
Entity entity = ChunkRegionLoader.a(compound, world, x, y, z, false);
|
Entity entity = ChunkRegionLoader.a(compound, world, x, y, z, false);
|
||||||
|
|
||||||
@ -66,7 +70,7 @@ public class SSpawnerImpl implements SSpawner {
|
|||||||
|
|
||||||
EntityInsentient entityInsentient = (EntityInsentient) entity;
|
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)) {
|
if (!canSpawn(entityInsentient, spot, canSpawnOn)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -99,29 +103,29 @@ public class SSpawnerImpl implements SSpawner {
|
|||||||
return null;
|
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()) {
|
if (!entityInsentient.canSpawn()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
CompatibleMaterial spawnedIn = CompatibleMaterial.getMaterial(location.getBlock());
|
Optional<XMaterial> spawnedIn = CompatibleMaterial.getMaterial(location.getBlock().getType());
|
||||||
CompatibleMaterial spawnedOn = CompatibleMaterial.getMaterial(location.getBlock().getRelative(BlockFace.DOWN));
|
Optional<XMaterial> spawnedOn = CompatibleMaterial.getMaterial(location.getBlock().getRelative(BlockFace.DOWN).getType());
|
||||||
|
|
||||||
if (spawnedIn == null || spawnedOn == null) {
|
if (!spawnedIn.isPresent() || !spawnedOn.isPresent()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!spawnedIn.isAir() &&
|
if (!CompatibleMaterial.isAir(spawnedIn.get()) &&
|
||||||
spawnedIn != CompatibleMaterial.WATER &&
|
spawnedIn.get() != XMaterial.WATER &&
|
||||||
!spawnedIn.name().contains("PRESSURE") &&
|
!spawnedIn.get().name().contains("PRESSURE") &&
|
||||||
!spawnedIn.name().contains("SLAB")) {
|
!spawnedIn.get().name().contains("SLAB")) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (CompatibleMaterial material : canSpawnOn) {
|
for (XMaterial material : canSpawnOn) {
|
||||||
if (material == null) continue;
|
if (material == null) continue;
|
||||||
|
|
||||||
if (spawnedOn.equals(material) || material.isAir()) {
|
if (spawnedOn.get() == material || CompatibleMaterial.isAir(material)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,19 +1,22 @@
|
|||||||
package com.craftaro.core.nms.v1_12_R1;
|
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.NmsImplementations;
|
||||||
import com.craftaro.core.nms.entity.NMSPlayer;
|
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.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.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.NmsWorldBorder;
|
||||||
import com.craftaro.core.nms.world.WorldCore;
|
import com.craftaro.core.nms.world.WorldCore;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
public class NmsImplementationsImpl implements NmsImplementations {
|
public class NmsImplementationsImpl implements NmsImplementations {
|
||||||
|
private final NmsEntity entity;
|
||||||
private final NMSPlayer player;
|
private final NMSPlayer player;
|
||||||
private final WorldCore world;
|
private final WorldCore world;
|
||||||
private final NmsWorldBorder worldBorder;
|
private final NmsWorldBorder worldBorder;
|
||||||
@ -21,6 +24,7 @@ public class NmsImplementationsImpl implements NmsImplementations {
|
|||||||
private final NBTCore nbt;
|
private final NBTCore nbt;
|
||||||
|
|
||||||
public NmsImplementationsImpl() {
|
public NmsImplementationsImpl() {
|
||||||
|
this.entity = new NmsEntityImpl();
|
||||||
this.player = new NMSPlayerImpl();
|
this.player = new NMSPlayerImpl();
|
||||||
this.world = new WorldCoreImpl();
|
this.world = new WorldCoreImpl();
|
||||||
this.worldBorder = new NmsWorldBorderImpl();
|
this.worldBorder = new NmsWorldBorderImpl();
|
||||||
@ -28,6 +32,11 @@ public class NmsImplementationsImpl implements NmsImplementations {
|
|||||||
this.nbt = new NBTCoreImpl();
|
this.nbt = new NBTCoreImpl();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @NotNull NmsEntity getEntity() {
|
||||||
|
return this.entity;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @NotNull NMSPlayer getPlayer() {
|
public @NotNull NMSPlayer getPlayer() {
|
||||||
return this.player;
|
return this.player;
|
||||||
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
@ -4,6 +4,7 @@ import com.craftaro.core.compatibility.CompatibleMaterial;
|
|||||||
import com.craftaro.core.compatibility.CompatibleParticleHandler;
|
import com.craftaro.core.compatibility.CompatibleParticleHandler;
|
||||||
import com.craftaro.core.nms.world.SSpawner;
|
import com.craftaro.core.nms.world.SSpawner;
|
||||||
import com.craftaro.core.nms.world.SpawnedEntity;
|
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.BlockPosition;
|
||||||
import net.minecraft.server.v1_12_R1.ChunkRegionLoader;
|
import net.minecraft.server.v1_12_R1.ChunkRegionLoader;
|
||||||
import net.minecraft.server.v1_12_R1.DifficultyDamageScaler;
|
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.entity.LivingEntity;
|
||||||
import org.bukkit.event.entity.CreatureSpawnEvent;
|
import org.bukkit.event.entity.CreatureSpawnEvent;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
@ -35,25 +37,27 @@ public class SSpawnerImpl implements SSpawner {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public LivingEntity spawnEntity(EntityType type, String particleType, SpawnedEntity spawned,
|
public LivingEntity spawnEntity(EntityType type, String particleType, SpawnedEntity spawned, Set<XMaterial> canSpawnOn) {
|
||||||
Set<CompatibleMaterial> canSpawnOn) {
|
|
||||||
MobSpawnerData data = new MobSpawnerData();
|
MobSpawnerData data = new MobSpawnerData();
|
||||||
NBTTagCompound compound = data.b();
|
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("mushroom_cow", "mooshroom")
|
||||||
.replace("iron_golem", "villager_golem");;
|
.replace("iron_golem", "villager_golem");
|
||||||
|
|
||||||
compound.setString("id", "minecraft:" + name);
|
compound.setString("id", "minecraft:" + name);
|
||||||
|
|
||||||
short spawnRange = 4;
|
short spawnRange = 4;
|
||||||
for (int i = 0; i < 50; i++) {
|
for (int i = 0; i < 50; ++i) {
|
||||||
WorldServer world = ((CraftWorld) spawnerLocation.getWorld()).getHandle();
|
WorldServer world = ((CraftWorld) this.spawnerLocation.getWorld()).getHandle();
|
||||||
|
|
||||||
Random random = world.random;
|
Random random = world.random;
|
||||||
double x = spawnerLocation.getX() + (random.nextDouble() - random.nextDouble()) * (double) spawnRange + 0.5D;
|
double x = this.spawnerLocation.getX() + (random.nextDouble() - random.nextDouble()) * (double) spawnRange + 0.5D;
|
||||||
double y = spawnerLocation.getY() + random.nextInt(3) - 1;
|
double y = this.spawnerLocation.getY() + random.nextInt(3) - 1;
|
||||||
double z = spawnerLocation.getZ() + (random.nextDouble() - random.nextDouble()) * (double) spawnRange + 0.5D;
|
double z = this.spawnerLocation.getZ() + (random.nextDouble() - random.nextDouble()) * (double) spawnRange + 0.5D;
|
||||||
|
|
||||||
Entity entity = ChunkRegionLoader.a(compound, world, x, y, z, false);
|
Entity entity = ChunkRegionLoader.a(compound, world, x, y, z, false);
|
||||||
|
|
||||||
@ -67,7 +71,7 @@ public class SSpawnerImpl implements SSpawner {
|
|||||||
|
|
||||||
EntityInsentient entityInsentient = (EntityInsentient) entity;
|
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)) {
|
if (!canSpawn(entityInsentient, spot, canSpawnOn)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -100,29 +104,29 @@ public class SSpawnerImpl implements SSpawner {
|
|||||||
return null;
|
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()) {
|
if (!entityInsentient.canSpawn()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
CompatibleMaterial spawnedIn = CompatibleMaterial.getMaterial(location.getBlock());
|
Optional<XMaterial> spawnedIn = CompatibleMaterial.getMaterial(location.getBlock().getType());
|
||||||
CompatibleMaterial spawnedOn = CompatibleMaterial.getMaterial(location.getBlock().getRelative(BlockFace.DOWN));
|
Optional<XMaterial> spawnedOn = CompatibleMaterial.getMaterial(location.getBlock().getRelative(BlockFace.DOWN).getType());
|
||||||
|
|
||||||
if (spawnedIn == null || spawnedOn == null) {
|
if (!spawnedIn.isPresent() || !spawnedOn.isPresent()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!spawnedIn.isAir() &&
|
if (!CompatibleMaterial.isAir(spawnedIn.get()) &&
|
||||||
spawnedIn != CompatibleMaterial.WATER &&
|
spawnedIn.get() != XMaterial.WATER &&
|
||||||
!spawnedIn.name().contains("PRESSURE") &&
|
!spawnedIn.get().name().contains("PRESSURE") &&
|
||||||
!spawnedIn.name().contains("SLAB")) {
|
!spawnedIn.get().name().contains("SLAB")) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (CompatibleMaterial material : canSpawnOn) {
|
for (XMaterial material : canSpawnOn) {
|
||||||
if (material == null) continue;
|
if (material == null) continue;
|
||||||
|
|
||||||
if (spawnedOn.equals(material) || material.isAir()) {
|
if (spawnedOn.get() == material || CompatibleMaterial.isAir(material)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,19 +1,22 @@
|
|||||||
package com.craftaro.core.nms.v1_13_R1;
|
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.anvil.AnvilCore;
|
||||||
import com.craftaro.core.nms.v1_13_R1.entity.NMSPlayerImpl;
|
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.nbt.NBTCoreImpl;
|
||||||
import com.craftaro.core.nms.v1_13_R1.world.NmsWorldBorderImpl;
|
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.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.NmsWorldBorder;
|
||||||
import com.craftaro.core.nms.world.WorldCore;
|
import com.craftaro.core.nms.world.WorldCore;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
public class NmsImplementationsImpl implements NmsImplementations {
|
public class NmsImplementationsImpl implements NmsImplementations {
|
||||||
|
private final NmsEntity entity;
|
||||||
private final NMSPlayer player;
|
private final NMSPlayer player;
|
||||||
private final WorldCore world;
|
private final WorldCore world;
|
||||||
private final NmsWorldBorder worldBorder;
|
private final NmsWorldBorder worldBorder;
|
||||||
@ -21,6 +24,7 @@ public class NmsImplementationsImpl implements NmsImplementations {
|
|||||||
private final NBTCore nbt;
|
private final NBTCore nbt;
|
||||||
|
|
||||||
public NmsImplementationsImpl() {
|
public NmsImplementationsImpl() {
|
||||||
|
this.entity = new NmsEntityImpl();
|
||||||
this.player = new NMSPlayerImpl();
|
this.player = new NMSPlayerImpl();
|
||||||
this.world = new WorldCoreImpl();
|
this.world = new WorldCoreImpl();
|
||||||
this.worldBorder = new NmsWorldBorderImpl();
|
this.worldBorder = new NmsWorldBorderImpl();
|
||||||
@ -28,6 +32,11 @@ public class NmsImplementationsImpl implements NmsImplementations {
|
|||||||
this.nbt = new NBTCoreImpl();
|
this.nbt = new NBTCoreImpl();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @NotNull NmsEntity getEntity() {
|
||||||
|
return this.entity;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @NotNull NMSPlayer getPlayer() {
|
public @NotNull NMSPlayer getPlayer() {
|
||||||
return this.player;
|
return this.player;
|
||||||
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
@ -4,6 +4,7 @@ import com.craftaro.core.compatibility.CompatibleMaterial;
|
|||||||
import com.craftaro.core.compatibility.CompatibleParticleHandler;
|
import com.craftaro.core.compatibility.CompatibleParticleHandler;
|
||||||
import com.craftaro.core.nms.world.SSpawner;
|
import com.craftaro.core.nms.world.SSpawner;
|
||||||
import com.craftaro.core.nms.world.SpawnedEntity;
|
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.BlockPosition;
|
||||||
import net.minecraft.server.v1_13_R1.ChunkRegionLoader;
|
import net.minecraft.server.v1_13_R1.ChunkRegionLoader;
|
||||||
import net.minecraft.server.v1_13_R1.DifficultyDamageScaler;
|
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.entity.LivingEntity;
|
||||||
import org.bukkit.event.entity.CreatureSpawnEvent;
|
import org.bukkit.event.entity.CreatureSpawnEvent;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
@ -35,8 +37,7 @@ public class SSpawnerImpl implements SSpawner {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public LivingEntity spawnEntity(EntityType type, String particleType, SpawnedEntity spawned,
|
public LivingEntity spawnEntity(EntityType type, String particleType, SpawnedEntity spawned, Set<XMaterial> canSpawnOn) {
|
||||||
Set<CompatibleMaterial> canSpawnOn) {
|
|
||||||
MobSpawnerData data = new MobSpawnerData();
|
MobSpawnerData data = new MobSpawnerData();
|
||||||
NBTTagCompound compound = data.b();
|
NBTTagCompound compound = data.b();
|
||||||
|
|
||||||
@ -45,13 +46,13 @@ public class SSpawnerImpl implements SSpawner {
|
|||||||
compound.setString("id", "minecraft:" + name);
|
compound.setString("id", "minecraft:" + name);
|
||||||
|
|
||||||
short spawnRange = 4;
|
short spawnRange = 4;
|
||||||
for (int i = 0; i < 50; i++) {
|
for (int i = 0; i < 50; ++i) {
|
||||||
WorldServer world = ((CraftWorld) spawnerLocation.getWorld()).getHandle();
|
WorldServer world = ((CraftWorld) this.spawnerLocation.getWorld()).getHandle();
|
||||||
|
|
||||||
Random random = world.random;
|
Random random = world.random;
|
||||||
double x = spawnerLocation.getX() + (random.nextDouble() - random.nextDouble()) * (double) spawnRange + 0.5D;
|
double x = this.spawnerLocation.getX() + (random.nextDouble() - random.nextDouble()) * (double) spawnRange + 0.5D;
|
||||||
double y = spawnerLocation.getY() + random.nextInt(3) - 1;
|
double y = this.spawnerLocation.getY() + random.nextInt(3) - 1;
|
||||||
double z = spawnerLocation.getZ() + (random.nextDouble() - random.nextDouble()) * (double) spawnRange + 0.5D;
|
double z = this.spawnerLocation.getZ() + (random.nextDouble() - random.nextDouble()) * (double) spawnRange + 0.5D;
|
||||||
|
|
||||||
Entity entity = ChunkRegionLoader.a(compound, world, x, y, z, false);
|
Entity entity = ChunkRegionLoader.a(compound, world, x, y, z, false);
|
||||||
|
|
||||||
@ -65,7 +66,7 @@ public class SSpawnerImpl implements SSpawner {
|
|||||||
|
|
||||||
EntityInsentient entityInsentient = (EntityInsentient) entity;
|
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)) {
|
if (!canSpawn(world, entityInsentient, spot, canSpawnOn)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -98,30 +99,29 @@ public class SSpawnerImpl implements SSpawner {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean canSpawn(WorldServer world, EntityInsentient entityInsentient, Location location,
|
private boolean canSpawn(WorldServer world, EntityInsentient entityInsentient, Location location, Set<XMaterial> canSpawnOn) {
|
||||||
Set<CompatibleMaterial> canSpawnOn) {
|
|
||||||
if (!world.getCubes(entityInsentient, entityInsentient.getBoundingBox())) {
|
if (!world.getCubes(entityInsentient, entityInsentient.getBoundingBox())) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
CompatibleMaterial spawnedIn = CompatibleMaterial.getMaterial(location.getBlock());
|
Optional<XMaterial> spawnedIn = CompatibleMaterial.getMaterial(location.getBlock().getType());
|
||||||
CompatibleMaterial spawnedOn = CompatibleMaterial.getMaterial(location.getBlock().getRelative(BlockFace.DOWN));
|
Optional<XMaterial> spawnedOn = CompatibleMaterial.getMaterial(location.getBlock().getRelative(BlockFace.DOWN).getType());
|
||||||
|
|
||||||
if (spawnedIn == null || spawnedOn == null) {
|
if (!spawnedIn.isPresent() || !spawnedOn.isPresent()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!spawnedIn.isAir() &&
|
if (!CompatibleMaterial.isAir(spawnedIn.get()) &&
|
||||||
spawnedIn != CompatibleMaterial.WATER &&
|
spawnedIn.get() != XMaterial.WATER &&
|
||||||
!spawnedIn.name().contains("PRESSURE") &&
|
!spawnedIn.get().name().contains("PRESSURE") &&
|
||||||
!spawnedIn.name().contains("SLAB")) {
|
!spawnedIn.get().name().contains("SLAB")) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (CompatibleMaterial material : canSpawnOn) {
|
for (XMaterial material : canSpawnOn) {
|
||||||
if (material == null) continue;
|
if (material == null) continue;
|
||||||
|
|
||||||
if (spawnedOn.equals(material) || material.isAir()) {
|
if (spawnedOn.get() == material || CompatibleMaterial.isAir(material)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,19 +1,22 @@
|
|||||||
package com.craftaro.core.nms.v1_13_R2;
|
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.anvil.AnvilCore;
|
||||||
import com.craftaro.core.nms.v1_13_R2.entity.NMSPlayerImpl;
|
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.nbt.NBTCoreImpl;
|
||||||
import com.craftaro.core.nms.v1_13_R2.world.NmsWorldBorderImpl;
|
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.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.NmsWorldBorder;
|
||||||
import com.craftaro.core.nms.world.WorldCore;
|
import com.craftaro.core.nms.world.WorldCore;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
public class NmsImplementationsImpl implements NmsImplementations {
|
public class NmsImplementationsImpl implements NmsImplementations {
|
||||||
|
private final NmsEntity entity;
|
||||||
private final NMSPlayer player;
|
private final NMSPlayer player;
|
||||||
private final WorldCore world;
|
private final WorldCore world;
|
||||||
private final NmsWorldBorder worldBorder;
|
private final NmsWorldBorder worldBorder;
|
||||||
@ -21,6 +24,7 @@ public class NmsImplementationsImpl implements NmsImplementations {
|
|||||||
private final NBTCore nbt;
|
private final NBTCore nbt;
|
||||||
|
|
||||||
public NmsImplementationsImpl() {
|
public NmsImplementationsImpl() {
|
||||||
|
this.entity = new NmsEntityImpl();
|
||||||
this.player = new NMSPlayerImpl();
|
this.player = new NMSPlayerImpl();
|
||||||
this.world = new WorldCoreImpl();
|
this.world = new WorldCoreImpl();
|
||||||
this.worldBorder = new NmsWorldBorderImpl();
|
this.worldBorder = new NmsWorldBorderImpl();
|
||||||
@ -28,6 +32,11 @@ public class NmsImplementationsImpl implements NmsImplementations {
|
|||||||
this.nbt = new NBTCoreImpl();
|
this.nbt = new NBTCoreImpl();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @NotNull NmsEntity getEntity() {
|
||||||
|
return this.entity;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @NotNull NMSPlayer getPlayer() {
|
public @NotNull NMSPlayer getPlayer() {
|
||||||
return this.player;
|
return this.player;
|
||||||
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
@ -4,6 +4,7 @@ import com.craftaro.core.compatibility.CompatibleMaterial;
|
|||||||
import com.craftaro.core.compatibility.CompatibleParticleHandler;
|
import com.craftaro.core.compatibility.CompatibleParticleHandler;
|
||||||
import com.craftaro.core.nms.world.SSpawner;
|
import com.craftaro.core.nms.world.SSpawner;
|
||||||
import com.craftaro.core.nms.world.SpawnedEntity;
|
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.BlockPosition;
|
||||||
import net.minecraft.server.v1_13_R2.ChunkRegionLoader;
|
import net.minecraft.server.v1_13_R2.ChunkRegionLoader;
|
||||||
import net.minecraft.server.v1_13_R2.DifficultyDamageScaler;
|
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.entity.LivingEntity;
|
||||||
import org.bukkit.event.entity.CreatureSpawnEvent;
|
import org.bukkit.event.entity.CreatureSpawnEvent;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
@ -35,8 +37,7 @@ public class SSpawnerImpl implements SSpawner {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public LivingEntity spawnEntity(EntityType type, String particleType, SpawnedEntity spawned,
|
public LivingEntity spawnEntity(EntityType type, String particleType, SpawnedEntity spawned, Set<XMaterial> canSpawnOn) {
|
||||||
Set<CompatibleMaterial> canSpawnOn) {
|
|
||||||
MobSpawnerData data = new MobSpawnerData();
|
MobSpawnerData data = new MobSpawnerData();
|
||||||
NBTTagCompound compound = data.b();
|
NBTTagCompound compound = data.b();
|
||||||
|
|
||||||
@ -45,13 +46,13 @@ public class SSpawnerImpl implements SSpawner {
|
|||||||
compound.setString("id", "minecraft:" + name);
|
compound.setString("id", "minecraft:" + name);
|
||||||
|
|
||||||
short spawnRange = 4;
|
short spawnRange = 4;
|
||||||
for (int i = 0; i < 50; i++) {
|
for (int i = 0; i < 50; ++i) {
|
||||||
WorldServer world = ((CraftWorld) spawnerLocation.getWorld()).getHandle();
|
WorldServer world = ((CraftWorld) this.spawnerLocation.getWorld()).getHandle();
|
||||||
|
|
||||||
Random random = world.random;
|
Random random = world.random;
|
||||||
double x = spawnerLocation.getX() + (random.nextDouble() - random.nextDouble()) * (double) spawnRange + 0.5D;
|
double x = this.spawnerLocation.getX() + (random.nextDouble() - random.nextDouble()) * (double) spawnRange + 0.5D;
|
||||||
double y = spawnerLocation.getY() + random.nextInt(3) - 1;
|
double y = this.spawnerLocation.getY() + random.nextInt(3) - 1;
|
||||||
double z = spawnerLocation.getZ() + (random.nextDouble() - random.nextDouble()) * (double) spawnRange + 0.5D;
|
double z = this.spawnerLocation.getZ() + (random.nextDouble() - random.nextDouble()) * (double) spawnRange + 0.5D;
|
||||||
|
|
||||||
Entity entity = ChunkRegionLoader.a(compound, world, x, y, z, false);
|
Entity entity = ChunkRegionLoader.a(compound, world, x, y, z, false);
|
||||||
|
|
||||||
@ -65,7 +66,7 @@ public class SSpawnerImpl implements SSpawner {
|
|||||||
|
|
||||||
EntityInsentient entityInsentient = (EntityInsentient) entity;
|
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)) {
|
if (!canSpawn(world, entityInsentient, spot, canSpawnOn)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -98,30 +99,29 @@ public class SSpawnerImpl implements SSpawner {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean canSpawn(WorldServer world, EntityInsentient entityInsentient, Location location,
|
private boolean canSpawn(WorldServer world, EntityInsentient entityInsentient, Location location, Set<XMaterial> canSpawnOn) {
|
||||||
Set<CompatibleMaterial> canSpawnOn) {
|
|
||||||
if (!world.getCubes(entityInsentient, entityInsentient.getBoundingBox())) {
|
if (!world.getCubes(entityInsentient, entityInsentient.getBoundingBox())) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
CompatibleMaterial spawnedIn = CompatibleMaterial.getMaterial(location.getBlock());
|
Optional<XMaterial> spawnedIn = CompatibleMaterial.getMaterial(location.getBlock().getType());
|
||||||
CompatibleMaterial spawnedOn = CompatibleMaterial.getMaterial(location.getBlock().getRelative(BlockFace.DOWN));
|
Optional<XMaterial> spawnedOn = CompatibleMaterial.getMaterial(location.getBlock().getRelative(BlockFace.DOWN).getType());
|
||||||
|
|
||||||
if (spawnedIn == null || spawnedOn == null) {
|
if (!spawnedIn.isPresent() || !spawnedOn.isPresent()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!spawnedIn.isAir() &&
|
if (!CompatibleMaterial.isAir(spawnedIn.get()) &&
|
||||||
spawnedIn != CompatibleMaterial.WATER &&
|
spawnedIn.get() != XMaterial.WATER &&
|
||||||
!spawnedIn.name().contains("PRESSURE") &&
|
!spawnedIn.get().name().contains("PRESSURE") &&
|
||||||
!spawnedIn.name().contains("SLAB")) {
|
!spawnedIn.get().name().contains("SLAB")) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (CompatibleMaterial material : canSpawnOn) {
|
for (XMaterial material : canSpawnOn) {
|
||||||
if (material == null) continue;
|
if (material == null) continue;
|
||||||
|
|
||||||
if (spawnedOn.equals(material) || material.isAir()) {
|
if (spawnedOn.get() == material || CompatibleMaterial.isAir(material)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,19 +1,22 @@
|
|||||||
package com.craftaro.core.nms.v1_14_R1;
|
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.NmsImplementations;
|
||||||
import com.craftaro.core.nms.entity.NMSPlayer;
|
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.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.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.NmsWorldBorder;
|
||||||
import com.craftaro.core.nms.world.WorldCore;
|
import com.craftaro.core.nms.world.WorldCore;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
public class NmsImplementationsImpl implements NmsImplementations {
|
public class NmsImplementationsImpl implements NmsImplementations {
|
||||||
|
private final NmsEntity entity;
|
||||||
private final NMSPlayer player;
|
private final NMSPlayer player;
|
||||||
private final WorldCore world;
|
private final WorldCore world;
|
||||||
private final NmsWorldBorder worldBorder;
|
private final NmsWorldBorder worldBorder;
|
||||||
@ -21,6 +24,7 @@ public class NmsImplementationsImpl implements NmsImplementations {
|
|||||||
private final NBTCore nbt;
|
private final NBTCore nbt;
|
||||||
|
|
||||||
public NmsImplementationsImpl() {
|
public NmsImplementationsImpl() {
|
||||||
|
this.entity = new NmsEntityImpl();
|
||||||
this.player = new NMSPlayerImpl();
|
this.player = new NMSPlayerImpl();
|
||||||
this.world = new WorldCoreImpl();
|
this.world = new WorldCoreImpl();
|
||||||
this.worldBorder = new NmsWorldBorderImpl();
|
this.worldBorder = new NmsWorldBorderImpl();
|
||||||
@ -28,6 +32,11 @@ public class NmsImplementationsImpl implements NmsImplementations {
|
|||||||
this.nbt = new NBTCoreImpl();
|
this.nbt = new NBTCoreImpl();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @NotNull NmsEntity getEntity() {
|
||||||
|
return this.entity;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @NotNull NMSPlayer getPlayer() {
|
public @NotNull NMSPlayer getPlayer() {
|
||||||
return this.player;
|
return this.player;
|
||||||
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
@ -4,6 +4,7 @@ import com.craftaro.core.compatibility.CompatibleMaterial;
|
|||||||
import com.craftaro.core.compatibility.CompatibleParticleHandler;
|
import com.craftaro.core.compatibility.CompatibleParticleHandler;
|
||||||
import com.craftaro.core.nms.world.SSpawner;
|
import com.craftaro.core.nms.world.SSpawner;
|
||||||
import com.craftaro.core.nms.world.SpawnedEntity;
|
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.BlockPosition;
|
||||||
import net.minecraft.server.v1_14_R1.DifficultyDamageScaler;
|
import net.minecraft.server.v1_14_R1.DifficultyDamageScaler;
|
||||||
import net.minecraft.server.v1_14_R1.Entity;
|
import net.minecraft.server.v1_14_R1.Entity;
|
||||||
@ -37,24 +38,26 @@ public class SSpawnerImpl implements SSpawner {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public LivingEntity spawnEntity(EntityType type, String particleType, SpawnedEntity spawned,
|
public LivingEntity spawnEntity(EntityType type, String particleType, SpawnedEntity spawned, Set<XMaterial> canSpawnOn) {
|
||||||
Set<CompatibleMaterial> canSpawnOn) {
|
|
||||||
MobSpawnerData data = new MobSpawnerData();
|
MobSpawnerData data = new MobSpawnerData();
|
||||||
NBTTagCompound compound = data.getEntity();
|
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");
|
.replace("mushroom_cow", "mooshroom");
|
||||||
compound.setString("id", "minecraft:" + name);
|
compound.setString("id", "minecraft:" + name);
|
||||||
|
|
||||||
short spawnRange = 4;
|
short spawnRange = 4;
|
||||||
for (int i = 0; i < 50; i++) {
|
for (int i = 0; i < 50; ++i) {
|
||||||
@SuppressWarnings("ConstantConditions")
|
@SuppressWarnings("ConstantConditions")
|
||||||
WorldServer world = ((CraftWorld) spawnerLocation.getWorld()).getHandle();
|
WorldServer world = ((CraftWorld) this.spawnerLocation.getWorld()).getHandle();
|
||||||
|
|
||||||
Random random = world.getRandom();
|
Random random = world.getRandom();
|
||||||
double x = spawnerLocation.getX() + (random.nextDouble() - random.nextDouble()) * (double) spawnRange + 0.5D;
|
double x = this.spawnerLocation.getX() + (random.nextDouble() - random.nextDouble()) * (double) spawnRange + 0.5D;
|
||||||
double y = spawnerLocation.getY() + random.nextInt(3) - 1;
|
double y = this.spawnerLocation.getY() + random.nextInt(3) - 1;
|
||||||
double z = spawnerLocation.getZ() + (random.nextDouble() - random.nextDouble()) * (double) spawnRange + 0.5D;
|
double z = this.spawnerLocation.getZ() + (random.nextDouble() - random.nextDouble()) * (double) spawnRange + 0.5D;
|
||||||
|
|
||||||
Optional<Entity> optionalEntity = EntityTypes.a(compound, world);
|
Optional<Entity> optionalEntity = EntityTypes.a(compound, world);
|
||||||
if (!optionalEntity.isPresent()) continue;
|
if (!optionalEntity.isPresent()) continue;
|
||||||
@ -71,7 +74,7 @@ public class SSpawnerImpl implements SSpawner {
|
|||||||
|
|
||||||
EntityInsentient entityInsentient = (EntityInsentient) entity;
|
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)) {
|
if (!canSpawn(world, entityInsentient, spot, canSpawnOn)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -104,30 +107,29 @@ public class SSpawnerImpl implements SSpawner {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean canSpawn(WorldServer world, EntityInsentient entityInsentient, Location location,
|
private boolean canSpawn(WorldServer world, EntityInsentient entityInsentient, Location location, Set<XMaterial> canSpawnOn) {
|
||||||
Set<CompatibleMaterial> canSpawnOn) {
|
|
||||||
if (!world.getCubes(entityInsentient, entityInsentient.getBoundingBox())) {
|
if (!world.getCubes(entityInsentient, entityInsentient.getBoundingBox())) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
CompatibleMaterial spawnedIn = CompatibleMaterial.getMaterial(location.getBlock());
|
Optional<XMaterial> spawnedIn = CompatibleMaterial.getMaterial(location.getBlock().getType());
|
||||||
CompatibleMaterial spawnedOn = CompatibleMaterial.getMaterial(location.getBlock().getRelative(BlockFace.DOWN));
|
Optional<XMaterial> spawnedOn = CompatibleMaterial.getMaterial(location.getBlock().getRelative(BlockFace.DOWN).getType());
|
||||||
|
|
||||||
if (spawnedIn == null || spawnedOn == null) {
|
if (!spawnedIn.isPresent() || !spawnedOn.isPresent()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!spawnedIn.isAir() &&
|
if (!CompatibleMaterial.isAir(spawnedIn.get()) &&
|
||||||
spawnedIn != CompatibleMaterial.WATER &&
|
spawnedIn.get() != XMaterial.WATER &&
|
||||||
!spawnedIn.name().contains("PRESSURE") &&
|
!spawnedIn.get().name().contains("PRESSURE") &&
|
||||||
!spawnedIn.name().contains("SLAB")) {
|
!spawnedIn.get().name().contains("SLAB")) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (CompatibleMaterial material : canSpawnOn) {
|
for (XMaterial material : canSpawnOn) {
|
||||||
if (material == null) continue;
|
if (material == null) continue;
|
||||||
|
|
||||||
if (spawnedOn.equals(material) || material.isAir()) {
|
if (spawnedOn.get() == material || CompatibleMaterial.isAir(material)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,19 +1,22 @@
|
|||||||
package com.craftaro.core.nms.v1_15_R1;
|
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.NmsImplementations;
|
||||||
import com.craftaro.core.nms.entity.NMSPlayer;
|
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.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.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.NmsWorldBorder;
|
||||||
import com.craftaro.core.nms.world.WorldCore;
|
import com.craftaro.core.nms.world.WorldCore;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
public class NmsImplementationsImpl implements NmsImplementations {
|
public class NmsImplementationsImpl implements NmsImplementations {
|
||||||
|
private final NmsEntity entity;
|
||||||
private final NMSPlayer player;
|
private final NMSPlayer player;
|
||||||
private final WorldCore world;
|
private final WorldCore world;
|
||||||
private final NmsWorldBorder worldBorder;
|
private final NmsWorldBorder worldBorder;
|
||||||
@ -21,6 +24,7 @@ public class NmsImplementationsImpl implements NmsImplementations {
|
|||||||
private final NBTCore nbt;
|
private final NBTCore nbt;
|
||||||
|
|
||||||
public NmsImplementationsImpl() {
|
public NmsImplementationsImpl() {
|
||||||
|
this.entity = new NmsEntityImpl();
|
||||||
this.player = new NMSPlayerImpl();
|
this.player = new NMSPlayerImpl();
|
||||||
this.world = new WorldCoreImpl();
|
this.world = new WorldCoreImpl();
|
||||||
this.worldBorder = new NmsWorldBorderImpl();
|
this.worldBorder = new NmsWorldBorderImpl();
|
||||||
@ -28,6 +32,11 @@ public class NmsImplementationsImpl implements NmsImplementations {
|
|||||||
this.nbt = new NBTCoreImpl();
|
this.nbt = new NBTCoreImpl();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @NotNull NmsEntity getEntity() {
|
||||||
|
return this.entity;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @NotNull NMSPlayer getPlayer() {
|
public @NotNull NMSPlayer getPlayer() {
|
||||||
return this.player;
|
return this.player;
|
||||||
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
@ -4,6 +4,7 @@ import com.craftaro.core.compatibility.CompatibleMaterial;
|
|||||||
import com.craftaro.core.compatibility.CompatibleParticleHandler;
|
import com.craftaro.core.compatibility.CompatibleParticleHandler;
|
||||||
import com.craftaro.core.nms.world.SSpawner;
|
import com.craftaro.core.nms.world.SSpawner;
|
||||||
import com.craftaro.core.nms.world.SpawnedEntity;
|
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.BlockPosition;
|
||||||
import net.minecraft.server.v1_15_R1.DifficultyDamageScaler;
|
import net.minecraft.server.v1_15_R1.DifficultyDamageScaler;
|
||||||
import net.minecraft.server.v1_15_R1.Entity;
|
import net.minecraft.server.v1_15_R1.Entity;
|
||||||
@ -37,24 +38,26 @@ public class SSpawnerImpl implements SSpawner {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public LivingEntity spawnEntity(EntityType type, String particleType, SpawnedEntity spawned,
|
public LivingEntity spawnEntity(EntityType type, String particleType, SpawnedEntity spawned, Set<XMaterial> canSpawnOn) {
|
||||||
Set<CompatibleMaterial> canSpawnOn) {
|
|
||||||
MobSpawnerData data = new MobSpawnerData();
|
MobSpawnerData data = new MobSpawnerData();
|
||||||
NBTTagCompound compound = data.getEntity();
|
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");
|
.replace("mushroom_cow", "mooshroom");
|
||||||
compound.setString("id", "minecraft:" + name);
|
compound.setString("id", "minecraft:" + name);
|
||||||
|
|
||||||
short spawnRange = 4;
|
short spawnRange = 4;
|
||||||
for (int i = 0; i < 50; i++) {
|
for (int i = 0; i < 50; ++i) {
|
||||||
@SuppressWarnings("ConstantConditions")
|
@SuppressWarnings("ConstantConditions")
|
||||||
WorldServer world = ((CraftWorld) spawnerLocation.getWorld()).getHandle();
|
WorldServer world = ((CraftWorld) this.spawnerLocation.getWorld()).getHandle();
|
||||||
|
|
||||||
Random random = world.getRandom();
|
Random random = world.getRandom();
|
||||||
double x = spawnerLocation.getX() + (random.nextDouble() - random.nextDouble()) * (double) spawnRange + 0.5D;
|
double x = this.spawnerLocation.getX() + (random.nextDouble() - random.nextDouble()) * (double) spawnRange + 0.5D;
|
||||||
double y = spawnerLocation.getY() + random.nextInt(3) - 1;
|
double y = this.spawnerLocation.getY() + random.nextInt(3) - 1;
|
||||||
double z = spawnerLocation.getZ() + (random.nextDouble() - random.nextDouble()) * (double) spawnRange + 0.5D;
|
double z = this.spawnerLocation.getZ() + (random.nextDouble() - random.nextDouble()) * (double) spawnRange + 0.5D;
|
||||||
|
|
||||||
Optional<Entity> optionalEntity = EntityTypes.a(compound, world);
|
Optional<Entity> optionalEntity = EntityTypes.a(compound, world);
|
||||||
if (!optionalEntity.isPresent()) {
|
if (!optionalEntity.isPresent()) {
|
||||||
@ -73,7 +76,7 @@ public class SSpawnerImpl implements SSpawner {
|
|||||||
|
|
||||||
EntityInsentient entityInsentient = (EntityInsentient) entity;
|
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)) {
|
if (!canSpawn(world, entityInsentient, spot, canSpawnOn)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -106,30 +109,29 @@ public class SSpawnerImpl implements SSpawner {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean canSpawn(WorldServer world, EntityInsentient entityInsentient, Location location,
|
private boolean canSpawn(WorldServer world, EntityInsentient entityInsentient, Location location, Set<XMaterial> canSpawnOn) {
|
||||||
Set<CompatibleMaterial> canSpawnOn) {
|
|
||||||
if (!world.getCubes(entityInsentient, entityInsentient.getBoundingBox())) {
|
if (!world.getCubes(entityInsentient, entityInsentient.getBoundingBox())) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
CompatibleMaterial spawnedIn = CompatibleMaterial.getMaterial(location.getBlock());
|
Optional<XMaterial> spawnedIn = CompatibleMaterial.getMaterial(location.getBlock().getType());
|
||||||
CompatibleMaterial spawnedOn = CompatibleMaterial.getMaterial(location.getBlock().getRelative(BlockFace.DOWN));
|
Optional<XMaterial> spawnedOn = CompatibleMaterial.getMaterial(location.getBlock().getRelative(BlockFace.DOWN).getType());
|
||||||
|
|
||||||
if (spawnedIn == null || spawnedOn == null) {
|
if (!spawnedIn.isPresent() || !spawnedOn.isPresent()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!spawnedIn.isAir() &&
|
if (!CompatibleMaterial.isAir(spawnedIn.get()) &&
|
||||||
spawnedIn != CompatibleMaterial.WATER &&
|
spawnedIn.get() != XMaterial.WATER &&
|
||||||
!spawnedIn.name().contains("PRESSURE") &&
|
!spawnedIn.get().name().contains("PRESSURE") &&
|
||||||
!spawnedIn.name().contains("SLAB")) {
|
!spawnedIn.get().name().contains("SLAB")) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (CompatibleMaterial material : canSpawnOn) {
|
for (XMaterial material : canSpawnOn) {
|
||||||
if (material == null) continue;
|
if (material == null) continue;
|
||||||
|
|
||||||
if (spawnedOn.equals(material) || material.isAir()) {
|
if (spawnedOn.get() == material || CompatibleMaterial.isAir(material)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,19 +1,22 @@
|
|||||||
package com.craftaro.core.nms.v1_16_R1;
|
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.anvil.AnvilCore;
|
||||||
import com.craftaro.core.nms.v1_16_R1.entity.NMSPlayerImpl;
|
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.nbt.NBTCoreImpl;
|
||||||
import com.craftaro.core.nms.v1_16_R1.world.NmsWorldBorderImpl;
|
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.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.NmsWorldBorder;
|
||||||
import com.craftaro.core.nms.world.WorldCore;
|
import com.craftaro.core.nms.world.WorldCore;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
public class NmsImplementationsImpl implements NmsImplementations {
|
public class NmsImplementationsImpl implements NmsImplementations {
|
||||||
|
private final NmsEntity entity;
|
||||||
private final NMSPlayer player;
|
private final NMSPlayer player;
|
||||||
private final WorldCore world;
|
private final WorldCore world;
|
||||||
private final NmsWorldBorder worldBorder;
|
private final NmsWorldBorder worldBorder;
|
||||||
@ -21,6 +24,7 @@ public class NmsImplementationsImpl implements NmsImplementations {
|
|||||||
private final NBTCore nbt;
|
private final NBTCore nbt;
|
||||||
|
|
||||||
public NmsImplementationsImpl() {
|
public NmsImplementationsImpl() {
|
||||||
|
this.entity = new NmsEntityImpl();
|
||||||
this.player = new NMSPlayerImpl();
|
this.player = new NMSPlayerImpl();
|
||||||
this.world = new WorldCoreImpl();
|
this.world = new WorldCoreImpl();
|
||||||
this.worldBorder = new NmsWorldBorderImpl();
|
this.worldBorder = new NmsWorldBorderImpl();
|
||||||
@ -28,6 +32,11 @@ public class NmsImplementationsImpl implements NmsImplementations {
|
|||||||
this.nbt = new NBTCoreImpl();
|
this.nbt = new NBTCoreImpl();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @NotNull NmsEntity getEntity() {
|
||||||
|
return this.entity;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @NotNull NMSPlayer getPlayer() {
|
public @NotNull NMSPlayer getPlayer() {
|
||||||
return this.player;
|
return this.player;
|
||||||
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
@ -4,6 +4,7 @@ import com.craftaro.core.compatibility.CompatibleMaterial;
|
|||||||
import com.craftaro.core.compatibility.CompatibleParticleHandler;
|
import com.craftaro.core.compatibility.CompatibleParticleHandler;
|
||||||
import com.craftaro.core.nms.world.SSpawner;
|
import com.craftaro.core.nms.world.SSpawner;
|
||||||
import com.craftaro.core.nms.world.SpawnedEntity;
|
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.BlockPosition;
|
||||||
import net.minecraft.server.v1_16_R1.DifficultyDamageScaler;
|
import net.minecraft.server.v1_16_R1.DifficultyDamageScaler;
|
||||||
import net.minecraft.server.v1_16_R1.Entity;
|
import net.minecraft.server.v1_16_R1.Entity;
|
||||||
@ -37,8 +38,7 @@ public class SSpawnerImpl implements SSpawner {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public LivingEntity spawnEntity(EntityType type, String particleType, SpawnedEntity spawned,
|
public LivingEntity spawnEntity(EntityType type, String particleType, SpawnedEntity spawned, Set<XMaterial> canSpawnOn) {
|
||||||
Set<CompatibleMaterial> canSpawnOn) {
|
|
||||||
MobSpawnerData data = new MobSpawnerData();
|
MobSpawnerData data = new MobSpawnerData();
|
||||||
NBTTagCompound compound = data.getEntity();
|
NBTTagCompound compound = data.getEntity();
|
||||||
|
|
||||||
@ -47,14 +47,14 @@ public class SSpawnerImpl implements SSpawner {
|
|||||||
compound.setString("id", "minecraft:" + name);
|
compound.setString("id", "minecraft:" + name);
|
||||||
|
|
||||||
short spawnRange = 4;
|
short spawnRange = 4;
|
||||||
for (int i = 0; i < 50; i++) {
|
for (int i = 0; i < 50; ++i) {
|
||||||
@SuppressWarnings("ConstantConditions")
|
@SuppressWarnings("ConstantConditions")
|
||||||
WorldServer world = ((CraftWorld) spawnerLocation.getWorld()).getHandle();
|
WorldServer world = ((CraftWorld) this.spawnerLocation.getWorld()).getHandle();
|
||||||
|
|
||||||
Random random = world.getRandom();
|
Random random = world.getRandom();
|
||||||
double x = spawnerLocation.getX() + (random.nextDouble() - random.nextDouble()) * (double) spawnRange + 0.5D;
|
double x = this.spawnerLocation.getX() + (random.nextDouble() - random.nextDouble()) * (double) spawnRange + 0.5D;
|
||||||
double y = spawnerLocation.getY() + random.nextInt(3) - 1;
|
double y = this.spawnerLocation.getY() + random.nextInt(3) - 1;
|
||||||
double z = spawnerLocation.getZ() + (random.nextDouble() - random.nextDouble()) * (double) spawnRange + 0.5D;
|
double z = this.spawnerLocation.getZ() + (random.nextDouble() - random.nextDouble()) * (double) spawnRange + 0.5D;
|
||||||
|
|
||||||
Optional<Entity> optionalEntity = EntityTypes.a(compound, world);
|
Optional<Entity> optionalEntity = EntityTypes.a(compound, world);
|
||||||
if (!optionalEntity.isPresent()) {
|
if (!optionalEntity.isPresent()) {
|
||||||
@ -73,7 +73,7 @@ public class SSpawnerImpl implements SSpawner {
|
|||||||
|
|
||||||
EntityInsentient entityInsentient = (EntityInsentient) entity;
|
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)) {
|
if (!canSpawn(world, entityInsentient, spot, canSpawnOn)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -106,30 +106,29 @@ public class SSpawnerImpl implements SSpawner {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean canSpawn(WorldServer world, EntityInsentient entityInsentient, Location location,
|
private boolean canSpawn(WorldServer world, EntityInsentient entityInsentient, Location location, Set<XMaterial> canSpawnOn) {
|
||||||
Set<CompatibleMaterial> canSpawnOn) {
|
|
||||||
if (!world.getCubes(entityInsentient, entityInsentient.getBoundingBox())) {
|
if (!world.getCubes(entityInsentient, entityInsentient.getBoundingBox())) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
CompatibleMaterial spawnedIn = CompatibleMaterial.getMaterial(location.getBlock());
|
Optional<XMaterial> spawnedIn = CompatibleMaterial.getMaterial(location.getBlock().getType());
|
||||||
CompatibleMaterial spawnedOn = CompatibleMaterial.getMaterial(location.getBlock().getRelative(BlockFace.DOWN));
|
Optional<XMaterial> spawnedOn = CompatibleMaterial.getMaterial(location.getBlock().getRelative(BlockFace.DOWN).getType());
|
||||||
|
|
||||||
if (spawnedIn == null || spawnedOn == null) {
|
if (!spawnedIn.isPresent() || !spawnedOn.isPresent()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!spawnedIn.isAir() &&
|
if (!CompatibleMaterial.isAir(spawnedIn.get()) &&
|
||||||
spawnedIn != CompatibleMaterial.WATER &&
|
spawnedIn.get() != XMaterial.WATER &&
|
||||||
!spawnedIn.name().contains("PRESSURE") &&
|
!spawnedIn.get().name().contains("PRESSURE") &&
|
||||||
!spawnedIn.name().contains("SLAB")) {
|
!spawnedIn.get().name().contains("SLAB")) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (CompatibleMaterial material : canSpawnOn) {
|
for (XMaterial material : canSpawnOn) {
|
||||||
if (material == null) continue;
|
if (material == null) continue;
|
||||||
|
|
||||||
if (spawnedOn.equals(material) || material.isAir()) {
|
if (spawnedOn.get() == material || CompatibleMaterial.isAir(material)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,19 +1,22 @@
|
|||||||
package com.craftaro.core.nms.v1_16_R2;
|
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.anvil.AnvilCore;
|
||||||
import com.craftaro.core.nms.v1_16_R2.entity.NMSPlayerImpl;
|
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.nbt.NBTCoreImpl;
|
||||||
import com.craftaro.core.nms.v1_16_R2.world.NmsWorldBorderImpl;
|
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.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.NmsWorldBorder;
|
||||||
import com.craftaro.core.nms.world.WorldCore;
|
import com.craftaro.core.nms.world.WorldCore;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
public class NmsImplementationsImpl implements NmsImplementations {
|
public class NmsImplementationsImpl implements NmsImplementations {
|
||||||
|
private final NmsEntity entity;
|
||||||
private final NMSPlayer player;
|
private final NMSPlayer player;
|
||||||
private final WorldCore world;
|
private final WorldCore world;
|
||||||
private final NmsWorldBorder worldBorder;
|
private final NmsWorldBorder worldBorder;
|
||||||
@ -21,6 +24,7 @@ public class NmsImplementationsImpl implements NmsImplementations {
|
|||||||
private final NBTCore nbt;
|
private final NBTCore nbt;
|
||||||
|
|
||||||
public NmsImplementationsImpl() {
|
public NmsImplementationsImpl() {
|
||||||
|
this.entity = new NmsEntityImpl();
|
||||||
this.player = new NMSPlayerImpl();
|
this.player = new NMSPlayerImpl();
|
||||||
this.world = new WorldCoreImpl();
|
this.world = new WorldCoreImpl();
|
||||||
this.worldBorder = new NmsWorldBorderImpl();
|
this.worldBorder = new NmsWorldBorderImpl();
|
||||||
@ -28,6 +32,11 @@ public class NmsImplementationsImpl implements NmsImplementations {
|
|||||||
this.nbt = new NBTCoreImpl();
|
this.nbt = new NBTCoreImpl();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @NotNull NmsEntity getEntity() {
|
||||||
|
return this.entity;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @NotNull NMSPlayer getPlayer() {
|
public @NotNull NMSPlayer getPlayer() {
|
||||||
return this.player;
|
return this.player;
|
||||||
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
@ -4,6 +4,7 @@ import com.craftaro.core.compatibility.CompatibleMaterial;
|
|||||||
import com.craftaro.core.compatibility.CompatibleParticleHandler;
|
import com.craftaro.core.compatibility.CompatibleParticleHandler;
|
||||||
import com.craftaro.core.nms.world.SSpawner;
|
import com.craftaro.core.nms.world.SSpawner;
|
||||||
import com.craftaro.core.nms.world.SpawnedEntity;
|
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.BlockPosition;
|
||||||
import net.minecraft.server.v1_16_R2.DifficultyDamageScaler;
|
import net.minecraft.server.v1_16_R2.DifficultyDamageScaler;
|
||||||
import net.minecraft.server.v1_16_R2.Entity;
|
import net.minecraft.server.v1_16_R2.Entity;
|
||||||
@ -37,8 +38,7 @@ public class SSpawnerImpl implements SSpawner {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public LivingEntity spawnEntity(EntityType type, String particleType, SpawnedEntity spawned,
|
public LivingEntity spawnEntity(EntityType type, String particleType, SpawnedEntity spawned, Set<XMaterial> canSpawnOn) {
|
||||||
Set<CompatibleMaterial> canSpawnOn) {
|
|
||||||
MobSpawnerData data = new MobSpawnerData();
|
MobSpawnerData data = new MobSpawnerData();
|
||||||
NBTTagCompound compound = data.getEntity();
|
NBTTagCompound compound = data.getEntity();
|
||||||
|
|
||||||
@ -47,14 +47,14 @@ public class SSpawnerImpl implements SSpawner {
|
|||||||
compound.setString("id", "minecraft:" + name);
|
compound.setString("id", "minecraft:" + name);
|
||||||
|
|
||||||
short spawnRange = 4;
|
short spawnRange = 4;
|
||||||
for (int i = 0; i < 50; i++) {
|
for (int i = 0; i < 50; ++i) {
|
||||||
@SuppressWarnings("ConstantConditions")
|
@SuppressWarnings("ConstantConditions")
|
||||||
WorldServer world = ((CraftWorld) spawnerLocation.getWorld()).getHandle();
|
WorldServer world = ((CraftWorld) this.spawnerLocation.getWorld()).getHandle();
|
||||||
|
|
||||||
Random random = world.getRandom();
|
Random random = world.getRandom();
|
||||||
double x = spawnerLocation.getX() + (random.nextDouble() - random.nextDouble()) * (double) spawnRange + 0.5D;
|
double x = this.spawnerLocation.getX() + (random.nextDouble() - random.nextDouble()) * (double) spawnRange + 0.5D;
|
||||||
double y = spawnerLocation.getY() + random.nextInt(3) - 1;
|
double y = this.spawnerLocation.getY() + random.nextInt(3) - 1;
|
||||||
double z = spawnerLocation.getZ() + (random.nextDouble() - random.nextDouble()) * (double) spawnRange + 0.5D;
|
double z = this.spawnerLocation.getZ() + (random.nextDouble() - random.nextDouble()) * (double) spawnRange + 0.5D;
|
||||||
|
|
||||||
Optional<Entity> optionalEntity = EntityTypes.a(compound, world);
|
Optional<Entity> optionalEntity = EntityTypes.a(compound, world);
|
||||||
if (!optionalEntity.isPresent()) {
|
if (!optionalEntity.isPresent()) {
|
||||||
@ -73,7 +73,7 @@ public class SSpawnerImpl implements SSpawner {
|
|||||||
|
|
||||||
EntityInsentient entityInsentient = (EntityInsentient) entity;
|
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)) {
|
if (!canSpawn(world, entityInsentient, spot, canSpawnOn)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -106,30 +106,29 @@ public class SSpawnerImpl implements SSpawner {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean canSpawn(WorldServer world, EntityInsentient entityInsentient, Location location,
|
private boolean canSpawn(WorldServer world, EntityInsentient entityInsentient, Location location, Set<XMaterial> canSpawnOn) {
|
||||||
Set<CompatibleMaterial> canSpawnOn) {
|
|
||||||
if (!world.getCubes(entityInsentient, entityInsentient.getBoundingBox())) {
|
if (!world.getCubes(entityInsentient, entityInsentient.getBoundingBox())) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
CompatibleMaterial spawnedIn = CompatibleMaterial.getMaterial(location.getBlock());
|
Optional<XMaterial> spawnedIn = CompatibleMaterial.getMaterial(location.getBlock().getType());
|
||||||
CompatibleMaterial spawnedOn = CompatibleMaterial.getMaterial(location.getBlock().getRelative(BlockFace.DOWN));
|
Optional<XMaterial> spawnedOn = CompatibleMaterial.getMaterial(location.getBlock().getRelative(BlockFace.DOWN).getType());
|
||||||
|
|
||||||
if (spawnedIn == null || spawnedOn == null) {
|
if (!spawnedIn.isPresent() || !spawnedOn.isPresent()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!spawnedIn.isAir() &&
|
if (!CompatibleMaterial.isAir(spawnedIn.get()) &&
|
||||||
spawnedIn != CompatibleMaterial.WATER &&
|
spawnedIn.get() != XMaterial.WATER &&
|
||||||
!spawnedIn.name().contains("PRESSURE") &&
|
!spawnedIn.get().name().contains("PRESSURE") &&
|
||||||
!spawnedIn.name().contains("SLAB")) {
|
!spawnedIn.get().name().contains("SLAB")) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (CompatibleMaterial material : canSpawnOn) {
|
for (XMaterial material : canSpawnOn) {
|
||||||
if (material == null) continue;
|
if (material == null) continue;
|
||||||
|
|
||||||
if (spawnedOn.equals(material) || material.isAir()) {
|
if (spawnedOn.get() == material || CompatibleMaterial.isAir(material)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,19 +1,22 @@
|
|||||||
package com.craftaro.core.nms.v1_16_R3;
|
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.anvil.AnvilCore;
|
||||||
import com.craftaro.core.nms.v1_16_R3.entity.NMSPlayerImpl;
|
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.nbt.NBTCoreImpl;
|
||||||
import com.craftaro.core.nms.v1_16_R3.world.NmsWorldBorderImpl;
|
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.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.NmsWorldBorder;
|
||||||
import com.craftaro.core.nms.world.WorldCore;
|
import com.craftaro.core.nms.world.WorldCore;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
public class NmsImplementationsImpl implements NmsImplementations {
|
public class NmsImplementationsImpl implements NmsImplementations {
|
||||||
|
private final NmsEntity entity;
|
||||||
private final NMSPlayer player;
|
private final NMSPlayer player;
|
||||||
private final WorldCore world;
|
private final WorldCore world;
|
||||||
private final NmsWorldBorder worldBorder;
|
private final NmsWorldBorder worldBorder;
|
||||||
@ -21,6 +24,7 @@ public class NmsImplementationsImpl implements NmsImplementations {
|
|||||||
private final NBTCore nbt;
|
private final NBTCore nbt;
|
||||||
|
|
||||||
public NmsImplementationsImpl() {
|
public NmsImplementationsImpl() {
|
||||||
|
this.entity = new NmsEntityImpl();
|
||||||
this.player = new NMSPlayerImpl();
|
this.player = new NMSPlayerImpl();
|
||||||
this.world = new WorldCoreImpl();
|
this.world = new WorldCoreImpl();
|
||||||
this.worldBorder = new NmsWorldBorderImpl();
|
this.worldBorder = new NmsWorldBorderImpl();
|
||||||
@ -28,6 +32,11 @@ public class NmsImplementationsImpl implements NmsImplementations {
|
|||||||
this.nbt = new NBTCoreImpl();
|
this.nbt = new NBTCoreImpl();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @NotNull NmsEntity getEntity() {
|
||||||
|
return this.entity;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @NotNull NMSPlayer getPlayer() {
|
public @NotNull NMSPlayer getPlayer() {
|
||||||
return this.player;
|
return this.player;
|
||||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user