Skip to content
This repository has been archived by the owner on Feb 20, 2024. It is now read-only.

Commit

Permalink
Merge pull request #2 from TheWylot/dev/v2.0.0
Browse files Browse the repository at this point in the history
V2.0.2 - Implemented Protection Plugins
  • Loading branch information
TheWylot authored Feb 8, 2023
2 parents 20913cf + a6ad493 commit 127da89
Show file tree
Hide file tree
Showing 8 changed files with 378 additions and 164 deletions.
30 changes: 28 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<groupId>ir.wy</groupId>
<artifactId>WyCore</artifactId>
<packaging>jar</packaging>
<version>2.0.1</version>
<version>2.0.2</version>


<properties>
Expand Down Expand Up @@ -296,7 +296,33 @@
<artifactId>WorldEdit</artifactId>
<version>7.2.10</version>
</dependency>

<dependency>
<groupId>com.sk89q.worldguard</groupId>
<artifactId>worldguard-bukkit</artifactId>
<version>PROVIDED</version>
<scope>system</scope>
<systemPath>${project.basedir}/libs/WorldGuard-7.1.0.jar</systemPath>
</dependency>
<dependency>
<groupId>ir.wy.deluxecombat</groupId>
<artifactId>deluxecombat-api</artifactId>
<version>PROVIDED</version>
<scope>system</scope>
<systemPath>${project.basedir}/libs/DeluxeCombat-API-1.0.jar</systemPath>
</dependency>
<dependency>
<groupId>com.sk89q.worldguard</groupId>
<artifactId>worldguard-core</artifactId>
<version>7.0.5</version>
<scope>system</scope>
<systemPath>${project.basedir}/libs/WorldGuard-API.jar</systemPath>
</dependency>
<dependency>
<groupId>com.github.TechFortress</groupId>
<artifactId>GriefPrevention</artifactId>
<version>16.18</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-test</artifactId>
Expand Down
3 changes: 0 additions & 3 deletions src/main/java/ir/wy/wycore/WyCore.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package ir.wy.wycore;

import io.papermc.lib.PaperLib;
import ir.wy.wycore.spigot.Heart;
import ir.wy.wycore.spigot.gui.GUI;
import lombok.Getter;
import lombok.NoArgsConstructor;
Expand All @@ -21,7 +20,6 @@ public class WyCore extends JavaPlugin {
private static WyCore instance;
private BukkitTask saveTask;
private boolean isTesting = false;
private Heart heart;

// Testing & Debug Logger
public WyCore(JavaPluginLoader loader, PluginDescriptionFile description, File dataFolder, File file) {
Expand All @@ -38,7 +36,6 @@ public static WyCore getInstance() {
public void onLoad() {
getDataFolder().mkdirs();

this.heart = new Heart(Heart.HeartType.YAML, this);
loadConfigs();
saveConfigs();
}
Expand Down
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");
}
}
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;
}
}
159 changes: 0 additions & 159 deletions src/main/java/ir/wy/wycore/spigot/Heart.java

This file was deleted.

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
}
}
Loading

0 comments on commit 127da89

Please sign in to comment.