Package com.bergerkiller.bukkit.tc.controller

Examples of com.bergerkiller.bukkit.tc.controller.MinecartGroup


  @Override
  public void update() {
    super.update();
    if (!owner.isUnloaded()) {
      MinecartGroup group = owner.getGroup();
      // Member owner could be dead and have no group
      if (group != null) {
        group.getBlockTracker().update();
      }
    }
  }
View Full Code Here


  @Override
  public void onPreMove(MinecartMember<?> member) {
    final CommonMinecart<?> entity = member.getEntity();

    MinecartGroup group = member.getGroup();
    // Velocity modifier for sloped tracks
    if (group.getProperties().isSlowingDown() && !member.isMovementControlled()) {
      entity.vel.xz.subtract(this.getDirection(), MinecartMember.SLOPE_VELOCITY_MULTIPLIER);
    }
    entity.vel.xz.add(this.getDirection(), entity.vel.getY());
    entity.vel.y.setZero();
View Full Code Here

    }

    //entities left behind?
    for (World world : WorldUtil.getWorlds()) {
      for (org.bukkit.entity.Entity entity : WorldUtil.getEntities(world)) {
        MinecartGroup group = MinecartGroup.get(entity);
        if (group != null) {
          group.unload();
        }
      }
    }

    save();
View Full Code Here

      listener.onLeave(mm);
    }
    if (mm.isUnloaded()) {
      return;
    }
    final MinecartGroup group = mm.getGroup();
    for (MinecartMember<?> ex : this.members) {
      if (ex != mm && ex.getGroup() == group) {
        return;
      }
    }
View Full Code Here

      listener.onEnter(mm);
    }
    if (mm.isUnloaded()) {
      return;
    }
    final MinecartGroup group = mm.getGroup();
    for (MinecartMember<?> ex : this.members) {
      if (ex != mm && ex.getGroup() == group) {
        return;
      }
    }
View Full Code Here

    return "train";
  }

  @Override
  public MinecartGroup getHolder() {
    MinecartGroup group = this.group.get();
    if (group == null || group.isRemoved()) {
      return this.group.set(MinecartGroup.get(this));
    } else {
      return group;
    }
  }
View Full Code Here

      this.setDefault(getDefaultsByPlayer(player));
    }
  }

  public void tryUpdate() {
    MinecartGroup g = this.getHolder();
    if (g != null) g.onPropertiesChanged();
  }
