-
-
Save anonymous/b146f7e02c1f0398dcb2 to your computer and use it in GitHub Desktop.
1v1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class AcceptCommand implements CommandExecutor | |
| { | |
| private ChallengeMain plugin; | |
| public AcceptCommand(ChallengeMain plugin) { | |
| this.plugin = plugin; | |
| } | |
| @Override | |
| public boolean onCommand(CommandSender sender, Command command, String label, String[] args) | |
| { | |
| if ( !(sender instanceof Player) ) return true; | |
| Player playerSender = (Player) sender; | |
| if (args.length != 1) | |
| { | |
| sender.sendMessage( "Usage: /accept <player>" ); | |
| return true; | |
| } | |
| Player player = Bukkit.getPlayer( args[ 0 ] ); | |
| if (player.isOnline()) | |
| { | |
| } else | |
| { | |
| // handle offline | |
| } | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class ChallengeCommand implements CommandExecutor | |
| { | |
| private ChallengeMain plugin; | |
| public ChallengeCommand(ChallengeMain plugin) { | |
| this.plugin = plugin; | |
| } | |
| @Override | |
| public boolean onCommand(CommandSender sender, Command command, String label, String[] args) | |
| { | |
| if ( !(sender instanceof Player) ) return true; | |
| Player playerSender = (Player) sender; | |
| if (args.length != 1) | |
| { | |
| sender.sendMessage( "Usage: /challenge <player>" ); | |
| return true; | |
| } | |
| Player player = Bukkit.getPlayer( args[ 0 ] ); | |
| if ( player.isOnline() ) | |
| { | |
| if ( !handleAdd( playerSender, player ) ) | |
| { | |
| playerSender.sendMessage( "you have to wait to challege again!" ) | |
| } | |
| } else { | |
| // TODO: handle offline player | |
| } | |
| } | |
| private boolean handleAdd(Player challenger, Player challenged) { | |
| Map<String, Long> innerMap; | |
| if ( plugin.getChallenges().containsKey( challenged.getName() ) ) | |
| { | |
| innerMap = plugin.getChallenges().get( challenged.getName() ); | |
| if ( innerMap.containsKey( challenger.getName() ) | |
| && ( innerMap.get( challenger.getName() ) + | |
| plugin.getExpireTime() ) - ( System.currentTimeMillis() / 1000 ) > 0 ) ) | |
| { | |
| return true; | |
| } | |
| } else { | |
| innerMap = new HashMap<>(); | |
| plugin.getChallenges().put( challenged.getName(), innerMap ); | |
| } | |
| innerMap.put( challenger.getName(), System.currentTimeMillis() / 1000 ); | |
| return false; | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class ChallengeMain extends JavaPlugin | |
| { | |
| private Map<String, Map<String, Long>> challenges = new HashMap<>(); | |
| private long expireTime = 15; // seconds | |
| @Override | |
| public void onEnable() | |
| { | |
| getCommand( "challenge" ).setExecutor( new ChallengeCommand( this ) ); | |
| getCommand( "accept" ).setExecutor( new AcceptCommand( this ) ); | |
| } | |
| public Map<String, Map<String, Long>> getChallenges() | |
| { | |
| return challenges; | |
| } | |
| public long getExpireTime() | |
| { | |
| return expireTime; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment