Add group tags

This commit is contained in:
Daniel Saukel 2017-02-28 16:07:15 +01:00
parent da049b4618
commit 9c311c3108
6 changed files with 101 additions and 6 deletions

View File

@ -24,6 +24,7 @@ import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import org.bukkit.Bukkit;
import org.bukkit.GameMode; import org.bukkit.GameMode;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
@ -87,6 +88,7 @@ public class GameRules {
/* Misc */ /* Misc */
DEFAULT_VALUES.msgs = new HashMap<>(); DEFAULT_VALUES.msgs = new HashMap<>();
DEFAULT_VALUES.secureObjects = new ArrayList<>(); DEFAULT_VALUES.secureObjects = new ArrayList<>();
DEFAULT_VALUES.groupTagEnabled = false;
} }
/* keepInventory */ /* keepInventory */
@ -142,6 +144,7 @@ public class GameRules {
/* Misc */ /* Misc */
protected Map<Integer, String> msgs; protected Map<Integer, String> msgs;
protected List<ItemStack> secureObjects; protected List<ItemStack> secureObjects;
protected Boolean groupTagEnabled;
/* Getters and setters */ /* Getters and setters */
// keepInventory // keepInventory
@ -527,6 +530,18 @@ public class GameRules {
return secureObjects; 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 */ /* Actions */
/** /**
* @param defaultValues * @param defaultValues
@ -740,6 +755,10 @@ public class GameRules {
} else if (defaultValues.secureObjects != null) { } else if (defaultValues.secureObjects != null) {
secureObjects.addAll(defaultValues.secureObjects); secureObjects.addAll(defaultValues.secureObjects);
} }
if (groupTagEnabled == null) {
groupTagEnabled = defaultValues.groupTagEnabled;
}
} }
} }

View File

@ -78,6 +78,8 @@ public class DGamePlayer extends DInstancePlayer {
private ItemStack oldHelmet; private ItemStack oldHelmet;
private DGroup stealing; private DGroup stealing;
private DGroupTag groupTag;
public DGamePlayer(Player player, DGameWorld world) { public DGamePlayer(Player player, DGameWorld world) {
super(player, world.getWorld()); super(player, world.getWorld());
@ -410,6 +412,22 @@ public class DGamePlayer extends DInstancePlayer {
stealing = dGroup; 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 */ /* Actions */
public void captureFlag() { public void captureFlag() {
if (stealing == null) { if (stealing == null) {

View File

@ -778,7 +778,9 @@ public class DGroup {
if (dPlayer == null) { if (dPlayer == null) {
dPlayer = new DGamePlayer(player, gameWorld); dPlayer = new DGamePlayer(player, gameWorld);
} }
if (rules.isGroupTagEnabled()) {
dPlayer.initDGroupTag();
}
if (!dPlayer.isReady()) { if (!dPlayer.isReady()) {
ready = false; ready = false;
} }

View File

@ -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 <http://www.gnu.org/licenses/>.
*/
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));
}
}

View File

@ -417,12 +417,17 @@ public class DPlayerListener implements Listener {
} }
DGameWorld gameWorld = DGameWorld.getByWorld(player.getWorld()); DGameWorld gameWorld = DGameWorld.getByWorld(player.getWorld());
DGamePlayer gamePlayer = DGamePlayer.getByPlayer(player); DGamePlayer gamePlayer = DGamePlayer.getByPlayer(player);
if (gameWorld != null && gamePlayer != null && gamePlayer.isStealing()) { if (gameWorld != null && gamePlayer != null) {
DGroup group = gamePlayer.getDGroup(); if (gamePlayer.getDGroupTag() != null) {
Location startLocation = gameWorld.getStartLocation(group); gamePlayer.getDGroupTag().update();
}
if (gamePlayer.isStealing()) {
DGroup group = gamePlayer.getDGroup();
Location startLocation = gameWorld.getStartLocation(group);
if (startLocation.distance(player.getLocation()) < 3) { if (startLocation.distance(player.getLocation()) < 3) {
gamePlayer.captureFlag(); gamePlayer.captureFlag();
}
} }
} }
} }

View File

@ -292,6 +292,10 @@ public class WorldConfig extends GameRules {
if (configFile.contains("title.show")) { if (configFile.contains("title.show")) {
titleShow = (int) configFile.getDouble("title.show") * 20; titleShow = (int) configFile.getDouble("title.show") * 20;
} }
if (configFile.contains("groupTagEnabled")) {
groupTagEnabled = configFile.getBoolean("groupTagEnabled");
}
} }
public void save() { public void save() {