示例#1
0
 @EventHandler(priority = EventPriority.HIGHEST)
 public void onBlockPlace(BlockPlaceEvent event) {
   if (event.getBlock().equals(place.getBlock())) {
     if (event.getBlock().getType().equals(Material.WOOL)) {
       if (((Wool) event.getBlock().getState().getData()).getColor().equals(color)) {
         if (Teams.getTeamByPlayer(event.getPlayer()).orNull() == team) {
           this.complete = true;
           if (this.show)
             ChatUtil.getGlobalChannel()
                 .sendLocalizedMessage(
                     new UnlocalizedChatMessage(
                         ChatColor.WHITE + "{0}",
                         new LocalizedChatMessage(
                             ChatConstant.UI_OBJECTIVE_PLACED,
                             team.getColor() + event.getPlayer().getName() + ChatColor.WHITE,
                             team.getCompleteName() + ChatColor.WHITE,
                             MiscUtil.convertDyeColorToChatColor(color)
                                 + name.toUpperCase().replaceAll("_", " ")
                                 + ChatColor.WHITE)));
           Fireworks.spawnFirework(
               event.getPlayer().getLocation(),
               event.getPlayer().getWorld(),
               MiscUtil.convertChatColorToColor(MiscUtil.convertDyeColorToChatColor(color)));
           ObjectiveCompleteEvent compEvent = new ObjectiveCompleteEvent(this, event.getPlayer());
           Bukkit.getServer().getPluginManager().callEvent(compEvent);
           event.setCancelled(false);
         } else {
           event.setCancelled(true);
           if (this.show)
             ChatUtil.sendWarningMessage(
                 event.getPlayer(), "You may not complete the other team's objective.");
         }
       } else {
         event.setCancelled(true);
         if (this.show)
           ChatUtil.sendWarningMessage(
               event.getPlayer(),
               new LocalizedChatMessage(
                   ChatConstant.ERROR_BLOCK_PLACE,
                   MiscUtil.convertDyeColorToChatColor(color)
                       + color.name().toUpperCase().replaceAll("_", " ")
                       + " WOOL"
                       + ChatColor.RED));
       }
     } else {
       event.setCancelled(true);
       if (this.show)
         ChatUtil.sendWarningMessage(
             event.getPlayer(),
             new LocalizedChatMessage(
                 ChatConstant.ERROR_BLOCK_PLACE,
                 MiscUtil.convertDyeColorToChatColor(color)
                     + color.name().toUpperCase().replaceAll("_", " ")
                     + " WOOL"
                     + ChatColor.RED));
     }
   }
 }
示例#2
0
 @EventHandler(priority = EventPriority.MONITOR)
 public void onSafetyPlace(BlockPlaceEvent event) {
   if (!event.isCancelled() && this.touched) {
     if (event.getBlock().getType().equals(Material.WOOL)) {
       if (((Wool) event.getBlock().getState().getData()).getColor().equals(color)) {
         if (Teams.getTeamByPlayer(event.getPlayer()).orNull() == team) {
           if (event.getBlockPlaced().getLocation().distance(place.getLocation()) < proximity) {
             double old = proximity;
             proximity = event.getBlockPlaced().getLocation().distance(place.getLocation());
             Bukkit.getServer()
                 .getPluginManager()
                 .callEvent(new ObjectiveProximityEvent(this, event.getPlayer(), old, proximity));
           }
         }
       }
     }
   }
 }
示例#3
0
 public boolean contains(BlockRegion region) {
   return contains(region.getVector());
 }
示例#4
0
 @EventHandler
 public void onBlockBreak(BlockBreakEvent event) {
   if (event.getBlock().equals(place.getBlock())) {
     event.setCancelled(true);
   }
 }
