mirror of
https://github.com/songoda/UltimateRepairing.git
synced 2024-11-01 00:10:19 +01:00
Redid the sound to have better performance.
This commit is contained in:
parent
91e99c5ba6
commit
7d85c153a4
@ -31,13 +31,13 @@ import java.util.UUID;
|
||||
*/
|
||||
public class RepairHandler {
|
||||
|
||||
private final UltimateRepairing instance;
|
||||
private final UltimateRepairing plugin;
|
||||
private final GuiManager guiManager;
|
||||
|
||||
private final Map<UUID, PlayerAnvilData> playerAnvilData = new HashMap<>();
|
||||
|
||||
public RepairHandler(UltimateRepairing instance, GuiManager guiManager) {
|
||||
this.instance = instance;
|
||||
public RepairHandler(UltimateRepairing plugin, GuiManager guiManager) {
|
||||
this.plugin = plugin;
|
||||
this.guiManager = guiManager;
|
||||
}
|
||||
|
||||
@ -60,16 +60,16 @@ public class RepairHandler {
|
||||
Item item = player.getWorld().dropItem(anvil.add(0.5, 2, 0.5), itemStack);
|
||||
|
||||
// Support for EpicHoppers suction.
|
||||
item.setMetadata("grabbed", new FixedMetadataValue(instance, "true"));
|
||||
item.setMetadata("grabbed", new FixedMetadataValue(plugin, "true"));
|
||||
|
||||
item.setMetadata("betterdrops_ignore", new FixedMetadataValue(instance, true));
|
||||
item.setMetadata("betterdrops_ignore", new FixedMetadataValue(plugin, true));
|
||||
Vector vec = player.getEyeLocation().getDirection();
|
||||
vec.setX(0);
|
||||
vec.setY(0);
|
||||
vec.setZ(0);
|
||||
item.setVelocity(vec);
|
||||
item.setPickupDelay(3600);
|
||||
item.setMetadata("UltimateRepairing", new FixedMetadataValue(instance, ""));
|
||||
item.setMetadata("UltimateRepairing", new FixedMetadataValue(plugin, ""));
|
||||
|
||||
playerData.setItem(item);
|
||||
playerData.setToBeRepaired(itemStack);
|
||||
@ -77,20 +77,20 @@ public class RepairHandler {
|
||||
|
||||
yesNo(player, type, itemStack);
|
||||
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(instance, () -> {
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, () -> {
|
||||
if (item.isValid() && !playerData.isBeingRepaired()) {
|
||||
|
||||
instance.getLocale().getMessage("event.repair.timeout").sendPrefixedMessage(player);
|
||||
plugin.getLocale().getMessage("event.repair.timeout").sendPrefixedMessage(player);
|
||||
removeItem(playerData, player);
|
||||
player.closeInventory();
|
||||
|
||||
}
|
||||
}, instance.getConfig().getLong("Main.Time Before Repair Auto Canceled"));
|
||||
}, plugin.getConfig().getLong("Main.Time Before Repair Auto Canceled"));
|
||||
}
|
||||
|
||||
public void initRepair(Player player, Location anvil) {
|
||||
if (anvil.add(0, 1, 0).getBlock().getType() != Material.AIR) {
|
||||
instance.getLocale().getMessage("event.repair.needspace").sendPrefixedMessage(player);
|
||||
plugin.getLocale().getMessage("event.repair.needspace").sendPrefixedMessage(player);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -117,7 +117,7 @@ public class RepairHandler {
|
||||
PlayerAnvilData playerData = playerAnvilData.computeIfAbsent(player.getUniqueId(), uuid -> new PlayerAnvilData());
|
||||
if (!answer) {
|
||||
removeItem(playerData, player);
|
||||
instance.getLocale().getMessage("event.repair.cancelled").sendPrefixedMessage(player);
|
||||
plugin.getLocale().getMessage("event.repair.cancelled").sendPrefixedMessage(player);
|
||||
return;
|
||||
}
|
||||
RepairType type = playerData.getType();
|
||||
@ -168,43 +168,65 @@ public class RepairHandler {
|
||||
|
||||
Location location = playerData.getLocations();
|
||||
player.getWorld().playEffect(location, effect, blockTypeFinal);
|
||||
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
|
||||
try {
|
||||
Runnable runnable = () -> player.getWorld().playEffect(location, effect, blockTypeFinal);
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(instance, runnable, 5L);
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(instance, () -> {
|
||||
|
||||
// Delay for 5 ticks (0.25 seconds)
|
||||
Thread.sleep(250);
|
||||
Bukkit.getScheduler().runTask(plugin, runnable);
|
||||
|
||||
// Delay for 10 ticks (0.5 seconds)
|
||||
Thread.sleep(500);
|
||||
Bukkit.getScheduler().runTask(plugin, () -> {
|
||||
player.getWorld().playEffect(location, effect, blockTypeFinal);
|
||||
player.getWorld().playEffect(location, effect, Material.STONE);
|
||||
XSound.BLOCK_ANVIL_LAND.play(player);
|
||||
}, 10L);
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(instance, runnable, 15L);
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(instance, runnable, 20L);
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(instance, () -> {
|
||||
});
|
||||
|
||||
// Delay for 15 ticks (0.75 seconds)
|
||||
Thread.sleep(500);
|
||||
Bukkit.getScheduler().runTask(plugin, runnable);
|
||||
|
||||
// Delay for 20 ticks (1 second)
|
||||
Thread.sleep(250);
|
||||
Bukkit.getScheduler().runTask(plugin, runnable);
|
||||
|
||||
// Delay for 20 ticks (1 second)
|
||||
Thread.sleep(250);
|
||||
Bukkit.getScheduler().runTask(plugin, runnable);
|
||||
|
||||
// Delay for 25 ticks (1.25 seconds)
|
||||
Thread.sleep(500);
|
||||
Bukkit.getScheduler().runTask(plugin, () -> {
|
||||
XSound.BLOCK_ANVIL_LAND.play(player);
|
||||
player.getWorld().playEffect(location, effect, blockTypeFinal);
|
||||
player.getWorld().playEffect(location, effect, Material.ANVIL);
|
||||
instance.getLocale().getMessage("event.repair.success").sendPrefixedMessage(player);
|
||||
|
||||
plugin.getLocale().getMessage("event.repair.success").sendPrefixedMessage(player);
|
||||
playerData.getToBeRepaired().setDurability((short) 0);
|
||||
removeItem(playerData, player);
|
||||
|
||||
if (player.getGameMode() != GameMode.CREATIVE &&
|
||||
type == RepairType.EXPERIENCE) {
|
||||
if (player.getGameMode() != GameMode.CREATIVE && type == RepairType.EXPERIENCE) {
|
||||
player.setLevel(player.getLevel() - playerData.getPrice());
|
||||
}
|
||||
player.closeInventory();
|
||||
}, 25L);
|
||||
});
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
if (type == RepairType.ECONOMY) {
|
||||
instance.getLocale().getMessage("event.repair.notenough")
|
||||
.processPlaceholder("type", instance.getLocale().getMessage("interface.repair.eco").getMessage())
|
||||
plugin.getLocale().getMessage("event.repair.notenough")
|
||||
.processPlaceholder("type", plugin.getLocale().getMessage("interface.repair.eco").getMessage())
|
||||
.sendPrefixedMessage(player);
|
||||
} else if (type == RepairType.EXPERIENCE)
|
||||
instance.getLocale().getMessage("event.repair.notenough")
|
||||
.processPlaceholder("type", instance.getLocale().getMessage("interface.repair.xp").getMessage())
|
||||
plugin.getLocale().getMessage("event.repair.notenough")
|
||||
.processPlaceholder("type", plugin.getLocale().getMessage("interface.repair.xp").getMessage())
|
||||
.sendPrefixedMessage(player);
|
||||
else
|
||||
instance.getLocale().getMessage("event.repair.notenough")
|
||||
plugin.getLocale().getMessage("event.repair.notenough")
|
||||
.processPlaceholder("type", name).sendPrefixedMessage(player);
|
||||
|
||||
// we've failed to repair, so return the item
|
||||
|
Loading…
Reference in New Issue
Block a user