Skip to content

Commit

Permalink
Merge pull request #43 from Permanently/pre-game-prep
Browse files Browse the repository at this point in the history
Pre-game preparation
  • Loading branch information
ericyoondotcom authored Jan 3, 2021
2 parents dc8a23a + 762438e commit 0e3e7bd
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
import java.util.UUID;
import java.util.stream.Collectors;

import static com.yoonicode.minecraftmanhunt.PluginListener.world;
import static com.yoonicode.minecraftmanhunt.PluginListener.worldBorderModified;
import static org.bukkit.Bukkit.*;

public class PluginCommands implements CommandExecutor {
Expand Down Expand Up @@ -267,6 +269,20 @@ public boolean onCommand(CommandSender commandSender, Command command, String la
main.runnersTeam.removeEntry(i);
}

if (main.getConfig().getBoolean("clearItemDropsOnStart", false)) {
commandSender.getServer().dispatchCommand(getServer().getConsoleSender(), "minecraft:kill @e[type=item]");
}

if (worldBorderModified) {
WorldBorder wb = world.getWorldBorder();
wb.setCenter(0.5, 0.5);
wb.setSize(60000000);
}

if (main.getConfig().getBoolean("setTimeToZero", true)) {
world.setTime(0);
}

for (String i : main.spectators) {
Player player = Bukkit.getPlayer(i);
if (player == null) continue;
Expand All @@ -282,7 +298,13 @@ public boolean onCommand(CommandSender commandSender, Command command, String la
player.setGameMode(GameMode.SURVIVAL);
player.setHealth(20.0);
player.setFoodLevel(20);
// player.getInventory().clear();

if (main.getConfig().getBoolean("clearRunnerInvOnStart", false)) {
player.getInventory().clear();
player.setExp(0);
player.setLevel(0);
}

main.runnersTeam.addEntry(player.getName());
if(!main.discord.assignRole(ManhuntTeam.RUNNER, player.getName())){
commandSender.sendMessage("Could not assign Discord role. Make sure the target's username is also their Discord nickname.");
Expand All @@ -297,7 +319,12 @@ public boolean onCommand(CommandSender commandSender, Command command, String la
player.addPotionEffect(new PotionEffect(PotionEffectType.SLOW_DIGGING, 20 * headStartDuration, 10));
player.setHealth(20.0);
player.setFoodLevel(20);
// player.getInventory().clear();

if (main.getConfig().getBoolean("clearHunterInvOnStart", false)) {
player.getInventory().clear();
player.setExp(0);
}

player.getInventory().addItem(new ItemStack(Material.COMPASS, 1));
main.huntersTeam.addEntry(player.getName());
if(!main.discord.assignRole(ManhuntTeam.HUNTER, player.getName())){
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
package com.yoonicode.minecraftmanhunt;

import net.dv8tion.jda.api.Permission;
import org.bukkit.GameMode;
import org.bukkit.Material;
import org.bukkit.OfflinePlayer;
import org.bukkit.*;
import org.bukkit.block.Skull;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
Expand All @@ -12,10 +10,7 @@
import org.bukkit.event.entity.PlayerDeathEvent;
import org.bukkit.event.inventory.CraftItemEvent;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.player.PlayerChatTabCompleteEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerPortalEvent;
import org.bukkit.event.player.PlayerRespawnEvent;
import org.bukkit.event.player.*;
import org.bukkit.event.server.TabCompleteEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.PlayerInventory;
Expand All @@ -28,6 +23,8 @@
public class PluginListener implements Listener {

boolean setRunnersToSpecOnDeath;
static boolean worldBorderModified = false;
static World world;
PluginMain main;
public PluginListener(PluginMain main) {
this.main = main;
Expand Down Expand Up @@ -108,6 +105,23 @@ public void onPlayerEnterPortal(PlayerPortalEvent event){
main.portals.put(event.getPlayer().getName(), event.getFrom());
}

@EventHandler
public void onPlayerJoin(PlayerJoinEvent event){
if (!worldBorderModified && main.getConfig().getBoolean("preGameWorldBorder", false)) {
Location joinLoc = event.getPlayer().getLocation();
world = event.getPlayer().getWorld();
WorldBorder wb = world.getWorldBorder();

wb.setDamageAmount(0);
wb.setWarningDistance(0);
wb.setCenter(joinLoc);
wb.setSize(main.getConfig().getInt("preGameBorderSize", 100));

worldBorderModified = true;
}

}

@EventHandler
public void onPlayerRespawn(PlayerRespawnEvent event){
String playerName = event.getPlayer().getName();
Expand Down
20 changes: 20 additions & 0 deletions MinecraftManhunt/src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,26 @@ huntersColor: "&c"
runnersColor: "&a"
spectatorsColor: "&b"

# You can change game preparations here.
# Depending on what environment you run this plugin in, this could erase your data.
# For example, if this is running on primary survival server, you may not want to clear inventory.

# Set to true to clear runner inventories and EXP when the game starts.
clearRunnerInvOnStart: false
# Set to true to clear hunter inventories and EXP when the game starts.
clearHunterInvOnStart: false
# Set to true to clear all item drops when the game starts.
clearItemDropsOnStart: true
# Set to true to set the world time to 0 when the game starts.
setTimeToZero: true

# Set to true if you want a pre-game world border to be set before the game starts.
# This may be useful if you don't want a player exploring the world, prior ot starting.
# If your server isn't only being used for manhunt, you may want to leave this as false.
preGameWorldBorder: true
# This will set the size of the pre-game border. Recommended to leave at 100.
preGameBorderSize: 100

# Read the plugin README/description for more info on how to set up Discord integration!
enableDiscord: false
discordToken: "XXXXX"
Expand Down
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,12 @@ Edit the `plugins/MinecraftManhunt/config.yml` file with the following options:
huntersColor | The color to give to the `hunters` team. | string | Optional
runnersColor | The color to give to the `runners` team. | string | Optional
spectatorsColor | The color to give to the `spectators` team. | string | Optional
clearRunnerInvOnStart | Set to true to clear the runner's inventory and experience when the game starts. | boolean | Optional, defaults to `false`
clearHunterInvOnStart | Set to true to clear the hunter's inventory and experience when the game starts. | boolean | Optional, defaults to `false`
clearItemDropsOnStart | Set to true to clear item drops when the game starts. | boolean | Optional, defaults to `false`
setTimeToZero | Set to true to set the time to 0 when the game starts. | boolean | Optional, defaults to `true`
preGameWorldBorder | Set to true to enforce a world border for pre-game. | boolean | Optional, defaults to `false`
preGameBorderSize | States how big the pre-game world border would be, if enabled. | int | Optional, defaults to `100`, ignored when *preGameWorldBorder* is `false`
enableDiscord | Set to true to turn on Discord integration. Read below for more information. | boolean | Required
discordToken | Enter the token of your Discord bot here. | string | Required if `enableDiscord` is `true`
ip | The Discord status message portion. Will display as `Playing {value}` so it's recommended that you make this your server's IP. | string | Optional
Expand Down

0 comments on commit 0e3e7bd

Please sign in to comment.