Rename stuff. Remove debug output.

This commit is contained in:
libraryaddict 2013-12-04 07:38:10 +13:00
parent 6420a989a9
commit 063b916c25
3 changed files with 74 additions and 51 deletions

View File

@ -1,6 +1,7 @@
package me.libraryaddict.disguise;
import java.lang.reflect.Field;
import java.util.Arrays;
import java.util.List;
import me.libraryaddict.disguise.disguisetypes.Disguise;
@ -59,14 +60,18 @@ public class DisguiseAPI {
DisguiseUtilities.setupFakeDisguise(disguise);
}
public static void disguiseIgnorePlayers(Entity entity, Disguise disguise, List<String> players) {
((TargetedDisguise) disguise).setTargetType(TargetType.SHOW_TO_EVERYONE_BUT_THESE_PLAYERS);
for (String name : players) {
((TargetedDisguise) disguise).setViewDisguise(name);
public static void disguiseIgnorePlayers(Entity entity, Disguise disguise, List<String> playersToNotSeeDisguise) {
((TargetedDisguise) disguise).setDisguiseTarget(TargetType.SHOW_TO_EVERYONE_BUT_THESE_PLAYERS);
for (String name : playersToNotSeeDisguise) {
((TargetedDisguise) disguise).addPlayer(name);
}
disguiseEntity(entity, disguise);
}
public static void disguiseIgnorePlayers(Entity entity, Disguise disguise, String... playersToNotSeeDisguise) {
disguiseIgnorePlayers(entity, disguise, Arrays.asList(playersToNotSeeDisguise));
}
/**
* Disguise the next entity to spawn with this disguise. This may not work however if the entity doesn't actually spawn.
*/
@ -91,20 +96,24 @@ public class DisguiseAPI {
*/
public static void disguiseToAll(Entity entity, Disguise disguise) {
// You called the disguiseToAll method foolish mortal! Prepare to have your custom settings wiped!!!
((TargetedDisguise) disguise).setTargetType(TargetType.SHOW_TO_EVERYONE_BUT_THESE_PLAYERS);
((TargetedDisguise) disguise).setDisguiseTarget(TargetType.SHOW_TO_EVERYONE_BUT_THESE_PLAYERS);
for (String observer : ((TargetedDisguise) disguise).getObservers())
((TargetedDisguise) disguise).unsetViewDisguise(observer);
((TargetedDisguise) disguise).removePlayer(observer);
disguiseEntity(entity, disguise);
}
public static void disguiseToPlayers(Entity entity, Disguise disguise, List<String> players) {
((TargetedDisguise) disguise).setTargetType(TargetType.HIDE_DISGUISE_TO_EVERYONE_BUT_THESE_PLAYERS);
for (String name : players) {
((TargetedDisguise) disguise).setViewDisguise(name);
public static void disguiseToPlayers(Entity entity, Disguise disguise, List<String> playersToViewDisguise) {
((TargetedDisguise) disguise).setDisguiseTarget(TargetType.HIDE_DISGUISE_TO_EVERYONE_BUT_THESE_PLAYERS);
for (String name : playersToViewDisguise) {
((TargetedDisguise) disguise).addPlayer(name);
}
disguiseEntity(entity, disguise);
}
public static void disguiseToPlayers(Entity entity, Disguise disguise, String... playersToViewDisguise) {
disguiseToPlayers(entity, disguise, Arrays.asList(playersToViewDisguise));
}
/**
* Get the disguise of a entity
*/

View File

@ -18,6 +18,20 @@ public abstract class TargetedDisguise extends Disguise {
private TargetType targetType = TargetType.SHOW_TO_EVERYONE_BUT_THESE_PLAYERS;
public void addPlayer(Player player) {
addPlayer(player.getName());
}
public void addPlayer(String playername) {
if (!disguiseViewers.contains(playername)) {
disguiseViewers.add(playername);
if (DisguiseAPI.isDisguiseInUse(this)) {
DisguiseUtilities.checkConflicts(this, playername);
DisguiseUtilities.refreshTracker(this, playername);
}
}
}
public boolean canSee(Player player) {
return canSee(player.getName());
}
@ -30,50 +44,44 @@ public abstract class TargetedDisguise extends Disguise {
return hasPlayer;
}
public TargetType getDisguiseTarget() {
return targetType;
}
public List<String> getObservers() {
return Collections.unmodifiableList(disguiseViewers);
}
public TargetType getTargetType() {
return targetType;
public void removePlayer(Player player) {
removePlayer(player.getName());
}
public void setTargetType(TargetType newTargetType) {
public void removePlayer(String playername) {
if (disguiseViewers.contains(playername)) {
disguiseViewers.remove(playername);
if (DisguiseAPI.isDisguiseInUse(this)) {
DisguiseUtilities.checkConflicts(this, playername);
DisguiseUtilities.refreshTracker(this, playername);
}
}
}
public void setDisguiseTarget(TargetType newTargetType) {
if (DisguiseUtilities.isDisguiseInUse(this)) {
throw new RuntimeException("Cannot set the disguise target after the entity has been disguised");
}
targetType = newTargetType;
}
public void silentlySetViewDisguise(String playername) {
public void silentlyAddPlayer(String playername) {
if (!disguiseViewers.contains(playername)) {
disguiseViewers.add(playername);
}
}
public void silentlyUnsetViewDisguise(String playername) {
public void silentlyRemovePlayer(String playername) {
if (disguiseViewers.contains(playername)) {
disguiseViewers.remove(playername);
}
}
public void setViewDisguise(String playername) {
if (!disguiseViewers.contains(playername)) {
disguiseViewers.add(playername);
if (DisguiseAPI.isDisguiseInUse(this)) {
DisguiseUtilities.checkConflicts(this, playername);
DisguiseUtilities.refreshTracker(this, playername);
}
}
}
public void unsetViewDisguise(String playername) {
if (disguiseViewers.contains(playername)) {
disguiseViewers.remove(playername);
if (DisguiseAPI.isDisguiseInUse(this)) {
DisguiseUtilities.checkConflicts(this, playername);
DisguiseUtilities.refreshTracker(this, playername);
}
}
}
}

View File

@ -2,7 +2,6 @@ package me.libraryaddict.disguise.utilities;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
@ -51,54 +50,61 @@ public class DisguiseUtilities {
* observers in the disguise don't see any other disguise.
*/
public static void checkConflicts(TargetedDisguise disguise, String name) {
// If the disguise is being used.. Else we may accidentally undisguise something else
if (DisguiseAPI.isDisguiseInUse(disguise)) {
Iterator<TargetedDisguise> disguiseItel = getDisguises().get(disguise.getEntity().getEntityId()).iterator();
// Iterate through the disguises
while (disguiseItel.hasNext()) {
TargetedDisguise d = disguiseItel.next();
// Make sure the disguise isn't the same thing
if (d != disguise) {
if (d.getTargetType() == TargetType.HIDE_DISGUISE_TO_EVERYONE_BUT_THESE_PLAYERS) {
// If the loop'd disguise is hiding the disguise to everyone in its list
if (d.getDisguiseTarget() == TargetType.HIDE_DISGUISE_TO_EVERYONE_BUT_THESE_PLAYERS) {
// If player is a observer in the loop
if (disguise.getTargetType() == TargetType.HIDE_DISGUISE_TO_EVERYONE_BUT_THESE_PLAYERS) {
if (disguise.getDisguiseTarget() == TargetType.HIDE_DISGUISE_TO_EVERYONE_BUT_THESE_PLAYERS) {
// If player is a observer in the disguise
// Remove them from the loop
if (name != null) {
d.unsetViewDisguise(name);
d.removePlayer(name);
} else {
for (String playername : disguise.getObservers()) {
d.silentlyUnsetViewDisguise(playername);
d.silentlyRemovePlayer(playername);
}
}
} else if (disguise.getTargetType() == TargetType.SHOW_TO_EVERYONE_BUT_THESE_PLAYERS) {
} else if (disguise.getDisguiseTarget() == TargetType.SHOW_TO_EVERYONE_BUT_THESE_PLAYERS) {
// If player is not a observer in the loop
if (name != null) {
if (!disguise.getObservers().contains(name)) {
d.unsetViewDisguise(name);
d.removePlayer(name);
}
} else {
for (String playername : d.getObservers()) {
if (!disguise.getObservers().contains(playername)) {
d.silentlyUnsetViewDisguise(playername);
d.silentlyRemovePlayer(playername);
}
}
}
}
} else if (d.getTargetType() == TargetType.SHOW_TO_EVERYONE_BUT_THESE_PLAYERS) {
} else if (d.getDisguiseTarget() == TargetType.SHOW_TO_EVERYONE_BUT_THESE_PLAYERS) {
// Here you add it to the loop if they see the disguise
if (disguise.getTargetType() == TargetType.HIDE_DISGUISE_TO_EVERYONE_BUT_THESE_PLAYERS) {
if (disguise.getDisguiseTarget() == TargetType.HIDE_DISGUISE_TO_EVERYONE_BUT_THESE_PLAYERS) {
// Everyone who is in the disguise needs to be added to the loop
if (name != null) {
d.setViewDisguise(name);
d.addPlayer(name);
} else {
for (String playername : disguise.getObservers()) {
d.silentlySetViewDisguise(playername);
d.silentlyAddPlayer(playername);
}
}
} else if (disguise.getTargetType() == TargetType.SHOW_TO_EVERYONE_BUT_THESE_PLAYERS) {
} else if (disguise.getDisguiseTarget() == TargetType.SHOW_TO_EVERYONE_BUT_THESE_PLAYERS) {
// This here is a paradox.
// If fed a name. I can do this.
// But the rest of the time.. Its going to conflict.
System.out.print("Cannot set more than one " + TargetType.SHOW_TO_EVERYONE_BUT_THESE_PLAYERS
+ " on a entity. Removed the old disguise.");
// The below is debug output. Most people wouldn't care for it.
// System.out.print("Cannot set more than one " + TargetType.SHOW_TO_EVERYONE_BUT_THESE_PLAYERS
// + " on a entity. Removed the old disguise.");
disguiseItel.remove();
/* if (name != null) {
if (!disguise.getObservers().contains(name)) {
@ -123,7 +129,7 @@ public class DisguiseUtilities {
TargetedDisguise toReturn = null;
if (getDisguises().containsKey(entityId)) {
for (TargetedDisguise disguise : getDisguises().get(entityId)) {
if (disguise.getTargetType() == TargetType.SHOW_TO_EVERYONE_BUT_THESE_PLAYERS
if (disguise.getDisguiseTarget() == TargetType.SHOW_TO_EVERYONE_BUT_THESE_PLAYERS
&& disguise.getObservers().isEmpty()) {
return disguise;
}