aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/los/numeros/EPHS/modules/MainModule.java
blob: b794eb4f62fad5fc1b44f26abffcea17997a9cf2 (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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
package los.numeros.EPHS.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.scoreboard.Scoreboard;
import net.minecraft.scoreboard.Team;
import net.minecraft.scoreboard.AbstractTeam.VisibilityRule;
import net.minecraft.server.command.ServerCommandSource;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.util.Formatting;
import net.minecraft.world.GameMode;
import los.numeros.EPHS.Constants;

public class MainModule implements Module {
  ServerPlayerEntity[] seekers, hiders, players;
  ServerCommandSource source;
  Scoreboard scoreboard;
  Team seekersTeam, hidersTeam;

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

  public void giveSeekerItems(ServerPlayerEntity[] seekers) {
    for (ServerPlayerEntity p : seekers) {
      // 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);

      // get diamond sword and put sarp 1 on it for seeker
      ItemStack sword = GiveItem.getItem("iron_sword");
      sword.addEnchantment(Enchantments.SHARPNESS, 1);

      // make sword unbreakable
      NbtCompound sTag = sword.getTag();
      sTag.putBoolean("Unbreakable", true);
      sword.setTag(sTag);
      p.equip(0, sword);

      // give seeker ender pearl x32
      GiveItem.giveMultipleItem(p, "ender_pearl", null, 32);

      // teleport to the seeker box
      p.teleport(Constants.seekerSpawnX, Constants.seekerSpawnY, Constants.seekerSpawnZ);

      scoreboard.addPlayerToTeam(p.getName().asString(), seekersTeam);
    }
  }

  public void giveHidersItems(ServerPlayerEntity[] hiders) {
    for (ServerPlayerEntity p : hiders) {
      // Give hiders ender pearls x16
      GiveItem.giveMultipleItem(p, "ender_pearl", null, 16);

      // tp hiders to fountain spawn
      p.teleport(Constants.hidersSpawnX, Constants.hidersSpawnY, Constants.hidersSpawnZ);

      // add each hider to the hiders team
      scoreboard.addPlayerToTeam(p.getName().asString(), hidersTeam);
    }
  }

  @Override
  public int init()
  {
    //set up seeker team
    scoreboard = players[0].getScoreboard();
    seekersTeam = scoreboard.addTeam("Seekers");
    seekersTeam.setColor(Formatting.GOLD);
    seekersTeam.setFriendlyFireAllowed(false);

    //set up hidders team
    hidersTeam = scoreboard.addTeam("Hidders");
    hidersTeam.setColor(Formatting.BLUE);
    hidersTeam.setFriendlyFireAllowed(false);
    hidersTeam.setNameTagVisibilityRule(VisibilityRule.HIDE_FOR_OTHER_TEAMS);

    // Give items and status effects to everyone playing game
    for (ServerPlayerEntity p : players) {
      // Put everyone to full health and hunger
      p.inventory.clear();
      p.addStatusEffect(new StatusEffectInstance(StatusEffects.SATURATION, 300, 100, false, false));
      p.heal(20);

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

      // set everyones gamemode
      p.setGameMode(GameMode.ADVENTURE);
    }
    giveSeekerItems(seekers);
    giveHidersItems(hiders);
    return 0;
  }
  
  @Override
  public int end()
  {
    for (ServerPlayerEntity p : players) {
      // resets all effects and inventoty and tp's aeveryone back to spawn
      p.teleport(Constants.spawnX, Constants.spawnY, Constants.spawnZ);
      p.clearStatusEffects();
      p.setGameMode(GameMode.CREATIVE);
      p.inventory.clear();
      
      // removes the teams
      scoreboard.removeTeam(hidersTeam);
      scoreboard.removeTeam(seekersTeam);
    }
    return 0;
  }
}