mirror of
https://github.com/alexcrea/CustomAnvil.git
synced 2026-06-23 16:16:17 +02:00
Create common nms module.
This commit is contained in:
parent
056892ee1e
commit
7d20ea83c3
13 changed files with 108 additions and 70 deletions
|
|
@ -8,7 +8,7 @@ import io.delilaheve.CustomAnvil;
|
|||
import org.bukkit.Material;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import xyz.alexcrea.cuanvil.dependency.protocolib.PacketManager;
|
||||
import xyz.alexcrea.cuanvil.dependency.packet.PacketManager;
|
||||
import xyz.alexcrea.cuanvil.gui.config.global.*;
|
||||
import xyz.alexcrea.cuanvil.gui.util.GuiGlobalItems;
|
||||
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ import org.bukkit.inventory.meta.ItemMeta;
|
|||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import xyz.alexcrea.cuanvil.config.ConfigHolder;
|
||||
import xyz.alexcrea.cuanvil.dependency.protocolib.PacketManager;
|
||||
import xyz.alexcrea.cuanvil.dependency.packet.PacketManager;
|
||||
import xyz.alexcrea.cuanvil.gui.ValueUpdatableGui;
|
||||
import xyz.alexcrea.cuanvil.gui.config.MainConfigGui;
|
||||
import xyz.alexcrea.cuanvil.gui.config.settings.BoolSettingsGui;
|
||||
|
|
@ -280,9 +280,10 @@ public class BasicConfigGui extends ChestGui implements ValueUpdatableGui {
|
|||
lore.add("\u00A77Even if cost is displayed as \u00A7aGreen\u00A77:");
|
||||
lore.add("\u00A77If the player do not have the required xp level, the action will not be completable.");
|
||||
|
||||
if(!this.packetManager.isProtocoLibInstalled()){
|
||||
if(!this.packetManager.getCanSetInstantBuild()){
|
||||
lore.add("");
|
||||
lore.add("\u00A74/!\\\u00A7cCaution/!\\ \u00A7cYou need ProtocoLib installed for this to work.");
|
||||
lore.add("\u00A74/!\\\u00A7cCaution\u00A74/!\\ \u00A7cYou need ProtocoLib installed and working or a newer version of this plugin for this to work.");
|
||||
lore.add("\u00A7cCurrently ProtocoLib is not detected.");
|
||||
}
|
||||
|
||||
String[] loreAsArray = new String[lore.size()];
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ import org.bukkit.inventory.InventoryView.Property.REPAIR_COST
|
|||
import org.bukkit.inventory.ItemStack
|
||||
import org.bukkit.inventory.meta.Repairable
|
||||
import xyz.alexcrea.cuanvil.config.ConfigHolder
|
||||
import xyz.alexcrea.cuanvil.dependency.protocolib.PacketManager
|
||||
import xyz.alexcrea.cuanvil.dependency.packet.PacketManager
|
||||
import xyz.alexcrea.cuanvil.group.ConflictType
|
||||
import xyz.alexcrea.cuanvil.recipe.AnvilCustomRecipe
|
||||
import xyz.alexcrea.cuanvil.util.UnitRepairUtil.getRepair
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
package xyz.alexcrea.cuanvil.dependency
|
||||
|
||||
import org.bukkit.Bukkit
|
||||
import xyz.alexcrea.cuanvil.dependency.protocolib.NoProtocoLib
|
||||
import xyz.alexcrea.cuanvil.dependency.protocolib.PacketManager
|
||||
import xyz.alexcrea.cuanvil.dependency.protocolib.ProtocoLibWrapper
|
||||
import xyz.alexcrea.cuanvil.dependency.packet.NoPacketManager
|
||||
import xyz.alexcrea.cuanvil.dependency.packet.PacketManager
|
||||
import xyz.alexcrea.cuanvil.dependency.packet.ProtocoLibWrapper
|
||||
|
||||
object DependencyManager {
|
||||
|
||||
|
|
@ -17,7 +17,7 @@ object DependencyManager {
|
|||
// ProtocolLib dependency
|
||||
packetManager =
|
||||
if(pluginManager.isPluginEnabled("ProtocolLib")) ProtocoLibWrapper()
|
||||
else NoProtocoLib()
|
||||
else NoPacketManager()
|
||||
|
||||
// Enchantment Squared dependency
|
||||
if(pluginManager.isPluginEnabled("EnchantsSquared")){
|
||||
|
|
|
|||
|
|
@ -1,13 +0,0 @@
|
|||
package xyz.alexcrea.cuanvil.dependency.protocolib
|
||||
|
||||
import org.bukkit.entity.Player
|
||||
|
||||
class NoProtocoLib: PacketManager {
|
||||
override val isProtocoLibInstalled: Boolean
|
||||
get() = false
|
||||
|
||||
// ProtocoLib not installed: We do nothing
|
||||
|
||||
override fun setInstantBuild(player: Player, instantBuild: Boolean) {}
|
||||
|
||||
}
|
||||
|
|
@ -1,11 +0,0 @@
|
|||
package xyz.alexcrea.cuanvil.dependency.protocolib
|
||||
|
||||
import org.bukkit.entity.Player
|
||||
|
||||
interface PacketManager {
|
||||
|
||||
val isProtocoLibInstalled: Boolean
|
||||
|
||||
fun setInstantBuild(player: Player, instantBuild: Boolean)
|
||||
|
||||
}
|
||||
|
|
@ -1,39 +0,0 @@
|
|||
package xyz.alexcrea.cuanvil.dependency.protocolib
|
||||
|
||||
import com.comphenix.protocol.PacketType
|
||||
import com.comphenix.protocol.ProtocolLibrary
|
||||
import com.comphenix.protocol.ProtocolManager
|
||||
import com.comphenix.protocol.events.PacketContainer
|
||||
import org.bukkit.entity.Player
|
||||
import java.lang.reflect.InvocationTargetException
|
||||
|
||||
class ProtocoLibWrapper: PacketManager {
|
||||
|
||||
private val protocolManager: ProtocolManager = ProtocolLibrary.getProtocolManager();
|
||||
|
||||
override val isProtocoLibInstalled: Boolean
|
||||
get() = true
|
||||
|
||||
override fun setInstantBuild(player: Player, instantBuild: Boolean) {
|
||||
val packet = PacketContainer(PacketType.Play.Server.ABILITIES)
|
||||
|
||||
// Set player's properties
|
||||
packet.float
|
||||
.write(0, player.flySpeed / 2)
|
||||
.write(1, player.walkSpeed / 2)
|
||||
|
||||
packet.booleans
|
||||
.write(0, player.isInvulnerable)
|
||||
.write(1, player.isFlying)
|
||||
.write(2, player.allowFlight)
|
||||
.write(3, instantBuild)
|
||||
|
||||
// Send packet
|
||||
try {
|
||||
protocolManager.sendServerPacket(player, packet)
|
||||
} catch (e: InvocationTargetException) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue