Skip to content

Commit

Permalink
Fixed #17 where you can attack Mobs.
Browse files Browse the repository at this point in the history
  • Loading branch information
larryTheCoder committed Aug 20, 2020
1 parent 3bac927 commit 46565f7
Show file tree
Hide file tree
Showing 7 changed files with 121 additions and 14 deletions.
Binary file added lib/MobPlugin-1.15.0.jar
Binary file not shown.
18 changes: 18 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,13 @@
<version>5.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>foo.bar</groupId>
<artifactId>mobplugin</artifactId>
<version>1.15.0</version>
<scope>system</scope>
<systemPath>${basedir}/lib/MobPlugin-1.15.0.jar</systemPath>
</dependency>
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
Expand Down Expand Up @@ -200,6 +207,17 @@
<goals>
<goal>shade</goal>
</goals>
<configuration>
<createDependencyReducedPom>false</createDependencyReducedPom>
<filters>
<filter>
<artifact>foo.bar:mobplugin:jar:1.15.0</artifact>
<excludes>
<exclude>*</exclude>
</excludes>
</filter>
</filters>
</configuration>
</execution>
</executions>

Expand Down
10 changes: 7 additions & 3 deletions src/main/java/com/larryTheCoder/ASkyBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@
import com.larryTheCoder.cache.FastCache;
import com.larryTheCoder.cache.settings.WorldSettings;
import com.larryTheCoder.command.Commands;
import com.larryTheCoder.database.config.AbstractConfig;
import com.larryTheCoder.database.config.MySQLConfig;
import com.larryTheCoder.database.config.SQLiteConfig;
import com.larryTheCoder.database.Database;
import com.larryTheCoder.database.QueryDb;
import com.larryTheCoder.database.QueryInfo;
import com.larryTheCoder.database.config.AbstractConfig;
import com.larryTheCoder.database.config.MySQLConfig;
import com.larryTheCoder.database.config.SQLiteConfig;
import com.larryTheCoder.island.GridManager;
import com.larryTheCoder.island.IslandManager;
import com.larryTheCoder.island.TeleportLogic;
Expand All @@ -54,6 +54,7 @@
import com.larryTheCoder.listener.LavaCheck;
import com.larryTheCoder.listener.PlayerEvent;
import com.larryTheCoder.listener.invitation.InvitationHandler;
import com.larryTheCoder.listener.nms.MobPluginListener;
import com.larryTheCoder.locales.LocaleInstance;
import com.larryTheCoder.locales.LocaleManager;
import com.larryTheCoder.schematic.SchematicHandler;
Expand Down Expand Up @@ -221,6 +222,9 @@ private void initIslands() {
pm.registerEvents(new IslandListener(this), this);
pm.registerEvents(new LavaCheck(this), this);
pm.registerEvents(new PlayerEvent(this), this);
if (getServer().getPluginManager().getPlugin("MobPlugin") != null) {
pm.registerEvents(new MobPluginListener(this), this);
}
}

private void loadPermissionNodes() {
Expand Down
18 changes: 8 additions & 10 deletions src/main/java/com/larryTheCoder/listener/IslandListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@
package com.larryTheCoder.listener;

import cn.nukkit.Player;
import cn.nukkit.block.Block;
import cn.nukkit.block.BlockLava;
import cn.nukkit.entity.Entity;
import cn.nukkit.entity.item.EntityPrimedTNT;
import cn.nukkit.entity.mob.EntityMob;
Expand All @@ -43,7 +41,10 @@
import cn.nukkit.event.entity.EntityExplodeEvent;
import cn.nukkit.event.inventory.CraftItemEvent;
import cn.nukkit.event.inventory.InventoryPickupItemEvent;
import cn.nukkit.event.player.*;
import cn.nukkit.event.player.PlayerCommandPreprocessEvent;
import cn.nukkit.event.player.PlayerDropItemEvent;
import cn.nukkit.event.player.PlayerInteractEvent;
import cn.nukkit.event.player.PlayerMoveEvent;
import cn.nukkit.utils.TextFormat;
import com.larryTheCoder.ASkyBlock;
import com.larryTheCoder.cache.IslandData;
Expand Down Expand Up @@ -158,20 +159,17 @@ public void onPlayerExecuteCommand(PlayerCommandPreprocessEvent event) {
}
}

