2016-09-11 2 views
0

Also habe ich dieses kleine Plugin erstellt und ich möchte wissen, wie Sie den Code von innerhalb onCommand in eine andere Klasse verschieben und diese Klasse in onCommand aufrufen/ausführen. Bitte Hilfe. DankTeilen von Code in verschiedene Klassen [Bukkit/Spigot]

public class SkinStandoff extends JavaPlugin { 
Block bEnd; 
Location End; 
Block ZeroBlock; 
Location Zero; 
Location ZeroEnd; 

@Override 
public void onEnable(){ 
} 

public boolean onCommand(CommandSender sender, Command cmd, String label, String args[]) { 
    if (cmd.getName().equalsIgnoreCase("build") && sender instanceof Player) { 
     Player player = (Player) sender; 
     Location start; 
     int Count; 
     Count = 1; 

     start = player.getLocation(); 
     End = start.add(3, -1, 3); 
     Zero = getEnd().add(1,0,0); 

     bEnd = End.getBlock(); 
     bEnd.setType(Material.REDSTONE_BLOCK); 
     do { 
      Zero= Zero.add(1,0,0); 
      ZeroBlock = Zero.getBlock(); 
      ZeroBlock.setType(Material.REDSTONE_BLOCK); 
      Count++; 
     } while (Count != 10); 
     return true; 
    } 
    return false; 
} 

public Location getEnd(){ 
    return End; 
} 
public Location getZeroEnd(Location ZeroEnd){ 
    ZeroEnd = this.Zero.add(10,0,0); 
    return ZeroEnd; 
} 
} 
+2

Hinweis: lernen über Java-Namenskonventionen. Ich habe keine Ahnung, welche Bibliotheken Sie verwenden. und ich frage mich wirklich, ob deine Zero * Variablen irgendwie Konstanten sein sollten; oder warum sie alle mit UpperCase-Namen beginnen! – GhostCat

+0

Und für den Rekord: Fragen zur Verbesserung der Arbeitscode kann auch codereview.stackexchange.com gehen. – GhostCat

Antwort

1

Sie neue Klasse Befehle erstellen und es wird:

public class Commands implements CommandExecutor { 

    private MainClass plugin; 

    public Commands(MainClass core) { 
     this.plugin = core; 
    } 

    @Override 
    public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { 
your commands here 
return true; 
} 
} 

Und in Ihrem Mainclass Sie haben CommandExecutor zu setzen:

getCommand("command").setExecutor(new Commands(this)); 
Verwandte Themen