Update for 1.16 while still supporting 1.15

This commit is contained in:
SeanOMik 2020-07-20 12:16:31 -05:00
parent aab53b8909
commit 995886672b
No known key found for this signature in database
GPG Key ID: FA4D55AC05268A88
5 changed files with 28 additions and 23 deletions

14
pom.xml
View File

@ -6,7 +6,7 @@
<groupId>net.seanomik</groupId> <groupId>net.seanomik</groupId>
<artifactId>energeticstorage</artifactId> <artifactId>energeticstorage</artifactId>
<version>0.2.2-SNAPSHOT</version> <version>0.2-SNAPSHOT</version>
<packaging>jar</packaging> <packaging>jar</packaging>
<name>EnergeticStorage</name> <name>EnergeticStorage</name>
@ -40,7 +40,9 @@
<goal>shade</goal> <goal>shade</goal>
</goals> </goals>
<configuration> <configuration>
<outputFile>D:\Code\java\spigotPlugins\_TEST_SERVER_1.15.2_\plugins\EnergeticStorage-MC-v1.15.X-v${project.version}.jar</outputFile> <!--<outputFile>D:\Code\java\spigotPlugins\_TEST_SERVER_1.14.4_\plugins\EnergeticStorage-v${project.version}.jar</outputFile>-->
<!--<outputFile>D:\Code\java\spigotPlugins\_TEST_SERVER_1.15.2_\plugins\EnergeticStorage-v${project.version}.jar</outputFile>-->
<outputFile>D:\Code\java\spigotPlugins\_TEST_SERVER_1.16.1_\plugins\EnergeticStorage-MC-v${project.version}.jar</outputFile>
<createDependencyReducedPom>false</createDependencyReducedPom> <createDependencyReducedPom>false</createDependencyReducedPom>
</configuration> </configuration>
</execution> </execution>
@ -63,7 +65,7 @@
<relocations> <relocations>
<relocation> <relocation>
<pattern>de.tr7zw.changeme.nbtapi</pattern> <pattern>de.tr7zw.changeme.nbtapi</pattern>
<shadedPattern>de.tr7zw.nbtapi</shadedPattern> <shadedPattern>de.tr7zw.nbtapi.energeticstorage</shadedPattern>
</relocation> </relocation>
</relocations> </relocations>
</configuration> </configuration>
@ -101,19 +103,19 @@
<dependency> <dependency>
<groupId>org.spigotmc</groupId> <groupId>org.spigotmc</groupId>
<artifactId>spigot</artifactId> <artifactId>spigot</artifactId>
<version>1.16.1-R0.1-SNAPSHOT</version> <version>1.15.2-R0.1-SNAPSHOT</version>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
<dependency> <dependency>
<groupId>de.tr7zw</groupId> <groupId>de.tr7zw</groupId>
<artifactId>item-nbt-api</artifactId> <artifactId>item-nbt-api</artifactId>
<version>2.4.1</version> <version>2.4.1</version>
<scope>compile</scope> <!--<scope>compile</scope>-->
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.github.WesJD.AnvilGUI</groupId> <groupId>com.github.WesJD.AnvilGUI</groupId>
<artifactId>anvilgui</artifactId> <artifactId>anvilgui</artifactId>
<version>ef71db62ecd6e14405eb7891d7d1c58341b9e61e</version> <version>ef71db62ec</version>
</dependency> </dependency>
</dependencies> </dependencies>
</project> </project>

View File