示例#5
0
 @EventHandler
 public void onWoolPickup(PlayerPickupItemEvent event) {
   Player player = event.getPlayer();
   if (!this.complete && GameHandler.getGameHandler().getMatch().isRunning()) {
     try {
       if (event.getItem().getItemStack().getType() == Material.WOOL
           && event.getItem().getItemStack().getData().getData() == color.getData()) {
         if (Teams.getTeamByPlayer(player).orNull() == team) {
           boolean touchMessage = false;
           if (!this.playersTouched.contains(player.getUniqueId())) {
             this.playersTouched.add(player.getUniqueId());
             if (this.show && !this.complete) {
               Teams.getTeamChannel(Optional.of(team))
                   .sendLocalizedMessage(
                       new UnlocalizedChatMessage(
                           ChatColor.WHITE + "{0}",
                           new LocalizedChatMessage(
                               ChatConstant.UI_OBJECTIVE_PICKED,
                               team.getColor() + player.getName() + ChatColor.WHITE,
                               MiscUtil.convertDyeColorToChatColor(color)
                                   + name.toUpperCase().replaceAll("_", " ")
                                   + ChatColor.WHITE,
                               team.getCompleteName() + ChatColor.WHITE)));
               for (Player player1 : Bukkit.getOnlinePlayers()) {
                 if (Teams.getTeamByPlayer(player1).isPresent()
                     && Teams.getTeamByPlayer(player1).get().isObserver()) {
                   player1.sendMessage(
                       new UnlocalizedChatMessage(
                               ChatColor.GRAY + "{0}",
                               new LocalizedChatMessage(
                                   ChatConstant.UI_OBJECTIVE_PICKED_FOR,
                                   team.getColor() + player.getName() + ChatColor.GRAY,
                                   MiscUtil.convertDyeColorToChatColor(color)
                                       + name.toUpperCase().replaceAll("_", " ")
                                       + ChatColor.GRAY,
                                   team.getCompleteName() + ChatColor.GRAY))
                           .getMessage(player1.getLocale()));
                 }
               }
               touchMessage = true;
             }
           }
           boolean oldState = this.touched;
           this.touched = true;
           if (touchMessage) {
             double newProx;
             if (location != null) {
               newProx = location.distance(place.getVector());
             } else {
               newProx = player.getLocation().toVector().distance(place.getVector());
             }
             if (!oldState || newProx < proximity) {
               proximity = newProx;
             }
           }
           ObjectiveTouchEvent touchEvent =
               new ObjectiveTouchEvent(this, player, !oldState, touchMessage);
           Bukkit.getServer().getPluginManager().callEvent(touchEvent);
         }
       }
     } catch (NullPointerException e) {
     }
   }
 }
  @SuppressWarnings({"unchecked"})
  private <T extends RegionModule> T mirrorRegion(T region) {

    if (region instanceof PointRegion) {

      PointRegion rg = (PointRegion) region;
      int[] v1 = getMirroredValues(rg.getX(), rg.getY(), rg.getZ());
      return (T) new PointRegion(null, rg.getX() + v1[0], rg.getY() + v1[1], rg.getZ() + v1[2]);

    } else if (region instanceof BlockRegion) {

      BlockRegion rg = (BlockRegion) region;
      int[] v1 = getMirroredValues(rg.getX(), rg.getY(), rg.getZ());
      return (T) new BlockRegion(null, rg.getX() + v1[0], rg.getY() + v1[1], rg.getZ() + v1[2]);

    } else if (region instanceof CircleRegion) {

      CircleRegion rg = (CircleRegion) region;
      int[] v1 = getMirroredValues(rg.getBaseX(), rg.getBaseY(), rg.getBaseZ());
      return (T)
          new CircleRegion(null, rg.getBaseX() + v1[0], rg.getBaseZ() + v1[2], rg.getRadius());

    } else if (region instanceof CylinderRegion) {

      CylinderRegion rg = (CylinderRegion) region;
      int[] v1 = getMirroredValues(rg.getBaseX(), rg.getBaseY(), rg.getBaseZ());
      return (T)
          new CylinderRegion(
              null,
              new Vector(rg.getBaseX() + v1[0], rg.getBaseY() + v1[1], rg.getBaseZ() + v1[2]),
              rg.getRadius(),
              rg.getHeight());

    } else if (region instanceof RectangleRegion) {

      RectangleRegion rg = (RectangleRegion) region;
      int[] v1 = getMirroredValues(rg.getXMin(), rg.getYMin(), rg.getZMin());
      int[] v2 = getMirroredValues(rg.getXMax(), rg.getYMax(), rg.getZMax());
      return (T)
          new RectangleRegion(
              null,
              rg.getXMin() + v1[0],
              rg.getZMin() + v1[2],
              rg.getXMax() + v2[0],
              rg.getZMax() + v2[2]);

    } else if (region instanceof CuboidRegion) {

      CuboidRegion rg = (CuboidRegion) region;
      int[] v1 = getMirroredValues(rg.getXMin(), rg.getYMin(), rg.getZMin());
      int[] v2 = getMirroredValues(rg.getXMax(), rg.getYMax(), rg.getZMax());
      return (T)
          new CuboidRegion(
              null,
              rg.getXMin() + v1[0],
              rg.getYMin() + v1[1],
              rg.getZMin() + v1[2],
              rg.getXMax() + v2[0],
              rg.getYMax() + v2[1],
              rg.getZMax() + v2[2]);

    } else if (region instanceof SphereRegion) {

      SphereRegion rg = (SphereRegion) region;
      int[] v1 = getMirroredValues(rg.getOriginX(), rg.getOriginY(), rg.getOriginZ());
      return (T)
          new SphereRegion(
              null,
              new Vector(rg.getOriginX() + v1[0], rg.getOriginY() + v1[1], rg.getOriginZ() + v1[2]),
              rg.getRadius());

    } else if (region instanceof EmptyRegion) {

      return (T) new EmptyRegion("");

    } else if (region instanceof ComplementRegion) {

      ComplementRegion rg = (ComplementRegion) region;
      ModuleCollection<RegionModule> regions = new ModuleCollection<>();
      for (RegionModule rg1 : rg.getRegions()) {
        regions.add(mirrorRegion(rg1));
      }
      return (T) new ComplementRegion(null, regions);

    } else if (region instanceof IntersectRegion) {

      IntersectRegion rg = (IntersectRegion) region;
      ModuleCollection<RegionModule> regions = new ModuleCollection<>();
      for (RegionModule rg1 : rg.getRegions()) {
        regions.add(mirrorRegion(rg1));
      }
      return (T) new IntersectRegion(null, regions);

    } else if (region instanceof NegativeRegion) {

      NegativeRegion rg = (NegativeRegion) region;
      ModuleCollection<RegionModule> regions = new ModuleCollection<>();
      for (RegionModule rg1 : rg.getRegions()) {
        regions.add(mirrorRegion(rg1));
      }
      return (T) new NegativeRegion(null, regions);

    } else if (region instanceof UnionRegion) {

      UnionRegion rg = (UnionRegion) region;
      ModuleCollection<RegionModule> regions = new ModuleCollection<>();
      for (RegionModule rg1 : rg.getRegions()) {
        regions.add(mirrorRegion(rg1));
      }
      return (T) new UnionRegion(null, regions);

    } else if (region instanceof TranslatedRegion) {

      TranslatedRegion rg = (TranslatedRegion) region;
      return (T) new TranslatedRegion(null, mirrorRegion(rg.getRegion()));

    } else if (region instanceof MirroredRegion) {

      MirroredRegion rg = (MirroredRegion) region;
      return (T) new MirroredRegion(null, mirrorRegion(rg.getRegion()));
    }
    return null;
  }