Add Shift + Right Click Edit Sign
Dieser Commit ist enthalten in:
Ursprung
d4464fb009
Commit
6376ef7dd5
@ -79,5 +79,12 @@
|
|||||||
<scope>system</scope>
|
<scope>system</scope>
|
||||||
<systemPath>${main.basedir}/lib/WorldEdit-1.15.jar</systemPath>
|
<systemPath>${main.basedir}/lib/WorldEdit-1.15.jar</systemPath>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>steamwar</groupId>
|
||||||
|
<artifactId>ProtocolLib</artifactId>
|
||||||
|
<version>4.5.0</version>
|
||||||
|
<scope>system</scope>
|
||||||
|
<systemPath>${main.basedir}/lib/ProtocolLib.jar</systemPath>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</project>
|
</project>
|
||||||
|
@ -20,18 +20,33 @@
|
|||||||
package de.steamwar.bausystem.world;
|
package de.steamwar.bausystem.world;
|
||||||
|
|
||||||
|
|
||||||
|
import com.comphenix.protocol.PacketType;
|
||||||
|
import com.comphenix.protocol.events.PacketAdapter;
|
||||||
|
import com.comphenix.protocol.events.PacketContainer;
|
||||||
|
import com.comphenix.protocol.events.PacketEvent;
|
||||||
|
import com.comphenix.protocol.wrappers.BlockPosition;
|
||||||
import de.steamwar.bausystem.BauSystem;
|
import de.steamwar.bausystem.BauSystem;
|
||||||
import de.steamwar.bausystem.Permission;
|
import de.steamwar.bausystem.Permission;
|
||||||
import de.steamwar.core.Core;
|
import de.steamwar.core.Core;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
|
import com.comphenix.protocol.ProtocolLibrary;
|
||||||
|
import org.bukkit.block.Block;
|
||||||
|
import org.bukkit.block.Sign;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.EventPriority;
|
import org.bukkit.event.EventPriority;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
|
import org.bukkit.event.block.Action;
|
||||||
import org.bukkit.event.block.BlockBreakEvent;
|
import org.bukkit.event.block.BlockBreakEvent;
|
||||||
import org.bukkit.event.block.BlockPlaceEvent;
|
import org.bukkit.event.block.BlockPlaceEvent;
|
||||||
import org.bukkit.event.block.SignChangeEvent;
|
import org.bukkit.event.block.SignChangeEvent;
|
||||||
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
|
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
|
||||||
|
import org.bukkit.event.player.PlayerInteractEvent;
|
||||||
|
|
||||||
|
import java.util.logging.Level;
|
||||||
|
|
||||||
|
import java.lang.reflect.InvocationTargetException;
|
||||||
|
|
||||||
public class RegionListener implements Listener {
|
public class RegionListener implements Listener {
|
||||||
|
|
||||||
@ -98,4 +113,53 @@ public class RegionListener implements Listener {
|
|||||||
event.setLine(i, line);
|
event.setLine(i, line);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void editSign(PlayerInteractEvent event) {
|
||||||
|
if(event.getAction() != Action.RIGHT_CLICK_BLOCK ||
|
||||||
|
!event.getClickedBlock().getType().name().contains("_SIGN") ||
|
||||||
|
!event.getPlayer().isSneaking())
|
||||||
|
return;
|
||||||
|
Player player = event.getPlayer();
|
||||||
|
Sign sign = (Sign) event.getClickedBlock().getState();
|
||||||
|
String[] lines = sign.getLines();
|
||||||
|
for (int i = 0; i < lines.length; i++) {
|
||||||
|
sign.setLine(i, lines[i].replace('§', '&'));
|
||||||
|
}
|
||||||
|
sign.update();
|
||||||
|
PacketContainer signOpen = ProtocolLibrary.getProtocolManager().createPacket(PacketType.Play.Server.OPEN_SIGN_EDITOR);
|
||||||
|
signOpen.getBlockPositionModifier().write(0, new BlockPosition(event.getClickedBlock().getLocation().toVector()));
|
||||||
|
try {
|
||||||
|
ProtocolLibrary.getProtocolManager().sendServerPacket(player, signOpen);
|
||||||
|
} catch (InvocationTargetException e) {
|
||||||
|
Bukkit.getLogger().log(Level.SEVERE, "Invocation target exception", e);
|
||||||
|
}
|
||||||
|
|
||||||
|
ProtocolLibrary.getProtocolManager().addPacketListener(new PacketAdapter(BauSystem.getPlugin(), PacketType.Play.Client.UPDATE_SIGN) {
|
||||||
|
@Override
|
||||||
|
public void onPacketReceiving(PacketEvent event) {
|
||||||
|
if(!event.getPlayer().equals(player))
|
||||||
|
return;
|
||||||
|
event.setCancelled(true);
|
||||||
|
Bukkit.getScheduler().runTask(BauSystem.getPlugin(), () -> {
|
||||||
|
PacketContainer packetContainer = event.getPacket();
|
||||||
|
BlockPosition position = packetContainer.getBlockPositionModifier().read(0);
|
||||||
|
String[] lines = packetContainer.getStringArrays().read(0);
|
||||||
|
|
||||||
|
Block signLoc = position.toLocation(player.getWorld()).getBlock();
|
||||||
|
if(!signLoc.getType().name().contains("_SIGN"))
|
||||||
|
return;
|
||||||
|
|
||||||
|
Sign sign = ((Sign) signLoc.getState());
|
||||||
|
sign.setEditable(true);
|
||||||
|
for (int i = 0; i < lines.length; i++) {
|
||||||
|
sign.setLine(i, ChatColor.translateAlternateColorCodes('&', lines[i]));
|
||||||
|
}
|
||||||
|
sign.update();
|
||||||
|
|
||||||
|
ProtocolLibrary.getProtocolManager().removePacketListener(this);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
name: BauSystem
|
name: BauSystem
|
||||||
author: Lixfel
|
author: Lixfel
|
||||||
version: "1.0"
|
version: "1.0"
|
||||||
depend: [WorldEdit, SpigotCore]
|
depend: [WorldEdit, SpigotCore, ProtocolLib]
|
||||||
load: POSTWORLD
|
load: POSTWORLD
|
||||||
main: de.steamwar.bausystem.BauSystem
|
main: de.steamwar.bausystem.BauSystem
|
||||||
api-version: "1.13"
|
api-version: "1.13"
|
||||||
|
In neuem Issue referenzieren
Einen Benutzer sperren