mirror of
				https://github.com/Aust1n46/VentureChat.git
				synced 2025-10-30 13:32:24 +00:00 
			
		
		
		
	Designing abstraction layers for commands.
This commit is contained in:
		
							parent
							
								
									54a4504713
								
							
						
					
					
						commit
						6f830190a6
					
				| @ -269,6 +269,7 @@ public class CommandController implements TabExecutor { | ||||
| 			} | ||||
| 		}, 0); | ||||
| 		 | ||||
| 		 | ||||
| 		registerCommand("channel", channel); | ||||
| 	} | ||||
| 
 | ||||
|  | ||||
| @ -30,7 +30,7 @@ public class Channel extends PlayerCommand { | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public void execute(final Player player, final String commandLabel, final String[] args) { | ||||
| 	protected void executeCommand(final Player player, final String commandLabel, final String[] args) { | ||||
| 		final VentureChatPlayer mcp = playerApiService.getOnlineMineverseChatPlayer(player); | ||||
| 		if (args.length > 0) { | ||||
| 			if (!configService.isChannel(args[0])) { | ||||
|  | ||||
| @ -5,20 +5,21 @@ import org.bukkit.entity.Player; | ||||
| 
 | ||||
| import venture.Aust1n46.chat.localization.LocalizedMessage; | ||||
| 
 | ||||
| public abstract class PlayerCommand extends UniversalCommand { | ||||
| public abstract class PlayerCommand extends PluginCommand { | ||||
| 	protected PlayerCommand(final String name) { | ||||
| 		super(name); | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public void executeVoid(final CommandSender sender, final String commandLabel, final String[] args) { | ||||
| 	public final boolean execute(final CommandSender sender, final String commandLabel, final String[] args) { | ||||
| 		if (sender instanceof Player) { | ||||
| 			final Player player = (Player) sender; | ||||
| 			execute(player, commandLabel, args); | ||||
| 			executeCommand(player, commandLabel, args); | ||||
| 		} else { | ||||
| 			plugin.getServer().getConsoleSender().sendMessage(LocalizedMessage.COMMAND_MUST_BE_RUN_BY_PLAYER.toString()); | ||||
| 		} | ||||
| 		return true; | ||||
| 	} | ||||
| 
 | ||||
| 	public abstract void execute(final Player player, final String commandLabel, final String[] args); | ||||
| 	protected abstract void executeCommand(final Player player, final String commandLabel, final String[] args); | ||||
| } | ||||
|  | ||||
							
								
								
									
										23
									
								
								src/main/java/venture/Aust1n46/chat/model/PluginCommand.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										23
									
								
								src/main/java/venture/Aust1n46/chat/model/PluginCommand.java
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,23 @@ | ||||
| package venture.Aust1n46.chat.model; | ||||
| 
 | ||||
| import org.bukkit.command.Command; | ||||
| import org.bukkit.command.PluginIdentifiableCommand; | ||||
| import org.bukkit.plugin.Plugin; | ||||
| 
 | ||||
| import com.google.inject.Inject; | ||||
| 
 | ||||
| import venture.Aust1n46.chat.initiators.application.VentureChat; | ||||
| 
 | ||||
| public abstract class PluginCommand extends Command implements PluginIdentifiableCommand { | ||||
| 	@Inject | ||||
| 	protected VentureChat plugin; | ||||
| 
 | ||||
| 	protected PluginCommand(final String name) { | ||||
| 		super(name); | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public final Plugin getPlugin() { | ||||
| 		return plugin; | ||||
| 	} | ||||
| } | ||||
| @ -1,32 +1,17 @@ | ||||
| package venture.Aust1n46.chat.model; | ||||
| 
 | ||||
| import org.bukkit.command.Command; | ||||
| import org.bukkit.command.CommandSender; | ||||
| import org.bukkit.command.PluginIdentifiableCommand; | ||||
| import org.bukkit.plugin.Plugin; | ||||
| 
 | ||||
| import com.google.inject.Inject; | ||||
| 
 | ||||
| import venture.Aust1n46.chat.initiators.application.VentureChat; | ||||
| 
 | ||||
| public abstract class UniversalCommand extends Command implements PluginIdentifiableCommand { | ||||
| 	@Inject | ||||
| 	protected VentureChat plugin; | ||||
| 
 | ||||
| public abstract class UniversalCommand extends PluginCommand { | ||||
| 	protected UniversalCommand(final String name) { | ||||
| 		super(name); | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public boolean execute(final CommandSender sender, final String commandLabel, final String[] args) { | ||||
| 		executeVoid(sender, commandLabel, args); | ||||
| 	public final boolean execute(final CommandSender sender, final String commandLabel, final String[] args) { | ||||
| 		executeCommand(sender, commandLabel, args); | ||||
| 		return true; | ||||
| 	} | ||||
| 
 | ||||
| 	public abstract void executeVoid(final CommandSender sender, final String commandLabel, final String[] args); | ||||
| 
 | ||||
| 	@Override | ||||
| 	public Plugin getPlugin() { | ||||
| 		return plugin; | ||||
| 	} | ||||
| 	protected abstract void executeCommand(final CommandSender sender, final String commandLabel, final String[] args); | ||||
| } | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 Aust1n46
						Aust1n46