Skip to content

Commit 7eb2f4e

Browse files
committed
Initial release
0 parents  commit 7eb2f4e

File tree

5 files changed

+141
-0
lines changed

5 files changed

+141
-0
lines changed

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
target/
2+
bin/
3+
.idea/
4+
**.iml
5+
.project
6+
.classpath

README.MD

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
### About
2+
AnvilUnlocker is a Bukkit plugin allowing anvils to be used past the normal level cap of 40. No permissions, no setup.
3+
4+
As this provides a definite gameplay advantage, I will not be modifying this plugin to add permissions.
5+
6+
### Caveats
7+
* 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.
8+
* 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.

pom.xml

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
7+
<groupId>com.github.jikoo</groupId>
8+
<artifactId>anvilunlocker</artifactId>
9+
<name>AnvilUnlocker</name>
10+
<version>1.0.0</version>
11+
12+
<properties>
13+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
14+
</properties>
15+
16+
<repositories>
17+
<repository>
18+
<id>spigot-repo</id>
19+
<url>https://hub.spigotmc.org/nexus/content/groups/public/</url>
20+
</repository>
21+
<repository>
22+
<id>dmulloy2-repo</id>
23+
<url>http://repo.dmulloy2.net/nexus/repository/public/</url>
24+
</repository>
25+
</repositories>
26+
27+
<dependencies>
28+
<dependency>
29+
<groupId>org.spigotmc</groupId>
30+
<artifactId>spigot-api</artifactId>
31+
<version>1.15.2-R0.1-SNAPSHOT</version>
32+
<scope>provided</scope>
33+
</dependency>
34+
<dependency>
35+
<groupId>com.comphenix.protocol</groupId>
36+
<artifactId>ProtocolLib</artifactId>
37+
<version>4.5.0</version>
38+
<scope>provided</scope>
39+
</dependency>
40+
</dependencies>
41+
42+
<build>
43+
<finalName>${project.name}</finalName>
44+
45+
<resources>
46+
<resource>
47+
<directory>src/main/resources</directory>
48+
<filtering>true</filtering>
49+
</resource>
50+
</resources>
51+
52+
<plugins>
53+
<plugin>
54+
<groupId>org.apache.maven.plugins</groupId>
55+
<artifactId>maven-compiler-plugin</artifactId>
56+
<version>3.8.1</version>
57+
<configuration>
58+
<source>1.8</source>
59+
<target>1.8</target>
60+
</configuration>
61+
</plugin>
62+
</plugins>
63+
</build>
64+
65+
</project>
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
package com.github.jikoo.anvilunlocker;
2+
3+
import com.comphenix.protocol.PacketType;
4+
import com.comphenix.protocol.ProtocolLibrary;
5+
import com.comphenix.protocol.events.PacketContainer;
6+
import java.lang.reflect.InvocationTargetException;
7+
import org.bukkit.GameMode;
8+
import org.bukkit.entity.Player;
9+
import org.bukkit.event.EventHandler;
10+
import org.bukkit.event.Listener;
11+
import org.bukkit.event.inventory.InventoryCloseEvent;
12+
import org.bukkit.event.inventory.InventoryOpenEvent;
13+
import org.bukkit.inventory.AnvilInventory;
14+
import org.bukkit.plugin.java.JavaPlugin;
15+
16+
public class AnvilUnlocker extends JavaPlugin implements Listener {
17+
18+
@Override
19+
public void onEnable() {
20+
getServer().getPluginManager().registerEvents(this, this);
21+
}
22+
23+
@EventHandler
24+
public void onInventoryOpen(InventoryOpenEvent event) {
25+
if (event.getInventory() instanceof AnvilInventory && event.getPlayer() instanceof Player
26+
&& event.getPlayer().getGameMode() != GameMode.CREATIVE) {
27+
((AnvilInventory) event.getInventory()).setMaximumRepairCost(Short.MAX_VALUE);
28+
setInstantBuild((Player) event.getPlayer(), true);
29+
}
30+
}
31+
32+
@EventHandler
33+
public void onInventoryClose(InventoryCloseEvent event) {
34+
if (event.getInventory() instanceof AnvilInventory && event.getPlayer() instanceof Player
35+
&& event.getPlayer().getGameMode() != GameMode.CREATIVE) {
36+
setInstantBuild((Player) event.getPlayer(), false);
37+
}
38+
}
39+
40+
public void setInstantBuild(Player player, boolean instantBuild) {
41+
PacketContainer packet = new PacketContainer(PacketType.Play.Server.ABILITIES);
42+
packet.getBooleans().write(0, player.isInvulnerable());
43+
packet.getBooleans().write(1, player.isFlying());
44+
packet.getBooleans().write(2, player.getAllowFlight());
45+
packet.getBooleans().write(3, instantBuild);
46+
packet.getFloat().write(0, player.getFlySpeed() / 2);
47+
packet.getFloat().write(1, player.getWalkSpeed() / 2);
48+
49+
try {
50+
ProtocolLibrary.getProtocolManager().sendServerPacket(player, packet);
51+
} catch (InvocationTargetException e) {
52+
e.printStackTrace();
53+
}
54+
}
55+
56+
}

src/main/resources/plugin.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
name: ${project.name}
2+
main: ${project.groupId}.${project.artifactId}.${project.name}
3+
version: ${project.version}
4+
api-version: "1.15"
5+
author: Jikoo
6+
softdepend: ["ProtocolLib"]

0 commit comments

Comments
 (0)