commit
00f67f0e45
35 changed files with 1057 additions and 164 deletions
BIN
img/banner.png
Normal file
BIN
img/banner.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 84 KiB |
BIN
img/logo.png
Normal file
BIN
img/logo.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 54 KiB |
115
pom.xml
115
pom.xml
|
@ -1,73 +1,82 @@
|
|||
<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>
|
||||
<artifactId>KenshinsHideAndSeek</artifactId>
|
||||
<version>1.5.1</version>
|
||||
<version>1.6.0</version>
|
||||
<name>Hide and Seek Plugin</name>
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
|
||||
<build>
|
||||
<defaultGoal>clean install</defaultGoal>
|
||||
<sourceDirectory>src/main/java</sourceDirectory>
|
||||
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>2.3.2</version>
|
||||
<configuration>
|
||||
<source>8</source>
|
||||
<target>8</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-shade-plugin</artifactId>
|
||||
<version>3.2.4</version>
|
||||
<configuration>
|
||||
<createDependencyReducedPom>false</createDependencyReducedPom>
|
||||
<relocations>
|
||||
<relocation>
|
||||
<pattern>com.cryptomorin.xseries</pattern>
|
||||
<shadedPattern>net.tylermurphy.dependencies.xseries</shadedPattern>
|
||||
</relocation>
|
||||
</relocations>
|
||||
<artifactSet>
|
||||
<includes>
|
||||
<include>com.github.cryptomorin:XSeries</include>
|
||||
<include>org.xerial:sqlite-jdbc</include>
|
||||
<include>org.mariadb.jdbc:mariadb-java-client</include>
|
||||
<include>com.zaxxer:HikariCP</include>
|
||||
</includes>
|
||||
</artifactSet>
|
||||
<filters>
|
||||
<filter>
|
||||
<artifact>*:*</artifact>
|
||||
<excludes>
|
||||
<exclude>META-INF/*.MF</exclude>
|
||||
<exclude>META-INF/*.MD</exclude>
|
||||
<exclude>META-INF/*.SF</exclude>
|
||||
<exclude>META-INF/*.DSA</exclude>
|
||||
<exclude>META-INF/*.RSA</exclude>
|
||||
<exclude>sqlite-jdbc.properties</exclude>
|
||||
</excludes>
|
||||
</filter>
|
||||
</filters>
|
||||
<transformers>
|
||||
<transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
|
||||
<resource>META-INF/services/java.sql.Driver</resource>
|
||||
</transformer>
|
||||
</transformers>
|
||||
<minimizeJar>true</minimizeJar>
|
||||
</configuration>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>shade</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<createDependencyReducedPom>false</createDependencyReducedPom>
|
||||
<relocations>
|
||||
<relocation>
|
||||
<pattern>com.cryptomorin.xseries</pattern>
|
||||
<shadedPattern>net.tylermurphy.dependencies.xseries</shadedPattern>
|
||||
</relocation>
|
||||
<relocation>
|
||||
<pattern>com.zaxxer.hikari</pattern>
|
||||
<shadedPattern>net.tylermurphy.dependencies.hikari</shadedPattern>
|
||||
</relocation>
|
||||
<relocation>
|
||||
<pattern>org.ibex.nestedvm</pattern>
|
||||
<shadedPattern>net.tylermurphy.dependencies.nestedvm</shadedPattern>
|
||||
</relocation>
|
||||
</relocations>
|
||||
<artifactSet>
|
||||
<includes>
|
||||
<include>com.github.cryptomorin:XSeries</include>
|
||||
<include>org.xerial:sqlite-jdbc</include>
|
||||
<include>org.mariadb.jdbc:mariadb-java-client</include>
|
||||
<include>com.zaxxer:HikariCP</include>
|
||||
</includes>
|
||||
</artifactSet>
|
||||
<filters>
|
||||
<filter>
|
||||
<artifact>*:*</artifact>
|
||||
<excludes>
|
||||
<exclude>META-INF/**</exclude>
|
||||
<exclude>sqlite-jdbc.properties</exclude>
|
||||
<exclude>mariadb.properties</exclude>
|
||||
</excludes>
|
||||
</filter>
|
||||
</filters>
|
||||
<transformers>
|
||||
<transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
|
||||
<resource>META-INF/services/java.sql.Driver</resource>
|
||||
</transformer>
|
||||
</transformers>
|
||||
<minimizeJar>true</minimizeJar>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
|
||||
<plugin>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>2.3.2</version>
|
||||
<configuration>
|
||||
<source>1.8</source>
|
||||
<target>1.8</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
|
||||
</plugins>
|
||||
|
||||
</build>
|
||||
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>spigot-repo</id>
|
||||
|
@ -87,8 +96,14 @@
|
|||
<groupId>org.spigotmc</groupId>
|
||||
<artifactId>spigot-api</artifactId>
|
||||
<version>1.13-R0.1-SNAPSHOT</version>
|
||||
<type>jar</type>
|
||||
<scope>provided</scope>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>*</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
<type>jar</type>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.comphenix.protocol</groupId>
|
||||
|
|
|
@ -23,11 +23,9 @@ import net.tylermurphy.hideAndSeek.configuration.Config;
|
|||
import net.tylermurphy.hideAndSeek.configuration.Items;
|
||||
import net.tylermurphy.hideAndSeek.configuration.Localization;
|
||||
import net.tylermurphy.hideAndSeek.database.Database;
|
||||
import net.tylermurphy.hideAndSeek.game.Board;
|
||||
import net.tylermurphy.hideAndSeek.game.PlayerLoader;
|
||||
import net.tylermurphy.hideAndSeek.game.*;
|
||||
import net.tylermurphy.hideAndSeek.game.util.Status;
|
||||
import net.tylermurphy.hideAndSeek.util.CommandHandler;
|
||||
import net.tylermurphy.hideAndSeek.game.Game;
|
||||
import net.tylermurphy.hideAndSeek.game.listener.*;
|
||||
import net.tylermurphy.hideAndSeek.util.PAPIExpansion;
|
||||
import net.tylermurphy.hideAndSeek.util.TabCompleter;
|
||||
|
@ -36,9 +34,7 @@ import org.bukkit.Location;
|
|||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.plugin.PluginDescriptionFile;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.bukkit.plugin.java.JavaPluginLoader;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.io.File;
|
||||
|
@ -54,43 +50,24 @@ public class Main extends JavaPlugin implements Listener {
|
|||
private static Main instance;
|
||||
private static int version;
|
||||
|
||||
private final Database database;
|
||||
private final Board board;
|
||||
|
||||
private Database database;
|
||||
private Board board;
|
||||
private Disguiser disguiser;
|
||||
private EntityHider entityHider;
|
||||
private Game game;
|
||||
|
||||
public Main() {
|
||||
super();
|
||||
onConstructed();
|
||||
board = new Board();
|
||||
database = new Database();
|
||||
}
|
||||
|
||||
protected Main(JavaPluginLoader loader, PluginDescriptionFile description, File dataFolder, File file) {
|
||||
super(loader, description, dataFolder, file);
|
||||
onConstructed();
|
||||
board = new Board();
|
||||
database = new Database();
|
||||
}
|
||||
|
||||
private void onConstructed(){
|
||||
|
||||
instance = this;
|
||||
|
||||
Matcher matcher = Pattern.compile("MC: \\d\\.(\\d+)").matcher(Bukkit.getVersion());
|
||||
if (matcher.find()) {
|
||||
version = Integer.parseInt(matcher.group(1));
|
||||
} else {
|
||||
throw new IllegalArgumentException("Failed to parse server version from: " + Bukkit.getVersion());
|
||||
}
|
||||
public void onEnable() {
|
||||
Main.instance = this;
|
||||
this.updateVersion();
|
||||
|
||||
Config.loadConfig();
|
||||
Localization.loadLocalization();
|
||||
Items.loadItems();
|
||||
}
|
||||
|
||||
public void onEnable() {
|
||||
|
||||
this.board = new Board();
|
||||
this.database = new Database();
|
||||
this.disguiser = new Disguiser();
|
||||
this.entityHider = new EntityHider(this, EntityHider.Policy.BLACKLIST);
|
||||
this.registerListeners();
|
||||
|
||||
CommandHandler.registerCommands();
|
||||
|
@ -118,17 +95,20 @@ public class Main extends JavaPlugin implements Listener {
|
|||
|
||||
Bukkit.getServer().getMessenger().unregisterOutgoingPluginChannel(this);
|
||||
board.cleanup();
|
||||
disguiser.cleanUp();
|
||||
}
|
||||
|
||||
private void onTick() {
|
||||
if(game.getStatus() == Status.ENDED) game = new Game(board);
|
||||
game.onTick();
|
||||
disguiser.check();
|
||||
}
|
||||
|
||||
private void registerListeners() {
|
||||
getServer().getPluginManager().registerEvents(new BlockedCommandHandler(), this);
|
||||
getServer().getPluginManager().registerEvents(new ChatHandler(), this);
|
||||
getServer().getPluginManager().registerEvents(new DamageHandler(), this);
|
||||
getServer().getPluginManager().registerEvents(new DisguiseHandler(), this);
|
||||
getServer().getPluginManager().registerEvents(new InteractHandler(), this);
|
||||
getServer().getPluginManager().registerEvents(new InventoryHandler(), this);
|
||||
getServer().getPluginManager().registerEvents(new JoinLeaveHandler(), this);
|
||||
|
@ -136,6 +116,15 @@ public class Main extends JavaPlugin implements Listener {
|
|||
getServer().getPluginManager().registerEvents(new PlayerHandler(), this);
|
||||
getServer().getPluginManager().registerEvents(new RespawnHandler(), this);
|
||||
}
|
||||
|
||||
private void updateVersion(){
|
||||
Matcher matcher = Pattern.compile("MC: \\d\\.(\\d+)").matcher(Bukkit.getVersion());
|
||||
if (matcher.find()) {
|
||||
version = Integer.parseInt(matcher.group(1));
|
||||
} else {
|
||||
throw new IllegalArgumentException("Failed to parse server version from: " + Bukkit.getVersion());
|
||||
}
|
||||
}
|
||||
|
||||
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command cmd, @NotNull String label, String[] args) {
|
||||
return CommandHandler.handleCommand(sender, args);
|
||||
|
@ -165,6 +154,10 @@ public class Main extends JavaPlugin implements Listener {
|
|||
return game;
|
||||
}
|
||||
|
||||
public Disguiser getDisguiser() { return disguiser; }
|
||||
|
||||
public EntityHider getEntityHider() { return entityHider; }
|
||||
|
||||
public boolean supports(int v){
|
||||
return version >= v;
|
||||
}
|
||||
|
|
|
@ -26,7 +26,7 @@ public class About implements ICommand {
|
|||
|
||||
public void execute(Player sender, String[] args) {
|
||||
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("%sHelp Command: %s/hs %shelp", ChatColor.GRAY, ChatColor.AQUA, ChatColor.WHITE)
|
||||
);
|
||||
|
|
|
@ -31,7 +31,7 @@ public class Debug implements ICommand {
|
|||
}
|
||||
|
||||
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 -> {
|
||||
if(mapSaveEnabled) {
|
||||
if(Bukkit.getWorld(Main.getInstance().getGame().getGameWorld()) == null) Main.getInstance().getGame().getWorldLoader().loadMap();
|
||||
|
@ -73,12 +73,10 @@ public class Debug implements ICommand {
|
|||
}
|
||||
player.teleport(new Location(Bukkit.getWorld(Main.getInstance().getGame().getGameWorld()), spawnPosition.getX(), spawnPosition.getY(), spawnPosition.getZ()));
|
||||
}));
|
||||
debugMenu.setItem(7, createOption(7, Material.ENDER_PEARL, "&d&lTeleport: &fLobby", 2, player -> {
|
||||
player.teleport(new Location(Bukkit.getWorld(lobbyWorld), lobbyPosition.getX(), lobbyPosition.getY(), lobbyPosition.getZ()));
|
||||
}));
|
||||
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()));
|
||||
}));
|
||||
debugMenu.setItem(7, createOption(7, Material.ENDER_PEARL, "&d&lTeleport: &fLobby", 2, player -> player.teleport(new Location(Bukkit.getWorld(lobbyWorld), lobbyPosition.getX(), lobbyPosition.getY(), lobbyPosition.getZ()))));
|
||||
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()))));
|
||||
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){
|
||||
|
|
|
@ -68,10 +68,9 @@ public class SetBorder implements ICommand {
|
|||
return;
|
||||
}
|
||||
Vector vec = new Vector();
|
||||
Player player = (Player) sender;
|
||||
vec.setX(player.getLocation().getBlockX());
|
||||
vec.setX(sender.getLocation().getBlockX());
|
||||
vec.setY(0);
|
||||
vec.setZ(player.getLocation().getBlockZ());
|
||||
vec.setZ(sender.getLocation().getBlockZ());
|
||||
if (spawnPosition.distance(vec) > 100) {
|
||||
sender.sendMessage(errorPrefix + message("WORLDBORDER_POSITION"));
|
||||
return;
|
||||
|
|
|
@ -37,12 +37,11 @@ public class SetBounds implements ICommand {
|
|||
sender.sendMessage(errorPrefix + message("ERROR_GAME_SPAWN"));
|
||||
return;
|
||||
}
|
||||
Player player = (Player) sender;
|
||||
if (!player.getWorld().getName().equals(spawnWorld)) {
|
||||
if (!sender.getWorld().getName().equals(spawnWorld)) {
|
||||
sender.sendMessage(errorPrefix + message("BOUNDS_WRONG_WORLD"));
|
||||
return;
|
||||
}
|
||||
if (player.getLocation().getBlockX() == 0 || player.getLocation().getBlockZ() == 0) {
|
||||
if (sender.getLocation().getBlockX() == 0 || sender.getLocation().getBlockZ() == 0) {
|
||||
sender.sendMessage(errorPrefix + message("NOT_AT_ZERO"));
|
||||
return;
|
||||
}
|
||||
|
@ -51,32 +50,32 @@ public class SetBounds implements ICommand {
|
|||
saveMinX = 0; saveMinZ= 0; saveMaxX = 0; saveMaxZ = 0;
|
||||
}
|
||||
if (saveMaxX == 0) {
|
||||
addToConfig("bounds.max.x", player.getLocation().getBlockX());
|
||||
saveMaxX = player.getLocation().getBlockX();
|
||||
} else if (saveMaxX < player.getLocation().getBlockX()) {
|
||||
addToConfig("bounds.max.x", sender.getLocation().getBlockX());
|
||||
saveMaxX = sender.getLocation().getBlockX();
|
||||
} else if (saveMaxX < sender.getLocation().getBlockX()) {
|
||||
first = false;
|
||||
addToConfig("bounds.max.x", player.getLocation().getBlockX());
|
||||
addToConfig("bounds.max.x", sender.getLocation().getBlockX());
|
||||
addToConfig("bounds.min.x", saveMaxX);
|
||||
saveMinX = saveMaxX;
|
||||
saveMaxX = player.getLocation().getBlockX();
|
||||
saveMaxX = sender.getLocation().getBlockX();
|
||||
} else {
|
||||
first = false;
|
||||
addToConfig("bounds.min.x", player.getLocation().getBlockX());
|
||||
saveMinX = player.getLocation().getBlockX();
|
||||
addToConfig("bounds.min.x", sender.getLocation().getBlockX());
|
||||
saveMinX = sender.getLocation().getBlockX();
|
||||
}
|
||||
if (saveMaxZ == 0) {
|
||||
addToConfig("bounds.max.z", player.getLocation().getBlockZ());
|
||||
saveMaxZ = player.getLocation().getBlockZ();
|
||||
} else if (saveMaxZ < player.getLocation().getBlockZ()) {
|
||||
addToConfig("bounds.max.z", sender.getLocation().getBlockZ());
|
||||
saveMaxZ = sender.getLocation().getBlockZ();
|
||||
} else if (saveMaxZ < sender.getLocation().getBlockZ()) {
|
||||
first = false;
|
||||
addToConfig("bounds.max.z", player.getLocation().getBlockZ());
|
||||
addToConfig("bounds.max.z", sender.getLocation().getBlockZ());
|
||||
addToConfig("bounds.min.z", saveMaxZ);
|
||||
saveMinZ = saveMaxZ;
|
||||
saveMaxZ = player.getLocation().getBlockZ();
|
||||
saveMaxZ = sender.getLocation().getBlockZ();
|
||||
} else {
|
||||
first = false;
|
||||
addToConfig("bounds.min.z", player.getLocation().getBlockZ());
|
||||
saveMinZ = player.getLocation().getBlockZ();
|
||||
addToConfig("bounds.min.z", sender.getLocation().getBlockZ());
|
||||
saveMinZ = sender.getLocation().getBlockZ();
|
||||
}
|
||||
sender.sendMessage(messagePrefix + message("BOUNDS").addAmount(first ? 1 : 2));
|
||||
saveConfig();
|
||||
|
|
|
@ -21,9 +21,7 @@ package net.tylermurphy.hideAndSeek.command;
|
|||
|
||||
import net.tylermurphy.hideAndSeek.Main;
|
||||
import net.tylermurphy.hideAndSeek.database.util.PlayerInfo;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.List;
|
||||
|
|
|
@ -90,7 +90,8 @@ public class Config {
|
|||
leaveOnEnd,
|
||||
mapSaveEnabled,
|
||||
allowNaturalCauses,
|
||||
saveInventory;
|
||||
saveInventory,
|
||||
blockhuntEnabled;
|
||||
|
||||
public static int
|
||||
minPlayers,
|
||||
|
@ -126,6 +127,9 @@ public class Config {
|
|||
blockedCommands,
|
||||
blockedInteracts;
|
||||
|
||||
public static List<Material>
|
||||
blockhuntBlocks;
|
||||
|
||||
public static String
|
||||
LOBBY_TITLE,
|
||||
GAME_TITLE,
|
||||
|
@ -288,6 +292,18 @@ public class Config {
|
|||
}
|
||||
bungeeLeave = config.getString("leaveType") == null || config.getString("leaveType").equalsIgnoreCase("proxy");
|
||||
leaveServer = config.getString("leaveServer");
|
||||
blockhuntEnabled = config.getBoolean("blockhunt.enabled") && Main.getInstance().supports(9);
|
||||
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
|
||||
LOBBY_TITLE = leaderboard.getString("lobby.title");
|
||||
|
|
|
@ -104,6 +104,7 @@ public class Database {
|
|||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("UnstableApiUsage")
|
||||
protected UUID decodeUUID(byte[] bytes) {
|
||||
InputStream is = new ByteArrayInputStream(bytes);
|
||||
ByteBuffer buffer = ByteBuffer.allocate(16);
|
||||
|
|
|
@ -200,8 +200,7 @@ public class GameDataTable {
|
|||
}
|
||||
}
|
||||
|
||||
protected boolean updateInfo(@NotNull byte[] uuid, int hider_wins, int seeker_wins, int hider_games, int seeker_games, int hider_kills, int seeker_kills, int hider_deaths, int seeker_deaths){
|
||||
boolean success;
|
||||
protected void updateInfo(byte[] uuid, int hider_wins, int seeker_wins, int hider_games, int seeker_games, int hider_kills, int seeker_kills, int hider_deaths, int seeker_deaths){
|
||||
String sql = "INSERT OR REPLACE INTO hs_data (uuid, hider_wins, seeker_wins, hider_games, seeker_games, hider_kills, seeker_kills, hider_deaths, seeker_deaths) VALUES (?,?,?,?,?,?,?,?,?)";
|
||||
try(Connection connection = database.connect(); PreparedStatement statement = connection.prepareStatement(sql)) {
|
||||
statement.setBytes(1, uuid);
|
||||
|
@ -214,16 +213,12 @@ public class GameDataTable {
|
|||
statement.setInt(8, hider_deaths);
|
||||
statement.setInt(9, seeker_deaths);
|
||||
statement.execute();
|
||||
statement.close();
|
||||
success = true;
|
||||
} catch (SQLException e) {
|
||||
Main.getInstance().getLogger().severe("SQL Error: " + e.getMessage());
|
||||
e.printStackTrace();
|
||||
success = false;
|
||||
} finally {
|
||||
CACHE.remove(database.decodeUUID(uuid));
|
||||
}
|
||||
return success;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -58,19 +58,16 @@ public class InventoryTable {
|
|||
return null;
|
||||
}
|
||||
|
||||
public boolean saveInventory(@NotNull UUID uuid, @NotNull ItemStack[] itemArray) {
|
||||
public void saveInventory(@NotNull UUID uuid, @NotNull ItemStack[] itemArray) {
|
||||
String sql = "INSERT OR REPLACE INTO hs_inventory (uuid, inventory) VALUES (?,?)";
|
||||
String data = itemStackArrayToBase64(itemArray);
|
||||
try(Connection connection = database.connect(); PreparedStatement statement = connection.prepareStatement(sql)) {
|
||||
statement.setBytes(1, database.encodeUUID(uuid));
|
||||
statement.setString(2, data);
|
||||
statement.execute();
|
||||
statement.close();
|
||||
return true;
|
||||
} catch (SQLException e) {
|
||||
Main.getInstance().getLogger().severe("SQL Error: " + e.getMessage());
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -19,8 +19,6 @@
|
|||
|
||||
package net.tylermurphy.hideAndSeek.database;
|
||||
|
||||
import net.tylermurphy.hideAndSeek.Main;
|
||||
import net.tylermurphy.hideAndSeek.database.Database;
|
||||
import net.tylermurphy.hideAndSeek.database.util.LegacyPlayerInfo;
|
||||
|
||||
import java.sql.Connection;
|
||||
|
@ -63,7 +61,6 @@ public class LegacyTable {
|
|||
while(resultSet.next()){
|
||||
legacyPlayerInfoList.add(new LegacyPlayerInfo(
|
||||
resultSet.getBytes("uuid"),
|
||||
resultSet.getInt("wins"),
|
||||
resultSet.getInt("hider_wins"),
|
||||
resultSet.getInt("seeker_wins"),
|
||||
resultSet.getInt("games_played")
|
||||
|
|
|
@ -25,7 +25,6 @@ import org.bukkit.OfflinePlayer;
|
|||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.lang.management.BufferPoolMXBean;
|
||||
import java.sql.*;
|
||||
import java.util.UUID;
|
||||
|
||||
|
@ -66,13 +65,14 @@ public class NameDataTable {
|
|||
e.printStackTrace();
|
||||
}
|
||||
OfflinePlayer retry = Bukkit.getOfflinePlayer(uuid);
|
||||
if(retry != null){
|
||||
if(retry != null && retry.getName() != null){
|
||||
this.update(uuid, retry.getName());
|
||||
return retry.getName();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Nullable
|
||||
public UUID getUUID(@NotNull String name) {
|
||||
String sql = "SELECT * FROM hs_names WHERE name = ?;";
|
||||
|
|
|
@ -19,19 +19,15 @@
|
|||
|
||||
package net.tylermurphy.hideAndSeek.database.util;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public class LegacyPlayerInfo {
|
||||
|
||||
private final byte[] uniqueId;
|
||||
private final int totalWins;
|
||||
private final int hiderWins;
|
||||
private final int seekerWins;
|
||||
private final int gamesPlayed;
|
||||
|
||||
public LegacyPlayerInfo(byte[] uniqueId, int totalWins, int hiderWins, int seekerWins, int gamesPlayed) {
|
||||
public LegacyPlayerInfo(byte[] uniqueId, int hiderWins, int seekerWins, int gamesPlayed) {
|
||||
this.uniqueId = uniqueId;
|
||||
this.totalWins = totalWins;
|
||||
this.hiderWins = hiderWins;
|
||||
this.seekerWins = seekerWins;
|
||||
this.gamesPlayed = gamesPlayed;
|
||||
|
@ -41,8 +37,6 @@ public class LegacyPlayerInfo {
|
|||
return uniqueId;
|
||||
}
|
||||
|
||||
public int getTotalWins() { return totalWins; }
|
||||
|
||||
public int getHiderWins() {
|
||||
return hiderWins;
|
||||
}
|
||||
|
|
|
@ -35,6 +35,7 @@ import java.util.stream.Collectors;
|
|||
import static net.tylermurphy.hideAndSeek.configuration.Config.*;
|
||||
import static net.tylermurphy.hideAndSeek.configuration.Localization.message;
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public class Board {
|
||||
|
||||
private final List<String> Hider = new ArrayList<>(), Seeker = new ArrayList<>(), Spectator = new ArrayList<>();
|
||||
|
@ -103,6 +104,9 @@ public class Board {
|
|||
}
|
||||
|
||||
public void addHider(Player player) {
|
||||
if(!Main.getInstance().supports(9)){
|
||||
player.spigot().setCollidesWithEntities(false);
|
||||
}
|
||||
Hider.add(player.getUniqueId().toString());
|
||||
Seeker.remove(player.getUniqueId().toString());
|
||||
Spectator.remove(player.getUniqueId().toString());
|
||||
|
@ -110,6 +114,9 @@ public class Board {
|
|||
}
|
||||
|
||||
public void addSeeker(Player player) {
|
||||
if(!Main.getInstance().supports(9)){
|
||||
player.spigot().setCollidesWithEntities(false);
|
||||
}
|
||||
Hider.remove(player.getUniqueId().toString());
|
||||
Seeker.add(player.getUniqueId().toString());
|
||||
Spectator.remove(player.getUniqueId().toString());
|
||||
|
@ -117,6 +124,9 @@ public class Board {
|
|||
}
|
||||
|
||||
public void addSpectator(Player player) {
|
||||
if(!Main.getInstance().supports(9)){
|
||||
player.spigot().setCollidesWithEntities(false);
|
||||
}
|
||||
Hider.remove(player.getUniqueId().toString());
|
||||
Seeker.remove(player.getUniqueId().toString());
|
||||
Spectator.add(player.getUniqueId().toString());
|
||||
|
@ -124,6 +134,9 @@ public class Board {
|
|||
}
|
||||
|
||||
public void remove(Player player) {
|
||||
if(!Main.getInstance().supports(9)){
|
||||
player.spigot().setCollidesWithEntities(true);
|
||||
}
|
||||
Hider.remove(player.getUniqueId().toString());
|
||||
Seeker.remove(player.getUniqueId().toString());
|
||||
Spectator.remove(player.getUniqueId().toString());
|
||||
|
@ -351,6 +364,7 @@ public class Board {
|
|||
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
class CustomBoard {
|
||||
|
||||
private final Scoreboard board;
|
||||
|
@ -401,6 +415,8 @@ class CustomBoard {
|
|||
hiderTeam.setOption(Team.Option.NAME_TAG_VISIBILITY, Team.OptionStatus.NEVER);
|
||||
seekerTeam.setOption(Team.Option.NAME_TAG_VISIBILITY, Team.OptionStatus.NEVER);
|
||||
}
|
||||
hiderTeam.setOption(Team.Option.COLLISION_RULE, Team.OptionStatus.NEVER);
|
||||
seekerTeam.setOption(Team.Option.COLLISION_RULE, Team.OptionStatus.NEVER);
|
||||
} else {
|
||||
if (nameTagsVisible) {
|
||||
hiderTeam.setNameTagVisibility(NameTagVisibility.HIDE_FOR_OTHER_TEAMS);
|
||||
|
|
|
@ -0,0 +1,72 @@
|
|||
package net.tylermurphy.hideAndSeek.game;
|
||||
|
||||
import static net.tylermurphy.hideAndSeek.configuration.Config.*;
|
||||
|
||||
import net.tylermurphy.hideAndSeek.game.util.Disguise;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class Disguiser {
|
||||
|
||||
private final Map<Player, Disguise> disguises;
|
||||
|
||||
public Disguiser(){
|
||||
this.disguises = new HashMap<>();
|
||||
}
|
||||
|
||||
public Disguise getDisguise(Player player){
|
||||
return disguises.get(player);
|
||||
}
|
||||
|
||||
public boolean disguised(Player player) { return disguises.containsKey(player); }
|
||||
|
||||
@Nullable
|
||||
public Disguise getByEntityID(int ID){
|
||||
return disguises.values().stream().filter(disguise -> disguise.getEntityID() == ID).findFirst().orElse(null);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public Disguise getByHitBoxID(int ID){
|
||||
return disguises.values().stream().filter(disguise -> disguise.getHitBoxID() == ID).findFirst().orElse(null);
|
||||
}
|
||||
|
||||
public void check(){
|
||||
for(Map.Entry<Player, Disguise> set : disguises.entrySet()){
|
||||
Disguise disguise = set.getValue();
|
||||
Player player = set.getKey();
|
||||
if(!player.isOnline()) {
|
||||
disguise.remove();
|
||||
disguises.remove(player);
|
||||
} else {
|
||||
disguise.update();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void disguise(Player player, Material material){
|
||||
if(!blockhuntEnabled){
|
||||
player.sendMessage(errorPrefix + "Please enable blockhunt in config.yml to enable disguises. Blockhunt does not work on 1.8");
|
||||
return;
|
||||
}
|
||||
if(disguises.containsKey(player)){
|
||||
disguises.get(player).remove();
|
||||
}
|
||||
Disguise disguise = new Disguise(player, material);
|
||||
disguises.put(player, disguise);
|
||||
}
|
||||
|
||||
public void reveal(Player player){
|
||||
if(disguises.containsKey(player))
|
||||
disguises.get(player).remove();
|
||||
disguises.remove(player);
|
||||
}
|
||||
|
||||
public void cleanUp() {
|
||||
disguises.values().forEach(Disguise::remove);
|
||||
}
|
||||
|
||||
}
|
286
src/main/java/net/tylermurphy/hideAndSeek/game/EntityHider.java
Normal file
286
src/main/java/net/tylermurphy/hideAndSeek/game/EntityHider.java
Normal file
|
@ -0,0 +1,286 @@
|
|||
package net.tylermurphy.hideAndSeek.game;
|
||||
|
||||
import static com.comphenix.protocol.PacketType.Play.Server.*;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.entity.EntityDeathEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
import org.bukkit.event.world.ChunkUnloadEvent;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
import com.comphenix.protocol.PacketType;
|
||||
import com.comphenix.protocol.ProtocolLibrary;
|
||||
import com.comphenix.protocol.ProtocolManager;
|
||||
import com.comphenix.protocol.events.PacketAdapter;
|
||||
import com.comphenix.protocol.events.PacketContainer;
|
||||
import com.comphenix.protocol.events.PacketEvent;
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.google.common.collect.HashBasedTable;
|
||||
import com.google.common.collect.Table;
|
||||
|
||||
public class EntityHider implements Listener {
|
||||
protected Table<Integer, Integer, Boolean> observerEntityMap = HashBasedTable.create();
|
||||
|
||||
private static final PacketType[] ENTITY_PACKETS = {
|
||||
ENTITY_EQUIPMENT, ANIMATION, NAMED_ENTITY_SPAWN,
|
||||
COLLECT, SPAWN_ENTITY, SPAWN_ENTITY_LIVING, SPAWN_ENTITY_PAINTING, SPAWN_ENTITY_EXPERIENCE_ORB,
|
||||
ENTITY_VELOCITY, REL_ENTITY_MOVE, ENTITY_LOOK,
|
||||
ENTITY_TELEPORT, ENTITY_HEAD_ROTATION, ENTITY_STATUS, ATTACH_ENTITY, ENTITY_METADATA,
|
||||
ENTITY_EFFECT, REMOVE_ENTITY_EFFECT, BLOCK_BREAK_ANIMATION
|
||||
};
|
||||
|
||||
public enum Policy {
|
||||
WHITELIST,
|
||||
BLACKLIST,
|
||||
}
|
||||
|
||||
private ProtocolManager manager;
|
||||
|
||||
private final Listener bukkitListener;
|
||||
private final PacketAdapter protocolListener;
|
||||
|
||||
protected final Policy policy;
|
||||
|
||||
public EntityHider(Plugin plugin, Policy policy) {
|
||||
Preconditions.checkNotNull(plugin, "plugin cannot be NULL.");
|
||||
|
||||
// Save policy
|
||||
this.policy = policy;
|
||||
this.manager = ProtocolLibrary.getProtocolManager();
|
||||
|
||||
// Register events and packet listener
|
||||
plugin.getServer().getPluginManager().registerEvents(
|
||||
bukkitListener = constructBukkit(), plugin);
|
||||
manager.addPacketListener(
|
||||
protocolListener = constructProtocol(plugin));
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the visibility status of a given entity for a particular observer.
|
||||
* @param observer - the observer player.
|
||||
* @param entityID - ID of the entity that will be hidden or made visible.
|
||||
* @param visible - TRUE if the entity should be made visible, FALSE if not.
|
||||
* @return TRUE if the entity was visible before this method call, FALSE otherwise.
|
||||
*/
|
||||
protected boolean setVisibility(Player observer, int entityID, boolean visible) {
|
||||
switch (policy) {
|
||||
case BLACKLIST:
|
||||
// Non-membership means they are visible
|
||||
return !setMembership(observer, entityID, !visible);
|
||||
case WHITELIST:
|
||||
return setMembership(observer, entityID, visible);
|
||||
default :
|
||||
throw new IllegalArgumentException("Unknown policy: " + policy);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add or remove the given entity and observer entry from the table.
|
||||
* @param observer - the player observer.
|
||||
* @param entityID - ID of the entity.
|
||||
* @param member - TRUE if they should be present in the table, FALSE otherwise.
|
||||
* @return TRUE if they already were present, FALSE otherwise.
|
||||
*/
|
||||
protected boolean setMembership(Player observer, int entityID, boolean member) {
|
||||
if (member) {
|
||||
return observerEntityMap.put(observer.getEntityId(), entityID, true) != null;
|
||||
} else {
|
||||
return observerEntityMap.remove(observer.getEntityId(), entityID) != null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if the given entity and observer is present in the table.
|
||||
* @param observer - the player observer.
|
||||
* @param entityID - ID of the entity.
|
||||
* @return TRUE if they are present, FALSE otherwise.
|
||||
*/
|
||||
protected boolean getMembership(Player observer, int entityID) {
|
||||
return observerEntityMap.contains(observer.getEntityId(), entityID);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if a given entity is visible for a particular observer.
|
||||
* @param observer - the observer player.
|
||||
* @param entityID - ID of the entity that we are testing for visibility.
|
||||
* @return TRUE if the entity is visible, FALSE otherwise.
|
||||
*/
|
||||
protected boolean isVisible(Player observer, int entityID) {
|
||||
// If we are using a whitelist, presence means visibility - if not, the opposite is the case
|
||||
boolean presence = getMembership(observer, entityID);
|
||||
|
||||
return (policy == Policy.WHITELIST) == presence;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the given entity from the underlying map.
|
||||
* @param entity - the entity to remove.
|
||||
*/
|
||||
protected void removeEntity(Entity entity) {
|
||||
int entityID = entity.getEntityId();
|
||||
|
||||
for (Map<Integer, Boolean> maps : observerEntityMap.rowMap().values()) {
|
||||
maps.remove(entityID);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Invoked when a player logs out.
|
||||
* @param player - the player that jused logged out.
|
||||
*/
|
||||
protected void removePlayer(Player player) {
|
||||
// Cleanup
|
||||
observerEntityMap.rowMap().remove(player.getEntityId());
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct the Bukkit event listener.
|
||||
* @return Our listener.
|
||||
*/
|
||||
private Listener constructBukkit() {
|
||||
return new Listener() {
|
||||
@EventHandler
|
||||
public void onEntityDeath(EntityDeathEvent e) {
|
||||
removeEntity(e.getEntity());
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onChunkUnload(ChunkUnloadEvent e) {
|
||||
for (Entity entity : e.getChunk().getEntities()) {
|
||||
removeEntity(entity);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerQuit(PlayerQuitEvent e) {
|
||||
removePlayer(e.getPlayer());
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct the packet listener that will be used to intercept every entity-related packet.
|
||||
* @param plugin - the parent plugin.
|
||||
* @return The packet listener.
|
||||
*/
|
||||
private PacketAdapter constructProtocol(Plugin plugin) {
|
||||
return new PacketAdapter(plugin, ENTITY_PACKETS) {
|
||||
@Override
|
||||
public void onPacketSending(PacketEvent event) {
|
||||
int entityID = event.getPacket().getIntegers().read(0);
|
||||
|
||||
// See if this packet should be cancelled
|
||||
if (!isVisible(event.getPlayer(), entityID)) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Toggle the visibility status of an entity for a player.
|
||||
* <p>
|
||||
* If the entity is visible, it will be hidden. If it is hidden, it will become visible.
|
||||
* @param observer - the player observer.
|
||||
* @param entity - the entity to toggle.
|
||||
* @return TRUE if the entity was visible before, FALSE otherwise.
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
public final boolean toggleEntity(Player observer, Entity entity) {
|
||||
if (isVisible(observer, entity.getEntityId())) {
|
||||
return hideEntity(observer, entity);
|
||||
} else {
|
||||
return !showEntity(observer, entity);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Allow the observer to see an entity that was previously hidden.
|
||||
* @param observer - the observer.
|
||||
* @param entity - the entity to show.
|
||||
* @return TRUE if the entity was hidden before, FALSE otherwise.
|
||||
*/
|
||||
public final boolean showEntity(Player observer, Entity entity) {
|
||||
validate(observer, entity);
|
||||
boolean hiddenBefore = !setVisibility(observer, entity.getEntityId(), true);
|
||||
|
||||
// Resend packets
|
||||
if (manager != null && hiddenBefore) {
|
||||
manager.updateEntity(entity, Collections.singletonList(observer));
|
||||
}
|
||||
return hiddenBefore;
|
||||
}
|
||||
|
||||
/**
|
||||
* Prevent the observer from seeing a given entity.
|
||||
* @param observer - the player observer.
|
||||
* @param entity - the entity to hide.
|
||||
* @return TRUE if the entity was previously visible, FALSE otherwise.
|
||||
*/
|
||||
public final boolean hideEntity(Player observer, Entity entity) {
|
||||
validate(observer, entity);
|
||||
boolean visibleBefore = setVisibility(observer, entity.getEntityId(), false);
|
||||
|
||||
if (visibleBefore) {
|
||||
PacketContainer destroyEntity = new PacketContainer(ENTITY_DESTROY);
|
||||
try {
|
||||
destroyEntity.getIntegerArrays().write(0, new int[]{entity.getEntityId()});
|
||||
} catch (Exception e){ return false; }
|
||||
// Make the entity disappear
|
||||
try {
|
||||
manager.sendServerPacket(observer, destroyEntity);
|
||||
} catch (InvocationTargetException e) {
|
||||
throw new RuntimeException("Cannot send server packet.", e);
|
||||
}
|
||||
}
|
||||
return visibleBefore;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if the given entity has been hidden from an observer.
|
||||
* <p>
|
||||
* Note that the entity may very well be occluded or out of range from the perspective
|
||||
* of the observer. This method simply checks if an entity has been completely hidden
|
||||
* for that observer.
|
||||
* @param observer - the observer.
|
||||
* @param entity - the entity that may be hidden.
|
||||
* @return TRUE if the player may see the entity, FALSE if the entity has been hidden.
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
public final boolean canSee(Player observer, Entity entity) {
|
||||
validate(observer, entity);
|
||||
|
||||
return isVisible(observer, entity.getEntityId());
|
||||
}
|
||||
|
||||
private void validate(Player observer, Entity entity) {
|
||||
Preconditions.checkNotNull(observer, "observer cannot be NULL.");
|
||||
Preconditions.checkNotNull(entity, "entity cannot be NULL.");
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the current visibility policy.
|
||||
* @return The current visibility policy.
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
public Policy getPolicy() {
|
||||
return policy;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public void close() {
|
||||
if (manager != null) {
|
||||
HandlerList.unregisterAll(bukkitListener);
|
||||
manager.removePacketListener(protocolListener);
|
||||
manager = null;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -107,7 +107,8 @@ public class Game {
|
|||
public void start() {
|
||||
try {
|
||||
Optional<Player> rand = board.getPlayers().stream().skip(new Random().nextInt(board.size())).findFirst();
|
||||
String seekerName = rand.get().getName();
|
||||
Player picked = rand.orElse(board.getPlayers().get(0));
|
||||
String seekerName = picked.getName();
|
||||
Player temp = Bukkit.getPlayer(seekerName);
|
||||
Player seeker = board.getPlayer(temp.getUniqueId());
|
||||
start(seeker);
|
||||
|
@ -210,6 +211,7 @@ public class Game {
|
|||
handleBungeeLeave(player);
|
||||
}
|
||||
|
||||
@SuppressWarnings("UnstableApiUsage")
|
||||
private void handleBungeeLeave(Player player) {
|
||||
if (bungeeLeave) {
|
||||
ByteArrayDataOutput out = ByteStreams.newDataOutput();
|
||||
|
|
|
@ -19,7 +19,6 @@
|
|||
|
||||
package net.tylermurphy.hideAndSeek.game;
|
||||
|
||||
import com.cryptomorin.xseries.XItemStack;
|
||||
import com.cryptomorin.xseries.messages.Titles;
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
import net.tylermurphy.hideAndSeek.Main;
|
||||
|
@ -30,6 +29,7 @@ import org.bukkit.Location;
|
|||
import org.bukkit.attribute.Attribute;
|
||||
import org.bukkit.attribute.AttributeInstance;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.potion.PotionEffect;
|
||||
import org.bukkit.potion.PotionEffectType;
|
||||
|
@ -38,6 +38,7 @@ import static net.tylermurphy.hideAndSeek.configuration.Config.*;
|
|||
import static net.tylermurphy.hideAndSeek.configuration.Config.lobbyPosition;
|
||||
import static net.tylermurphy.hideAndSeek.configuration.Localization.message;
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public class PlayerLoader {
|
||||
|
||||
public static void loadHider(Player player, String gameWorld){
|
||||
|
@ -45,6 +46,9 @@ public class PlayerLoader {
|
|||
loadPlayer(player);
|
||||
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());
|
||||
if(blockhuntEnabled){
|
||||
openBlockHuntPicker(player);
|
||||
}
|
||||
}
|
||||
|
||||
public static void loadSeeker(Player player, String gameWorld){
|
||||
|
@ -64,9 +68,7 @@ public class PlayerLoader {
|
|||
player.setFallDistance(0.0F);
|
||||
player.getInventory().setItem(flightToggleItemPosition, flightToggleItem);
|
||||
player.getInventory().setItem(teleportItemPosition, teleportItem);
|
||||
Main.getInstance().getBoard().getPlayers().forEach(otherPlayer -> {
|
||||
otherPlayer.hidePlayer(player);
|
||||
});
|
||||
Main.getInstance().getBoard().getPlayers().forEach(otherPlayer -> otherPlayer.hidePlayer(player));
|
||||
Titles.sendTitle(player, 10, 70, 20, ChatColor.GRAY + "" + ChatColor.BOLD + "SPECTATING", ChatColor.WHITE + message("SPECTATOR_SUBTITLE").toString());
|
||||
}
|
||||
|
||||
|
@ -94,6 +96,7 @@ public class PlayerLoader {
|
|||
public static void unloadPlayer(Player player){
|
||||
player.setGameMode(GameMode.ADVENTURE);
|
||||
player.getInventory().clear();
|
||||
Main.getInstance().getDisguiser().reveal(player);
|
||||
for(PotionEffect effect : player.getActivePotionEffects()) {
|
||||
player.removePotionEffect(effect.getType());
|
||||
}
|
||||
|
@ -130,6 +133,8 @@ public class PlayerLoader {
|
|||
player.setGameMode(GameMode.ADVENTURE);
|
||||
player.getInventory().clear();
|
||||
for(PotionEffect effect : player.getActivePotionEffects()) {
|
||||
Main.getInstance().getLogger().severe(player.getName() + " " + effect.getType());
|
||||
if(effect.getType().getName().equals("INVISIBILITY") && Main.getInstance().getDisguiser().disguised(player)) continue;
|
||||
player.removePotionEffect(effect.getType());
|
||||
}
|
||||
player.setFoodLevel(20);
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -15,6 +15,7 @@ import org.bukkit.event.EventPriority;
|
|||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||
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.spawnPosition;
|
||||
|
@ -24,10 +25,8 @@ public class DamageHandler implements Listener {
|
|||
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
public void onEntityDamage(EntityDamageEvent event) {
|
||||
|
||||
Board board = Main.getInstance().getBoard();
|
||||
Game game = Main.getInstance().getGame();
|
||||
|
||||
// If you are not a player, get out of here
|
||||
if (!(event.getEntity() instanceof Player)) return;
|
||||
// Define variables
|
||||
|
@ -45,6 +44,7 @@ public class DamageHandler implements Listener {
|
|||
}
|
||||
// Makes sure that if there was an attacking player, that the event is allowed for the game
|
||||
if (attacker != null) {
|
||||
System.out.println(event.getFinalDamage() + " " + player.getDisplayName() + " " + attacker.getDisplayName());
|
||||
// Cancel if one player is in the game but other isn't
|
||||
if ((board.contains(player) && !board.contains(attacker)) || (!board.contains(player) && board.contains(attacker))) {
|
||||
event.setCancelled(true);
|
||||
|
@ -94,6 +94,8 @@ public class DamageHandler implements Listener {
|
|||
} else {
|
||||
XSound.ENTITY_PLAYER_HURT.play(player, 1, 1);
|
||||
}
|
||||
// Reveal player if they are disguised
|
||||
Main.getInstance().getDisguiser().reveal(player);
|
||||
// Teleport player to seeker spawn
|
||||
player.teleport(new Location(Bukkit.getWorld(game.getGameWorld()), spawnPosition.getX(), spawnPosition.getY(), spawnPosition.getZ()));
|
||||
// Add leaderboard stats
|
||||
|
@ -115,4 +117,9 @@ public class DamageHandler implements Listener {
|
|||
board.reloadBoardTeams();
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR)
|
||||
public void onPlayerDeath(PlayerDeathEvent event){
|
||||
Main.getInstance().getDisguiser().reveal(event.getEntity());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,187 @@
|
|||
package net.tylermurphy.hideAndSeek.game.listener;
|
||||
|
||||
import static com.comphenix.protocol.PacketType.Play.Client.*;
|
||||
|
||||
import com.comphenix.protocol.ProtocolLibrary;
|
||||
import com.comphenix.protocol.ProtocolManager;
|
||||
import com.comphenix.protocol.events.PacketAdapter;
|
||||
import com.comphenix.protocol.events.PacketContainer;
|
||||
import com.comphenix.protocol.events.PacketEvent;
|
||||
import com.cryptomorin.xseries.XMaterial;
|
||||
import net.tylermurphy.hideAndSeek.Main;
|
||||
import net.tylermurphy.hideAndSeek.game.util.Disguise;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.attribute.Attribute;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||
import org.bukkit.event.entity.EntityDamageEvent;
|
||||
import org.bukkit.event.player.PlayerMoveEvent;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.potion.PotionEffect;
|
||||
import org.bukkit.potion.PotionEffectType;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public class DisguiseHandler implements Listener {
|
||||
|
||||
private static final ProtocolManager protocolManager = ProtocolLibrary.getProtocolManager();
|
||||
|
||||
public DisguiseHandler(){
|
||||
protocolManager.addPacketListener(createProtocol());
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
public void onMove(PlayerMoveEvent event) {
|
||||
final Disguise disguise = Main.getInstance().getDisguiser().getDisguise(event.getPlayer());
|
||||
if(disguise == null) return;
|
||||
final Location lastLocation = event.getPlayer().getLocation();
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(Main.getInstance(), () -> {
|
||||
final Location currentLocation = event.getPlayer().getLocation();
|
||||
if(lastLocation.getWorld() != currentLocation.getWorld()) return;
|
||||
double distance = lastLocation.distance(currentLocation);
|
||||
disguise.setSolidify(distance < .1);
|
||||
}, 40L);
|
||||
if(event.getFrom().distance(event.getTo()) > .1)
|
||||
disguise.setSolidify(false);
|
||||
}
|
||||
|
||||
// @EventHandler(priority = EventPriority.MONITOR)
|
||||
// public void onInteract(PlayerInteractEvent event) {
|
||||
// Action action = event.getAction();
|
||||
// Player player = event.getPlayer();
|
||||
// Block block = event.
|
||||
// }
|
||||
|
||||
private PacketAdapter createProtocol(){
|
||||
return new PacketAdapter(Main.getInstance(), USE_ENTITY) {
|
||||
|
||||
@Override
|
||||
public void onPacketReceiving(PacketEvent event){
|
||||
PacketContainer packet = event.getPacket();
|
||||
Player player = event.getPlayer();
|
||||
// if(!Main.getInstance().getBoard().isSeeker(player)) return;
|
||||
int id = packet.getIntegers().read(0);
|
||||
Disguise disguise = Main.getInstance().getDisguiser().getByEntityID(id);
|
||||
if(disguise == null) disguise = Main.getInstance().getDisguiser().getByHitBoxID(id);
|
||||
if(disguise == null) return;
|
||||
if(disguise.getPlayer().getGameMode() == GameMode.CREATIVE) return;
|
||||
event.setCancelled(true);
|
||||
handleAttack(disguise, player);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private final List<Player> debounce = new ArrayList<>();
|
||||
|
||||
private void handleAttack(Disguise disguise, Player seeker){
|
||||
|
||||
if(disguise.getPlayer() == seeker) return;
|
||||
|
||||
double amount;
|
||||
if(Main.getInstance().supports(9)) {
|
||||
amount = seeker.getAttribute(Attribute.GENERIC_ATTACK_DAMAGE).getValue();
|
||||
} else {
|
||||
amount = getItemDamageValue(seeker.getItemInHand(), disguise.getPlayer(), seeker);
|
||||
}
|
||||
|
||||
disguise.setSolidify(false);
|
||||
if(debounce.contains(disguise.getPlayer())) return;
|
||||
debounce.add(disguise.getPlayer());
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(Main.getInstance(), () -> {
|
||||
EntityDamageByEntityEvent event =
|
||||
new EntityDamageByEntityEvent(seeker, disguise.getPlayer(), EntityDamageEvent.DamageCause.ENTITY_ATTACK, amount);
|
||||
event.setDamage(amount);
|
||||
disguise.getPlayer().setLastDamageCause(event);
|
||||
Main.getInstance().getServer().getPluginManager().callEvent(event);
|
||||
if(!event.isCancelled()){
|
||||
disguise.getPlayer().damage(amount);
|
||||
disguise.getPlayer().setVelocity(seeker.getLocation().getDirection().setY(.2).multiply(1));
|
||||
}
|
||||
|
||||
}, 0);
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(Main.getInstance(), () -> debounce.remove(disguise.getPlayer()), 10);
|
||||
}
|
||||
|
||||
private int getItemDamageValue(ItemStack is, Player damaged, Player attacker) {
|
||||
double damageValue = 0;
|
||||
if (is != null) {
|
||||
if (is.getType() == XMaterial.WOODEN_SWORD.parseMaterial()) {
|
||||
damageValue = 5;
|
||||
} else if (is.getType() == Material.STONE_SWORD) {
|
||||
damageValue = 6;
|
||||
} else if (is.getType() == Material.IRON_SWORD) {
|
||||
damageValue = 7;
|
||||
} else if (is.getType() == Material.DIAMOND_SWORD) {
|
||||
damageValue = 8;
|
||||
} else {
|
||||
damageValue = 1;
|
||||
}
|
||||
damageValue += is.getEnchantmentLevel(Enchantment.DAMAGE_ALL);
|
||||
}
|
||||
|
||||
if (damaged != null) {
|
||||
Inventory i = damaged.getInventory();
|
||||
Material helmet = i.getItem(39).getType();
|
||||
Material chestplate = i.getItem(40).getType();
|
||||
Material leggings = i.getItem(41).getType();
|
||||
Material boots = i.getItem(42).getType();
|
||||
if (helmet == Material.LEATHER_HELMET)
|
||||
damageValue -= (0.5 / 1.5);
|
||||
// value shown at bar above the health bar / 1.5
|
||||
else if (helmet == Material.CHAINMAIL_HELMET
|
||||
|| helmet == Material.IRON_HELMET
|
||||
|| helmet == Material.DIAMOND_HELMET
|
||||
|| helmet == XMaterial.GOLDEN_HELMET.parseMaterial())
|
||||
damageValue -= (1 / 1.5);
|
||||
|
||||
if (chestplate == Material.LEATHER_CHESTPLATE)
|
||||
damageValue -= (1.0);
|
||||
else if (chestplate == Material.CHAINMAIL_CHESTPLATE
|
||||
|| chestplate == XMaterial.GOLDEN_CHESTPLATE.parseMaterial())
|
||||
damageValue -= (2.5 / 1.5);
|
||||
else if (chestplate == Material.IRON_CHESTPLATE)
|
||||
damageValue -= (3 / 1.5);
|
||||
else if (chestplate == Material.DIAMOND_CHESTPLATE)
|
||||
damageValue -= (4 / 1.5);
|
||||
|
||||
if (leggings == Material.LEATHER_LEGGINGS)
|
||||
damageValue -= (1 / 1.5);
|
||||
else if (leggings == XMaterial.GOLDEN_LEGGINGS.parseMaterial())
|
||||
damageValue -= (1.0);
|
||||
else if (leggings == Material.CHAINMAIL_LEGGINGS)
|
||||
damageValue -= (2 / 1.5);
|
||||
else if (leggings == Material.IRON_LEGGINGS)
|
||||
damageValue -= (2.5 / 1.5);
|
||||
else if (leggings == Material.DIAMOND_LEGGINGS)
|
||||
damageValue -= (3 / 1.5);
|
||||
|
||||
if (boots == Material.LEATHER_BOOTS
|
||||
|| boots == XMaterial.GOLDEN_BOOTS.parseMaterial()
|
||||
|| boots == Material.CHAINMAIL_BOOTS)
|
||||
damageValue -= (0.5 / 1.5);
|
||||
else if (boots == Material.IRON_BOOTS)
|
||||
damageValue -= (1 / 1.5);
|
||||
else if (boots == Material.DIAMOND_BOOTS)
|
||||
damageValue -= (1.0);
|
||||
}
|
||||
|
||||
for (PotionEffect effect : attacker.getActivePotionEffects()){
|
||||
if (effect.getType() == PotionEffectType.HARM) {
|
||||
damageValue += effect.getAmplifier()*1.5;
|
||||
}
|
||||
}
|
||||
|
||||
return (int) Math.round(Math.max(damageValue, 0.0));
|
||||
}
|
||||
|
||||
}
|
|
@ -22,6 +22,7 @@ import static net.tylermurphy.hideAndSeek.configuration.Config.*;
|
|||
import static net.tylermurphy.hideAndSeek.configuration.Config.glowPowerupItem;
|
||||
import static net.tylermurphy.hideAndSeek.configuration.Localization.message;
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public class InteractHandler implements Listener {
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
|
@ -96,25 +97,21 @@ public class InteractHandler implements Listener {
|
|||
int amount = Main.getInstance().getBoard().getHiders().size() + Main.getInstance().getBoard().getSeekers().size();
|
||||
Inventory teleportMenu = Main.getInstance().getServer().createInventory(null, 9*(((amount-1)/9)+1), ChatColor.stripColor(teleportItem.getItemMeta().getDisplayName()));
|
||||
List<String> hider_lore = new ArrayList<>(); hider_lore.add(message("HIDER_TEAM_NAME").toString());
|
||||
Main.getInstance().getBoard().getHiders().forEach(hider -> {
|
||||
teleportMenu.addItem(getSkull(hider, hider_lore));
|
||||
});
|
||||
Main.getInstance().getBoard().getHiders().forEach(hider -> teleportMenu.addItem(getSkull(hider, hider_lore)));
|
||||
List<String> seeker_lore = new ArrayList<>(); seeker_lore.add(message("SEEKER_TEAM_NAME").toString());
|
||||
Main.getInstance().getBoard().getSeekers().forEach(seeker -> {
|
||||
teleportMenu.addItem(getSkull(seeker, seeker_lore));
|
||||
});
|
||||
Main.getInstance().getBoard().getSeekers().forEach(seeker -> teleportMenu.addItem(getSkull(seeker, seeker_lore)));
|
||||
event.getPlayer().openInventory(teleportMenu);
|
||||
}
|
||||
}
|
||||
|
||||
private ItemStack getSkull(Player player, List<String> lore){
|
||||
assert XMaterial.PLAYER_HEAD.parseMaterial() != null;
|
||||
ItemStack playerhead = new ItemStack(XMaterial.PLAYER_HEAD.parseMaterial(), 1, (byte) 3);
|
||||
SkullMeta playerheadmeta = (SkullMeta) playerhead.getItemMeta();
|
||||
playerheadmeta.setOwner(player.getName());
|
||||
playerheadmeta.setDisplayName(player.getName());
|
||||
playerheadmeta.setLore(lore);
|
||||
playerhead.setItemMeta(playerheadmeta);
|
||||
return playerhead;
|
||||
ItemStack playerHead = new ItemStack(XMaterial.PLAYER_HEAD.parseMaterial(), 1, (byte) 3);
|
||||
SkullMeta playerHeadMeta = (SkullMeta) playerHead.getItemMeta();
|
||||
playerHeadMeta.setOwner(player.getName());
|
||||
playerHeadMeta.setDisplayName(player.getName());
|
||||
playerHeadMeta.setLore(lore);
|
||||
playerHead.setItemMeta(playerHeadMeta);
|
||||
return playerHead;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,26 +19,29 @@
|
|||
|
||||
package net.tylermurphy.hideAndSeek.game.listener;
|
||||
|
||||
import static net.tylermurphy.hideAndSeek.configuration.Config.*;
|
||||
|
||||
import com.cryptomorin.xseries.XMaterial;
|
||||
import net.tylermurphy.hideAndSeek.Main;
|
||||
import net.tylermurphy.hideAndSeek.command.Debug;
|
||||
import net.tylermurphy.hideAndSeek.game.util.Status;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.event.inventory.InventoryCloseEvent;
|
||||
|
||||
public class InventoryHandler implements Listener {
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
public void onInventoryClick(InventoryClickEvent event) {
|
||||
if (!(event.getWhoClicked() instanceof Player)) return;
|
||||
|
||||
Player player = (Player) event.getWhoClicked();
|
||||
checkForInventoryMove(event);
|
||||
checkForSpectatorTeleportMenu(event);
|
||||
checkForDebugMenu(event);
|
||||
checkForBlockHuntMenu(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();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -15,7 +15,6 @@ import org.bukkit.event.player.PlayerJoinEvent;
|
|||
import org.bukkit.event.player.PlayerKickEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.potion.PotionEffect;
|
||||
|
||||
import static net.tylermurphy.hideAndSeek.configuration.Config.*;
|
||||
import static net.tylermurphy.hideAndSeek.configuration.Config.exitPosition;
|
||||
|
@ -56,6 +55,10 @@ public class JoinLeaveHandler implements Listener {
|
|||
|
||||
@EventHandler(priority = EventPriority.MONITOR)
|
||||
public void onKick(PlayerKickEvent event) {
|
||||
if(event.getReason().equals("Flying is not enabled on this server!")){
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
handleLeave(event.getPlayer());
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
package net.tylermurphy.hideAndSeek.game.listener;
|
||||
|
||||
import com.comphenix.protocol.PacketType;
|
||||
import com.google.common.collect.Sets;
|
||||
import net.tylermurphy.hideAndSeek.Main;
|
||||
import net.tylermurphy.hideAndSeek.game.listener.events.PlayerJumpEvent;
|
||||
|
@ -22,6 +21,7 @@ public class MovementHandler implements Listener {
|
|||
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
public void onMove(PlayerMoveEvent event) {
|
||||
|
||||
if (event.getTo() == null || event.getTo().getWorld() == null) return;
|
||||
checkJumping(event);
|
||||
checkBounds(event);
|
||||
|
|
|
@ -0,0 +1,175 @@
|
|||
package net.tylermurphy.hideAndSeek.game.util;
|
||||
|
||||
import net.tylermurphy.hideAndSeek.Main;
|
||||
import net.tylermurphy.hideAndSeek.util.packet.BlockChangePacket;
|
||||
import net.tylermurphy.hideAndSeek.util.packet.EntityTeleportPacket;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.*;
|
||||
import org.bukkit.potion.PotionEffect;
|
||||
import org.bukkit.potion.PotionEffectType;
|
||||
import org.bukkit.scoreboard.Scoreboard;
|
||||
import org.bukkit.scoreboard.Team;
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public class Disguise {
|
||||
|
||||
final Player hider;
|
||||
final Material material;
|
||||
FallingBlock block;
|
||||
Horse hitBox;
|
||||
Location blockLocation;
|
||||
boolean solid, solidify;
|
||||
static Team hidden;
|
||||
|
||||
static {
|
||||
if(Main.getInstance().supports(9)) {
|
||||
Scoreboard board = Bukkit.getScoreboardManager().getMainScoreboard();
|
||||
hidden = board.getTeam("KenshinHideAndSeek_CollisionGroup");
|
||||
if (hidden == null) {
|
||||
hidden = board.registerNewTeam("KenshinHideAndSeek_CollisionGroup");
|
||||
}
|
||||
hidden.setOption(Team.Option.COLLISION_RULE, Team.OptionStatus.NEVER);
|
||||
hidden.setCanSeeFriendlyInvisibles(false);
|
||||
}
|
||||
}
|
||||
|
||||
public Disguise(Player player, Material material){
|
||||
this.hider = player;
|
||||
this.material = material;
|
||||
this.solid = false;
|
||||
respawnFallingBlock();
|
||||
player.addPotionEffect(new PotionEffect(PotionEffectType.INVISIBILITY, 1000000, 0,false, false));
|
||||
if(Main.getInstance().supports(9)) {
|
||||
hidden.addEntry(player.getName());
|
||||
} else {
|
||||
hider.spigot().setCollidesWithEntities(false);
|
||||
}
|
||||
}
|
||||
|
||||
public void remove(){
|
||||
if(block != null)
|
||||
block.remove();
|
||||
if(hitBox != null){
|
||||
if(Main.getInstance().supports(9))
|
||||
hidden.removeEntry(hitBox.getUniqueId().toString());
|
||||
hitBox.remove();
|
||||
}
|
||||
if(solid)
|
||||
sendBlockUpdate(blockLocation, Material.AIR);
|
||||
hider.removePotionEffect(PotionEffectType.INVISIBILITY);
|
||||
if(Main.getInstance().supports(9)) {
|
||||
hidden.removeEntry(hider.getName());
|
||||
} else {
|
||||
hider.spigot().setCollidesWithEntities(true);
|
||||
}
|
||||
}
|
||||
|
||||
public int getEntityID() {
|
||||
if(block == null) return -1;
|
||||
return block.getEntityId();
|
||||
}
|
||||
|
||||
public int getHitBoxID() {
|
||||
if(hitBox == null) return -1;
|
||||
return hitBox.getEntityId();
|
||||
}
|
||||
|
||||
public Player getPlayer() {
|
||||
return hider;
|
||||
}
|
||||
|
||||
public void update(){
|
||||
|
||||
if(block == null || block.isDead()){
|
||||
if(block != null) block.remove();
|
||||
respawnFallingBlock();
|
||||
}
|
||||
|
||||
if(solidify){
|
||||
if(!solid) {
|
||||
solid = true;
|
||||
blockLocation = hider.getLocation().getBlock().getLocation();
|
||||
respawnHitbox();
|
||||
}
|
||||
sendBlockUpdate(blockLocation, material);
|
||||
} else if(solid){
|
||||
solid = false;
|
||||
if(Main.getInstance().supports(9))
|
||||
hidden.removeEntry(hitBox.getUniqueId().toString());
|
||||
hitBox.remove();
|
||||
hitBox = null;
|
||||
sendBlockUpdate(blockLocation, Material.AIR);
|
||||
}
|
||||
toggleEntityVisibility(block, !solid);
|
||||
teleportEntity(hitBox, true);
|
||||
teleportEntity(block, solid);
|
||||
}
|
||||
|
||||
public void setSolidify(boolean value){
|
||||
this.solidify = value;
|
||||
}
|
||||
|
||||
private void sendBlockUpdate(Location location, Material material){
|
||||
BlockChangePacket packet = new BlockChangePacket();
|
||||
packet.setBlockPosition(location);
|
||||
packet.setMaterial(material);
|
||||
Bukkit.getOnlinePlayers().forEach(receiver -> {
|
||||
if(receiver.getName().equals(hider.getName())) return;
|
||||
packet.send(receiver);
|
||||
});
|
||||
}
|
||||
|
||||
private void teleportEntity(Entity entity, boolean center) {
|
||||
if(entity == null) return;
|
||||
EntityTeleportPacket packet = new EntityTeleportPacket();
|
||||
packet.setEntity(entity);
|
||||
double x,y,z;
|
||||
if(center){
|
||||
x = Math.round(hider.getLocation().getX()+.5)-.5;
|
||||
y = Math.round(hider.getLocation().getY());
|
||||
z = Math.round(hider.getLocation().getZ()+.5)-.5;
|
||||
} else {
|
||||
x = hider.getLocation().getX();
|
||||
y = hider.getLocation().getY();
|
||||
z = hider.getLocation().getZ();
|
||||
}
|
||||
packet.setX(x);
|
||||
packet.setY(y);
|
||||
packet.setZ(z);
|
||||
Bukkit.getOnlinePlayers().forEach(packet::send);
|
||||
}
|
||||
|
||||
private void toggleEntityVisibility(Entity entity, boolean show){
|
||||
if(entity == null) return;
|
||||
Bukkit.getOnlinePlayers().forEach(receiver -> {
|
||||
if(receiver == hider) return;
|
||||
if(show)
|
||||
Main.getInstance().getEntityHider().showEntity(receiver, entity);
|
||||
else
|
||||
Main.getInstance().getEntityHider().hideEntity(receiver, entity);
|
||||
});
|
||||
}
|
||||
|
||||
private void respawnFallingBlock(){
|
||||
block = hider.getLocation().getWorld().spawnFallingBlock(hider.getLocation().add(0, 1000, 0), material, (byte)0);
|
||||
block.setGravity(false);
|
||||
block.setDropItem(false);
|
||||
block.setInvulnerable(true);
|
||||
}
|
||||
|
||||
private void respawnHitbox(){
|
||||
hitBox = (Horse) hider.getLocation().getWorld().spawnEntity(hider.getLocation().add(0, 1000, 0), EntityType.HORSE);
|
||||
hitBox.setAI(false);
|
||||
hitBox.setGravity(false);
|
||||
hitBox.setInvulnerable(true);
|
||||
hitBox.setCanPickupItems(false);
|
||||
hitBox.setCollidable(false);
|
||||
hitBox.addPotionEffect(new PotionEffect(PotionEffectType.INVISIBILITY, 1000000, 0,false, false));
|
||||
if(Main.getInstance().supports(9)){
|
||||
hidden.addEntry(hitBox.getUniqueId().toString());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -36,6 +36,7 @@ public class PAPIExpansion extends PlaceholderExpansion {
|
|||
return true;
|
||||
}
|
||||
|
||||
@SuppressWarnings("ConstantConditions")
|
||||
@Override
|
||||
public String onRequest(OfflinePlayer player, @NotNull String params) {
|
||||
Database database = Main.getInstance().getDatabase();
|
||||
|
|
|
@ -0,0 +1,31 @@
|
|||
package net.tylermurphy.hideAndSeek.util.packet;
|
||||
|
||||
import com.comphenix.protocol.PacketType;
|
||||
import com.comphenix.protocol.ProtocolLibrary;
|
||||
import com.comphenix.protocol.ProtocolManager;
|
||||
import com.comphenix.protocol.events.PacketContainer;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
|
||||
public class AbstractPacket {
|
||||
|
||||
private static final ProtocolManager protocolManager;
|
||||
static {
|
||||
protocolManager = ProtocolLibrary.getProtocolManager();
|
||||
}
|
||||
|
||||
protected final PacketContainer packet;
|
||||
|
||||
protected AbstractPacket(PacketType type){
|
||||
packet = protocolManager.createPacket(type);
|
||||
packet.getModifier().writeDefaults();
|
||||
}
|
||||
|
||||
public void send(Player player){
|
||||
try {
|
||||
protocolManager.sendServerPacket(player, packet);
|
||||
} catch (InvocationTargetException ignored) {}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
package net.tylermurphy.hideAndSeek.util.packet;
|
||||
|
||||
import com.comphenix.protocol.PacketType;
|
||||
import com.comphenix.protocol.wrappers.BlockPosition;
|
||||
import com.comphenix.protocol.wrappers.WrappedBlockData;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class BlockChangePacket extends AbstractPacket {
|
||||
|
||||
public BlockChangePacket(){
|
||||
super(PacketType.Play.Server.BLOCK_CHANGE);
|
||||
}
|
||||
|
||||
public void setBlockPosition(@NotNull Location location){
|
||||
super.packet.getBlockPositionModifier().write(0, new BlockPosition(location.toVector()));
|
||||
}
|
||||
|
||||
public void setMaterial(Material material){
|
||||
super.packet.getBlockData().write(0, WrappedBlockData.createData(material));
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,29 @@
|
|||
package net.tylermurphy.hideAndSeek.util.packet;
|
||||
|
||||
import com.comphenix.protocol.PacketType;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class EntityTeleportPacket extends AbstractPacket {
|
||||
|
||||
public EntityTeleportPacket(){
|
||||
super(PacketType.Play.Server.ENTITY_TELEPORT);
|
||||
}
|
||||
|
||||
public void setEntity(@NotNull Entity entity){
|
||||
super.packet.getIntegers().write(0, entity.getEntityId());
|
||||
}
|
||||
|
||||
public void setX(double x){
|
||||
super.packet.getDoubles().write(0, x);
|
||||
}
|
||||
|
||||
public void setY(double y){
|
||||
super.packet.getDoubles().write(1, y);
|
||||
}
|
||||
|
||||
public void setZ(double z){
|
||||
super.packet.getDoubles().write(2, z);
|
||||
}
|
||||
|
||||
}
|
|
@ -28,8 +28,10 @@ import java.util.Collections;
|
|||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
@SuppressWarnings({"unused"})
|
||||
public class VoidGenerator extends ChunkGenerator{
|
||||
|
||||
// 1.14 And On
|
||||
public @NotNull List<BlockPopulator> getDefaultPopulators(@NotNull World world) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
@ -66,7 +68,7 @@ public class VoidGenerator extends ChunkGenerator{
|
|||
return true;
|
||||
}
|
||||
|
||||
// Backwards compatibility
|
||||
// 1.13 And Prev
|
||||
public @NotNull ChunkData generateChunkData(@NotNull World world, @NotNull Random random, int x, int z, @NotNull BiomeGrid biome) { return createChunkData(world); }
|
||||
|
||||
}
|
||||
|
|
|
@ -124,6 +124,14 @@ databaseName: hideandseek
|
|||
# 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.
|
||||
# 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:
|
||||
x: 0
|
||||
z: 0
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
name: KenshinsHideAndSeek
|
||||
main: net.tylermurphy.hideAndSeek.Main
|
||||
version: 1.5.1
|
||||
version: 1.6.0
|
||||
author: KenshinEto
|
||||
load: STARTUP
|
||||
api-version: 1.13
|
||||
|
|
Loading…
Reference in a new issue