-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 7eb2f4e
Showing
5 changed files
with
141 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
target/ | ||
bin/ | ||
.idea/ | ||
**.iml | ||
.project | ||
.classpath |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
56
src/main/java/com/github/jikoo/anvilunlocker/AnvilUnlocker.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"] |