Adding initial commit.
This commit is contained in:
commit
7d6bd44543
|
@ -0,0 +1,136 @@
|
|||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>me.sergiotarxz.bv</groupId>
|
||||
<artifactId>BetterVillager</artifactId>
|
||||
<!-- Version is used in plugin.yml -->
|
||||
<version>0.1-SNAPSHOT</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<!-- Plugin Information -->
|
||||
<!-- Name, Description, and URL are used in plugin.yml -->
|
||||
<name>BetterVillager</name>
|
||||
<description>Example of a Spigot plugin using Maven</description>
|
||||
<url>http://sgray.me/project/spigotplugin</url>
|
||||
|
||||
<licenses>
|
||||
<license>
|
||||
<name>Zlib License</name>
|
||||
<url>http://opensource.org/licenses/Zlib</url>
|
||||
<comments>Copyright (c) 2014 Shaila Gray
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
arising from the use of this software.
|
||||
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it
|
||||
freely, subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not
|
||||
claim that you wrote the original software. If you use this software
|
||||
in a product, an acknowledgment in the product documentation would be
|
||||
appreciated but is not required.
|
||||
|
||||
2. Altered source versions must be plainly marked as such, and must not be
|
||||
misrepresented as being the original software.
|
||||
|
||||
3. This notice may not be removed or altered from any source
|
||||
distribution.</comments>
|
||||
</license>
|
||||
</licenses>
|
||||
|
||||
<developers>
|
||||
<developer>
|
||||
<name>Shaila Gray</name>
|
||||
<url>http://sgray.me</url>
|
||||
</developer>
|
||||
</developers>
|
||||
|
||||
<properties>
|
||||
<!-- Author and MainClass are used in plugin.yml -->
|
||||
<author>SGray</author>
|
||||
<mainClass>me.sergiotarxz.bv.BetterVillager</mainClass>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.spigotmc</groupId>
|
||||
<artifactId>spigot-api</artifactId>
|
||||
<version>1.20-R0.1-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>de.tr7zw</groupId>
|
||||
<artifactId>item-nbt-api</artifactId>
|
||||
<version>2.13.1</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>spigot-repo</id>
|
||||
<url>https://hub.spigotmc.org/nexus/content/groups/public/</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>codemc-repo</id>
|
||||
<url>https://repo.codemc.io/repository/maven-public/</url>
|
||||
<layout>default</layout>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
<build>
|
||||
<sourceDirectory>src/main/java</sourceDirectory>
|
||||
<defaultGoal>clean install</defaultGoal>
|
||||
<resources>
|
||||
<resource>
|
||||
<directory>src/main/resources</directory>
|
||||
<!-- Keeping filtering at true here reduces plugin.yml redundancy! -->
|
||||
<filtering>true</filtering>
|
||||
<includes>
|
||||
<include>plugin.yml</include>
|
||||
</includes>
|
||||
</resource>
|
||||
<resource>
|
||||
<directory>src/main/resources</directory>
|
||||
<!-- Keep filtering at false for other resources to prevent bad magic -->
|
||||
<filtering>false</filtering>
|
||||
<excludes>
|
||||
<exclude>**/*.java</exclude>
|
||||
<exclude>plugin.yml</exclude>
|
||||
</excludes>
|
||||
</resource>
|
||||
</resources>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.1</version>
|
||||
<configuration>
|
||||
<compilerArgument>-Xlint:unchecked</compilerArgument>
|
||||
<source>17</source>
|
||||
<target>17</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-shade-plugin</artifactId>
|
||||
<version>3.6.0</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>shade</id>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>shade</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
<configuration>
|
||||
<relocations>
|
||||
<relocation>
|
||||
<pattern>de.tr7zw.changeme.nbtapi</pattern>
|
||||
<shadedPattern>me.sergiotarxz.bv.nbt</shadedPattern>
|
||||
</relocation>
|
||||
</relocations>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
|
@ -0,0 +1,81 @@
|
|||
package me.sergiotarxz.bv;
|
||||
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.bukkit.event.entity.*;
|
||||
import org.bukkit.entity.*;
|
||||
import org.bukkit.event.player.*;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import java.util.logging.Level;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.persistence.*;
|
||||
import java.util.Set;
|
||||
import java.util.List;
|
||||
import java.util.Iterator;
|
||||
import java.util.UUID;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.metadata.MetadataValue;
|
||||
import de.tr7zw.changeme.nbtapi.*;
|
||||
import de.tr7zw.changeme.nbtapi.iface.*;
|
||||
|
||||
public class BetterVillager extends JavaPlugin implements Listener {
|
||||
@Override
|
||||
public void onDisable() {
|
||||
// Don't log disabling, Spigot does that for you automatically!
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
if (!NBT.preloadApi()) {
|
||||
getLogger().warning("NBT-API wasn't initialized properly, disabling the plugin");
|
||||
getPluginLoader().disablePlugin(this);
|
||||
return;
|
||||
}
|
||||
getServer().getPluginManager().registerEvents(this, this);
|
||||
}
|
||||
|
||||
|
||||
/** Event handler for when a player right-clicks on an entity. */
|
||||
@EventHandler
|
||||
public void onEntityInteraction(PlayerInteractEntityEvent event) {
|
||||
if (event == null || event.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
Entity entity = event.getRightClicked();
|
||||
Player player = event.getPlayer();
|
||||
UUID playerUUID = player.getUniqueId();
|
||||
if (!(entity instanceof Villager)) {
|
||||
return;
|
||||
}
|
||||
Villager villager = (Villager) entity;
|
||||
getLogger().log(Level.INFO, "Listing villager keys");
|
||||
// {Target:[I;-595241863,-91010251,-1338114026,1482075547],Type:"major_positive",Value:20}
|
||||
NBT.modify(villager, nbt -> {
|
||||
ReadWriteNBTCompoundList gossips = nbt.getCompoundList("Gossips");
|
||||
ReadWriteNBT currentPlayerGossip = null;
|
||||
int maxValueGossip = 0;
|
||||
for (int i = 0; i < gossips.size(); i++) {
|
||||
ReadWriteNBT gossip = gossips.get(i);
|
||||
if (!gossip.getString("Type").equals("major_positive")) {
|
||||
continue;
|
||||
}
|
||||
int value = gossip.getInteger("Value").intValue();
|
||||
if (maxValueGossip < value) {
|
||||
maxValueGossip = value;
|
||||
}
|
||||
if (playerUUID.equals(gossip.getUUID("Target"))) {
|
||||
currentPlayerGossip = gossip;
|
||||
}
|
||||
getLogger().log(Level.INFO, gossip.toString());
|
||||
}
|
||||
if (maxValueGossip <= 0) {
|
||||
return;
|
||||
}
|
||||
if (currentPlayerGossip == null) {
|
||||
currentPlayerGossip = gossips.addCompound();
|
||||
}
|
||||
currentPlayerGossip.setUUID("Target", playerUUID);
|
||||
currentPlayerGossip.setInteger("Value", new Integer(maxValueGossip));
|
||||
currentPlayerGossip.setString("Type", "major_positive");
|
||||
});
|
||||
}
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
name: ${name}
|
||||
version: ${version}
|
||||
description: ${description}
|
||||
author: ${author}
|
||||
website: ${url}
|
||||
|
||||
main: ${mainClass}
|
||||
|
||||
permissions: {}
|
Loading…
Reference in New Issue