Exemplo n.º 1
0
 @Override
 public void unregister(EventPriority priority) {
   Object listener = listeners.get(priority);
   if (listener != null) {
     Pore.getGame().getEventManager().unregisterListeners(listener);
   }
 }
Exemplo n.º 2
0
 @SuppressWarnings({
   "rawtypes",
   "unchecked"
 }) // I can't parameterize this either; it scares the compiler
 private static <T extends VariantData<U, T, ?>, U extends CatalogType> T getItemData(
     ItemStack item, Class<T> type, BiMap<U, Integer> map) {
   int damage = item.getDurability();
   if (!map.containsValue(damage)) {
     throw new UnsupportedOperationException();
   }
   // no idea why a typecast is necessary here but excluding it makes javac angry
   @SuppressWarnings("RedundantCast")
   T data =
       (T)
           Pore.getGame()
               .getRegistry()
               .createItemBuilder()
               .itemType(MaterialConverter.asItem(item.getType()))
               .quantity(1)
               .build()
               .getOrCreate(type)
               .get();
   data.type().set(map.inverse().get(damage));
   return data;
 }
Exemplo n.º 3
0
    @Override
    public void unregister() {
      EventManager manager = Pore.getGame().getEventManager();

      for (Object listener : listeners.values()) {
        manager.unregisterListeners(listener);
      }
    }
Exemplo n.º 4
0
    @Override
    public void register(EventPriority priority) {
      PoreEventHandler<S> listener = listeners.get(priority);
      if (listener == null) {
        if (constructor == null) {
          this.constructor = PoreConstructors.create(pore, sponge);
        }

        listener = new PoreEventHandler<>(priority, constructor);
        listeners.put(priority, listener);
      }

      Pore.getGame()
          .getEventManager()
          .registerListener(
              Pore.getPlugin(), sponge, EventPriorityConverter.of(priority), listener);
    }
Exemplo n.º 5
0
 /**
  * Obtains {@link DataManipulator} from an ItemStack.
  *
  * @param item The ItemStack to retrieve {@link DataManipulator} from
  * @return The obtained {@link DataManipulator}, or {@code null} if none can be discerned
  */
 @SuppressWarnings(
     "rawtypes") // I tried parameterizing the return value but Java absolutely spazzed out about
                 // it
 public static DataManipulator getItemData(ItemStack item) {
   switch (item.getType()) {
     case COAL:
       return getItemData(item, COAL_ITEM_DATA, COAL_MAP);
     case COOKED_FISH:
       return getItemData(item, COOKED_FISH_ITEM_DATA, COOKED_FISH_MAP);
     case WOOL:
       break;
     case INK_SACK:
       break;
     case STAINED_CLAY:
       break;
     case STAINED_GLASS:
       break;
     case STAINED_GLASS_PANE:
       return getItemData(item, DYEABLE_DATA, DYE_MAP);
     case RAW_FISH:
       return getItemData(item, FISH_DATA, FISH_MAP);
     case GOLDEN_APPLE:
       return getItemData(item, GOLDEN_APPLE_ITEM_DATA, GOLDEN_APPLE_MAP);
     default:
       Optional<DurabilityData> data =
           Pore.getGame()
               .getRegistry()
               .createItemBuilder()
               .itemType(MaterialConverter.asItem(item.getType()))
               .quantity(1)
               .build()
               .get(DURABILITY_DATA);
       if (data.isPresent()) {
         return data.get();
       } else {
         throw new UnsupportedOperationException();
       }
   }
   return null;
 }