Forge ile kodladığım komutu oyuncular kullanamıyor

Mucosoft

Bedrock Kaşifi
Mesajlar
1,614
En iyi cevaplar
1
Beğeniler
650
Puanları
1,740
Minecraft Forge 1.12.2 ile mod geliştiriyorum. Böyle bir kod yazdım. Oyuncular yetki olmadığına dair hata alıyor. Nasıl çözerim?
Java:
       Event.registerServerCommand(new CommandBase()
        {
            @Override
            public String getName() {
                return "Home";
            }
            @Override
            public String getUsage(ICommandSender Sender)
            {
                return "Home -> Home saving and teleporting command.";
            }
            @Override
            public void execute(MinecraftServer Server, ICommandSender Sender, String[] Args) throws CommandException
            {
                EntityPlayer Pl = (EntityPlayer) Sender;
                String Username = Pl.getName();
                if (Args.length >= 1)
                {
                    if (Args[0].equals("Set"))
                    {
                        if (Functions.FileExists("Mucosoft/PlayerHomes/" + Username + ".txt"))
                        {
                            MinecraftFunctions.SaveLocation(Sender, "Mucosoft/PlayerHomes/" + Username + ".txt");
                            BlockPos Loc = Pl.getPosition();
                            String X = String.valueOf(Pl.getPosition().getX());
                            String Y = String.valueOf(Pl.getPosition().getY());
                            String Z = String.valueOf(Pl.getPosition().getZ());
                            HomeLocations.put(Username, X + "," + Y + "," + Z);
                            MinecraftFunctions.SendMessage(Sender, MinecraftFunctions.MsgType.Success, "Home location updated.");
                        }
                        else
                        {
                            Functions.CreateFile("Mucosoft/PlayerHomes/" + Username + ".txt");
                            MinecraftFunctions.SaveLocation(Sender, "Mucosoft/PlayerHomes/" + Username + ".txt");
                            BlockPos Loc = Pl.getPosition();
                            String X = String.valueOf(Pl.getPosition().getX());
                            String Y = String.valueOf(Pl.getPosition().getY());
                            String Z = String.valueOf(Pl.getPosition().getZ());
                            HomeLocations.put(Username, X + "," + Y + "," + Z);
                            MinecraftFunctions.SendMessage(Sender, MinecraftFunctions.MsgType.Success, "Home location created.");
                        }
                    }
                    else if (Args[0].equals("Go"))
                    {
                        if (HomeLocations.containsKey(Username))
                        {
                            String[] Data = HomeLocations.get(Username).split(",");
                            Double X = Double.valueOf(Data[0]);
                            Double Y = Double.valueOf(Data[1]);
                            Double Z = Double.valueOf(Data[2]);
                            Pl.setPositionAndUpdate(X, Y, Z);
                        }
                        else
                        {
                            MinecraftFunctions.SendMessage(Sender, MinecraftFunctions.MsgType.Error, "Missing home location.");
                        }
                    }
                    else
                    {
                        MinecraftFunctions.SendMessage(Sender, MinecraftFunctions.MsgType.Error, NoArg);
                    }
                }
                else
                {
                    MinecraftFunctions.SendMessage(Sender, MinecraftFunctions.MsgType.Info, "/Home Set\n/Home Go");
                }
            }
        });
 


mahmud118

Are you?
Mesajlar
618
En iyi cevaplar
4
Beğeniler
278
Puanları
1,320
Ruh hali
"checkPermission(MinecraftServer, ICommandSender)" methodunu override etmen gerekiyor. Bir de "getRequiredPermissionLevel()" methoduna bak.

Örnek kod:

Java:
       Event.registerServerCommand(new CommandBase()
        {
            @Override
            public int getRequiredPermissionLevel() {
                return 0; // En düşük sıfır sanırım.
            }

            @Override
            public boolean checkPermission(MinecraftServer server, ICommandSender sender) {
                return true;
            }
            @Override
            public String getName() {
                return "Home";
            }
            @Override
            public String getUsage(ICommandSender Sender)
            {
                return "Home -> Home saving and teleporting command.";
            }
            @Override
            public void execute(MinecraftServer Server, ICommandSender Sender, String[] Args) throws CommandException
            {
                EntityPlayer Pl = (EntityPlayer) Sender;
                String Username = Pl.getName();
                if (Args.length >= 1)
                {
                    if (Args[0].equals("Set"))
                    {
                        if (Functions.FileExists("Mucosoft/PlayerHomes/" + Username + ".txt"))
                        {
                            MinecraftFunctions.SaveLocation(Sender, "Mucosoft/PlayerHomes/" + Username + ".txt");
                            BlockPos Loc = Pl.getPosition();
                            String X = String.valueOf(Pl.getPosition().getX());
                            String Y = String.valueOf(Pl.getPosition().getY());
                            String Z = String.valueOf(Pl.getPosition().getZ());
                            HomeLocations.put(Username, X + "," + Y + "," + Z);
                            MinecraftFunctions.SendMessage(Sender, MinecraftFunctions.MsgType.Success, "Home location updated.");
                        }
                        else
                        {
                            Functions.CreateFile("Mucosoft/PlayerHomes/" + Username + ".txt");
                            MinecraftFunctions.SaveLocation(Sender, "Mucosoft/PlayerHomes/" + Username + ".txt");
                            BlockPos Loc = Pl.getPosition();
                            String X = String.valueOf(Pl.getPosition().getX());
                            String Y = String.valueOf(Pl.getPosition().getY());
                            String Z = String.valueOf(Pl.getPosition().getZ());
                            HomeLocations.put(Username, X + "," + Y + "," + Z);
                            MinecraftFunctions.SendMessage(Sender, MinecraftFunctions.MsgType.Success, "Home location created.");
                        }
                    }
                    else if (Args[0].equals("Go"))
                    {
                        if (HomeLocations.containsKey(Username))
                        {
                            String[] Data = HomeLocations.get(Username).split(",");
                            Double X = Double.valueOf(Data[0]);
                            Double Y = Double.valueOf(Data[1]);
                            Double Z = Double.valueOf(Data[2]);
                            Pl.setPositionAndUpdate(X, Y, Z);
                        }
                        else
                        {
                            MinecraftFunctions.SendMessage(Sender, MinecraftFunctions.MsgType.Error, "Missing home location.");
                        }
                    }
                    else
                    {
                        MinecraftFunctions.SendMessage(Sender, MinecraftFunctions.MsgType.Error, NoArg);
                    }
                }
                else
                {
                    MinecraftFunctions.SendMessage(Sender, MinecraftFunctions.MsgType.Info, "/Home Set\n/Home Go");
                }
            }
        });

