Merge branch 'breaking' of https://github.com/IntellectualSites/PlotSquared into breaking

This commit is contained in:
dordsor21
2018-12-26 21:18:38 +00:00
10 changed files with 165 additions and 104 deletions

View File

@ -4,13 +4,20 @@ import com.github.intellectualsites.plotsquared.commands.CommandDeclaration;
import com.github.intellectualsites.plotsquared.plot.config.C;
import com.github.intellectualsites.plotsquared.plot.flag.Flags;
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) 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) {
Location loc = player.getLocation();
final Plot plot = loc.getPlotAbs();
@ -29,26 +36,32 @@ import com.github.intellectualsites.plotsquared.plot.util.WorldUtil;
}
if (item.getPlotBlock().equalsAny(7, "bedrock")) {
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());
C.FLAG_ADDED.send(player);
} else {
C.FLAG_NOT_ADDED.send(player);
}
return false;
}
};
int index = 0;
for (int i = 2256; i < 2268; i++) {
String name =
"&r&6" + WorldUtil.IMP.getClosestMatchingName(PlotBlock.get((short) i, (byte) 0));
String[] lore = {"&r&aClick to play!"};
PlotItemStack item = new PlotItemStack(i, (byte) 0, 1, name, lore);
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));
for (final String disc : DISCS) {
final String name = String.format("&r&6%s", disc);
final String[] lore = {"&r&aClick to play!"};
final PlotItemStack item = new PlotItemStack(disc, 1, name, lore);
inv.setItem(index++, item);
}
// 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();
return true;
}

View File

@ -15,7 +15,7 @@ import java.util.HashMap;
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 IntegerListFlag ANALYSIS =
(IntegerListFlag) new IntegerListFlag("analysis").reserve();

View File

@ -124,24 +124,24 @@ public class PlotListener {
Optional<PlotWeather> weatherFlag = plot.getFlag(Flags.WEATHER);
if (weatherFlag.isPresent()) {
player.setWeather(weatherFlag.get());
}
Optional<Integer> musicFlag = plot.getFlag(Flags.MUSIC);
} Optional<String> musicFlag = plot.getFlag(Flags.MUSIC);
if (musicFlag.isPresent()) {
Number id = musicFlag.get();
if ((id.intValue() >= 2256 && id.intValue() <= 2267) || (id.intValue() == 0)) {
final String id = musicFlag.get();
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 lastLoc = player.getMeta("music");
if (lastLoc != null) {
player.playMusic(lastLoc, 0);
if (id.intValue() == 0) {
player.playMusic(lastLoc, PlotBlock.get("air"));
if (PlotBlock.isEverything(block) || block.isAir()) {
player.deleteMeta("music");
}
}
if (id.intValue() != 0) {
if (!(PlotBlock.isEverything(block) || block.isAir())) {
try {
player.setMeta("music", loc);
player.playMusic(loc, id.intValue());
player.playMusic(loc, block);
} catch (Exception ignored) {
}
}
@ -150,7 +150,7 @@ public class PlotListener {
Location lastLoc = player.getMeta("music");
if (lastLoc != null) {
player.deleteMeta("music");
player.playMusic(lastLoc, 0);
player.playMusic(lastLoc, PlotBlock.get("air"));
}
}
CommentManager.sendTitle(player, plot);
@ -255,7 +255,7 @@ public class PlotListener {
Location lastLoc = player.getMeta("music");
if (lastLoc != null) {
player.deleteMeta("music");
player.playMusic(lastLoc, 0);
player.playMusic(lastLoc, PlotBlock.get("air"));
}
}
return true;

View File

@ -115,7 +115,7 @@ public class ConsolePlayer extends PlotPlayer {
@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) {

View File

@ -1,9 +1,30 @@
package com.github.intellectualsites.plotsquared.plot.object;
import com.github.intellectualsites.plotsquared.plot.PlotSquared;
import com.github.intellectualsites.plotsquared.plot.util.InventoryUtil;
import lombok.NonNull;
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 int size;
private final PlotItemStack[] items;
@ -32,14 +53,21 @@ public class PlotInventory {
if (this.title == null) {
return;
}
this.open = true;
InventoryUtil.manager.open(this);
if (hasPlotInventoryOpen(player)) {
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() {
if (this.title == null) {
return;
}
removePlotInventoryOpen(player);
InventoryUtil.manager.close(this);
this.open = false;
}

View File

@ -5,22 +5,34 @@ import com.github.intellectualsites.plotsquared.plot.util.WorldUtil;
import lombok.Getter;
public class PlotItemStack {
public final int amount;
public final String name;
public final String[] lore;
// public final int id;
// public final short data;
@Getter private final PlotBlock plotBlock;
@Deprecated
public PlotItemStack(final int id, final short data, final int amount, final String name,
final String... lore) {
/**
* @param id Legacy numerical item ID
* @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.name = name;
this.lore = lore;
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,
final String... lore) {
StringComparison<PlotBlock>.ComparisonResult match = WorldUtil.IMP.getClosestBlock(id);

View File

@ -432,9 +432,9 @@ public abstract class PlotPlayer implements CommandCaller, OfflinePlotPlayer {
* Play music at a location for this player.
*
* @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.