Jump to content

Recommended Posts

Posted (edited)

Hello I created a command And I would that all player have access to this command

 

package fr.atonha.saofrmod.commands;

import java.util.List;

import fr.atonha.saofrmod.ExtendedPlayer;
import fr.atonha.saofrmod.Main;
import fr.atonha.saofrmod.network.PacketAttributeGui;
import fr.atonha.saofrmod.network.PacketSync;
import net.minecraft.command.CommandBase;
import net.minecraft.command.ICommandSender;
import net.minecraft.entity.SharedMonsterAttributes;
import net.minecraft.entity.ai.attributes.IAttributeInstance;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.server.MinecraftServer;
import net.minecraft.util.ChatComponentText;
import net.minecraft.util.EnumChatFormatting;
import net.minecraft.world.World;

public class MainCommand extends CommandBase {
	
	String name = "saofr";

	@Override
	public String getCommandName() {
		return name;
	}

	@Override
	public String getCommandUsage(ICommandSender p_71518_1_) {
		return "/" + name;
	}

	@Override
	public void processCommand(ICommandSender sender, String[] args) {
		if(args.length == 0) {
			displayHelp(sender);
		}
		else if(args.length >= 1 && args[0].equalsIgnoreCase("open")) {
			Main.getPacketHandler().sendTo(new PacketAttributeGui(), (EntityPlayerMP) sender);
			ExtendedPlayer data = ExtendedPlayer.get((EntityPlayer)sender);
			Main.getPacketHandler().sendTo(new PacketSync(data.getLevel(), data.healthPoints, data.damagePoints, data.getPoint()), (EntityPlayerMP)sender);
		}
		else if(args.length >= 1 && args[0].equalsIgnoreCase("reset")) {
			if(!MinecraftServer.getServer().getConfigurationManager().func_152596_g(((EntityPlayer) sender).getGameProfile())){
				sender.addChatMessage(new ChatComponentText(EnumChatFormatting.RED + "[" + Main.MODID + "]" + " Tu n'as pas la permission pour utiliser cette commande"));
				return;
			}
			if(args.length >= 2 && this.isOnline(sender.getEntityWorld(), args[1])) {
				EntityPlayer argPlayer = this.getPlayer(sender.getEntityWorld(), args[1]);
				ExtendedPlayer pData = ExtendedPlayer.get(argPlayer);
				argPlayer.experienceLevel = 1;
				pData.setLevel(1);
				pData.setPoints(0);
				pData.damagePoints = 0;
				pData.healthPoints = 0;
				pData.setHP(ExtendedPlayer.startHP);
				pData.setDamage(ExtendedPlayer.startDamage);
				IAttributeInstance healthAttribute = argPlayer.getEntityAttribute(SharedMonsterAttributes.maxHealth);
		   		IAttributeInstance damageAttribute = argPlayer.getEntityAttribute(SharedMonsterAttributes.attackDamage);
		   		if(healthAttribute.getModifier(pData.healthModifier) != null)
		   			healthAttribute.removeModifier(healthAttribute.getModifier(pData.healthModifier));
		   		if(damageAttribute.getModifier(pData.damageModifier) != null)
		   			damageAttribute.removeModifier(damageAttribute.getModifier(pData.damageModifier));
				sender.addChatMessage(new ChatComponentText(EnumChatFormatting.GREEN + "[" + Main.MODID + "]" + " Donnees du joueur reinitialiser"));
			}
			else {
				sender.addChatMessage(new ChatComponentText(EnumChatFormatting.RED + "[" + Main.MODID + "]" + " Ce joueur n'est pas connecte"));
				return;
			}
		}
		else if(args.length >= 1 && args[0].equalsIgnoreCase("addPoints")) {
			if(!MinecraftServer.getServer().getConfigurationManager().func_152596_g(((EntityPlayer) sender).getGameProfile())){
				sender.addChatMessage(new ChatComponentText(EnumChatFormatting.RED + "[" + Main.MODID + "]" + " Tu n'as pas la permission pour utiliser cette commande"));
				return;
			}
			if(args.length >= 2 && this.isOnline(sender.getEntityWorld(), args[1]))
			{
				if(args.length >= 3 && this.isInteger(args[2])) {
					if(Integer.parseInt(args[2]) > 0) {
						EntityPlayer argPlayer = this.getPlayer(sender.getEntityWorld(), args[1]);
						ExtendedPlayer data = ExtendedPlayer.get((EntityPlayer) argPlayer);
						data.setPoints(data.getPoint() + Integer.parseInt(args[2]));
						sender.addChatMessage(new ChatComponentText(EnumChatFormatting.GREEN + "[" + Main.MODID + "]" + " Points ajouté avec succès"));
					}
					else {
						sender.addChatMessage(new ChatComponentText(EnumChatFormatting.RED + "[" + Main.MODID + "]" + " Vous devez entrer un nombre > 0"));
						return;
					}
				}
				else
				{
					sender.addChatMessage(new ChatComponentText(EnumChatFormatting.RED + "[" + Main.MODID + "]" + " Vous devez entrer un nombre"));
					return;
				}
			}
			else {
				sender.addChatMessage(new ChatComponentText(EnumChatFormatting.RED + "[" + Main.MODID + "]" + " Ce joueur n'est pas connecte"));
				return;
			}
		}
		else 
			displayHelp(sender);
		
	}
	
	
	public void displayHelp(ICommandSender sender) {
		sender.addChatMessage(new ChatComponentText(EnumChatFormatting.GREEN + "SaoFr main commands help:"));
		sender.addChatMessage(new ChatComponentText(EnumChatFormatting.GOLD + "-/saofr open " + EnumChatFormatting.WHITE + "-" + EnumChatFormatting.GOLD + " ouvre l'interface"));
		sender.addChatMessage(new ChatComponentText(EnumChatFormatting.GOLD + "-/saofr reset <Pseudo> " + EnumChatFormatting.WHITE + "-" + EnumChatFormatting.GOLD + " reinitialise les donnees d'un joueur"));
		sender.addChatMessage(new ChatComponentText(EnumChatFormatting.GOLD + "-/saofr addpoints <Pseudo> <Points>" + EnumChatFormatting.WHITE + "-" + EnumChatFormatting.GOLD + " ajoute des points"));
	}
	
	
	public boolean isOnline(World world, String name) {
		for(Object player : world.playerEntities) {
			EntityPlayer p  = (EntityPlayer) player;
			if(p.getCommandSenderName().equalsIgnoreCase(name))
				return true;
		}
		return false;	
	}
	
