diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/game/GameRules.java b/core/src/main/java/io/github/dre2n/dungeonsxl/game/GameRules.java index 4f1183f4..6c7dbe09 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/game/GameRules.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/game/GameRules.java @@ -24,6 +24,7 @@ import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Set; +import org.bukkit.Bukkit; import org.bukkit.GameMode; import org.bukkit.Material; import org.bukkit.inventory.ItemStack; @@ -87,6 +88,7 @@ public class GameRules { /* Misc */ DEFAULT_VALUES.msgs = new HashMap<>(); DEFAULT_VALUES.secureObjects = new ArrayList<>(); + DEFAULT_VALUES.groupTagEnabled = false; } /* keepInventory */ @@ -142,6 +144,7 @@ public class GameRules { /* Misc */ protected Map msgs; protected List secureObjects; + protected Boolean groupTagEnabled; /* Getters and setters */ // keepInventory @@ -527,6 +530,18 @@ public class GameRules { return secureObjects; } + /** + * @return + * if the group tag is enabled. + * Returns false if HolographicDisplays isn't loaded + */ + public boolean isGroupTagEnabled() { + if (!Bukkit.getPluginManager().isPluginEnabled("HolographicDisplays")) { + return false; + } + return groupTagEnabled; + } + /* Actions */ /** * @param defaultValues @@ -740,6 +755,10 @@ public class GameRules { } else if (defaultValues.secureObjects != null) { secureObjects.addAll(defaultValues.secureObjects); } + + if (groupTagEnabled == null) { + groupTagEnabled = defaultValues.groupTagEnabled; + } } } diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/player/DGamePlayer.java b/core/src/main/java/io/github/dre2n/dungeonsxl/player/DGamePlayer.java index 63727a41..7c8ad116 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/player/DGamePlayer.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/player/DGamePlayer.java @@ -78,6 +78,8 @@ public class DGamePlayer extends DInstancePlayer { private ItemStack oldHelmet; private DGroup stealing; + private DGroupTag groupTag; + public DGamePlayer(Player player, DGameWorld world) { super(player, world.getWorld()); @@ -410,6 +412,22 @@ public class DGamePlayer extends DInstancePlayer { stealing = dGroup; } + /** + * @return + * the player's group tag + */ + public DGroupTag getDGroupTag() { + return groupTag; + } + + /** + * @return + * the player's group tag + */ + public void initDGroupTag() { + groupTag = new DGroupTag(this); + } + /* Actions */ public void captureFlag() { if (stealing == null) { diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/player/DGroup.java b/core/src/main/java/io/github/dre2n/dungeonsxl/player/DGroup.java index 7ed81a1d..9077b100 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/player/DGroup.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/player/DGroup.java @@ -778,7 +778,9 @@ public class DGroup { if (dPlayer == null) { dPlayer = new DGamePlayer(player, gameWorld); } - + if (rules.isGroupTagEnabled()) { + dPlayer.initDGroupTag(); + } if (!dPlayer.isReady()) { ready = false; } diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/player/DGroupTag.java b/core/src/main/java/io/github/dre2n/dungeonsxl/player/DGroupTag.java new file mode 100644 index 00000000..d62f389a --- /dev/null +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/player/DGroupTag.java @@ -0,0 +1,47 @@ +/* + * Copyright (C) 2012-2017 Frank Baumann + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package io.github.dre2n.dungeonsxl.player; + +import com.gmail.filoghost.holographicdisplays.api.Hologram; +import com.gmail.filoghost.holographicdisplays.api.HologramsAPI; +import io.github.dre2n.dungeonsxl.DungeonsXL; +import org.bukkit.Material; +import org.bukkit.inventory.ItemStack; + +/** + * @author Daniel Saukel + */ +public class DGroupTag { + + private DGamePlayer player; + private Hologram hologram; + + public DGroupTag(DGamePlayer player) { + this.player = player; + DGroup group = player.getDGroup(); + if (group != null) { + hologram = HologramsAPI.createHologram(DungeonsXL.getInstance(), player.getPlayer().getLocation().clone().add(0, 3.5, 0)); + hologram.appendItemLine(new ItemStack(Material.WOOL, 1, group.getDColor().getWoolData())); + hologram.appendTextLine(group.getName()); + } + } + + public void update() { + hologram.teleport(player.getPlayer().getLocation().clone().add(0, 3.5, 0)); + } + +} diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/player/DPlayerListener.java b/core/src/main/java/io/github/dre2n/dungeonsxl/player/DPlayerListener.java index fd8b122e..9ec34d4a 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/player/DPlayerListener.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/player/DPlayerListener.java @@ -417,12 +417,17 @@ public class DPlayerListener implements Listener { } DGameWorld gameWorld = DGameWorld.getByWorld(player.getWorld()); DGamePlayer gamePlayer = DGamePlayer.getByPlayer(player); - if (gameWorld != null && gamePlayer != null && gamePlayer.isStealing()) { - DGroup group = gamePlayer.getDGroup(); - Location startLocation = gameWorld.getStartLocation(group); + if (gameWorld != null && gamePlayer != null) { + if (gamePlayer.getDGroupTag() != null) { + gamePlayer.getDGroupTag().update(); + } + if (gamePlayer.isStealing()) { + DGroup group = gamePlayer.getDGroup(); + Location startLocation = gameWorld.getStartLocation(group); - if (startLocation.distance(player.getLocation()) < 3) { - gamePlayer.captureFlag(); + if (startLocation.distance(player.getLocation()) < 3) { + gamePlayer.captureFlag(); + } } } } diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/world/WorldConfig.java b/core/src/main/java/io/github/dre2n/dungeonsxl/world/WorldConfig.java index b172d2ae..ff4839b9 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/world/WorldConfig.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/world/WorldConfig.java @@ -292,6 +292,10 @@ public class WorldConfig extends GameRules { if (configFile.contains("title.show")) { titleShow = (int) configFile.getDouble("title.show") * 20; } + + if (configFile.contains("groupTagEnabled")) { + groupTagEnabled = configFile.getBoolean("groupTagEnabled"); + } } public void save() {