From 7d150d24e1e2270b065a197d42b3a8faf300b5af Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sat, 26 Mar 2022 16:09:49 +0100 Subject: [PATCH] Add clickable messages --- src/de/steamwar/lobby/LobbySystem.properties | 4 ++ src/de/steamwar/lobby/team/TeamPlayer.java | 59 +++++++++++++++----- 2 files changed, 49 insertions(+), 14 deletions(-) diff --git a/src/de/steamwar/lobby/LobbySystem.properties b/src/de/steamwar/lobby/LobbySystem.properties index a157b1b..84304c5 100644 --- a/src/de/steamwar/lobby/LobbySystem.properties +++ b/src/de/steamwar/lobby/LobbySystem.properties @@ -3,6 +3,10 @@ TIME = HH:mm:ss DATE=........ COMMAND_HELP_HEAD=§7---=== (§e{0}§7) ===--- +# ServerTeamNPC's +NPC_CHAT_1 = §fHallo, ich bin {0} und habe den Rang {1}. +NPC_CHAT_2 = §fWillkommen auf §eSteam§8War§f, viel Spaß dir. + # Portal Command PORTAL_COMMAND_LIST_HELP = §8/§7portal §elist §8- §7Listet alle Portale auf PORTAL_COMMAND_ADD_HELP = §8/§7portal §ecreate §8[§7PortalType§8] §8[§7PortalName§8] §8- §7Fügt ein Portal hinzu diff --git a/src/de/steamwar/lobby/team/TeamPlayer.java b/src/de/steamwar/lobby/team/TeamPlayer.java index ea44726..6c79212 100644 --- a/src/de/steamwar/lobby/team/TeamPlayer.java +++ b/src/de/steamwar/lobby/team/TeamPlayer.java @@ -29,10 +29,13 @@ import org.bukkit.Location; import org.bukkit.World; import org.bukkit.entity.Entity; import org.bukkit.entity.EntityType; +import org.bukkit.entity.Player; import org.bukkit.entity.Villager; import org.bukkit.event.EventHandler; import org.bukkit.event.entity.EntityDamageEvent; import org.bukkit.event.entity.EntityInteractEvent; +import org.bukkit.event.player.PlayerInteractEntityEvent; +import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.potion.PotionEffect; import org.bukkit.potion.PotionEffectType; @@ -43,20 +46,6 @@ import java.util.stream.Collectors; public class TeamPlayer extends BasicListener { - @AllArgsConstructor - private static class Cuboid { - private double x1; - private double y1; - private double z1; - private double x2; - private double y2; - private double z2; - - public boolean contains(Location location) { - return location.getX() >= x1 && location.getX() <= x2 && location.getY() >= y1 && location.getY() <= y2 && location.getZ() >= z1 && location.getZ() <= z2; - } - } - private static final List cuboids = new ArrayList<>(); static { @@ -70,6 +59,15 @@ public class TeamPlayer extends BasicListener { private static final World world = Bukkit.getWorlds().get(0); private static final Map entities = new HashMap<>(); + private Set players = new HashSet<>(); + + private Random random = new Random(); + private List strings = new ArrayList<>(); + { + strings.add("NPC_CHAT_1"); + strings.add("NPC_CHAT_2"); + } + public static void spawnTeamPlayer(World world, SteamwarUser steamwarUser) { Location location = new Location(world, 1524.5, 52, 1484.5); String name = steamwarUser.getUserName(); @@ -157,6 +155,25 @@ public class TeamPlayer extends BasicListener { return false; } + @EventHandler + public void onPlayerInteractEntity(PlayerInteractEntityEvent event) { + if (!(event.getRightClicked() instanceof Villager)) { + return; + } + if (!players.add(event.getPlayer())) { + players.remove(event.getPlayer()); + return; + } + SteamwarUser user = SteamwarUser.get(event.getRightClicked().getName()); + String message = strings.get(random.nextInt(strings.size())); + LobbySystem.getMessage().send(message, event.getPlayer(), event.getRightClicked().getName(), user.getUserGroup().getColorCode() + user.getUserGroup().name()); + } + + @EventHandler + public void onPlayerQuit(PlayerQuitEvent event) { + players.remove(event.getPlayer()); + } + @EventHandler public void onEntityInteract(EntityInteractEvent event) { if (event.getEntityType() == EntityType.VILLAGER) { @@ -170,4 +187,18 @@ public class TeamPlayer extends BasicListener { event.setCancelled(true); } } + + @AllArgsConstructor + private static class Cuboid { + private double x1; + private double y1; + private double z1; + private double x2; + private double y2; + private double z2; + + public boolean contains(Location location) { + return location.getX() >= x1 && location.getX() <= x2 && location.getY() >= y1 && location.getY() <= y2 && location.getZ() >= z1 && location.getZ() <= z2; + } + } }