diff --git a/.github/workflows/build-and-test.yaml b/.github/workflows/build-and-test.yaml new file mode 100644 index 000000000..76115a51f --- /dev/null +++ b/.github/workflows/build-and-test.yaml @@ -0,0 +1,42 @@ +--- +name: build-and-test +on: + pull_request: + types: + - opened + - synchronize + - reopened + push: + branches: + - master + - main + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Set up JDK 1.8 + uses: actions/setup-java@v2 + with: + distribution: 'temurin' + java-version: 8 + + - name: Set up Maven + uses: stCarolas/setup-maven@v4.5 + with: + maven-version: 3.9.1 + + - name: build application + shell: bash + run: | + mvn clean install + + - name: Upload artifact + uses: actions/upload-artifact@v3 + with: + name: WorldGuard + path: target/*.jar \ No newline at end of file diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 000000000..70c055d6c --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,45 @@ +name: Release Workflow + +on: + push: + branches: + - main + - master + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Set up JDK 1.8 + uses: actions/setup-java@v2 + with: + distribution: 'temurin' + java-version: 8 + + - name: Get the version from pom.xml + id: get_version + run: echo "PROJECT_VERSION=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout)" >> $GITHUB_ENV + + - name: Fail if snapshot version + run: | + if [[ $PROJECT_VERSION == *"-SNAPSHOT"* ]]; then + echo "Snapshot versions are not releasable" + exit 0 + fi + + - name: Build with Maven + run: mvn clean package + + - name: Create GitHub Release + if: ${{ !endsWith(env.PROJECT_VERSION, '-SNAPSHOT') }} + uses: softprops/action-gh-release@v1 + with: + tag_name: ${{ env.PROJECT_VERSION }} + files: | + target/*.jar + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.gitignore b/.gitignore new file mode 100644 index 000000000..1153958e7 --- /dev/null +++ b/.gitignore @@ -0,0 +1,225 @@ + +# Created by https://www.gitignore.io/api/java,intellij,intellij+all,intellij+iml +# Edit at https://www.gitignore.io/?templates=java,intellij,intellij+all,intellij+iml + +### Intellij ### +# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and WebStorm +# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 + +# User-specific stuff +.idea/**/workspace.xml +.idea/**/tasks.xml +.idea/**/usage.statistics.xml +.idea/**/dictionaries +.idea/**/shelf + +# Generated files +.idea/**/contentModel.xml + +# Sensitive or high-churn files +.idea/**/dataSources/ +.idea/**/dataSources.ids +.idea/**/dataSources.local.xml +.idea/**/sqlDataSources.xml +.idea/**/dynamic.xml +.idea/**/uiDesigner.xml +.idea/**/dbnavigator.xml + +# Gradle +.idea/**/gradle.xml +.idea/**/libraries + +# Gradle and Maven with auto-import +# When using Gradle or Maven with auto-import, you should exclude module files, +# since they will be recreated, and may cause churn. Uncomment if using +# auto-import. +# .idea/modules.xml +# .idea/*.iml +# .idea/modules +# *.iml +# *.ipr + +# CMake +cmake-build-*/ + +# Mongo Explorer plugin +.idea/**/mongoSettings.xml + +# File-based project format +*.iws + +# IntelliJ +out/ +libs/ + +# mpeltonen/sbt-idea plugin +.idea_modules/ + +# JIRA plugin +atlassian-ide-plugin.xml + +# Cursive Clojure plugin +.idea/replstate.xml + +# Crashlytics plugin (for Android Studio and IntelliJ) +com_crashlytics_export_strings.xml +crashlytics.properties +crashlytics-build.properties +fabric.properties + +# Editor-based Rest Client +.idea/httpRequests + +# Android studio 3.1+ serialized cache file +.idea/caches/build_file_checksums.ser + +### Intellij Patch ### +# Comment Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-215987721 + +# *.iml +# modules.xml +# .idea/misc.xml +# *.ipr + +# Sonarlint plugin +.idea/**/sonarlint/ + +# SonarQube Plugin +.idea/**/sonarIssues.xml + +# Markdown Navigator plugin +.idea/**/markdown-navigator.xml +.idea/**/markdown-navigator/ + +### Intellij+all ### +# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and WebStorm +# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 + +# User-specific stuff + +# Generated files + +# Sensitive or high-churn files + +# Gradle + +# Gradle and Maven with auto-import +# When using Gradle or Maven with auto-import, you should exclude module files, +# since they will be recreated, and may cause churn. Uncomment if using +# auto-import. +# .idea/modules.xml +# .idea/*.iml +# .idea/modules +# *.iml +# *.ipr + +# CMake + +# Mongo Explorer plugin + +# File-based project format + +# IntelliJ + +# mpeltonen/sbt-idea plugin + +# JIRA plugin + +# Cursive Clojure plugin + +# Crashlytics plugin (for Android Studio and IntelliJ) + +# Editor-based Rest Client + +# Android studio 3.1+ serialized cache file + +### Intellij+all Patch ### +# Ignores the whole .idea folder and all .iml files +# See https://github.com/joeblau/gitignore.io/issues/186 and https://github.com/joeblau/gitignore.io/issues/360 + +.idea/ + +# Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-249601023 + +*.iml +modules.xml +.idea/misc.xml +*.ipr + +# Sonarlint plugin +.idea/sonarlint + +### Intellij+iml ### +# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and WebStorm +# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 + +# User-specific stuff + +# Generated files + +# Sensitive or high-churn files + +# Gradle + +# Gradle and Maven with auto-import +# When using Gradle or Maven with auto-import, you should exclude module files, +# since they will be recreated, and may cause churn. Uncomment if using +# auto-import. +# .idea/modules.xml +# .idea/*.iml +# .idea/modules +# *.iml +# *.ipr + +# CMake + +# Mongo Explorer plugin + +# File-based project format + +# IntelliJ + +# mpeltonen/sbt-idea plugin + +# JIRA plugin + +# Cursive Clojure plugin + +# Crashlytics plugin (for Android Studio and IntelliJ) + +# Editor-based Rest Client + +# Android studio 3.1+ serialized cache file + +### Intellij+iml Patch ### +# Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-249601023 + + +### Java ### +# Compiled class file +*.class + +# Log file +*.log + +# BlueJ files +*.ctxt + +# Mobile Tools for Java (J2ME) +.mtj.tmp/ + +# Package Files # +*.jar +*.war +*.nar +*.ear +*.zip +*.tar.gz +*.rar + +# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml +hs_err_pid* + +# End of https://www.gitignore.io/api/java,intellij,intellij+all,intellij+iml + +target/ diff --git a/pom.xml b/pom.xml index e6af050fa..50ac88f78 100644 --- a/pom.xml +++ b/pom.xml @@ -19,30 +19,53 @@ + + + + + + + + + + + - sk89q-mvn2 - http://mvn2.sk89q.com/repo + johnymuffin-nexus-releases + https://repository.johnymuffin.com/repository/maven-public/ + + true + + + false + - + - bukkit-repo - http://repo.bukkit.org/artifactory/repo + johnymuffin-nexus-snapshots + https://repository.johnymuffin.com/repository/maven-snapshots/ + + false + + + true + - com.sk89q - worldedit - 4.4.2 + com.sk89q.worldedit + bukkit + 4.7 - org.bukkit - bukkit - 0.0.1-SNAPSHOT + com.legacyminecraft.poseidon + poseidon-craftbukkit + 1.1.8 @@ -93,7 +116,11 @@ org.apache.maven.plugins maven-compiler-plugin - 2.3.2 + 3.8.1 + + 1.8 + 1.8 + diff --git a/src/main/java/com/sk89q/worldguard/bukkit/BukkitUtil.java b/src/main/java/com/sk89q/worldguard/bukkit/BukkitUtil.java index 7dbee385e..a62060495 100644 --- a/src/main/java/com/sk89q/worldguard/bukkit/BukkitUtil.java +++ b/src/main/java/com/sk89q/worldguard/bukkit/BukkitUtil.java @@ -28,7 +28,7 @@ import org.bukkit.World; import org.bukkit.block.Block; import org.bukkit.entity.Entity; -import org.bukkit.entity.ExperienceOrb; +//import org.bukkit.entity.ExperienceOrb; import org.bukkit.entity.Item; import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; @@ -240,7 +240,7 @@ public static String replaceColorMacros(String str) { public static boolean isIntensiveEntity(Entity entity) { return entity instanceof Item || entity instanceof TNTPrimed - || entity instanceof ExperienceOrb +// || entity instanceof ExperienceOrb || (entity instanceof LivingEntity && !(entity instanceof Tameable) && !(entity instanceof Player)); diff --git a/src/main/java/com/sk89q/worldguard/bukkit/FlagStateManager.java b/src/main/java/com/sk89q/worldguard/bukkit/FlagStateManager.java index 096f8d136..b93d6c2c7 100644 --- a/src/main/java/com/sk89q/worldguard/bukkit/FlagStateManager.java +++ b/src/main/java/com/sk89q/worldguard/bukkit/FlagStateManager.java @@ -19,19 +19,17 @@ package com.sk89q.worldguard.bukkit; -import static com.sk89q.worldguard.bukkit.BukkitUtil.toVector; - -import java.util.HashMap; -import java.util.Map; - -import org.bukkit.GameMode; -import org.bukkit.World; -import org.bukkit.entity.Player; - import com.sk89q.worldedit.Vector; import com.sk89q.worldguard.protection.ApplicableRegionSet; import com.sk89q.worldguard.protection.flags.DefaultFlag; import com.sk89q.worldguard.protection.managers.RegionManager; +import org.bukkit.World; +import org.bukkit.entity.Player; + +import java.util.HashMap; +import java.util.Map; + +import static com.sk89q.worldguard.bukkit.BukkitUtil.toVector; /** * This processes per-player state information and is also meant to be used @@ -87,12 +85,13 @@ public void run() { .get(player.getWorld()); ApplicableRegionSet applicable = regionManager .getApplicableRegions(playerLocation); - + if (!RegionQueryUtil.isInvincible(plugin, player, applicable) && !plugin.getGlobalStateManager().hasGodMode(player) - && !(player.getGameMode() == GameMode.CREATIVE)) { +// && !(player.getGameMode() == GameMode.CREATIVE)) { + ) { processHeal(applicable, player, state); - processFeed(applicable, player, state); +// processFeed(applicable, player, state); } } } @@ -127,7 +126,7 @@ private void processHeal(ApplicableRegionSet applicable, Player player, if (player.getHealth() >= maxHealth && healAmount > 0) { return; } - + if (healDelay <= 0) { player.setHealth(healAmount > 0 ? maxHealth : minHealth); // this will insta-kill if the flag is unset state.lastHeal = now; @@ -137,43 +136,43 @@ private void processHeal(ApplicableRegionSet applicable, Player player, state.lastHeal = now; } } - - /** - * Process restoring hunger for a player. - * - * @param applicable - * @param player - * @param state - */ - private void processFeed(ApplicableRegionSet applicable, Player player, - PlayerFlagState state) { - Integer feedAmount = applicable.getFlag(DefaultFlag.FEED_AMOUNT); - Integer feedDelay = applicable.getFlag(DefaultFlag.FEED_DELAY); - Integer minHunger = applicable.getFlag(DefaultFlag.MIN_FOOD); - Integer maxHunger = applicable.getFlag(DefaultFlag.MAX_FOOD); - - if (feedAmount == null || feedDelay == null || feedAmount == 0 || feedDelay < 0) { - return; - } - if (minHunger == null) minHunger = 0; - if (maxHunger == null) maxHunger = 20; - - if (player.getFoodLevel() >= maxHunger && feedAmount > 0) { - return; - } - - if (feedDelay <= 0) { - player.setFoodLevel(feedAmount > 0 ? maxHunger : minHunger); // this will insta-kill if the flag is unset - } else { - // clamp health between minimum and maximum - player.setFoodLevel(Math.min(maxHunger, Math.max(minHunger, player.getFoodLevel() + feedAmount))); - } - } +// /** +// * Process restoring hunger for a player. +// * +// * @param applicable +// * @param player +// * @param state +// */ +// private void processFeed(ApplicableRegionSet applicable, Player player, +// PlayerFlagState state) { +// +// Integer feedAmount = applicable.getFlag(DefaultFlag.FEED_AMOUNT); +// Integer feedDelay = applicable.getFlag(DefaultFlag.FEED_DELAY); +// Integer minHunger = applicable.getFlag(DefaultFlag.MIN_FOOD); +// Integer maxHunger = applicable.getFlag(DefaultFlag.MAX_FOOD); +// +// if (feedAmount == null || feedDelay == null || feedAmount == 0 || feedDelay < 0) { +// return; +// } +// if (minHunger == null) minHunger = 0; +// if (maxHunger == null) maxHunger = 20; +// +// if (player.getFoodLevel() >= maxHunger && feedAmount > 0) { +// return; +// } +// +// if (feedDelay <= 0) { +// player.setFoodLevel(feedAmount > 0 ? maxHunger : minHunger); // this will insta-kill if the flag is unset +// } else { +// // clamp health between minimum and maximum +// player.setFoodLevel(Math.min(maxHunger, Math.max(minHunger, player.getFoodLevel() + feedAmount))); +// } +// } /** * Forget a player. - * + * * @param player */ public synchronized void forget(Player player) { diff --git a/src/main/java/com/sk89q/worldguard/bukkit/WorldGuardEntityListener.java b/src/main/java/com/sk89q/worldguard/bukkit/WorldGuardEntityListener.java index abbfca213..79cc528ca 100644 --- a/src/main/java/com/sk89q/worldguard/bukkit/WorldGuardEntityListener.java +++ b/src/main/java/com/sk89q/worldguard/bukkit/WorldGuardEntityListener.java @@ -23,6 +23,7 @@ import java.util.Set; import java.util.logging.Logger; +import com.legacyminecraft.poseidon.event.PlayerDeathEvent; import org.bukkit.ChatColor; import org.bukkit.Location; import org.bukkit.Material; @@ -45,8 +46,8 @@ import org.bukkit.event.Event.Priority; import org.bukkit.event.entity.CreatureSpawnEvent; import org.bukkit.event.entity.CreeperPowerEvent; -import org.bukkit.event.entity.EndermanPickupEvent; -import org.bukkit.event.entity.EndermanPlaceEvent; +//import org.bukkit.event.entity.EndermanPickupEvent; +//import org.bukkit.event.entity.EndermanPlaceEvent; import org.bukkit.event.entity.EntityCombustEvent; import org.bukkit.event.entity.EntityDamageByBlockEvent; import org.bukkit.event.entity.EntityDamageByEntityEvent; @@ -58,7 +59,7 @@ import org.bukkit.event.entity.EntityRegainHealthEvent; import org.bukkit.event.entity.ExplosionPrimeEvent; import org.bukkit.event.entity.PigZapEvent; -import org.bukkit.event.entity.PlayerDeathEvent; +//import org.bukkit.event.entity.PlayerDeathEvent; import org.bukkit.event.entity.EntityDamageEvent.DamageCause; import org.bukkit.event.painting.PaintingBreakByEntityEvent; import org.bukkit.event.painting.PaintingBreakEvent; @@ -157,9 +158,9 @@ public void onEntityInteract(EntityInteractEvent event) { @Override public void onEntityDeath(EntityDeathEvent event) { WorldConfiguration wcfg = plugin.getGlobalStateManager().get(event.getEntity().getWorld()); - if (wcfg.disableExpDrops) { - event.setDroppedExp(0); - } +// if (wcfg.disableExpDrops) { +// event.setDroppedExp(0); +// } if (event instanceof PlayerDeathEvent && wcfg.disableDeathMessages) { ((PlayerDeathEvent) event).setDeathMessage(""); } @@ -170,7 +171,7 @@ public void onEntityDeath(EntityDeathEvent event) { * * @param event */ - private void onEntityDamageByBlock(EntityDamageByBlockEvent event) { + public void onEntityDamageByBlock(EntityDamageByBlockEvent event) { Entity defender = event.getEntity(); DamageCause type = event.getCause(); @@ -224,7 +225,7 @@ private void onEntityDamageByBlock(EntityDamageByBlockEvent event) { * * @param event */ - private void onEntityDamageByEntity(EntityDamageByEntityEvent event) { + public void onEntityDamageByEntity(EntityDamageByEntityEvent event) { if (event.getCause() == DamageCause.PROJECTILE) { onEntityDamageByProjectile(event); return; @@ -796,61 +797,61 @@ public void onEntityRegainHealth(EntityRegainHealthEvent event) { } } - /** - * Called when an enderman picks a block up. - */ - @Override - public void onEndermanPickup(EndermanPickupEvent event) { - if (event.isCancelled()) { - return; - } - - Entity ent = event.getEntity(); - Block block = event.getBlock(); - - ConfigurationManager cfg = plugin.getGlobalStateManager(); - WorldConfiguration wcfg = cfg.get(ent.getWorld()); - - if (wcfg.disableEndermanGriefing) { - event.setCancelled(true); - return; - } - - if (wcfg.useRegions) { - if (!plugin.getGlobalRegionManager().allows(DefaultFlag.ENDER_BUILD, block.getLocation())) { - event.setCancelled(true); - return; - } - } - } - - /** - * Called when an enderman places a block. - */ - @Override - public void onEndermanPlace(EndermanPlaceEvent event) { - if (event.isCancelled()) { - return; - } - - Entity ent = event.getEntity(); - Location loc = event.getLocation(); - - ConfigurationManager cfg = plugin.getGlobalStateManager(); - WorldConfiguration wcfg = cfg.get(ent.getWorld()); - - if (wcfg.disableEndermanGriefing) { - event.setCancelled(true); - return; - } - - if (wcfg.useRegions) { - if (!plugin.getGlobalRegionManager().allows(DefaultFlag.ENDER_BUILD, loc)) { - event.setCancelled(true); - return; - } - } - } +// /** +// * Called when an enderman picks a block up. +// */ +// @Override +// public void onEndermanPickup(EndermanPickupEvent event) { +// if (event.isCancelled()) { +// return; +// } +// +// Entity ent = event.getEntity(); +// Block block = event.getBlock(); +// +// ConfigurationManager cfg = plugin.getGlobalStateManager(); +// WorldConfiguration wcfg = cfg.get(ent.getWorld()); +// +// if (wcfg.disableEndermanGriefing) { +// event.setCancelled(true); +// return; +// } +// +// if (wcfg.useRegions) { +// if (!plugin.getGlobalRegionManager().allows(DefaultFlag.ENDER_BUILD, block.getLocation())) { +// event.setCancelled(true); +// return; +// } +// } +// } +// +// /** +// * Called when an enderman places a block. +// */ +// @Override +// public void onEndermanPlace(EndermanPlaceEvent event) { +// if (event.isCancelled()) { +// return; +// } +// +// Entity ent = event.getEntity(); +// Location loc = event.getLocation(); +// +// ConfigurationManager cfg = plugin.getGlobalStateManager(); +// WorldConfiguration wcfg = cfg.get(ent.getWorld()); +// +// if (wcfg.disableEndermanGriefing) { +// event.setCancelled(true); +// return; +// } +// +// if (wcfg.useRegions) { +// if (!plugin.getGlobalRegionManager().allows(DefaultFlag.ENDER_BUILD, loc)) { +// event.setCancelled(true); +// return; +// } +// } +// } /** * Check if a player is invincible, via either god mode or region flag. If diff --git a/src/main/java/com/sk89q/worldguard/bukkit/WorldGuardPlayerListener.java b/src/main/java/com/sk89q/worldguard/bukkit/WorldGuardPlayerListener.java index 41c50e574..30613c76a 100644 --- a/src/main/java/com/sk89q/worldguard/bukkit/WorldGuardPlayerListener.java +++ b/src/main/java/com/sk89q/worldguard/bukkit/WorldGuardPlayerListener.java @@ -605,7 +605,7 @@ private void handleBlockRightClick(PlayerInteractEvent event) { || type == Material.DIODE_BLOCK_ON || type == Material.WOODEN_DOOR || type == Material.TRAP_DOOR - || type == Material.FENCE_GATE +// || type == Material.FENCE_GATE || type == Material.WORKBENCH) { if (!plugin.getGlobalRegionManager().hasBypass(player, world) && !set.allows(DefaultFlag.USE)