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
commit fba7eac6d8
10 changed files with 165 additions and 104 deletions

View File

@ -32,7 +32,6 @@ import org.bukkit.event.block.*;
import org.bukkit.event.entity.*;
import org.bukkit.event.hanging.HangingBreakByEntityEvent;
import org.bukkit.event.hanging.HangingPlaceEvent;
import org.bukkit.event.inventory.InventoryAction;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.inventory.InventoryCloseEvent;
import org.bukkit.event.player.*;
@ -641,72 +640,73 @@ import java.util.regex.Pattern;
Vehicle vehicle = event.getVehicle();
// Check allowed
if (!vehicle.getPassengers().isEmpty()) {
Entity passenger = vehicle.getPassengers().get(0);
if (passenger instanceof Player) {
final Player player = (Player) passenger;
// reset
if (moveTmp == null)
moveTmp = new PlayerMoveEvent(null, from, to);
moveTmp.setFrom(from);
moveTmp.setTo(to);
moveTmp.setCancelled(false);
fieldPlayer.set(moveTmp, player);
Entity passenger = vehicle.getPassengers().get(1);
List<Entity> passengers = vehicle.getPassengers();
if (passenger instanceof Player) {
final Player player = (Player) passenger;
// reset
if (moveTmp == null)
moveTmp = new PlayerMoveEvent(null, from, to);
moveTmp.setFrom(from);
moveTmp.setTo(to);
moveTmp.setCancelled(false);
fieldPlayer.set(moveTmp, player);
List<Entity> passengers = vehicle.getPassengers();
this.playerMove(moveTmp);
org.bukkit.Location dest;
if (moveTmp.isCancelled()) {
dest = from;
} else if (MathMan.roundInt(moveTmp.getTo().getX()) != toX
|| MathMan.roundInt(moveTmp.getTo().getZ()) != toZ) {
dest = to;
} else {
dest = null;
}
if (dest != null) {
if (passengers != null) {
vehicle.eject();
vehicle.setVelocity(new Vector(0d, 0d, 0d));
vehicle.teleport(dest);
passengers.forEach(vehicle::addPassenger);
this.playerMove(moveTmp);
org.bukkit.Location dest;
if (moveTmp.isCancelled()) {
dest = from;
} else if (MathMan.roundInt(moveTmp.getTo().getX()) != toX
|| MathMan.roundInt(moveTmp.getTo().getZ()) != toZ) {
dest = to;
} else {
vehicle.eject();
vehicle.setVelocity(new Vector(0d, 0d, 0d));
vehicle.teleport(dest);
vehicle.setPassenger(player);
dest = null;
}
if (dest != null) {
if (passengers != null) {
vehicle.eject();
vehicle.setVelocity(new Vector(0d, 0d, 0d));
vehicle.teleport(dest);
passengers.forEach(vehicle::addPassenger);
} else {
vehicle.eject();
vehicle.setVelocity(new Vector(0d, 0d, 0d));
vehicle.teleport(dest);
vehicle.setPassenger(player);
}
return;
}
return;
}
}
if (Settings.Enabled_Components.KILL_ROAD_VEHICLES) {
switch (vehicle.getType()) {
case MINECART:
case MINECART_CHEST:
case MINECART_COMMAND:
case MINECART_FURNACE:
case MINECART_HOPPER:
case MINECART_MOB_SPAWNER:
case ENDER_CRYSTAL:
case MINECART_TNT:
case BOAT: {
List<MetadataValue> meta = vehicle.getMetadata("plot");
Plot toPlot = BukkitUtil.getLocation(to).getPlot();
if (!meta.isEmpty()) {
Plot origin = (Plot) meta.get(0).value();
if (!origin.getBasePlot(false).equals(toPlot)) {
vehicle.remove();
if (Settings.Enabled_Components.KILL_ROAD_VEHICLES) {
switch (vehicle.getType()) {
case MINECART:
case MINECART_CHEST:
case MINECART_COMMAND:
case MINECART_FURNACE:
case MINECART_HOPPER:
case MINECART_MOB_SPAWNER:
case ENDER_CRYSTAL:
case MINECART_TNT:
case BOAT: {
List<MetadataValue> meta = vehicle.getMetadata("plot");
Plot toPlot = BukkitUtil.getLocation(to).getPlot();
if (!meta.isEmpty()) {
Plot origin = (Plot) meta.get(0).value();
if (!origin.getBasePlot(false).equals(toPlot)) {
vehicle.remove();
}
} else if (toPlot != null) {
vehicle.setMetadata("plot",
new FixedMetadataValue((Plugin) PlotSquared.get().IMP, toPlot));
}
} else if (toPlot != null) {
vehicle.setMetadata("plot",
new FixedMetadataValue((Plugin) PlotSquared.get().IMP, toPlot));
}
}
}
}
}
}
@ -1496,10 +1496,10 @@ import java.util.regex.Pattern;
@SuppressWarnings("deprecation")
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onInventoryClick(InventoryClickEvent event) {
if (!event.isLeftClick() || (event.getAction() != InventoryAction.PLACE_ALL) || event
/*if (!event.isLeftClick() || (event.getAction() != InventoryAction.PLACE_ALL) || event
.isShiftClick()) {
return;
}
}*/
HumanEntity entity = event.getWhoClicked();
if (!(entity instanceof Player) || !PlotSquared.get()
.hasPlotArea(entity.getWorld().getName())) {
@ -1512,7 +1512,7 @@ import java.util.regex.Pattern;
}
Player player = (Player) clicker;
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.onClick(event.getSlot())) {
event.setResult(Event.Result.DENY);
@ -2210,7 +2210,7 @@ import java.util.regex.Pattern;
return;
}
Player player = (Player) closer;
BukkitUtil.getPlayer(player).deleteMeta("inventory");
PlotInventory.removePlotInventoryOpen(BukkitUtil.getPlayer(player));
}
@EventHandler(priority = EventPriority.MONITOR) public void onLeave(PlayerQuitEvent event) {

View File

@ -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.config.C;
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.util.*;
import org.bukkit.Effect;
import org.bukkit.GameMode;
import org.bukkit.WeatherType;
import org.bukkit.*;
import org.bukkit.entity.Player;
import org.bukkit.event.Event;
import org.bukkit.event.EventException;
@ -17,8 +16,10 @@ import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
import org.bukkit.permissions.PermissionAttachmentInfo;
import org.bukkit.plugin.RegisteredListener;
import java.util.Arrays;
import java.util.Set;
import java.util.UUID;
import java.util.stream.Collectors;
public class BukkitPlayer extends PlotPlayer {
@ -251,9 +252,18 @@ public class BukkitPlayer extends PlotPlayer {
this.player.setAllowFlight(fly);
}
@Override public void playMusic(Location location, int id) {
//noinspection deprecation
this.player.playEffect(BukkitUtil.getLocation(location), Effect.RECORD_PLAY, id);
@Override public void playMusic(Location location, PlotBlock id) {
if (PlotBlock.isEverything(id) || id.isAir()) {
// 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) {

View File

@ -56,7 +56,6 @@ public class BukkitInventoryUtil extends InventoryUtil {
inventory.setItem(i, getItem(item));
}
}
inv.player.setMeta("inventory", inv);
bp.player.openInventory(inventory);
}
@ -64,7 +63,6 @@ public class BukkitInventoryUtil extends InventoryUtil {
if (!inv.isOpen()) {
return;
}
inv.player.deleteMeta("inventory");
BukkitPlayer bp = (BukkitPlayer) inv.player;
bp.player.closeInventory();
}

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.