Domanda Permessi in una mod per server

Stato
Discussione chiusa ad ulteriori risposte.

iNabbo

Utente Electrum
21 Novembre 2014
260
54
11
160
Come faccio un comando che unisce un player ad un gruppo e poi come faccio a controllare a che gruppo appartiene un player.
P.S. il comando si dovrebbe poter utilizzare una sola volta.
 
Ultima modifica:
Mod
ok sono riuscito solo che il "clan" dopo essere usciti e rientrati si resetta (è una variabile interna alla mod)
come posso risolvere?
Inviata da GT-S7390 tramite app ufficiale di Inforge.net
 
ho fatto così perchè non funziona?
PlayerInfo
Codice:
package sekwah.mods.narutomod.player.extendedproperties;

import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.world.World;
import net.minecraftforge.common.IExtendedEntityProperties;

public class PlayerInfo implements IExtendedEntityProperties
{

    public final static String identifier = "narutomod_playerdata";

    private final EntityPlayer player;

    private int chakra;
    private int maxChakra;
    private int chakraRegenCooldown;
    private double chakraRegenRate;

    private int stamina;
    private int maxStamina;
    private int staminaRegenCooldown;
    private double staminaRegenRate;

    private int CLAN_WATCHER = 21;

    public static String clan;

    public static String hasAskedToSetClan = "0";
 
    public static String sharingan = "0";

    private int levelXP, level;

    private int health, maxHealth;


    private String rpFirstName, rpLastName;


    private int strengthStat, jutsuStat, intStat, defStat, luckStat, speedStat, dexStat, fortitudeStat, willpowerStat;

    public void setClan(String clan) {
        this.clan = clan;
    }

    public String getClan() {
        return this.clan;
    }
    public PlayerInfo(EntityPlayer player)
    {
        this.player = player;
       if (clan == "uzumaki"){
         this.maxChakra = this.chakra = 200;
       }
       else
       {
        this.maxChakra = this.chakra = 100;
       }
       if (clan == "uciha")
       {
          this.maxStamina = this.stamina = 200;
       }
       else
       {
        this.maxStamina = this.stamina = 100;
       }
        this.staminaRegenRate = 0.22;

        this.chakraRegenRate = 0.025;

    }

    public boolean consumeChakra(int amount)
    {
 
        boolean sufficient = amount <= this.chakra;
        this.chakra -= (sufficient ? amount : 0); // false, take away no mana
        return sufficient;
    }

    public void rechargeChakra(int amount)
    {
        boolean sufficient = amount <= this.chakra;
        // Consume the amount anyway; if it's more than the player's current ki,
        this.chakra += (amount < this.chakra ? amount : this.maxChakra);
    }
    public void replenishChakra()
    {
        this.chakra = this.maxChakra;
    }

    public void chakraRegenTick() {
        if (chakraRegenCooldown > 0) {
            chakraRegenCooldown--;
        } else if (chakra < maxChakra) {
            chakra += chakraRegenRate;
        }
    }


    @Override
    public void saveNBTData(NBTTagCompound nbt) {
        nbt.setString("clan", this.getClan());
        System.out.println("saved data");
     
    }


    @Override
    public void loadNBTData(NBTTagCompound nbt) {
        this.setClan(nbt.getString("clan"));
        System.out.println("loaded data");
    }
    @Override
    public void init(Entity entity, World world) {
    }
    public static PlayerInfo get(EntityPlayer player) {
        return (PlayerInfo) player.getExtendedProperties(identifier);
    }

    public static void register(EntityPlayer player) {
        player.registerExtendedProperties(identifier, new PlayerInfo(player));
    }

    public boolean isServerSide() {
        return this.player instanceof EntityPlayerMP;
    }
    public void reloadDW() {
        player.getDataWatcher().updateObject(CLAN_WATCHER, "Undefined");

        System.out.println("Clan: " + clan);
        player.getDataWatcher().updateObject(CLAN_WATCHER, clan);
    }
    public void copyData(PlayerInfo info) {
        this.clan = info.clan;
        player.getDataWatcher().updateObject(CLAN_WATCHER, clan);
    }
EventHook
Codice:
package sekwah.mods.narutomod.client;

import cpw.mods.fml.client.registry.RenderingRegistry;
import net.minecraft.client.renderer.entity.Render;
import net.minecraft.client.renderer.entity.RenderManager;
import net.minecraft.client.resources.I18n;
import net.minecraftforge.client.event.RenderPlayerEvent;
import net.minecraftforge.common.IExtendedEntityProperties;
import sekwah.mods.narutomod.animation.NarutoAnimator;
import sekwah.mods.narutomod.client.gui.GuiClanSelectionMenu;
import sekwah.mods.narutomod.player.RenderNinjaPlayer;
import sekwah.mods.narutomod.player.extendedproperties.PlayerInfo;
import cpw.mods.fml.client.FMLClientHandler;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import net.minecraft.client.entity.EntityClientPlayerMP;
import net.minecraft.client.entity.EntityPlayerSP;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.ChatComponentText;
import net.minecraft.util.EnumChatFormatting;
import net.minecraftforge.event.entity.EntityEvent.EntityConstructing;
import net.minecraftforge.event.entity.EntityJoinWorldEvent;

import net.minecraftforge.event.entity.player.PlayerEvent;


public class EventHook {
    @SubscribeEvent
    public void onEntityJoinWorld(EntityJoinWorldEvent e) {
        if (e.entity instanceof EntityPlayer) {
            PlayerInfo.get((EntityPlayer) e.entity);
        }
    }
    @SubscribeEvent
    public void onEntityConstructing(EntityConstructing e) {
        if (e.entity instanceof EntityPlayer) {
            e.entity.registerExtendedProperties(PlayerInfo.clan, null);
        }
    }

    @SubscribeEvent
    public void onClonePlayer(PlayerEvent.Clone e) {
      if(e.wasDeath) {
        NBTTagCompound nbt = new NBTTagCompound();
        PlayerInfo.get(e.original).saveNBTData(nbt);
        PlayerInfo.get(e.entityPlayer).loadNBTData(nbt);
      }
    }
}
 
Stato
Discussione chiusa ad ulteriori risposte.