Skip to content

Commit

Permalink
Change some stuff to work with CivCraft.
Browse files Browse the repository at this point in the history
  • Loading branch information
ataranlen committed Feb 19, 2016
1 parent 1e5de0d commit 5fb5520
Show file tree
Hide file tree
Showing 6 changed files with 213 additions and 42 deletions.
7 changes: 4 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<groupId>net.md-5</groupId>
<artifactId>iTag</artifactId>
<version>1.1.0-SNAPSHOT</version>
<version>1.1.2-SNAPSHOT</version>
<packaging>jar</packaging>

<name>iTag</name>
Expand Down Expand Up @@ -41,8 +41,9 @@
<dependency>
<groupId>com.comphenix.protocol</groupId>
<artifactId>ProtocolLib</artifactId>
<version>3.6.3-SNAPSHOT</version>
<scope>compile</scope>
<version>3.6.5-SNAPSHOT</version>
<scope>system</scope>
<systemPath>D:/civcraftsvn/trunk/lib/ProtocolLib.jar</systemPath>
</dependency>
<dependency>
<groupId>org.bukkit</groupId>
Expand Down
38 changes: 31 additions & 7 deletions src/main/java/net/md_5/itag/iTag.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,17 @@
import com.comphenix.protocol.wrappers.PlayerInfoData;
import com.comphenix.protocol.wrappers.WrappedGameProfile;
import com.google.common.base.Preconditions;

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.UUID;

import lombok.Getter;

import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
Expand All @@ -27,9 +31,8 @@

public class iTag extends JavaPlugin implements Listener
{

@Getter
private static iTag instance;
public static iTag instance;
private TagAPI tagAPI;
private Map<Integer, Player> entityIdMap;
private static final int[] uuidSplit = new int[]
Expand All @@ -42,7 +45,7 @@ public void onEnable()
{
instance = this;
entityIdMap = new HashMap<Integer, Player>();
tagAPI = new TagAPI( this );
setTagAPI(new TagAPI( this ));

for ( Player player : getServer().getOnlinePlayers() )
{
Expand Down Expand Up @@ -101,7 +104,7 @@ public void onDisable()

entityIdMap.clear();
entityIdMap = null;
tagAPI = null;
setTagAPI(null);
instance = null;
}

Expand Down Expand Up @@ -132,10 +135,9 @@ private WrappedGameProfile getSentName(int sentEntityId, WrappedGameProfile sent
}
AsyncPlayerReceiveNameTagEvent newEvent = new AsyncPlayerReceiveNameTagEvent( destinationPlayer, namedPlayer, oldEvent.getTag(), UUID.fromString( builtUUID.toString() ) );
getServer().getPluginManager().callEvent( newEvent );

WrappedGameProfile newProfile = new WrappedGameProfile( newEvent.getUUID(), newEvent.getTag().substring( 0, Math.min( newEvent.getTag().length(), 16 ) ) );
if (sent.getProperties().containsKey("textures"))
newProfile.getProperties().putAll("textures", sent.getProperties().get("textures"));
newProfile.getProperties().putAll("textures", sent.getProperties().get("textures"));
return newProfile;
}

Expand Down Expand Up @@ -168,6 +170,19 @@ public void run()
}, 2 );
}
}

public void refreshPlayer(Player player, Collection<? extends Player> forWhom)
{
Preconditions.checkState( isEnabled(), "Not Enabled!" );
Preconditions.checkNotNull( player, "player" );
Preconditions.checkNotNull( forWhom, "forWhom" );

for ( Player playerFor : forWhom )
{
refreshPlayer( player, playerFor );
refreshPlayer( playerFor, player );
}
}

public void refreshPlayer(Player player, Set<Player> forWhom)
{
Expand All @@ -178,6 +193,15 @@ public void refreshPlayer(Player player, Set<Player> forWhom)
for ( Player playerFor : forWhom )
{
refreshPlayer( player, playerFor );
refreshPlayer( playerFor, player );
}
}
}

public TagAPI getTagAPI() {
return tagAPI;
}

public void setTagAPI(TagAPI tagAPI) {
this.tagAPI = tagAPI;
}
}
27 changes: 27 additions & 0 deletions src/main/java/org/kitteh/tag/AsyncPlayerReceiveNameTagEvent.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,20 @@ public AsyncPlayerReceiveNameTagEvent(Player who, Player namedPlayer, String ini
this.tagModified = namedPlayer.getName().equals( initialName );
this.UUID = uuid;
}

public Player getPlayer() {

Preconditions.checkNotNull( this.player, "player" );
return this.player;

}

public Player getNamedPlayer() {

Preconditions.checkNotNull( this.namedPlayer, "namedPlayer" );
return this.namedPlayer;

}

public boolean setTag(String tag)
{
Expand All @@ -48,6 +62,19 @@ public boolean setTag(String tag)

return tag.length() < 16;
}

public String getTag() {

Preconditions.checkNotNull( this.tag, "tag" );
return this.tag;
}

public UUID getUUID()
{
Preconditions.checkNotNull( this.UUID, "uuid" );

return this.UUID;
}

public void setUUID(UUID uuid)
{
Expand Down
8 changes: 8 additions & 0 deletions src/main/java/org/kitteh/tag/PlayerReceiveNameTagEvent.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package org.kitteh.tag;

import com.google.common.base.Preconditions;

import lombok.Getter;

import org.bukkit.entity.Player;
import org.bukkit.event.HandlerList;
import org.bukkit.event.player.PlayerEvent;
Expand Down Expand Up @@ -38,6 +40,12 @@ public boolean setTag(String tag)

return tag.length() < 16;
}

public String getTag() {

Preconditions.checkNotNull( this.tag, "tag" );
return this.tag;
}

@Override
public HandlerList getHandlers()
Expand Down
Loading

0 comments on commit 5fb5520

Please sign in to comment.