Added 1.16.4 Compatibility

This might have bug due to inability to test it througtly
This commit is contained in:
White_SoftwareDevelopment 2020-11-05 07:56:48 -05:00
parent 967b9f2ce3
commit 87a59b1c75
10 changed files with 303 additions and 64 deletions

82
.gitignore vendored
View File

@ -1,12 +1,80 @@
/bin/
/target/
!.mvn/wrapper/maven-wrapper.jar
/.idea/
*.iml
/.settings/
### STS ###
.apt_generated
.classpath
.project
.factorypath
.project
.settings
.springBeans
.sts4-cache
/.vscode/
### IntelliJ IDEA ###
.idea
*.iws
*.iml
*.ipr
### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/
/build/
nb-configuration.xml
nbactions.xml
settings.xml
# BlueJ files
*.ctxt
# Mobile Tools for Java (J2ME)
.mtj.tmp/
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*
# Compiled source #
###################
*.com
*.class
*.dll
*.exe
*.o
*.so
# Packages #
############
# it's better to unpack these files and commit the raw source
# git has its own built in compression methods
*.7z
*.dmg
*.gz
*.iso
*.jar
*.rar
*.tar
*.tar.gz
*.nar
*.ear
*.zip
*.war
# Logs and databases #
######################
*.log
# OS generated files #
######################
.DS_Store
.DS_Store?
._*
.Spotlight-V100
.Trashes
ehthumbs.db
Thumbs.db
/nbproject/

View File

@ -0,0 +1,9 @@
CALL mvn install:install-file -Dfile=%CD%/lib/PlotSquared-Bukkit-4.4.495.jar ^
-DgroupId=com.plotsquared ^
-DartifactId=PlotSquared ^
-Dversion=5.1 ^
-Dpackaging=jar ^
-DgeneratePom=true
pause

47
pom.xml
View File

@ -6,7 +6,7 @@
<groupId>de.epiceric</groupId>
<artifactId>ShopChest</artifactId>
<version>1.13-SNAPSHOT</version>
<version>1.16.4-R0.1-SNAPSHOT-0.0.1</version>
<name>ShopChest</name>
<url>https://www.spigotmc.org/resources/shopchest.11431/</url>
@ -94,12 +94,14 @@
</repositories>
<dependencies>
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.16.2-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<!-- SPIGOT -->
<!--Spigot API https://www.spigotmc.org/wiki/spigot-maven/-->
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.16.4-R0.1-SNAPSHOT</version> <!-- versions https://hub.spigotmc.org/nexus/content/repositories/snapshots/org/spigotmc/spigot-api/ -->
<scope>provided</scope>
</dependency>
<dependency>
<groupId>net.milkbowl.vault</groupId>
<artifactId>VaultAPI</artifactId>
@ -112,12 +114,26 @@
<version>5.4.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<!-- use "install_windows_maven_local_PlotSquared_dependency.bat" to install this dependency locally -->
<!-- <dependency>
<groupId>com.plotsquared</groupId>
<artifactId>PlotSquared</artifactId>
<version>5.1</version>
<scope>provided</scope>
</dependency>
</dependency>-->
<!-- PlotSquared Core API -->
<dependency>
<groupId>com.plotsquared</groupId>
<artifactId>PlotSquared-Core</artifactId>
<version>5.13.3</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.jetbrains/annotations -->
<dependency>
<groupId>org.jetbrains</groupId>
<artifactId>annotations</artifactId>
<version>16.0.1</version>
</dependency>
<dependency>
<groupId>com.github.rlf</groupId>
<artifactId>uSkyBlock-API</artifactId>
@ -191,6 +207,19 @@
<artifactId>slf4j-jdk14</artifactId>
<version>1.7.26</version>
</dependency>
<dependency>
<groupId>com.github.white-sdev</groupId>
<artifactId>White_Validations</artifactId>
<version>1.0.2</version>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
<build>

View File

