Skip to content

Commit

Permalink
Use ItemNBTAPI
Browse files Browse the repository at this point in the history
  • Loading branch information
HSGamer committed Apr 8, 2019
1 parent 4cd304c commit bcb5927
Show file tree
Hide file tree
Showing 10 changed files with 70 additions and 1,103 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions NBT-CommandItems.iml
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,6 @@
<orderEntry type="library" name="Maven: com.google.code.findbugs:jsr305:2.0.1" level="project" />
<orderEntry type="library" name="Maven: commons-io:commons-io:2.4" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: me.clip:placeholderapi:2.9.2" level="project" />
<orderEntry type="library" name="Maven: com.github.tr7zw.Item-NBT-API:item-nbt-api:master-be4dfa593b-1" level="project" />
</component>
</module>
25 changes: 9 additions & 16 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,22 +28,6 @@
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.1.0</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<createDependencyReducedPom>false</createDependencyReducedPom>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
<resources>
<resource>
Expand Down Expand Up @@ -71,6 +55,10 @@
<id>placeholderapi</id>
<url>http://repo.extendedclip.com/content/repositories/placeholderapi/</url>
</repository>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>

<dependencies>
Expand All @@ -91,5 +79,10 @@
<version>2.9.2</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.github.tr7zw.Item-NBT-API</groupId>
<artifactId>item-nbt-api</artifactId>
<version>master-SNAPSHOT</version>
</dependency>
</dependencies>
</project>
3 changes: 3 additions & 0 deletions src/main/java/me/hsgamer/nbtcommanditems/ConfigEnums.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ public enum ConfigEnums {
PERMISSION_SET_RIGHT_COMMAND("permissions.setrightcommand"),
PERMISSION_SET_ONE_TIME_USE("permissions.setonetimeuse"),
PERMISSION_GET_COMMAND("permissions.getcommand"),

GET_COMMAND_FOUND("messages.getcommand.found"),
GET_COMMAND_NOT_FOUND("messages.getcommand.not-found")
;
String path;
ConfigEnums(String path) {
Expand Down
14 changes: 9 additions & 5 deletions src/main/java/me/hsgamer/nbtcommanditems/Listeners.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package me.hsgamer.nbtcommanditems;

import de.tr7zw.itemnbtapi.NBTItem;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
Expand All @@ -12,23 +13,26 @@ public class Listeners implements Listener {
public void onUse(PlayerInteractEvent event) {
if (!event.hasItem()) return;
ItemStack item = event.getItem();
NBTItem nbtitem = new NBTItem(item);
Player player = event.getPlayer();
String leftclick = (String) NBTEditor.getItemTag(item, NBTEnums.LEFT_CLICK.get());
String rightclick = (String) NBTEditor.getItemTag(item, NBTEnums.RIGHT_CLICK.get());
if (leftclick == null && rightclick == null) return;
if (!(nbtitem.hasKey(NBTEnums.LEFT_CLICK.get()) && nbtitem.hasKey(NBTEnums.RIGHT_CLICK.get()))) return;
String leftclick = nbtitem.getString(NBTEnums.LEFT_CLICK.get());
String rightclick = nbtitem.getString(NBTEnums.RIGHT_CLICK.get());
if (event.getAction() == Action.LEFT_CLICK_AIR || event.getAction() == Action.LEFT_CLICK_BLOCK) {
if (leftclick != null) {
player.chat("/" + NBTCommandItems.getVariable().getParsed(player, leftclick));
event.setCancelled(true);
}
} else if (event.getAction() == Action.RIGHT_CLICK_AIR || event.getAction() == Action.RIGHT_CLICK_BLOCK) {
if (rightclick != null) {
player.chat("/" + NBTCommandItems.getVariable().getParsed(player, rightclick));
event.setCancelled(true);
}
} else {
return;
}
if (NBTEditor.getItemTag(item, NBTEnums.ONE_TIME_USE.get()) != null) {
boolean onetimeuse = (boolean) NBTEditor.getItemTag(item, NBTEnums.ONE_TIME_USE.get());
if (nbtitem.hasKey(NBTEnums.ONE_TIME_USE.get()) != null) {
boolean onetimeuse = nbtitem.getBoolean(NBTEnums.ONE_TIME_USE.get());
if (onetimeuse) {
if (item.getAmount() > 1) {
item.setAmount(item.getAmount() - 1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public static Variable getVariable() {
public void onEnable() {
saveDefaultConfig();
instance = this;
variable = new Variable(this);
variable = new Variable();
getCommand("commanditems").setExecutor(new PluginCommand());
getServer().getPluginManager().registerEvents(new Listeners(), this);
}
Expand Down
Loading

0 comments on commit bcb5927

Please sign in to comment.