Hologram command
Dieser Commit ist enthalten in:
Ursprung
e1b0bdfc72
Commit
e3d8e60aea
@ -19,6 +19,7 @@
|
|||||||
|
|
||||||
package de.steamwar.lobby;
|
package de.steamwar.lobby;
|
||||||
|
|
||||||
|
import de.steamwar.lobby.command.HologramCommand;
|
||||||
import de.steamwar.lobby.command.PortalCommand;
|
import de.steamwar.lobby.command.PortalCommand;
|
||||||
import de.steamwar.lobby.listener.Fightservers;
|
import de.steamwar.lobby.listener.Fightservers;
|
||||||
import de.steamwar.lobby.listener.Join;
|
import de.steamwar.lobby.listener.Join;
|
||||||
@ -28,8 +29,7 @@ import org.bukkit.plugin.java.JavaPlugin;
|
|||||||
|
|
||||||
public class LobbySystem extends JavaPlugin {
|
public class LobbySystem extends JavaPlugin {
|
||||||
|
|
||||||
// This should be treated as final!
|
private static Message message;
|
||||||
public static Message MESSAGE;
|
|
||||||
private static LobbySystem plugin;
|
private static LobbySystem plugin;
|
||||||
private static Config config;
|
private static Config config;
|
||||||
|
|
||||||
@ -40,14 +40,15 @@ public class LobbySystem extends JavaPlugin {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onEnable() {
|
public void onEnable() {
|
||||||
MESSAGE = new Message("de.steamwar.lobby.LobbySystem", getClassLoader());
|
message = new Message("de.steamwar.lobby.LobbySystem", getClassLoader());
|
||||||
|
|
||||||
new Join();
|
new Join();
|
||||||
new Fightservers();
|
new Fightservers();
|
||||||
new Portals();
|
new Portals();
|
||||||
config = new Config(getConfig());
|
|
||||||
|
|
||||||
new PortalCommand();
|
new PortalCommand();
|
||||||
|
new HologramCommand();
|
||||||
|
|
||||||
|
config = new Config(getConfig());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static LobbySystem getPlugin() {
|
public static LobbySystem getPlugin() {
|
||||||
@ -57,4 +58,8 @@ public class LobbySystem extends JavaPlugin {
|
|||||||
public static Config config() {
|
public static Config config() {
|
||||||
return config;
|
return config;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Message getMessage() {
|
||||||
|
return message;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
63
src/de/steamwar/lobby/command/HologramCommand.java
Normale Datei
63
src/de/steamwar/lobby/command/HologramCommand.java
Normale Datei
@ -0,0 +1,63 @@
|
|||||||
|
/*
|
||||||
|
* This file is a part of the SteamWar software.
|
||||||
|
*
|
||||||
|
* Copyright (C) 2021 SteamWar.de-Serverteam
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Affero General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Affero General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package de.steamwar.lobby.command;
|
||||||
|
|
||||||
|
import de.steamwar.command.SWCommand;
|
||||||
|
import de.steamwar.lobby.LobbySystem;
|
||||||
|
import de.steamwar.lobby.display.Hologram;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
public class HologramCommand extends SWCommand {
|
||||||
|
|
||||||
|
public HologramCommand() {
|
||||||
|
super("hologram");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Register(help = true)
|
||||||
|
public void genericHelp(Player player, String... args) {
|
||||||
|
if (PortalCommand.noPermissions(player)) return;
|
||||||
|
|
||||||
|
player.sendMessage("/hologram create <id> <text>");
|
||||||
|
player.sendMessage("/hologram list");
|
||||||
|
player.sendMessage("/hologram delete <id>");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Register("create")
|
||||||
|
public void portalCreate(Player player, String id, String... text) {
|
||||||
|
if (PortalCommand.noPermissions(player)) return;
|
||||||
|
|
||||||
|
new Hologram(id, player.getLocation(), String.join(" ", text));
|
||||||
|
LobbySystem.config().save();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Register("list")
|
||||||
|
public void portalList(Player player) {
|
||||||
|
if (PortalCommand.noPermissions(player)) return;
|
||||||
|
Hologram.getHolograms().forEach(hologram -> player.sendMessage(hologram.toString()));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Register("delete")
|
||||||
|
public void portalDelete(Player player, String id) {
|
||||||
|
if (PortalCommand.noPermissions(player)) return;
|
||||||
|
|
||||||
|
Hologram.getHologram(id).delete();
|
||||||
|
LobbySystem.config().save();
|
||||||
|
}
|
||||||
|
}
|
@ -25,7 +25,7 @@ public class PortalCommand extends SWCommand {
|
|||||||
super("portal");
|
super("portal");
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean noPermissions(Player player) {
|
public static boolean noPermissions(Player player) {
|
||||||
SteamwarUser steamwarUser = SteamwarUser.get(player.getUniqueId());
|
SteamwarUser steamwarUser = SteamwarUser.get(player.getUniqueId());
|
||||||
return !steamwarUser.getUserGroup().isTeamGroup();
|
return !steamwarUser.getUserGroup().isTeamGroup();
|
||||||
}
|
}
|
||||||
@ -33,18 +33,18 @@ public class PortalCommand extends SWCommand {
|
|||||||
@Register(help = true)
|
@Register(help = true)
|
||||||
public void genericHelp(Player player, String... args) {
|
public void genericHelp(Player player, String... args) {
|
||||||
if (noPermissions(player)) return;
|
if (noPermissions(player)) return;
|
||||||
LobbySystem.MESSAGE.sendPrefixless("COMMAND_HELP_HEAD", player, "portal");
|
LobbySystem.getMessage().sendPrefixless("COMMAND_HELP_HEAD", player, "portal");
|
||||||
LobbySystem.MESSAGE.sendPrefixless("PORTAL_COMMAND_LIST_HELP", player);
|
LobbySystem.getMessage().sendPrefixless("PORTAL_COMMAND_LIST_HELP", player);
|
||||||
LobbySystem.MESSAGE.sendPrefixless("PORTAL_COMMAND_ADD_HELP", player);
|
LobbySystem.getMessage().sendPrefixless("PORTAL_COMMAND_ADD_HELP", player);
|
||||||
LobbySystem.MESSAGE.sendPrefixless("PORTAL_COMMAND_REMOVE_HELP", player);
|
LobbySystem.getMessage().sendPrefixless("PORTAL_COMMAND_REMOVE_HELP", player);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Register("list")
|
@Register("list")
|
||||||
public void portalList(Player player) {
|
public void portalList(Player player) {
|
||||||
if (noPermissions(player)) return;
|
if (noPermissions(player)) return;
|
||||||
LobbySystem.MESSAGE.sendPrefixless("COMMAND_HELP_HEAD", player, "portal list");
|
LobbySystem.getMessage().sendPrefixless("COMMAND_HELP_HEAD", player, "portal list");
|
||||||
Portal.getPortals().forEach(portal -> {
|
Portal.getPortals().forEach(portal -> {
|
||||||
LobbySystem.MESSAGE.sendPrefixless("PORTAL_COMMAND_LIST_SHORT_INFO", player, portal.type().name(), portal.getId(), portal.getPos1().toVector().toString(), portal.getPos1().toVector().toString());
|
LobbySystem.getMessage().sendPrefixless("PORTAL_COMMAND_LIST_SHORT_INFO", player, portal.type().name(), portal.getId(), portal.getPos1().toVector().toString(), portal.getPos1().toVector().toString());
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -53,7 +53,7 @@ public class PortalCommand extends SWCommand {
|
|||||||
if (noPermissions(player)) return;
|
if (noPermissions(player)) return;
|
||||||
Tuple<Location, Location> tuple = getSelection(player);
|
Tuple<Location, Location> tuple = getSelection(player);
|
||||||
if (tuple == null) {
|
if (tuple == null) {
|
||||||
LobbySystem.MESSAGE.send("PORTAL_NO_WORLDEDIT_SELECTION", player);
|
LobbySystem.getMessage().send("PORTAL_NO_WORLDEDIT_SELECTION", player);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
new Portal(portalName, tuple.k, tuple.v, portal -> new CommandPortal(String.join(" ", command)));
|
new Portal(portalName, tuple.k, tuple.v, portal -> new CommandPortal(String.join(" ", command)));
|
||||||
@ -64,7 +64,7 @@ public class PortalCommand extends SWCommand {
|
|||||||
if (noPermissions(player)) return;
|
if (noPermissions(player)) return;
|
||||||
Tuple<Location, Location> tuple = getSelection(player);
|
Tuple<Location, Location> tuple = getSelection(player);
|
||||||
if (tuple == null) {
|
if (tuple == null) {
|
||||||
LobbySystem.MESSAGE.send("PORTAL_NO_WORLDEDIT_SELECTION", player);
|
LobbySystem.getMessage().send("PORTAL_NO_WORLDEDIT_SELECTION", player);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
new Portal(portalName, tuple.k, tuple.v, portal -> new FightserverPortal(portal, group, target));
|
new Portal(portalName, tuple.k, tuple.v, portal -> new FightserverPortal(portal, group, target));
|
||||||
@ -75,7 +75,7 @@ public class PortalCommand extends SWCommand {
|
|||||||
if (noPermissions(player)) return;
|
if (noPermissions(player)) return;
|
||||||
Tuple<Location, Location> tuple = getSelection(player);
|
Tuple<Location, Location> tuple = getSelection(player);
|
||||||
if (tuple == null) {
|
if (tuple == null) {
|
||||||
LobbySystem.MESSAGE.send("PORTAL_NO_WORLDEDIT_SELECTION", player);
|
LobbySystem.getMessage().send("PORTAL_NO_WORLDEDIT_SELECTION", player);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
new Portal(portalName, tuple.k, tuple.v, portal -> new TeleportPortal(portal, portalDestination));
|
new Portal(portalName, tuple.k, tuple.v, portal -> new TeleportPortal(portal, portalDestination));
|
||||||
@ -86,7 +86,7 @@ public class PortalCommand extends SWCommand {
|
|||||||
if (noPermissions(player)) return;
|
if (noPermissions(player)) return;
|
||||||
Tuple<Location, Location> tuple = getSelection(player);
|
Tuple<Location, Location> tuple = getSelection(player);
|
||||||
if (tuple == null) {
|
if (tuple == null) {
|
||||||
LobbySystem.MESSAGE.send("PORTAL_NO_WORLDEDIT_SELECTION", player);
|
LobbySystem.getMessage().send("PORTAL_NO_WORLDEDIT_SELECTION", player);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
new Portal(portalName, tuple.k, tuple.v, portal -> new StackPortal(portal, portalDestination, String.join(" ", command)));
|
new Portal(portalName, tuple.k, tuple.v, portal -> new StackPortal(portal, portalDestination, String.join(" ", command)));
|
||||||
|
@ -74,12 +74,15 @@ public class Hologram implements ConfigurationSerializable {
|
|||||||
private static final Reflection.ConstructorInvoker destoryPacketConstructor = Reflection.getConstructor(destroyPacket);
|
private static final Reflection.ConstructorInvoker destoryPacketConstructor = Reflection.getConstructor(destroyPacket);
|
||||||
private static final Reflection.FieldAccessor<int[]> destroyIds = Reflection.getField(destroyPacket, int[].class, 0);
|
private static final Reflection.FieldAccessor<int[]> destroyIds = Reflection.getField(destroyPacket, int[].class, 0);
|
||||||
|
|
||||||
private static final List<Hologram> holograms = new ArrayList<>();
|
private static final Map<String, Hologram> holograms = new HashMap<>();
|
||||||
private static int entityIds = -1;
|
private static int entityIds = -1;
|
||||||
private static final Random random = new Random();
|
private static final Random random = new Random();
|
||||||
|
|
||||||
public static List<Hologram> getHolograms() {
|
public static List<Hologram> getHolograms() {
|
||||||
return holograms;
|
return new ArrayList<>(holograms.values());
|
||||||
|
}
|
||||||
|
public static Hologram getHologram(String id) {
|
||||||
|
return holograms.get(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
private final Displayable display;
|
private final Displayable display;
|
||||||
@ -114,7 +117,7 @@ public class Hologram implements ConfigurationSerializable {
|
|||||||
display = new Displayable(location, this::show, this::hide);
|
display = new Displayable(location, this::show, this::hide);
|
||||||
|
|
||||||
if(id != null)
|
if(id != null)
|
||||||
holograms.add(this);
|
holograms.put(id, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void show(Player player) {
|
private void show(Player player) {
|
||||||
@ -151,4 +154,9 @@ public class Hologram implements ConfigurationSerializable {
|
|||||||
if(id != null)
|
if(id != null)
|
||||||
holograms.remove(this);
|
holograms.remove(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return id + " " + location + " " + text;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
In neuem Issue referenzieren
Einen Benutzer sperren