예제 #1
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);
 }
예제 #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);
     }
   }
 }
예제 #3
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;
   }
 }
예제 #4
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);
     }
   }
 }
예제 #5
0
 @Override
 public void sendMessage(String message) {
   s.Log(message);
 }