Example #1
0
 private EventList getEventListeners(Class<? extends Event> type) {
   try {
     Method method = getRegistrationClass(type).getDeclaredMethod("getEventList");
     method.setAccessible(true);
     return (EventList) method.invoke(null);
   } catch (Exception e) {
     server.Log("==!EVENT ERROR!==");
     server.logError(e);
     return null;
   }
 }
Example #2
0
 public void registerEvents(Listener l) {
   for (Map.Entry<Class<? extends Event>, Set<RegisteredListener>> entry :
       addMuffins(l).entrySet()) {
     try {
       getEventListeners(getRegistrationClass(entry.getKey())).registerAll(entry.getValue());
     } catch (IllegalAccessException e) {
       server.Log("==!EVENT ERROR!==");
       server.logError(e);
     }
   }
 }
Example #3
0
 public void callEvent(Event event) {
   EventList events = event.getEvents();
   RegisteredListener[] listeners = events.getRegisteredListeners();
   for (RegisteredListener listen : listeners) {
     try {
       listen.execute(event);
     } catch (Exception e) {
       server.Log("==!EVENT ERROR!==");
       server.logError(e);
     }
   }
 }
Example #4
0
 public void start() {
   s = new Server("[MCForge] Default", 25565, "Welcome!");
   s.start(this, true, ss);
   Scanner scanner = new Scanner(System.in);
   while (s.Running) {
     String line = scanner.nextLine();
     if (line.equals("/stop")) {
       try {
         s.stop();
       } catch (InterruptedException e) {
         e.printStackTrace(s.getLoggerOutput());
       } catch (IOException e) {
         e.printStackTrace(s.getLoggerOutput());
       }
     } else if (line.startsWith("/")) {
       line = line.substring(1); // Get rid of the / at the beginning
       if (line.split("\\ ").length > 1)
         s.getCommandHandler()
             .execute(
                 this, line.split("\\ ")[0], line.substring(line.indexOf(line.split("\\ ")[1])));
       else s.getCommandHandler().execute(this, line, "");
     } else {
       super.sendGlobalMessage(line);
       s.Log("[Server] " + line);
     }
   }
   System.out.println("Server stopped..");
   scanner.close();
   System.exit(0);
 }
Example #5
0
 public ChunkLevel(Server server, String name) {
   this.owner = server;
   this.name = name;
   spawnx = 0.0;
   spawny = 255.0;
   spawnz = 0.0;
   cgs = new ChunkGeneratorService(this);
   server.getTicker().addTick(cgs);
 }
Example #6
0
 @Override
 public void Write(IOClient p, Server server) {
   PacketPrepareEvent event = new PacketPrepareEvent(p, this, server);
   server.getEventSystem().callEvent(event);
   if (event.isCancelled()) return;
   Player player;
   if (p instanceof Player) {
     player = (Player) p;
   } else return;
   try {
     while (player.kickreason.length() < 64) {
       player.kickreason += " ";
     }
     byte[] temp = player.kickreason.getBytes("US-ASCII");
     byte[] finals = new byte[1 + temp.length];
     finals[0] = ID;
     System.arraycopy(temp, 0, finals, 1, temp.length);
     player.writeData(finals);
   } catch (UnsupportedEncodingException e) {
     e.printStackTrace();
   } catch (IOException e) {
     e.printStackTrace();
   }
 }
Example #7
0
 @Override
 public void sendMessage(String message) {
   s.Log(message);
 }