Skip to content

Commit 46565f7

Browse files
committed
Fixed #17 where you can attack Mobs.
1 parent 3bac927 commit 46565f7

7 files changed

Lines changed: 121 additions & 14 deletions

File tree

lib/MobPlugin-1.15.0.jar

342 KB
Binary file not shown.

pom.xml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,13 @@
106106
<version>5.0</version>
107107
<scope>provided</scope>
108108
</dependency>
109+
<dependency>
110+
<groupId>foo.bar</groupId>
111+
<artifactId>mobplugin</artifactId>
112+
<version>1.15.0</version>
113+
<scope>system</scope>
114+
<systemPath>${basedir}/lib/MobPlugin-1.15.0.jar</systemPath>
115+
</dependency>
109116
<dependency>
110117
<groupId>org.json</groupId>
111118
<artifactId>json</artifactId>
@@ -200,6 +207,17 @@
200207
<goals>
201208
<goal>shade</goal>
202209
</goals>
210+
<configuration>
211+
<createDependencyReducedPom>false</createDependencyReducedPom>
212+
<filters>
213+
<filter>
214+
<artifact>foo.bar:mobplugin:jar:1.15.0</artifact>
215+
<excludes>
216+
<exclude>*</exclude>
217+
</excludes>
218+
</filter>
219+
</filters>
220+
</configuration>
203221
</execution>
204222
</executions>
205223

src/main/java/com/larryTheCoder/ASkyBlock.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,12 @@
3939
import com.larryTheCoder.cache.FastCache;
4040
import com.larryTheCoder.cache.settings.WorldSettings;
4141
import com.larryTheCoder.command.Commands;
42-
import com.larryTheCoder.database.config.AbstractConfig;
43-
import com.larryTheCoder.database.config.MySQLConfig;
44-
import com.larryTheCoder.database.config.SQLiteConfig;
4542
import com.larryTheCoder.database.Database;
4643
import com.larryTheCoder.database.QueryDb;
4744
import com.larryTheCoder.database.QueryInfo;
45+
import com.larryTheCoder.database.config.AbstractConfig;
46+
import com.larryTheCoder.database.config.MySQLConfig;
47+
import com.larryTheCoder.database.config.SQLiteConfig;
4848
import com.larryTheCoder.island.GridManager;
4949
import com.larryTheCoder.island.IslandManager;
5050
import com.larryTheCoder.island.TeleportLogic;
@@ -54,6 +54,7 @@
5454
import com.larryTheCoder.listener.LavaCheck;
5555
import com.larryTheCoder.listener.PlayerEvent;
5656
import com.larryTheCoder.listener.invitation.InvitationHandler;
57+
import com.larryTheCoder.listener.nms.MobPluginListener;
5758
import com.larryTheCoder.locales.LocaleInstance;
5859
import com.larryTheCoder.locales.LocaleManager;
5960
import com.larryTheCoder.schematic.SchematicHandler;
@@ -221,6 +222,9 @@ private void initIslands() {
221222
pm.registerEvents(new IslandListener(this), this);
222223
pm.registerEvents(new LavaCheck(this), this);
223224
pm.registerEvents(new PlayerEvent(this), this);
225+
if (getServer().getPluginManager().getPlugin("MobPlugin") != null) {
226+
pm.registerEvents(new MobPluginListener(this), this);
227+
}
224228
}
225229

226230
private void loadPermissionNodes() {

src/main/java/com/larryTheCoder/listener/IslandListener.java

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@
2727
package com.larryTheCoder.listener;
2828

2929
import cn.nukkit.Player;
30-
import cn.nukkit.block.Block;
31-
import cn.nukkit.block.BlockLava;
3230
import cn.nukkit.entity.Entity;
3331
import cn.nukkit.entity.item.EntityPrimedTNT;
3432
import cn.nukkit.entity.mob.EntityMob;
@@ -43,7 +41,10 @@
4341
import cn.nukkit.event.entity.EntityExplodeEvent;
4442
import cn.nukkit.event.inventory.CraftItemEvent;
4543
import cn.nukkit.event.inventory.InventoryPickupItemEvent;
46-
import cn.nukkit.event.player.*;
44+
import cn.nukkit.event.player.PlayerCommandPreprocessEvent;
45+
import cn.nukkit.event.player.PlayerDropItemEvent;
46+
import cn.nukkit.event.player.PlayerInteractEvent;
47+
import cn.nukkit.event.player.PlayerMoveEvent;
4748
import cn.nukkit.utils.TextFormat;
4849
import com.larryTheCoder.ASkyBlock;
4950
import com.larryTheCoder.cache.IslandData;
@@ -158,20 +159,17 @@ public void onPlayerExecuteCommand(PlayerCommandPreprocessEvent event) {
158159
}
159160
}
160161

