Skip to content

Commit

Permalink
Initial release
Browse files Browse the repository at this point in the history
  • Loading branch information
Jikoo committed Mar 23, 2020
0 parents commit 7eb2f4e
Show file tree
Hide file tree
Showing 5 changed files with 141 additions and 0 deletions.
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
target/
bin/
.idea/
**.iml
.project
.classpath
8 changes: 8 additions & 0 deletions README.MD
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
### About
AnvilUnlocker is a Bukkit plugin allowing anvils to be used past the normal level cap of 40. No permissions, no setup.

As this provides a definite gameplay advantage, I will not be modifying this plugin to add permissions.

### Caveats
* Due to client limitations, repair costs over 40 levels cannot be displayed in red whether or not the client has the experience required to complete the repair. For simplicity and consistency, AnvilUnlocker uses an approach that sends a minimum number of packets but entirely removes the mechanic of the cost turning red when the client lacks the required experience, even when the cost is under 40 levels.
* Due to the client's inability to display items' costs greater than a short's max value (32767) and subsequent wrapping around, the new maximum is capped to 32767 instead of allowing any valid int value.
65 changes: 65 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<?xml version="1.0" encoding="UTF-8"?>
<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>com.github.jikoo</groupId>
<artifactId>anvilunlocker</artifactId>
<name>AnvilUnlocker</name>
<version>1.0.0</version>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<repositories>
<repository>
<id>spigot-repo</id>
<url>https://hub.spigotmc.org/nexus/content/groups/public/</url>
</repository>
<repository>
<id>dmulloy2-repo</id>
<url>http://repo.dmulloy2.net/nexus/repository/public/</url>
</repository>
</repositories>

<dependencies>
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.15.2-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.comphenix.protocol</groupId>
<artifactId>ProtocolLib</artifactId>
<version>4.5.0</version>
<scope>provided</scope>
</dependency>
</dependencies>

<build>
<finalName>${project.name}</finalName>

<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>

<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>

</project>
56 changes: 56 additions & 0 deletions src/main/java/com/github/jikoo/anvilunlocker/AnvilUnlocker.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package com.github.jikoo.anvilunlocker;

import com.comphenix.protocol.PacketType;
import com.comphenix.protocol.ProtocolLibrary;
import com.comphenix.protocol.events.PacketContainer;
import java.lang.reflect.InvocationTargetException;
import org.bukkit.GameMode;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.inventory.InventoryCloseEvent;
import org.bukkit.event.inventory.InventoryOpenEvent;
import org.bukkit.inventory.AnvilInventory;
import org.bukkit.plugin.java.JavaPlugin;

public class AnvilUnlocker extends JavaPlugin implements Listener {

@Override
public void onEnable() {
getServer().getPluginManager().registerEvents(this, this);
}

@EventHandler
public void onInventoryOpen(InventoryOpenEvent event) {
if (event.getInventory() instanceof AnvilInventory && event.getPlayer() instanceof Player
&& event.getPlayer().getGameMode() != GameMode.CREATIVE) {
((AnvilInventory) event.getInventory()).setMaximumRepairCost(Short.MAX_VALUE);
setInstantBuild((Player) event.getPlayer(), true);
}
}

@EventHandler
public void onInventoryClose(InventoryCloseEvent event) {
if (event.getInventory() instanceof AnvilInventory && event.getPlayer() instanceof Player
&& event.getPlayer().getGameMode() != GameMode.CREATIVE) {
setInstantBuild((Player) event.getPlayer(), false);
}
}

public void setInstantBuild(Player player, boolean instantBuild) {
PacketContainer packet = new PacketContainer(PacketType.Play.Server.ABILITIES);
packet.getBooleans().write(0, player.isInvulnerable());
packet.getBooleans().write(1, player.isFlying());
packet.getBooleans().write(2, player.getAllowFlight());
packet.getBooleans().write(3, instantBuild);
packet.getFloat().write(0, player.getFlySpeed() / 2);
packet.getFloat().write(1, player.getWalkSpeed() / 2);

try {
ProtocolLibrary.getProtocolManager().sendServerPacket(player, packet);
} catch (InvocationTargetException e) {
e.printStackTrace();
}
}

}
6 changes: 6 additions & 0 deletions src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
name: ${project.name}
main: ${project.groupId}.${project.artifactId}.${project.name}
version: ${project.version}
api-version: "1.15"
author: Jikoo
softdepend: ["ProtocolLib"]

0 comments on commit 7eb2f4e

Please sign in to comment.