aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/los/numeros/HidersAndDiggers/modules/MainModule.java
blob: 7513cca7dace89a654d3eb35bbb4c829b190ac9a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
package los.numeros.HidersAndDiggers.modules;

import los.numeros.GameEngine.Module;
import los.numeros.utils.GiveItem;
import net.minecraft.enchantment.Enchantments;
import net.minecraft.entity.effect.StatusEffectInstance;
import net.minecraft.entity.effect.StatusEffects;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.server.command.ServerCommandSource;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.world.GameMode;

public class MainModule implements Module {
  ServerPlayerEntity[] diggers, hidders, players;
  ServerCommandSource source;

  public MainModule(ServerPlayerEntity[] diggers, ServerPlayerEntity[] hidders, ServerPlayerEntity[] players, ServerCommandSource source) {
    this.diggers = diggers;
    this.hidders = hidders;
    this.players = players;
    this.source = source;
  }

  public void giveDiggerItems(ServerPlayerEntity[] diggers) {
    // get pickace with efficiency 3
    ItemStack pickaxe = GiveItem.getItem("diamond_pickaxe");
    pickaxe.addEnchantment(Enchantments.EFFICIENCY, 3);

    // put unbreakable attribute into NBT tag
    NbtCompound pTag = pickaxe.getTag();
    pTag.putBoolean("Unbreakable", true);
    pickaxe.setTag(pTag);

    for (ServerPlayerEntity p : diggers) {
      // give armor
      GiveItem.givePlayerItem(p, "diamond_helmet", GiveItem.ARMOR_HEAD);
      GiveItem.givePlayerItem(p, "diamond_leggings", GiveItem.ARMOR_LEGS);
      GiveItem.givePlayerItem(p, "diamond_chestplate", GiveItem.ARMOR_CHEST);
      GiveItem.givePlayerItem(p, "diamond_boots", GiveItem.ARMOR_BOOTS);
      GiveItem.givePlayerItem(p, "iron_sword", 0);

      // equip pick axe and glow diggers
      p.equip(1, pickaxe);
      p.addStatusEffect(new StatusEffectInstance(StatusEffects.GLOWING, 200000000, 3, false, false));
    }
  }

  public void giveHidersItems(ServerPlayerEntity[] hiders) {
    // get pick with silk touch
    ItemStack pickaxe = GiveItem.getItem("diamond_pickaxe");
    pickaxe.addEnchantment(Enchantments.SILK_TOUCH, 1);

    // put unbreakable attribute into NBT tag
    NbtCompound pTag = pickaxe.getTag();
    pTag.putBoolean("Unbreakable", true);
    pickaxe.setTag(pTag);

    for (ServerPlayerEntity p : hiders) {
      // equip picaxe on each player
      p.equip(0, pickaxe);
      // give stone x10
      GiveItem.giveMultipleItem(p, "minecraft:stone", null, 10);
    }
  }

  @Override
  public int init()
  {
    // Give items and status effects to everyone playing game
    for (ServerPlayerEntity p : players) {
      // Put everyone to full health and hunger and give them night vision on haste until game ends
      p.inventory.clear();
      p.addStatusEffect(new StatusEffectInstance(StatusEffects.NIGHT_VISION, 200000000, 3, false, false));
      p.addStatusEffect(new StatusEffectInstance(StatusEffects.HASTE, 200000000, 1, false, false));
      p.addStatusEffect(new StatusEffectInstance(StatusEffects.SATURATION, 300, 100, false, false));
      p.heal(20);

      // give steak x64
      GiveItem.giveMultipleItem(p, "cooked_beef", 2, 64);

      p.setGameMode(GameMode.SURVIVAL);
    }
    giveDiggerItems(diggers);
    giveHidersItems(hidders);

    ServerWorld world = source.getWorld();
    // TODO: FILL AND TP PLAYERS AND CLEAR ALL ITEMS
    return 0;
  }
  
  @Override
  public int end()
  {
    for (ServerPlayerEntity p : players) {
      p.clearStatusEffects();
      p.setGameMode(GameMode.CREATIVE);
      p.inventory.clear();
    }
    return 0;
  }
}