161-
@EventHandler(priority = EventPriority.LOW)
162+
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
162163
public void onPlayerHitEvent(EntityDamageEvent e) {
163164
Entity target = e.getEntity();
164165

165166
if (notInWorld(target)) return;
166167
if (e instanceof EntityDamageByEntityEvent) {
167-
EntityDamageByEntityEvent damage = (EntityDamageByEntityEvent) e;
168-
Entity cause = damage.getDamager();
169-
170168
// Identifier for player mobs attack.
171-
if (!(cause instanceof Player)) {
172-
if (cause instanceof EntityAnimal) {
169+
if (!(target instanceof Player)) {
170+
if (target instanceof EntityAnimal) {
173171
if (actionAllowed(target.getLocation(), SettingsFlag.HURT_MOBS)) return;
174-
} else if (cause instanceof EntityMob) {
172+
} else if (target instanceof EntityMob) {
175173
if (actionAllowed(target.getLocation(), SettingsFlag.HURT_MONSTERS)) return;
176174
}
177175
} else {
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
/*
2+
* Adapted from the Wizardry License
3+
*
4+
* Copyright (c) 2016-2020 larryTheCoder and contributors
5+
*
6+
* Permission is hereby granted to any persons and/or organizations
7+
* using this software to copy, modify, merge, publish, and distribute it.
8+
* Said persons and/or organizations are not allowed to use the software or
9+
* any derivatives of the work for commercial use or any other means to generate
10+
* income, nor are they allowed to claim this software as their own.
11+
*
12+
* The persons and/or organizations are also disallowed from sub-licensing
13+
* and/or trademarking this software without explicit permission from larryTheCoder.
14+
*
15+
* Any persons and/or organizations using this software must disclose their
16+
* source code and have it publicly available, include this license,
17+
* provide sufficient credit to the original authors of the project (IE: larryTheCoder),
18+
* as well as provide a link to the original project.
19+
*
20+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
21+
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,FITNESS FOR A PARTICULAR
22+
* PURPOSE AND NON INFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
23+
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
24+
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
25+
* USE OR OTHER DEALINGS IN THE SOFTWARE.
26+
*/
27+
28+
package com.larryTheCoder.listener.nms;
29+
30+
import cn.nukkit.Player;
31+
import cn.nukkit.entity.Entity;
32+
import cn.nukkit.entity.mob.EntityMob;
33+
import cn.nukkit.entity.passive.EntityAnimal;
34+
import cn.nukkit.event.EventHandler;
35+
import cn.nukkit.event.EventPriority;
36+
import cn.nukkit.event.Listener;
37+
import cn.nukkit.event.entity.EntityDamageByEntityEvent;
38+
import cn.nukkit.event.entity.EntityDamageEvent;
39+
import com.larryTheCoder.ASkyBlock;
40+
import com.larryTheCoder.listener.Action;
41+
import com.larryTheCoder.utils.SettingsFlag;
42+
import lombok.extern.log4j.Log4j2;
43+
import nukkitcoders.mobplugin.entities.animal.Animal;
44+
import nukkitcoders.mobplugin.entities.monster.Monster;
45+
46+
@Log4j2
47+
public class MobPluginListener extends Action implements Listener {
48+
49+
public MobPluginListener(ASkyBlock plugin) {
50+
super(plugin);
51+
52+
log.debug("Using MobPlugin");
53+
}
54+
55+
@EventHandler(priority = EventPriority.LOWEST)
56+
public void onPlayerHitEvent(EntityDamageEvent e) {
57+
log.debug("DEBUG: " + e.getEventName());
58+
log.debug("DEBUG: NMS MobPlugin notation.");
59+
60+
Entity target = e.getEntity();
61+
62+
if (notInWorld(target)) return;
63+
if (e instanceof EntityDamageByEntityEvent) {
64+
// Identifier for player mobs attack.
65+
if (!(target instanceof Player)) {
66+
log.debug("Target is not a player.");
67+
68+
if (target instanceof Animal) {
69+
log.debug("Target is not an animal.");
70+
71+
if (actionAllowed(target.getLocation(), SettingsFlag.HURT_MOBS)) return;
72+
} else if (target instanceof Monster) {
73+
log.debug("Target is not a monster.");
74+
75+
if (actionAllowed(target.getLocation(), SettingsFlag.HURT_MONSTERS)) return;
76+
}
77+
} else {
78+
log.debug("Target is a player");
79+
if (actionAllowed(target.getLocation(), SettingsFlag.PVP)) return;
80+
}
81+
82+
log.debug("Target cancelled.");
83+
84+
e.setCancelled();
85+
}
86+
}
87+
}

src/main/java/com/larryTheCoder/task/LevelCalcTask.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727

2828
package com.larryTheCoder.task;
2929

30-
import cn.nukkit.Player;
3130
import cn.nukkit.Server;
3231
import cn.nukkit.block.Block;
3332
import cn.nukkit.level.Level;

src/main/resources/plugin.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ softdepend:
1818
- EconomyAPI
1919
- LuckPerms
2020
- DbLib
21+
- MobPlugin
2122

2223
description: "Advanced minecraft PE SkyBlock plugin!"
2324

0 commit comments

Comments
 (0)