GUI. getNearbyPlayers. Stuff
This commit is contained in:
parent
fdc7935d44
commit
9d85db13b1
@ -80,14 +80,26 @@ public class ChestGui
|
||||
public List<Runnable> getRunnablesClose() { return this.runnablesClose; }
|
||||
|
||||
// -------------------------------------------- //
|
||||
// SOUND
|
||||
// SOUNDS
|
||||
// -------------------------------------------- //
|
||||
// The click sound you should hear when clicking an action slot.
|
||||
// You can disable it by setting null.
|
||||
// This section contains all kinds of sounds.
|
||||
// You can disable a sound by setting it to null.
|
||||
|
||||
private SoundEffect soundEffect = MassiveCoreMConf.get().clickSound;
|
||||
public SoundEffect getSoundEffect() { return this.soundEffect; }
|
||||
public ChestGui setSoundEffect(SoundEffect soundEffect) { this.soundEffect = soundEffect; return this; }
|
||||
// The sound you should hear when clicking an action slot.
|
||||
private SoundEffect soundClick = MassiveCoreMConf.get().clickSound;
|
||||
public SoundEffect getSoundClick() { return this.soundClick; }
|
||||
public ChestGui setSoundClick(SoundEffect soundClick) { this.soundClick = soundClick; return this; }
|
||||
|
||||
// The sound you should hear when opening the GUI.
|
||||
private SoundEffect soundOpen = SoundEffect.valueOf("CHEST_OPEN", 0.75f, 1.0f);
|
||||
public SoundEffect getSoundOpen() { return this.soundOpen; }
|
||||
public ChestGui setSoundOpen(SoundEffect soundOpen) { this.soundOpen = soundOpen; return this; }
|
||||
|
||||
// The sound you should hear when closing the GUI.
|
||||
// This sound will be skipped if another inventory was opened by the GUI action.
|
||||
private SoundEffect soundClose = SoundEffect.valueOf("CHEST_CLOSE", 0.75f, 1.0f);
|
||||
public SoundEffect getSoundClose() { return this.soundClose; }
|
||||
public ChestGui setSoundClose(SoundEffect soundClose) { this.soundClose= soundClose; return this; }
|
||||
|
||||
// -------------------------------------------- //
|
||||
// AUTOCLOSING
|
||||
|
@ -1,12 +1,15 @@
|
||||
package com.massivecraft.massivecore.engine;
|
||||
|
||||
import org.bukkit.event.Event.Result;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.HumanEntity;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.event.inventory.InventoryCloseEvent;
|
||||
import org.bukkit.event.inventory.InventoryOpenEvent;
|
||||
import org.bukkit.event.inventory.InventoryType;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import com.massivecraft.massivecore.Engine;
|
||||
import com.massivecraft.massivecore.SoundEffect;
|
||||
@ -60,9 +63,9 @@ public class EngineMassiveCoreChestGui extends Engine
|
||||
// ... set last action ...
|
||||
gui.setLastAction(action);
|
||||
|
||||
// ... then play the sound ...
|
||||
SoundEffect soundEffect = gui.getSoundEffect();
|
||||
if (soundEffect != null) soundEffect.run(event.getWhoClicked());
|
||||
// ... then play click sound ...
|
||||
SoundEffect sound = gui.getSoundClick();
|
||||
if (sound != null) sound.run(event.getWhoClicked());
|
||||
|
||||
// ... close the GUI ...
|
||||
if (gui.isAutoclosing()) event.getView().close();
|
||||
@ -80,12 +83,21 @@ public class EngineMassiveCoreChestGui extends Engine
|
||||
final ChestGui gui = ChestGui.get(inventory);
|
||||
if (gui == null) return;
|
||||
|
||||
// Runnables
|
||||
// Sound
|
||||
SoundEffect sound = gui.getSoundOpen();
|
||||
if (sound != null)
|
||||
{
|
||||
HumanEntity human = event.getPlayer();
|
||||
sound.run(human);
|
||||
}
|
||||
|
||||
// Later
|
||||
Bukkit.getScheduler().runTask(getPlugin(), new Runnable()
|
||||
{
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
// Runnables
|
||||
for (Runnable runnable : gui.getRunnablesOpen())
|
||||
{
|
||||
runnable.run();
|
||||
@ -94,8 +106,6 @@ public class EngineMassiveCoreChestGui extends Engine
|
||||
});
|
||||
}
|
||||
|
||||
// NOTE:
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR)
|
||||
public void onClose(InventoryCloseEvent event)
|
||||
{
|
||||
@ -105,16 +115,27 @@ public class EngineMassiveCoreChestGui extends Engine
|
||||
final ChestGui gui = ChestGui.get(inventory);
|
||||
if (gui == null) return;
|
||||
|
||||
// Runnables
|
||||
// Human
|
||||
final HumanEntity human = event.getPlayer();
|
||||
|
||||
// Later
|
||||
Bukkit.getScheduler().runTask(getPlugin(), new Runnable()
|
||||
{
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
// Runnables
|
||||
for (Runnable runnable : gui.getRunnablesClose())
|
||||
{
|
||||
runnable.run();
|
||||
}
|
||||
|
||||
// Sound
|
||||
SoundEffect sound = gui.getSoundClose();
|
||||
if (sound != null && human.getOpenInventory().getTopInventory().getType() == InventoryType.CRAFTING)
|
||||
{
|
||||
sound.run(human);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -0,0 +1,41 @@
|
||||
package com.massivecraft.massivecore.event;
|
||||
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
||||
// "Aknowledge" is in our mind the opposite of "Ignore".
|
||||
// The purpose of this event is to decide if a unit of communication should be received or ignored.
|
||||
// A unit of communication can for example be a chat message or a sound effect.
|
||||
public class EventMassiveCoreAknowledge extends EventMassiveCore
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// REQUIRED EVENT CODE
|
||||
// -------------------------------------------- //
|
||||
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
@Override public HandlerList getHandlers() { return handlers; }
|
||||
public static HandlerList getHandlerList() { return handlers; }
|
||||
|
||||
// -------------------------------------------- //
|
||||
// FIELDS
|
||||
// -------------------------------------------- //
|
||||
|
||||
private final Object sender;
|
||||
public Object getSender() { return this.sender; }
|
||||
|
||||
private final Object sendee;
|
||||
public Object getSendee() { return this.sendee; }
|
||||
|
||||
// -------------------------------------------- //
|
||||
// CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
public EventMassiveCoreAknowledge(Object sender, Object sendee)
|
||||
{
|
||||
if (sender == null) throw new NullPointerException("sender");
|
||||
if (sendee == null) throw new NullPointerException("sendee");
|
||||
|
||||
this.sender = sender;
|
||||
this.sendee = sendee;
|
||||
}
|
||||
|
||||
}
|
@ -10,6 +10,7 @@ import org.bukkit.entity.Player;
|
||||
|
||||
import com.google.common.base.Objects;
|
||||
import com.massivecraft.massivecore.Named;
|
||||
import com.massivecraft.massivecore.event.EventMassiveCoreAknowledge;
|
||||
import com.massivecraft.massivecore.mixin.MixinDisplayName;
|
||||
import com.massivecraft.massivecore.mixin.MixinMessage;
|
||||
import com.massivecraft.massivecore.mixin.MixinPlayed;
|
||||
@ -184,6 +185,17 @@ public abstract class SenderEntity<E extends SenderEntity<E>> extends Entity<E>
|
||||
return MixinDisplayName.get().getDisplayNameMson(this.getId(), watcherObject);
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// AKNOWLEDGE
|
||||
// -------------------------------------------- //
|
||||
|
||||
public boolean isAcknowledging(Object sender)
|
||||
{
|
||||
EventMassiveCoreAknowledge event = new EventMassiveCoreAknowledge(sender, this);
|
||||
event.run();
|
||||
return ! event.isCancelled();
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// MSG / MESSAGE
|
||||
// -------------------------------------------- //
|
||||
|
@ -177,6 +177,39 @@ public class MUtil
|
||||
}
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// GET NEARBY PLAYERS
|
||||
// -------------------------------------------- //
|
||||
|
||||
public static Set<Player> getNearbyPlayers(Entity entity, double raidus, boolean includeSelf)
|
||||
{
|
||||
Set<Player> ret = getNearbyPlayers(entity.getLocation(), raidus);
|
||||
if (isPlayer(entity) && !includeSelf) ret.remove(entity);
|
||||
return ret;
|
||||
}
|
||||
|
||||
public static Set<Player> getNearbyPlayers(Location location, double radius)
|
||||
{
|
||||
// Create
|
||||
Set<Player> ret = new MassiveSet<>();
|
||||
|
||||
// Fill
|
||||
final World world = location.getWorld();
|
||||
final double radiusSquared = radius * radius;
|
||||
for (Player player : MUtil.getOnlinePlayers())
|
||||
{
|
||||
Location playerLocation = player.getLocation();
|
||||
World playerWorld = playerLocation.getWorld();
|
||||
if ( ! world.equals(playerWorld)) continue;
|
||||
double distanceSquared = location.distanceSquared(playerLocation);
|
||||
if (distanceSquared > radiusSquared) continue;
|
||||
ret.add(player);
|
||||
}
|
||||
|
||||
// Return
|
||||
return ret;
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// IS SYNCHRONOUS
|
||||
// -------------------------------------------- //
|
||||
|
Loading…
Reference in New Issue
Block a user