Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d9f5411e87 | ||
|
|
19ed0162e5 | ||
|
|
03bd19480e | ||
|
|
947c59882e | ||
|
|
8ed4216c64 | ||
|
|
64188f5a75 | ||
|
|
55fec1d092 | ||
|
|
c1eecefa6f | ||
|
|
204d6c8d5f |
No files matched your search
@@ -18,7 +18,7 @@ For a detailed description of the plugin, please visit [spigotmc.org/resources/c
|
||||
| CoreProtect Discord: | [discord.gg/b4DZ4jy](https://discord.gg/b4DZ4jy) |
|
||||
| CoreProtect Patreon: | [patreon.com/coreprotect](https://www.patreon.com/coreprotect) |
|
||||
| CoreProtect Documentation: | [docs.coreprotect.net](https://docs.coreprotect.net) |
|
||||
| Downloads for MC 1.14 - 1.17: | [spigotmc.org/resources/coreprotect.8631](https://www.spigotmc.org/resources/coreprotect.8631/) |
|
||||
| Downloads for MC 1.14 - 1.18: | [spigotmc.org/resources/coreprotect.8631](https://www.spigotmc.org/resources/coreprotect.8631/) |
|
||||
| Downloads for MC 1.8 - 1.12: | [coreprotect.net/legacy](https://coreprotect.net/legacy/) |
|
||||
|
||||
bStats
|
||||
@@ -41,7 +41,7 @@ Maven
|
||||
<dependency>
|
||||
<groupId>net.coreprotect</groupId>
|
||||
<artifactId>coreprotect</artifactId>
|
||||
<version>20.0</version>
|
||||
<version>20.4</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
```
|
||||
|
||||
+1
-1
@@ -7,7 +7,7 @@ plugins {
|
||||
}
|
||||
|
||||
group = 'net.coreprotect'
|
||||
String projectVersion = '20.3'
|
||||
String projectVersion = '20.4'
|
||||
String projectBranch = ''
|
||||
version = projectVersion // `version` might be modified, we don't always want that (e.g. plugin.yml)
|
||||
description = 'Provides block protection for your server.'
|
||||
|
||||
+197
@@ -0,0 +1,197 @@
|
||||
# CoreProtect Language File (ja)
|
||||
|
||||
ACTION_NOT_SUPPORTED: "そのアクションはサポートされていません。"
|
||||
AMOUNT_BLOCK: "{0} {ブロック|ブロック}"
|
||||
AMOUNT_CHUNK: "{0} {チャンク|チャンク}"
|
||||
AMOUNT_ENTITY: "{0} {エンティティ|エンティティ}"
|
||||
AMOUNT_ITEM: "{0} {item|items}"
|
||||
API_TEST: "APIテストが成功しました。"
|
||||
CACHE_ERROR: "警告:検証中にエラーが発生しました {0} キャッシュ。"
|
||||
CACHE_RELOAD: "のリロードを強制する {マッピング|世界} データベースからのキャッシュ。"
|
||||
CHECK_CONFIG: "config.ymlを確認してください"
|
||||
COMMAND_NOT_FOUND: "指示 \"{0}\" 見つかりません。"
|
||||
COMMAND_THROTTLED: "しばらく待ってから、もう一度お試しください。"
|
||||
CONTAINER_HEADER: "コンテナトランザクション"
|
||||
DATABASE_BUSY: "データベースがビジーです。後でもう一度やり直してください。"
|
||||
DATABASE_INDEX_ERROR: "データベースインデックスを検証できません。"
|
||||
DATABASE_LOCKED_1: "データベースがロックされています。最大15秒待機しています..."
|
||||
DATABASE_LOCKED_2: "データベースはすでに使用されています。もう一度やり直してください。"
|
||||
DATABASE_LOCKED_3: "データベースロックを無効にするには、「database-lock:false」を設定します。"
|
||||
DATABASE_LOCKED_4: "データベースロックを無効にすると、データが破損する可能性があります。"
|
||||
DATABASE_UNREACHABLE: "データベースにアクセスできません。データを破棄してシャットダウンします。"
|
||||
DEVELOPMENT_BRANCH: "開発ブランチが検出され、パッチスクリプトをスキップしました。"
|
||||
DIRT_BLOCK: "あなたの下にダートブロックを置きました。"
|
||||
DISABLE_SUCCESS: "成功!無効 {0}"
|
||||
ENABLE_FAILED: "{0} 開始できませんでした。"
|
||||
ENABLE_SUCCESS: "{0} これで有効になります!"
|
||||
ENJOY_COREPROTECT: "楽しみ {0}?私たちに参加する Discord!"
|
||||
FINISHING_CONVERSION: "データ変換を終了します。お待ちください..."
|
||||
FINISHING_LOGGING: "データロギングの終了。お待ちください..."
|
||||
FIRST_VERSION: "初期DB:{0}"
|
||||
GLOBAL_LOOKUP: "グローバルルックアップを実行するために半径を指定しないでください。"
|
||||
GLOBAL_ROLLBACK: "つかいます \"{0}「グローバルに {ロールバック|復元}"
|
||||
HELP_ACTION_1: "ルックアップをアクションに制限します。"
|
||||
HELP_ACTION_2: "例:[a:block]、 [a:+block]、 [a:-block] [a:click]、 [a:container]、 [a:inventory]、 [a:item]、 [a:kill]、 [a:chat]、 [a:command]、 [a:sign]、 [a:session]、 [a:username]"
|
||||
HELP_COMMAND: "追加情報を表示します。"
|
||||
HELP_EXCLUDE_1: "ブロック/ユーザーを除外します。"
|
||||
HELP_EXCLUDE_2: "例:[e:stone]、 [e:Notch]、 [e:stone,Notch]"
|
||||
HELP_HEADER: "{0} ヘルプ"
|
||||
HELP_INCLUDE_1: "ブロック/エンティティを含めます。"
|
||||
HELP_INCLUDE_2: "例:[i:stone]、 [i:zombie]、 [i:stone,wood,bedrock]"
|
||||
HELP_INSPECT_1: "インスペクターを有効にすると、次のことができます。"
|
||||
HELP_INSPECT_2: "左クリックして配置を確認します。"
|
||||
HELP_INSPECT_3: "右クリックして、隣接する削除を表示します。"
|
||||
HELP_INSPECT_4: "ブロックを配置して、削除を確認します。"
|
||||
HELP_INSPECT_5: "ブロックを液体に入れて配置を確認します。"
|
||||
HELP_INSPECT_6: "右クリックしてチェストトランザクションを表示します。"
|
||||
HELP_INSPECT_7: "ヒント:「/coi」だけを使用できます。"
|
||||
HELP_INSPECT_COMMAND: "ブロックインスペクターを切り替えます。"
|
||||
HELP_LIST: "すべてのコマンドのリストを表示します。"
|
||||
HELP_LOOKUP_1: "コマンドショートカット。"
|
||||
HELP_LOOKUP_2: "追加のページを表示します。"
|
||||
HELP_LOOKUP_COMMAND: "ルックアップブロックデータ。"
|
||||
HELP_NO_INFO: "コマンドの情報 \"{0}\" 見つかりません。"
|
||||
HELP_PARAMETER: "見てください \"{0}詳細なパラメータ情報については、「」を参照してください。"
|
||||
HELP_PARAMS_1: "を実行します {ルックアップ|ロールバック|復元}。"
|
||||
HELP_PARAMS_2: "ユーザーを指定して {ルックアップ|ロールバック|復元}。"
|
||||
HELP_PARAMS_3: "時間を指定します {ルックアップ|ロールバック|復元}。"
|
||||
HELP_PARAMS_4: "制限する {ルックアップ|ロールバック|復元} 半径に。"
|
||||
HELP_PARAMS_5: "制限する {ルックアップ|ロールバック|復元} アクションに。"
|
||||
HELP_PARAMS_6: "ブロック/エンティティをに含める {ルックアップ|ロールバック|復元}。"
|
||||
HELP_PARAMS_7: "ブロック/ユーザーをから除外する {ルックアップ|ロールバック|復元}。"
|
||||
HELP_PURGE_1: "古いデータを削除します。"
|
||||
HELP_PURGE_2: "例えば、 \"{0}\" は、1か月より古いすべてのデータを削除し、過去30日間のデータのみを保持します。"
|
||||
HELP_PURGE_COMMAND: "古いブロックデータを削除します。"
|
||||
HELP_RADIUS_1: "半径領域を指定します。"
|
||||
HELP_RADIUS_2: "例:[r:10] (変更は10ブロック以内でのみ行ってください)"
|
||||
HELP_RELOAD_COMMAND: "構成ファイルを再ロードします。"
|
||||
HELP_RESTORE_COMMAND: "ブロックデータを復元します。"
|
||||
HELP_ROLLBACK_COMMAND: "ブロックデータをロールバックします。"
|
||||
HELP_STATUS: "プラグインのステータスを表示します。"
|
||||
HELP_STATUS_COMMAND: "プラグインのステータスを表示します。"
|
||||
HELP_TELEPORT: "テレポート。"
|
||||
HELP_TIME_1: "時間を指定します。"
|
||||
HELP_TIME_2: "例:[t:2w,5d,7h,2m,10s]、 [t:5d2h]、 [t:2.50h]"
|
||||
HELP_USER_1: "ユーザーを指定します。"
|
||||
HELP_USER_2: "例:[u:Notch]、 [u:Notch,#enderman]"
|
||||
INCOMPATIBLE_ACTION: "「」{0}「そのアクションでは使用できません。"
|
||||
INSPECTOR_ERROR: "すでに検査官 {有効|無効}。"
|
||||
INSPECTOR_TOGGLED: "今インスペクター {有効|無効}。"
|
||||
INTEGRATION_ERROR: "できません {初期化|無効化} {0} ロギング。"
|
||||
INTEGRATION_SUCCESS: "{0} 正常にロギング {初期化|無効}。"
|
||||
INTEGRATION_VERSION: "無効 {0} バージョンが見つかりました。"
|
||||
INTERACTIONS_HEADER: "プレイヤーの相互作用"
|
||||
INVALID_ACTION: "それは有効なアクションではありません。"
|
||||
INVALID_BRANCH_1: "プラグインのバージョンが無効です(ブランチが設定されていません)。"
|
||||
INVALID_BRANCH_2: "続行するには、プロジェクトブランチを「開発」に設定します。"
|
||||
INVALID_BRANCH_3: "開発コードを実行すると、データが破損する可能性があります。"
|
||||
INVALID_CONTAINER: "最初に有効なコンテナを調べてください。"
|
||||
INVALID_DONATION_KEY: "寄付キーが無効です。"
|
||||
INVALID_INCLUDE: "「」{0}\" は無効な値です。"
|
||||
INVALID_INCLUDE_COMBO: "これは無効な型の組み合わせです。"
|
||||
INVALID_RADIUS: "有効な半径を入力してください。"
|
||||
INVALID_SELECTION: "{0} 選択が見つかりません。"
|
||||
INVALID_USERNAME: "「」{0}\" は無効なユーザー名です。"
|
||||
INVALID_WORLD: "有効なワールドを指定してください。"
|
||||
LATEST_VERSION: "最新バージョン: {0}"
|
||||
LINK_DISCORD: "Discord: {0}"
|
||||
LINK_DOWNLOAD: "ダウンロード:{0}"
|
||||
LINK_PATREON: "Patreon: {0}"
|
||||
LINK_WIKI_BLOCK: "ブロック名:{0}"
|
||||
LINK_WIKI_ENTITY: "エンティティ名:{0}"
|
||||
LOGGING_ITEMS: "{0} ログに残されたアイテム。お待ちください..."
|
||||
LOGGING_TIME_LIMIT: "ロギングの制限時間に達しました。データを破棄してシャットダウンします。"
|
||||
LOOKUP_BLOCK: "{0} {配置|壊れた} {1}。"
|
||||
LOOKUP_CONTAINER: "{0} {追加|削除} {1} {2}。"
|
||||
LOOKUP_HEADER: "{0} 結果"
|
||||
LOOKUP_INTERACTION: "{0} {クリック|殺された} {1}。"
|
||||
LOOKUP_ITEM: "{0} {拾った|落とした} {1} {2}。"
|
||||
LOOKUP_LOGIN: "{0} ログに記録されます {in|out}。"
|
||||
LOOKUP_PAGE: "ページ {0}"
|
||||
LOOKUP_ROWS_FOUND: "{0} {行|行} 見つかった。"
|
||||
LOOKUP_SEARCHING: "ルックアップ検索。お待ちください..."
|
||||
LOOKUP_STORAGE: "{0} {預け入れ|撤回} {1} {2}。"
|
||||
LOOKUP_TIME: "{0} 前に"
|
||||
LOOKUP_USERNAME: "{0} としてログイン {1}。"
|
||||
LOOKUP_VIEW_PAGE: "ページを表示するには、「{0}\" 。"
|
||||
MAXIMUM_RADIUS: "最大 {ルックアップ|ロールバック|復元} 半径は {0}。"
|
||||
MISSING_ACTION_USER: "そのアクションを使用するには、ユーザーを指定してください。"
|
||||
MISSING_LOOKUP_TIME: "時間を指定してください {ルックアップ|ロールバック|復元}。"
|
||||
MISSING_LOOKUP_USER: "ユーザーを指定するか、 {ブロック|半径}。"
|
||||
MISSING_PARAMETERS: "使ってください \"{0}\" 。"
|
||||
MISSING_ROLLBACK_RADIUS: "指定しませんでした {ロールバック|復元} 半径。"
|
||||
MISSING_ROLLBACK_USER: "指定しませんでした {ロールバック|復元} ユーザー。"
|
||||
MYSQL_UNAVAILABLE: "接続できません MySQL サーバ。"
|
||||
NO_DATA: "でデータが見つかりません {0}。"
|
||||
NO_DATA_LOCATION: "番号 {データ|トランザクション|相互作用|メッセージ} 見つかった。"
|
||||
NO_PERMISSION: "あなたにはそれをする許可がありません。"
|
||||
NO_RESULTS: "結果が見つかりません。"
|
||||
NO_RESULTS_PAGE: "番号 {結果|データ} そのページで見つかりました。"
|
||||
NO_ROLLBACK: "番号 {保留中|前へ} ロールバック/復元が見つかりました。"
|
||||
PATCH_INTERRUPTED: "アップグレードが中断されました。再起動時に再試行します。"
|
||||
PATCH_OUTDATED_1: "古いデータベースをアップグレードできません {0}。"
|
||||
PATCH_OUTDATED_2: "サポートされているバージョンでアップグレードしてください CoreProtect。"
|
||||
PATCH_PROCESSING: "新しいデータを処理しています。お待ちください..."
|
||||
PATCH_SKIP_UPDATE: "スキップ {テーブル|インデックス} {更新|作成|削除} の上 {0}。"
|
||||
PATCH_STARTED: "実行する {0} アップグレード。お待ちください..."
|
||||
PATCH_SUCCESS: "正常にアップグレードされました {0}。"
|
||||
PATCH_UPGRADING: "データベースのアップグレードが進行中です。お待ちください..."
|
||||
PLEASE_SELECT: "選んでください: \"{0}\" また \"{1}\" 。"
|
||||
PREVIEW_CANCELLED: "プレビューがキャンセルされました。"
|
||||
PREVIEW_CANCELLING: "プレビューをキャンセルしています..."
|
||||
PREVIEW_CONTAINER: "コンテナトランザクションをプレビューすることはできません。"
|
||||
PREVIEW_IN_GAME: "ゲーム内でのみロールバックをプレビューできます。"
|
||||
PURGE_ABORTED: "パージに失敗しました。データベースが破損している可能性があります。"
|
||||
PURGE_ERROR: "処理できません {0} データ!"
|
||||
PURGE_FAILED: "パージに失敗しました。後でもう一度やり直してください。"
|
||||
PURGE_IN_PROGRESS: "進行中のパージ。後でもう一度やり直してください。"
|
||||
PURGE_MINIMUM_TIME: "パージできるのは、より古いデータのみです。 {0} {日|時間}。"
|
||||
PURGE_NOTICE_1: "これには時間がかかる場合がありますのでご注意ください。"
|
||||
PURGE_NOTICE_2: "完了するまでサーバーを再起動しないでください。"
|
||||
PURGE_OPTIMIZING: "データベースの最適化。お待ちください..."
|
||||
PURGE_PROCESSING: "処理 {0} データ..."
|
||||
PURGE_REPAIRING: "修復しようとしています。これには時間がかかる場合があります..."
|
||||
PURGE_ROWS: "{0} {行|行} 削除されたデータの。"
|
||||
PURGE_STARTED: "データの削除は \"で開始されました{0}\" 。"
|
||||
PURGE_SUCCESS: "データのパージに成功しました。"
|
||||
RELOAD_STARTED: "構成の再読み込み-しばらくお待ちください。"
|
||||
RELOAD_SUCCESS: "構成が正常に再ロードされました。"
|
||||
ROLLBACK_ABORTED: "ロールバックまたは復元が中止されました。"
|
||||
ROLLBACK_CHUNKS_FOUND: "見つかった {0} {チャンク|チャンク} 変更します。"
|
||||
ROLLBACK_CHUNKS_MODIFIED: "変更 {0}/{1} {チャンク|チャンク}。"
|
||||
ROLLBACK_COMPLETED: "{ロールバック|復元|プレビュー} 「のために完成{0}\" 。"
|
||||
ROLLBACK_EXCLUDED_USERS: "除外 {ユーザー|ユーザー}: \"{0}\" 。"
|
||||
ROLLBACK_INCLUDE: "{含まれる|除外される} {ブロック|エンティティ|ターゲット} {タイプ|タイプ}: \"{0}\" 。"
|
||||
ROLLBACK_IN_PROGRESS: "ロールバック/復元はすでに進行中です。"
|
||||
ROLLBACK_LENGTH: "所要時間:{0} {秒|秒}。"
|
||||
ROLLBACK_MODIFIED: "{変更|変更} {0}。"
|
||||
ROLLBACK_RADIUS: "半径:{0} {ブロック|ブロック}。"
|
||||
ROLLBACK_SELECTION: "半径を「{0}\" 。"
|
||||
ROLLBACK_STARTED: "{ロールバック|復元|プレビュー} 「で始まった{0}\" 。"
|
||||
ROLLBACK_TIME: "時間範囲:{0}。"
|
||||
ROLLBACK_WORLD_ACTION: "に制限 {世界|アクション} 「」{0}\" 。"
|
||||
SIGN_HEADER: "メッセージに署名する"
|
||||
STATUS_CONSUMER: "消費者: {0} {item|items} 順番待ち。"
|
||||
STATUS_DATABASE: "データベース: 使用する {0}。"
|
||||
STATUS_INTEGRATION: "{0}: 統合 {有効|無効}。"
|
||||
STATUS_LICENSE: "ライセンス: {0}"
|
||||
STATUS_VERSION: "バージョン: {0}"
|
||||
TELEPORTED: "にテレポート {0}。"
|
||||
TELEPORTED_SAFETY: "安全にテレポートしました。"
|
||||
TELEPORT_PLAYERS: "テレポートコマンドはプレイヤーだけが使用できます。"
|
||||
TIME_DAYS: "{0} {日|日}"
|
||||
TIME_HOURS: "{0} {時間|時間}"
|
||||
TIME_MINUTES: "{0} {分|分}"
|
||||
TIME_SECONDS: "{0} {秒|秒}"
|
||||
TIME_WEEKS: "{0} {週|週}"
|
||||
UPDATE_ERROR: "更新の確認中にエラーが発生しました。"
|
||||
UPDATE_HEADER: "{0} アップデート"
|
||||
UPDATE_NOTICE: "知らせ:{0} 現在利用できます。"
|
||||
UPGRADE_IN_PROGRESS: "アップグレードが進行中です。後でもう一度やり直してください。"
|
||||
USER_NOT_FOUND: "ユーザー \"{0}\" 見つかりません。"
|
||||
USING_MYSQL: "使用する MySQL データストレージ用。"
|
||||
USING_SQLITE: "使用する SQLite データストレージ用。"
|
||||
VALID_DONATION_KEY: "有効な寄付キー。"
|
||||
VERSION_NOTICE: "バージョン {0} 現在利用できます。"
|
||||
VERSION_REQUIRED: "{0} {1} 以上が必要です。"
|
||||
WORLD_NOT_FOUND: "世界 \"{0}\" 見つかりません。"
|
||||
@@ -2,7 +2,7 @@
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>net.coreprotect</groupId>
|
||||
<artifactId>CoreProtect</artifactId>
|
||||
<version>20.3</version>
|
||||
<version>20.4</version>
|
||||
<properties>
|
||||
<project.branch></project.branch>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
|
||||
@@ -13,6 +13,7 @@ import net.coreprotect.config.Config;
|
||||
import net.coreprotect.config.ConfigHandler;
|
||||
import net.coreprotect.consumer.Consumer;
|
||||
import net.coreprotect.consumer.process.Process;
|
||||
import net.coreprotect.database.Database;
|
||||
import net.coreprotect.language.Language;
|
||||
import net.coreprotect.language.Phrase;
|
||||
import net.coreprotect.listener.ListenerHandler;
|
||||
@@ -189,6 +190,7 @@ public final class CoreProtect extends JavaPlugin {
|
||||
Thread.sleep(100);
|
||||
}
|
||||
|
||||
Database.closeConnection();
|
||||
Chat.console(Phrase.build(Phrase.DISABLE_SUCCESS, "CoreProtect v" + plugin.getDescription().getVersion()));
|
||||
}
|
||||
catch (Exception e) {
|
||||
|
||||
@@ -464,7 +464,7 @@ public class CoreProtectAPI extends Queue {
|
||||
int xMax = location.getBlockX() + radius;
|
||||
int zMin = location.getBlockZ() - radius;
|
||||
int zMax = location.getBlockZ() + radius;
|
||||
argRadius = new Integer[] { radius, xMin, xMax, -1, -1, zMin, zMax, 0 };
|
||||
argRadius = new Integer[] { radius, xMin, xMax, null, null, zMin, zMax, 0 };
|
||||
}
|
||||
|
||||
if (lookup == 1) {
|
||||
|
||||
@@ -563,12 +563,12 @@ public class CommandHandler implements CommandExecutor {
|
||||
rcount++;
|
||||
}
|
||||
if (location != null) {
|
||||
int xmin = location.getBlockX() - r_x;
|
||||
int xmax = location.getBlockX() + r_x;
|
||||
int ymin = -1;
|
||||
int ymax = -1;
|
||||
int zmin = location.getBlockZ() - r_z;
|
||||
int zmax = location.getBlockZ() + r_z;
|
||||
Integer xmin = location.getBlockX() - r_x;
|
||||
Integer xmax = location.getBlockX() + r_x;
|
||||
Integer ymin = null;
|
||||
Integer ymax = null;
|
||||
Integer zmin = location.getBlockZ() - r_z;
|
||||
Integer zmax = location.getBlockZ() + r_z;
|
||||
if (r_y > -1) {
|
||||
ymin = location.getBlockY() - r_y;
|
||||
ymax = location.getBlockY() + r_y;
|
||||
|
||||
@@ -94,12 +94,14 @@ public class PurgeCommand extends Consumer {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
try (Connection connection = Database.getConnection(false, 500)) {
|
||||
try {
|
||||
long timestamp = (System.currentTimeMillis() / 1000L);
|
||||
long ptime = timestamp - seconds;
|
||||
long removed = 0;
|
||||
|
||||
Connection connection = null;
|
||||
for (int i = 0; i <= 5; i++) {
|
||||
connection = Database.getConnection(false, 500);
|
||||
if (connection != null) {
|
||||
break;
|
||||
}
|
||||
@@ -327,6 +329,11 @@ public class PurgeCommand extends Consumer {
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
if (!ConfigHandler.serverRunning) {
|
||||
Chat.sendGlobalMessage(player, Phrase.build(Phrase.PURGE_FAILED));
|
||||
return;
|
||||
}
|
||||
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
@@ -342,6 +349,8 @@ public class PurgeCommand extends Consumer {
|
||||
}
|
||||
}
|
||||
|
||||
connection.close();
|
||||
|
||||
if (abort) {
|
||||
if (!Config.getGlobal().MYSQL) {
|
||||
(new File(ConfigHandler.path + ConfigHandler.sqlite + ".tmp")).delete();
|
||||
|
||||
@@ -157,7 +157,7 @@ public class RollbackRestoreCommand {
|
||||
int xmax = location.getBlockX() + DEFAULT_RADIUS;
|
||||
int zmin = location.getBlockZ() - DEFAULT_RADIUS;
|
||||
int zmax = location.getBlockZ() + DEFAULT_RADIUS;
|
||||
argRadius = new Integer[] { DEFAULT_RADIUS, xmin, xmax, -1, -1, zmin, zmax, 0 };
|
||||
argRadius = new Integer[] { DEFAULT_RADIUS, xmin, xmax, null, null, zmin, zmax, 0 };
|
||||
}
|
||||
// if (arg_radius==-2)arg_radius = -1;
|
||||
|
||||
|
||||
@@ -11,6 +11,7 @@ import net.coreprotect.language.Phrase;
|
||||
import net.coreprotect.utility.Chat;
|
||||
import net.coreprotect.utility.ChatMessage;
|
||||
import net.coreprotect.utility.Color;
|
||||
import net.coreprotect.utility.Teleport;
|
||||
import net.coreprotect.utility.Util;
|
||||
|
||||
public class TeleportCommand {
|
||||
@@ -103,7 +104,7 @@ public class TeleportCommand {
|
||||
}
|
||||
|
||||
// Teleport the player to a safe location
|
||||
Util.performSafeTeleport(((Player) player), location, true);
|
||||
Teleport.performSafeTeleport(((Player) player), location, true);
|
||||
|
||||
ConfigHandler.teleportThrottle.put(player.getName(), new Object[] { false, System.currentTimeMillis() });
|
||||
}
|
||||
|
||||
@@ -175,10 +175,7 @@ public class ConfigHandler extends Queue {
|
||||
|
||||
public static void loadDatabase() {
|
||||
// close old pool when we reload the database, e.g. in purge command
|
||||
if (ConfigHandler.hikariDataSource != null) {
|
||||
ConfigHandler.hikariDataSource.close();
|
||||
ConfigHandler.hikariDataSource = null;
|
||||
}
|
||||
Database.closeConnection();
|
||||
|
||||
if (!Config.getGlobal().MYSQL) {
|
||||
try {
|
||||
@@ -210,6 +207,14 @@ public class ConfigHandler extends Queue {
|
||||
}
|
||||
else {
|
||||
HikariConfig config = new HikariConfig();
|
||||
try {
|
||||
Class.forName("com.mysql.cj.jdbc.Driver");
|
||||
config.setDriverClassName("com.mysql.cj.jdbc.Driver");
|
||||
}
|
||||
catch (Exception e) {
|
||||
config.setDriverClassName("com.mysql.jdbc.Driver");
|
||||
}
|
||||
|
||||
config.setJdbcUrl("jdbc:mysql://" + ConfigHandler.host + ":" + ConfigHandler.port + "/" + ConfigHandler.database);
|
||||
config.setUsername(ConfigHandler.username);
|
||||
config.setPassword(ConfigHandler.password);
|
||||
|
||||
@@ -8,7 +8,7 @@ import org.bukkit.entity.EntityType;
|
||||
|
||||
import net.coreprotect.config.ConfigHandler;
|
||||
import net.coreprotect.database.statement.EntityStatement;
|
||||
import net.coreprotect.utility.Util;
|
||||
import net.coreprotect.utility.entity.EntityUtil;
|
||||
|
||||
class EntitySpawnProcess {
|
||||
|
||||
@@ -18,7 +18,7 @@ class EntitySpawnProcess {
|
||||
EntityType type = (EntityType) ((Object[]) object)[1];
|
||||
String query = "SELECT data FROM " + ConfigHandler.prefix + "entity WHERE rowid='" + rowId + "' LIMIT 0, 1";
|
||||
List<Object> data = EntityStatement.getData(statement, block, query);
|
||||
Util.spawnEntity(block, type, data);
|
||||
EntityUtil.spawnEntity(block, type, data);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,14 +2,14 @@ package net.coreprotect.consumer.process;
|
||||
|
||||
import org.bukkit.block.BlockState;
|
||||
|
||||
import net.coreprotect.utility.Util;
|
||||
import net.coreprotect.utility.entity.HangingUtil;
|
||||
|
||||
class HangingRemoveProcess {
|
||||
|
||||
static void process(Object object, int delay) {
|
||||
if (object instanceof BlockState) {
|
||||
BlockState block = (BlockState) object;
|
||||
Util.removeHanging(block, delay);
|
||||
HangingUtil.removeHanging(block, delay);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3,14 +3,14 @@ package net.coreprotect.consumer.process;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.BlockState;
|
||||
|
||||
import net.coreprotect.utility.Util;
|
||||
import net.coreprotect.utility.entity.HangingUtil;
|
||||
|
||||
class HangingSpawnProcess {
|
||||
|
||||
static void process(Object object, Material type, int data, int delay) {
|
||||
if (object instanceof BlockState) {
|
||||
BlockState block = (BlockState) object;
|
||||
Util.spawnHanging(block, type, data, delay);
|
||||
HangingUtil.spawnHanging(block, type, data, delay);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -175,6 +175,18 @@ public class Database extends Queue {
|
||||
return connection;
|
||||
}
|
||||
|
||||
public static void closeConnection() {
|
||||
try {
|
||||
if (ConfigHandler.hikariDataSource != null) {
|
||||
ConfigHandler.hikariDataSource.close();
|
||||
ConfigHandler.hikariDataSource = null;
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static void performUpdate(Statement statement, long id, int action, int table) {
|
||||
try {
|
||||
int rolledBack = 1;
|
||||
|
||||
@@ -484,15 +484,15 @@ public class Lookup extends Queue {
|
||||
}
|
||||
|
||||
if (radius != null) {
|
||||
int xmin = radius[1];
|
||||
int xmax = radius[2];
|
||||
int ymin = radius[3];
|
||||
int ymax = radius[4];
|
||||
int zmin = radius[5];
|
||||
int zmax = radius[6];
|
||||
Integer xmin = radius[1];
|
||||
Integer xmax = radius[2];
|
||||
Integer ymin = radius[3];
|
||||
Integer ymax = radius[4];
|
||||
Integer zmin = radius[5];
|
||||
Integer zmax = radius[6];
|
||||
String queryY = "";
|
||||
|
||||
if (ymin > -1 && ymax > -1) {
|
||||
if (ymin != null && ymax != null) {
|
||||
queryY = " y >= '" + ymin + "' AND y <= '" + ymax + "' AND";
|
||||
}
|
||||
|
||||
|
||||
@@ -84,6 +84,7 @@ import net.coreprotect.thread.CacheHandler;
|
||||
import net.coreprotect.utility.Chat;
|
||||
import net.coreprotect.utility.ChestTool;
|
||||
import net.coreprotect.utility.Color;
|
||||
import net.coreprotect.utility.Teleport;
|
||||
import net.coreprotect.utility.Util;
|
||||
|
||||
public class Rollback extends Queue {
|
||||
@@ -1227,7 +1228,7 @@ public class Rollback extends Queue {
|
||||
int chunkZ = playerLocation.getBlockZ() >> 4;
|
||||
|
||||
if (chunkX == finalChunkX && chunkZ == finalChunkZ) {
|
||||
Util.performSafeTeleport(player, playerLocation, false);
|
||||
Teleport.performSafeTeleport(player, playerLocation, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.block.BlockSpreadEvent;
|
||||
|
||||
import net.coreprotect.bukkit.BukkitAdapter;
|
||||
import net.coreprotect.config.Config;
|
||||
import net.coreprotect.consumer.Queue;
|
||||
import net.coreprotect.model.BlockGroup;
|
||||
@@ -59,7 +60,7 @@ public final class BlockSpreadListener extends Queue implements Listener {
|
||||
Location below = sourceBlock.getLocation().clone();
|
||||
below.setY(below.getY() - 2);
|
||||
for (int i = 0; i < 2; i++) {
|
||||
if (below.getY() >= 0) {
|
||||
if (below.getY() >= BukkitAdapter.ADAPTER.getMinHeight(block.getWorld())) {
|
||||
Block belowBlock = below.getBlock();
|
||||
if (belowBlock.getType().equals(Material.BAMBOO)) {
|
||||
Queue.queueBlockPlaceDelayed("#bamboo", belowBlock.getLocation(), belowBlock.getType(), null, belowBlock.getState(), 0);
|
||||
@@ -69,8 +70,8 @@ public final class BlockSpreadListener extends Queue implements Listener {
|
||||
}
|
||||
below = null;
|
||||
|
||||
Queue.queueBlockPlaceDelayed("#bamboo", sourceBlock.getLocation(), sourceBlock.getType(), null, sourceBlock.getState(), 0);
|
||||
Queue.queueBlockPlaceDelayed("#bamboo", block.getLocation(), block.getType(), null, block.getState(), 0);
|
||||
Queue.queueBlockPlaceDelayed("#bamboo", sourceBlock.getLocation(), type, null, sourceBlock.getState(), 0);
|
||||
Queue.queueBlockPlaceDelayed("#bamboo", block.getLocation(), type, null, block.getState(), 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,105 @@
|
||||
package net.coreprotect.utility;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import net.coreprotect.language.Phrase;
|
||||
import net.coreprotect.model.BlockGroup;
|
||||
|
||||
public class Teleport {
|
||||
|
||||
private Teleport() {
|
||||
throw new IllegalStateException("Utility class");
|
||||
}
|
||||
|
||||
public static void performSafeTeleport(Player player, Location location, boolean enforceTeleport) {
|
||||
try {
|
||||
Set<Material> unsafeBlocks = new HashSet<>(Arrays.asList(Material.LAVA));
|
||||
unsafeBlocks.addAll(BlockGroup.FIRE);
|
||||
|
||||
int worldHeight = location.getWorld().getMaxHeight();
|
||||
int playerX = location.getBlockX();
|
||||
int playerY = location.getBlockY();
|
||||
int playerZ = location.getBlockZ();
|
||||
int checkY = playerY - 1;
|
||||
boolean safeBlock = false;
|
||||
boolean placeSafe = false;
|
||||
boolean alert = false;
|
||||
|
||||
while (!safeBlock) {
|
||||
int above = checkY + 1;
|
||||
if (above > worldHeight) {
|
||||
above = worldHeight;
|
||||
}
|
||||
|
||||
Block block1 = location.getWorld().getBlockAt(playerX, checkY, playerZ);
|
||||
Block block2 = location.getWorld().getBlockAt(playerX, above, playerZ);
|
||||
Material type1 = block1.getType();
|
||||
Material type2 = block2.getType();
|
||||
|
||||
if (!Util.solidBlock(type1) && !Util.solidBlock(type2)) {
|
||||
if (unsafeBlocks.contains(type1)) {
|
||||
placeSafe = true;
|
||||
}
|
||||
else {
|
||||
safeBlock = true;
|
||||
if (placeSafe) {
|
||||
int below = checkY - 1;
|
||||
Block blockBelow = location.getWorld().getBlockAt(playerX, below, playerZ);
|
||||
|
||||
if (checkY < worldHeight && unsafeBlocks.contains(blockBelow.getType())) {
|
||||
alert = true;
|
||||
block1.setType(Material.DIRT);
|
||||
checkY++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (checkY >= worldHeight || player.getGameMode() == GameMode.SPECTATOR) {
|
||||
safeBlock = true;
|
||||
|
||||
if (checkY < worldHeight) {
|
||||
checkY++;
|
||||
}
|
||||
}
|
||||
|
||||
if (safeBlock && (checkY > playerY || enforceTeleport)) {
|
||||
if (checkY > worldHeight) {
|
||||
checkY = worldHeight;
|
||||
}
|
||||
|
||||
double oldY = location.getY();
|
||||
location.setY(checkY);
|
||||
player.teleport(location);
|
||||
|
||||
if (!enforceTeleport) {
|
||||
// Only send a message if the player was moved by at least 1 block
|
||||
if (location.getY() >= (oldY + 1.00)) {
|
||||
Chat.sendMessage(player, Color.DARK_AQUA + "CoreProtect " + Color.WHITE + "- " + Phrase.build(Phrase.TELEPORTED_SAFETY));
|
||||
}
|
||||
}
|
||||
else {
|
||||
Chat.sendMessage(player, Color.DARK_AQUA + "CoreProtect " + Color.WHITE + "- " + Phrase.build(Phrase.TELEPORTED, "x" + playerX + "/y" + checkY + "/z" + playerZ + "/" + location.getWorld().getName()));
|
||||
}
|
||||
if (alert) {
|
||||
Chat.sendMessage(player, Color.DARK_AQUA + "CoreProtect " + Color.WHITE + Color.ITALIC + "- " + Phrase.build(Phrase.DIRT_BLOCK));
|
||||
}
|
||||
}
|
||||
|
||||
checkY++;
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -12,7 +12,6 @@ import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
@@ -22,19 +21,11 @@ import java.util.TreeSet;
|
||||
|
||||
import org.bukkit.Art;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.DyeColor;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.attribute.Attributable;
|
||||
import org.bukkit.attribute.Attribute;
|
||||
import org.bukkit.attribute.AttributeInstance;
|
||||
import org.bukkit.attribute.AttributeModifier;
|
||||
import org.bukkit.block.Banner;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.block.BlockState;
|
||||
import org.bukkit.block.Chest;
|
||||
import org.bukkit.block.CommandBlock;
|
||||
@@ -46,50 +37,14 @@ import org.bukkit.command.ConsoleCommandSender;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.configuration.serialization.ConfigurationSerialization;
|
||||
import org.bukkit.configuration.serialization.DelegateDeserialization;
|
||||
import org.bukkit.entity.AbstractHorse;
|
||||
import org.bukkit.entity.AbstractVillager;
|
||||
import org.bukkit.entity.Ageable;
|
||||
import org.bukkit.entity.Cat;
|
||||
import org.bukkit.entity.ChestedHorse;
|
||||
import org.bukkit.entity.Creeper;
|
||||
import org.bukkit.entity.Enderman;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Fox;
|
||||
import org.bukkit.entity.Horse;
|
||||
import org.bukkit.entity.Horse.Style;
|
||||
import org.bukkit.entity.IronGolem;
|
||||
import org.bukkit.entity.ItemFrame;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Llama;
|
||||
import org.bukkit.entity.MushroomCow;
|
||||
import org.bukkit.entity.Painting;
|
||||
import org.bukkit.entity.Panda;
|
||||
import org.bukkit.entity.Panda.Gene;
|
||||
import org.bukkit.entity.Parrot;
|
||||
import org.bukkit.entity.Parrot.Variant;
|
||||
import org.bukkit.entity.Phantom;
|
||||
import org.bukkit.entity.Pig;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.entity.Raider;
|
||||
import org.bukkit.entity.Sheep;
|
||||
import org.bukkit.entity.Slime;
|
||||
import org.bukkit.entity.Spellcaster;
|
||||
import org.bukkit.entity.Spellcaster.Spell;
|
||||
import org.bukkit.entity.Tameable;
|
||||
import org.bukkit.entity.TropicalFish;
|
||||
import org.bukkit.entity.Villager;
|
||||
import org.bukkit.entity.Villager.Profession;
|
||||
import org.bukkit.entity.Wolf;
|
||||
import org.bukkit.entity.Zombie;
|
||||
import org.bukkit.entity.ZombieVillager;
|
||||
import org.bukkit.inventory.BlockInventoryHolder;
|
||||
import org.bukkit.inventory.EntityEquipment;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.MerchantRecipe;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.inventory.meta.LeatherArmorMeta;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.util.io.BukkitObjectOutputStream;
|
||||
|
||||
@@ -569,84 +524,6 @@ public class Util extends Queue {
|
||||
return artname;
|
||||
}
|
||||
|
||||
public static int getBlockFace(BlockFace rotation) {
|
||||
switch (rotation) {
|
||||
case NORTH:
|
||||
return 0;
|
||||
case NORTH_NORTH_EAST:
|
||||
return 1;
|
||||
case NORTH_EAST:
|
||||
return 2;
|
||||
case EAST_NORTH_EAST:
|
||||
return 3;
|
||||
case EAST:
|
||||
return 4;
|
||||
case EAST_SOUTH_EAST:
|
||||
return 5;
|
||||
case SOUTH_EAST:
|
||||
return 6;
|
||||
case SOUTH_SOUTH_EAST:
|
||||
return 7;
|
||||
case SOUTH:
|
||||
return 8;
|
||||
case SOUTH_SOUTH_WEST:
|
||||
return 9;
|
||||
case SOUTH_WEST:
|
||||
return 10;
|
||||
case WEST_SOUTH_WEST:
|
||||
return 11;
|
||||
case WEST:
|
||||
return 12;
|
||||
case WEST_NORTH_WEST:
|
||||
return 13;
|
||||
case NORTH_WEST:
|
||||
return 14;
|
||||
case NORTH_NORTH_WEST:
|
||||
return 15;
|
||||
default:
|
||||
throw new IllegalArgumentException("Invalid BlockFace rotation: " + rotation);
|
||||
}
|
||||
}
|
||||
|
||||
public static BlockFace getBlockFace(int rotation) {
|
||||
switch (rotation) {
|
||||
case 0:
|
||||
return BlockFace.NORTH;
|
||||
case 1:
|
||||
return BlockFace.NORTH_NORTH_EAST;
|
||||
case 2:
|
||||
return BlockFace.NORTH_EAST;
|
||||
case 3:
|
||||
return BlockFace.EAST_NORTH_EAST;
|
||||
case 4:
|
||||
return BlockFace.EAST;
|
||||
case 5:
|
||||
return BlockFace.EAST_SOUTH_EAST;
|
||||
case 6:
|
||||
return BlockFace.SOUTH_EAST;
|
||||
case 7:
|
||||
return BlockFace.SOUTH_SOUTH_EAST;
|
||||
case 8:
|
||||
return BlockFace.SOUTH;
|
||||
case 9:
|
||||
return BlockFace.SOUTH_SOUTH_WEST;
|
||||
case 10:
|
||||
return BlockFace.SOUTH_WEST;
|
||||
case 11:
|
||||
return BlockFace.WEST_SOUTH_WEST;
|
||||
case 12:
|
||||
return BlockFace.WEST;
|
||||
case 13:
|
||||
return BlockFace.WEST_NORTH_WEST;
|
||||
case 14:
|
||||
return BlockFace.NORTH_WEST;
|
||||
case 15:
|
||||
return BlockFace.NORTH_NORTH_WEST;
|
||||
default:
|
||||
throw new AssertionError(rotation);
|
||||
}
|
||||
}
|
||||
|
||||
public static ItemStack[] getArmorStandContents(EntityEquipment equipment) {
|
||||
ItemStack[] contents = new ItemStack[6];
|
||||
if (equipment != null) {
|
||||
@@ -1077,89 +954,6 @@ public class Util extends Queue {
|
||||
Chat.sendComponent(consoleSender, Color.RESET + "[CoreProtect] " + string + Chat.COMPONENT_TAG_OPEN + Chat.COMPONENT_POPUP + "| | " + Chat.COMPONENT_TAG_CLOSE);
|
||||
}
|
||||
|
||||
public static void performSafeTeleport(Player player, Location location, boolean enforceTeleport) {
|
||||
try {
|
||||
Set<Material> unsafeBlocks = new HashSet<>(Arrays.asList(Material.LAVA));
|
||||
unsafeBlocks.addAll(BlockGroup.FIRE);
|
||||
|
||||
int worldHeight = location.getWorld().getMaxHeight();
|
||||
int playerX = location.getBlockX();
|
||||
int playerY = location.getBlockY();
|
||||
int playerZ = location.getBlockZ();
|
||||
int checkY = playerY - 1;
|
||||
boolean safeBlock = false;
|
||||
boolean placeSafe = false;
|
||||
boolean alert = false;
|
||||
|
||||
while (!safeBlock) {
|
||||
int above = checkY + 1;
|
||||
if (above > worldHeight) {
|
||||
above = worldHeight;
|
||||
}
|
||||
|
||||
Block block1 = location.getWorld().getBlockAt(playerX, checkY, playerZ);
|
||||
Block block2 = location.getWorld().getBlockAt(playerX, above, playerZ);
|
||||
Material type1 = block1.getType();
|
||||
Material type2 = block2.getType();
|
||||
|
||||
if (!Util.solidBlock(type1) && !Util.solidBlock(type2)) {
|
||||
if (unsafeBlocks.contains(type1)) {
|
||||
placeSafe = true;
|
||||
}
|
||||
else {
|
||||
safeBlock = true;
|
||||
if (placeSafe) {
|
||||
int below = checkY - 1;
|
||||
Block blockBelow = location.getWorld().getBlockAt(playerX, below, playerZ);
|
||||
|
||||
if (checkY < worldHeight && unsafeBlocks.contains(blockBelow.getType())) {
|
||||
alert = true;
|
||||
block1.setType(Material.DIRT);
|
||||
checkY++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (checkY >= worldHeight || player.getGameMode() == GameMode.SPECTATOR) {
|
||||
safeBlock = true;
|
||||
|
||||
if (checkY < worldHeight) {
|
||||
checkY++;
|
||||
}
|
||||
}
|
||||
|
||||
if (safeBlock && (checkY > playerY || enforceTeleport)) {
|
||||
if (checkY > worldHeight) {
|
||||
checkY = worldHeight;
|
||||
}
|
||||
|
||||
double oldY = location.getY();
|
||||
location.setY(checkY);
|
||||
player.teleport(location);
|
||||
|
||||
if (!enforceTeleport) {
|
||||
// Only send a message if the player was moved by at least 1 block
|
||||
if (location.getY() >= (oldY + 1.00)) {
|
||||
Chat.sendMessage(player, Color.DARK_AQUA + "CoreProtect " + Color.WHITE + "- " + Phrase.build(Phrase.TELEPORTED_SAFETY));
|
||||
}
|
||||
}
|
||||
else {
|
||||
Chat.sendMessage(player, Color.DARK_AQUA + "CoreProtect " + Color.WHITE + "- " + Phrase.build(Phrase.TELEPORTED, "x" + playerX + "/y" + checkY + "/z" + playerZ + "/" + location.getWorld().getName()));
|
||||
}
|
||||
if (alert) {
|
||||
Chat.sendMessage(player, Color.DARK_AQUA + "CoreProtect " + Color.WHITE + Color.ITALIC + "- " + Phrase.build(Phrase.DIRT_BLOCK));
|
||||
}
|
||||
}
|
||||
|
||||
checkY++;
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static String nameFilter(String name, int data) {
|
||||
if (name.equals("stone")) {
|
||||
switch (data) {
|
||||
@@ -1381,24 +1175,6 @@ public class Util extends Queue {
|
||||
return meta;
|
||||
}
|
||||
|
||||
public static void removeHanging(final BlockState block, int delay) {
|
||||
Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(CoreProtect.getInstance(), () -> {
|
||||
try {
|
||||
for (Entity e : block.getChunk().getEntities()) {
|
||||
if (e instanceof ItemFrame || e instanceof Painting) {
|
||||
Location el = e.getLocation();
|
||||
if (el.getBlockX() == block.getX() && el.getBlockY() == block.getY() && el.getBlockZ() == block.getZ()) {
|
||||
e.remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}, delay);
|
||||
}
|
||||
|
||||
public static void sendBlockChange(Player player, Location location, BlockData blockData) {
|
||||
player.sendBlockChange(location, blockData);
|
||||
}
|
||||
@@ -1428,607 +1204,6 @@ public class Util extends Queue {
|
||||
block.setBlockData(blockData, update);
|
||||
}
|
||||
|
||||
public static void spawnEntity(final BlockState block, final EntityType type, final List<Object> list) {
|
||||
if (type == null) {
|
||||
return;
|
||||
}
|
||||
Bukkit.getServer().getScheduler().runTask(CoreProtect.getInstance(), () -> {
|
||||
try {
|
||||
Location location = block.getLocation();
|
||||
location.setX(location.getX() + 0.50);
|
||||
location.setZ(location.getZ() + 0.50);
|
||||
Entity entity = block.getLocation().getWorld().spawnEntity(location, type);
|
||||
|
||||
if (list.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
List<Object> age = (List<Object>) list.get(0);
|
||||
@SuppressWarnings("unchecked")
|
||||
List<Object> tame = (List<Object>) list.get(1);
|
||||
@SuppressWarnings("unchecked")
|
||||
List<Object> data = (List<Object>) list.get(2);
|
||||
|
||||
if (list.size() >= 5) {
|
||||
entity.setCustomNameVisible((Boolean) list.get(3));
|
||||
entity.setCustomName((String) list.get(4));
|
||||
}
|
||||
|
||||
int unixtimestamp = (int) (System.currentTimeMillis() / 1000L);
|
||||
int wid = Util.getWorldId(block.getWorld().getName());
|
||||
String token = "" + block.getX() + "." + block.getY() + "." + block.getZ() + "." + wid + "." + type.name() + "";
|
||||
CacheHandler.entityCache.put(token, new Object[] { unixtimestamp, entity.getEntityId() });
|
||||
|
||||
if (entity instanceof Ageable) {
|
||||
int count = 0;
|
||||
Ageable ageable = (Ageable) entity;
|
||||
for (Object value : age) {
|
||||
if (count == 0) {
|
||||
int set = (Integer) value;
|
||||
ageable.setAge(set);
|
||||
}
|
||||
else if (count == 1) {
|
||||
boolean set = (Boolean) value;
|
||||
ageable.setAgeLock(set);
|
||||
}
|
||||
else if (count == 2) {
|
||||
boolean set = (Boolean) value;
|
||||
if (set) {
|
||||
ageable.setAdult();
|
||||
}
|
||||
else {
|
||||
ageable.setBaby();
|
||||
}
|
||||
}
|
||||
else if (count == 3) {
|
||||
boolean set = (Boolean) value;
|
||||
ageable.setBreed(set);
|
||||
}
|
||||
else if (count == 4 && value != null) {
|
||||
// deprecated
|
||||
double set = (Double) value;
|
||||
ageable.setMaxHealth(set);
|
||||
}
|
||||
count++;
|
||||
}
|
||||
}
|
||||
if (entity instanceof Tameable) {
|
||||
int count = 0;
|
||||
Tameable tameable = (Tameable) entity;
|
||||
for (Object value : tame) {
|
||||
if (count == 0) {
|
||||
boolean set = (Boolean) value;
|
||||
tameable.setTamed(set);
|
||||
}
|
||||
else if (count == 1) {
|
||||
String set = (String) value;
|
||||
if (set.length() > 0) {
|
||||
Player owner = Bukkit.getServer().getPlayer(set);
|
||||
if (owner == null) {
|
||||
OfflinePlayer offlinePlayer = Bukkit.getServer().getOfflinePlayer(set);
|
||||
if (offlinePlayer != null) {
|
||||
tameable.setOwner(offlinePlayer);
|
||||
}
|
||||
}
|
||||
else {
|
||||
tameable.setOwner(owner);
|
||||
}
|
||||
}
|
||||
}
|
||||
count++;
|
||||
}
|
||||
}
|
||||
if (entity instanceof Attributable && list.size() >= 6) {
|
||||
Attributable attributable = (Attributable) entity;
|
||||
@SuppressWarnings("unchecked")
|
||||
List<Object> attributes = (List<Object>) list.get(5);
|
||||
for (Object value : attributes) {
|
||||
@SuppressWarnings("unchecked")
|
||||
List<Object> attributeData = (List<Object>) value;
|
||||
Attribute attribute = (Attribute) attributeData.get(0);
|
||||
Double baseValue = (Double) attributeData.get(1);
|
||||
@SuppressWarnings("unchecked")
|
||||
List<Object> attributeModifiers = (List<Object>) attributeData.get(2);
|
||||
|
||||
AttributeInstance entityAttribute = attributable.getAttribute(attribute);
|
||||
if (entityAttribute != null) {
|
||||
entityAttribute.setBaseValue(baseValue);
|
||||
for (AttributeModifier modifier : entityAttribute.getModifiers()) {
|
||||
entityAttribute.removeModifier(modifier);
|
||||
}
|
||||
for (Object modifier : attributeModifiers) {
|
||||
@SuppressWarnings("unchecked")
|
||||
Map<String, Object> serializedModifier = (Map<String, Object>) modifier;
|
||||
entityAttribute.addModifier(AttributeModifier.deserialize(serializedModifier));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (entity instanceof LivingEntity && list.size() >= 7) {
|
||||
LivingEntity livingEntity = (LivingEntity) entity;
|
||||
@SuppressWarnings("unchecked")
|
||||
List<Object> details = (List<Object>) list.get(6);
|
||||
int count = 0;
|
||||
for (Object value : details) {
|
||||
if (count == 0) {
|
||||
boolean set = (Boolean) value;
|
||||
livingEntity.setRemoveWhenFarAway(set);
|
||||
}
|
||||
else if (count == 1) {
|
||||
boolean set = (Boolean) value;
|
||||
livingEntity.setCanPickupItems(set);
|
||||
}
|
||||
count++;
|
||||
}
|
||||
}
|
||||
|
||||
int count = 0;
|
||||
for (Object value : data) {
|
||||
if (entity instanceof Creeper) {
|
||||
Creeper creeper = (Creeper) entity;
|
||||
if (count == 0) {
|
||||
boolean set = (Boolean) value;
|
||||
creeper.setPowered(set);
|
||||
}
|
||||
}
|
||||
else if (entity instanceof Enderman) {
|
||||
Enderman enderman = (Enderman) entity;
|
||||
if (count == 1) {
|
||||
String blockDataString = (String) value;
|
||||
BlockData blockData = Bukkit.getServer().createBlockData(blockDataString);
|
||||
enderman.setCarriedBlock(blockData);
|
||||
}
|
||||
}
|
||||
else if (entity instanceof IronGolem) {
|
||||
IronGolem irongolem = (IronGolem) entity;
|
||||
if (count == 0) {
|
||||
boolean set = (Boolean) value;
|
||||
irongolem.setPlayerCreated(set);
|
||||
}
|
||||
}
|
||||
else if (entity instanceof Cat) {
|
||||
Cat cat = (Cat) entity;
|
||||
if (count == 0) {
|
||||
Cat.Type set = (Cat.Type) value;
|
||||
cat.setCatType(set);
|
||||
}
|
||||
else if (count == 1) {
|
||||
DyeColor set = (DyeColor) value;
|
||||
cat.setCollarColor(set);
|
||||
}
|
||||
}
|
||||
else if (entity instanceof Fox) {
|
||||
Fox fox = (Fox) entity;
|
||||
if (count == 0) {
|
||||
Fox.Type set = (Fox.Type) value;
|
||||
fox.setFoxType(set);
|
||||
}
|
||||
else if (count == 1) {
|
||||
boolean set = (Boolean) value;
|
||||
fox.setSitting(set);
|
||||
}
|
||||
}
|
||||
else if (entity instanceof Panda) {
|
||||
Panda panda = (Panda) entity;
|
||||
if (count == 0) {
|
||||
Gene set = (Gene) value;
|
||||
panda.setMainGene(set);
|
||||
}
|
||||
else if (count == 1) {
|
||||
Gene set = (Gene) value;
|
||||
panda.setHiddenGene(set);
|
||||
}
|
||||
}
|
||||
else if (entity instanceof Pig) {
|
||||
Pig pig = (Pig) entity;
|
||||
if (count == 0) {
|
||||
boolean set = (Boolean) value;
|
||||
pig.setSaddle(set);
|
||||
}
|
||||
}
|
||||
else if (entity instanceof Sheep) {
|
||||
Sheep sheep = (Sheep) entity;
|
||||
if (count == 0) {
|
||||
boolean set = (Boolean) value;
|
||||
sheep.setSheared(set);
|
||||
}
|
||||
else if (count == 1) {
|
||||
DyeColor set = (DyeColor) value;
|
||||
sheep.setColor(set);
|
||||
}
|
||||
}
|
||||
else if (entity instanceof MushroomCow) {
|
||||
MushroomCow mushroomCow = (MushroomCow) entity;
|
||||
if (count == 0) {
|
||||
MushroomCow.Variant set = (MushroomCow.Variant) value;
|
||||
mushroomCow.setVariant(set);
|
||||
}
|
||||
}
|
||||
else if (entity instanceof Slime) {
|
||||
Slime slime = (Slime) entity;
|
||||
if (count == 0) {
|
||||
int set = (Integer) value;
|
||||
slime.setSize(set);
|
||||
}
|
||||
}
|
||||
else if (entity instanceof Parrot) {
|
||||
Parrot parrot = (Parrot) entity;
|
||||
if (count == 0) {
|
||||
Variant set = (Variant) value;
|
||||
parrot.setVariant(set);
|
||||
}
|
||||
}
|
||||
else if (entity instanceof TropicalFish) {
|
||||
TropicalFish tropicalFish = (TropicalFish) entity;
|
||||
if (count == 0) {
|
||||
DyeColor set = (DyeColor) value;
|
||||
tropicalFish.setBodyColor(set);
|
||||
}
|
||||
else if (count == 1) {
|
||||
TropicalFish.Pattern set = (TropicalFish.Pattern) value;
|
||||
tropicalFish.setPattern(set);
|
||||
}
|
||||
else if (count == 2) {
|
||||
DyeColor set = (DyeColor) value;
|
||||
tropicalFish.setPatternColor(set);
|
||||
}
|
||||
}
|
||||
else if (entity instanceof Phantom) {
|
||||
Phantom phantom = (Phantom) entity;
|
||||
if (count == 0) {
|
||||
int set = (Integer) value;
|
||||
phantom.setSize(set);
|
||||
}
|
||||
}
|
||||
else if (entity instanceof AbstractVillager) {
|
||||
AbstractVillager abstractVillager = (AbstractVillager) entity;
|
||||
if (count == 0) {
|
||||
if (abstractVillager instanceof Villager) {
|
||||
Villager villager = (Villager) abstractVillager;
|
||||
Profession set = (Profession) value;
|
||||
villager.setProfession(set);
|
||||
}
|
||||
}
|
||||
else if (count == 1) {
|
||||
if (abstractVillager instanceof Villager && value instanceof Villager.Type) {
|
||||
Villager villager = (Villager) abstractVillager;
|
||||
Villager.Type set = (Villager.Type) value;
|
||||
villager.setVillagerType(set);
|
||||
}
|
||||
}
|
||||
else if (count == 2) {
|
||||
List<MerchantRecipe> merchantRecipes = new ArrayList<>();
|
||||
@SuppressWarnings("unchecked")
|
||||
List<Object> set = (List<Object>) value;
|
||||
for (Object recipes : set) {
|
||||
@SuppressWarnings("unchecked")
|
||||
List<Object> recipe = (List<Object>) recipes;
|
||||
@SuppressWarnings("unchecked")
|
||||
List<Object> itemMap = (List<Object>) recipe.get(0);
|
||||
@SuppressWarnings("unchecked")
|
||||
ItemStack result = ItemStack.deserialize((Map<String, Object>) itemMap.get(0));
|
||||
@SuppressWarnings("unchecked")
|
||||
List<List<Map<String, Object>>> metadata = (List<List<Map<String, Object>>>) itemMap.get(1);
|
||||
Object[] populatedStack = Rollback.populateItemStack(result, metadata);
|
||||
result = (ItemStack) populatedStack[1];
|
||||
int uses = (int) recipe.get(1);
|
||||
int maxUses = (int) recipe.get(2);
|
||||
boolean experienceReward = (boolean) recipe.get(3);
|
||||
List<ItemStack> merchantIngredients = new ArrayList<>();
|
||||
@SuppressWarnings("unchecked")
|
||||
List<Object> ingredients = (List<Object>) recipe.get(4);
|
||||
for (Object ingredient : ingredients) {
|
||||
@SuppressWarnings("unchecked")
|
||||
List<Object> ingredientMap = (List<Object>) ingredient;
|
||||
@SuppressWarnings("unchecked")
|
||||
ItemStack item = ItemStack.deserialize((Map<String, Object>) ingredientMap.get(0));
|
||||
@SuppressWarnings("unchecked")
|
||||
List<List<Map<String, Object>>> itemMetaData = (List<List<Map<String, Object>>>) ingredientMap.get(1);
|
||||
populatedStack = Rollback.populateItemStack(item, itemMetaData);
|
||||
item = (ItemStack) populatedStack[1];
|
||||
merchantIngredients.add(item);
|
||||
}
|
||||
MerchantRecipe merchantRecipe = new MerchantRecipe(result, uses, maxUses, experienceReward);
|
||||
if (recipe.size() > 6) {
|
||||
int villagerExperience = (int) recipe.get(5);
|
||||
float priceMultiplier = (float) recipe.get(6);
|
||||
merchantRecipe = new MerchantRecipe(result, uses, maxUses, experienceReward, villagerExperience, priceMultiplier);
|
||||
}
|
||||
merchantRecipe.setIngredients(merchantIngredients);
|
||||
merchantRecipes.add(merchantRecipe);
|
||||
}
|
||||
if (!merchantRecipes.isEmpty()) {
|
||||
abstractVillager.setRecipes(merchantRecipes);
|
||||
}
|
||||
}
|
||||
else {
|
||||
Villager villager = (Villager) abstractVillager;
|
||||
|
||||
if (count == 3) {
|
||||
int set = (int) value;
|
||||
villager.setVillagerLevel(set);
|
||||
}
|
||||
else if (count == 4) {
|
||||
int set = (int) value;
|
||||
villager.setVillagerExperience(set);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (entity instanceof Raider) {
|
||||
Raider raider = (Raider) entity;
|
||||
if (count == 0) {
|
||||
boolean set = (Boolean) value;
|
||||
raider.setPatrolLeader(set);
|
||||
}
|
||||
|
||||
if (entity instanceof Spellcaster && count == 1) {
|
||||
Spellcaster spellcaster = (Spellcaster) entity;
|
||||
Spell set = (Spell) value;
|
||||
spellcaster.setSpell(set);
|
||||
}
|
||||
}
|
||||
else if (entity instanceof Wolf) {
|
||||
Wolf wolf = (Wolf) entity;
|
||||
if (count == 0) {
|
||||
boolean set = (Boolean) value;
|
||||
wolf.setSitting(set);
|
||||
}
|
||||
else if (count == 1) {
|
||||
DyeColor set = (DyeColor) value;
|
||||
wolf.setCollarColor(set);
|
||||
}
|
||||
}
|
||||
else if (entity instanceof ZombieVillager) {
|
||||
ZombieVillager zombieVillager = (ZombieVillager) entity;
|
||||
if (count == 0) {
|
||||
boolean set = (Boolean) value;
|
||||
zombieVillager.setBaby(set);
|
||||
}
|
||||
else if (count == 1) {
|
||||
Profession set = (Profession) value;
|
||||
zombieVillager.setVillagerProfession(set);
|
||||
}
|
||||
}
|
||||
else if (entity instanceof Zombie) {
|
||||
Zombie zombie = (Zombie) entity;
|
||||
if (count == 0) {
|
||||
boolean set = (Boolean) value;
|
||||
zombie.setBaby(set);
|
||||
}
|
||||
}
|
||||
else if (entity instanceof AbstractHorse) {
|
||||
AbstractHorse abstractHorse = (AbstractHorse) entity;
|
||||
if (count == 0 && value != null) {
|
||||
// deprecated
|
||||
boolean set = (Boolean) value;
|
||||
if (entity instanceof ChestedHorse) {
|
||||
ChestedHorse chestedHorse = (ChestedHorse) entity;
|
||||
chestedHorse.setCarryingChest(set);
|
||||
}
|
||||
}
|
||||
else if (count == 1 && value != null) {
|
||||
// deprecated
|
||||
org.bukkit.entity.Horse.Color set = (org.bukkit.entity.Horse.Color) value;
|
||||
if (entity instanceof Horse) {
|
||||
Horse horse = (Horse) entity;
|
||||
horse.setColor(set);
|
||||
}
|
||||
}
|
||||
else if (count == 2) {
|
||||
int set = (Integer) value;
|
||||
abstractHorse.setDomestication(set);
|
||||
}
|
||||
else if (count == 3) {
|
||||
double set = (Double) value;
|
||||
abstractHorse.setJumpStrength(set);
|
||||
}
|
||||
else if (count == 4) {
|
||||
int set = (Integer) value;
|
||||
abstractHorse.setMaxDomestication(set);
|
||||
}
|
||||
else if (count == 5 && value != null) {
|
||||
// deprecated
|
||||
Style set = (Style) value;
|
||||
Horse horse = (Horse) entity;
|
||||
horse.setStyle(set);
|
||||
}
|
||||
if (entity instanceof Horse) {
|
||||
Horse horse = (Horse) entity;
|
||||
if (count == 8) {
|
||||
if (value != null) {
|
||||
@SuppressWarnings("unchecked")
|
||||
ItemStack set = ItemStack.deserialize((Map<String, Object>) value);
|
||||
horse.getInventory().setSaddle(set);
|
||||
}
|
||||
}
|
||||
else if (count == 9) {
|
||||
org.bukkit.entity.Horse.Color set = (org.bukkit.entity.Horse.Color) value;
|
||||
horse.setColor(set);
|
||||
}
|
||||
else if (count == 10) {
|
||||
Style set = (Style) value;
|
||||
horse.setStyle(set);
|
||||
}
|
||||
else if (count == 11) {
|
||||
if (value != null) {
|
||||
@SuppressWarnings("unchecked")
|
||||
ItemStack set = ItemStack.deserialize((Map<String, Object>) value);
|
||||
horse.getInventory().setArmor(set);
|
||||
}
|
||||
}
|
||||
else if (count == 12 && value != null) {
|
||||
@SuppressWarnings("unchecked")
|
||||
org.bukkit.Color set = org.bukkit.Color.deserialize((Map<String, Object>) value);
|
||||
ItemStack armor = horse.getInventory().getArmor();
|
||||
if (armor != null) {
|
||||
ItemMeta itemMeta = armor.getItemMeta();
|
||||
if (itemMeta instanceof LeatherArmorMeta) {
|
||||
LeatherArmorMeta leatherArmorMeta = (LeatherArmorMeta) itemMeta;
|
||||
leatherArmorMeta.setColor(set);
|
||||
armor.setItemMeta(leatherArmorMeta);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (entity instanceof ChestedHorse) {
|
||||
if (count == 7) {
|
||||
ChestedHorse chestedHorse = (ChestedHorse) entity;
|
||||
boolean set = (Boolean) value;
|
||||
chestedHorse.setCarryingChest(set);
|
||||
}
|
||||
if (entity instanceof Llama) {
|
||||
Llama llama = (Llama) entity;
|
||||
if (count == 8) {
|
||||
if (value != null) {
|
||||
@SuppressWarnings("unchecked")
|
||||
ItemStack set = ItemStack.deserialize((Map<String, Object>) value);
|
||||
llama.getInventory().setDecor(set);
|
||||
}
|
||||
}
|
||||
else if (count == 9) {
|
||||
Llama.Color set = (Llama.Color) value;
|
||||
llama.setColor(set);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
BukkitAdapter.ADAPTER.setEntityMeta(entity, value, count);
|
||||
}
|
||||
count++;
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||
public static void spawnHanging(final BlockState blockstate, final Material rowType, final int rowData, int delay) {
|
||||
Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(CoreProtect.getInstance(), () -> {
|
||||
try {
|
||||
Block block = blockstate.getBlock();
|
||||
int x = block.getX();
|
||||
int y = block.getY();
|
||||
int z = block.getZ();
|
||||
|
||||
for (Entity e : block.getChunk().getEntities()) {
|
||||
if ((BukkitAdapter.ADAPTER.isItemFrame(rowType) && e instanceof ItemFrame) || (rowType.equals(Material.PAINTING) && e instanceof Painting)) {
|
||||
Location el = e.getLocation();
|
||||
if (el.getBlockX() == x && el.getBlockY() == y && el.getBlockZ() == z) {
|
||||
e.remove();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Block c1 = block.getWorld().getBlockAt((x + 1), y, z);
|
||||
Block c2 = block.getWorld().getBlockAt((x - 1), y, z);
|
||||
Block c3 = block.getWorld().getBlockAt(x, y, (z + 1));
|
||||
Block c4 = block.getWorld().getBlockAt(x, y, (z - 1));
|
||||
|
||||
BlockFace faceSet = null;
|
||||
if (!BlockGroup.NON_ATTACHABLE.contains(c1.getType())) {
|
||||
faceSet = BlockFace.WEST;
|
||||
block = c1;
|
||||
}
|
||||
else if (!BlockGroup.NON_ATTACHABLE.contains(c2.getType())) {
|
||||
faceSet = BlockFace.EAST;
|
||||
block = c2;
|
||||
}
|
||||
else if (!BlockGroup.NON_ATTACHABLE.contains(c3.getType())) {
|
||||
faceSet = BlockFace.NORTH;
|
||||
block = c3;
|
||||
}
|
||||
else if (!BlockGroup.NON_ATTACHABLE.contains(c4.getType())) {
|
||||
faceSet = BlockFace.SOUTH;
|
||||
block = c4;
|
||||
}
|
||||
|
||||
BlockFace face = null;
|
||||
if (!solidBlock(Util.getType(block.getRelative(BlockFace.EAST)))) {
|
||||
face = BlockFace.EAST;
|
||||
}
|
||||
else if (!solidBlock(Util.getType(block.getRelative(BlockFace.NORTH)))) {
|
||||
face = BlockFace.NORTH;
|
||||
}
|
||||
else if (!solidBlock(Util.getType(block.getRelative(BlockFace.WEST)))) {
|
||||
face = BlockFace.WEST;
|
||||
}
|
||||
else if (!solidBlock(Util.getType(block.getRelative(BlockFace.SOUTH)))) {
|
||||
face = BlockFace.SOUTH;
|
||||
}
|
||||
|
||||
if (faceSet != null && face != null) {
|
||||
if (rowType.equals(Material.PAINTING)) {
|
||||
String name = Util.getArtName(rowData);
|
||||
Art painting = Art.getByName(name.toUpperCase(Locale.ROOT));
|
||||
int height = painting.getBlockHeight();
|
||||
int width = painting.getBlockWidth();
|
||||
int paintingX = x;
|
||||
int paintingY = y;
|
||||
int paintingZ = z;
|
||||
if (height != 1 || width != 1) {
|
||||
if (height > 1) {
|
||||
if (height != 3) {
|
||||
paintingY = paintingY - 1;
|
||||
}
|
||||
}
|
||||
if (width > 1) {
|
||||
if (faceSet.equals(BlockFace.WEST)) {
|
||||
paintingZ--;
|
||||
}
|
||||
else if (faceSet.equals(BlockFace.SOUTH)) {
|
||||
paintingX--;
|
||||
}
|
||||
}
|
||||
}
|
||||
Block spawnBlock = block.getRelative(face);
|
||||
Util.setTypeAndData(spawnBlock, Material.AIR, null, true);
|
||||
Painting hanging = null;
|
||||
try {
|
||||
hanging = block.getWorld().spawn(spawnBlock.getLocation(), Painting.class);
|
||||
}
|
||||
catch (Exception e) {
|
||||
}
|
||||
if (hanging != null) {
|
||||
hanging.teleport(block.getWorld().getBlockAt(paintingX, paintingY, paintingZ).getLocation());
|
||||
hanging.setFacingDirection(faceSet, true);
|
||||
hanging.setArt(painting, true);
|
||||
}
|
||||
}
|
||||
else if (BukkitAdapter.ADAPTER.isItemFrame(rowType)) {
|
||||
try {
|
||||
Block spawnBlock = block.getRelative(face);
|
||||
Util.setTypeAndData(spawnBlock, Material.AIR, null, true);
|
||||
Class itemFrame = BukkitAdapter.ADAPTER.getFrameClass(rowType);
|
||||
Entity entity = block.getWorld().spawn(spawnBlock.getLocation(), itemFrame);
|
||||
if (entity instanceof ItemFrame) {
|
||||
ItemFrame hanging = (ItemFrame) entity;
|
||||
hanging.teleport(block.getWorld().getBlockAt(x, y, z).getLocation());
|
||||
hanging.setFacingDirection(faceSet, true);
|
||||
|
||||
Material type = Util.getType(rowData);
|
||||
if (type != null) {
|
||||
ItemStack istack = new ItemStack(type, 1);
|
||||
hanging.setItem(istack);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}, delay);
|
||||
}
|
||||
|
||||
public static boolean successfulQuery(Connection connection, String query) {
|
||||
boolean result = false;
|
||||
try {
|
||||
|
||||
@@ -0,0 +1,547 @@
|
||||
package net.coreprotect.utility.entity;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.DyeColor;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.attribute.Attributable;
|
||||
import org.bukkit.attribute.Attribute;
|
||||
import org.bukkit.attribute.AttributeInstance;
|
||||
import org.bukkit.attribute.AttributeModifier;
|
||||
import org.bukkit.block.BlockState;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
import org.bukkit.entity.AbstractHorse;
|
||||
import org.bukkit.entity.AbstractVillager;
|
||||
import org.bukkit.entity.Ageable;
|
||||
import org.bukkit.entity.Cat;
|
||||
import org.bukkit.entity.ChestedHorse;
|
||||
import org.bukkit.entity.Creeper;
|
||||
import org.bukkit.entity.Enderman;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Fox;
|
||||
import org.bukkit.entity.Horse;
|
||||
import org.bukkit.entity.Horse.Style;
|
||||
import org.bukkit.entity.IronGolem;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Llama;
|
||||
import org.bukkit.entity.MushroomCow;
|
||||
import org.bukkit.entity.Panda;
|
||||
import org.bukkit.entity.Panda.Gene;
|
||||
import org.bukkit.entity.Parrot;
|
||||
import org.bukkit.entity.Parrot.Variant;
|
||||
import org.bukkit.entity.Phantom;
|
||||
import org.bukkit.entity.Pig;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.entity.Raider;
|
||||
import org.bukkit.entity.Sheep;
|
||||
import org.bukkit.entity.Slime;
|
||||
import org.bukkit.entity.Spellcaster;
|
||||
import org.bukkit.entity.Spellcaster.Spell;
|
||||
import org.bukkit.entity.Tameable;
|
||||
import org.bukkit.entity.TropicalFish;
|
||||
import org.bukkit.entity.Villager;
|
||||
import org.bukkit.entity.Villager.Profession;
|
||||
import org.bukkit.entity.Wolf;
|
||||
import org.bukkit.entity.Zombie;
|
||||
import org.bukkit.entity.ZombieVillager;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.MerchantRecipe;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.inventory.meta.LeatherArmorMeta;
|
||||
|
||||
import net.coreprotect.CoreProtect;
|
||||
import net.coreprotect.bukkit.BukkitAdapter;
|
||||
import net.coreprotect.database.Rollback;
|
||||
import net.coreprotect.thread.CacheHandler;
|
||||
import net.coreprotect.utility.Util;
|
||||
|
||||
public class EntityUtil {
|
||||
|
||||
private EntityUtil() {
|
||||
throw new IllegalStateException("Utility class");
|
||||
}
|
||||
|
||||
public static void spawnEntity(final BlockState block, final EntityType type, final List<Object> list) {
|
||||
if (type == null) {
|
||||
return;
|
||||
}
|
||||
Bukkit.getServer().getScheduler().runTask(CoreProtect.getInstance(), () -> {
|
||||
try {
|
||||
Location location = block.getLocation();
|
||||
location.setX(location.getX() + 0.50);
|
||||
location.setZ(location.getZ() + 0.50);
|
||||
Entity entity = block.getLocation().getWorld().spawnEntity(location, type);
|
||||
|
||||
if (list.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
List<Object> age = (List<Object>) list.get(0);
|
||||
@SuppressWarnings("unchecked")
|
||||
List<Object> tame = (List<Object>) list.get(1);
|
||||
@SuppressWarnings("unchecked")
|
||||
List<Object> data = (List<Object>) list.get(2);
|
||||
|
||||
if (list.size() >= 5) {
|
||||
entity.setCustomNameVisible((Boolean) list.get(3));
|
||||
entity.setCustomName((String) list.get(4));
|
||||
}
|
||||
|
||||
int unixtimestamp = (int) (System.currentTimeMillis() / 1000L);
|
||||
int wid = Util.getWorldId(block.getWorld().getName());
|
||||
String token = "" + block.getX() + "." + block.getY() + "." + block.getZ() + "." + wid + "." + type.name() + "";
|
||||
CacheHandler.entityCache.put(token, new Object[] { unixtimestamp, entity.getEntityId() });
|
||||
|
||||
if (entity instanceof Ageable) {
|
||||
int count = 0;
|
||||
Ageable ageable = (Ageable) entity;
|
||||
for (Object value : age) {
|
||||
if (count == 0) {
|
||||
int set = (Integer) value;
|
||||
ageable.setAge(set);
|
||||
}
|
||||
else if (count == 1) {
|
||||
boolean set = (Boolean) value;
|
||||
ageable.setAgeLock(set);
|
||||
}
|
||||
else if (count == 2) {
|
||||
boolean set = (Boolean) value;
|
||||
if (set) {
|
||||
ageable.setAdult();
|
||||
}
|
||||
else {
|
||||
ageable.setBaby();
|
||||
}
|
||||
}
|
||||
else if (count == 3) {
|
||||
boolean set = (Boolean) value;
|
||||
ageable.setBreed(set);
|
||||
}
|
||||
else if (count == 4 && value != null) {
|
||||
// deprecated
|
||||
double set = (Double) value;
|
||||
ageable.setMaxHealth(set);
|
||||
}
|
||||
count++;
|
||||
}
|
||||
}
|
||||
if (entity instanceof Tameable) {
|
||||
int count = 0;
|
||||
Tameable tameable = (Tameable) entity;
|
||||
for (Object value : tame) {
|
||||
if (count == 0) {
|
||||
boolean set = (Boolean) value;
|
||||
tameable.setTamed(set);
|
||||
}
|
||||
else if (count == 1) {
|
||||
String set = (String) value;
|
||||
if (set.length() > 0) {
|
||||
Player owner = Bukkit.getServer().getPlayer(set);
|
||||
if (owner == null) {
|
||||
OfflinePlayer offlinePlayer = Bukkit.getServer().getOfflinePlayer(set);
|
||||
if (offlinePlayer != null) {
|
||||
tameable.setOwner(offlinePlayer);
|
||||
}
|
||||
}
|
||||
else {
|
||||
tameable.setOwner(owner);
|
||||
}
|
||||
}
|
||||
}
|
||||
count++;
|
||||
}
|
||||
}
|
||||
if (entity instanceof Attributable && list.size() >= 6) {
|
||||
Attributable attributable = (Attributable) entity;
|
||||
@SuppressWarnings("unchecked")
|
||||
List<Object> attributes = (List<Object>) list.get(5);
|
||||
for (Object value : attributes) {
|
||||
@SuppressWarnings("unchecked")
|
||||
List<Object> attributeData = (List<Object>) value;
|
||||
Attribute attribute = (Attribute) attributeData.get(0);
|
||||
Double baseValue = (Double) attributeData.get(1);
|
||||
@SuppressWarnings("unchecked")
|
||||
List<Object> attributeModifiers = (List<Object>) attributeData.get(2);
|
||||
|
||||
AttributeInstance entityAttribute = attributable.getAttribute(attribute);
|
||||
if (entityAttribute != null) {
|
||||
entityAttribute.setBaseValue(baseValue);
|
||||
for (AttributeModifier modifier : entityAttribute.getModifiers()) {
|
||||
entityAttribute.removeModifier(modifier);
|
||||
}
|
||||
for (Object modifier : attributeModifiers) {
|
||||
@SuppressWarnings("unchecked")
|
||||
Map<String, Object> serializedModifier = (Map<String, Object>) modifier;
|
||||
entityAttribute.addModifier(AttributeModifier.deserialize(serializedModifier));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (entity instanceof LivingEntity && list.size() >= 7) {
|
||||
LivingEntity livingEntity = (LivingEntity) entity;
|
||||
@SuppressWarnings("unchecked")
|
||||
List<Object> details = (List<Object>) list.get(6);
|
||||
int count = 0;
|
||||
for (Object value : details) {
|
||||
if (count == 0) {
|
||||
boolean set = (Boolean) value;
|
||||
livingEntity.setRemoveWhenFarAway(set);
|
||||
}
|
||||
else if (count == 1) {
|
||||
boolean set = (Boolean) value;
|
||||
livingEntity.setCanPickupItems(set);
|
||||
}
|
||||
count++;
|
||||
}
|
||||
}
|
||||
|
||||
int count = 0;
|
||||
for (Object value : data) {
|
||||
if (entity instanceof Creeper) {
|
||||
Creeper creeper = (Creeper) entity;
|
||||
if (count == 0) {
|
||||
boolean set = (Boolean) value;
|
||||
creeper.setPowered(set);
|
||||
}
|
||||
}
|
||||
else if (entity instanceof Enderman) {
|
||||
Enderman enderman = (Enderman) entity;
|
||||
if (count == 1) {
|
||||
String blockDataString = (String) value;
|
||||
BlockData blockData = Bukkit.getServer().createBlockData(blockDataString);
|
||||
enderman.setCarriedBlock(blockData);
|
||||
}
|
||||
}
|
||||
else if (entity instanceof IronGolem) {
|
||||
IronGolem irongolem = (IronGolem) entity;
|
||||
if (count == 0) {
|
||||
boolean set = (Boolean) value;
|
||||
irongolem.setPlayerCreated(set);
|
||||
}
|
||||
}
|
||||
else if (entity instanceof Cat) {
|
||||
Cat cat = (Cat) entity;
|
||||
if (count == 0) {
|
||||
Cat.Type set = (Cat.Type) value;
|
||||
cat.setCatType(set);
|
||||
}
|
||||
else if (count == 1) {
|
||||
DyeColor set = (DyeColor) value;
|
||||
cat.setCollarColor(set);
|
||||
}
|
||||
}
|
||||
else if (entity instanceof Fox) {
|
||||
Fox fox = (Fox) entity;
|
||||
if (count == 0) {
|
||||
Fox.Type set = (Fox.Type) value;
|
||||
fox.setFoxType(set);
|
||||
}
|
||||
else if (count == 1) {
|
||||
boolean set = (Boolean) value;
|
||||
fox.setSitting(set);
|
||||
}
|
||||
}
|
||||
else if (entity instanceof Panda) {
|
||||
Panda panda = (Panda) entity;
|
||||
if (count == 0) {
|
||||
Gene set = (Gene) value;
|
||||
panda.setMainGene(set);
|
||||
}
|
||||
else if (count == 1) {
|
||||
Gene set = (Gene) value;
|
||||
panda.setHiddenGene(set);
|
||||
}
|
||||
}
|
||||
else if (entity instanceof Pig) {
|
||||
Pig pig = (Pig) entity;
|
||||
if (count == 0) {
|
||||
boolean set = (Boolean) value;
|
||||
pig.setSaddle(set);
|
||||
}
|
||||
}
|
||||
else if (entity instanceof Sheep) {
|
||||
Sheep sheep = (Sheep) entity;
|
||||
if (count == 0) {
|
||||
boolean set = (Boolean) value;
|
||||
sheep.setSheared(set);
|
||||
}
|
||||
else if (count == 1) {
|
||||
DyeColor set = (DyeColor) value;
|
||||
sheep.setColor(set);
|
||||
}
|
||||
}
|
||||
else if (entity instanceof MushroomCow) {
|
||||
MushroomCow mushroomCow = (MushroomCow) entity;
|
||||
if (count == 0) {
|
||||
MushroomCow.Variant set = (MushroomCow.Variant) value;
|
||||
mushroomCow.setVariant(set);
|
||||
}
|
||||
}
|
||||
else if (entity instanceof Slime) {
|
||||
Slime slime = (Slime) entity;
|
||||
if (count == 0) {
|
||||
int set = (Integer) value;
|
||||
slime.setSize(set);
|
||||
}
|
||||
}
|
||||
else if (entity instanceof Parrot) {
|
||||
Parrot parrot = (Parrot) entity;
|
||||
if (count == 0) {
|
||||
Variant set = (Variant) value;
|
||||
parrot.setVariant(set);
|
||||
}
|
||||
}
|
||||
else if (entity instanceof TropicalFish) {
|
||||
TropicalFish tropicalFish = (TropicalFish) entity;
|
||||
if (count == 0) {
|
||||
DyeColor set = (DyeColor) value;
|
||||
tropicalFish.setBodyColor(set);
|
||||
}
|
||||
else if (count == 1) {
|
||||
TropicalFish.Pattern set = (TropicalFish.Pattern) value;
|
||||
tropicalFish.setPattern(set);
|
||||
}
|
||||
else if (count == 2) {
|
||||
DyeColor set = (DyeColor) value;
|
||||
tropicalFish.setPatternColor(set);
|
||||
}
|
||||
}
|
||||
else if (entity instanceof Phantom) {
|
||||
Phantom phantom = (Phantom) entity;
|
||||
if (count == 0) {
|
||||
int set = (Integer) value;
|
||||
phantom.setSize(set);
|
||||
}
|
||||
}
|
||||
else if (entity instanceof AbstractVillager) {
|
||||
AbstractVillager abstractVillager = (AbstractVillager) entity;
|
||||
if (count == 0) {
|
||||
if (abstractVillager instanceof Villager) {
|
||||
Villager villager = (Villager) abstractVillager;
|
||||
Profession set = (Profession) value;
|
||||
villager.setProfession(set);
|
||||
}
|
||||
}
|
||||
else if (count == 1) {
|
||||
if (abstractVillager instanceof Villager && value instanceof Villager.Type) {
|
||||
Villager villager = (Villager) abstractVillager;
|
||||
Villager.Type set = (Villager.Type) value;
|
||||
villager.setVillagerType(set);
|
||||
}
|
||||
}
|
||||
else if (count == 2) {
|
||||
List<MerchantRecipe> merchantRecipes = new ArrayList<>();
|
||||
@SuppressWarnings("unchecked")
|
||||
List<Object> set = (List<Object>) value;
|
||||
for (Object recipes : set) {
|
||||
@SuppressWarnings("unchecked")
|
||||
List<Object> recipe = (List<Object>) recipes;
|
||||
@SuppressWarnings("unchecked")
|
||||
List<Object> itemMap = (List<Object>) recipe.get(0);
|
||||
@SuppressWarnings("unchecked")
|
||||
ItemStack result = ItemStack.deserialize((Map<String, Object>) itemMap.get(0));
|
||||
@SuppressWarnings("unchecked")
|
||||
List<List<Map<String, Object>>> metadata = (List<List<Map<String, Object>>>) itemMap.get(1);
|
||||
Object[] populatedStack = Rollback.populateItemStack(result, metadata);
|
||||
result = (ItemStack) populatedStack[1];
|
||||
int uses = (int) recipe.get(1);
|
||||
int maxUses = (int) recipe.get(2);
|
||||
boolean experienceReward = (boolean) recipe.get(3);
|
||||
List<ItemStack> merchantIngredients = new ArrayList<>();
|
||||
@SuppressWarnings("unchecked")
|
||||
List<Object> ingredients = (List<Object>) recipe.get(4);
|
||||
for (Object ingredient : ingredients) {
|
||||
@SuppressWarnings("unchecked")
|
||||
List<Object> ingredientMap = (List<Object>) ingredient;
|
||||
@SuppressWarnings("unchecked")
|
||||
ItemStack item = ItemStack.deserialize((Map<String, Object>) ingredientMap.get(0));
|
||||
@SuppressWarnings("unchecked")
|
||||
List<List<Map<String, Object>>> itemMetaData = (List<List<Map<String, Object>>>) ingredientMap.get(1);
|
||||
populatedStack = Rollback.populateItemStack(item, itemMetaData);
|
||||
item = (ItemStack) populatedStack[1];
|
||||
merchantIngredients.add(item);
|
||||
}
|
||||
MerchantRecipe merchantRecipe = new MerchantRecipe(result, uses, maxUses, experienceReward);
|
||||
if (recipe.size() > 6) {
|
||||
int villagerExperience = (int) recipe.get(5);
|
||||
float priceMultiplier = (float) recipe.get(6);
|
||||
merchantRecipe = new MerchantRecipe(result, uses, maxUses, experienceReward, villagerExperience, priceMultiplier);
|
||||
}
|
||||
merchantRecipe.setIngredients(merchantIngredients);
|
||||
merchantRecipes.add(merchantRecipe);
|
||||
}
|
||||
if (!merchantRecipes.isEmpty()) {
|
||||
abstractVillager.setRecipes(merchantRecipes);
|
||||
}
|
||||
}
|
||||
else {
|
||||
Villager villager = (Villager) abstractVillager;
|
||||
|
||||
if (count == 3) {
|
||||
int set = (int) value;
|
||||
villager.setVillagerLevel(set);
|
||||
}
|
||||
else if (count == 4) {
|
||||
int set = (int) value;
|
||||
villager.setVillagerExperience(set);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (entity instanceof Raider) {
|
||||
Raider raider = (Raider) entity;
|
||||
if (count == 0) {
|
||||
boolean set = (Boolean) value;
|
||||
raider.setPatrolLeader(set);
|
||||
}
|
||||
|
||||
if (entity instanceof Spellcaster && count == 1) {
|
||||
Spellcaster spellcaster = (Spellcaster) entity;
|
||||
Spell set = (Spell) value;
|
||||
spellcaster.setSpell(set);
|
||||
}
|
||||
}
|
||||
else if (entity instanceof Wolf) {
|
||||
Wolf wolf = (Wolf) entity;
|
||||
if (count == 0) {
|
||||
boolean set = (Boolean) value;
|
||||
wolf.setSitting(set);
|
||||
}
|
||||
else if (count == 1) {
|
||||
DyeColor set = (DyeColor) value;
|
||||
wolf.setCollarColor(set);
|
||||
}
|
||||
}
|
||||
else if (entity instanceof ZombieVillager) {
|
||||
ZombieVillager zombieVillager = (ZombieVillager) entity;
|
||||
if (count == 0) {
|
||||
boolean set = (Boolean) value;
|
||||
zombieVillager.setBaby(set);
|
||||
}
|
||||
else if (count == 1) {
|
||||
Profession set = (Profession) value;
|
||||
zombieVillager.setVillagerProfession(set);
|
||||
}
|
||||
}
|
||||
else if (entity instanceof Zombie) {
|
||||
Zombie zombie = (Zombie) entity;
|
||||
if (count == 0) {
|
||||
boolean set = (Boolean) value;
|
||||
zombie.setBaby(set);
|
||||
}
|
||||
}
|
||||
else if (entity instanceof AbstractHorse) {
|
||||
AbstractHorse abstractHorse = (AbstractHorse) entity;
|
||||
if (count == 0 && value != null) {
|
||||
// deprecated
|
||||
boolean set = (Boolean) value;
|
||||
if (entity instanceof ChestedHorse) {
|
||||
ChestedHorse chestedHorse = (ChestedHorse) entity;
|
||||
chestedHorse.setCarryingChest(set);
|
||||
}
|
||||
}
|
||||
else if (count == 1 && value != null) {
|
||||
// deprecated
|
||||
org.bukkit.entity.Horse.Color set = (org.bukkit.entity.Horse.Color) value;
|
||||
if (entity instanceof Horse) {
|
||||
Horse horse = (Horse) entity;
|
||||
horse.setColor(set);
|
||||
}
|
||||
}
|
||||
else if (count == 2) {
|
||||
int set = (Integer) value;
|
||||
abstractHorse.setDomestication(set);
|
||||
}
|
||||
else if (count == 3) {
|
||||
double set = (Double) value;
|
||||
abstractHorse.setJumpStrength(set);
|
||||
}
|
||||
else if (count == 4) {
|
||||
int set = (Integer) value;
|
||||
abstractHorse.setMaxDomestication(set);
|
||||
}
|
||||
else if (count == 5 && value != null) {
|
||||
// deprecated
|
||||
Style set = (Style) value;
|
||||
Horse horse = (Horse) entity;
|
||||
horse.setStyle(set);
|
||||
}
|
||||
if (entity instanceof Horse) {
|
||||
Horse horse = (Horse) entity;
|
||||
if (count == 8) {
|
||||
if (value != null) {
|
||||
@SuppressWarnings("unchecked")
|
||||
ItemStack set = ItemStack.deserialize((Map<String, Object>) value);
|
||||
horse.getInventory().setSaddle(set);
|
||||
}
|
||||
}
|
||||
else if (count == 9) {
|
||||
org.bukkit.entity.Horse.Color set = (org.bukkit.entity.Horse.Color) value;
|
||||
horse.setColor(set);
|
||||
}
|
||||
else if (count == 10) {
|
||||
Style set = (Style) value;
|
||||
horse.setStyle(set);
|
||||
}
|
||||
else if (count == 11) {
|
||||
if (value != null) {
|
||||
@SuppressWarnings("unchecked")
|
||||
ItemStack set = ItemStack.deserialize((Map<String, Object>) value);
|
||||
horse.getInventory().setArmor(set);
|
||||
}
|
||||
}
|
||||
else if (count == 12 && value != null) {
|
||||
@SuppressWarnings("unchecked")
|
||||
org.bukkit.Color set = org.bukkit.Color.deserialize((Map<String, Object>) value);
|
||||
ItemStack armor = horse.getInventory().getArmor();
|
||||
if (armor != null) {
|
||||
ItemMeta itemMeta = armor.getItemMeta();
|
||||
if (itemMeta instanceof LeatherArmorMeta) {
|
||||
LeatherArmorMeta leatherArmorMeta = (LeatherArmorMeta) itemMeta;
|
||||
leatherArmorMeta.setColor(set);
|
||||
armor.setItemMeta(leatherArmorMeta);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (entity instanceof ChestedHorse) {
|
||||
if (count == 7) {
|
||||
ChestedHorse chestedHorse = (ChestedHorse) entity;
|
||||
boolean set = (Boolean) value;
|
||||
chestedHorse.setCarryingChest(set);
|
||||
}
|
||||
if (entity instanceof Llama) {
|
||||
Llama llama = (Llama) entity;
|
||||
if (count == 8) {
|
||||
if (value != null) {
|
||||
@SuppressWarnings("unchecked")
|
||||
ItemStack set = ItemStack.deserialize((Map<String, Object>) value);
|
||||
llama.getInventory().setDecor(set);
|
||||
}
|
||||
}
|
||||
else if (count == 9) {
|
||||
Llama.Color set = (Llama.Color) value;
|
||||
llama.setColor(set);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
BukkitAdapter.ADAPTER.setEntityMeta(entity, value, count);
|
||||
}
|
||||
count++;
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,169 @@
|
||||
package net.coreprotect.utility.entity;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
import org.bukkit.Art;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.block.BlockState;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.ItemFrame;
|
||||
import org.bukkit.entity.Painting;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import net.coreprotect.CoreProtect;
|
||||
import net.coreprotect.bukkit.BukkitAdapter;
|
||||
import net.coreprotect.model.BlockGroup;
|
||||
import net.coreprotect.utility.Util;
|
||||
|
||||
public class HangingUtil {
|
||||
|
||||
private HangingUtil() {
|
||||
throw new IllegalStateException("Utility class");
|
||||
}
|
||||
|
||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||
public static void spawnHanging(final BlockState blockstate, final Material rowType, final int rowData, int delay) {
|
||||
Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(CoreProtect.getInstance(), () -> {
|
||||
try {
|
||||
Block block = blockstate.getBlock();
|
||||
int x = block.getX();
|
||||
int y = block.getY();
|
||||
int z = block.getZ();
|
||||
|
||||
for (Entity e : block.getChunk().getEntities()) {
|
||||
if ((BukkitAdapter.ADAPTER.isItemFrame(rowType) && e instanceof ItemFrame) || (rowType.equals(Material.PAINTING) && e instanceof Painting)) {
|
||||
Location el = e.getLocation();
|
||||
if (el.getBlockX() == x && el.getBlockY() == y && el.getBlockZ() == z) {
|
||||
e.remove();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Block c1 = block.getWorld().getBlockAt((x + 1), y, z);
|
||||
Block c2 = block.getWorld().getBlockAt((x - 1), y, z);
|
||||
Block c3 = block.getWorld().getBlockAt(x, y, (z + 1));
|
||||
Block c4 = block.getWorld().getBlockAt(x, y, (z - 1));
|
||||
|
||||
BlockFace faceSet = null;
|
||||
if (!BlockGroup.NON_ATTACHABLE.contains(c1.getType())) {
|
||||
faceSet = BlockFace.WEST;
|
||||
block = c1;
|
||||
}
|
||||
else if (!BlockGroup.NON_ATTACHABLE.contains(c2.getType())) {
|
||||
faceSet = BlockFace.EAST;
|
||||
block = c2;
|
||||
}
|
||||
else if (!BlockGroup.NON_ATTACHABLE.contains(c3.getType())) {
|
||||
faceSet = BlockFace.NORTH;
|
||||
block = c3;
|
||||
}
|
||||
else if (!BlockGroup.NON_ATTACHABLE.contains(c4.getType())) {
|
||||
faceSet = BlockFace.SOUTH;
|
||||
block = c4;
|
||||
}
|
||||
|
||||
BlockFace face = null;
|
||||
if (!Util.solidBlock(Util.getType(block.getRelative(BlockFace.EAST)))) {
|
||||
face = BlockFace.EAST;
|
||||
}
|
||||
else if (!Util.solidBlock(Util.getType(block.getRelative(BlockFace.NORTH)))) {
|
||||
face = BlockFace.NORTH;
|
||||
}
|
||||
else if (!Util.solidBlock(Util.getType(block.getRelative(BlockFace.WEST)))) {
|
||||
face = BlockFace.WEST;
|
||||
}
|
||||
else if (!Util.solidBlock(Util.getType(block.getRelative(BlockFace.SOUTH)))) {
|
||||
face = BlockFace.SOUTH;
|
||||
}
|
||||
|
||||
if (faceSet != null && face != null) {
|
||||
if (rowType.equals(Material.PAINTING)) {
|
||||
String name = Util.getArtName(rowData);
|
||||
Art painting = Art.getByName(name.toUpperCase(Locale.ROOT));
|
||||
int height = painting.getBlockHeight();
|
||||
int width = painting.getBlockWidth();
|
||||
int paintingX = x;
|
||||
int paintingY = y;
|
||||
int paintingZ = z;
|
||||
if (height != 1 || width != 1) {
|
||||
if (height > 1) {
|
||||
if (height != 3) {
|
||||
paintingY = paintingY - 1;
|
||||
}
|
||||
}
|
||||
if (width > 1) {
|
||||
if (faceSet.equals(BlockFace.WEST)) {
|
||||
paintingZ--;
|
||||
}
|
||||
else if (faceSet.equals(BlockFace.SOUTH)) {
|
||||
paintingX--;
|
||||
}
|
||||
}
|
||||
}
|
||||
Block spawnBlock = block.getRelative(face);
|
||||
Util.setTypeAndData(spawnBlock, Material.AIR, null, true);
|
||||
Painting hanging = null;
|
||||
try {
|
||||
hanging = block.getWorld().spawn(spawnBlock.getLocation(), Painting.class);
|
||||
}
|
||||
catch (Exception e) {
|
||||
}
|
||||
if (hanging != null) {
|
||||
hanging.teleport(block.getWorld().getBlockAt(paintingX, paintingY, paintingZ).getLocation());
|
||||
hanging.setFacingDirection(faceSet, true);
|
||||
hanging.setArt(painting, true);
|
||||
}
|
||||
}
|
||||
else if (BukkitAdapter.ADAPTER.isItemFrame(rowType)) {
|
||||
try {
|
||||
Block spawnBlock = block.getRelative(face);
|
||||
Util.setTypeAndData(spawnBlock, Material.AIR, null, true);
|
||||
Class itemFrame = BukkitAdapter.ADAPTER.getFrameClass(rowType);
|
||||
Entity entity = block.getWorld().spawn(spawnBlock.getLocation(), itemFrame);
|
||||
if (entity instanceof ItemFrame) {
|
||||
ItemFrame hanging = (ItemFrame) entity;
|
||||
hanging.teleport(block.getWorld().getBlockAt(x, y, z).getLocation());
|
||||
hanging.setFacingDirection(faceSet, true);
|
||||
|
||||
Material type = Util.getType(rowData);
|
||||
if (type != null) {
|
||||
ItemStack istack = new ItemStack(type, 1);
|
||||
hanging.setItem(istack);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}, delay);
|
||||
}
|
||||
|
||||
public static void removeHanging(final BlockState block, int delay) {
|
||||
Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(CoreProtect.getInstance(), () -> {
|
||||
try {
|
||||
for (Entity e : block.getChunk().getEntities()) {
|
||||
if (e instanceof ItemFrame || e instanceof Painting) {
|
||||
Location el = e.getLocation();
|
||||
if (el.getBlockX() == block.getX() && el.getBlockY() == block.getY() && el.getBlockZ() == block.getZ()) {
|
||||
e.remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}, delay);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user