geforkt von Mirrors/Paper
#1170: Add preliminary support for multi sided signs
By: Yannick Lamprecht <yannicklamprecht@live.de>
Dieser Commit ist enthalten in:
Ursprung
3ef16a899d
Commit
d8a3b1e7f0
@ -2,46 +2,40 @@ package org.bukkit.craftbukkit.block;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import net.minecraft.network.chat.IChatBaseComponent;
|
||||
import net.minecraft.world.item.EnumColor;
|
||||
import net.minecraft.world.level.block.entity.TileEntitySign;
|
||||
import org.bukkit.DyeColor;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Sign;
|
||||
import org.bukkit.block.sign.Side;
|
||||
import org.bukkit.block.sign.SignSide;
|
||||
import org.bukkit.craftbukkit.block.sign.CraftSignSide;
|
||||
import org.bukkit.craftbukkit.entity.CraftPlayer;
|
||||
import org.bukkit.craftbukkit.util.CraftChatMessage;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class CraftSign<T extends TileEntitySign> extends CraftBlockEntityState<T> implements Sign {
|
||||
|
||||
// Lazily initialized only if requested:
|
||||
private String[] originalLines = null;
|
||||
private String[] lines = null;
|
||||
private final CraftSignSide front;
|
||||
|
||||
public CraftSign(World world, T tileEntity) {
|
||||
super(world, tileEntity);
|
||||
this.front = new CraftSignSide(this.getSnapshot());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getLines() {
|
||||
if (lines == null) {
|
||||
// Lazy initialization:
|
||||
TileEntitySign sign = this.getSnapshot();
|
||||
lines = new String[sign.messages.length];
|
||||
System.arraycopy(revertComponents(sign.messages), 0, lines, 0, lines.length);
|
||||
originalLines = new String[lines.length];
|
||||
System.arraycopy(lines, 0, originalLines, 0, originalLines.length);
|
||||
}
|
||||
return lines;
|
||||
return front.getLines();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getLine(int index) throws IndexOutOfBoundsException {
|
||||
return getLines()[index];
|
||||
return front.getLine(index);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setLine(int index, String line) throws IndexOutOfBoundsException {
|
||||
getLines()[index] = line;
|
||||
front.setLine(index, line);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -56,37 +50,37 @@ public class CraftSign<T extends TileEntitySign> extends CraftBlockEntityState<T
|
||||
|
||||
@Override
|
||||
public boolean isGlowingText() {
|
||||
return getSnapshot().hasGlowingText();
|
||||
return front.isGlowingText();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setGlowingText(boolean glowing) {
|
||||
getSnapshot().setHasGlowingText(glowing);
|
||||
front.setGlowingText(glowing);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public SignSide getSide(Side side) {
|
||||
Preconditions.checkArgument(side != null, "side == null");
|
||||
|
||||
return front;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DyeColor getColor() {
|
||||
return DyeColor.getByWoolData((byte) getSnapshot().getColor().getId());
|
||||
return front.getColor();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setColor(DyeColor color) {
|
||||
getSnapshot().setColor(EnumColor.byId(color.getWoolData()));
|
||||
front.setColor(color);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void applyTo(T sign) {
|
||||
super.applyTo(sign);
|
||||
front.applyLegacyStringToSignSide();
|
||||
|
||||
if (lines != null) {
|
||||
for (int i = 0; i < lines.length; i++) {
|
||||
String line = (lines[i] == null) ? "" : lines[i];
|
||||
if (line.equals(originalLines[i])) {
|
||||
continue; // The line contents are still the same, skip.
|
||||
}
|
||||
sign.setMessage(i, CraftChatMessage.fromString(line)[0]);
|
||||
}
|
||||
}
|
||||
super.applyTo(sign);
|
||||
}
|
||||
|
||||
public static void openSign(Sign sign, Player player) {
|
||||
|
@ -0,0 +1,79 @@
|
||||
package org.bukkit.craftbukkit.block.sign;
|
||||
|
||||
import net.minecraft.world.item.EnumColor;
|
||||
import net.minecraft.world.level.block.entity.TileEntitySign;
|
||||
import org.bukkit.DyeColor;
|
||||
import org.bukkit.block.sign.SignSide;
|
||||
import org.bukkit.craftbukkit.block.CraftSign;
|
||||
import org.bukkit.craftbukkit.util.CraftChatMessage;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class CraftSignSide implements SignSide {
|
||||
|
||||
// Lazily initialized only if requested:
|
||||
private String[] originalLines = null;
|
||||
private String[] lines = null;
|
||||
private final TileEntitySign signText;
|
||||
|
||||
public CraftSignSide(TileEntitySign signText) {
|
||||
this.signText = signText;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String[] getLines() {
|
||||
if (lines == null) {
|
||||
// Lazy initialization:
|
||||
lines = new String[signText.messages.length];
|
||||
System.arraycopy(CraftSign.revertComponents(signText.messages), 0, lines, 0, lines.length);
|
||||
originalLines = new String[lines.length];
|
||||
System.arraycopy(lines, 0, originalLines, 0, originalLines.length);
|
||||
}
|
||||
return lines;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String getLine(int index) throws IndexOutOfBoundsException {
|
||||
return getLines()[index];
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setLine(int index, @NotNull String line) throws IndexOutOfBoundsException {
|
||||
getLines()[index] = line;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isGlowingText() {
|
||||
return signText.hasGlowingText();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setGlowingText(boolean glowing) {
|
||||
signText.setHasGlowingText(glowing);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public DyeColor getColor() {
|
||||
return DyeColor.getByWoolData((byte) signText.getColor().getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setColor(@NotNull DyeColor color) {
|
||||
signText.setColor(EnumColor.byId(color.getWoolData()));
|
||||
}
|
||||
|
||||
public void applyLegacyStringToSignSide() {
|
||||
if (lines != null) {
|
||||
for (int i = 0; i < lines.length; i++) {
|
||||
String line = (lines[i] == null) ? "" : lines[i];
|
||||
if (line.equals(originalLines[i])) {
|
||||
continue; // The line contents are still the same, skip.
|
||||
}
|
||||
signText.setMessage(i, CraftChatMessage.fromString(line)[0]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -112,6 +112,7 @@ import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockState;
|
||||
import org.bukkit.block.Sign;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
import org.bukkit.block.sign.Side;
|
||||
import org.bukkit.configuration.serialization.DelegateDeserialization;
|
||||
import org.bukkit.conversations.Conversation;
|
||||
import org.bukkit.conversations.ConversationAbandonedEvent;
|
||||
@ -162,6 +163,7 @@ import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.plugin.messaging.StandardMessenger;
|
||||
import org.bukkit.profile.PlayerProfile;
|
||||
import org.bukkit.scoreboard.Scoreboard;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@DelegateDeserialization(CraftOfflinePlayer.class)
|
||||
public class CraftPlayer extends CraftHumanEntity implements Player {
|
||||
@ -2093,6 +2095,11 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
|
||||
CraftSign.openSign(sign, this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void openSign(@NotNull Sign sign, @NotNull Side side) {
|
||||
openSign(sign); // todo implement per side
|
||||
}
|
||||
|
||||
@Override
|
||||
public void showDemoScreen() {
|
||||
if (getHandle().connection == null) return;
|
||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren