Advertisement
Wouto1997

asdf

Oct 20th, 2013
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.90 KB | None | 0 0
  1.     public static void HandleSetter(BlockCommandSender sender, ArrayList<Player> affectedPlayers, String arg) {
  2.         Setter setter = new Gson().fromJson(arg, Setter.class);
  3.         if (setter.giveitems.length > 0) {
  4.             for (Inventory inv : setter.giveitems) {
  5.                 if (inv.id != -1) {
  6.                     int id = inv.id;
  7.                     int meta = inv.data != -1 ? inv.data : 0;
  8.                     int amount = inv.amount != -1 ? inv.amount : 1;
  9.                     ItemStack is = new ItemStack(id, amount, (short)meta);
  10.                     if (id == Material.MAP.getId() && inv.mapurl != null) {
  11.                         is = MapChanger.getCustomMap(inv.mapurl);
  12.                         is.setAmount(amount);
  13.                     }
  14.                     if (inv.name != null) {
  15.                         is.getItemMeta().setDisplayName(inv.name);
  16.                     }
  17.                     if (inv.lore.length > 0) {
  18.                         List<String> lore = new ArrayList<String>();
  19.                         for (String clore : inv.lore) {
  20.                             lore.add(clore);
  21.                         }
  22.                         is.getItemMeta().setLore(lore);
  23.                     }
  24.                     if (inv.ench.length > 0) {
  25.                         for (Enchantment e : inv.ench) {
  26.                             if (e.id != -1 && e.level != -1) {
  27.                                 is.getItemMeta().addEnchant(org.bukkit.enchantments.Enchantment.getById(e.id), e.level, true);
  28.                             }
  29.                         }
  30.                     }
  31.                     if (inv.skullowner != null && (is.getType() == Material.SKULL || is.getType() == Material.SKULL_ITEM)) {
  32.                         SkullMeta smeta = (SkullMeta)is.getItemMeta();
  33.                         smeta.setOwner(inv.skullowner);
  34.                         is.setItemMeta(smeta);
  35.                     }
  36.                     for (Player p : affectedPlayers) {
  37.                         if (inv.slot != -1) {
  38.                             p.getInventory().setItem(inv.slot, is);
  39.                         } else {
  40.                             p.getInventory().addItem(is);
  41.                         }
  42.                     }
  43.                 }
  44.             }
  45.         }
  46.         if (setter.setblocks.length > 0) {
  47.             for (SetBlock sb : setter.setblocks) {
  48.                 if (sb.x != Integer.MAX_VALUE && sb.y != Integer.MAX_VALUE && sb.z != Integer.MAX_VALUE) {
  49.                     Location loc = new Location(sender.getBlock().getWorld(), sb.x, sb.y, sb.z);
  50.                     int id = (sb.id == -1) ? sender.getBlock().getWorld().getBlockAt(loc).getTypeId() : sb.id;
  51.                     int meta = sb.meta;
  52.                     sender.getBlock().getWorld().getBlockAt(loc).setTypeIdAndData(id, (byte)meta, true);
  53.                 }
  54.             }
  55.         }
  56.         if (setter.newobj != null) {
  57.             if (setter.newobj.name != null && setter.newobj.goals.length > 0) {
  58.                 ObjectiveSystem.AddObjective(setter.newobj.name, setter.newobj.goals);
  59.             }
  60.         }
  61.         if (setter.setobj != null) {
  62.             if (setter.setobj.completegoal.length > 1) {
  63.                 Objective obj = ObjectiveSystem.find(setter.setobj.completegoal[0]);
  64.                 obj.completeGoal(setter.setobj.completegoal[1]);
  65.             }
  66.             if (setter.setobj.deleteobj != null) {
  67.                 Objective obj = ObjectiveSystem.find(setter.setobj.deleteobj);
  68.                 if (obj == null) { Msg.send("couldn't find objective: '" + setter.setobj.deleteobj + "'"); }
  69.                 else {
  70.                     ObjectiveSystem.objectives.remove(obj);
  71.                 }
  72.             }
  73.             if (setter.setobj.reset == 1) {
  74.                 ObjectiveSystem.objectives.clear();
  75.             }
  76.         }
  77.         if (setter.spawnmobs.length > 0) {
  78.             for (SpawnMob sm : setter.spawnmobs) {
  79.                 if (sm.x != Integer.MAX_VALUE && sm.y != Integer.MAX_VALUE && sm.z != Integer.MAX_VALUE && sm.types.length > 0 && sm.count > 0) {
  80.                     Location center = new Location(sender.getBlock().getWorld(), sm.x, sm.y, sm.z);
  81.                     for (int i=0;i<sm.count;i++) {
  82.                         String mobtype = getRandomMob(sm.types);
  83.                         Location spawnloc = getSpreadLocation(center, sm.spread);
  84.                         if (mobtype.equalsIgnoreCase("skeleton")) {
  85.                             sender.getBlock().getWorld().spawnEntity(spawnloc, EntityType.SKELETON);
  86.                         } else if (mobtype.equalsIgnoreCase("creeper")) {
  87.                             sender.getBlock().getWorld().spawnEntity(spawnloc, EntityType.CREEPER);
  88.                         } else {
  89.                             sender.getBlock().getWorld().spawnEntity(spawnloc, EntityType.ZOMBIE);
  90.                         }
  91.                     }
  92.                 }
  93.             }
  94.         }
  95.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement