Maven Attempt 1

This commit is contained in:
Olof Larsson
2014-09-13 00:50:33 +02:00
parent 3debf17f27
commit 13a4afdfb4
170 changed files with 151 additions and 49 deletions

View File

@@ -1,97 +0,0 @@
package com.massivecraft.factions.util;
import java.util.*;
import org.bukkit.ChatColor;
public class AsciiCompass
{
public enum Point
{
N('N'),
NE('/'),
E('E'),
SE('\\'),
S('S'),
SW('/'),
W('W'),
NW('\\');
public final char asciiChar;
private Point(final char asciiChar)
{
this.asciiChar = asciiChar;
}
@Override
public String toString()
{
return String.valueOf(this.asciiChar);
}
public String toString(boolean isActive, ChatColor colorActive, String colorDefault)
{
return (isActive ? colorActive : colorDefault)+String.valueOf(this.asciiChar);
}
}
public static AsciiCompass.Point getCompassPointForDirection(double inDegrees)
{
double degrees = (inDegrees - 180) % 360 ;
if (degrees < 0)
degrees += 360;
if (0 <= degrees && degrees < 22.5)
return AsciiCompass.Point.N;
else if (22.5 <= degrees && degrees < 67.5)
return AsciiCompass.Point.NE;
else if (67.5 <= degrees && degrees < 112.5)
return AsciiCompass.Point.E;
else if (112.5 <= degrees && degrees < 157.5)
return AsciiCompass.Point.SE;
else if (157.5 <= degrees && degrees < 202.5)
return AsciiCompass.Point.S;
else if (202.5 <= degrees && degrees < 247.5)
return AsciiCompass.Point.SW;
else if (247.5 <= degrees && degrees < 292.5)
return AsciiCompass.Point.W;
else if (292.5 <= degrees && degrees < 337.5)
return AsciiCompass.Point.NW;
else if (337.5 <= degrees && degrees < 360.0)
return AsciiCompass.Point.N;
else
return null;
}
public static ArrayList<String> getAsciiCompass(Point point, ChatColor colorActive, String colorDefault)
{
ArrayList<String> ret = new ArrayList<String>();
String row;
row = "";
row += Point.NW.toString(Point.NW == point, colorActive, colorDefault);
row += Point.N.toString(Point.N == point, colorActive, colorDefault);
row += Point.NE.toString(Point.NE == point, colorActive, colorDefault);
ret.add(row);
row = "";
row += Point.W.toString(Point.W == point, colorActive, colorDefault);
row += colorDefault+"+";
row += Point.E.toString(Point.E == point, colorActive, colorDefault);
ret.add(row);
row = "";
row += Point.SW.toString(Point.SW == point, colorActive, colorDefault);
row += Point.S.toString(Point.S == point, colorActive, colorDefault);
row += Point.SE.toString(Point.SE == point, colorActive, colorDefault);
ret.add(row);
return ret;
}
public static ArrayList<String> getAsciiCompass(double inDegrees, ChatColor colorActive, String colorDefault)
{
return getAsciiCompass(getCompassPointForDirection(inDegrees), colorActive, colorDefault);
}
}

View File

@@ -1,52 +0,0 @@
package com.massivecraft.factions.util;
import java.util.Arrays;
import java.util.HashSet;
import org.bukkit.ChatColor;
public class MiscUtil
{
// Inclusive range
public static long[] range(long start, long end) {
long[] values = new long[(int) Math.abs(end - start) + 1];
if (end < start) {
long oldstart = start;
start = end;
end = oldstart;
}
for (long i = start; i <= end; i++) {
values[(int) (i - start)] = i;
}
return values;
}
public static HashSet<String> substanceChars = new HashSet<String>(Arrays.asList(new String []{
"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F", "G", "H",
"I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z",
"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r",
"s", "t", "u", "v", "w", "x", "y", "z"
}));
public static String getComparisonString(String str)
{
String ret = "";
str = ChatColor.stripColor(str);
str = str.toLowerCase();
for (char c : str.toCharArray())
{
if (substanceChars.contains(String.valueOf(c)))
{
ret += c;
}
}
return ret.toLowerCase();
}
}

View File

