refactoring and blockhunt disguise bug fixes
This commit is contained in:
parent
055abc11bd
commit
a353e29246
26 changed files with 241 additions and 178 deletions
117
pom.xml
117
pom.xml
|
@ -3,71 +3,84 @@
|
|||
<artifactId>KenshinsHideAndSeek</artifactId>
|
||||
<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>
|
||||
<relocation>
|
||||
<pattern>org.sqlite</pattern>
|
||||
<shadedPattern>net.tylermurphy.dependencies.sqlite</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 +100,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>
|
||||
|
|
|
@ -34,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;
|
||||
|
|
|
@ -73,16 +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);
|
||||
}));
|
||||
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;
|
||||
|
|
|
@ -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<>();
|
||||
|
@ -363,6 +364,7 @@ public class Board {
|
|||
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
class CustomBoard {
|
||||
|
||||
private final Scoreboard board;
|
||||
|
|
|
@ -3,7 +3,7 @@ package net.tylermurphy.hideAndSeek.game;
|
|||
import static com.comphenix.protocol.PacketType.Play.Server.*;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
|
||||
import org.bukkit.entity.Entity;
|
||||
|
@ -30,9 +30,9 @@ public class EntityHider implements Listener {
|
|||
protected Table<Integer, Integer, Boolean> observerEntityMap = HashBasedTable.create();
|
||||
|
||||
private static final PacketType[] ENTITY_PACKETS = {
|
||||
ENTITY_EQUIPMENT, BED, ANIMATION, NAMED_ENTITY_SPAWN,
|
||||
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_MOVE_LOOK, ENTITY_MOVE_LOOK,
|
||||
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
|
||||
};
|
||||
|
@ -193,6 +193,7 @@ public class EntityHider implements Listener {
|
|||
* @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);
|
||||
|
@ -213,7 +214,7 @@ public class EntityHider implements Listener {
|
|||
|
||||
// Resend packets
|
||||
if (manager != null && hiddenBefore) {
|
||||
manager.updateEntity(entity, Arrays.asList(observer));
|
||||
manager.updateEntity(entity, Collections.singletonList(observer));
|
||||
}
|
||||
return hiddenBefore;
|
||||
}
|
||||
|
@ -253,6 +254,7 @@ public class EntityHider implements Listener {
|
|||
* @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);
|
||||
|
||||
|
@ -268,10 +270,12 @@ public class EntityHider implements Listener {
|
|||
* 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);
|
||||
|
|
|
@ -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;
|
||||
|
@ -27,7 +26,6 @@ import net.tylermurphy.hideAndSeek.configuration.Items;
|
|||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.attribute.Attribute;
|
||||
import org.bukkit.attribute.AttributeInstance;
|
||||
import org.bukkit.entity.Player;
|
||||
|
@ -40,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){
|
||||
|
@ -69,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());
|
||||
}
|
||||
|
||||
|
|
|
@ -7,7 +7,6 @@ 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.comphenix.protocol.wrappers.BlockPosition;
|
||||
import com.cryptomorin.xseries.XMaterial;
|
||||
import net.tylermurphy.hideAndSeek.Main;
|
||||
import net.tylermurphy.hideAndSeek.game.util.Disguise;
|
||||
|
@ -27,19 +26,17 @@ import org.bukkit.inventory.Inventory;
|
|||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.potion.PotionEffect;
|
||||
import org.bukkit.potion.PotionEffectType;
|
||||
import org.bukkit.util.BlockVector;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public class DisguiseHandler implements Listener {
|
||||
|
||||
private static final ProtocolManager protocolManager = ProtocolLibrary.getProtocolManager();
|
||||
private final PacketAdapter packetListener;
|
||||
|
||||
public DisguiseHandler(){
|
||||
packetListener = createProtocol();
|
||||
protocolManager.addPacketListener(packetListener);
|
||||
protocolManager.addPacketListener(createProtocol());
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -1,12 +1,8 @@
|
|||
package net.tylermurphy.hideAndSeek.game.util;
|
||||
|
||||
import com.comphenix.protocol.PacketType;
|
||||
import com.comphenix.protocol.ProtocolLibrary;
|
||||
import com.comphenix.protocol.ProtocolManager;
|
||||
import com.comphenix.protocol.events.PacketContainer;
|
||||
import com.comphenix.protocol.wrappers.BlockPosition;
|
||||
import com.comphenix.protocol.wrappers.WrappedBlockData;
|
||||
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;
|
||||
|
@ -16,17 +12,14 @@ import org.bukkit.potion.PotionEffectType;
|
|||
import org.bukkit.scoreboard.Scoreboard;
|
||||
import org.bukkit.scoreboard.Team;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public class Disguise {
|
||||
|
||||
private static final ProtocolManager protocolManager = ProtocolLibrary.getProtocolManager();
|
||||
|
||||
final Player hider;
|
||||
final Material material;
|
||||
FallingBlock block;
|
||||
Horse hitBox;
|
||||
Location solidLocation;
|
||||
Location blockLocation;
|
||||
boolean solid, solidify;
|
||||
static Team hidden;
|
||||
|
||||
|
@ -64,7 +57,7 @@ public class Disguise {
|
|||
hitBox.remove();
|
||||
}
|
||||
if(solid)
|
||||
sendBlockUpdate(Material.AIR);
|
||||
sendBlockUpdate(blockLocation, Material.AIR);
|
||||
hider.removePotionEffect(PotionEffectType.INVISIBILITY);
|
||||
if(Main.getInstance().supports(9)) {
|
||||
hidden.removeEntry(hider.getName());
|
||||
|
@ -97,18 +90,18 @@ public class Disguise {
|
|||
if(solidify){
|
||||
if(!solid) {
|
||||
solid = true;
|
||||
solidLocation = hider.getLocation().getBlock().getLocation();
|
||||
respawnHotbox();
|
||||
teleportEntity(hitBox, false);
|
||||
blockLocation = hider.getLocation().getBlock().getLocation();
|
||||
respawnHitbox();
|
||||
teleportEntity(hitBox, true);
|
||||
}
|
||||
sendBlockUpdate(material);
|
||||
sendBlockUpdate(blockLocation, material);
|
||||
} else if(solid){
|
||||
solid = false;
|
||||
if(Main.getInstance().supports(9))
|
||||
hidden.removeEntry(hitBox.getUniqueId().toString());
|
||||
hitBox.remove();
|
||||
hitBox = null;
|
||||
sendBlockUpdate(Material.AIR);
|
||||
sendBlockUpdate(blockLocation, Material.AIR);
|
||||
}
|
||||
toggleEntityVisibility(block, !solid);
|
||||
teleportEntity(block, solid);
|
||||
|
@ -118,38 +111,33 @@ public class Disguise {
|
|||
this.solidify = value;
|
||||
}
|
||||
|
||||
private void sendBlockUpdate(Material material){
|
||||
final PacketContainer packet = protocolManager.createPacket(PacketType.Play.Server.BLOCK_CHANGE);
|
||||
packet.getModifier().writeDefaults();
|
||||
packet.getBlockPositionModifier().write(0, new BlockPosition(solidLocation.toVector()));
|
||||
packet.getBlockData().write(0, WrappedBlockData.createData(material));
|
||||
private void sendBlockUpdate(Location location, Material material){
|
||||
BlockChangePacket packet = new BlockChangePacket();
|
||||
packet.setBlockPosition(location);
|
||||
packet.setMaterial(material);
|
||||
Bukkit.getOnlinePlayers().forEach(receiver -> {
|
||||
if(receiver == hider) return;
|
||||
try {
|
||||
protocolManager.sendServerPacket(receiver, packet);
|
||||
} catch (InvocationTargetException ignored) {}
|
||||
if(receiver.getName().equals(hider.getName())) return;
|
||||
packet.send(receiver);
|
||||
});
|
||||
}
|
||||
|
||||
private void teleportEntity(Entity entity, boolean center) {
|
||||
final PacketContainer packet = protocolManager.createPacket(PacketType.Play.Server.ENTITY_TELEPORT);
|
||||
Location location = hider.getLocation();
|
||||
packet.getModifier().writeDefaults();
|
||||
packet.getIntegers().write(0, entity.getEntityId());
|
||||
EntityTeleportPacket packet = new EntityTeleportPacket();
|
||||
packet.setEntity(entity);
|
||||
double x,y,z;
|
||||
if(center){
|
||||
packet.getDoubles().write(0, Math.round(location.getX()+.5)-.5);
|
||||
packet.getDoubles().write(1, (double)Math.round(location.getY()));
|
||||
packet.getDoubles().write(2, Math.round(location.getZ()+.5)-.5);
|
||||
x = Math.round(hider.getLocation().getX()+.5)-.5;
|
||||
y = Math.round(hider.getLocation().getY());
|
||||
z = Math.round(hider.getLocation().getZ()+.5)-.5;
|
||||
} else {
|
||||
packet.getDoubles().write(0, location.getX());
|
||||
packet.getDoubles().write(1, location.getY());
|
||||
packet.getDoubles().write(2, location.getZ());
|
||||
x = hider.getLocation().getX();
|
||||
y = hider.getLocation().getY();
|
||||
z = hider.getLocation().getZ();
|
||||
}
|
||||
Bukkit.getOnlinePlayers().forEach(receiver -> {
|
||||
try {
|
||||
protocolManager.sendServerPacket(receiver, packet);
|
||||
} catch (InvocationTargetException ignored) {}
|
||||
});
|
||||
packet.setX(x);
|
||||
packet.setY(y);
|
||||
packet.setZ(z);
|
||||
Bukkit.getOnlinePlayers().forEach(packet::send);
|
||||
}
|
||||
|
||||
private void toggleEntityVisibility(Entity entity, boolean show){
|
||||
|
@ -164,13 +152,13 @@ public class Disguise {
|
|||
}
|
||||
|
||||
private void respawnFallingBlock(){
|
||||
block = hider.getLocation().getWorld().spawnFallingBlock(hider.getLocation(), material, (byte)0);
|
||||
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 respawnHotbox(){
|
||||
private void respawnHitbox(){
|
||||
hitBox = (Horse) hider.getLocation().getWorld().spawnEntity(hider.getLocation().add(0, 1000, 0), EntityType.HORSE);
|
||||
hitBox.setAI(false);
|
||||
hitBox.setGravity(false);
|
||||
|
|
|
@ -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); }
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue