When ops make changes to the servers blacklist entries, the change is sent out to all currently logged in players so that they remain in sync with the servers entries.
This commit is contained in:
parent
73fd3a4e28
commit
e9f834555f
6 changed files with 126 additions and 5 deletions
|
@ -33,7 +33,7 @@ public class BlacklistRegistry {
|
|||
|
||||
private final Set<WrappedStack> knowledgeBlacklist, exchangeBlacklist;
|
||||
public static File knowledgeBlacklistFile, exchangeBlacklistFile;
|
||||
private transient boolean loadedFromServer;
|
||||
private transient boolean shouldSave;
|
||||
|
||||
/**
|
||||
* TODO Finish JavaDoc
|
||||
|
@ -42,7 +42,7 @@ public class BlacklistRegistry {
|
|||
|
||||
knowledgeBlacklist = new TreeSet<>();
|
||||
exchangeBlacklist = new TreeSet<>();
|
||||
loadedFromServer = false;
|
||||
shouldSave = true;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -161,6 +161,10 @@ public class BlacklistRegistry {
|
|||
}
|
||||
}
|
||||
|
||||
public void setShouldSave(boolean shouldSave) {
|
||||
this.shouldSave = shouldSave;
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO Finish JavaDoc
|
||||
*/
|
||||
|
@ -185,7 +189,7 @@ public class BlacklistRegistry {
|
|||
|
||||
if (blacklist != null && blacklistSet != null) {
|
||||
|
||||
loadedFromServer = true;
|
||||
setShouldSave(false);
|
||||
|
||||
if (blacklist == Blacklist.KNOWLEDGE) {
|
||||
LogHelper.info("Received {} player knowledge blacklist entries from server", blacklistSet.size());
|
||||
|
@ -207,7 +211,7 @@ public class BlacklistRegistry {
|
|||
*/
|
||||
public void save(Blacklist blacklist) {
|
||||
|
||||
if (!loadedFromServer) {
|
||||
if (shouldSave) {
|
||||
if (blacklist == Blacklist.KNOWLEDGE) {
|
||||
LogHelper.trace(BLACKLIST_MARKER, "Saving player knowledge blacklist to {}", knowledgeBlacklistFile.getAbsolutePath());
|
||||
SerializationHelper.writeJsonFile(knowledgeBlacklistFile, SerializationHelper.GSON.toJson(knowledgeBlacklist));
|
||||
|
@ -224,7 +228,7 @@ public class BlacklistRegistry {
|
|||
*/
|
||||
public void saveAll() {
|
||||
|
||||
if (!loadedFromServer) {
|
||||
if (shouldSave) {
|
||||
LogHelper.trace(BLACKLIST_MARKER, "Saving all blacklists to disk", exchangeBlacklistFile.getAbsolutePath());
|
||||
SerializationHelper.writeJsonFile(knowledgeBlacklistFile, SerializationHelper.GSON.toJson(knowledgeBlacklist));
|
||||
SerializationHelper.writeJsonFile(exchangeBlacklistFile, SerializationHelper.GSON.toJson(exchangeBlacklist));
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
package com.pahimar.ee3.command;
|
||||
|
||||
import com.pahimar.ee3.api.blacklist.BlacklistRegistryProxy;
|
||||
import com.pahimar.ee3.network.PacketHandler;
|
||||
import com.pahimar.ee3.network.message.MessageSetBlacklistEntry;
|
||||
import com.pahimar.ee3.reference.Messages;
|
||||
import com.pahimar.ee3.reference.Names;
|
||||
import net.minecraft.command.CommandBase;
|
||||
|
@ -77,6 +79,7 @@ public class CommandSetItemLearnable extends CommandBase
|
|||
}
|
||||
|
||||
BlacklistRegistryProxy.removeFromBlacklist(itemStack, BlacklistRegistryProxy.Blacklist.KNOWLEDGE);
|
||||
PacketHandler.INSTANCE.sendToAll(new MessageSetBlacklistEntry(itemStack, BlacklistRegistryProxy.Blacklist.KNOWLEDGE, false));
|
||||
func_152373_a(commandSender, this, Messages.Commands.SET_ITEM_LEARNABLE_SUCCESS, new Object[]{commandSender.getCommandSenderName(), itemStack.func_151000_E()});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
package com.pahimar.ee3.command;
|
||||
|
||||
import com.pahimar.ee3.api.blacklist.BlacklistRegistryProxy;
|
||||
import com.pahimar.ee3.network.PacketHandler;
|
||||
import com.pahimar.ee3.network.message.MessageSetBlacklistEntry;
|
||||
import com.pahimar.ee3.reference.Messages;
|
||||
import com.pahimar.ee3.reference.Names;
|
||||
import net.minecraft.command.CommandBase;
|
||||
|
@ -77,6 +79,7 @@ public class CommandSetItemNotLearnable extends CommandBase
|
|||
}
|
||||
|
||||
BlacklistRegistryProxy.addToBlacklist(itemStack, BlacklistRegistryProxy.Blacklist.KNOWLEDGE);
|
||||
PacketHandler.INSTANCE.sendToAll(new MessageSetBlacklistEntry(itemStack, BlacklistRegistryProxy.Blacklist.KNOWLEDGE, true));
|
||||
func_152373_a(commandSender, this, Messages.Commands.SET_ITEM_NOT_LEARNABLE_SUCCESS, new Object[]{commandSender.getCommandSenderName(), itemStack.func_151000_E()});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
package com.pahimar.ee3.command;
|
||||
|
||||
import com.pahimar.ee3.api.blacklist.BlacklistRegistryProxy;
|
||||
import com.pahimar.ee3.network.PacketHandler;
|
||||
import com.pahimar.ee3.network.message.MessageSetBlacklistEntry;
|
||||
import com.pahimar.ee3.reference.Messages;
|
||||
import com.pahimar.ee3.reference.Names;
|
||||
import net.minecraft.command.CommandBase;
|
||||
|
@ -77,6 +79,7 @@ public class CommandSetItemNotRecoverable extends CommandBase
|
|||
}
|
||||
|
||||
BlacklistRegistryProxy.addToBlacklist(itemStack, BlacklistRegistryProxy.Blacklist.EXCHANGE);
|
||||
PacketHandler.INSTANCE.sendToAll(new MessageSetBlacklistEntry(itemStack, BlacklistRegistryProxy.Blacklist.EXCHANGE, true));
|
||||
func_152373_a(commandSender, this, Messages.Commands.SET_ITEM_NOT_RECOVERABLE_SUCCESS, new Object[]{commandSender.getCommandSenderName(), itemStack.func_151000_E()});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
package com.pahimar.ee3.command;
|
||||
|
||||
import com.pahimar.ee3.api.blacklist.BlacklistRegistryProxy;
|
||||
import com.pahimar.ee3.network.PacketHandler;
|
||||
import com.pahimar.ee3.network.message.MessageSetBlacklistEntry;
|
||||
import com.pahimar.ee3.reference.Messages;
|
||||
import com.pahimar.ee3.reference.Names;
|
||||
import net.minecraft.command.CommandBase;
|
||||
|
@ -77,6 +79,7 @@ public class CommandSetItemRecoverable extends CommandBase
|
|||
}
|
||||
|
||||
BlacklistRegistryProxy.removeFromBlacklist(itemStack, BlacklistRegistryProxy.Blacklist.EXCHANGE);
|
||||
PacketHandler.INSTANCE.sendToAll(new MessageSetBlacklistEntry(itemStack, BlacklistRegistryProxy.Blacklist.EXCHANGE, true));
|
||||
func_152373_a(commandSender, this, Messages.Commands.SET_ITEM_RECOVERABLE_SUCCESS, new Object[]{commandSender.getCommandSenderName(), itemStack.func_151000_E()});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,26 +1,131 @@
|
|||
package com.pahimar.ee3.network.message;
|
||||
|
||||
import com.google.gson.JsonParseException;
|
||||
import com.pahimar.ee3.api.blacklist.BlacklistRegistryProxy;
|
||||
import com.pahimar.ee3.blacklist.BlacklistRegistry;
|
||||
import com.pahimar.ee3.exchange.WrappedStack;
|
||||
import com.pahimar.ee3.util.CompressionHelper;
|
||||
import com.pahimar.ee3.util.LogHelper;
|
||||
import com.pahimar.ee3.util.SerializationHelper;
|
||||
import cpw.mods.fml.common.network.simpleimpl.IMessage;
|
||||
import cpw.mods.fml.common.network.simpleimpl.IMessageHandler;
|
||||
import cpw.mods.fml.common.network.simpleimpl.MessageContext;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
import static com.pahimar.ee3.api.blacklist.BlacklistRegistryProxy.Blacklist;
|
||||
|
||||
public class MessageSetBlacklistEntry implements IMessage, IMessageHandler<MessageSetBlacklistEntry, IMessage> {
|
||||
|
||||
public Blacklist blacklist;
|
||||
public boolean isBlacklistAction;
|
||||
public WrappedStack wrappedStack;
|
||||
|
||||
public MessageSetBlacklistEntry() {
|
||||
}
|
||||
|
||||
public MessageSetBlacklistEntry(Object object, Blacklist blacklist, boolean isBlacklistAction) {
|
||||
|
||||
if (WrappedStack.canBeWrapped(object)) {
|
||||
this.wrappedStack = WrappedStack.wrap(object, 1);
|
||||
}
|
||||
else {
|
||||
wrappedStack = null;
|
||||
}
|
||||
this.blacklist = blacklist;
|
||||
this.isBlacklistAction = isBlacklistAction;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fromBytes(ByteBuf buf) {
|
||||
|
||||
int blacklistOrdinal = buf.readInt();
|
||||
|
||||
if (blacklistOrdinal >= 0) {
|
||||
|
||||
if (blacklistOrdinal == 0) {
|
||||
blacklist = Blacklist.KNOWLEDGE;
|
||||
}
|
||||
else if (blacklistOrdinal == 1) {
|
||||
blacklist = Blacklist.EXCHANGE;
|
||||
}
|
||||
else {
|
||||
blacklist = null;
|
||||
}
|
||||
|
||||
if (blacklist != null) {
|
||||
|
||||
isBlacklistAction = buf.readBoolean();
|
||||
int compressedJsonLength = buf.readInt();
|
||||
|
||||
if (compressedJsonLength != 0) {
|
||||
|
||||
byte[] compressedWrappedStack = buf.readBytes(compressedJsonLength).array();
|
||||
|
||||
if (compressedWrappedStack != null) {
|
||||
|
||||
String jsonWrappedStack = CompressionHelper.decompress(compressedWrappedStack);
|
||||
|
||||
try {
|
||||
wrappedStack = SerializationHelper.GSON.fromJson(jsonWrappedStack, WrappedStack.class);
|
||||
}
|
||||
catch (JsonParseException e) {
|
||||
LogHelper.warn("Failed to receive {} blacklist data from server", blacklist);
|
||||
wrappedStack = null;
|
||||
}
|
||||
}
|
||||
else {
|
||||
wrappedStack = null;
|
||||
}
|
||||
}
|
||||
else {
|
||||
wrappedStack = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
blacklist = null;
|
||||
isBlacklistAction = false;
|
||||
wrappedStack = null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toBytes(ByteBuf buf) {
|
||||
|
||||
if (blacklist != null) {
|
||||
|
||||
buf.writeBoolean(isBlacklistAction);
|
||||
|
||||
if (wrappedStack != null && wrappedStack.getWrappedObject() != null) {
|
||||
|
||||
byte[] compressedWrappedStack = CompressionHelper.compress(SerializationHelper.GSON.toJson(wrappedStack));
|
||||
buf.writeInt(compressedWrappedStack.length);
|
||||
buf.writeBytes(compressedWrappedStack);
|
||||
}
|
||||
else {
|
||||
buf.writeInt(0);
|
||||
}
|
||||
}
|
||||
else {
|
||||
buf.writeInt(-1);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public IMessage onMessage(MessageSetBlacklistEntry message, MessageContext ctx) {
|
||||
|
||||
if (message.blacklist != null && message.wrappedStack != null) {
|
||||
|
||||
if (message.isBlacklistAction) {
|
||||
BlacklistRegistryProxy.addToBlacklist(message.wrappedStack, message.blacklist);
|
||||
BlacklistRegistry.INSTANCE.setShouldSave(false);
|
||||
}
|
||||
else {
|
||||
BlacklistRegistryProxy.removeFromBlacklist(message.wrappedStack, message.blacklist);
|
||||
BlacklistRegistry.INSTANCE.setShouldSave(false);
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue