blockhunt start

This commit is contained in:
Tyler Murphy 2022-07-27 18:20:11 -04:00
parent 72314cabf8
commit e4abbae6af
12 changed files with 210 additions and 7 deletions

View file

@ -1,7 +1,7 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"><modelVersion>4.0.0</modelVersion> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"><modelVersion>4.0.0</modelVersion>
<groupId>net.tylermurphy</groupId> <groupId>net.tylermurphy</groupId>
<artifactId>KenshinsHideAndSeek</artifactId> <artifactId>KenshinsHideAndSeek</artifactId>
<version>1.5.1</version> <version>1.6.0</version>
<name>Hide and Seek Plugin</name> <name>Hide and Seek Plugin</name>
<properties> <properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

View file

@ -24,6 +24,7 @@ import net.tylermurphy.hideAndSeek.configuration.Items;
import net.tylermurphy.hideAndSeek.configuration.Localization; import net.tylermurphy.hideAndSeek.configuration.Localization;
import net.tylermurphy.hideAndSeek.database.Database; import net.tylermurphy.hideAndSeek.database.Database;
import net.tylermurphy.hideAndSeek.game.Board; import net.tylermurphy.hideAndSeek.game.Board;
import net.tylermurphy.hideAndSeek.game.Disguiser;
import net.tylermurphy.hideAndSeek.game.PlayerLoader; import net.tylermurphy.hideAndSeek.game.PlayerLoader;
import net.tylermurphy.hideAndSeek.game.util.Status; import net.tylermurphy.hideAndSeek.game.util.Status;
import net.tylermurphy.hideAndSeek.util.CommandHandler; import net.tylermurphy.hideAndSeek.util.CommandHandler;
@ -56,6 +57,7 @@ public class Main extends JavaPlugin implements Listener {
private final Database database; private final Database database;
private final Board board; private final Board board;
private final Disguiser disguiser;
private Game game; private Game game;
@ -64,6 +66,7 @@ public class Main extends JavaPlugin implements Listener {
onConstructed(); onConstructed();
board = new Board(); board = new Board();
database = new Database(); database = new Database();
disguiser = new Disguiser();
} }
protected Main(JavaPluginLoader loader, PluginDescriptionFile description, File dataFolder, File file) { protected Main(JavaPluginLoader loader, PluginDescriptionFile description, File dataFolder, File file) {
@ -71,6 +74,7 @@ public class Main extends JavaPlugin implements Listener {
onConstructed(); onConstructed();
board = new Board(); board = new Board();
database = new Database(); database = new Database();
disguiser = new Disguiser();
} }
private void onConstructed(){ private void onConstructed(){
@ -123,12 +127,14 @@ public class Main extends JavaPlugin implements Listener {
private void onTick() { private void onTick() {
if(game.getStatus() == Status.ENDED) game = new Game(board); if(game.getStatus() == Status.ENDED) game = new Game(board);
game.onTick(); game.onTick();
disguiser.check();
} }
private void registerListeners() { private void registerListeners() {
getServer().getPluginManager().registerEvents(new BlockedCommandHandler(), this); getServer().getPluginManager().registerEvents(new BlockedCommandHandler(), this);
getServer().getPluginManager().registerEvents(new ChatHandler(), this); getServer().getPluginManager().registerEvents(new ChatHandler(), this);
getServer().getPluginManager().registerEvents(new DamageHandler(), this); getServer().getPluginManager().registerEvents(new DamageHandler(), this);
getServer().getPluginManager().registerEvents(new DisguiseHandler(), this);
getServer().getPluginManager().registerEvents(new InteractHandler(), this); getServer().getPluginManager().registerEvents(new InteractHandler(), this);
getServer().getPluginManager().registerEvents(new InventoryHandler(), this); getServer().getPluginManager().registerEvents(new InventoryHandler(), this);
getServer().getPluginManager().registerEvents(new JoinLeaveHandler(), this); getServer().getPluginManager().registerEvents(new JoinLeaveHandler(), this);
@ -165,6 +171,8 @@ public class Main extends JavaPlugin implements Listener {
return game; return game;
} }
public Disguiser getDisguiser() { return disguiser; }
public boolean supports(int v){ public boolean supports(int v){
return version >= v; return version >= v;
} }

View file

@ -26,7 +26,7 @@ public class About implements ICommand {
public void execute(Player sender, String[] args) { public void execute(Player sender, String[] args) {
sender.sendMessage( sender.sendMessage(
String.format("%s%sHide and Seek %s(%s1.5.1%s)\n", ChatColor.AQUA, ChatColor.BOLD, ChatColor.GRAY,ChatColor.WHITE,ChatColor.GRAY) + String.format("%s%sHide and Seek %s(%s1.6.0%s)\n", ChatColor.AQUA, ChatColor.BOLD, ChatColor.GRAY,ChatColor.WHITE,ChatColor.GRAY) +
String.format("%sAuthor: %s[KenshinEto]\n", ChatColor.GRAY, ChatColor.WHITE) + String.format("%sAuthor: %s[KenshinEto]\n", ChatColor.GRAY, ChatColor.WHITE) +
String.format("%sHelp Command: %s/hs %shelp", ChatColor.GRAY, ChatColor.AQUA, ChatColor.WHITE) String.format("%sHelp Command: %s/hs %shelp", ChatColor.GRAY, ChatColor.AQUA, ChatColor.WHITE)
); );

View file

@ -31,7 +31,7 @@ public class Debug implements ICommand {
} }
private void createMenu(){ private void createMenu(){
debugMenu = Main.getInstance().getServer().createInventory(null, 9, "Debug Menu"); debugMenu = Main.getInstance().getServer().createInventory(null, 18, "Debug Menu");
debugMenu.setItem(0, createOption(0, XMaterial.LEATHER_CHESTPLATE.parseMaterial(), "&6Become a &lHider", 1, player -> { debugMenu.setItem(0, createOption(0, XMaterial.LEATHER_CHESTPLATE.parseMaterial(), "&6Become a &lHider", 1, player -> {
if(mapSaveEnabled) { if(mapSaveEnabled) {
if(Bukkit.getWorld(Main.getInstance().getGame().getGameWorld()) == null) Main.getInstance().getGame().getWorldLoader().loadMap(); if(Bukkit.getWorld(Main.getInstance().getGame().getGameWorld()) == null) Main.getInstance().getGame().getWorldLoader().loadMap();
@ -79,6 +79,10 @@ public class Debug implements ICommand {
debugMenu.setItem(8, createOption(8, Material.ENDER_PEARL, "&d&lTeleport: &fExit", 3, player -> { debugMenu.setItem(8, createOption(8, Material.ENDER_PEARL, "&d&lTeleport: &fExit", 3, player -> {
player.teleport(new Location(Bukkit.getWorld(exitWorld), exitPosition.getX(), exitPosition.getY(), exitPosition.getZ())); player.teleport(new Location(Bukkit.getWorld(exitWorld), exitPosition.getX(), exitPosition.getY(), exitPosition.getZ()));
})); }));
debugMenu.setItem(9, createOption(9, XMaterial.GLASS.parseMaterial(), "&dEnable Disguise", 1, PlayerLoader::openBlockHuntPicker));
debugMenu.setItem(10, createOption(10, XMaterial.PLAYER_HEAD.parseMaterial(), "&dDisable Disguise", 1, player -> {
Main.getInstance().getDisguiser().reveal(player);
}));
} }
private ItemStack createOption(int slow, Material material, String name, int amount, Consumer<Player> callback){ private ItemStack createOption(int slow, Material material, String name, int amount, Consumer<Player> callback){

View file

@ -90,7 +90,8 @@ public class Config {
leaveOnEnd, leaveOnEnd,
mapSaveEnabled, mapSaveEnabled,
allowNaturalCauses, allowNaturalCauses,
saveInventory; saveInventory,
blockhuntEnabled;
public static int public static int
minPlayers, minPlayers,
@ -126,6 +127,9 @@ public class Config {
blockedCommands, blockedCommands,
blockedInteracts; blockedInteracts;
public static List<Material>
blockhuntBlocks;
public static String public static String
LOBBY_TITLE, LOBBY_TITLE,
GAME_TITLE, GAME_TITLE,
@ -288,6 +292,18 @@ public class Config {
} }
bungeeLeave = config.getString("leaveType") == null || config.getString("leaveType").equalsIgnoreCase("proxy"); bungeeLeave = config.getString("leaveType") == null || config.getString("leaveType").equalsIgnoreCase("proxy");
leaveServer = config.getString("leaveServer"); leaveServer = config.getString("leaveServer");
blockhuntEnabled = config.getBoolean("blockhunt.enabled");
blockhuntBlocks = new ArrayList<>();
tempInteracts = config.getStringList("blockhunt.blocks");
for(String id : tempInteracts) {
Optional<XMaterial> optional_mat = XMaterial.matchXMaterial(id);
if (optional_mat.isPresent()) {
Material mat = optional_mat.get().parseMaterial();
if (mat != null) {
blockhuntBlocks.add(mat);
}
}
}
//Leaderboard //Leaderboard
LOBBY_TITLE = leaderboard.getString("lobby.title"); LOBBY_TITLE = leaderboard.getString("lobby.title");

View file

@ -0,0 +1,62 @@
package net.tylermurphy.hideAndSeek.game;
import org.bukkit.Material;
import org.bukkit.entity.FallingBlock;
import org.bukkit.entity.Player;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
import java.util.HashMap;
import java.util.Map;
public class Disguiser {
private final Map<Player, FallingBlock> blocks;
public Disguiser(){
this.blocks = new HashMap<>();
}
public FallingBlock getBlock(Player player){
return blocks.get(player);
}
public boolean contains(FallingBlock block) { return blocks.containsValue(block); }
public boolean disguised(Player player) { return blocks.containsKey(player); }
public void check(){
for(Map.Entry<Player, FallingBlock> set : blocks.entrySet()){
Player player = set.getKey();
FallingBlock block = set.getValue();
if(block.isDead()){
block.remove();
FallingBlock replacement = player.getLocation().getWorld().spawnFallingBlock(player.getLocation(), block.getMaterial(), (byte)0);
replacement.setGravity(false);
replacement.setDropItem(false);
blocks.put(player, replacement);
}
}
}
public void disguise(Player player, Material material){
if(blocks.containsKey(player)){
FallingBlock block = blocks.get(player);
block.remove();
}
FallingBlock block = player.getLocation().getWorld().spawnFallingBlock(player.getLocation(), material, (byte)0);
block.setGravity(false);
block.setDropItem(false);
blocks.put(player, block);
player.addPotionEffect(new PotionEffect(PotionEffectType.INVISIBILITY, 1000000, 0,false, false));
}
public void reveal(Player player){
if(!blocks.containsKey(player)) return;
FallingBlock block = blocks.get(player);
block.remove();
blocks.remove(player);
player.removePotionEffect(PotionEffectType.INVISIBILITY);
}
}

View file

@ -27,9 +27,11 @@ import net.tylermurphy.hideAndSeek.configuration.Items;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.GameMode; import org.bukkit.GameMode;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.attribute.Attribute; import org.bukkit.attribute.Attribute;
import org.bukkit.attribute.AttributeInstance; import org.bukkit.attribute.AttributeInstance;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.potion.PotionEffect; import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType; import org.bukkit.potion.PotionEffectType;
@ -45,6 +47,9 @@ public class PlayerLoader {
loadPlayer(player); loadPlayer(player);
player.addPotionEffect(new PotionEffect(PotionEffectType.SPEED,1000000,5,false,false)); player.addPotionEffect(new PotionEffect(PotionEffectType.SPEED,1000000,5,false,false));
Titles.sendTitle(player, 10, 70, 20, ChatColor.WHITE + "" + message("HIDER_TEAM_NAME"), ChatColor.WHITE + message("HIDERS_SUBTITLE").toString()); Titles.sendTitle(player, 10, 70, 20, ChatColor.WHITE + "" + message("HIDER_TEAM_NAME"), ChatColor.WHITE + message("HIDERS_SUBTITLE").toString());
if(blockhuntEnabled){
openBlockHuntPicker(player);
}
} }
public static void loadSeeker(Player player, String gameWorld){ public static void loadSeeker(Player player, String gameWorld){
@ -141,4 +146,13 @@ public class PlayerLoader {
} }
} }
public static void openBlockHuntPicker(Player player){
int slots = ((blockhuntBlocks.size()-1)/9)*9+9;
Inventory inventory = Main.getInstance().getServer().createInventory(null, slots, "Select a Block");
for(int i=0;i<blockhuntBlocks.size();i++){
inventory.setItem(i, new ItemStack(blockhuntBlocks.get(i)));
}
player.openInventory(inventory);
}
} }

View file

@ -15,6 +15,7 @@ import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityDamageByEntityEvent; import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.entity.EntityDamageEvent; import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.entity.PlayerDeathEvent;
import static net.tylermurphy.hideAndSeek.configuration.Config.*; import static net.tylermurphy.hideAndSeek.configuration.Config.*;
import static net.tylermurphy.hideAndSeek.configuration.Config.spawnPosition; import static net.tylermurphy.hideAndSeek.configuration.Config.spawnPosition;
@ -94,6 +95,8 @@ public class DamageHandler implements Listener {
} else { } else {
XSound.ENTITY_PLAYER_HURT.play(player, 1, 1); XSound.ENTITY_PLAYER_HURT.play(player, 1, 1);
} }
// Reveal player if they are disguised
Main.getInstance().getDisguiser().reveal(player);
// Teleport player to seeker spawn // Teleport player to seeker spawn
player.teleport(new Location(Bukkit.getWorld(game.getGameWorld()), spawnPosition.getX(), spawnPosition.getY(), spawnPosition.getZ())); player.teleport(new Location(Bukkit.getWorld(game.getGameWorld()), spawnPosition.getX(), spawnPosition.getY(), spawnPosition.getZ()));
// Add leaderboard stats // Add leaderboard stats
@ -115,4 +118,9 @@ public class DamageHandler implements Listener {
board.reloadBoardTeams(); board.reloadBoardTeams();
} }
@EventHandler(priority = EventPriority.MONITOR)
public void onPlayerDeath(PlayerDeathEvent event){
Main.getInstance().getDisguiser().reveal(event.getEntity());
}
} }

View file

@ -0,0 +1,46 @@
package net.tylermurphy.hideAndSeek.game.listener;
import com.comphenix.protocol.PacketType;
import com.comphenix.protocol.ProtocolLibrary;
import com.comphenix.protocol.ProtocolManager;
import com.comphenix.protocol.events.PacketContainer;
import net.tylermurphy.hideAndSeek.Main;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.entity.FallingBlock;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerMoveEvent;
import java.lang.reflect.InvocationTargetException;
public class DisguiseHandler implements Listener {
private static final ProtocolManager protocolManager = ProtocolLibrary.getProtocolManager();
@EventHandler(priority = EventPriority.HIGHEST)
public void onMove(PlayerMoveEvent event) {
FallingBlock block = Main.getInstance().getDisguiser().getBlock(event.getPlayer());
if(block == null) return;
Bukkit.getOnlinePlayers().forEach(player -> {
teleportEntity(player, block, event.getPlayer().getLocation());
});
}
private void teleportEntity(Player player, FallingBlock block, Location location) {
PacketContainer packet = protocolManager.createPacket(PacketType.Play.Server.ENTITY_TELEPORT);
packet.getModifier().writeDefaults();
packet.getIntegers().write(0, block.getEntityId());
packet.getDoubles().write(0, location.getX());
packet.getDoubles().write(1, location.getY());
packet.getDoubles().write(2, location.getZ());
try {
protocolManager.sendServerPacket(player, packet);
} catch (InvocationTargetException e) {
e.printStackTrace();
}
}
}

View file

@ -19,26 +19,29 @@
package net.tylermurphy.hideAndSeek.game.listener; package net.tylermurphy.hideAndSeek.game.listener;
import static net.tylermurphy.hideAndSeek.configuration.Config.*;
import com.cryptomorin.xseries.XMaterial; import com.cryptomorin.xseries.XMaterial;
import net.tylermurphy.hideAndSeek.Main; import net.tylermurphy.hideAndSeek.Main;
import net.tylermurphy.hideAndSeek.command.Debug; import net.tylermurphy.hideAndSeek.command.Debug;
import net.tylermurphy.hideAndSeek.game.util.Status; import net.tylermurphy.hideAndSeek.game.util.Status;
import org.bukkit.Material;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority; import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.inventory.InventoryClickEvent; import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.inventory.InventoryCloseEvent;
public class InventoryHandler implements Listener { public class InventoryHandler implements Listener {
@EventHandler(priority = EventPriority.HIGHEST) @EventHandler(priority = EventPriority.HIGHEST)
public void onInventoryClick(InventoryClickEvent event) { public void onInventoryClick(InventoryClickEvent event) {
if (!(event.getWhoClicked() instanceof Player)) return; if (!(event.getWhoClicked() instanceof Player)) return;
Player player = (Player) event.getWhoClicked();
checkForInventoryMove(event); checkForInventoryMove(event);
checkForSpectatorTeleportMenu(event); checkForSpectatorTeleportMenu(event);
checkForDebugMenu(event); checkForDebugMenu(event);
checkForBlockHuntMenu(event);
} }
private void checkForInventoryMove(InventoryClickEvent event){ private void checkForInventoryMove(InventoryClickEvent event){
@ -74,4 +77,38 @@ public class InventoryHandler implements Listener {
} }
} }
private void checkForBlockHuntMenu(InventoryClickEvent event){
boolean test;
if(Main.getInstance().supports(14)){
test = event.getView().getTitle().equals("Select a Block");
} else {
test = event.getInventory().getName().equals("Select a Block");
}
if(!test) return;
event.setCancelled(true);
Material mat = blockhuntBlocks.get(event.getRawSlot());
if(mat == null) return;
Player player = (Player) event.getWhoClicked();
Main.getInstance().getDisguiser().disguise(player, mat);
player.closeInventory();
}
@EventHandler(priority = EventPriority.HIGHEST)
public void onInventoryClose(InventoryCloseEvent event){
if (!(event.getPlayer() instanceof Player)) return;
boolean test;
if(Main.getInstance().supports(14)){
test = event.getView().getTitle().equals("Select a Block");
} else {
test = event.getInventory().getName().equals("Select a Block");
}
if(!test) return;
Material mat = blockhuntBlocks.get(0);
if(mat == null) return;
Player player = (Player) event.getPlayer();
if(Main.getInstance().getDisguiser().disguised(player)) return;
Main.getInstance().getDisguiser().disguise(player, mat);
player.closeInventory();
}
} }

View file

@ -124,6 +124,14 @@ databaseName: hideandseek
# Thw world border starts at [size], and decreases 100 blocks every interval. # Thw world border starts at [size], and decreases 100 blocks every interval.
# x & z are the center location. [enabled] is whenever the border is enabled. # x & z are the center location. [enabled] is whenever the border is enabled.
# You can choose if Hiders are warned 30 seconds before the border moves. # You can choose if Hiders are warned 30 seconds before the border moves.
# You want block hunt? We have block hunt! Just enable it below, and set the
# available blocks to pick from, and you're all set! It's that easy!
# Items are displayed in the order that they are listed below.
blockhunt:
enabled: false
blocks: [CRAFTING_TABLE, GRASS_BLOCK, DIRT, BEACON, BOOKSHELF]
worldBorder: worldBorder:
x: 0 x: 0
z: 0 z: 0

View file

@ -1,6 +1,6 @@
name: KenshinsHideAndSeek name: KenshinsHideAndSeek
main: net.tylermurphy.hideAndSeek.Main main: net.tylermurphy.hideAndSeek.Main
version: 1.5.1 version: 1.6.0
author: KenshinEto author: KenshinEto
load: STARTUP load: STARTUP
api-version: 1.13 api-version: 1.13