1
mirror of https://github.com/StarWishsama/Slimefun4.git synced 2024-09-20 19:55:48 +00:00

Did the requested changes

This commit is contained in:
LinoxGH 2020-06-26 23:59:40 +03:00
parent 207cb35dda
commit f1aa8a08d0
4 changed files with 37 additions and 67 deletions

View File

@ -7,8 +7,11 @@ import java.util.Map;
import java.util.Set;
import java.util.UUID;
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem;
import org.bukkit.Bukkit;
import org.bukkit.GameMode;
import org.bukkit.Material;
import org.bukkit.Sound;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.enchantments.Enchantment;
@ -63,8 +66,10 @@ public class ClimbingPick extends SimpleSlimefunItem<ItemUseHandler> implements
materialSpeedsDef.put(Material.DIORITE.name(), 0.6D);
materialSpeedsDef.put(Material.GRANITE.name(), 0.6D);
materialSpeedsDef.put(Material.ANDESITE.name(), 0.6D);
if (SlimefunPlugin.getMinecraftVersion().isAtLeast(MinecraftVersion.MINECRAFT_1_16)) materialSpeedsDef.put(Material.BLACKSTONE.name(), 0.6D);
materialSpeedsDef.put(Material.NETHERRACK.name(), 0.6D);
if (SlimefunPlugin.getMinecraftVersion().isAtLeast(MinecraftVersion.MINECRAFT_1_16)) {
materialSpeedsDef.put(Material.BLACKSTONE.name(), 0.6D);
}
addItemSetting(materialSpeeds);
}
@ -80,7 +85,8 @@ public class ClimbingPick extends SimpleSlimefunItem<ItemUseHandler> implements
@Override
public ItemUseHandler getItemHandler() {
return e -> {
if (e.getClickedBlock().isPresent()) {
if (!e.getClickedBlock().isPresent()) return;
Block block = e.getClickedBlock().get();
ItemStack item = e.getItem();
Player p = e.getPlayer();
@ -95,19 +101,26 @@ public class ClimbingPick extends SimpleSlimefunItem<ItemUseHandler> implements
}
Material mat = block.getType();
if (materialSpeeds.getValue().containsKey(mat.name())) {
double launch = materialSpeeds.getValue().get(mat.name());
if (item.getEnchantments().containsKey(Enchantment.DIG_SPEED)) {
launch += (item.getEnchantmentLevel(Enchantment.DIG_SPEED) * 0.2);
Double launch = materialSpeeds.getValue().get(mat.name());
if (launch != null) {
Integer efficiencyLevel = item.getEnchantments().get(Enchantment.DIG_SPEED);
if (efficiencyLevel != null){
launch += (efficiencyLevel * 0.2);
}
velocity = velocity.setY(velocity.getY() + launch);
}
users.add(p.getUniqueId());
Bukkit.getScheduler().runTaskLaterAsynchronously(SlimefunPlugin.instance, () -> users.remove(p.getUniqueId()), 4L);
}
ClimbingPickLaunchEvent event = new ClimbingPickLaunchEvent(p, velocity, item);
Bukkit.getPluginManager().callEvent(event);
p.setVelocity(event.getVelocity());
p.playSound(p.getLocation(), Sound.ENTITY_ENDERMAN_TELEPORT, 1F, 1F);
if (p.getGameMode() != GameMode.CREATIVE) {
((ClimbingPick) SlimefunItem.getByItem(e.getItem())).damageItem(p, e.getItem());
}
}
};

View File

@ -1,41 +0,0 @@
package io.github.thebusybiscuit.slimefun4.implementation.listeners;
import org.bukkit.GameMode;
import org.bukkit.Sound;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.util.Vector;
import io.github.thebusybiscuit.slimefun4.api.events.ClimbingPickLaunchEvent;
import io.github.thebusybiscuit.slimefun4.implementation.items.tools.ClimbingPick;
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem;
import me.mrCookieSlime.Slimefun.SlimefunPlugin;
/**
* The special event listener for {@link ClimbingPick}.
* This is made like this to allow addons to add more materials to climbing pick.
*
* @author Linox
*
* @see ClimbingPick
*
*/
public class ClimbingPickListener implements Listener {
public ClimbingPickListener(SlimefunPlugin plugin) {
plugin.getServer().getPluginManager().registerEvents(this, plugin);
}
@EventHandler
public void onLaunch(ClimbingPickLaunchEvent e) {
Player p = e.getPlayer();
p.setVelocity(e.getVelocity());
p.playSound(p.getLocation(), Sound.ENTITY_ENDERMAN_TELEPORT, 1F, 1F);
if (p.getGameMode() != GameMode.CREATIVE) {
((ClimbingPick) SlimefunItem.getByItem(e.getItem())).damageItem(p, e.getItem());
}
}
}

View File

@ -10,7 +10,6 @@ import java.util.Set;
import java.util.logging.Level;
import java.util.stream.Collectors;
import io.github.thebusybiscuit.slimefun4.implementation.listeners.ClimbingPickListener;
import org.bukkit.Bukkit;
import org.bukkit.Server;
import org.bukkit.command.Command;
@ -238,7 +237,6 @@ public final class SlimefunPlugin extends JavaPlugin implements SlimefunAddon {
new WitherListener(this);
new IronGolemListener(this);
new PlayerInteractEntityListener(this);
new ClimbingPickListener(this);
new MobDropListener(this, (BasicCircuitBoard) SlimefunItems.BASIC_CIRCUIT_BOARD.getItem());

View File

@ -53,11 +53,11 @@ public class TestClimbingPick implements SlimefunItemTest<ClimbingPick> {
for (BlockFace face : BlockFace.values()) {
BlockMock block1 = new BlockMock(Material.STONE);
simulateRightClickBlock(player, pick, block1, face);
server.getPluginManager().assertEventFired(ClimbingPickLaunchEvent.class);
server.getPluginManager().assertEventFired(ClimbingPickLaunchEvent.class, e -> !e.isCancelled());
BlockMock block2 = new BlockMock(Material.DIRT);
simulateRightClickBlock(player, pick, block2, face);
server.getPluginManager().assertEventFired(ClimbingPickLaunchEvent.class);
server.getPluginManager().assertEventFired(ClimbingPickLaunchEvent.class, ClimbingPickLaunchEvent::isCancelled);
}
}
}