mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2024-11-14 10:35:50 +01:00
Fix plot music (and plot inventories)
This commit is contained in:
parent
5bdc5a0fcc
commit
2b9fe5afda
@ -32,7 +32,6 @@ import org.bukkit.event.block.*;
|
|||||||
import org.bukkit.event.entity.*;
|
import org.bukkit.event.entity.*;
|
||||||
import org.bukkit.event.hanging.HangingBreakByEntityEvent;
|
import org.bukkit.event.hanging.HangingBreakByEntityEvent;
|
||||||
import org.bukkit.event.hanging.HangingPlaceEvent;
|
import org.bukkit.event.hanging.HangingPlaceEvent;
|
||||||
import org.bukkit.event.inventory.InventoryAction;
|
|
||||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||||
import org.bukkit.event.inventory.InventoryCloseEvent;
|
import org.bukkit.event.inventory.InventoryCloseEvent;
|
||||||
import org.bukkit.event.player.*;
|
import org.bukkit.event.player.*;
|
||||||
@ -1498,10 +1497,10 @@ import java.util.regex.Pattern;
|
|||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("deprecation")
|
||||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||||
public void onInventoryClick(InventoryClickEvent event) {
|
public void onInventoryClick(InventoryClickEvent event) {
|
||||||
if (!event.isLeftClick() || (event.getAction() != InventoryAction.PLACE_ALL) || event
|
/*if (!event.isLeftClick() || (event.getAction() != InventoryAction.PLACE_ALL) || event
|
||||||
.isShiftClick()) {
|
.isShiftClick()) {
|
||||||
return;
|
return;
|
||||||
}
|
}*/
|
||||||
HumanEntity entity = event.getWhoClicked();
|
HumanEntity entity = event.getWhoClicked();
|
||||||
if (!(entity instanceof Player) || !PlotSquared.get()
|
if (!(entity instanceof Player) || !PlotSquared.get()
|
||||||
.hasPlotArea(entity.getWorld().getName())) {
|
.hasPlotArea(entity.getWorld().getName())) {
|
||||||
@ -1514,7 +1513,7 @@ import java.util.regex.Pattern;
|
|||||||
}
|
}
|
||||||
Player player = (Player) clicker;
|
Player player = (Player) clicker;
|
||||||
PlotPlayer pp = BukkitUtil.getPlayer(player);
|
PlotPlayer pp = BukkitUtil.getPlayer(player);
|
||||||
PlotInventory inventory = pp.getMeta("inventory");
|
final PlotInventory inventory = PlotInventory.getOpenPlotInventory(pp);
|
||||||
if (inventory != null && event.getRawSlot() == event.getSlot()) {
|
if (inventory != null && event.getRawSlot() == event.getSlot()) {
|
||||||
if (!inventory.onClick(event.getSlot())) {
|
if (!inventory.onClick(event.getSlot())) {
|
||||||
event.setResult(Event.Result.DENY);
|
event.setResult(Event.Result.DENY);
|
||||||
@ -2212,7 +2211,7 @@ import java.util.regex.Pattern;
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Player player = (Player) closer;
|
Player player = (Player) closer;
|
||||||
BukkitUtil.getPlayer(player).deleteMeta("inventory");
|
PlotInventory.removePlotInventoryOpen(BukkitUtil.getPlayer(player));
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.MONITOR) public void onLeave(PlayerQuitEvent event) {
|
@EventHandler(priority = EventPriority.MONITOR) public void onLeave(PlayerQuitEvent event) {
|
||||||
|
@ -4,11 +4,10 @@ import com.github.intellectualsites.plotsquared.bukkit.util.BukkitUtil;
|
|||||||
import com.github.intellectualsites.plotsquared.plot.PlotSquared;
|
import com.github.intellectualsites.plotsquared.plot.PlotSquared;
|
||||||
import com.github.intellectualsites.plotsquared.plot.config.C;
|
import com.github.intellectualsites.plotsquared.plot.config.C;
|
||||||
import com.github.intellectualsites.plotsquared.plot.object.Location;
|
import com.github.intellectualsites.plotsquared.plot.object.Location;
|
||||||
|
import com.github.intellectualsites.plotsquared.plot.object.PlotBlock;
|
||||||
import com.github.intellectualsites.plotsquared.plot.object.PlotPlayer;
|
import com.github.intellectualsites.plotsquared.plot.object.PlotPlayer;
|
||||||
import com.github.intellectualsites.plotsquared.plot.util.*;
|
import com.github.intellectualsites.plotsquared.plot.util.*;
|
||||||
import org.bukkit.Effect;
|
import org.bukkit.*;
|
||||||
import org.bukkit.GameMode;
|
|
||||||
import org.bukkit.WeatherType;
|
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.Event;
|
import org.bukkit.event.Event;
|
||||||
import org.bukkit.event.EventException;
|
import org.bukkit.event.EventException;
|
||||||
@ -17,8 +16,10 @@ import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
|
|||||||
import org.bukkit.permissions.PermissionAttachmentInfo;
|
import org.bukkit.permissions.PermissionAttachmentInfo;
|
||||||
import org.bukkit.plugin.RegisteredListener;
|
import org.bukkit.plugin.RegisteredListener;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public class BukkitPlayer extends PlotPlayer {
|
public class BukkitPlayer extends PlotPlayer {
|
||||||
|
|
||||||
@ -251,9 +252,18 @@ public class BukkitPlayer extends PlotPlayer {
|
|||||||
this.player.setAllowFlight(fly);
|
this.player.setAllowFlight(fly);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public void playMusic(Location location, int id) {
|
@Override public void playMusic(Location location, PlotBlock id) {
|
||||||
//noinspection deprecation
|
if (PlotBlock.isEverything(id) || id.isAir()) {
|
||||||
this.player.playEffect(BukkitUtil.getLocation(location), Effect.RECORD_PLAY, id);
|
// Let's just stop all the discs because why not?
|
||||||
|
for (final Sound sound : Arrays.stream(Sound.values()).filter(sound -> sound.name().contains("DISC")).collect(
|
||||||
|
Collectors.toList())) {
|
||||||
|
player.stopSound(sound);
|
||||||
|
}
|
||||||
|
// this.player.playEffect(BukkitUtil.getLocation(location), Effect.RECORD_PLAY, Material.AIR);
|
||||||
|
} else {
|
||||||
|
// this.player.playEffect(BukkitUtil.getLocation(location), Effect.RECORD_PLAY, id.to(Material.class));
|
||||||
|
this.player.playSound(BukkitUtil.getLocation(location), Sound.valueOf(id.to(Material.class).name()), Float.MAX_VALUE, 1f);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public void kick(String message) {
|
@Override public void kick(String message) {
|
||||||
|
@ -56,7 +56,6 @@ public class BukkitInventoryUtil extends InventoryUtil {
|
|||||||
inventory.setItem(i, getItem(item));
|
inventory.setItem(i, getItem(item));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
inv.player.setMeta("inventory", inv);
|
|
||||||
bp.player.openInventory(inventory);
|
bp.player.openInventory(inventory);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -64,7 +63,6 @@ public class BukkitInventoryUtil extends InventoryUtil {
|
|||||||
if (!inv.isOpen()) {
|
if (!inv.isOpen()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
inv.player.deleteMeta("inventory");
|
|
||||||
BukkitPlayer bp = (BukkitPlayer) inv.player;
|
BukkitPlayer bp = (BukkitPlayer) inv.player;
|
||||||
bp.player.closeInventory();
|
bp.player.closeInventory();
|
||||||
}
|
}
|
||||||
|
@ -4,11 +4,18 @@ import com.github.intellectualsites.plotsquared.commands.CommandDeclaration;
|
|||||||
import com.github.intellectualsites.plotsquared.plot.config.C;
|
import com.github.intellectualsites.plotsquared.plot.config.C;
|
||||||
import com.github.intellectualsites.plotsquared.plot.flag.Flags;
|
import com.github.intellectualsites.plotsquared.plot.flag.Flags;
|
||||||
import com.github.intellectualsites.plotsquared.plot.object.*;
|
import com.github.intellectualsites.plotsquared.plot.object.*;
|
||||||
import com.github.intellectualsites.plotsquared.plot.util.WorldUtil;
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.Locale;
|
||||||
|
|
||||||
@CommandDeclaration(command = "music", permission = "plots.music", description = "Play music in your plot", usage = "/plot music", category = CommandCategory.APPEARANCE, requiredType = RequiredType.PLAYER)
|
@CommandDeclaration(command = "music", permission = "plots.music", description = "Play music in your plot", usage = "/plot music", category = CommandCategory.APPEARANCE, requiredType = RequiredType.PLAYER)
|
||||||
public class Music extends SubCommand {
|
public class Music extends SubCommand {
|
||||||
|
|
||||||
|
private static final Collection<String> DISCS = Arrays.asList("music_disc_13", "music_disc_cat",
|
||||||
|
"music_disc_blocks", "music_disc_chirp", "music_disc_far", "music_disc_mall", "music_disc_mellohi",
|
||||||
|
"music_disc_stal", "music_disc_strad", "music_disc_ward", "music_disc_11", "music_disc_wait");
|
||||||
|
|
||||||
@Override public boolean onCommand(PlotPlayer player, String[] args) {
|
@Override public boolean onCommand(PlotPlayer player, String[] args) {
|
||||||
Location loc = player.getLocation();
|
Location loc = player.getLocation();
|
||||||
final Plot plot = loc.getPlotAbs();
|
final Plot plot = loc.getPlotAbs();
|
||||||
@ -27,26 +34,32 @@ public class Music extends SubCommand {
|
|||||||
}
|
}
|
||||||
if (item.getPlotBlock().equalsAny(7, "bedrock")) {
|
if (item.getPlotBlock().equalsAny(7, "bedrock")) {
|
||||||
plot.removeFlag(Flags.MUSIC);
|
plot.removeFlag(Flags.MUSIC);
|
||||||
} else {
|
C.FLAG_REMOVED.send(player);
|
||||||
|
} else if (item.name.toLowerCase(Locale.ENGLISH).contains("disc")) {
|
||||||
plot.setFlag(Flags.MUSIC, item.getPlotBlock().getRawId());
|
plot.setFlag(Flags.MUSIC, item.getPlotBlock().getRawId());
|
||||||
|
C.FLAG_ADDED.send(player);
|
||||||
|
} else {
|
||||||
|
C.FLAG_NOT_ADDED.send(player);
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
int index = 0;
|
int index = 0;
|
||||||
for (int i = 2256; i < 2268; i++) {
|
|
||||||
String name =
|
for (final String disc : DISCS) {
|
||||||
"&r&6" + WorldUtil.IMP.getClosestMatchingName(PlotBlock.get((short) i, (byte) 0));
|
final String name = String.format("&r&6%s", disc);
|
||||||
String[] lore = {"&r&aClick to play!"};
|
final String[] lore = {"&r&aClick to play!"};
|
||||||
PlotItemStack item = new PlotItemStack(i, (byte) 0, 1, name, lore);
|
final PlotItemStack item = new PlotItemStack(disc, 1, name, lore);
|
||||||
inv.setItem(index, item);
|
inv.setItem(index++, item);
|
||||||
index++;
|
|
||||||
}
|
|
||||||
if (player.getMeta("music") != null) {
|
|
||||||
String name = "&r&6Cancel music";
|
|
||||||
String[] lore = {"&r&cClick to cancel!"};
|
|
||||||
inv.setItem(index, new PlotItemStack(7, (short) 0, 1, name, lore));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Always add the cancel button
|
||||||
|
// if (player.getMeta("music") != null) {
|
||||||
|
String name = "&r&6Cancel music";
|
||||||
|
String[] lore = {"&r&cClick to cancel!"};
|
||||||
|
inv.setItem(index, new PlotItemStack("bedrock", 1, name, lore));
|
||||||
|
// }
|
||||||
|
|
||||||
inv.openInventory();
|
inv.openInventory();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -15,7 +15,7 @@ import java.util.HashMap;
|
|||||||
|
|
||||||
public final class Flags {
|
public final class Flags {
|
||||||
|
|
||||||
public static final IntegerFlag MUSIC = new IntegerFlag("music");
|
public static final StringFlag MUSIC = new StringFlag("music");
|
||||||
public static final StringFlag DESCRIPTION = new StringFlag("description");
|
public static final StringFlag DESCRIPTION = new StringFlag("description");
|
||||||
public static final IntegerListFlag ANALYSIS =
|
public static final IntegerListFlag ANALYSIS =
|
||||||
(IntegerListFlag) new IntegerListFlag("analysis").reserve();
|
(IntegerListFlag) new IntegerListFlag("analysis").reserve();
|
||||||
|
@ -124,24 +124,24 @@ public class PlotListener {
|
|||||||
Optional<PlotWeather> weatherFlag = plot.getFlag(Flags.WEATHER);
|
Optional<PlotWeather> weatherFlag = plot.getFlag(Flags.WEATHER);
|
||||||
if (weatherFlag.isPresent()) {
|
if (weatherFlag.isPresent()) {
|
||||||
player.setWeather(weatherFlag.get());
|
player.setWeather(weatherFlag.get());
|
||||||
}
|
} Optional<String> musicFlag = plot.getFlag(Flags.MUSIC);
|
||||||
|
|
||||||
Optional<Integer> musicFlag = plot.getFlag(Flags.MUSIC);
|
|
||||||
if (musicFlag.isPresent()) {
|
if (musicFlag.isPresent()) {
|
||||||
Number id = musicFlag.get();
|
final String id = musicFlag.get();
|
||||||
if ((id.intValue() >= 2256 && id.intValue() <= 2267) || (id.intValue() == 0)) {
|
final PlotBlock block = PlotBlock.get(id);
|
||||||
|
final String rawId = block.getRawId().toString();
|
||||||
|
if (rawId.contains("disc") || PlotBlock.isEverything(block) || block.isAir()) {
|
||||||
Location loc = player.getLocation();
|
Location loc = player.getLocation();
|
||||||
Location lastLoc = player.getMeta("music");
|
Location lastLoc = player.getMeta("music");
|
||||||
if (lastLoc != null) {
|
if (lastLoc != null) {
|
||||||
player.playMusic(lastLoc, 0);
|
player.playMusic(lastLoc, PlotBlock.get("air"));
|
||||||
if (id.intValue() == 0) {
|
if (PlotBlock.isEverything(block) || block.isAir()) {
|
||||||
player.deleteMeta("music");
|
player.deleteMeta("music");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (id.intValue() != 0) {
|
if (!(PlotBlock.isEverything(block) || block.isAir())) {
|
||||||
try {
|
try {
|
||||||
player.setMeta("music", loc);
|
player.setMeta("music", loc);
|
||||||
player.playMusic(loc, id.intValue());
|
player.playMusic(loc, block);
|
||||||
} catch (Exception ignored) {
|
} catch (Exception ignored) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -150,7 +150,7 @@ public class PlotListener {
|
|||||||
Location lastLoc = player.getMeta("music");
|
Location lastLoc = player.getMeta("music");
|
||||||
if (lastLoc != null) {
|
if (lastLoc != null) {
|
||||||
player.deleteMeta("music");
|
player.deleteMeta("music");
|
||||||
player.playMusic(lastLoc, 0);
|
player.playMusic(lastLoc, PlotBlock.get("air"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
CommentManager.sendTitle(player, plot);
|
CommentManager.sendTitle(player, plot);
|
||||||
@ -257,7 +257,7 @@ public class PlotListener {
|
|||||||
Location lastLoc = player.getMeta("music");
|
Location lastLoc = player.getMeta("music");
|
||||||
if (lastLoc != null) {
|
if (lastLoc != null) {
|
||||||
player.deleteMeta("music");
|
player.deleteMeta("music");
|
||||||
player.playMusic(lastLoc, 0);
|
player.playMusic(lastLoc, PlotBlock.get("air"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
@ -115,7 +115,7 @@ public class ConsolePlayer extends PlotPlayer {
|
|||||||
@Override public void setFlight(boolean fly) {
|
@Override public void setFlight(boolean fly) {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public void playMusic(Location location, int id) {
|
@Override public void playMusic(Location location, PlotBlock id) {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public void kick(String message) {
|
@Override public void kick(String message) {
|
||||||
|
@ -1,9 +1,30 @@
|
|||||||
package com.github.intellectualsites.plotsquared.plot.object;
|
package com.github.intellectualsites.plotsquared.plot.object;
|
||||||
|
|
||||||
|
import com.github.intellectualsites.plotsquared.plot.PlotSquared;
|
||||||
import com.github.intellectualsites.plotsquared.plot.util.InventoryUtil;
|
import com.github.intellectualsites.plotsquared.plot.util.InventoryUtil;
|
||||||
|
import lombok.NonNull;
|
||||||
|
|
||||||
public class PlotInventory {
|
public class PlotInventory {
|
||||||
|
|
||||||
|
private static final String META_KEY = "inventory";
|
||||||
|
|
||||||
|
public static boolean hasPlotInventoryOpen(@NonNull final PlotPlayer plotPlayer) {
|
||||||
|
return getOpenPlotInventory(plotPlayer) != null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static PlotInventory getOpenPlotInventory(@NonNull final PlotPlayer plotPlayer) {
|
||||||
|
return plotPlayer.getMeta(META_KEY, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void setPlotInventoryOpen(@NonNull final PlotPlayer plotPlayer,
|
||||||
|
@NonNull final PlotInventory plotInventory) {
|
||||||
|
plotPlayer.setMeta(META_KEY, plotInventory);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void removePlotInventoryOpen(@NonNull final PlotPlayer plotPlayer) {
|
||||||
|
plotPlayer.deleteMeta(META_KEY);
|
||||||
|
}
|
||||||
|
|
||||||
public final PlotPlayer player;
|
public final PlotPlayer player;
|
||||||
public final int size;
|
public final int size;
|
||||||
private final PlotItemStack[] items;
|
private final PlotItemStack[] items;
|
||||||
@ -32,14 +53,21 @@ public class PlotInventory {
|
|||||||
if (this.title == null) {
|
if (this.title == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this.open = true;
|
if (hasPlotInventoryOpen(player)) {
|
||||||
InventoryUtil.manager.open(this);
|
PlotSquared.debug(String.format("Failed to open plot inventory for %s "
|
||||||
|
+ "because the player already has an open plot inventory", player.getName()));
|
||||||
|
} else {
|
||||||
|
this.open = true;
|
||||||
|
setPlotInventoryOpen(player, this);
|
||||||
|
InventoryUtil.manager.open(this);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void close() {
|
public void close() {
|
||||||
if (this.title == null) {
|
if (this.title == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
removePlotInventoryOpen(player);
|
||||||
InventoryUtil.manager.close(this);
|
InventoryUtil.manager.close(this);
|
||||||
this.open = false;
|
this.open = false;
|
||||||
}
|
}
|
||||||
|
@ -5,22 +5,34 @@ import com.github.intellectualsites.plotsquared.plot.util.WorldUtil;
|
|||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
|
|
||||||
public class PlotItemStack {
|
public class PlotItemStack {
|
||||||
|
|
||||||
public final int amount;
|
public final int amount;
|
||||||
public final String name;
|
public final String name;
|
||||||
public final String[] lore;
|
public final String[] lore;
|
||||||
// public final int id;
|
|
||||||
// public final short data;
|
|
||||||
@Getter private final PlotBlock plotBlock;
|
@Getter private final PlotBlock plotBlock;
|
||||||
|
|
||||||
@Deprecated
|
/**
|
||||||
public PlotItemStack(final int id, final short data, final int amount, final String name,
|
* @param id Legacy numerical item ID
|
||||||
final String... lore) {
|
* @param data Legacy numerical item data
|
||||||
|
* @param amount Amount of items in the stack
|
||||||
|
* @param name The display name of the item stack
|
||||||
|
* @param lore The item stack lore
|
||||||
|
* @deprecated Use {@link PlotItemStack(String, int, String, String...)}
|
||||||
|
*/
|
||||||
|
@Deprecated public PlotItemStack(final int id, final short data, final int amount,
|
||||||
|
final String name, final String... lore) {
|
||||||
this.amount = amount;
|
this.amount = amount;
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.lore = lore;
|
this.lore = lore;
|
||||||
this.plotBlock = PlotBlock.get(id, data);
|
this.plotBlock = PlotBlock.get(id, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param id String ID
|
||||||
|
* @param amount Amount of items in the stack
|
||||||
|
* @param name The display name of the item stack
|
||||||
|
* @param lore The item stack lore
|
||||||
|
*/
|
||||||
public PlotItemStack(final String id, final int amount, final String name,
|
public PlotItemStack(final String id, final int amount, final String name,
|
||||||
final String... lore) {
|
final String... lore) {
|
||||||
StringComparison<PlotBlock>.ComparisonResult match = WorldUtil.IMP.getClosestBlock(id);
|
StringComparison<PlotBlock>.ComparisonResult match = WorldUtil.IMP.getClosestBlock(id);
|
||||||
|
@ -434,9 +434,9 @@ public abstract class PlotPlayer implements CommandCaller, OfflinePlotPlayer {
|
|||||||
* Play music at a location for this player.
|
* Play music at a location for this player.
|
||||||
*
|
*
|
||||||
* @param location where to play the music
|
* @param location where to play the music
|
||||||
* @param id the numerical record item id
|
* @param id the record item id
|
||||||
*/
|
*/
|
||||||
public abstract void playMusic(Location location, int id);
|
public abstract void playMusic(Location location, PlotBlock id);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check if this player is banned.
|
* Check if this player is banned.
|
||||||
|
Loading…
Reference in New Issue
Block a user