	public static boolean isInteger(String s) {
	    try { 
	        Integer.parseInt(s); 
	    } catch(NumberFormatException e) { 
	        return false; 
	    } catch(NullPointerException e) {
	        return false;
	    }
	    return true;
	}
	
	public EntityPlayer getPlayer(World world, String name) {
		for(Object player : world.playerEntities) {
			EntityPlayer p  = (EntityPlayer) player;
			if(p.getCommandSenderName().equalsIgnoreCase(name))
				return p;
		}
		return null;	
	}
	
    @Override 
    public boolean canCommandSenderUseCommand(ICommandSender var1) 
    { 
        return true;
    } 
    
    @Override  
    public List addTabCompletionOptions(ICommandSender var1, String[] var2) 
    { 
        return null; 
    } 

    @Override 
    public boolean isUsernameIndex(String[] var1, int var2) 
    { 
        return false;
    } 

}

 

but players not op doesn't not have access to command I do not understand thanks in advance .

Edited by INeoxz
Posted
9 minutes ago, INeoxz said:

ChatComponentText

 

9 minutes ago, INeoxz said:

canCommandSenderUseCommand

 

10 minutes ago, INeoxz said:

import net.minecraft.util.EnumChatFormatting;

What version of the game are you using?

Guest
This topic is now closed to further replies.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Hello all. I'm currently grappling with the updateShape method in a custom class extending Block.  My code currently looks like this: The conditionals in CheckState are there to switch blockstate properties, which is working fine, as it functions correctly every time in getStateForPlacement.  The problem I'm running into is that when I update a state, the blocks seem to call CheckState with the position of the block which was changed updated last.  If I build a wall I can see the same change propagate across. My question thus is this: is updateShape sending its return to the neighbouring block?  Is each block not independently executing the updateShape method, thus inserting its own current position?  The first statement appears to be true, and the second false (each block is not independently executing the method). I have tried to fix this by saving the block's own position to a variable myPos at inception, and then feeding this in as CheckState(myPos) but this causes a worse outcome, where all blocks take the update of the first modified block, rather than just their neighbour.  This raises more questions than it answers, obviously: how is a different instance's variable propagating here?  I also tried changing it so that CheckState did not take a BlockPos, but had myPos built into the body - same problem. I have previously looked at neighbourUpdate and onNeighbourUpdate, but could not find a way to get this to work at all.  One post on here about updatePostPlacement and other methods has proven itself long superceded.  All other sources on the net seem to be out of date. Many thanks in advance for any help you might offer me, it's been several days now of trying to get this work and several weeks of generally trying to get round this roadblock.  - Sandermall
    • sorry, I might be stupid, but how do I open it? because the only options I have are too X out, copy it, which doesn't work and send crash report, which doesn't show it to me, also, sorry for taking so long.
    • Can you reproduce this with version 55.0.21? A whole lot of plant placement issues were just fixed in this PR.
    • Necro'ing that thread to ask if you found a solution ? I'm encountering the same crash on loading the world. I created the world in Creative to test my MP, went into survival to test combat, died, crashed on respawn and since then crash on loading the world. Deactivating Oculus isn't fixing it either, and I don't have Optifine (Twilight forest is incompatible)
  • Topics

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.