Fix #32, add bstats metrics

This commit is contained in:
SeanOMik 2022-01-25 20:43:58 -05:00
parent 9beef25970
commit 277974edae
6 changed files with 44 additions and 50 deletions

2
.gitignore vendored
View File

@ -106,4 +106,6 @@ modules.xml
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*
.attach_*
# End of https://www.gitignore.io/api/java,intellij+iml

View File

@ -1,10 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="RunConfigurationProducerService">
<option name="ignoredProducers">
<set>
<option value="com.android.tools.idea.compose.preview.runconfiguration.ComposePreviewRunConfigurationProducer" />
</set>
</option>
</component>
</project>

View File

@ -42,8 +42,12 @@
<pattern>net.wesjd.anvilgui</pattern>
<shadedPattern>net.seanomik.energeticstorage.anvilgui</shadedPattern>
</relocation>
<relocation>
<pattern>org.bstats</pattern>
<shadedPattern>net.seanomik.energeticstorage.bstats</shadedPattern>
</relocation>
</relocations>
<outputFile>C:\Development\Java\Spigot Servers\${server.version}\plugins\EnergeticStorage-v${project.version}.jar</outputFile>
<outputFile>/home/seanomik/Development/java/spigot-dev/test-servers/${server.version}/plugins/EnergeticStorage-v${project.version}.jar</outputFile>
</configuration>
</execution>
</executions>

13
pom.xml
View File

@ -50,9 +50,14 @@
<pattern>net.wesjd.anvilgui</pattern>
<shadedPattern>net.seanomik.energeticstorage.anvilgui</shadedPattern>
</relocation>
<relocation>
<pattern>org.bstats</pattern>
<!-- Replace this with your package! -->
<shadedPattern>net.seanomik.energeticstorage.bstats</shadedPattern>
</relocation>
</relocations>
<outputFile>C:\Development\Java\Spigot Servers\${server.version}\plugins\EnergeticStorage-v${project.version}.jar</outputFile>
<outputFile>/home/seanomik/Development/java/spigot-dev/test-servers/${server.version}/plugins/EnergeticStorage-v${project.version}.jar</outputFile>
</configuration>
</execution>
</executions>
@ -132,5 +137,11 @@
<artifactId>authlib</artifactId>
<version>1.5.21</version>
</dependency>
<dependency>
<groupId>org.bstats</groupId>
<artifactId>bstats-bukkit</artifactId>
<version>2.2.1</version>
<scope>compile</scope>
</dependency>
</dependencies>
</project>

View File

@ -15,11 +15,13 @@ import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.world.WorldSaveEvent;
import org.bukkit.plugin.java.JavaPlugin;
import org.bstats.bukkit.Metrics;
import java.util.*;
public final class EnergeticStorage extends JavaPlugin implements Listener {
private static EnergeticStorage plugin;
public static final int BSTATS_PLUGIN_ID = 14068;
private static HopperTask hopperTask;
@Override
@ -39,6 +41,8 @@ public final class EnergeticStorage extends JavaPlugin implements Listener {
hopperTask = new HopperTask();
hopperTask.runTaskTimerAsynchronously(this, 0L, 8L);
}
Metrics metrics = new Metrics(this, BSTATS_PLUGIN_ID);
}
private void registerCommands() {

View File

@ -154,7 +154,8 @@ public class ESDriveGUI implements InventoryHolder, Listener {
ESSystem esSystem = openSystems.get(player.getUniqueId());
// Make sure no items will get copied to other players open inventory
Inventory inv = player.getOpenInventory().getTopInventory();
Inventory thisInv = player.getOpenInventory().getTopInventory();
Inventory playerInv = player.getInventory();
// Handle type of click.
switch (clickType) {
@ -162,42 +163,21 @@ public class ESDriveGUI implements InventoryHolder, Listener {
break;
case SWAP:
break;
case INVENTORY_CLICK:
case SHIFT_IN:
case INTO_HALF:
case INTO:
if (Utils.isItemValid(clickedItem) && Utils.isItemADrive(clickedItem)) {
event.setCancelled(true);
// Add the item into the player's inventory
int driveSlot = inv.firstEmpty();
ItemStack oneClicked = clickedItem.clone();
oneClicked.setAmount(1);
inv.setItem(driveSlot, oneClicked);
int firstEmpty = thisInv.firstEmpty();
if (firstEmpty != -1) {
thisInv.setItem(firstEmpty, clickedItem);
playerInv.removeItem(clickedItem);
List<ESDrive> drives = esSystem.getESDrives();
drives.add(driveSlot - 2, new ESDrive(clickedItem));
drives.add(new ESDrive(clickedItem));
esSystem.setESDrives(drives);
// Remove the item from the players inventory
clickedItem.setAmount(clickedItem.getAmount() - 1);
}
break;
case INTO_HALF:
case INTO:
if (Utils.isItemValid(cursor) && Utils.isItemADrive(cursor)) {
NBTItem clickedNBT = new NBTItem(cursor);
if (clickedNBT.hasKey("ES_Drive") && clickedNBT.getBoolean("ES_Drive")) {
List<ESDrive> drives = esSystem.getESDrives();
if (drives.contains(null)) {
drives.set(drives.indexOf(null), new ESDrive(cursor));
} else {
drives.add(new ESDrive(cursor));
}
esSystem.setESDrives(drives);
initializeItems(player, esSystem);
event.setCancelled(true);
cursor.setAmount(0);
}
}
break;
@ -209,17 +189,20 @@ public class ESDriveGUI implements InventoryHolder, Listener {
Reference.ES_TERMINAL_GUI.openInventory(player, esSystem);
} else if (slot != 1 && slot != 7 && slot != 8) {
if (Utils.isItemADrive(clickedItem)) {
if (Utils.isItemValid(clickedItem) && Utils.isItemADrive(clickedItem)) {
event.setCancelled(true);
int firstEmpty = playerInv.firstEmpty();
if (firstEmpty != -1) {
playerInv.setItem(firstEmpty, clickedItem);
thisInv.removeItem(clickedItem);
List<ESDrive> drives = esSystem.getESDrives();
drives.set(slot - 2, null);
esSystem.setESDrives(drives);
event.setCancelled(false);
}
}
break;
case INVENTORY_CLICK:
event.setCancelled(false);
}
break;
}
}