@@ -1,148 +0,0 @@
package com.massivecraft.factions.util;
import org.bukkit.ChatColor;
import com.massivecraft.factions.FFlag;
import com.massivecraft.factions.Rel;
import com.massivecraft.factions.RelationParticipator;
import com.massivecraft.factions.entity.UPlayer;
import com.massivecraft.factions.entity.Faction;
import com.massivecraft.factions.entity.MConf;
import com.massivecraft.massivecore.util.Txt;
public class RelationUtil
{
public static String describeThatToMe(RelationParticipator that, RelationParticipator me, boolean ucfirst)
{
String ret = "";
if (that == null)
{
return "A server admin";
}
Faction thatFaction = getFaction(that);
if (thatFaction == null) return "ERROR"; // ERROR
Faction myFaction = getFaction(me);
// if (myFaction == null) return thatFaction.getTag(); // no relation, but can show basic name or tag
if (that instanceof Faction)
{
if (me instanceof UPlayer && myFaction == thatFaction)
{
ret = "your faction";
}
else
{
ret = thatFaction.getName();
}
}
else if (that instanceof UPlayer)
{
UPlayer uplayerthat = (UPlayer) that;
if (that == me)
{
ret = "you";
}
else if (thatFaction == myFaction)
{
ret = uplayerthat.getNameAndTitle(myFaction);
}
else
{
ret = uplayerthat.getNameAndFactionName();
}
}
if (ucfirst)
{
ret = Txt.upperCaseFirst(ret);
}
return "" + getColorOfThatToMe(that, me) + ret;
}
public static String describeThatToMe(RelationParticipator that, RelationParticipator me)
{
return describeThatToMe(that, me, false);
}
public static Rel getRelationOfThatToMe(RelationParticipator that, RelationParticipator me)
{
return getRelationOfThatToMe(that, me, false);
}
public static Rel getRelationOfThatToMe(RelationParticipator that, RelationParticipator me, boolean ignorePeaceful)
{
Rel ret = null;
Faction myFaction = getFaction(me);
if (myFaction == null) return Rel.NEUTRAL; // ERROR
Faction thatFaction = getFaction(that);
if (thatFaction == null) return Rel.NEUTRAL; // ERROR
// The faction with the lowest wish "wins"
if (thatFaction.getRelationWish(myFaction).isLessThan(myFaction.getRelationWish(thatFaction)))
{
ret = thatFaction.getRelationWish(myFaction);
}
else
{
ret = myFaction.getRelationWish(thatFaction);
}
if (myFaction.equals(thatFaction))
{
ret = Rel.MEMBER;
// Do officer and leader check
//P.p.log("getRelationOfThatToMe the factions are the same for "+that.getClass().getSimpleName()+" and observer "+me.getClass().getSimpleName());
if (that instanceof UPlayer)
{
ret = ((UPlayer)that).getRole();
//P.p.log("getRelationOfThatToMe it was a player and role is "+ret);
}
}
else if (!ignorePeaceful && (thatFaction.getFlag(FFlag.PEACEFUL) || myFaction.getFlag(FFlag.PEACEFUL)))
{
ret = Rel.TRUCE;
}
return ret;
}
public static Faction getFaction(RelationParticipator rp)
{
if (rp instanceof Faction)
{
return (Faction) rp;
}
if (rp instanceof UPlayer)
{
return ((UPlayer) rp).getFaction();
}
// ERROR
return null;
}
public static ChatColor getColorOfThatToMe(RelationParticipator that, RelationParticipator me)
{
Faction thatFaction = getFaction(that);
if (thatFaction != null && thatFaction != getFaction(me))
{
if (thatFaction.getFlag(FFlag.FRIENDLYFIRE) == true)
{
return MConf.get().colorFriendlyFire;
}
if (thatFaction.getFlag(FFlag.PVP) == false)
{
return MConf.get().colorNoPVP;
}
}
return getRelationOfThatToMe(that, me).getColor();
}
}

View File

@@ -1,110 +0,0 @@
package com.massivecraft.factions.util;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.UUID;
import org.bukkit.Location;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
// TODO: Only send blocks in visual range
// TODO: Only send blocks that where changed when clearing?
// TODO: Create packed queue to avoid freezes.
public class VisualizeUtil
{
protected static Map<UUID, Set<Location>> playerLocations = new HashMap<UUID, Set<Location>>();
public static Set<Location> getPlayerLocations(Player player)
{
return getPlayerLocations(player.getUniqueId());
}
public static Set<Location> getPlayerLocations(UUID uuid)
{
Set<Location> ret = playerLocations.get(uuid);
if (ret == null)
{
ret = new HashSet<Location>();
playerLocations.put(uuid, ret);
}
return ret;
}
// -------------------------------------------- //
// SINGLE
// -------------------------------------------- //
@SuppressWarnings("deprecation")
public static void addLocation(Player player, Location location, int typeId, byte data)
{
getPlayerLocations(player).add(location);
player.sendBlockChange(location, typeId, data);
}
@SuppressWarnings("deprecation")
public static void addLocation(Player player, Location location, int typeId)
{
getPlayerLocations(player).add(location);
player.sendBlockChange(location, typeId, (byte) 0);
}
// -------------------------------------------- //
// MANY
// -------------------------------------------- //
@SuppressWarnings("deprecation")
public static void addLocations(Player player, Map<Location, Integer> locationMaterialIds)
{
Set<Location> ploc = getPlayerLocations(player);
for (Entry<Location, Integer> entry : locationMaterialIds.entrySet())
{
ploc.add(entry.getKey());
player.sendBlockChange(entry.getKey(), entry.getValue(), (byte) 0);
}
}
@SuppressWarnings("deprecation")
public static void addLocations(Player player, Collection<Location> locations, int typeId)
{
Set<Location> ploc = getPlayerLocations(player);
for (Location location : locations)
{
ploc.add(location);
player.sendBlockChange(location, typeId, (byte) 0);
}
}
@SuppressWarnings("deprecation")
public static void addBlocks(Player player, Collection<Block> blocks, int typeId)
{
Set<Location> ploc = getPlayerLocations(player);
for (Block block : blocks)
{
Location location = block.getLocation();
ploc.add(location);
player.sendBlockChange(location, typeId, (byte) 0);
}
}
// -------------------------------------------- //
// CLEAR
// -------------------------------------------- //
@SuppressWarnings("deprecation")
public static void clear(Player player)
{
Set<Location> locations = getPlayerLocations(player);
if (locations == null) return;
for (Location location : locations)
{
Block block = location.getWorld().getBlockAt(location);
player.sendBlockChange(location, block.getTypeId(), block.getData());
}
locations.clear();
}
}