Skip to content

Commit

Permalink
Merge branch 'pre-game-prep-2' into staging-43
Browse files Browse the repository at this point in the history
  • Loading branch information
ericyoondotcom committed Jan 3, 2021
2 parents 0e3e7bd + 0021729 commit b4881c8
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,11 @@ public class PluginCommands implements CommandExecutor {
"music",
"setheadstart"
};
public static boolean hitHasRegistered;

int compassTask = -1;
int dangerLevelTask = -1;
public boolean gameIsRunning = false;
public static boolean gameIsRunning = false;
boolean compassEnabledInNether;
private final PluginMain main;

Expand Down Expand Up @@ -255,6 +256,12 @@ public boolean onCommand(CommandSender commandSender, Command command, String la
commandSender.sendMessage("Not enough speedrunners to start");
return true;
}

if (main.getConfig().getBoolean("startGameByHit", false) && !hitHasRegistered) {
commandSender.sendMessage("The /start command is disabled. The game will start when a runner hits a hunter.");
return true;
}

commandSender.sendMessage("Starting game...");
main.targets.clear();
int headStartDuration = main.getConfig().getInt("headStartDuration");
Expand Down Expand Up @@ -376,6 +383,9 @@ public void run() {
commandSender.sendMessage("There is no game in progress. Use /start to start a new game.");
return true;
}
if(main.getConfig().getBoolean("startGameByHit", false)){
hitHasRegistered = false;
}
BukkitScheduler scheduler = getServer().getScheduler();
if (compassTask != -1) {
scheduler.cancelTask(compassTask);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@
import org.bukkit.*;
import org.bukkit.block.Skull;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.PlayerDeathEvent;
import org.bukkit.event.entity.*;
import org.bukkit.event.inventory.CraftItemEvent;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.player.*;
Expand All @@ -20,6 +22,9 @@
import java.lang.annotation.Target;
import java.util.List;

import static com.yoonicode.minecraftmanhunt.PluginCommands.gameIsRunning;
import static org.bukkit.Bukkit.getServer;

public class PluginListener implements Listener {

boolean setRunnersToSpecOnDeath;
Expand Down Expand Up @@ -106,7 +111,7 @@ public void onPlayerEnterPortal(PlayerPortalEvent event){
}

@EventHandler
public void onPlayerJoin(PlayerJoinEvent event){
public void onPlayerJoin(PlayerJoinEvent event) {
if (!worldBorderModified && main.getConfig().getBoolean("preGameWorldBorder", false)) {
Location joinLoc = event.getPlayer().getLocation();
world = event.getPlayer().getWorld();
Expand All @@ -119,16 +124,31 @@ public void onPlayerJoin(PlayerJoinEvent event){

worldBorderModified = true;
}
}

@EventHandler
public void onPlayerAttacked(EntityDamageByEntityEvent event) {
if (!PluginCommands.gameIsRunning && main.getConfig().getBoolean("startGameByHit", false)) {
Entity victim = event.getEntity();
Entity attacker = event.getDamager();
EntityDamageEvent.DamageCause cause = event.getCause();
if (attacker.getType() == EntityType.PLAYER && victim.getType() == EntityType.PLAYER
&& cause == EntityDamageEvent.DamageCause.ENTITY_ATTACK
&& PluginMain.huntersTeam.getEntries().contains(victim.getName())
&& PluginMain.runnersTeam.getEntries().contains(attacker.getName())) {
PluginCommands.hitHasRegistered = true;
attacker.getServer().dispatchCommand(getServer().getConsoleSender(), "start");
}
}
}

@EventHandler
public void onPlayerRespawn(PlayerRespawnEvent event){
String playerName = event.getPlayer().getName();
if(main.commands.gameIsRunning && main.hunters.contains(playerName)){
if(gameIsRunning && main.hunters.contains(playerName)){
event.getPlayer().getInventory().addItem(new ItemStack(Material.COMPASS, 1));
}
if(setRunnersToSpecOnDeath && main.commands.gameIsRunning && main.runners.contains(playerName)){
if(setRunnersToSpecOnDeath && gameIsRunning && main.runners.contains(playerName)){
event.getPlayer().setGameMode(GameMode.SPECTATOR);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ public class PluginMain extends JavaPlugin {
public ArrayList<String> spectators = new ArrayList<String>();
public HashMap<String, String> targets = new HashMap<String, String>();
public HashMap<String, Location> portals = new HashMap<String, Location>();
public Team huntersTeam;
public Team runnersTeam;
public static Team huntersTeam;
public static Team runnersTeam;
public Team spectatorsTeam;
public Logger logger;
public DiscordManager discord;
Expand Down
2 changes: 2 additions & 0 deletions MinecraftManhunt/src/main/resources/config.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# How long the hunters should get blindness and slowness when the match starts.
headStartDuration: 30
# Set to true to start the game by having a runner hit a hunter, instead of using the /start command.
startGameByHit: false
# Set to true to allow the compass to work in the nether.
compassEnabledInNether: true
# Set to true to put runners in spectator mode when they die.
Expand Down

0 comments on commit b4881c8

Please sign in to comment.