View Full Code Here

      } else {
        MinecartMember<?> member = MinecartMemberStore.get(event.getEntity());
        if (member == null) {
          return;
        }
        MinecartGroup group = member.getGroup();
        if (group == null) {
          return;
        }
        // Minecart was removed but was not dead - unload the group
        // This really should never happen - Chunk/World unload events take care of this
        // If it does happen, it implies that a chunk unloaded without raising an event
        if (group.canUnload()) {
          TrainCarts.plugin.log(Level.WARNING, "Train '" + group.getProperties().getTrainName() + "' forcibly unloaded!");
        } else {
          TrainCarts.plugin.log(Level.WARNING, "Train '" + group.getProperties().getTrainName() + "' had to be restored after unexpected unload");
        }
        group.unload();
        // For the next tick: update the storage system to restore trains here and there
        CommonUtil.nextTick(new Runnable() {
          public void run() {
            OfflineGroupManager.refresh();
          }
View Full Code Here

    for (TrainProperties prop : TrainProperties.getAll()) {
      if (!prop.hasOwnership(player)) {
        continue;
      }
      if (prop.hasHolder() && statement.length() > 0) {
        MinecartGroup group = prop.getHolder();
        SignActionEvent event = new SignActionEvent(null, group);
        if (!Statement.has(group, statement, event)) {
          continue;
        }
      }
View Full Code Here

        prop.setDestination(dest);
        p.sendMessage(ChatColor.YELLOW + "You set " + ChatColor.WHITE + dest + ChatColor.YELLOW + " as destination for all the minecarts in this train!");
      }
    } else if (cmd.equals("remove") || cmd.equals("destroy")) {
      Permission.COMMAND_DESTROY.handle(p);
      MinecartGroup group = prop.getHolder();
      if (group == null) {
        TrainPropertiesStore.remove(prop.getTrainName());
        OfflineGroupManager.removeGroup(prop.getTrainName());
      } else {
        group.destroy();
      }
      p.sendMessage(ChatColor.YELLOW + "The selected train has been destroyed!");
    } else if (cmd.equals("public")) {
      Permission.COMMAND_SETPUBLIC.handle(p);
      boolean pub;
      if (args.length == 0) {
        pub = true;
      } else {
        pub = ParseUtil.parseBool(args[0]);
      }
      prop.setPublic(pub);
      p.sendMessage(ChatColor.YELLOW + "The selected train can be used by everyone: " + ChatColor.WHITE + pub);
    } else if (cmd.equals("private") || cmd.equals("locked") || cmd.equals("lock")) {
      Permission.COMMAND_SETPUBLIC.handle(p);
      boolean pub;
      if (args.length == 0) {
        pub = false;
      } else {
        pub = !ParseUtil.parseBool(args[0]);
      }
      prop.setPublic(pub);
      p.sendMessage(ChatColor.YELLOW + "The selected train can only be used by the respective owners: " + ChatColor.WHITE + !pub);
    } else if (cmd.equals("pickup")) {
      Permission.COMMAND_PICKUP.handle(p);
      boolean mode = true;
      if (args.length > 0) mode = ParseUtil.parseBool(args[0]);
      prop.setPickup(mode);
      p.sendMessage(ChatColor.YELLOW + "The selected train picks up nearby items: " + ChatColor.WHITE + mode);
    } else if (cmd.equals("default") || cmd.equals("def")) {
      Permission.COMMAND_DEFAULT.handle(p);
      if (args.length == 0) {
       
      } else {
        prop.setDefault(args[0]);
        p.sendMessage(ChatColor.GREEN + "Train properties has been re-set to the defaults named '" + args[0] + "'!");
      }
    } else if (cmd.equals("break")) {
      Permission.COMMAND_BREAKBLOCK.handle(p);
      if (args.length == 0) {
        Set<Material> types = new HashSet<Material>();
        for (CartProperties cprop : prop) types.addAll(cprop.getBlockBreakTypes());
        p.sendMessage(ChatColor.YELLOW + "This train breaks: " + ChatColor.WHITE + StringUtil.combineNames(types));
      } else {
        if (ParseUtil.isBool(args[0]) && !ParseUtil.parseBool(args[0])) {
          for (CartProperties cprop : prop) cprop.clearBlockBreakTypes();
          p.sendMessage(ChatColor.YELLOW + "Train block break types have been cleared!");
        } else {
          boolean asBreak = true;
          boolean lastIsBool = ParseUtil.isBool(args[args.length - 1]);
          if (lastIsBool) asBreak = ParseUtil.parseBool(args[args.length - 1]);
          int count = lastIsBool ? args.length - 1 : args.length;
          Set<Material> mats = new HashSet<Material>();
          for (int i = 0; i < count; i++) {
            Material mat = ParseUtil.parseMaterial(args[i], null);
            if (mat != null) {
              if (p.hasPermission("train.command.break.admin") || TrainCarts.canBreak(mat)) {
                mats.add(mat);
              } else {
                p.sendMessage(ChatColor.RED + "You are not allowed to make this train break '" + mat.toString() + "'!");
              }
            }
          }
          if (mats.isEmpty()) {
            p.sendMessage(ChatColor.RED + "Failed to find possible and allowed block types in the list given.");
            return true;
          }
          if (asBreak) {
            for (CartProperties cprop : prop) {
              cprop.getBlockBreakTypes().addAll(mats);
            }
            p.sendMessage(ChatColor.YELLOW + "This cart can now (also) break: " + ChatColor.WHITE + StringUtil.combineNames(mats));
          } else {
            for (CartProperties cprop : prop) {
              cprop.getBlockBreakTypes().removeAll(mats);
            }
            p.sendMessage(ChatColor.YELLOW + "This cart can no longer break: " + ChatColor.WHITE + StringUtil.combineNames(mats));
          }
        }
      }
    } else if (cmd.equals("path") || cmd.equals("route") || cmd.equals("pathinfo")) {
      Permission.COMMAND_PATHINFO.handle(p);
      Commands.showPathInfo(p, prop);
    } else if (cmd.equals("teleport") || cmd.equals("tp")) {
      Permission.COMMAND_TELEPORT.handle(p);
      if (!prop.restore()) {
        p.sendMessage(ChatColor.RED + "Train location could not be found: Train is lost");
      } else {
        BlockLocation bloc = prop.getLocation();
        World world = bloc.getWorld();
        if (world == null) {
          p.sendMessage(ChatColor.RED + "Train is on a world that is not loaded (" + bloc.world + ")");
        } else {
          EntityUtil.teleport(p, new Location(world, bloc.x + 0.5, bloc.y + 0.5, bloc.z + 0.5));
        }
      }
    } else if (LogicUtil.contains(cmd, "setblock", "setblocks", "changeblock", "changeblocks", "blockchanger")) {
      Permission.COMMAND_CHANGEBLOCK.handle(p);
      MinecartGroup members = prop.getHolder();
      if (members == null) {
        p.sendMessage(ChatColor.RED + "The selected train is unloaded: we can not change it at this time!");
      } else if (args.length == 0) {
        for (MinecartMember<?> member : members) {
          member.getEntity().setBlock(Material.AIR);
        }
        p.sendMessage(ChatColor.YELLOW + "The selected train has its displayed blocks cleared!");
      } else {
        SignActionBlockChanger.setBlocks(members, StringUtil.join(" ", args));
        p.sendMessage(ChatColor.YELLOW + "The selected train has its displayed blocks updated!");
      }
    } else if (LogicUtil.contains(cmd, "setblockoffset", "changeblockoffset", "blockoffset")) {
      Permission.COMMAND_CHANGEBLOCK.handle(p);
      MinecartGroup members = prop.getHolder();
      if (members == null) {
        p.sendMessage(ChatColor.RED + "The selected train is unloaded: we can not change it at this time!");
      } else if (args.length == 0) {
        for (MinecartMember<?> member : members) {
          member.getEntity().setBlockOffset(9);
View Full Code Here

TOP

Related Classes of com.bergerkiller.bukkit.tc.controller.MinecartGroup

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.