@ -1,6 +1,6 @@
package de.epiceric.shopchest.exceptions;
public class ChestNotFoundException extends Exception {
public class ChestNotFoundException extends ShopChestException {
private static final long serialVersionUID = -6446875473671870708L;
public ChestNotFoundException(String message) {

View File

@ -1,6 +1,6 @@
package de.epiceric.shopchest.exceptions;
public class NotEnoughSpaceException extends Exception {
public class NotEnoughSpaceException extends ShopChestException {
private static final long serialVersionUID = 3718475607700458355L;
public NotEnoughSpaceException(String message) {

View File

@ -0,0 +1,68 @@
/*
* The MIT License (MIT)
Copyright (c) 2016 Eric
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
package de.epiceric.shopchest.exceptions;
//import static org.white_sdev.white_validations.parameters.ParameterValidator.notNullValidation;
/**
*
* @author <a href="mailto:obed.vazquez@gmail.com">Obed Vazquez</a>
* @since Nov 4, 2020
*/
public class ShopChestException extends RuntimeException {
public ShopChestException(String string, Exception e) {
super(string, e);
}
public ShopChestException(String string) {
super(string);
}
public String getCauses() {
final String BREAKLINE = "\n";
final String BREAKLINE_REGEX = "[[\\r\\n]\\r\\n]";
String causes = "Cause: " + getMessage() + BREAKLINE;
String causeMessage;
String lastAt = "";
for (Throwable cause = this.getCause(); cause != null; cause = cause.getCause()) {
causeMessage = cause.getMessage();
if (causeMessage != null && !causeMessage.isBlank()) {
String[] causedBy = causeMessage.split(BREAKLINE_REGEX);
causes += "Cause: " + causedBy[0] + BREAKLINE;
//causes+="---"+cause.getLocalizedMessage();
//lastAt=causedBy.length>1?causedBy[1]:"";
}
}
causes += lastAt;
return causes;
}
}

View File

@ -1,6 +1,6 @@
package de.epiceric.shopchest.exceptions;
public class WorldNotFoundException extends Exception {
public class WorldNotFoundException extends ShopChestException {
private static final long serialVersionUID = -555886332156936972L;
public WorldNotFoundException(String worldName) {

View File

@ -8,7 +8,10 @@ import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import de.epiceric.shopchest.ShopChest;
import de.epiceric.shopchest.exceptions.ShopChestException;
import de.epiceric.shopchest.utils.Utils;
import java.lang.reflect.Constructor;
import java.util.logging.Level;
public class ArmorStandWrapper {
@ -20,7 +23,7 @@ public class ArmorStandWrapper {
private final UUID uuid = UUID.randomUUID();
private final int entityId;
private ShopChest plugin;
private final ShopChest plugin;
private Object entity;
private Location location;
private String customName;
@ -34,18 +37,26 @@ public class ArmorStandWrapper {
public void setVisible(Player player, boolean visible) {
try {
plugin.getLogger().finest("ArmorStandWrapper::setVisible(player,visible): Starting:");
if (visible) {
plugin.getLogger().log(Level.FINE, "ArmorStandWrapper::setVisible(player,visible): Getting: Utils.createDataWatcher({0}, null) ", customName);
//Utils.plugin=plugin; //activate logs
Object dataWatcher = Utils.createDataWatcher(customName, null);
plugin.getLogger().log(Level.FINE, "ArmorStandWrapper::setVisible(player,visible): Obtained={0}", dataWatcher);
Utils.sendPacket(plugin, Utils.createPacketSpawnEntity(plugin, entityId, uuid, location, EntityType.ARMOR_STAND), player);
Utils.sendPacket(plugin, packetPlayOutEntityMetadataClass.getConstructor(int.class, dataWatcherClass, boolean.class)
.newInstance(entityId, dataWatcher, true), player);
Constructor constructor=packetPlayOutEntityMetadataClass!=null?
packetPlayOutEntityMetadataClass.getConstructor(int.class, dataWatcherClass, boolean.class):null;
Object object=constructor!=null && dataWatcher!=null ?
constructor.newInstance(entityId, dataWatcher, true):null;
if(object!=null) Utils.sendPacket(plugin, object, player);
} else if (entityId != -1) {
Utils.sendPacket(plugin, packetPlayOutEntityDestroyClass.getConstructor(int[].class).newInstance((Object) new int[]{entityId}), player);
}
} catch (ReflectiveOperationException e) {
plugin.getLogger().severe("Could not change hologram visibility");
plugin.debug("Could not change armor stand visibility");
plugin.debug(e);
plugin.getLogger().severe("ArmorStandWrapper::setVisible(player,visible): Error: Could not change hologram visibility to visible");
throw new ShopChestException("Could not change hologram visibility to visible",e);
}
}
@ -103,9 +114,15 @@ public class ArmorStandWrapper {
}
public void remove() {
for (Player player : location.getWorld().getPlayers()) {
setVisible(player, false);
}
try{
plugin.getLogger().fine("ArmorStandWrapper::remove(): Starting:");
for (Player player : location.getWorld().getPlayers()) {
setVisible(player, false);
}
}catch(Exception e){
plugin.getLogger().severe("ArmorStandWrapper::remove(): Error: Error when -removing- [hologram?]");
throw new ShopChestException("Error when -removing- [hologram?]",e);
}
}
public int getEntityId() {

View File

@ -13,6 +13,8 @@ import org.bukkit.entity.Player;
import de.epiceric.shopchest.ShopChest;
import de.epiceric.shopchest.config.Config;
import de.epiceric.shopchest.exceptions.ShopChestException;
import static org.white_sdev.white_validations.parameters.ParameterValidator.notNullValidation;
public class Hologram {
// concurrent since update task is in async thread
@ -137,9 +139,16 @@ public class Hologram {
}
private void togglePlayer(Player p, boolean visible) {
for (ArmorStandWrapper wrapper : wrappers) {
wrapper.setVisible(p, visible);
}
notNullValidation(new Object[]{p,visible},"the provided Player and visible must be specified to toggle the player visibility.");
try{
plugin.getLogger().fine("Hologram::togglePlayer(Player,visible): Starting:");
for (ArmorStandWrapper wrapper : wrappers) {
if(wrapper!=null) wrapper.setVisible(p, visible);
}
}catch(Exception e){
plugin.getLogger().severe("Hologram::togglePlayer(Player,visible): Error: When -toggleqing Player- [hologram visibility?]");
throw new ShopChestException("Error when -toggleqing Player- [hologram visibility?]",e);
}
}
/**
@ -167,42 +176,48 @@ public class Hologram {
}
private void addLine(int line, String text, boolean forceUpdateLine) {
if (text == null || text.isEmpty()) return;
try{
plugin.getLogger().fine("Hologram::addLine(line,text,forceUpdateLine): Starting:");
if (text == null || text.isEmpty()) return;
if (line >= wrappers.size()) {
line = wrappers.size();
}
if (line >= wrappers.size()) {
line = wrappers.size();
}
text = ChatColor.translateAlternateColorCodes('&', text);
text = ChatColor.translateAlternateColorCodes('&', text);
if (Config.hologramFixedBottom) {
for (int i = 0; i < line; i++) {
ArmorStandWrapper wrapper = wrappers.get(i);
wrapper.setLocation(wrapper.getLocation().add(0, 0.25, 0));
}
} else {
for (int i = line; i < wrappers.size(); i++) {
ArmorStandWrapper wrapper = wrappers.get(i);
wrapper.setLocation(wrapper.getLocation().subtract(0, 0.25, 0));
}
}
if (Config.hologramFixedBottom) {
for (int i = 0; i < line; i++) {
ArmorStandWrapper wrapper = wrappers.get(i);
wrapper.setLocation(wrapper.getLocation().add(0, 0.25, 0));
}
} else {
for (int i = line; i < wrappers.size(); i++) {
ArmorStandWrapper wrapper = wrappers.get(i);
wrapper.setLocation(wrapper.getLocation().subtract(0, 0.25, 0));
}
}
Location loc = getLocation();
Location loc = getLocation();
if (!Config.hologramFixedBottom) {
loc.subtract(0, line * 0.25, 0);
}
if (!Config.hologramFixedBottom) {
loc.subtract(0, line * 0.25, 0);
}
ArmorStandWrapper wrapper = new ArmorStandWrapper(plugin, loc, text, false);
wrappers.add(line, wrapper);
ArmorStandWrapper wrapper = new ArmorStandWrapper(plugin, loc, text, false);
wrappers.add(line, wrapper);
if (forceUpdateLine) {
for (Player player : location.getWorld().getPlayers()) {
if (viewers.contains(player.getUniqueId())) {
wrapper.setVisible(player, true);
}
}
}
if (forceUpdateLine) {
for (Player player : location.getWorld().getPlayers()) {
if (viewers.contains(player.getUniqueId())) {
wrapper.setVisible(player, true);
}
}
}
}catch(Exception e){
plugin.getLogger().severe("Hologram::addLine(line,text,forceUpdateLine): Error: When -adding line- [on holograms?]");
throw new ShopChestException("Error when -adding line- [on holograms?]",e);
}
}
/**

View File

@ -41,8 +41,11 @@ import de.epiceric.shopchest.language.Replacement;
import de.epiceric.shopchest.nms.CustomBookMeta;
import de.epiceric.shopchest.nms.JsonBuilder;
import de.epiceric.shopchest.shop.Shop;
import java.util.logging.Level;
public class Utils {
public static ShopChest plugin;
/**
* Check if two items are similar to each other
@ -341,8 +344,15 @@ public class Utils {
*/
public static Class<?> getNMSClass(String className) {
try {
return Class.forName("net.minecraft.server." + getServerVersion() + "." + className);
if(plugin!=null)plugin.getLogger().fine("Utils::getNMSClass(className): Starting:");
// org.bukkit.command.SimpleCommandMap test3;
// net.minecraft.server.v1_15_R1.EntityHuman test2;
// net.minecraft.server.v1_12_R1.EntityPlayer test;
Class<?> clazz=Class.forName("net.minecraft.server." + getServerVersion() + "." + className);
if(plugin!=null)plugin.getLogger().log(Level.FINE, "Utils::getNMSClass(className): obtained class: {0}", clazz);
return clazz;
} catch (ClassNotFoundException e) {
if(plugin!=null)plugin.getLogger().warning("Utils::getNMSClass(className): Impossible to obtain the NMSClass [net.minecraft.server." + getServerVersion() + ".className]");
return null;
}
}
@ -360,13 +370,14 @@ public class Utils {
}
/**
* Create a NMS data watcher object to send via a {@code PacketPlayOutEntityMetadata} packet.
* Gravity will be disabled and the custom name will be displayed if available.
* Create a NMS data watcher object to send via a {@code PacketPlayOutEntityMetadata} packet.Gravity will be disabled and the custom name will be displayed if available.
* @param customName Custom Name of the entity or {@code null}
* @param nmsItemStack NMS ItemStack or {@code null} if armor stand
* @return
*/
public static Object createDataWatcher(String customName, Object nmsItemStack) {
String version = getServerVersion();
if(plugin!=null)plugin.getLogger().log(Level.FINE, "Utils::createDataWatcher(customName, nmsItemStack): Version={0}", version);
int majorVersion = getMajorVersion();
try {
@ -380,6 +391,8 @@ public class Utils {
byte armorStandFlags = nmsItemStack == null ? (byte) 0b10000 : 0; // marker (since 1.8_R2)
Object dataWatcher = dataWatcherClass.getConstructor(entityClass).newInstance((Object) null);
if(plugin!=null)plugin.getLogger().log(Level.FINE, "Utils::createDataWatcher(customName, nmsItemStack): obtained dataWatcher Object : {0}", dataWatcher);
if (majorVersion < 9) {
if (getRevision() == 1) armorStandFlags = 0; // Marker not supported on 1.8_R1
@ -392,8 +405,12 @@ public class Utils {
a.invoke(dataWatcher, 10, nmsItemStack == null ? armorStandFlags : nmsItemStack); // item / armor stand flags
} else {
Method register = dataWatcherClass.getMethod("register", dataWatcherObjectClass, Object.class);
if(plugin!=null)plugin.getLogger().log(Level.FINE, "Utils::createDataWatcher(customName, nmsItemStack): IMPORTANT register: {0}", register);
String[] dataWatcherObjectFieldNames;
/*
* https://wiki.vg/Pre-release_protocol#Entity_Metadata
*/
if ("v1_9_R1".equals(version)) {
dataWatcherObjectFieldNames = new String[] {"ax", "ay", "aA", "az", "aB", null, "c", "a"};
} else if ("v1_9_R2".equals(version)){
@ -413,19 +430,35 @@ public class Utils {
} else if ("v1_16_R1".equals(version)) {
dataWatcherObjectFieldNames = new String[] {"T", "AIR_TICKS", "ay", "ax", "az", "aA", "ITEM", "b"};
} else if ("v1_16_R2".equals(version)) {
if(plugin!=null)plugin.getLogger().fine("Utils::createDataWatcher(customName, nmsItemStack):: Using Version v1_16_R2");
dataWatcherObjectFieldNames = new String[] {"S", "AIR_TICKS", "ar", "aq", "as", "at", "ITEM", "b"};
} else if ("v1_16_R3".equals(version)) { // 1.16.4
if(plugin!=null)plugin.getLogger().fine("Utils::createDataWatcher(customName, nmsItemStack):: Using Version v1_16_R2");
dataWatcherObjectFieldNames = new String[] {"S", "AIR_TICKS", "ar", "aq", "as", "at", "ITEM", "b"};
} else {
return null;
if(plugin!=null)plugin.getLogger().info("Utils::createDataWatcher(customName, nmsItemStack):: Using Not explicity supported Version");
dataWatcherObjectFieldNames = new String[] {"S", "AIR_TICKS", "ar", "aq", "as", "at", "ITEM", "b"};
}
/*
* https://github.com/Bukkit/mc-dev/blob/master/net/minecraft/server/Entity.java
*/
Field fEntityFlags = entityClass.getDeclaredField(dataWatcherObjectFieldNames[0]);
if(plugin!=null)plugin.getLogger().log(Level.FINE, "Utils::createDataWatcher(customName, nmsItemStack): fEntityFlags : {0}", fEntityFlags);
Field fAirTicks = entityClass.getDeclaredField(dataWatcherObjectFieldNames[1]);
if(plugin!=null)plugin.getLogger().log(Level.FINE, "Utils::createDataWatcher(customName, nmsItemStack): fAirTicks : {0}", fAirTicks);
Field fNameVisible = entityClass.getDeclaredField(dataWatcherObjectFieldNames[2]);
if(plugin!=null)plugin.getLogger().log(Level.FINE, "Utils::createDataWatcher(customName, nmsItemStack): fNameVisible : {0}", fNameVisible);
Field fCustomName = entityClass.getDeclaredField(dataWatcherObjectFieldNames[3]);
if(plugin!=null)plugin.getLogger().log(Level.FINE, "Utils::createDataWatcher(customName, nmsItemStack): fEntityFlags : {0}", fCustomName);
Field fSilent = entityClass.getDeclaredField(dataWatcherObjectFieldNames[4]);
if(plugin!=null)plugin.getLogger().log(Level.FINE, "Utils::createDataWatcher(customName, nmsItemStack): fEntityFlags : {0}", fSilent);
Field fNoGravity = majorVersion >= 10 ? entityClass.getDeclaredField(dataWatcherObjectFieldNames[5]) : null;
if(plugin!=null)plugin.getLogger().log(Level.FINE, "Utils::createDataWatcher(customName, nmsItemStack): fEntityFlags : {0}", fNoGravity);
Field fItem = entityItemClass.getDeclaredField(dataWatcherObjectFieldNames[6]);
if(plugin!=null)plugin.getLogger().log(Level.FINE, "Utils::createDataWatcher(customName, nmsItemStack): fEntityFlags : {0}", fItem);
Field fArmorStandFlags = entityArmorStandClass.getDeclaredField(dataWatcherObjectFieldNames[7]);
if(plugin!=null)plugin.getLogger().log(Level.FINE, "Utils::createDataWatcher(customName, nmsItemStack): fEntityFlags : {0}", fArmorStandFlags);
fEntityFlags.setAccessible(true);
fAirTicks.setAccessible(true);