This repository has been archived by the owner on Feb 20, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from TheWylot/dev/v2.0.0
V2.0.2 - Implemented Protection Plugins
- Loading branch information
Showing
8 changed files
with
378 additions
and
164 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
99 changes: 99 additions & 0 deletions
99
src/main/java/ir/wy/wycore/behind/support/protection/ProtectionManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
package ir.wy.wycore.behind.support.protection; | ||
|
||
import org.bukkit.Location; | ||
import org.bukkit.block.Block; | ||
import org.bukkit.entity.LivingEntity; | ||
import org.bukkit.entity.Player; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
import java.util.HashSet; | ||
import java.util.Set; | ||
|
||
public final class ProtectionManager { | ||
|
||
private static final Set<ProtectionSupport> REGISTERED = new HashSet<>(); | ||
|
||
/** | ||
* Register a new AntiGrief/Land Management integration. | ||
* | ||
* @param antigrief The integration to register. | ||
*/ | ||
public static void register(@NotNull final ProtectionSupport antigrief) { | ||
REGISTERED.removeIf(it -> it.getPluginName().equalsIgnoreCase(antigrief.getPluginName())); | ||
REGISTERED.add(antigrief); | ||
} | ||
|
||
/** | ||
* Unregister an AntiGrief/Land Management integration. | ||
* | ||
* @param antigrief The integration to unregister. | ||
*/ | ||
public static void unregister(@NotNull final ProtectionSupport antigrief) { | ||
REGISTERED.removeIf(it -> it.getPluginName().equalsIgnoreCase(antigrief.getPluginName())); | ||
REGISTERED.remove(antigrief); | ||
} | ||
|
||
/** | ||
* Can player pickup item. | ||
* | ||
* @param player The player. | ||
* @param location The location. | ||
* @return If player can pick up item. | ||
*/ | ||
public static boolean canPickupItem(@NotNull final Player player, | ||
@NotNull final Location location) { | ||
return REGISTERED.stream().allMatch(antigriefIntegration -> antigriefIntegration.canPickupItem(player, location)); | ||
} | ||
|
||
/** | ||
* Can player break block. | ||
* | ||
* @param player The player. | ||
* @param block The block. | ||
* @return If player can break block. | ||
*/ | ||
public static boolean canBreakBlock(@NotNull final Player player, | ||
@NotNull final Block block) { | ||
return REGISTERED.stream().allMatch(antigriefIntegration -> antigriefIntegration.canBreakBlock(player, block)); | ||
} | ||
|
||
/** | ||
* Can player create explosion at location. | ||
* | ||
* @param player The player. | ||
* @param location The location. | ||
* @return If player can create explosion. | ||
*/ | ||
public static boolean canCreateExplosion(@NotNull final Player player, | ||
@NotNull final Location location) { | ||
return REGISTERED.stream().allMatch(antigriefIntegration -> antigriefIntegration.canCreateExplosion(player, location)); | ||
} | ||
|
||
/** | ||
* Can player place block. | ||
* | ||
* @param player The player. | ||
* @param block The block. | ||
* @return If player can place block. | ||
*/ | ||
public static boolean canPlaceBlock(@NotNull final Player player, | ||
@NotNull final Block block) { | ||
return REGISTERED.stream().allMatch(antigriefIntegration -> antigriefIntegration.canPlaceBlock(player, block)); | ||
} | ||
|
||
/** | ||
* Can player injure living entity. | ||
* | ||
* @param player The player. | ||
* @param victim The victim. | ||
* @return If player can injure. | ||
*/ | ||
public static boolean canInjure(@NotNull final Player player, | ||
@NotNull final LivingEntity victim) { | ||
return REGISTERED.stream().allMatch(antigriefIntegration -> antigriefIntegration.canInjure(player, victim)); | ||
} | ||
|
||
private ProtectionManager() { | ||
throw new UnsupportedOperationException("This is a utility class and cannot be instantiated"); | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
src/main/java/ir/wy/wycore/behind/support/protection/ProtectionSupport.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package ir.wy.wycore.behind.support.protection; | ||
|
||
import ir.wy.wycore.spigot.support.Support; | ||
import org.bukkit.Location; | ||
import org.bukkit.block.Block; | ||
import org.bukkit.entity.LivingEntity; | ||
import org.bukkit.entity.Player; | ||
|
||
import org.jetbrains.annotations.NotNull; | ||
|
||
public interface ProtectionSupport extends Support { | ||
|
||
boolean canBreakBlock(@NotNull Player player, @NotNull Block block); | ||
|
||
boolean canCreateExplosion(@NotNull Player player, @NotNull Location location); | ||
|
||
boolean canPlaceBlock(@NotNull Player player, @NotNull Block block); | ||
|
||
boolean canInjure(@NotNull Player player, @NotNull LivingEntity victim); | ||
|
||
default boolean canPickupItem(@NotNull Player player, @NotNull Location location) { | ||
return true; | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
41 changes: 41 additions & 0 deletions
41
src/main/java/ir/wy/wycore/spigot/support/protection/DeluxeCombat.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package ir.wy.wycore.spigot.support.protection | ||
|
||
import ir.wy.wycore.behind.support.protection.ProtectionSupport; | ||
|
||
import nl.marido.deluxecombat.api.DeluxeCombatAPI | ||
import org.bukkit.Location | ||
import org.bukkit.block.Block | ||
import org.bukkit.entity.LivingEntity | ||
import org.bukkit.entity.Player | ||
|
||
class DeluxeCombat : ProtectionSupport { | ||
override fun getPluginName(): String { | ||
return "DeluxeCombat" | ||
} | ||
|
||
override fun canBreakBlock(player: Player, block: Block): Boolean { | ||
return true | ||
} | ||
|
||
override fun canCreateExplosion(player: Player, location: Location): Boolean { | ||
return true | ||
} | ||
|
||
override fun canPlaceBlock(player: Player, block: Block): Boolean { | ||
return true | ||
} | ||
|
||
override fun canInjure(player: Player, victim: LivingEntity): Boolean { | ||
val api = DeluxeCombatAPI() | ||
return when(victim) { | ||
is Player -> { | ||
if (api.hasProtection(player) || !api.hasPvPEnabled(player)) false | ||
else ((!api.hasProtection(victim) && api.hasPvPEnabled(victim)) || api.isInCombat(victim))} | ||
else -> true | ||
} | ||
} | ||
|
||
override fun canPickupItem(player: Player, location: Location): Boolean { | ||
return true | ||
} | ||
} |
Oops, something went wrong.