Improved performance for particles.
This commit is contained in:
parent
f7689483f1
commit
424f65b287
|
@ -14,7 +14,7 @@ import com.craftaro.ultimaterepairing.anvil.UAnvil;
|
|||
import com.craftaro.ultimaterepairing.commands.CommandReload;
|
||||
import com.craftaro.ultimaterepairing.commands.CommandSettings;
|
||||
import com.craftaro.ultimaterepairing.commands.CommandURAnvil;
|
||||
import com.craftaro.ultimaterepairing.handlers.ParticleTask;
|
||||
import com.craftaro.ultimaterepairing.task.ParticleTask;
|
||||
import com.craftaro.ultimaterepairing.handlers.RepairHandler;
|
||||
import com.craftaro.ultimaterepairing.listeners.BlockListeners;
|
||||
import com.craftaro.ultimaterepairing.listeners.InteractListeners;
|
||||
|
@ -171,4 +171,8 @@ public class UltimateRepairing extends SongodaPlugin {
|
|||
public GuiManager getGuiManager() {
|
||||
return guiManager;
|
||||
}
|
||||
|
||||
public ParticleTask getParticleTask() {
|
||||
return particleTask;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package com.craftaro.ultimaterepairing.gui;
|
||||
|
||||
import com.craftaro.third_party.com.cryptomorin.xseries.XMaterial;
|
||||
import com.craftaro.ultimaterepairing.UltimateRepairing;
|
||||
import com.craftaro.ultimaterepairing.anvil.UAnvil;
|
||||
import com.craftaro.core.gui.Gui;
|
||||
import com.craftaro.core.gui.GuiUtils;
|
||||
|
@ -52,6 +53,7 @@ public class AnvilSettingsGui extends Gui {
|
|||
(event) -> {
|
||||
anvil.setParticles(!anvil.isParticles());
|
||||
updateItemLore(event.slot, ChatColor.GRAY + "Currently: " + (anvil.isParticles() ? ChatColor.GREEN + "Enabled" : ChatColor.RED + "Disabled") + ChatColor.GRAY + ".");
|
||||
UltimateRepairing.getInstance().getParticleTask().start();
|
||||
});
|
||||
|
||||
}
|
||||
|
|
|
@ -1,54 +0,0 @@
|
|||
package com.craftaro.ultimaterepairing.handlers;
|
||||
|
||||
import com.craftaro.ultimaterepairing.UltimateRepairing;
|
||||
import com.craftaro.core.compatibility.CompatibleParticleHandler;
|
||||
import com.craftaro.core.compatibility.CompatibleParticleHandler.ParticleType;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
|
||||
/**
|
||||
* Created by songoda on 2/24/2017.
|
||||
*/
|
||||
public class ParticleTask implements Listener {
|
||||
|
||||
private final UltimateRepairing instance;
|
||||
int amt;
|
||||
String typeName;
|
||||
ParticleType type;
|
||||
BukkitTask task = null;
|
||||
|
||||
public ParticleTask(UltimateRepairing instance) {
|
||||
this.instance = instance;
|
||||
}
|
||||
|
||||
public void start() {
|
||||
reload();
|
||||
if (task == null) {
|
||||
task = Bukkit.getServer().getScheduler().runTaskTimerAsynchronously(instance, this::applyParticles, 0L, 4L);
|
||||
}
|
||||
}
|
||||
|
||||
public void stop() {
|
||||
if (task != null) {
|
||||
Bukkit.getServer().getScheduler().cancelTask(task.getTaskId());
|
||||
task = null;
|
||||
}
|
||||
}
|
||||
|
||||
public void reload() {
|
||||
amt = instance.getConfig().getInt("Main.Particle Amount", 24) / 2;
|
||||
typeName = instance.getConfig().getString("Main.Particle Type", "SPELL_WITCH");
|
||||
type = ParticleType.getParticle(typeName);
|
||||
if (type == null) {
|
||||
type = ParticleType.SPELL_WITCH;
|
||||
}
|
||||
}
|
||||
|
||||
public void applyParticles() {
|
||||
if (instance.getAnvilManager().getAnvils().isEmpty()) return;
|
||||
instance.getAnvilManager().getAnvils().parallelStream()
|
||||
.filter(anvil -> anvil.isParticles() && anvil.isInLoadedChunk())
|
||||
.forEach(anvil -> CompatibleParticleHandler.spawnParticles(type, anvil.getLocation().add(.5, 0, .5), amt, 0.25, 0.25, 0.25));
|
||||
}
|
||||
}
|
|
@ -16,7 +16,6 @@ public class PlayerListeners implements Listener {
|
|||
|
||||
@EventHandler
|
||||
public void onLeave(PlayerQuitEvent event) {
|
||||
|
||||
if (!plugin.getRepairHandler().hasInstance(event.getPlayer())
|
||||
|| !plugin.getRepairHandler().getDataFor(event.getPlayer()).getInRepair())
|
||||
return;
|
||||
|
|
|
@ -0,0 +1,63 @@
|
|||
package com.craftaro.ultimaterepairing.task;
|
||||
|
||||
import com.craftaro.core.compatibility.CompatibleParticleHandler;
|
||||
import com.craftaro.core.compatibility.CompatibleParticleHandler.ParticleType;
|
||||
import com.craftaro.ultimaterepairing.UltimateRepairing;
|
||||
import com.craftaro.ultimaterepairing.anvil.UAnvil;
|
||||
import com.craftaro.ultimaterepairing.settings.Settings;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* Created by songoda on 2/24/2017.
|
||||
*/
|
||||
public class ParticleTask extends BukkitRunnable {
|
||||
|
||||
private final UltimateRepairing plugin;
|
||||
private int amt;
|
||||
private String typeName;
|
||||
private ParticleType type;
|
||||
|
||||
public ParticleTask(UltimateRepairing plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
public void start() {
|
||||
if (isCancelled())
|
||||
return;
|
||||
|
||||
reload();
|
||||
runTaskTimerAsynchronously(plugin, 0L, 4L);
|
||||
}
|
||||
|
||||
public void reload() {
|
||||
amt = Settings.PARTICLE_AMOUNT.getInt(24) / 2;
|
||||
typeName = Settings.PARTICLE_TYPE.getString("SPELL_WITCH");
|
||||
type = ParticleType.getParticle(typeName);
|
||||
if (type == null)
|
||||
type = ParticleType.SPELL_WITCH;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
if (plugin.getAnvilManager().getAnvils().isEmpty()) {
|
||||
cancel();
|
||||
return;
|
||||
}
|
||||
|
||||
List<UAnvil> anvils = plugin.getAnvilManager().getAnvils().parallelStream()
|
||||
.filter(UAnvil::isParticles).collect(Collectors.toList());
|
||||
|
||||
if (anvils.isEmpty()) {
|
||||
cancel();
|
||||
return;
|
||||
}
|
||||
|
||||
anvils.stream().filter(UAnvil::isInLoadedChunk)
|
||||
.forEach(anvil -> CompatibleParticleHandler
|
||||
.spawnParticles(type, anvil.getLocation().add(.5, 0, .5), amt,
|
||||
0.25, 0.25, 0.25));
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue