Fixes #11
This commit is contained in:
parent
37ac1846d5
commit
e20fc16a81
|
@ -6,11 +6,12 @@
|
|||
<sourceOutputDir name="target/generated-sources/annotations" />
|
||||
<sourceTestOutputDir name="target/generated-test-sources/test-annotations" />
|
||||
<outputRelativeToContentRoot value="true" />
|
||||
<module name="EnergeticStorage" />
|
||||
<module name="energeticstorage" />
|
||||
</profile>
|
||||
</annotationProcessing>
|
||||
<bytecodeTargetLevel>
|
||||
<module name="EnergeticStorage" target="1.8" />
|
||||
<module name="energeticstorage" target="1.8" />
|
||||
</bytecodeTargetLevel>
|
||||
</component>
|
||||
</project>
|
|
@ -0,0 +1,40 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="RemoteRepositoriesConfiguration">
|
||||
<remote-repository>
|
||||
<option name="id" value="codemc-repo" />
|
||||
<option name="name" value="codemc-repo" />
|
||||
<option name="url" value="https://repo.codemc.org/repository/maven-public/" />
|
||||
</remote-repository>
|
||||
<remote-repository>
|
||||
<option name="id" value="central" />
|
||||
<option name="name" value="Central Repository" />
|
||||
<option name="url" value="https://repo.maven.apache.org/maven2" />
|
||||
</remote-repository>
|
||||
<remote-repository>
|
||||
<option name="id" value="jitpack.io" />
|
||||
<option name="name" value="jitpack.io" />
|
||||
<option name="url" value="https://jitpack.io" />
|
||||
</remote-repository>
|
||||
<remote-repository>
|
||||
<option name="id" value="sonatype" />
|
||||
<option name="name" value="sonatype" />
|
||||
<option name="url" value="https://oss.sonatype.org/content/groups/public/" />
|
||||
</remote-repository>
|
||||
<remote-repository>
|
||||
<option name="id" value="spigotmc-repo" />
|
||||
<option name="name" value="spigotmc-repo" />
|
||||
<option name="url" value="https://hub.spigotmc.org/nexus/content/repositories/snapshots/" />
|
||||
</remote-repository>
|
||||
<remote-repository>
|
||||
<option name="id" value="central" />
|
||||
<option name="name" value="Maven Central repository" />
|
||||
<option name="url" value="https://repo1.maven.org/maven2" />
|
||||
</remote-repository>
|
||||
<remote-repository>
|
||||
<option name="id" value="jboss.community" />
|
||||
<option name="name" value="JBoss Community repository" />
|
||||
<option name="url" value="https://repository.jboss.org/nexus/content/repositories/public/" />
|
||||
</remote-repository>
|
||||
</component>
|
||||
</project>
|
22
pom.xml
22
pom.xml
|
@ -53,7 +53,8 @@
|
|||
<!--<outputFile>D:\Code\java\spigotPlugins\_TEST_SERVER_1.16.2_\plugins\EnergeticStorage-MC-v${project.version}.jar</outputFile>-->
|
||||
<!--<outputFile>D:\Code\java\spigotPlugins\_TEST_SERVER_PAPER_1.16.1_\plugins\EnergeticStorage-v${project.version}.jar</outputFile>-->
|
||||
<!--<outputFile>D:\Code\java\spigotPlugins\_TEST_SERVER_PAPER_1.16.2_\plugins\EnergeticStorage-v${project.version}.jar</outputFile>-->
|
||||
<outputFile>D:\Code\java\spigotPlugins\_TEST_SERVER_1.16.4_\plugins\EnergeticStorage-v${project.version}.jar</outputFile>
|
||||
<!--<outputFile>D:\Code\java\spigotPlugins\_TEST_SERVER_1.16.4_\plugins\EnergeticStorage-v${project.version}.jar</outputFile>-->
|
||||
<outputFile>D:\Code\java\spigotPlugins\_TEST_SERVER_PAPER_1.16.4_\plugins\EnergeticStorage-v${project.version}.jar</outputFile>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
|
@ -90,19 +91,34 @@
|
|||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.spigotmc</groupId>
|
||||
<artifactId>spigot</artifactId>
|
||||
<artifactId>spigot-api</artifactId>
|
||||
<version>1.14-R0.1-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>de.tr7zw</groupId>
|
||||
<artifactId>item-nbt-api</artifactId>
|
||||
<version>2.6.0</version>
|
||||
<version>2.7.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.github.WesJD.AnvilGUI</groupId>
|
||||
<artifactId>anvilgui</artifactId>
|
||||
<version>master-5d0f592c63-1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.googlecode.json-simple</groupId>
|
||||
<artifactId>json-simple</artifactId>
|
||||
<version>1.1.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-text</artifactId>
|
||||
<version>1.9</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.jetbrains</groupId>
|
||||
<artifactId>annotations</artifactId>
|
||||
<version>13.0</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
|
|
|
@ -1,14 +1,10 @@
|
|||
package net.seanomik.energeticstorage;
|
||||
|
||||
import com.mojang.authlib.GameProfile;
|
||||
import com.mojang.authlib.properties.Property;
|
||||
import net.seanomik.energeticstorage.utils.Utils;
|
||||
import de.tr7zw.changeme.nbtapi.NBTCompound;
|
||||
import de.tr7zw.changeme.nbtapi.NBTItem;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.SkullMeta;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.UUID;
|
||||
|
||||
public enum Skulls {
|
||||
|
||||
|
@ -19,30 +15,33 @@ public enum Skulls {
|
|||
private ItemStack item;
|
||||
private String name;
|
||||
private String texture;
|
||||
private String uuid;
|
||||
|
||||
Skulls(String name, int id, String texture, String uuid) {
|
||||
item = createSkull(texture, name);
|
||||
this.texture = texture;
|
||||
this.name = name;
|
||||
this.uuid = uuid;
|
||||
item = createSkull(uuid, name);
|
||||
}
|
||||
|
||||
private ItemStack createSkull (String url, String name) {
|
||||
ItemStack head = new ItemStack(Material.PLAYER_HEAD, 1, (short) 3);
|
||||
if (url.isEmpty()) return head;
|
||||
|
||||
SkullMeta headMeta = (SkullMeta) head.getItemMeta();
|
||||
GameProfile gameProfile = new GameProfile(UUID.randomUUID(), null);
|
||||
NBTItem headNBT = new NBTItem(head);
|
||||
String version = Bukkit.getServer().getClass().getPackage().getName().split("\\.")[3];
|
||||
|
||||
gameProfile.getProperties().put("textures", new Property("textures", url));
|
||||
|
||||
try {
|
||||
Field profileField = headMeta.getClass().getDeclaredField("profile");
|
||||
profileField.setAccessible(true);
|
||||
profileField.set(headMeta, gameProfile);
|
||||
} catch (IllegalArgumentException | NoSuchFieldException | SecurityException | IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
NBTCompound ownerNBT;
|
||||
if (version.startsWith("v1_16")) {
|
||||
ownerNBT = headNBT.addCompound("SkullOwner");
|
||||
} else {
|
||||
ownerNBT = headNBT.addCompound("Owner");
|
||||
}
|
||||
head.setItemMeta(headMeta);
|
||||
|
||||
ownerNBT.addCompound("Properties").getCompoundList("textures").addCompound().setString("Value", texture);
|
||||
ownerNBT.setString("Id", uuid);
|
||||
head = headNBT.getItem();
|
||||
|
||||
return head;
|
||||
}
|
||||
|
||||
|
|
|
@ -72,6 +72,11 @@ public class ESGiveCommand implements TabExecutor {
|
|||
return true;
|
||||
}
|
||||
|
||||
if (args.length == 0) {
|
||||
sender.sendMessage(generateCommandUsage(args));
|
||||
return true;
|
||||
}
|
||||
|
||||
switch (args[0]) { // Switch on item type
|
||||
case "save":
|
||||
PlayersFile.savePlayerSystems(Reference.ES_SYSTEMS.get(((Player) sender).getUniqueId()));
|
||||
|
|
|
@ -240,6 +240,7 @@ public class PlayersFile extends YamlConfiguration {
|
|||
getConfig().set(systemPath + "drives", null);
|
||||
|
||||
for (ESDrive drive : esSystem.getESDrives()) {
|
||||
if (drive == null) continue;
|
||||
getConfig().set(systemPath + "drives." + drive.getUUID() + ".size", drive.getSize());
|
||||
|
||||
JSONArray itemsJson = new JSONArray();
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package net.seanomik.energeticstorage.gui;
|
||||
|
||||
import de.tr7zw.changeme.nbtapi.NBTItem;
|
||||
import net.seanomik.energeticstorage.EnergeticStorage;
|
||||
import net.seanomik.energeticstorage.files.PlayersFile;
|
||||
import net.seanomik.energeticstorage.objects.ESDrive;
|
||||
import net.seanomik.energeticstorage.objects.ESSystem;
|
||||
|
@ -58,7 +59,9 @@ public class ESDriveGUI implements InventoryHolder, Listener {
|
|||
for (int i = 2; i < esSystem.getESDrives().size() + 2; i++) {
|
||||
ESDrive drive = esSystem.getESDrives().get(i - 2);
|
||||
|
||||
inv.setItem(i , drive.getDriveItem());
|
||||
if (drive != null) {
|
||||
inv.setItem(i, drive.getDriveItem());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -149,7 +152,11 @@ public class ESDriveGUI implements InventoryHolder, Listener {
|
|||
return;
|
||||
} else {
|
||||
Player player = (Player) event.getPlayer();
|
||||
PlayersFile.savePlayerSystem(openSystems.get(player.getUniqueId()));
|
||||
ESSystem openSystem = openSystems.get(player.getUniqueId());
|
||||
// Serialize null drives
|
||||
openSystem.getESDrives().removeIf(Objects::isNull);
|
||||
|
||||
PlayersFile.savePlayerSystem(openSystem);
|
||||
|
||||
openSystems.remove(player);
|
||||
}
|
||||
|
@ -219,12 +226,12 @@ public class ESDriveGUI implements InventoryHolder, Listener {
|
|||
|
||||
Reference.ES_TERMINAL_GUI.openInventory(player, esSystem);
|
||||
} else if (slot != 1 && slot != 7 && slot != 8) {
|
||||
if (Utils.isItemADrive(cursor)) {
|
||||
event.setCancelled(false);
|
||||
|
||||
if (Utils.isItemADrive(clickedItem)) {
|
||||
List<ESDrive> drives = esSystem.getESDrives();
|
||||
drives.remove(slot - 2);
|
||||
drives.set(slot - 2, null);
|
||||
esSystem.setESDrives(drives);
|
||||
|
||||
event.setCancelled(false);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package net.seanomik.energeticstorage.listeners;
|
||||
|
||||
import net.seanomik.energeticstorage.EnergeticStorage;
|
||||
import net.seanomik.energeticstorage.files.PlayersFile;
|
||||
import net.seanomik.energeticstorage.objects.ESDrive;
|
||||
import net.seanomik.energeticstorage.objects.ESSystem;
|
||||
|
@ -7,7 +8,9 @@ import net.seanomik.energeticstorage.utils.ItemConstructor;
|
|||
import net.seanomik.energeticstorage.utils.PermissionChecks;
|
||||
import net.seanomik.energeticstorage.utils.Reference;
|
||||
import net.seanomik.energeticstorage.utils.Utils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.Player;
|
||||
|
@ -36,15 +39,19 @@ public class BlockBreakListener implements Listener {
|
|||
}
|
||||
|
||||
// Remove the system from cache and storage
|
||||
Bukkit.getScheduler().runTaskAsynchronously(EnergeticStorage.getPlugin(), () -> {
|
||||
PlayersFile.removePlayerSystem(player.getUniqueId(), esSystem.getUUID());
|
||||
|
||||
List<ESSystem> systems = new LinkedList<>(Reference.ES_SYSTEMS.get(player.getUniqueId()));
|
||||
systems.removeIf(esSystem::equals);
|
||||
Reference.ES_SYSTEMS.replace(player.getUniqueId(), systems);
|
||||
});
|
||||
|
||||
// Drop an ES System
|
||||
// Only drop the system if they're not in creative.
|
||||
event.setDropItems(false);
|
||||
if (player.getGameMode() != GameMode.CREATIVE) {
|
||||
event.getBlock().getLocation().getWorld().dropItemNaturally(event.getBlock().getLocation(), ItemConstructor.createSystemBlock());
|
||||
}
|
||||
} else {
|
||||
event.setCancelled(true);
|
||||
player.sendMessage(Reference.PREFIX + ChatColor.RED + "You are not trusted to this system!");
|
||||
|
|
|
@ -1,12 +1,14 @@
|
|||
package net.seanomik.energeticstorage.listeners;
|
||||
|
||||
import de.tr7zw.changeme.nbtapi.NBTTileEntity;
|
||||
import net.seanomik.energeticstorage.EnergeticStorage;
|
||||
import net.seanomik.energeticstorage.Skulls;
|
||||
import net.seanomik.energeticstorage.files.PlayersFile;
|
||||
import net.seanomik.energeticstorage.objects.ESSystem;
|
||||
import net.seanomik.energeticstorage.utils.PermissionChecks;
|
||||
import net.seanomik.energeticstorage.utils.Reference;
|
||||
import net.seanomik.energeticstorage.utils.Utils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.Player;
|
||||
|
@ -26,6 +28,8 @@ public class BlockPlaceListener implements Listener {
|
|||
|
||||
if (Utils.isBlockASystem(block)) {
|
||||
if (PermissionChecks.canCreateSystem(player)) {
|
||||
// Cache and store the new system on another thread
|
||||
Bukkit.getScheduler().runTaskAsynchronously(EnergeticStorage.getPlugin(), () -> {
|
||||
ESSystem newSystem = new ESSystem(player.getUniqueId(), UUID.randomUUID(), block.getLocation());
|
||||
PlayersFile.savePlayerSystem(newSystem);
|
||||
|
||||
|
@ -38,6 +42,7 @@ public class BlockPlaceListener implements Listener {
|
|||
} else {
|
||||
Reference.ES_SYSTEMS.put(player.getUniqueId(), Collections.singletonList(newSystem));
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,9 +5,9 @@ import net.seanomik.energeticstorage.utils.ItemConstructor;
|
|||
import net.seanomik.energeticstorage.utils.ItemSerialization;
|
||||
import net.seanomik.energeticstorage.utils.Reference;
|
||||
import net.seanomik.energeticstorage.utils.Utils;
|
||||
import org.apache.commons.text.StringEscapeUtils;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.configuration.InvalidConfigurationException;
|
||||
import org.bukkit.craftbukkit.libs.org.apache.commons.lang3.StringEscapeUtils;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.json.simple.JSONArray;
|
||||
import org.json.simple.JSONObject;
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
package net.seanomik.energeticstorage.utils;
|
||||
|
||||
import de.tr7zw.changeme.nbtapi.NBTCompound;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import de.tr7zw.changeme.nbtapi.NBTItem;
|
||||
import de.tr7zw.changeme.nbtapi.NBTTileEntity;
|
||||
import net.seanomik.energeticstorage.Skulls;
|
||||
|
@ -12,7 +14,6 @@ import org.bukkit.block.Block;
|
|||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.*;
|
||||
|
||||
public class Utils {
|
||||
|
@ -132,13 +133,15 @@ public class Utils {
|
|||
public static boolean isBlockASystem(Block block) {
|
||||
NBTTileEntity blockNBT = new NBTTileEntity(block.getState());
|
||||
String version = Bukkit.getServer().getClass().getPackage().getName().split("\\.")[3];
|
||||
if (version.substring(0, 5).equals("v1_15") || version.substring(0, 5).equals("v1_14")) {
|
||||
return blockNBT.getCompound("Owner").getCompound("Properties").getCompoundList("textures").get(0).getString("Value").equals(Skulls.Computer.getTexture());
|
||||
} else if (version.substring(0, 5).equals("v1_16")) {
|
||||
return blockNBT.getCompound("SkullOwner").getCompound("Properties").getCompoundList("textures").get(0).getString("Value").equals(Skulls.Computer.getTexture());
|
||||
|
||||
NBTCompound ownerNBT;
|
||||
if (version.startsWith("v1_16")) {
|
||||
ownerNBT = blockNBT.getCompound("SkullOwner");
|
||||
} else {
|
||||
ownerNBT = blockNBT.getCompound("Owner");
|
||||
}
|
||||
|
||||
return false;
|
||||
return ownerNBT.getCompound("Properties").getCompoundList("textures").get(0).getString("Value").equals(Skulls.Computer.getTexture());
|
||||
}
|
||||
|
||||
public static boolean isItemADrive(ItemStack item) {
|
||||
|
|
Loading…
Reference in New Issue