@EventHandler(priority = EventPriority.LOW)
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onPlayerHitEvent(EntityDamageEvent e) {
Entity target = e.getEntity();

if (notInWorld(target)) return;
if (e instanceof EntityDamageByEntityEvent) {
EntityDamageByEntityEvent damage = (EntityDamageByEntityEvent) e;
Entity cause = damage.getDamager();

// Identifier for player mobs attack.
if (!(cause instanceof Player)) {
if (cause instanceof EntityAnimal) {
if (!(target instanceof Player)) {
if (target instanceof EntityAnimal) {
if (actionAllowed(target.getLocation(), SettingsFlag.HURT_MOBS)) return;
} else if (cause instanceof EntityMob) {
} else if (target instanceof EntityMob) {
if (actionAllowed(target.getLocation(), SettingsFlag.HURT_MONSTERS)) return;
}
} else {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
/*
* Adapted from the Wizardry License
*
* Copyright (c) 2016-2020 larryTheCoder and contributors
*
* Permission is hereby granted to any persons and/or organizations
* using this software to copy, modify, merge, publish, and distribute it.
* Said persons and/or organizations are not allowed to use the software or
* any derivatives of the work for commercial use or any other means to generate
* income, nor are they allowed to claim this software as their own.
*
* The persons and/or organizations are also disallowed from sub-licensing
* and/or trademarking this software without explicit permission from larryTheCoder.
*
* Any persons and/or organizations using this software must disclose their
* source code and have it publicly available, include this license,
* provide sufficient credit to the original authors of the project (IE: larryTheCoder),
* as well as provide a link to the original project.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,FITNESS FOR A PARTICULAR
* PURPOSE AND NON INFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
* USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

package com.larryTheCoder.listener.nms;

import cn.nukkit.Player;
import cn.nukkit.entity.Entity;
import cn.nukkit.entity.mob.EntityMob;
import cn.nukkit.entity.passive.EntityAnimal;
import cn.nukkit.event.EventHandler;
import cn.nukkit.event.EventPriority;
import cn.nukkit.event.Listener;
import cn.nukkit.event.entity.EntityDamageByEntityEvent;
import cn.nukkit.event.entity.EntityDamageEvent;
import com.larryTheCoder.ASkyBlock;
import com.larryTheCoder.listener.Action;
import com.larryTheCoder.utils.SettingsFlag;
import lombok.extern.log4j.Log4j2;
import nukkitcoders.mobplugin.entities.animal.Animal;
import nukkitcoders.mobplugin.entities.monster.Monster;

@Log4j2
public class MobPluginListener extends Action implements Listener {

public MobPluginListener(ASkyBlock plugin) {
super(plugin);

log.debug("Using MobPlugin");
}

@EventHandler(priority = EventPriority.LOWEST)
public void onPlayerHitEvent(EntityDamageEvent e) {
log.debug("DEBUG: " + e.getEventName());
log.debug("DEBUG: NMS MobPlugin notation.");

Entity target = e.getEntity();

if (notInWorld(target)) return;
if (e instanceof EntityDamageByEntityEvent) {
// Identifier for player mobs attack.
if (!(target instanceof Player)) {
log.debug("Target is not a player.");

if (target instanceof Animal) {
log.debug("Target is not an animal.");

if (actionAllowed(target.getLocation(), SettingsFlag.HURT_MOBS)) return;
} else if (target instanceof Monster) {
log.debug("Target is not a monster.");

if (actionAllowed(target.getLocation(), SettingsFlag.HURT_MONSTERS)) return;
}
} else {
log.debug("Target is a player");
if (actionAllowed(target.getLocation(), SettingsFlag.PVP)) return;
}

log.debug("Target cancelled.");

e.setCancelled();
}
}
}
1 change: 0 additions & 1 deletion src/main/java/com/larryTheCoder/task/LevelCalcTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@

package com.larryTheCoder.task;

import cn.nukkit.Player;
import cn.nukkit.Server;
import cn.nukkit.block.Block;
import cn.nukkit.level.Level;
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ softdepend:
- EconomyAPI
- LuckPerms
- DbLib
- MobPlugin

description: "Advanced minecraft PE SkyBlock plugin!"

Expand Down

0 comments on commit 46565f7

Please sign in to comment.