mirror of
https://github.com/songoda/UltimateStacker.git
synced 2024-11-23 10:35:22 +01:00
Merge branch 'development'
This commit is contained in:
commit
ac2315e1a8
7
pom.xml
7
pom.xml
@ -2,7 +2,7 @@
|
||||
<groupId>com.songoda</groupId>
|
||||
<artifactId>UltimateStacker</artifactId>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<version>2.1.2b</version>
|
||||
<version>2.1.3</version>
|
||||
<build>
|
||||
<defaultGoal>clean install</defaultGoal>
|
||||
<finalName>UltimateStacker-${project.version}</finalName>
|
||||
@ -126,11 +126,6 @@
|
||||
<artifactId>Lootables</artifactId>
|
||||
<version>1.0.8</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.gamingmesh</groupId>
|
||||
<artifactId>jobs</artifactId>
|
||||
<version>4.10.3</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.bgsoftware</groupId>
|
||||
<artifactId>wildstacker</artifactId>
|
||||
|
@ -192,9 +192,9 @@ public class UltimateStacker extends SongodaPlugin {
|
||||
pluginManager.registerEvents(new ClearLagListeners(this), this);
|
||||
|
||||
// Register Hooks
|
||||
if (pluginManager.isPluginEnabled("Jobs")) {
|
||||
if (pluginManager.isPluginEnabled("Jobs"))
|
||||
stackerHooks.add(new JobsHook());
|
||||
}
|
||||
|
||||
HologramManager.load(this);
|
||||
|
||||
// Database stuff, go!
|
||||
|
@ -1,30 +1,26 @@
|
||||
package com.songoda.ultimatestacker.hook.hooks;
|
||||
|
||||
import com.gamingmesh.jobs.Jobs;
|
||||
import com.gamingmesh.jobs.actions.EntityActionInfo;
|
||||
import com.gamingmesh.jobs.container.ActionType;
|
||||
import com.gamingmesh.jobs.container.JobsPlayer;
|
||||
import com.songoda.core.hooks.jobs.JobsPlayerHandler;
|
||||
import com.songoda.ultimatestacker.hook.StackerHook;
|
||||
import com.songoda.ultimatestacker.stackable.entity.EntityStack;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class JobsHook implements StackerHook {
|
||||
|
||||
@Override
|
||||
public void applyExperience(Player player, EntityStack entityStack) {
|
||||
if (player.getGameMode().equals(GameMode.CREATIVE))
|
||||
if (player.getGameMode().equals(GameMode.CREATIVE) || entityStack.getHostEntity() == null)
|
||||
return;
|
||||
|
||||
JobsPlayer jPlayer = Jobs.getPlayerManager().getJobsPlayer(player);
|
||||
JobsPlayerHandler jPlayer = com.songoda.core.hooks.JobsHook.getPlayer(player);
|
||||
if (jPlayer == null)
|
||||
return;
|
||||
|
||||
for (int i = 1; i < entityStack.getAmount(); i++) {
|
||||
Entity entity = entityStack.getHostEntity();
|
||||
EntityActionInfo eInfo = new EntityActionInfo(entity, ActionType.KILL);
|
||||
Jobs.action(jPlayer, eInfo, entity);
|
||||
LivingEntity entity = entityStack.getHostEntity();
|
||||
jPlayer.killEntity(entity);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -11,6 +11,7 @@ import org.bukkit.GameRule;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.entity.ChestedHorse;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
@ -18,13 +19,17 @@ import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||
import org.bukkit.event.entity.EntityDamageEvent;
|
||||
import org.bukkit.event.entity.EntityDeathEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
import java.util.UUID;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class DeathListeners implements Listener {
|
||||
@ -37,8 +42,23 @@ public class DeathListeners implements Listener {
|
||||
this.random = new Random();
|
||||
}
|
||||
|
||||
|
||||
private final Map<UUID, List<ItemStack>> finalItems = new HashMap<>();
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
|
||||
public void onEntityDamage(EntityDamageEvent event) {
|
||||
if (!(event.getEntity() instanceof LivingEntity))
|
||||
return;
|
||||
LivingEntity entity = (LivingEntity) event.getEntity();
|
||||
|
||||
if (entity.getHealth() - event.getFinalDamage() < 0)
|
||||
finalItems.put(entity.getUniqueId(), getItems(entity));
|
||||
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
|
||||
public void onEntityDeath(EntityDeathEvent event) {
|
||||
LivingEntity entity = event.getEntity();
|
||||
if (event.getEntityType() == EntityType.PLAYER
|
||||
|| event.getEntityType() == EntityType.ARMOR_STAND) return;
|
||||
|
||||
@ -54,26 +74,26 @@ public class DeathListeners implements Listener {
|
||||
}
|
||||
|
||||
if (ServerVersion.isServerVersionAtLeast(ServerVersion.V1_13)
|
||||
&& !event.getEntity().getWorld().getGameRuleValue(GameRule.DO_MOB_LOOT))
|
||||
&& !entity.getWorld().getGameRuleValue(GameRule.DO_MOB_LOOT))
|
||||
drops.clear();
|
||||
|
||||
if (plugin.getEntityStackManager().isStackedAndLoaded(event.getEntity()))
|
||||
plugin.getEntityStackManager().getStack(event.getEntity())
|
||||
.onDeath(event.getEntity(), drops, custom, event.getDroppedExp(), event);
|
||||
.onDeath(entity, drops, custom, event.getDroppedExp(), event);
|
||||
else
|
||||
DropUtils.processStackedDrop(event.getEntity(), drops, event);
|
||||
finalItems.remove(entity.getUniqueId());
|
||||
}
|
||||
|
||||
private boolean shouldDrop(LivingEntity entity, Material material) {
|
||||
if (entity.getEquipment() != null && entity.getEquipment().getArmorContents().length != 0) {
|
||||
List<ItemStack> items = new ArrayList<>(Arrays.asList(entity.getEquipment().getArmorContents()));
|
||||
items.add(entity.getEquipment().getItemInHand());
|
||||
if (ServerVersion.isServerVersionAtLeast(ServerVersion.V1_9))
|
||||
items.add(entity.getEquipment().getItemInOffHand());
|
||||
if (finalItems.containsKey(entity.getUniqueId())) {
|
||||
List<ItemStack> items = finalItems.get(entity.getUniqueId());
|
||||
for (ItemStack item : items)
|
||||
if (item.getType() == material)
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if (ServerVersion.isServerVersionAtLeast(ServerVersion.V1_11)
|
||||
&& entity instanceof ChestedHorse
|
||||
&& ((ChestedHorse) entity).getInventory().contains(material))
|
||||
@ -110,6 +130,17 @@ public class DeathListeners implements Listener {
|
||||
}
|
||||
}
|
||||
|
||||
public List<ItemStack> getItems(LivingEntity entity) {
|
||||
if (entity.getEquipment() != null && entity.getEquipment().getArmorContents().length != 0) {
|
||||
List<ItemStack> items = new ArrayList<>(Arrays.asList(entity.getEquipment().getArmorContents()));
|
||||
items.add(entity.getEquipment().getItemInHand());
|
||||
if (ServerVersion.isServerVersionAtLeast(ServerVersion.V1_9))
|
||||
items.add(entity.getEquipment().getItemInOffHand());
|
||||
return items;
|
||||
}
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onEntityHit(EntityDamageByEntityEvent event) {
|
||||
if (!(event.getDamager() instanceof Player) || ServerVersion.isServerVersionAtOrBelow(ServerVersion.V1_12))
|
||||
|
Loading…
Reference in New Issue
Block a user