Fixed packet singletons

This commit is contained in:
Auxilor 2020-09-21 21:13:39 +01:00
parent bea49ad2e7
commit 6096a37bf9
6 changed files with 8 additions and 40 deletions

View File

@ -9,15 +9,11 @@ import com.willfp.ecoenchants.EcoEnchantsPlugin;
import java.util.Collections;
public abstract class AbstractPacketAdapter extends PacketAdapter {
protected static AbstractPacketAdapter instance;
private final PacketType type;
protected AbstractPacketAdapter(PacketType type) {
super(EcoEnchantsPlugin.getInstance(), Collections.singletonList(type));
this.type = type;
instance = this;
}
public void onReceive(PacketContainer packet) {}

View File

@ -11,7 +11,7 @@ import java.util.List;
import java.util.stream.Collectors;
public final class PacketOpenWindowMerchant extends AbstractPacketAdapter {
private PacketOpenWindowMerchant() {
public PacketOpenWindowMerchant() {
super(PacketType.Play.Server.OPEN_WINDOW_MERCHANT);
}
@ -38,11 +38,4 @@ public final class PacketOpenWindowMerchant extends AbstractPacketAdapter {
packet.getMerchantRecipeLists().writeSafely(0, newList);
}
public static AbstractPacketAdapter getInstance() {
if(instance == null) {
instance = new PacketOpenWindowMerchant();
}
return instance;
}
}

View File

@ -6,7 +6,7 @@ import com.willfp.ecoenchants.display.AbstractPacketAdapter;
import com.willfp.ecoenchants.display.EnchantDisplay;
public final class PacketSetCreativeSlot extends AbstractPacketAdapter {
private PacketSetCreativeSlot() {
public PacketSetCreativeSlot() {
super(PacketType.Play.Client.SET_CREATIVE_SLOT);
}
@ -17,11 +17,4 @@ public final class PacketSetCreativeSlot extends AbstractPacketAdapter {
return item;
});
}
public static AbstractPacketAdapter getInstance() {
if(instance == null) {
instance = new PacketSetCreativeSlot();
}
return instance;
}
}

View File

@ -6,7 +6,7 @@ import com.willfp.ecoenchants.display.AbstractPacketAdapter;
import com.willfp.ecoenchants.display.EnchantDisplay;
public final class PacketSetSlot extends AbstractPacketAdapter {
private PacketSetSlot() {
public PacketSetSlot() {
super(PacketType.Play.Server.SET_SLOT);
}
@ -17,11 +17,4 @@ public final class PacketSetSlot extends AbstractPacketAdapter {
return item;
});
}
public static AbstractPacketAdapter getInstance() {
if(instance == null) {
instance = new PacketSetSlot();
}
return instance;
}
}

View File

@ -6,7 +6,7 @@ import com.willfp.ecoenchants.display.AbstractPacketAdapter;
import com.willfp.ecoenchants.display.EnchantDisplay;
public final class PacketWindowItems extends AbstractPacketAdapter {
private PacketWindowItems() {
public PacketWindowItems() {
super(PacketType.Play.Server.WINDOW_ITEMS);
}
@ -17,11 +17,4 @@ public final class PacketWindowItems extends AbstractPacketAdapter {
return itemStacks;
});
}
public static AbstractPacketAdapter getInstance() {
if(instance == null) {
instance = new PacketWindowItems();
}
return instance;
}
}

View File

@ -99,10 +99,10 @@ public class Loader {
Bukkit.getLogger().info("Loading ProtocolLib...");
EcoEnchantsPlugin.getInstance().protocolManager = ProtocolLibrary.getProtocolManager();
PacketOpenWindowMerchant.getInstance().register();
PacketSetCreativeSlot.getInstance().register();
PacketSetSlot.getInstance().register();
PacketWindowItems.getInstance().register();
new PacketOpenWindowMerchant().register();
new PacketSetCreativeSlot().register();
new PacketSetSlot().register();
new PacketWindowItems().register();
/*
Load land management support