-
-
Save effective-light/73bdf9cc92806c6ddb95 to your computer and use it in GitHub Desktop.
stuff
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() ) | |
| { | |
| if ( plugin.getChallenges().containsKey( playerSender.getName() ) ) | |
| { | |
| Map<String, Long> innerMap = plugin.getChallenges().get( playerSender.getName() ); | |
| if ( innerMap.containsKey( player.getName() ) ) | |
| { | |
| long time = innerMap.get( player.getName() ) + | |
| plugin.getExpireTime() - ( System.currentTimeMillis() / 1000L ); | |
| if ( time > 0 ) | |
| { | |
| // teleport, etc | |
| } else | |
| { | |
| innerMap.remove( player.getName() ); | |
| } | |
| } | |
| } | |
| } else | |
| { | |
| // handle offline | |
| } | |
| return true; | |
| } | |
| } |
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() ) | |
| { | |
| long time = handleAdd( playerSender, player ); | |
| if ( time > 0L ) | |
| { | |
| playerSender.sendMessage( "you have to wait to " + time + " challege again!" ); | |
| } else if ( time == -1 ) { | |
| playerSender.sendMessage( "you challenged " + player.getName() ); | |
| } | |
| } else | |
| { | |
| // TODO: handle offline player | |
| } | |
| return true; | |
| } | |
| private long 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() ) ) | |
| { | |
| long time = (innerMap.get( challenger.getName() ) + | |
| plugin.getExpireTime() ) - ( System.currentTimeMillis() / 1000L ); | |
| if ( time < 0 ) | |
| { | |
| time = -1L; | |
| innerMap.put( challenger.getName(), System.currentTimeMillis() / 1000L ); | |
| } | |
| return time; | |
| } | |
| } else | |
| { | |
| innerMap = new HashMap<>(); | |
| plugin.getChallenges().put( challenged.getName(), innerMap ); | |
| } | |
| innerMap.put( challenger.getName(), System.currentTimeMillis() / 1000L ); | |
| return -1L; | |
| } | |
| } |
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