Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class RedisStuff implements Listener{
- private static ConcurrentHashMap<Long, Integer> map = new ConcurrentHashMap<>();
- public static void register(){
- try{
- Bukkit.getScheduler().runTaskLater(NetAPI.plugin, new Runnable() {
- @Override
- public void run() {
- if(Bukkit.getPluginManager().getPlugin("General") != null)
- RedisBukkit.a().registerChannel("distributor_bridge_netapi");
- }
- }, 2);
- }catch(Exception ex){
- ex.printStackTrace();
- }
- }
- @EventHandler
- public void onPubSub(AsyncRedisMessageReceivedEvent e){
- if(e.getChannel().equalsIgnoreCase("distributor_bridge_netapi")){
- String[] data = e.getMessage().split("%split%");
- long session = Long.valueOf(data[0]);
- int id = Integer.parseInt(data[1]);
- map.put(session, id);
- }
- }
- public static int loadGameMode(String gametype, boolean ignoreincalculation){
- long session = new Random().nextLong();
- RedisBukkit.a().sendMessage("distributor_bridge_netapi", gametype+"%split%"+ignoreincalculation+"%split%"+session);
- int timeout = 2000;
- long start = System.currentTimeMillis();
- while(System.currentTimeMillis()-start < timeout){
- if(map.containsKey(session)){
- int id = map.get(session);
- map.remove(session);
- return id;
- }
- try {
- Thread.sleep(2);
- } catch (InterruptedException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- return -2;
- }
- }
- return -2;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement