mirror of
https://github.com/StarWishsama/Slimefun4.git
synced 2024-09-20 03:35:51 +00:00
Some code cleanup and fix grappling hook dupe
This commit is contained in:
parent
c661d09f9a
commit
9d3ca22b1f
@ -19,18 +19,18 @@ import org.bukkit.inventory.ItemStack;
|
||||
public class RitualAnimation implements Runnable {
|
||||
|
||||
List<Block> altars;
|
||||
|
||||
|
||||
Block altar;
|
||||
Location l;
|
||||
ItemStack output;
|
||||
List<Block> pedestals;
|
||||
List<ItemStack> items;
|
||||
|
||||
|
||||
List<Location> particles;
|
||||
|
||||
|
||||
boolean running;
|
||||
int stage;
|
||||
|
||||
|
||||
public RitualAnimation(List<Block> altars, Block altar, Location drop, ItemStack output, List<Block> pedestals, List<ItemStack> items) {
|
||||
this.l = drop;
|
||||
this.altar = altar;
|
||||
@ -39,7 +39,7 @@ public class RitualAnimation implements Runnable {
|
||||
this.pedestals = pedestals;
|
||||
this.items = items;
|
||||
this.particles = new ArrayList<Location>();
|
||||
|
||||
|
||||
this.running = true;
|
||||
this.stage = 0;
|
||||
}
|
||||
@ -57,7 +57,7 @@ public class RitualAnimation implements Runnable {
|
||||
this.stage += 1;
|
||||
SlimefunStartup.instance.getServer().getScheduler().scheduleSyncDelayedTask(SlimefunStartup.instance, this, 8);
|
||||
}
|
||||
|
||||
|
||||
private void idle() {
|
||||
try {
|
||||
ParticleEffect.SPELL_WITCH.display(l, 1.2F, 0F, 1.2F, 0, 16);
|
||||
@ -70,7 +70,7 @@ public class RitualAnimation implements Runnable {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void checkPedestal(Block pedestal) {
|
||||
Item item = AncientAltarListener.findItem(pedestal);
|
||||
if (item == null) abort();
|
||||
@ -78,14 +78,14 @@ public class RitualAnimation implements Runnable {
|
||||
particles.add(pedestal.getLocation().add(0.5, 1.5, 0.5));
|
||||
items.add(AncientAltarListener.fixItemStack(item.getItemStack(), item.getCustomName()));
|
||||
pedestal.getWorld().playSound(pedestal.getLocation(), Sound.ENTITY_ENDERMEN_TELEPORT, 5F, 2F);
|
||||
|
||||
|
||||
try {
|
||||
ParticleEffect.ENCHANTMENT_TABLE.display(pedestal.getLocation().add(0.5, 1.5, 0.5), 0.3F, 0.2F, 0.3F, 0, 16);
|
||||
ParticleEffect.CRIT_MAGIC.display(pedestal.getLocation().add(0.5, 1.5, 0.5), 0.3F, 0.2F, 0.3F, 0, 8);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
|
||||
item.remove();
|
||||
pedestal.removeMetadata("item_placed", SlimefunStartup.instance);
|
||||
}
|
||||
@ -93,24 +93,24 @@ public class RitualAnimation implements Runnable {
|
||||
|
||||
private void abort() {
|
||||
running = false;
|
||||
// for (ItemStack stack: items) {
|
||||
// l.getWorld().dropItemNaturally(l, stack);
|
||||
// }
|
||||
l.getWorld().playSound(l, Sound.BLOCK_NOTE_SNARE, 5F, 1F);
|
||||
pedestals.forEach((pblock) -> Variables.altarinuse.remove(pblock.getLocation()));
|
||||
Variables.altarinuse.remove(altar.getLocation()); // should re-enable altar blocks on craft failure.
|
||||
l.getWorld().playSound(l, Sound.ENTITY_ZOMBIE_ATTACK_IRON_DOOR, 5F, 1F);
|
||||
altars.remove(altar);
|
||||
}
|
||||
|
||||
|
||||
private void finish() {
|
||||
l.getWorld().playSound(l, Sound.ENTITY_ZOMBIE_VILLAGER_CURE, 1F, 1F);
|
||||
l.getWorld().playEffect(l, Effect.STEP_SOUND, Material.EMERALD_BLOCK);
|
||||
l.getWorld().dropItemNaturally(l.add(0, 1, 0), output);
|
||||
if (running) {
|
||||
l.getWorld().playSound(l, Sound.ENTITY_ZOMBIE_VILLAGER_CURE, 1F, 1F);
|
||||
l.getWorld().playEffect(l, Effect.STEP_SOUND, Material.EMERALD_BLOCK);
|
||||
l.getWorld().dropItemNaturally(l.add(0, 1, 0), output);
|
||||
|
||||
pedestals.forEach((pblock)->{
|
||||
Variables.altarinuse.remove(pblock.getLocation());
|
||||
});
|
||||
Variables.altarinuse.remove(altar.getLocation()); // should re-enable altar blocks on craft completion.
|
||||
|
||||
altars.remove(altar);
|
||||
pedestals.forEach((pblock)-> Variables.altarinuse.remove(pblock.getLocation()));
|
||||
Variables.altarinuse.remove(altar.getLocation()); // should re-enable altar blocks on craft completion.
|
||||
altars.remove(altar);
|
||||
}
|
||||
else {
|
||||
l.getWorld().playSound(l, Sound.ENTITY_ZOMBIE_BREAK_DOOR_WOOD, 1F, 1F);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -1138,8 +1138,12 @@ public class SlimefunSetup {
|
||||
public boolean onRightClick(ItemUseEvent e, Player p, ItemStack item) {
|
||||
if (SlimefunManager.isItemSimiliar(item, SlimefunItems.GRAPPLING_HOOK, true)) {
|
||||
if (e.getClickedBlock() == null && !Variables.jump.containsKey(p.getUniqueId())) {
|
||||
Variables.jump.put(p.getUniqueId(), p.getInventory().getItemInMainHand().getType() != Material.SHEARS);
|
||||
e.setCancelled(true);
|
||||
if (p.getInventory().getItemInOffHand().getType().equals(Material.BOW)) {
|
||||
// Cancel, to fix dupe #740
|
||||
return false;
|
||||
}
|
||||
Variables.jump.put(p.getUniqueId(), p.getInventory().getItemInMainHand().getType() != Material.SHEARS);
|
||||
if (p.getInventory().getItemInMainHand().getType() == Material.LEASH) PlayerInventory.consumeItemInHand(p);
|
||||
|
||||
Vector direction = p.getEyeLocation().getDirection().multiply(2.0);
|
||||
|
@ -261,25 +261,22 @@ public class SlimefunStartup extends JavaPlugin {
|
||||
|
||||
@EventHandler
|
||||
public void onDisconnect(PlayerQuitEvent e) {
|
||||
if (SlimefunGuide.history.containsKey(e.getPlayer().getUniqueId())) SlimefunGuide.history.remove(e.getPlayer().getUniqueId());
|
||||
SlimefunGuide.history.remove(e.getPlayer().getUniqueId());
|
||||
}
|
||||
|
||||
}, this);
|
||||
|
||||
// Initiating various Stuff and all Items with a slightly delay (0ms after the Server finished loading)
|
||||
getServer().getScheduler().scheduleSyncDelayedTask(this, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Slimefun.emeraldenchants = getServer().getPluginManager().isPluginEnabled("EmeraldEnchants");
|
||||
SlimefunGuide.all_recipes = config.getBoolean("options.show-vanilla-recipes-in-guide");
|
||||
MiscSetup.loadItems();
|
||||
getServer().getScheduler().scheduleSyncDelayedTask(this, () -> {
|
||||
Slimefun.emeraldenchants = getServer().getPluginManager().isPluginEnabled("EmeraldEnchants");
|
||||
SlimefunGuide.all_recipes = config.getBoolean("options.show-vanilla-recipes-in-guide");
|
||||
MiscSetup.loadItems();
|
||||
|
||||
for (World world: Bukkit.getWorlds()) {
|
||||
new BlockStorage(world);
|
||||
}
|
||||
|
||||
if (SlimefunItem.getByID("ANCIENT_ALTAR") != null) new AncientAltarListener((SlimefunStartup) instance);
|
||||
for (World world: Bukkit.getWorlds()) {
|
||||
new BlockStorage(world);
|
||||
}
|
||||
|
||||
if (SlimefunItem.getByID("ANCIENT_ALTAR") != null) new AncientAltarListener((SlimefunStartup) instance);
|
||||
}, 0);
|
||||
|
||||
// WorldEdit Hook to clear Slimefun Data upon //set 0 //cut or any other equivalent
|
||||
@ -299,53 +296,49 @@ public class SlimefunStartup extends JavaPlugin {
|
||||
|
||||
// Armor Update Task
|
||||
if (config.getBoolean("options.enable-armor-effects")) {
|
||||
getServer().getScheduler().runTaskTimer(this, new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
for (Player p: Bukkit.getOnlinePlayers()) {
|
||||
for (ItemStack armor: p.getInventory().getArmorContents()) {
|
||||
if (armor != null) {
|
||||
if (Slimefun.hasUnlocked(p, armor, true)) {
|
||||
if (SlimefunItem.getByItem(armor) instanceof SlimefunArmorPiece) {
|
||||
for (PotionEffect effect: ((SlimefunArmorPiece) SlimefunItem.getByItem(armor)).getEffects()) {
|
||||
p.removePotionEffect(effect.getType());
|
||||
p.addPotionEffect(effect);
|
||||
}
|
||||
getServer().getScheduler().runTaskTimer(this, () -> {
|
||||
for (Player p: Bukkit.getOnlinePlayers()) {
|
||||
for (ItemStack armor: p.getInventory().getArmorContents()) {
|
||||
if (armor != null) {
|
||||
if (Slimefun.hasUnlocked(p, armor, true)) {
|
||||
if (SlimefunItem.getByItem(armor) instanceof SlimefunArmorPiece) {
|
||||
for (PotionEffect effect: ((SlimefunArmorPiece) SlimefunItem.getByItem(armor)).getEffects()) {
|
||||
p.removePotionEffect(effect.getType());
|
||||
p.addPotionEffect(effect);
|
||||
}
|
||||
if (SlimefunManager.isItemSimiliar(armor, SlimefunItem.getItem("SOLAR_HELMET"), false)) {
|
||||
if (p.getWorld().getTime() < 12300 || p.getWorld().getTime() > 23850) {
|
||||
if (p.getEyeLocation().getBlock().getLightFromSky() == 15) {
|
||||
ItemEnergy.chargeInventory(p, Float.valueOf(String.valueOf(Slimefun.getItemValue("SOLAR_HELMET", "charge-amount"))));
|
||||
}
|
||||
}
|
||||
if (SlimefunManager.isItemSimiliar(armor, SlimefunItem.getItem("SOLAR_HELMET"), false)) {
|
||||
if (p.getWorld().getTime() < 12300 || p.getWorld().getTime() > 23850) {
|
||||
if (p.getEyeLocation().getBlock().getLightFromSky() == 15) {
|
||||
ItemEnergy.chargeInventory(p, Float.valueOf(String.valueOf(Slimefun.getItemValue("SOLAR_HELMET", "charge-amount"))));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (ItemStack radioactive: SlimefunItem.radioactive) {
|
||||
if (p.getInventory().containsAtLeast(radioactive, 1) || SlimefunManager.isItemSimiliar(p.getInventory().getItemInOffHand(), radioactive, true)) {
|
||||
// Check if player is wearing the hazmat suit
|
||||
// If so, break the loop
|
||||
if (SlimefunManager.isItemSimiliar(SlimefunItems.SCUBA_HELMET, p.getInventory().getHelmet(), true) &&
|
||||
SlimefunManager.isItemSimiliar(SlimefunItems.HAZMATSUIT_CHESTPLATE, p.getInventory().getChestplate(), true) &&
|
||||
SlimefunManager.isItemSimiliar(SlimefunItems.HAZMATSUIT_LEGGINGS, p.getInventory().getLeggings(), true) &&
|
||||
SlimefunManager.isItemSimiliar(SlimefunItems.RUBBER_BOOTS, p.getInventory().getBoots(), true)) {
|
||||
break;
|
||||
}
|
||||
for (ItemStack radioactive: SlimefunItem.radioactive) {
|
||||
if (p.getInventory().containsAtLeast(radioactive, 1) || SlimefunManager.isItemSimiliar(p.getInventory().getItemInOffHand(), radioactive, true)) {
|
||||
// Check if player is wearing the hazmat suit
|
||||
// If so, break the loop
|
||||
if (SlimefunManager.isItemSimiliar(SlimefunItems.SCUBA_HELMET, p.getInventory().getHelmet(), true) &&
|
||||
SlimefunManager.isItemSimiliar(SlimefunItems.HAZMATSUIT_CHESTPLATE, p.getInventory().getChestplate(), true) &&
|
||||
SlimefunManager.isItemSimiliar(SlimefunItems.HAZMATSUIT_LEGGINGS, p.getInventory().getLeggings(), true) &&
|
||||
SlimefunManager.isItemSimiliar(SlimefunItems.RUBBER_BOOTS, p.getInventory().getBoots(), true)) {
|
||||
break;
|
||||
}
|
||||
|
||||
// If the item is enabled in the world, then make radioactivity do its job
|
||||
if (Slimefun.isEnabled(p, radioactive, false)) {
|
||||
p.addPotionEffect(new PotionEffect(PotionEffectType.WITHER, 400, 3));
|
||||
p.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, 400, 3));
|
||||
p.addPotionEffect(new PotionEffect(PotionEffectType.CONFUSION, 400, 3));
|
||||
p.addPotionEffect(new PotionEffect(PotionEffectType.WEAKNESS, 400, 3));
|
||||
p.addPotionEffect(new PotionEffect(PotionEffectType.SLOW, 400, 1));
|
||||
p.addPotionEffect(new PotionEffect(PotionEffectType.SLOW_DIGGING, 400, 1));
|
||||
p.setFireTicks(400);
|
||||
break; // Break the loop to save some calculations
|
||||
}
|
||||
// If the item is enabled in the world, then make radioactivity do its job
|
||||
if (Slimefun.isEnabled(p, radioactive, false)) {
|
||||
p.addPotionEffect(new PotionEffect(PotionEffectType.WITHER, 400, 3));
|
||||
p.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, 400, 3));
|
||||
p.addPotionEffect(new PotionEffect(PotionEffectType.CONFUSION, 400, 3));
|
||||
p.addPotionEffect(new PotionEffect(PotionEffectType.WEAKNESS, 400, 3));
|
||||
p.addPotionEffect(new PotionEffect(PotionEffectType.SLOW, 400, 1));
|
||||
p.addPotionEffect(new PotionEffect(PotionEffectType.SLOW_DIGGING, 400, 1));
|
||||
p.setFireTicks(400);
|
||||
break; // Break the loop to save some calculations
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
package me.mrCookieSlime.Slimefun.api;
|
||||
package me.mrCookieSlime.Slimefun.api;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
|
@ -34,19 +34,15 @@ public class BowListener implements Listener {
|
||||
|
||||
@EventHandler
|
||||
public void onArrowHit(final ProjectileHitEvent e) {
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(SlimefunStartup.instance, new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
if (!e.getEntity().isValid()) return;
|
||||
if (Variables.arrows.containsKey(e.getEntity().getUniqueId())) Variables.arrows.remove(e.getEntity().getUniqueId());
|
||||
if (e.getEntity() instanceof Arrow) handleGrapplingHook((Arrow) e.getEntity());
|
||||
}
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(SlimefunStartup.instance, () -> {
|
||||
if (!e.getEntity().isValid()) return;
|
||||
if (Variables.arrows.containsKey(e.getEntity().getUniqueId())) Variables.arrows.remove(e.getEntity().getUniqueId());
|
||||
if (e.getEntity() instanceof Arrow) handleGrapplingHook((Arrow) e.getEntity());
|
||||
}, 4L);
|
||||
}
|
||||
|
||||
private void handleGrapplingHook(Arrow arrow) {
|
||||
if (arrow instanceof Arrow) {
|
||||
if (arrow != null) {
|
||||
if (arrow.getShooter() instanceof Player && Variables.jump.containsKey(((Player) arrow.getShooter()).getUniqueId())) {
|
||||
final Player p = (Player) arrow.getShooter();
|
||||
if (p.getGameMode() != GameMode.CREATIVE && Variables.jump.get(p.getUniqueId())) arrow.getWorld().dropItem(arrow.getLocation(), SlimefunItem.getItem("GRAPPLING_HOOK"));
|
||||
@ -59,13 +55,9 @@ public class BowListener implements Listener {
|
||||
n.remove();
|
||||
}
|
||||
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(SlimefunStartup.instance, new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
Variables.jump.remove(p.getUniqueId());
|
||||
Variables.remove.remove(p.getUniqueId());
|
||||
}
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(SlimefunStartup.instance, () -> {
|
||||
Variables.jump.remove(p.getUniqueId());
|
||||
Variables.remove.remove(p.getUniqueId());
|
||||
}, 20L);
|
||||
}
|
||||
else {
|
||||
|
Loading…
Reference in New Issue
Block a user