2016-09-11 1 views
0

이 작은 플러그인을 만들었으므로 onCommand 안의 코드를 다른 클래스로 옮기고 onCommand에서 해당 클래스를 호출/실행하는 방법을 알고 싶습니다. 도와주세요. 감사합니다코드를 다른 클래스로 나누기 [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

힌트 : 자바 명명 규칙에 대해 알아보세요. 나는 당신이 사용하고있는 라이브러리를 모른다. Zero * 변수가 어떻게 든 상수가되어야하는지 궁금합니다. 또는 왜 모두 대문자 이름으로 시작하는지! – GhostCat

+0

그리고 기록을 위해 : working code를 개선하는 것에 관한 질문은 codereview.stackexchange.com에 갈 수도 있습니다. – GhostCat

답변

1

새로운 클래스 명령 만들 수있을 것입니다 :

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; 
} 
} 

그리고 당신은 CommandExecutor을 설정해야합니다 귀하의 MainClass에서

:

getCommand("command").setExecutor(new Commands(this)); 
관련 문제