@ -1,7 +1,5 @@
package net.seanomik.energeticstorage.listeners; package net.seanomik.energeticstorage.listeners;
import de.tr7zw.changeme.nbtapi.NBTTileEntity;
import net.seanomik.energeticstorage.Skulls;
import net.seanomik.energeticstorage.files.PlayersFile; import net.seanomik.energeticstorage.files.PlayersFile;
import net.seanomik.energeticstorage.objects.ESDrive; import net.seanomik.energeticstorage.objects.ESDrive;
import net.seanomik.energeticstorage.objects.ESSystem; import net.seanomik.energeticstorage.objects.ESSystem;
@ -28,8 +26,7 @@ public class BlockBreakListener implements Listener {
Block block = event.getBlock(); Block block = event.getBlock();
Player player = event.getPlayer(); Player player = event.getPlayer();
NBTTileEntity blockNBT = new NBTTileEntity(block.getState()); if (Utils.isBlockASystem(block)) {
if (blockNBT.getCompound("SkullOwner").getCompound("Properties").getCompoundList("textures").get(0).getString("Value").equals(Skulls.Computer.getTexture())) {
ESSystem esSystem = Utils.findSystemAtLocation(block.getLocation()); ESSystem esSystem = Utils.findSystemAtLocation(block.getLocation());
if (esSystem != null) { if (esSystem != null) {

View File

@ -14,10 +14,7 @@ import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockPlaceEvent; import org.bukkit.event.block.BlockPlaceEvent;
import java.util.Arrays; import java.util.*;
import java.util.LinkedList;
import java.util.List;
import java.util.UUID;
public class BlockPlaceListener implements Listener { public class BlockPlaceListener implements Listener {
@ -27,9 +24,7 @@ public class BlockPlaceListener implements Listener {
Block block = event.getBlock(); Block block = event.getBlock();
Player player = event.getPlayer(); Player player = event.getPlayer();
NBTTileEntity blockNBT = new NBTTileEntity(block.getState()); if (Utils.isBlockASystem(block)) {
if (blockNBT.getCompound("SkullOwner").getCompound("Properties").getCompoundList("textures").get(0).getString("Value").equals(Skulls.Computer.getTexture())) {
if (PermissionChecks.canCreateSystem(player)) { if (PermissionChecks.canCreateSystem(player)) {
ESSystem newSystem = new ESSystem(player.getUniqueId(), UUID.randomUUID(), block.getLocation()); ESSystem newSystem = new ESSystem(player.getUniqueId(), UUID.randomUUID(), block.getLocation());
PlayersFile.savePlayerSystem(newSystem); PlayersFile.savePlayerSystem(newSystem);
@ -41,7 +36,7 @@ public class BlockPlaceListener implements Listener {
Reference.ES_SYSTEMS.replace(player.getUniqueId(), playerESSystems); Reference.ES_SYSTEMS.replace(player.getUniqueId(), playerESSystems);
} else { } else {
Reference.ES_SYSTEMS.put(player.getUniqueId(), Arrays.asList(newSystem)); Reference.ES_SYSTEMS.put(player.getUniqueId(), Collections.singletonList(newSystem));
} }
} }
} }

View File

@ -1,7 +1,5 @@
package net.seanomik.energeticstorage.listeners; package net.seanomik.energeticstorage.listeners;
import de.tr7zw.changeme.nbtapi.NBTTileEntity;
import net.seanomik.energeticstorage.Skulls;
import net.seanomik.energeticstorage.objects.ESSystem; import net.seanomik.energeticstorage.objects.ESSystem;
import net.seanomik.energeticstorage.utils.PermissionChecks; import net.seanomik.energeticstorage.utils.PermissionChecks;
import net.seanomik.energeticstorage.utils.Reference; import net.seanomik.energeticstorage.utils.Reference;
@ -24,9 +22,7 @@ public class PlayerInteractListener implements Listener {
Block block = event.getClickedBlock(); Block block = event.getClickedBlock();
Player player = event.getPlayer(); Player player = event.getPlayer();
NBTTileEntity blockNBT = new NBTTileEntity(block.getState()); if (Utils.isBlockASystem(block)) {
if (blockNBT.getCompound("SkullOwner").getCompound("Properties").getCompoundList("textures").get(0).getString("Value").equals(Skulls.Computer.getTexture())) {
event.setCancelled(true); event.setCancelled(true);
ESSystem esSystem = Utils.findSystemAtLocation(block.getLocation()); ESSystem esSystem = Utils.findSystemAtLocation(block.getLocation());

View File

@ -1,10 +1,13 @@
package net.seanomik.energeticstorage.utils; package net.seanomik.energeticstorage.utils;
import de.tr7zw.changeme.nbtapi.NBTTileEntity;
import net.seanomik.energeticstorage.Skulls;
import net.seanomik.energeticstorage.objects.ESSystem; import net.seanomik.energeticstorage.objects.ESSystem;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.inventory.meta.ItemMeta;
@ -124,4 +127,16 @@ public class Utils {
return false; return false;
} }
public static boolean isBlockASystem(Block block) {
NBTTileEntity blockNBT = new NBTTileEntity(block.getState());
String version = Bukkit.getServer().getClass().getPackage().getName().split("\\.")[3];
if (version.equals("v1_15_R1")) {
return blockNBT.getCompound("Owner").getCompound("Properties").getCompoundList("textures").get(0).getString("Value").equals(Skulls.Computer.getTexture());
} else if (version.equals("v1_16_R1")) {
return blockNBT.getCompound("SkullOwner").getCompound("Properties").getCompoundList("textures").get(0).getString("Value").equals(Skulls.Computer.getTexture());
}
return false;
}
} }