Edit.
Kodda Dimension kontrolü yok. Piyasa karışır haberin ola

Edit2.
Örnek Dimension control/teleport: (Testleri SinglePlayer'da yaptım.)
Java:
import net.minecraft.world.Teleporter;
import net.minecraft.entity.Entity;

// Kullanıcının Dimension'ı alma
int dimension = Pl.world.provider.getDimension();

// Dimension Teleport
Pl.changeDimension(dimension, new Teleporter(Pl.getServer().getWorld(dimension)) {
    // Portal oluşturmaması için.
    @Override
    public boolean makePortal(Entity entity) {
        return false;
    }

    // Mevcut bir portala yerleştirmemesi için. (sanırım)
    @Override
    public boolean placeInExistingPortal(Entity entity, float val) {
        return false;
    }
});

// Dimension değiştirdikten sonra, ışınla
Pl.setPositionAndUpdate(X, Y, Z);

Edit3.
Tüm Test Kodu
Java:
package com.example.examplemod;

import net.minecraft.command.CommandBase;
import net.minecraft.command.ICommandSender;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.server.MinecraftServer;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.text.TextComponentString;
import net.minecraft.world.Teleporter;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.Mod.EventHandler;
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
import net.minecraftforge.fml.common.event.FMLServerStartingEvent;
import org.apache.logging.log4j.Logger;

@Mod(modid = ExampleMod.MODID, name = ExampleMod.NAME, version = ExampleMod.VERSION)
public class ExampleMod
{
    public static final String MODID = "examplemod";
    public static final String NAME = "Example Mod";
    public static final String VERSION = "1.0";

    private static Logger logger;

    @EventHandler
    public void preInit(FMLPreInitializationEvent event)
    {
        logger = event.getModLog();
    }

    @EventHandler
    public void init(FMLInitializationEvent event) {
        // some example code
        logger.info("DIRT BLOCK >> {}", Blocks.DIRT.getRegistryName());
    }

    @EventHandler
    public void postInit(FMLServerStartingEvent event) {
        logger.info("Event registered.");
        event.registerServerCommand(
                new CommandBase() {
                    @Override
                    public int getRequiredPermissionLevel() {
                        return 0;
                    }

                    @Override
                    public boolean checkPermission(MinecraftServer server, ICommandSender sender) {
                        return true;
                    }

                    int dimension;
                    double X;
                    double Y;
                    double Z;
                    @Override
                    public String getName() {
                        return "home";
                    }
                    @Override
                    public String getUsage(ICommandSender Sender)
                    {
                        return "/home <set/go> -> Home saving and teleporting command.";
                    }
                    @Override
                    public void execute(MinecraftServer server, ICommandSender sender, String[] args) {
                        EntityPlayer player = (EntityPlayer) sender;
                        if (args.length >= 1)
                        {
                            if (args[0].equals("set"))
                            {
                                dimension = player.world.provider.getDimension();
                                BlockPos loc = player.getPosition();
                                X = loc.getX();
                                Y = loc.getY();
                                Z = loc.getZ();
                                player.sendMessage(new TextComponentString("Saved"));
                            }
                            else if (args[0].equals("go"))
                            {
                                if(X != 0 && Y != 0 && Z != 0){
                                    player.changeDimension(dimension, new Teleporter(server.getWorld(dimension)) {
                                        @Override
                                        public boolean makePortal(Entity entity) {
                                            return false;
                                        }

                                        @Override
                                        public boolean placeInExistingPortal(Entity entity, float val) {
                                            return false;
                                        }
                                    });

                                    player.setPositionAndUpdate(X, Y, Z);
                                    player.sendMessage(new TextComponentString("Went"));
                                }
                            } else {
                                player.sendMessage(new TextComponentString("Wrong usage"));
                            }
                        } else {
                            player.sendMessage(new TextComponentString("/home <set/go>"));
                        }
                    }
                }
        );


    }


}
 
Son düzenleme:

Üst