mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2025-06-26 02:34:42 +02:00
Port MusicFlag
This commit is contained in:
@ -6,6 +6,7 @@ import com.github.intellectualsites.plotsquared.configuration.file.YamlConfigura
|
|||||||
import com.github.intellectualsites.plotsquared.configuration.serialization.ConfigurationSerialization;
|
import com.github.intellectualsites.plotsquared.configuration.serialization.ConfigurationSerialization;
|
||||||
import com.github.intellectualsites.plotsquared.plot.commands.WE_Anywhere;
|
import com.github.intellectualsites.plotsquared.plot.commands.WE_Anywhere;
|
||||||
import com.github.intellectualsites.plotsquared.plot.config.Caption;
|
import com.github.intellectualsites.plotsquared.plot.config.Caption;
|
||||||
|
import com.github.intellectualsites.plotsquared.plot.config.CaptionUtility;
|
||||||
import com.github.intellectualsites.plotsquared.plot.config.Captions;
|
import com.github.intellectualsites.plotsquared.plot.config.Captions;
|
||||||
import com.github.intellectualsites.plotsquared.plot.config.Configuration;
|
import com.github.intellectualsites.plotsquared.plot.config.Configuration;
|
||||||
import com.github.intellectualsites.plotsquared.plot.config.Settings;
|
import com.github.intellectualsites.plotsquared.plot.config.Settings;
|
||||||
@ -319,7 +320,7 @@ import java.util.zip.ZipInputStream;
|
|||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
PlotSquared.log(Captions.PREFIX + Captions
|
PlotSquared.log(Captions.PREFIX + CaptionUtility
|
||||||
.format(Captions.ENABLED.getTranslated(), IMP.getPluginName()));
|
.format(Captions.ENABLED.getTranslated(), IMP.getPluginName()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -536,6 +536,7 @@ public enum Captions implements Caption {
|
|||||||
FLAG_CATEGORY_TELEPORT_DENY("Teleport Deny Flag", "Flags"),
|
FLAG_CATEGORY_TELEPORT_DENY("Teleport Deny Flag", "Flags"),
|
||||||
FLAG_CATEGORY_STRING_LIST("String List Flags", "Flags"),
|
FLAG_CATEGORY_STRING_LIST("String List Flags", "Flags"),
|
||||||
FLAG_CATEGORY_WEATHER("Weather Flags", "Flags"),
|
FLAG_CATEGORY_WEATHER("Weather Flags", "Flags"),
|
||||||
|
FLAG_CATEGORY_MUSIC("Music Flags", "Flags"),
|
||||||
FLAG_CATEGORY_BLOCK_LIST("Material Flags", "Flags"),
|
FLAG_CATEGORY_BLOCK_LIST("Material Flags", "Flags"),
|
||||||
FLAG_CATEGORY_INTERVALS("Interval Flags", "Flags"),
|
FLAG_CATEGORY_INTERVALS("Interval Flags", "Flags"),
|
||||||
FLAG_CATEGORY_INTEGER_LIST("Integer List Flags", "Flags"),
|
FLAG_CATEGORY_INTEGER_LIST("Integer List Flags", "Flags"),
|
||||||
@ -547,6 +548,7 @@ public enum Captions implements Caption {
|
|||||||
//</editor-fold>
|
//</editor-fold>
|
||||||
//<editor-fold desc="Flag descriptions">
|
//<editor-fold desc="Flag descriptions">
|
||||||
FLAG_DESCRIPTION_EXPLOSION("Set to 'true' to enable explosions in the plot, and 'false' to disable them", "Flags"),
|
FLAG_DESCRIPTION_EXPLOSION("Set to 'true' to enable explosions in the plot, and 'false' to disable them", "Flags"),
|
||||||
|
FLAG_DESCRIPTION_MUSIC("Set to a music disk ID (item name) to play the music disc inside of the plot", "Flags"),
|
||||||
//</editor-fold>
|
//</editor-fold>
|
||||||
//<editor-fold desc="Flag category errors">
|
//<editor-fold desc="Flag category errors">
|
||||||
FLAG_ERROR_BOOLEAN("Flag value must be a boolean (true|false)", "Flags"),
|
FLAG_ERROR_BOOLEAN("Flag value must be a boolean (true|false)", "Flags"),
|
||||||
@ -563,6 +565,7 @@ public enum Captions implements Caption {
|
|||||||
FLAG_ERROR_STRING("Flag value must be alphanumeric. Some special characters are allowed.", "Flags"),
|
FLAG_ERROR_STRING("Flag value must be alphanumeric. Some special characters are allowed.", "Flags"),
|
||||||
FLAG_ERROR_STRINGLIST("Flag value must be a string list", "Flags"),
|
FLAG_ERROR_STRINGLIST("Flag value must be a string list", "Flags"),
|
||||||
FLAG_ERROR_WEATHER("Flag must be a weather: 'rain' or 'sun'", "Flags"),
|
FLAG_ERROR_WEATHER("Flag must be a weather: 'rain' or 'sun'", "Flags"),
|
||||||
|
FLAG_ERROR_MUSIC("Flag value must be a valid music disc ID.", "Flags"),
|
||||||
//</editor-fold>
|
//</editor-fold>
|
||||||
//<editor-fold desc="Trusted">
|
//<editor-fold desc="Trusted">
|
||||||
TRUSTED_ADDED("$4You successfully trusted a user to the plot", "Trusted"),
|
TRUSTED_ADDED("$4You successfully trusted a user to the plot", "Trusted"),
|
||||||
|
@ -13,7 +13,6 @@ import java.util.HashMap;
|
|||||||
|
|
||||||
public final class Flags {
|
public final class Flags {
|
||||||
|
|
||||||
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();
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package com.github.intellectualsites.plotsquared.plot.flags;
|
package com.github.intellectualsites.plotsquared.plot.flags;
|
||||||
|
|
||||||
import com.github.intellectualsites.plotsquared.plot.flags.implementations.ExplosionFlag;
|
import com.github.intellectualsites.plotsquared.plot.flags.implementations.ExplosionFlag;
|
||||||
|
import com.github.intellectualsites.plotsquared.plot.flags.implementations.MusicFlag;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
@ -38,6 +39,7 @@ public final class GlobalFlagContainer extends FlagContainer {
|
|||||||
super(null);
|
super(null);
|
||||||
// Register all default flags here
|
// Register all default flags here
|
||||||
this.addFlag(ExplosionFlag.EXPLOSION_FALSE);
|
this.addFlag(ExplosionFlag.EXPLOSION_FALSE);
|
||||||
|
this.addFlag(MusicFlag.MUSIC_FLAG_NONE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public void addFlag(PlotFlag<?, ?> flag) {
|
@Override public void addFlag(PlotFlag<?, ?> flag) {
|
||||||
|
@ -5,6 +5,7 @@ import com.github.intellectualsites.plotsquared.plot.flags.types.BooleanFlag;
|
|||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
public class ExplosionFlag extends BooleanFlag<ExplosionFlag> {
|
public class ExplosionFlag extends BooleanFlag<ExplosionFlag> {
|
||||||
|
|
||||||
public static final ExplosionFlag EXPLOSION_TRUE = new ExplosionFlag(true);
|
public static final ExplosionFlag EXPLOSION_TRUE = new ExplosionFlag(true);
|
||||||
public static final ExplosionFlag EXPLOSION_FALSE = new ExplosionFlag(false);
|
public static final ExplosionFlag EXPLOSION_FALSE = new ExplosionFlag(false);
|
||||||
|
|
||||||
|
@ -0,0 +1,59 @@
|
|||||||
|
package com.github.intellectualsites.plotsquared.plot.flags.implementations;
|
||||||
|
|
||||||
|
import com.github.intellectualsites.plotsquared.plot.config.Captions;
|
||||||
|
import com.github.intellectualsites.plotsquared.plot.flags.FlagParseException;
|
||||||
|
import com.github.intellectualsites.plotsquared.plot.flags.PlotFlag;
|
||||||
|
import com.github.intellectualsites.plotsquared.plot.util.world.ItemUtil;
|
||||||
|
import com.sk89q.worldedit.world.item.ItemType;
|
||||||
|
import com.sk89q.worldedit.world.item.ItemTypes;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
|
||||||
|
public final class MusicFlag extends PlotFlag<ItemType, MusicFlag> {
|
||||||
|
|
||||||
|
public static final MusicFlag MUSIC_FLAG_NONE = new MusicFlag(ItemTypes.AIR);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Construct a new flag instance.
|
||||||
|
*
|
||||||
|
* @param value Flag value
|
||||||
|
*/
|
||||||
|
protected MusicFlag(ItemType value) {
|
||||||
|
super(value, Captions.FLAG_CATEGORY_MUSIC, Captions.FLAG_DESCRIPTION_MUSIC);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override public MusicFlag parse(@NotNull String input) throws FlagParseException {
|
||||||
|
if (!input.isEmpty() && !input.contains("music_disc_")) {
|
||||||
|
input = "music_disc_" + input;
|
||||||
|
}
|
||||||
|
final ItemType itemType = ItemUtil.get(input);
|
||||||
|
if (itemType == ItemTypes.AIR || itemType.getId().contains("music_disc_")) {
|
||||||
|
return new MusicFlag(ItemUtil.get(input));
|
||||||
|
} else {
|
||||||
|
throw new FlagParseException(this, input, Captions.FLAG_ERROR_MUSIC);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override public MusicFlag merge(@NotNull ItemType newValue) {
|
||||||
|
if (getValue().equals(ItemTypes.AIR)) {
|
||||||
|
return new MusicFlag(newValue);
|
||||||
|
} else if (newValue.equals(ItemTypes.AIR)) {
|
||||||
|
return this;
|
||||||
|
} else {
|
||||||
|
return new MusicFlag(newValue);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override public String toString() {
|
||||||
|
return getValue().getId();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override public String getExample() {
|
||||||
|
return "ward";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override protected MusicFlag flagOf(@NotNull ItemType value) {
|
||||||
|
return new MusicFlag(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -5,6 +5,7 @@ import com.github.intellectualsites.plotsquared.plot.config.Settings;
|
|||||||
import com.github.intellectualsites.plotsquared.plot.flag.Flag;
|
import com.github.intellectualsites.plotsquared.plot.flag.Flag;
|
||||||
import com.github.intellectualsites.plotsquared.plot.flag.FlagManager;
|
import com.github.intellectualsites.plotsquared.plot.flag.FlagManager;
|
||||||
import com.github.intellectualsites.plotsquared.plot.flag.Flags;
|
import com.github.intellectualsites.plotsquared.plot.flag.Flags;
|
||||||
|
import com.github.intellectualsites.plotsquared.plot.flags.implementations.MusicFlag;
|
||||||
import com.github.intellectualsites.plotsquared.plot.object.Location;
|
import com.github.intellectualsites.plotsquared.plot.object.Location;
|
||||||
import com.github.intellectualsites.plotsquared.plot.object.Plot;
|
import com.github.intellectualsites.plotsquared.plot.object.Plot;
|
||||||
import com.github.intellectualsites.plotsquared.plot.object.PlotArea;
|
import com.github.intellectualsites.plotsquared.plot.object.PlotArea;
|
||||||
@ -142,26 +143,26 @@ public class PlotListener {
|
|||||||
FlagManager.removePlotFlag(plot, Flags.TIME);
|
FlagManager.removePlotFlag(plot, Flags.TIME);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Optional<PlotWeather> weatherFlag = plot.getFlag(Flags.WEATHER);
|
Optional<PlotWeather> weatherFlag = plot.getFlag(Flags.WEATHER);
|
||||||
weatherFlag.ifPresent(player::setWeather);
|
weatherFlag.ifPresent(player::setWeather);
|
||||||
Optional<String> musicFlag = plot.getFlag(Flags.MUSIC);
|
|
||||||
if (musicFlag.isPresent()) {
|
ItemType musicFlag = plot.getFlag(MusicFlag.class);
|
||||||
final String id = musicFlag.get();
|
if (musicFlag != null) {
|
||||||
final ItemType item = ItemUtil.get(id);
|
final String rawId = musicFlag.getId();
|
||||||
final String rawId = item.getId();
|
if (rawId.contains("disc") || musicFlag == ItemTypes.AIR) {
|
||||||
if (rawId.contains("disc") || item == ItemTypes.AIR) {
|
|
||||||
Location location = player.getLocation();
|
Location location = player.getLocation();
|
||||||
Location lastLocation = player.getMeta("music");
|
Location lastLocation = player.getMeta("music");
|
||||||
if (lastLocation != null) {
|
if (lastLocation != null) {
|
||||||
player.playMusic(lastLocation, item);
|
player.playMusic(lastLocation, musicFlag);
|
||||||
if (item == ItemTypes.AIR) {
|
if (musicFlag == ItemTypes.AIR) {
|
||||||
player.deleteMeta("music");
|
player.deleteMeta("music");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (item != ItemTypes.AIR) {
|
if (musicFlag != ItemTypes.AIR) {
|
||||||
try {
|
try {
|
||||||
player.setMeta("music", location);
|
player.setMeta("music", location);
|
||||||
player.playMusic(location, item);
|
player.playMusic(location, musicFlag);
|
||||||
} catch (Exception ignored) {
|
} catch (Exception ignored) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -66,4 +66,5 @@ public class PlotMessage {
|
|||||||
public void send(PlotPlayer player) {
|
public void send(PlotPlayer player) {
|
||||||
ChatManager.manager.send(this, player);
|
ChatManager.manager.send(this, player);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
package com.github.intellectualsites.plotsquared.plot.util.world;
|
package com.github.intellectualsites.plotsquared.plot.util.world;
|
||||||
|
|
||||||
import com.github.intellectualsites.plotsquared.plot.util.MathMan;
|
import com.github.intellectualsites.plotsquared.plot.util.MathMan;
|
||||||
import com.sk89q.worldedit.world.block.BlockState;
|
|
||||||
import com.sk89q.worldedit.world.item.ItemType;
|
import com.sk89q.worldedit.world.item.ItemType;
|
||||||
import com.sk89q.worldedit.world.item.ItemTypes;
|
import com.sk89q.worldedit.world.item.ItemTypes;
|
||||||
import com.sk89q.worldedit.world.registry.LegacyMapper;
|
import com.sk89q.worldedit.world.registry.LegacyMapper;
|
||||||
@ -12,6 +11,9 @@ public final class ItemUtil {
|
|||||||
private ItemUtil(){}
|
private ItemUtil(){}
|
||||||
|
|
||||||
public static ItemType get(String input) {
|
public static ItemType get(String input) {
|
||||||
|
if (input == null || input.isEmpty()) {
|
||||||
|
return ItemTypes.AIR;
|
||||||
|
}
|
||||||
input = input.toLowerCase(Locale.ROOT);
|
input = input.toLowerCase(Locale.ROOT);
|
||||||
if (Character.isDigit(input.charAt(0))) {
|
if (Character.isDigit(input.charAt(0))) {
|
||||||
String[] split = input.split(":");
|
String[] split = input.split(":");
|
||||||
|
Reference in New Issue
Block a user