mirror of
https://github.com/ViaVersion/ViaRewind-Legacy-Support.git
synced 2025-01-24 21:21:50 +01:00
first commit
This commit is contained in:
parent
bea4097139
commit
f1b0592c9c
71
pom.xml
Normal file
71
pom.xml
Normal file
@ -0,0 +1,71 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
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>de.gerrygames</groupId>
|
||||
<artifactId>viarewind-legacy-support</artifactId>
|
||||
<version>1.0.0</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<properties>
|
||||
<!-- Project Properties -->
|
||||
<projectEncoding>UTF-8</projectEncoding>
|
||||
<project.build.sourceEncoding>${projectEncoding}</project.build.sourceEncoding>
|
||||
<project.build.outputEncoding>${projectEncoding}</project.build.outputEncoding>
|
||||
<maven.compiler.source>1.8</maven.compiler.source>
|
||||
<maven.compiler.target>1.8</maven.compiler.target>
|
||||
</properties>
|
||||
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>viaversion-repo</id>
|
||||
<url>https://repo.viaversion.com</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>spigot-repo</id>
|
||||
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
<dependencies>
|
||||
<!-- Lombok -->
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<version>1.16.18</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<!-- ViaVersion -->
|
||||
<dependency>
|
||||
<groupId>us.myles</groupId>
|
||||
<artifactId>viaversion</artifactId>
|
||||
<version>1.3.0</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<!-- Spigot API -->
|
||||
<dependency>
|
||||
<groupId>org.spigotmc</groupId>
|
||||
<artifactId>spigot-api</artifactId>
|
||||
<version>1.12.2-R0.1-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<resources>
|
||||
<resource>
|
||||
<targetPath>.</targetPath>
|
||||
<filtering>true</filtering>
|
||||
<directory>src/main/resources/</directory>
|
||||
<includes>
|
||||
<include>*</include>
|
||||
</includes>
|
||||
</resource>
|
||||
</resources>
|
||||
</build>
|
||||
|
||||
</project>
|
@ -0,0 +1,20 @@
|
||||
package de.gerrygames.viarewind.legacysupport;
|
||||
|
||||
import de.gerrygames.viarewind.legacysupport.injector.LilyPadFixer;
|
||||
import de.gerrygames.viarewind.legacysupport.listener.BrewingListener;
|
||||
import de.gerrygames.viarewind.legacysupport.listener.EnchantingListener;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
public class BukkitPlugin extends JavaPlugin {
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
saveDefaultConfig();
|
||||
FileConfiguration config = getConfig();
|
||||
if (config.getBoolean("enchanting-gui-fix")) Bukkit.getPluginManager().registerEvents(new EnchantingListener(), this);
|
||||
if (config.getBoolean("brewing-stand-gui-fix")) Bukkit.getPluginManager().registerEvents(new BrewingListener(), this);
|
||||
if (config.getBoolean("lily-pad-fix")) LilyPadFixer.fix();
|
||||
}
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
package de.gerrygames.viarewind.legacysupport.injector;
|
||||
|
||||
import de.gerrygames.viarewind.legacysupport.reflection.ReflectionAPI;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
|
||||
public class LilyPadFixer {
|
||||
public static void fix() {
|
||||
try {
|
||||
Class blockWaterLilyClass = NMSReflection.getNMSClass("BlockWaterLily");
|
||||
Class boundingBoxClass = NMSReflection.getNMSClass("AxisAlignedBB");
|
||||
Constructor boundingBoxConstructor = boundingBoxClass.getConstructor(double.class, double.class, double.class, double.class, double.class, double.class);
|
||||
Object boundingBox = boundingBoxConstructor.newInstance(0.0625, 0.0, 0.0625, 0.9375, 0.015625, 0.9375);
|
||||
ReflectionAPI.setFinalValue(blockWaterLilyClass, "a", boundingBox);
|
||||
} catch (Exception ignored) {
|
||||
System.out.println("Could not fix Lily Pads bounding box.");
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,20 @@
|
||||
package de.gerrygames.viarewind.legacysupport.injector;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
public class NMSReflection {
|
||||
private static String version;
|
||||
|
||||
public static String getVersion() {
|
||||
return version==null ? version = Bukkit.getServer().getClass().getPackage().getName().split("\\.")[3] : version;
|
||||
}
|
||||
|
||||
public static Class getNMSClass(String name) {
|
||||
try {
|
||||
return Class.forName("net.minecraft.server." + NMSReflection.getVersion() + "." + name);
|
||||
} catch (ClassNotFoundException ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
@ -0,0 +1,43 @@
|
||||
package de.gerrygames.viarewind.legacysupport.listener;
|
||||
|
||||
import org.bukkit.Material;
|
||||
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.BrewerInventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.PlayerInventory;
|
||||
import us.myles.ViaVersion.api.Via;
|
||||
|
||||
public class BrewingListener implements Listener {
|
||||
|
||||
@EventHandler
|
||||
public void onInventoryOpen(InventoryOpenEvent e) {
|
||||
if (!(e.getInventory() instanceof BrewerInventory)) return;
|
||||
Player player = (Player) e.getPlayer();
|
||||
int version = Via.getAPI().getPlayerVersion(player);
|
||||
if (version>5) return;
|
||||
PlayerInventory playerInventory = player.getInventory();
|
||||
ItemStack blazePowder = new ItemStack(Material.BLAZE_POWDER);
|
||||
int amount = 0;
|
||||
for (int i = 0; i<playerInventory.getSize(); i++) {
|
||||
ItemStack item = playerInventory.getItem(i);
|
||||
if (item==null || !item.isSimilar(blazePowder)) continue;
|
||||
if (amount + item.getAmount() > 64) {
|
||||
item.setAmount(amount + item.getAmount() - 64);
|
||||
amount = 64;
|
||||
} else {
|
||||
amount += item.getAmount();
|
||||
item = new ItemStack(Material.AIR);
|
||||
}
|
||||
playerInventory.setItem(i, item);
|
||||
if (amount==64) break;
|
||||
}
|
||||
if (amount==0) return;
|
||||
BrewerInventory inventory = (BrewerInventory) e.getInventory();
|
||||
blazePowder.setAmount(amount);
|
||||
inventory.setFuel(blazePowder);
|
||||
}
|
||||
}
|
@ -0,0 +1,57 @@
|
||||
package de.gerrygames.viarewind.legacysupport.listener;
|
||||
|
||||
import org.bukkit.Material;
|
||||
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.EnchantingInventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.PlayerInventory;
|
||||
import us.myles.ViaVersion.api.Via;
|
||||
|
||||
public class EnchantingListener implements Listener {
|
||||
|
||||
@EventHandler
|
||||
public void onInventoryOpen(InventoryOpenEvent e) {
|
||||
if (!(e.getInventory() instanceof EnchantingInventory)) return;
|
||||
Player player = (Player) e.getPlayer();
|
||||
int version = Via.getAPI().getPlayerVersion(player);
|
||||
if (version>5) return;
|
||||
PlayerInventory playerInventory = player.getInventory();
|
||||
ItemStack lapis = new ItemStack(Material.INK_SACK, 1, (short) 4);
|
||||
int amount = 0;
|
||||
for (int i = 0; i<playerInventory.getSize(); i++) {
|
||||
ItemStack item = playerInventory.getItem(i);
|
||||
if (item==null || !item.isSimilar(lapis)) continue;
|
||||
if (amount + item.getAmount() > 64) {
|
||||
item.setAmount(amount + item.getAmount() - 64);
|
||||
amount = 64;
|
||||
} else {
|
||||
amount += item.getAmount();
|
||||
item = new ItemStack(Material.AIR);
|
||||
}
|
||||
playerInventory.setItem(i, item);
|
||||
if (amount==64) break;
|
||||
}
|
||||
if (amount==0) return;
|
||||
EnchantingInventory inventory = (EnchantingInventory) e.getInventory();
|
||||
lapis.setAmount(amount);
|
||||
inventory.setSecondary(lapis);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onInventoryClose(InventoryCloseEvent e) {
|
||||
if (!(e.getInventory() instanceof EnchantingInventory)) return;
|
||||
Player player = (Player) e.getPlayer();
|
||||
int version = Via.getAPI().getPlayerVersion(player);
|
||||
if (version>5) return;
|
||||
PlayerInventory playerInventory = player.getInventory();
|
||||
EnchantingInventory inventory = (EnchantingInventory) e.getInventory();
|
||||
ItemStack item = inventory.getSecondary();
|
||||
if (item==null || item.getType()==Material.AIR) return;
|
||||
inventory.setSecondary(new ItemStack(Material.AIR));
|
||||
playerInventory.addItem(item);
|
||||
}
|
||||
}
|
@ -0,0 +1,146 @@
|
||||
package de.gerrygames.viarewind.legacysupport.reflection;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class ReflectionAPI {
|
||||
private static Map<String, Field> fields = new HashMap<>();
|
||||
|
||||
public static Field getField(Class clazz, String fieldname) throws NoSuchFieldException {
|
||||
String c = clazz.getName() + ":" + fieldname;
|
||||
Field f = fields.get(c);
|
||||
if (f == null) {
|
||||
f = clazz.getDeclaredField(fieldname);
|
||||
fields.put(c, f);
|
||||
}
|
||||
return f;
|
||||
}
|
||||
|
||||
public static void setFieldNotFinal(Field field) {
|
||||
try {
|
||||
Field modifiers = Field.class.getDeclaredField("modifiers");
|
||||
modifiers.setAccessible(true);
|
||||
if (Modifier.isFinal(field.getModifiers())) {
|
||||
modifiers.set(field, field.getModifiers() & ~Modifier.FINAL);
|
||||
}
|
||||
} catch (Exception ignored) {}
|
||||
}
|
||||
|
||||
public static Field getFieldAccessible(Class clazz, String fieldname) throws NoSuchFieldException {
|
||||
Field field = getField(clazz, fieldname);
|
||||
field.setAccessible(true);
|
||||
return field;
|
||||
}
|
||||
|
||||
public static Object getValue(Class clazz, Object object, String fieldname) throws Exception {
|
||||
return getFieldAccessible(clazz, fieldname).get(object);
|
||||
}
|
||||
|
||||
public static Object getValue(Object object, String fieldname) throws Exception {
|
||||
return getValue(object.getClass(), object, fieldname);
|
||||
}
|
||||
|
||||
public static Object getValue(Class clazz, String fieldname) throws Exception {
|
||||
return getValue(clazz, null, fieldname);
|
||||
}
|
||||
|
||||
public static Object getValuePrintException(Object object, String fieldname) {
|
||||
try {
|
||||
return getValue(object, fieldname);
|
||||
} catch (Exception ex) {ex.printStackTrace();}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static Object getValuePrintException(Class clazz, String fieldname) {
|
||||
try {
|
||||
return getValue(clazz, fieldname);
|
||||
} catch (Exception ex) {ex.printStackTrace();}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static Object getValueIgnoreException(Object object, String fieldname) {
|
||||
try {
|
||||
return getValue(object, fieldname);
|
||||
} catch (Exception ignored) {}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static Object getValueIgnoreException(Class clazz, String fieldname) {
|
||||
try {
|
||||
return getValue(clazz, fieldname);
|
||||
} catch (Exception ignored) {}
|
||||
return null;
|
||||
}
|
||||
|
||||
private static void setValue(Class clazz, Object object, String fieldname, Object value, boolean isFinal) throws Exception {
|
||||
Field field = getFieldAccessible(clazz, fieldname);
|
||||
if (isFinal) setFieldNotFinal(field);
|
||||
field.set(object, value);
|
||||
}
|
||||
|
||||
public static void setValue(Object object, String fieldname, Object value) throws Exception {
|
||||
setValue(object.getClass(), object, fieldname, value, false);
|
||||
}
|
||||
|
||||
public static void setValue(Class clazz, String fieldname, Object value) throws Exception {
|
||||
setValue(clazz, null, fieldname, value, false);
|
||||
}
|
||||
|
||||
public static void setFinalValue(Object object, String fieldname, Object value) throws Exception {
|
||||
setValue(object.getClass(), object, fieldname, value, true);
|
||||
}
|
||||
|
||||
public static void setFinalValue(Class clazz, String fieldname, Object value) throws Exception {
|
||||
setValue(clazz, null, fieldname, value, true);
|
||||
}
|
||||
|
||||
public static void setValuePrintException(Object object, String fieldname, Object value) {
|
||||
try {
|
||||
setValue(object, fieldname, value);
|
||||
} catch (Exception ex) {ex.printStackTrace();}
|
||||
}
|
||||
|
||||
public static void setValuePrintException(Class clazz, String fieldname, Object value) {
|
||||
try {
|
||||
setValue(clazz, fieldname, value);
|
||||
} catch (Exception ex) {ex.printStackTrace();}
|
||||
}
|
||||
|
||||
public static void setFinalValuePrintException(Object object, String fieldname, Object value) {
|
||||
try {
|
||||
setFinalValue(object, fieldname, value);
|
||||
} catch (Exception ex) {ex.printStackTrace();}
|
||||
}
|
||||
|
||||
public static void setFinalValuePrintException(Class clazz, String fieldname, Object value) {
|
||||
try {
|
||||
setFinalValue(clazz, fieldname, value);
|
||||
} catch (Exception ex) {ex.printStackTrace();}
|
||||
}
|
||||
|
||||
public static void setValueIgnoreException(Object object, String fieldname, Object value) {
|
||||
try {
|
||||
setValue(object, fieldname, value);
|
||||
} catch (Exception ignored) {}
|
||||
}
|
||||
|
||||
public static void setValueIgnoreException(Class clazz, String fieldname, Object value) {
|
||||
try {
|
||||
setValue(clazz, fieldname, value);
|
||||
} catch (Exception ignored) {}
|
||||
}
|
||||
|
||||
public static void setFinalValueIgnoreException(Object object, String fieldname, Object value) {
|
||||
try {
|
||||
setFinalValue(object, fieldname, value);
|
||||
} catch (Exception ignored) {}
|
||||
}
|
||||
|
||||
public static void setFinalValueIgnoreException(Class clazz, String fieldname, Object value) {
|
||||
try {
|
||||
setFinalValue(clazz, fieldname, value);
|
||||
} catch (Exception ignored) {}
|
||||
}
|
||||
}
|
4
src/main/resources/config.yml
Normal file
4
src/main/resources/config.yml
Normal file
@ -0,0 +1,4 @@
|
||||
brewing-stand-gui-fix: true
|
||||
enchanting-gui-fix: true
|
||||
vehicle-fix: true
|
||||
lily-pad-fix: true
|
8
src/main/resources/plugin.yml
Normal file
8
src/main/resources/plugin.yml
Normal file
@ -0,0 +1,8 @@
|
||||
name: ViaRewind-Legacy-Support
|
||||
version: ${project.version}
|
||||
main: de.gerrygames.viarewind.legacysupport.BukkitPlugin
|
||||
|
||||
authors: [Gerrygames]
|
||||
website: https://github.com/Gerrygames
|
||||
|
||||
depend: [ViaVersion]
|
Loading…
Reference in New Issue
Block a user