Résolu Tableau de String et d'int dans un Packet
-
Salut !
J’aimerais envoyer des tableaux de String et d’int dans un packet mais, il y a pas de méthode du style ByteBufUtils.readStringTableau(“Truc”);
ou buf.readStringTableau(“Truc”);Faut-il passer par des boucle for ?
Et comment faire pour l’envoi du Packet je dois tout marqué ? this.raisonInterpol[0], this.raisonInterpol[1], this.raisonInterpol[2]… ?
ModAltisCraft.instance.network.sendToServer(new PacketRestrainServer(this.escorte, this.menotte, this.cash, this.money, this.spawned, this.vip, this.vipp, this.rebelle, this.staff, this.gendarme, this.adjoint, this.brigadier, this.sergent, this.adjudant, this.major, this.aspirant, this.lieutenant, this.capitaine, this.commandant, this.colonel, this.general, this.bac, this.transaltis, this.samu, this.garagiste, this.antv, this.velo, this.conduire, this.camion, this.bateau, this.arme, this.pilote, this.diamant, this.archeologie, this.gang, this.raisonInterpol[]));
Merci d’avance
-
T’es obligé de faire une boucle for (), en tous cas c’est ce que moi j’ai fais
Et au lieu de faire de tonnes de ce que je crois étre des boolean, t’aurai pu faire un int qui, selon à quoi il est égal, donne le grade
-
Tu peux m’envoyer un de tes packets avec un tableau s’il te plaît je galère :S
-
Peux pas tt de suite (pas chez moi) mais ds une heure oui
Mais simplement, tu writr la taille du tableau puis pour chaque string tu le write (dans un for).
Après à la réception, tu récupères la taille du tableau, tu re crées un tableau de cette taille et dans un autre for, tu le remplis. -
Ok pas de soucis merci
-
Dans public void toBytes(ByteBuf buf) :
buf.writeInt(this.nomDuTableau.lenght); for(int i = 0; i < this.nomDuTableau.lenght; i++) { ByteBufUtils.writeUTF8String(buf, this.nomDuTableau*); }
Dans public void fromBytes(ByteBuf buf) :
this.nomDuTableau = new String[buf.readInt()]; for(int i = 0; i < this.nomDuTableau.lenght; i++) { this.nomDuTableau* = ByteBufUtils.readUTF8String(buf); }
-
Robin t’a répondu à ma place
-
D’accord merci mais comment je fais pour l’envoi du packet ? C’est surtout pour ça que je galère…
J’aimerais faire un truc clean comme ça en une fois et ne pas faire le galérien comme ça…
ModAltisCraft.instance.network.sendToServer(new PacketRestrainServer(this.raisonInterpol[]));
ModAltisCraft.instance.network.sendToServer(new PacketRestrainServer(this.raisonInterpol[0],this.raisonInterpol[1],this.raisonInterpol[2],this.raisonInterpol[3],this.raisonInterpol[4]…));
-
ModAltisCraft.instance.network.sendToServer(new PacketRestrainServer(this.raisonInterpol));
Juste comme ça.
Et dans le constructeur tu mets directement un tableau de String. -
Ok nice je vais tester
-
Mais juste j’ai un doute ça va si je fais comme ça dans le constructeur du Packet ?
public PacketRestrainServer(String[] raisonInterpol, int[] montantInterpol) { this.raisonInterpol = raisonInterpol; this.montantInterpol = montantInterpol; }
Ou faut aussi que je fasse une boucle ici ?
-
Non pas de boucle dans le constructeur.
-
J’ai l’impression que y a du NPE dans l’air, la sync marche plus très bien.
Mon ExtendedProperties
public String[] raisonInterpol = new String[50]; public int[] montantInterpol = new int[50]; for(int i = 0; i < this.raisonInterpol.length; i++) { this.raisonInterpol* = ""; } for(int i = 0; i < this.montantInterpol.length; i++) { this.montantInterpol* = 0; } for(int i = 0; i < this.raisonInterpol.length; i++) { properties.setString("raisonInterpol" + i, this.raisonInterpol*); } for(int i = 0; i < this.montantInterpol.length; i++) { properties.setInteger("montantInterpol" + i, this.montantInterpol*); } for(int i = 0; i < this.raisonInterpol.length; i++) { this.raisonInterpol* = properties.getString("raisonInterpol" + i); } for(int i = 0; i < this.montantInterpol.length; i++) { this.montantInterpol* = properties.getInteger("montantInterpol" + i); } public final void sync() { if(player.worldObj.isRemote) { ModAltisCraft.instance.network.sendToServer(new PacketRestrainServer(this.escorte, this.menotte, this.cash, this.money, this.spawned, this.vip, this.vipp, this.rebelle, this.staff, this.gendarme, this.adjoint, this.brigadier, this.sergent, this.adjudant, this.major, this.aspirant, this.lieutenant, this.capitaine, this.commandant, this.colonel, this.general, this.bac, this.transaltis, this.samu, this.garagiste, this.antv, this.velo, this.conduire, this.camion, this.bateau, this.arme, this.pilote, this.diamant, this.archeologie, this.gang, this.raisonInterpol, this.montantInterpol)); } if(!player.worldObj.isRemote) { EntityPlayerMP player1 = (EntityPlayerMP)player; ModAltisCraft.instance.network.sendTo(new PacketRestrainClientServer(this.escorte, this.menotte, this.cash, this.money, this.spawned, this.vip, this.vipp, this.rebelle, this.staff, this.gendarme, this.adjoint, this.brigadier, this.sergent, this.adjudant, this.major, this.aspirant, this.lieutenant, this.capitaine, this.commandant, this.colonel, this.general, this.bac, this.transaltis, this.samu, this.garagiste, this.antv, this.velo, this.conduire, this.camion, this.bateau, this.arme, this.pilote, this.diamant, this.archeologie, this.gang, this.raisonInterpol, this.montantInterpol), player1); } }
Les packets de Sync
package fr.altiscraft.benjaminloison.packets; import cpw.mods.fml.common.network.ByteBufUtils; 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 fr.altiscraft.benjaminloison.entity.EEPRestrained; import io.netty.buffer.ByteBuf; import net.minecraft.entity.player.EntityPlayer; public class PacketRestrainServer implements IMessage { private boolean escorte, menotte, isMoney, spawned, vip, vipp, rebelle, staff, gendarme, adjoint, brigadier, sergent, adjudant, aspirant, major, lieutenant, capitaine, commandant, colonel, general, bac, transaltis, samu, garagiste, antv, velo, conduire, camion, bateau, arme, pilote, diamant, archeologie; private long money, cash; private String gang; private String[] raisonInterpol; private int[] montantInterpol; public PacketRestrainServer(boolean escorte, boolean menotte, long cash, long money, boolean spawned, boolean vip, boolean vipp, boolean rebelle, boolean staff, boolean gendarme, boolean adjoint, boolean brigadier, boolean sergent, boolean adjudant, boolean major, boolean aspirant, boolean lieutenant, boolean capitaine, boolean commandant, boolean colonel, boolean general, boolean bac, boolean transaltis, boolean samu, boolean garagiste, boolean antv, boolean velo, boolean conduire, boolean camion, boolean bateau, boolean arme, boolean pilote, boolean diamant, boolean archeologie, String gang, String[] raisonInterpol, int[] montantInterpol) { this.escorte = escorte; this.menotte = menotte; this.cash = cash; this.money = money; this.spawned = spawned; this.vip = vip; this.vipp = vipp; this.rebelle = rebelle; this.staff = staff; this.gendarme = gendarme; this.adjoint = adjoint; this.brigadier = brigadier; this.sergent = sergent; this.adjudant = adjudant; this.aspirant = aspirant; this.major = major; this.lieutenant = lieutenant; this.capitaine = capitaine; this.commandant = commandant; this.colonel = colonel; this.general = general; this.bac = bac; this.transaltis = transaltis; this.samu = samu; this.garagiste = garagiste; this.antv = antv; this.velo = velo; this.conduire = conduire; this.camion = camion; this.bateau = bateau; this.arme = arme; this.pilote = pilote; this.diamant = diamant; this.archeologie = archeologie; this.gang = gang; this.raisonInterpol = raisonInterpol; this.montantInterpol = montantInterpol; } public PacketRestrainServer() {} @Override public void fromBytes(ByteBuf buf) { this.escorte = buf.readBoolean(); this.menotte = buf.readBoolean(); this.spawned = buf.readBoolean(); this.money = buf.readLong(); this.cash = buf.readLong(); this.vip = buf.readBoolean(); this.vipp = buf.readBoolean(); this.rebelle = buf.readBoolean(); this.staff = buf.readBoolean(); this.gendarme = buf.readBoolean(); this.adjoint = buf.readBoolean(); this.brigadier = buf.readBoolean(); this.sergent = buf.readBoolean(); this.adjudant = buf.readBoolean(); this.major = buf.readBoolean(); this.aspirant = buf.readBoolean(); this.lieutenant = buf.readBoolean(); this.capitaine = buf.readBoolean(); this.commandant = buf.readBoolean(); this.colonel = buf.readBoolean(); this.general = buf.readBoolean(); this.bac = buf.readBoolean(); this.transaltis = buf.readBoolean(); this.samu = buf.readBoolean(); this.garagiste = buf.readBoolean(); this.antv = buf.readBoolean(); this.velo = buf.readBoolean(); this.conduire = buf.readBoolean(); this.camion = buf.readBoolean(); this.bateau = buf.readBoolean(); this.arme = buf.readBoolean(); this.pilote = buf.readBoolean(); this.diamant = buf.readBoolean(); this.archeologie = buf.readBoolean(); this.gang = ByteBufUtils.readUTF8String(buf); this.raisonInterpol = new String[buf.readInt()]; for(int i = 0; i < this.raisonInterpol.length; i++) { this.raisonInterpol* = ByteBufUtils.readUTF8String(buf); } this.montantInterpol = new int[buf.readInt()]; for(int i = 0; i < this.montantInterpol.length; i++) { this.montantInterpol* = buf.readInt(); } } @Override public void toBytes(ByteBuf buf) { buf.writeBoolean(this.escorte); buf.writeBoolean(this.menotte); buf.writeBoolean(this.spawned); buf.writeLong(this.money); buf.writeLong(this.cash); buf.writeBoolean(this.vip); buf.writeBoolean(this.vipp); buf.writeBoolean(this.rebelle); buf.writeBoolean(this.staff); buf.writeBoolean(this.gendarme); buf.writeBoolean(this.adjoint); buf.writeBoolean(this.brigadier); buf.writeBoolean(this.sergent); buf.writeBoolean(this.adjudant); buf.writeBoolean(this.major); buf.writeBoolean(this.aspirant); buf.writeBoolean(this.lieutenant); buf.writeBoolean(this.capitaine); buf.writeBoolean(this.commandant); buf.writeBoolean(this.colonel); buf.writeBoolean(this.general); buf.writeBoolean(this.bac); buf.writeBoolean(this.transaltis); buf.writeBoolean(this.samu); buf.writeBoolean(this.garagiste); buf.writeBoolean(this.antv); buf.writeBoolean(this.velo); buf.writeBoolean(this.conduire); buf.writeBoolean(this.camion); buf.writeBoolean(this.bateau); buf.writeBoolean(this.arme); buf.writeBoolean(this.pilote); buf.writeBoolean(this.diamant); buf.writeBoolean(this.archeologie); ByteBufUtils.writeUTF8String(buf, this.gang); buf.writeInt(this.raisonInterpol.length); for(int i = 0; i < this.raisonInterpol.length; i++) { ByteBufUtils.writeUTF8String(buf, this.raisonInterpol*); } buf.writeInt(this.montantInterpol.length); for(int i = 0; i < this.montantInterpol.length; i++) { buf.writeInt(this.montantInterpol*); } } public static class Handler implements IMessageHandler <packetrestrainserver, imessage="">{ @Override public IMessage onMessage(PacketRestrainServer message, MessageContext ctx) { EntityPlayer player = ctx.getServerHandler().playerEntity; EEPRestrained props = EEPRestrained.get(player); props.escorte = message.escorte; props.menotte = message.menotte; props.money = message.money; props.cash = message.cash; props.spawned = message.spawned; props.vip = message.vip; props.vipp = message.vipp; props.rebelle = message.rebelle; props.staff = message.staff; props.gendarme = message.gendarme; props.adjoint = message.adjoint; props.brigadier = message.brigadier; props.sergent = message.sergent; props.adjudant = message.adjudant; props.major = message.major; props.aspirant = message.aspirant; props.capitaine = message.capitaine; props.commandant = message.commandant; props.colonel = message.colonel; props.general = message.general; props.bac = message.bac; props.transaltis = message.transaltis; props.samu = message.samu; props.garagiste = message.garagiste; props.antv = message.antv; props.velo = message.velo; props.conduire = message.conduire; props.camion = message.camion; props.bateau = message.bateau; props.arme = message.arme; props.pilote = message.pilote; props.diamant = message.diamant; props.archeologie = message.archeologie; props.gang = message.gang; props.raisonInterpol = message.raisonInterpol; props.montantInterpol = message.montantInterpol; return null; } } } package fr.altiscraft.benjaminloison.packets; import cpw.mods.fml.common.network.ByteBufUtils; 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 cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; import fr.altiscraft.benjaminloison.entity.EEPRestrained; import io.netty.buffer.ByteBuf; import net.minecraft.client.Minecraft; import net.minecraft.entity.player.EntityPlayer; public class PacketRestrainClientServer implements IMessage { private boolean escorte, menotte, isMoney, spawned, vip, vipp, rebelle, staff, gendarme, adjoint, brigadier, sergent, adjudant, major, aspirant, lieutenant, capitaine, commandant, colonel, general, bac, transaltis, samu, garagiste, antv, velo, conduire, camion, bateau, arme, pilote, diamant, archeologie; private long money, cash; private String gang; private String[] raisonInterpol; private int[] montantInterpol; public PacketRestrainClientServer(boolean escorte, boolean menotte, long cash, long money, boolean spawned, boolean vip, boolean vipp, boolean rebelle, boolean staff, boolean gendarme, boolean adjoint, boolean brigadier, boolean sergent, boolean adjudant, boolean major, boolean aspirant, boolean lieutenant, boolean capitaine, boolean commandant, boolean colonel, boolean general, boolean bac, boolean transaltis, boolean samu, boolean garagiste, boolean antv, boolean velo, boolean conduire, boolean camion, boolean bateau, boolean arme, boolean pilote, boolean diamant, boolean archeologie, String gang, String[] raisonInterpol, int[] montantInterpol) { this.escorte = escorte; this.menotte = menotte; this.cash = cash; this.money = money; this.spawned = spawned; this.vip = vip; this.vipp = vipp; this.rebelle = rebelle; this.staff = staff; this.gendarme = gendarme; this.adjoint = adjoint; this.brigadier = brigadier; this.sergent = sergent; this.adjudant = adjudant; this.major = major; this.aspirant = aspirant; this.lieutenant = lieutenant; this.capitaine = capitaine; this.commandant = commandant; this.colonel = colonel; this.general = general; this.bac = bac; this.transaltis = transaltis; this.samu = samu; this.garagiste = garagiste; this.antv = antv; this.velo = velo; this.conduire = conduire; this.camion = camion; this.bateau = bateau; this.arme = arme; this.pilote = pilote; this.diamant = diamant; this.archeologie = archeologie; this.gang = gang; this.raisonInterpol = raisonInterpol; this.montantInterpol = montantInterpol; } public PacketRestrainClientServer() {} @Override public void fromBytes(ByteBuf buf) { this.escorte = buf.readBoolean(); this.menotte = buf.readBoolean(); this.spawned = buf.readBoolean(); this.money = buf.readLong(); this.cash = buf.readLong(); this.vip = buf.readBoolean(); this.vipp = buf.readBoolean(); this.rebelle = buf.readBoolean(); this.staff = buf.readBoolean(); this.gendarme = buf.readBoolean(); this.adjoint = buf.readBoolean(); this.brigadier = buf.readBoolean(); this.sergent = buf.readBoolean(); this.adjudant = buf.readBoolean(); this.major = buf.readBoolean(); this.aspirant = buf.readBoolean(); this.lieutenant = buf.readBoolean(); this.capitaine = buf.readBoolean(); this.commandant = buf.readBoolean(); this.colonel = buf.readBoolean(); this.general = buf.readBoolean(); this.bac = buf.readBoolean(); this.transaltis = buf.readBoolean(); this.samu = buf.readBoolean(); this.garagiste = buf.readBoolean(); this.antv = buf.readBoolean(); this.velo = buf.readBoolean(); this.conduire = buf.readBoolean(); this.camion = buf.readBoolean(); this.bateau = buf.readBoolean(); this.arme = buf.readBoolean(); this.pilote = buf.readBoolean(); this.diamant = buf.readBoolean(); this.archeologie = buf.readBoolean(); this.gang = ByteBufUtils.readUTF8String(buf); this.raisonInterpol = new String[buf.readInt()]; for(int i = 0; i < this.raisonInterpol.length; i++) { this.raisonInterpol* = ByteBufUtils.readUTF8String(buf); } this.montantInterpol = new int[buf.readInt()]; for(int i = 0; i < this.montantInterpol.length; i++) { this.montantInterpol* = buf.readInt(); } } @Override public void toBytes(ByteBuf buf) { buf.writeBoolean(this.escorte); buf.writeBoolean(this.menotte); buf.writeBoolean(this.spawned); buf.writeLong(this.money); buf.writeLong(this.cash); buf.writeBoolean(this.vip); buf.writeBoolean(this.vipp); buf.writeBoolean(this.rebelle); buf.writeBoolean(this.staff); buf.writeBoolean(this.gendarme); buf.writeBoolean(this.adjoint); buf.writeBoolean(this.brigadier); buf.writeBoolean(this.sergent); buf.writeBoolean(this.adjudant); buf.writeBoolean(this.major); buf.writeBoolean(this.aspirant); buf.writeBoolean(this.lieutenant); buf.writeBoolean(this.capitaine); buf.writeBoolean(this.commandant); buf.writeBoolean(this.colonel); buf.writeBoolean(this.general); buf.writeBoolean(this.bac); buf.writeBoolean(this.transaltis); buf.writeBoolean(this.samu); buf.writeBoolean(this.garagiste); buf.writeBoolean(this.antv); buf.writeBoolean(this.velo); buf.writeBoolean(this.conduire); buf.writeBoolean(this.camion); buf.writeBoolean(this.bateau); buf.writeBoolean(this.arme); buf.writeBoolean(this.pilote); buf.writeBoolean(this.diamant); buf.writeBoolean(this.archeologie); ByteBufUtils.writeUTF8String(buf, this.gang); buf.writeInt(this.raisonInterpol.length); for(int i = 0; i < this.raisonInterpol.length; i++) { ByteBufUtils.writeUTF8String(buf, this.raisonInterpol*); } buf.writeInt(this.montantInterpol.length); for(int i = 0; i < this.montantInterpol.length; i++) { buf.writeInt(this.montantInterpol*); } } public static class Handler implements IMessageHandler <packetrestrainclientserver, imessage="">{ @Override @SideOnly(Side.CLIENT) public IMessage onMessage(PacketRestrainClientServer message, MessageContext ctx) { EntityPlayer player = Minecraft.getMinecraft().thePlayer; EEPRestrained props = EEPRestrained.get(player); props.escorte = message.escorte; props.menotte = message.menotte; props.money = message.money; props.cash = message.cash; props.spawned = message.spawned; props.vip = message.vip; props.vipp = message.vipp; props.rebelle = message.rebelle; props.staff = message.staff; props.gendarme = message.gendarme; props.adjoint = message.adjoint; props.brigadier = message.brigadier; props.sergent = message.sergent; props.adjudant = message.adjudant; props.major = message.major; props.aspirant = message.aspirant; props.capitaine = message.capitaine; props.commandant = message.commandant; props.colonel = message.colonel; props.general = message.general; props.bac = message.bac; props.transaltis = message.transaltis; props.samu = message.samu; props.garagiste = message.garagiste; props.antv = message.antv; props.velo = message.velo; props.conduire = message.conduire; props.camion = message.camion; props.bateau = message.bateau; props.arme = message.arme; props.pilote = message.pilote; props.diamant = message.diamant; props.archeologie = message.archeologie; props.gang = message.gang; props.raisonInterpol = message.raisonInterpol; props.montantInterpol = message.montantInterpol; return null; } } } ```</packetrestrainclientserver,></packetrestrainserver,>
-
Logs ?
-
Lorsque je tue quelqu’un :
@SideOnly(Side.SERVER) @SubscribeEvent public void onPlayerKill(LivingDeathEvent event) { if(event.entity instanceof EntityPlayer) { if(event.source.getEntity() instanceof EntityPlayer) { EntityPlayer playerSource = (EntityPlayer)event.source.getEntity(); EntityPlayer playerKilled = (EntityPlayer)event.entity; if(playerSource != null) { if(playerKilled != null) { playerSource.addChatMessage(new ChatComponentText(EnumChatFormatting.RED + "Vous avez tue " + playerKilled.getEntityId())); playerKilled.addChatMessage(new ChatComponentText(EnumChatFormatting.RED + "Vous avez ete tue par " + playerSource.getEntityId())); EEPRestrained props = EEPRestrained.get(playerSource); EEPRestrained propse = EEPRestrained.get(playerKilled); props.addInterpol("Meurte",10000); props.resetInterpol(); List <entityplayermp>players = MinecraftServer.getServer().getConfigurationManager().playerEntityList; props.setCash(props.cash + propse.cash); propse.setCash(0); for(EntityPlayerMP player : players) { EEPRestrained propsee = EEPRestrained.get(player); if(propsee.gendarme || propsee.staff && playerSource != player) { player.addChatMessage(new ChatComponentText(EnumChatFormatting.GREEN + playerSource.getDisplayName() + EnumChatFormatting.AQUA + " (" + EnumChatFormatting.WHITE + playerSource.getEntityId() + EnumChatFormatting.AQUA + ") " + EnumChatFormatting.RED + "a tu" + I18n.format("accent.er") + " " + EnumChatFormatting.GREEN + playerKilled.getDisplayName() + EnumChatFormatting.AQUA + " (" + EnumChatFormatting.WHITE + playerKilled.getEntityId() + EnumChatFormatting.AQUA + ")")); } else if(propsee.samu && !propsee.gendarme && !propsee.staff && playerSource != player) { player.addChatMessage(new ChatComponentText(EnumChatFormatting.GREEN + playerKilled.getDisplayName() + EnumChatFormatting.AQUA + " (" + EnumChatFormatting.WHITE + playerKilled.getEntityId() + EnumChatFormatting.AQUA + ") " + EnumChatFormatting.RED + "est mort.")); } } } } } } }
Juste en un kill j’ai tout ça d’erreur :
Ma classe Extended en entière :
package fr.altiscraft.benjaminloison.entity; import fr.altiscraft.benjaminloison.common.ModAltisCraft; import fr.altiscraft.benjaminloison.packets.PacketMessage; import fr.altiscraft.benjaminloison.packets.PacketRestrainClientServer; import fr.altiscraft.benjaminloison.packets.PacketRestrainServer; import fr.altiscraft.benjaminloison.proxy.CommonProxy; import net.minecraft.entity.Entity; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.init.Items; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.world.World; import net.minecraftforge.common.IExtendedEntityProperties; public class EEPRestrained implements IExtendedEntityProperties { public final static String EXT_PROP_NAME = "EEPRestrained"; private EntityPlayer player; public long cash, money; public boolean escorte, menotte, spawned, vip, vipp, rebelle, staff, gendarme, adjoint, brigadier, sergent, adjudant, aspirant, major, lieutenant, capitaine, commandant, colonel, general, bac, transaltis, samu, garagiste, antv, velo, conduire, camion, bateau, arme, pilote, diamant, archeologie; public String gang; public String[] raisonInterpol = new String[50]; public int[] montantInterpol = new int[50]; public EEPRestrained(EntityPlayer player) { this.player = player; this.escorte = false; this.menotte = false; this.cash = 0; this.money = 0; this.spawned = false; this.vip = false; this.vipp = false; this.rebelle = false; this.staff = false; this.gendarme = false; this.adjoint = false; this.brigadier = false; this.sergent = false; this.adjudant = false; this.aspirant = false; this.major = false; this.lieutenant = false; this.capitaine = false; this.commandant = false; this.colonel = false; this.general = false; this.bac = false; this.transaltis = false; this.samu = false; this.garagiste = false; this.antv = false; this.velo = false; this.conduire = false; this.camion = false; this.bateau = false; this.arme = false; this.pilote = false; this.diamant = false; this.archeologie = false; this.gang = ""; for(int i = 0; i < this.raisonInterpol.length; i++) { this.raisonInterpol* = ""; } for(int i = 0; i < this.montantInterpol.length; i++) { this.montantInterpol* = 0; } } public static final void register(EntityPlayer player) { player.registerExtendedProperties(EEPRestrained.EXT_PROP_NAME, new EEPRestrained(player)); } public static final EEPRestrained get(EntityPlayer player) { return (EEPRestrained)player.getExtendedProperties(EXT_PROP_NAME); } @Override public void saveNBTData(NBTTagCompound compound) { NBTTagCompound properties = new NBTTagCompound(); properties.setBoolean("Escorte", this.escorte); properties.setBoolean("Menotte", this.menotte); properties.setLong("Cash", this.cash); properties.setLong("Money", this.money); properties.setBoolean("vip", this.vip); properties.setBoolean("vipp", this.vipp); properties.setBoolean("rebelle", this.rebelle); properties.setBoolean("staff", this.staff); properties.setBoolean("gendarme", this.gendarme); properties.setBoolean("adjoint", this.adjoint); properties.setBoolean("brigadier", this.brigadier); properties.setBoolean("sergent", this.sergent); properties.setBoolean("adjudant", this.adjudant); properties.setBoolean("major", this.major); properties.setBoolean("aspirant", this.aspirant); properties.setBoolean("lieutenant", this.lieutenant); properties.setBoolean("capitaine", this.capitaine); properties.setBoolean("commandant", this.commandant); properties.setBoolean("colonel", this.colonel); properties.setBoolean("general", this.general); properties.setBoolean("bac", this.bac); properties.setBoolean("transaltis", this.transaltis); properties.setBoolean("samu", this.samu); properties.setBoolean("garagiste", this.garagiste); properties.setBoolean("antv", this.antv); properties.setBoolean("velo", this.velo); properties.setBoolean("conduire", this.conduire); properties.setBoolean("camion", this.camion); properties.setBoolean("bateau", this.bateau); properties.setBoolean("arme", this.arme); properties.setBoolean("pilote", this.pilote); properties.setBoolean("diamant", this.diamant); properties.setBoolean("archeologie", this.archeologie); properties.setString("gang", this.gang); for(int i = 0; i < this.raisonInterpol.length; i++) { properties.setString("raisonInterpol" + i, this.raisonInterpol*); } for(int i = 0; i < this.montantInterpol.length; i++) { properties.setInteger("montantInterpol" + i, this.montantInterpol*); } compound.setTag(EXT_PROP_NAME, properties); } public void saveNBTDataMoney(NBTTagCompound compound) { NBTTagCompound properties = new NBTTagCompound(); properties.setLong("Money", this.money); properties.setBoolean("vip", this.vip); properties.setBoolean("vipp", this.vipp); properties.setBoolean("rebelle", this.rebelle); properties.setBoolean("staff", this.staff); properties.setBoolean("gendarme", this.gendarme); properties.setBoolean("adjoint", this.adjoint); properties.setBoolean("brigadier", this.brigadier); properties.setBoolean("sergent", this.sergent); properties.setBoolean("adjudant", this.adjudant); properties.setBoolean("aspirant", this.aspirant); properties.setBoolean("major", this.major); properties.setBoolean("lieutenant", this.lieutenant); properties.setBoolean("capitaine", this.capitaine); properties.setBoolean("commandant", this.commandant); properties.setBoolean("colonel", this.colonel); properties.setBoolean("general", this.general); properties.setBoolean("bac", this.bac); properties.setBoolean("transaltis", this.transaltis); properties.setBoolean("samu", this.samu); properties.setBoolean("garagiste", this.garagiste); properties.setBoolean("antv", this.antv); properties.setBoolean("velo", this.velo); properties.setBoolean("conduire", this.conduire); properties.setBoolean("camion", this.camion); properties.setBoolean("bateau", this.bateau); properties.setBoolean("arme", this.arme); properties.setBoolean("pilote", this.pilote); properties.setBoolean("diamant", this.diamant); properties.setBoolean("archeologie", this.archeologie); properties.setString("gang", this.gang); compound.setTag(EXT_PROP_NAME, properties); } @Override public void loadNBTData(NBTTagCompound compound) { NBTTagCompound properties = (NBTTagCompound)compound.getTag(EXT_PROP_NAME); this.escorte = properties.getBoolean("Escorte"); this.menotte = properties.getBoolean("Menotte"); this.cash = properties.getLong("Cash"); this.money = properties.getLong("Money"); this.vip = properties.getBoolean("vip"); this.vipp = properties.getBoolean("vipp"); this.rebelle = properties.getBoolean("rebelle"); this.staff = properties.getBoolean("staff"); this.gendarme = properties.getBoolean("gendarme"); this.adjoint = properties.getBoolean("adjoint"); this.brigadier = properties.getBoolean("brigadier"); this.sergent = properties.getBoolean("sergent"); this.adjudant = properties.getBoolean("adjudant"); this.major = properties.getBoolean("major"); this.aspirant = properties.getBoolean("aspirant"); this.lieutenant = properties.getBoolean("lieutenant"); this.capitaine = properties.getBoolean("capitaine"); this.commandant = properties.getBoolean("commandant"); this.colonel = properties.getBoolean("colonel"); this.general = properties.getBoolean("general"); this.bac = properties.getBoolean("bac"); this.transaltis = properties.getBoolean("transaltis"); this.samu = properties.getBoolean("samu"); this.garagiste = properties.getBoolean("garagiste"); this.antv = properties.getBoolean("antv"); this.velo = properties.getBoolean("velo"); this.conduire = properties.getBoolean("conduire"); this.camion = properties.getBoolean("camion"); this.bateau = properties.getBoolean("bateau"); this.arme = properties.getBoolean("arme"); this.pilote = properties.getBoolean("pilote"); this.diamant = properties.getBoolean("diamant"); this.archeologie = properties.getBoolean("archeologie"); this.gang = properties.getString("gang"); for(int i = 0; i < this.raisonInterpol.length; i++) { this.raisonInterpol* = properties.getString("raisonInterpol" + i); } for(int i = 0; i < this.montantInterpol.length; i++) { this.montantInterpol* = properties.getInteger("montantInterpol" + i); } } @Override public void init(Entity entity, World world) {} public final void sync() { if(player.worldObj.isRemote) { ModAltisCraft.instance.network.sendToServer(new PacketRestrainServer(this.escorte, this.menotte, this.cash, this.money, this.spawned, this.vip, this.vipp, this.rebelle, this.staff, this.gendarme, this.adjoint, this.brigadier, this.sergent, this.adjudant, this.major, this.aspirant, this.lieutenant, this.capitaine, this.commandant, this.colonel, this.general, this.bac, this.transaltis, this.samu, this.garagiste, this.antv, this.velo, this.conduire, this.camion, this.bateau, this.arme, this.pilote, this.diamant, this.archeologie, this.gang, this.raisonInterpol, this.montantInterpol)); } if(!player.worldObj.isRemote) { EntityPlayerMP player1 = (EntityPlayerMP)player; ModAltisCraft.instance.network.sendTo(new PacketRestrainClientServer(this.escorte, this.menotte, this.cash, this.money, this.spawned, this.vip, this.vipp, this.rebelle, this.staff, this.gendarme, this.adjoint, this.brigadier, this.sergent, this.adjudant, this.major, this.aspirant, this.lieutenant, this.capitaine, this.commandant, this.colonel, this.general, this.bac, this.transaltis, this.samu, this.garagiste, this.antv, this.velo, this.conduire, this.camion, this.bateau, this.arme, this.pilote, this.diamant, this.archeologie, this.gang, this.raisonInterpol, this.montantInterpol), player1); } } private static String getSaveKey(EntityPlayer player) { return player.getDisplayName() + ":" + EXT_PROP_NAME; } public static void saveProxyData(EntityPlayer player) { EEPRestrained playerData = EEPRestrained.get(player); NBTTagCompound savedData = new NBTTagCompound(); playerData.saveNBTData(savedData); CommonProxy.storeEntityData(getSaveKey(player), savedData); } public static void loadProxyData(EntityPlayer player) { EEPRestrained playerData = EEPRestrained.get(player); NBTTagCompound savedData = CommonProxy.getEntityData(getSaveKey(player)); if(savedData != null) { playerData.loadNBTData(savedData); } playerData.sync(); } public void creditCash(Item item, int prix) { if(player.inventory.hasItem(ModAltisCraft.CarteBancaire)) { if(cash + money >= prix) { setMoney(getMoney() - (prix - cash)); setCash(0); } } else { ModAltisCraft.instance.network.sendTo(new PacketMessage("t4.notenoughmoney ", true), (EntityPlayerMP)player); sync(); } } public void menotte() { this.menotte = true; this.sync(); } public void resetInterpol() { this.raisonInterpol = null; this.montantInterpol = null; this.sync(); } public void addInterpol(String raison, int montant) { for(int i = 0; i < this.raisonInterpol.length; i++) { if(this.raisonInterpol*.equals("") && this.raisonInterpol* != null) { this.raisonInterpol* = raison; this.montantInterpol* = montant; } } this.sync(); } public void vip(boolean vip2) { this.vip = vip2; this.sync(); } public boolean getvip() { return this.vip; } public void vipp(boolean vipp2) { this.vipp = vipp2; this.sync(); } public boolean getvipp() { return this.vipp; } public void rebelle(boolean rebelle2) { this.rebelle = rebelle2; this.sync(); } public boolean getrebelle() { return this.rebelle; } public void staff(boolean staff2) { this.staff = staff2; this.sync(); } public boolean getstaff() { return this.staff; } public void gendarme(boolean gendarme2) { this.gendarme = gendarme2; this.sync(); } public boolean getgendarme() { return this.gendarme; } public void gang(String gang2) { this.gang = gang2; this.sync(); } public String getgang() { return this.gang; } public void adjoint(boolean adjoint2) { this.adjoint = adjoint2; this.sync(); } public boolean getadjoint() { return this.adjoint; } public void brigadier(boolean brigadier2) { this.brigadier = brigadier2; this.sync(); } public boolean getbrigadier() { return this.brigadier; } public void sergent(boolean sergent2) { this.sergent = sergent2; this.sync(); } public boolean getsergent() { return this.sergent; } public void adjudant(boolean adjudant2) { this.adjudant = adjudant2; this.sync(); } public boolean getadjudant() { return this.adjudant; } public void major(boolean major2) { this.major = major2; this.sync(); } public boolean getmajor() { return this.major; } public void aspirant(boolean aspirant2) { this.aspirant = aspirant2; this.sync(); } public boolean getaspirant() { return this.aspirant; } public void lieutenant(boolean lieutenant2) { this.lieutenant = lieutenant2; this.sync(); } public boolean getlieutenant() { return this.lieutenant; } public void escorte(boolean escorte2) { this.escorte = escorte2; this.sync(); } public boolean getescorte() { return this.escorte; } public void capitaine(boolean capitaine2) { this.capitaine = capitaine2; this.sync(); } public boolean getcapitaine() { return this.capitaine; } public void commandant(boolean commandant2) { this.commandant = commandant2; this.sync(); } public boolean getcommandant() { return this.commandant; } public void colonel(boolean colonel2) { this.colonel = colonel2; this.sync(); } public boolean getcolonel() { return this.colonel; } public void general(boolean general2) { this.general = general2; this.sync(); } public boolean getgeneral() { return this.general; } public void bac(boolean bac2) { this.bac = bac2; this.sync(); } public boolean getbac() { return this.bac; } public void transaltis(boolean transaltis2) { this.transaltis = transaltis2; this.sync(); } public boolean gettransaltis() { return this.transaltis; } public void samu(boolean samu2) { this.samu = samu2; this.sync(); } public boolean getsamu() { return this.samu; } public void garagiste(boolean garagiste2) { this.garagiste = garagiste2; this.sync(); } public boolean getgaragiste() { return this.garagiste; } public void antv(boolean antv2) { this.antv = antv2; this.sync(); } public boolean getantv() { return this.antv; } public void velo(boolean velo2) { this.velo = velo2; this.sync(); } public boolean getvelo() { return this.velo; } public void conduire(boolean conduire2) { this.conduire = conduire2; this.sync(); } public boolean getconduire() { return this.conduire; } public void bateau(boolean bateau2) { this.bateau = bateau2; this.sync(); } public boolean getbateau() { return this.bateau; } public void camion(boolean camion2) { this.camion = camion2; this.sync(); } public boolean getcamion() { return this.camion; } public void arme(boolean arme2) { this.arme = arme2; this.sync(); } public boolean getarme() { return this.arme; } public void pilote(boolean pilote2) { this.pilote = pilote2; this.sync(); } public boolean getpilote() { return this.pilote; } public void diamant(boolean diamant2) { this.diamant = diamant2; this.sync(); } public boolean getdiamant() { return this.diamant; } public void archeologie(boolean archeologie2) { this.archeologie = archeologie2; this.sync(); } public boolean getarcheologie() { return this.archeologie; } public void demenotte() { this.menotte = false; this.sync(); } public boolean isRestrained() { return menotte; } public void pay() { this.sync(); } public void addCash(long amount) { boolean sufficient = amount <= this.getMoney(); if(sufficient) { this.cash += amount; this.money -= amount; this.sync(); } } public boolean sufficient(long amount) { boolean sufficient = amount <= this.getCash(); if(sufficient) { return true; } else { return false; } } public boolean sufficientm(long amount) { boolean sufficient = amount <= this.getMoney(); if(sufficient) { return true; } else { return false; } } public String buyCashTest(long amount, ItemStack item) { boolean sufficient = amount <= this.getCash(); if(sufficient) { if(item != null) { boolean isEmpty = false; for(int i = 0; i <= player.inventory.getSizeInventory() - 5; i++) { if(player.inventory.mainInventory* == item || player.inventory.mainInventory* == null) { isEmpty = true; break; } } if(isEmpty) { return "t4.boughtitem"; } else { return "t4.notenoughspace"; } } else {} } else { return "t4.notenoughmoney"; } return null; } public void buyCash(long amount, ItemStack item) { boolean sufficient = amount <= this.getCash(); if(sufficient) { if(item != null) { boolean isEmpty = false; for(int i = 0; i <= player.inventory.getSizeInventory() - 5; i++) { if(player.inventory.mainInventory* == item || player.inventory.mainInventory* == null) { isEmpty = true; break; } } if(isEmpty) { this.delCash2(amount); player.inventory.addItemStackToInventory(item); } else {} } else {} } else {} } public void buyPermis(long amount, String permis) { boolean sufficient = amount <= this.getCash(); EEPRestrained props = EEPRestrained.get(player); if(sufficient) { ModAltisCraft.instance.network.sendTo(new PacketMessage("t4.bought", false, Math.round(amount)), (EntityPlayerMP)player); if(permis.contains("velo")) { props.velo(true); } else if(permis.contains("conduire")) { props.conduire(true); } else if(permis.contains("camion")) { props.camion(true); } else if(permis.contains("bateau")) { props.bateau(true); } else if(permis.contains("pilote")) { props.pilote(true); } else if(permis.contains("arme")) { props.arme(true); } else if(permis.contains("diamant")) { props.diamant(true); } else if(permis.contains("archeologie")) { props.archeologie(true); } else if(permis.contains("rebelle")) { props.rebelle(true); } props.delCash2(amount); } else { ModAltisCraft.instance.network.sendTo(new PacketMessage("t4.notenoughmoney ", true), (EntityPlayerMP)player); } } public void buyColorant(long amount, int color) { boolean sufficient = amount <= this.getCash(); EEPRestrained props = EEPRestrained.get(player); if(sufficient) { ModAltisCraft.instance.network.sendTo(new PacketMessage("t4.bought", false, Math.round(amount)), (EntityPlayerMP)player); ItemStack colorant = new ItemStack(Items.dye, 1, color); player.inventory.addItemStackToInventory(colorant); props.delCash2(amount); } else { ModAltisCraft.instance.network.sendTo(new PacketMessage("t4.notenoughmoney ", true), (EntityPlayerMP)player); } } public void addCashRaw(long amount) { this.cash += amount; this.sync(); } public void delCash(long amount) { boolean sufficient = amount <= this.getCash(); if(sufficient) { this.cash -= amount; this.money += amount; this.sync(); } } public void delCash2(long amount) { boolean sufficient = amount <= this.getCash(); if(sufficient) { this.cash -= amount; this.sync(); } } public void delMoney(long amount) { boolean sufficient = amount <= this.getMoney(); if(sufficient) { this.money -= amount; this.sync(); } } public long getCash() { return this.cash; } public void addMoney(long amount) { this.money += amount; this.sync(); } public void setMoney(long amount) { this.money = amount; this.sync(); } public void setCash(long amount) { this.cash = amount; this.sync(); } public long getMoney() { return this.money; } } ```</entityplayermp>
-
Visiblement écrire un string null c’est pas bon.
Faudrait plutôt les remplacer par un string vide. (“”).