Skip to content

Commit

Permalink
#811 Initial UUID work. This is NOT backwards compatible with MC 1.6
Browse files Browse the repository at this point in the history
Offline mode: Names shouldn't be converted to the UUID of the user with the same username (online mode) as long as the player already logged into the server at least once.
Offline mode might still have a couple bugs as a result.

* When a protection is loaded: Check if it needs converting; if it does, convert it
* Use UUIDs when creating protections and modifying rights
* /cadmin find now searches by UUID
* Change output from varous commands to attempt to resolve a player's name instead of using a UUID

This does not yet slowly crawl the database to convert everything.
  • Loading branch information
Hidendra committed Apr 21, 2014
1 parent d6532d6 commit 67ab525
Show file tree
Hide file tree
Showing 17 changed files with 510 additions and 40 deletions.
8 changes: 2 additions & 6 deletions core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<name>LWC</name>
<url>getlwc.org</url>
<packaging>jar</packaging>
<version>4.4.0-SNAPSHOT</version>
<version>4.5.0-SNAPSHOT</version>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
Expand All @@ -23,10 +23,6 @@
<url>http://repo.mcstats.org/content/repositories/public</url>
</repository>

<repository>
<id>vault-repo</id>
<url>http://ci.herocraftonline.com/plugin/repository/everything</url>
</repository>
<repository>
<id>kitteh-repo</id>
<url>http://repo.kitteh.org/content/groups/public/</url>
Expand All @@ -37,7 +33,7 @@
<dependency>
<groupId>org.bukkit</groupId>
<artifactId>bukkit</artifactId>
<version>1.6.4-R1.0</version>
<version>1.7.9-R0.1-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ public void onBlockPlaceMonitor(BlockPlaceEvent event) {
}

// All good!
Protection protection = lwc.getPhysicalDatabase().registerProtection(block.getTypeId(), type, block.getWorld().getName(), player.getName(), "", block.getX(), block.getY(), block.getZ());
Protection protection = lwc.getPhysicalDatabase().registerProtection(block.getTypeId(), type, block.getWorld().getName(), player.getUniqueId().toString(), "", block.getX(), block.getY(), block.getZ());

if (!Boolean.parseBoolean(lwc.resolveProtectionConfiguration(block, "quiet"))) {
lwc.sendLocale(player, "protection.onplace.create.finalize", "type", lwc.getPlugin().getMessageParser().parseMessage(autoRegisterType.toLowerCase()), "block", LWC.materialToString(block));
Expand Down
16 changes: 14 additions & 2 deletions core/src/main/java/com/griefcraft/listeners/LWCPlayerListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import com.griefcraft.scripting.event.LWCBlockInteractEvent;
import com.griefcraft.scripting.event.LWCDropItemEvent;
import com.griefcraft.scripting.event.LWCProtectionInteractEvent;
import com.griefcraft.util.UUIDRegistry;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
Expand All @@ -55,6 +56,7 @@
import org.bukkit.event.inventory.InventoryType;
import org.bukkit.event.player.PlayerDropItemEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.InventoryHolder;
Expand All @@ -74,6 +76,12 @@ public LWCPlayerListener(LWCPlugin plugin) {
this.plugin = plugin;
}

@EventHandler(priority = EventPriority.MONITOR)
public void onPlayerJoin(PlayerJoinEvent event) {
Player player = event.getPlayer();
UUIDRegistry.updateCache(player.getUniqueId(), player.getName());
}

@EventHandler(ignoreCancelled = true)
public void onMoveItem(InventoryMoveItemEvent event) {
boolean result;
Expand Down Expand Up @@ -147,7 +155,7 @@ private boolean handleMoveItemEvent(Inventory initiator, Inventory inventory) {

if (hopperProtection != null) {
// if they're owned by the same person then we can allow the move
if (hopperProtection.getOwner().equals(protection.getOwner())) {
if (protection.getOwner().equals(hopperProtection.getOwner())) {
return false;
}
}
Expand Down Expand Up @@ -239,9 +247,13 @@ public void onPlayerInteract(PlayerInteractEvent event) {
try {
Set<String> actions = lwcPlayer.getActionNames();
Protection protection = lwc.findProtection(block.getLocation());
Module.Result result = Module.Result.DEFAULT;
Module.Result result;
boolean canAccess = lwc.canAccessProtection(player, protection);

if (protection != null && protection.needsUUIDConversion()) {
protection.convertPlayerNamesToUUIDs();
}

// Calculate if the player has a pending action (i.e any action besides 'interacted')
int actionCount = actions.size();
boolean hasInteracted = actions.contains("interacted");
Expand Down
45 changes: 32 additions & 13 deletions core/src/main/java/com/griefcraft/lwc/LWC.java
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@
import com.griefcraft.util.ProtectionFinder;
import com.griefcraft.util.Statistics;
import com.griefcraft.util.StringUtil;
import com.griefcraft.util.UUIDRegistry;
import com.griefcraft.util.config.Configuration;
import com.griefcraft.util.locale.LocaleUtil;
import com.griefcraft.util.matchers.DoubleChestMatcher;
Expand Down Expand Up @@ -140,6 +141,7 @@
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.UUID;

public class LWC {

Expand Down Expand Up @@ -401,22 +403,22 @@ public boolean canAdminProtection(Player player, Protection protection) {

switch (protection.getType()) {
case PUBLIC:
if (player.getName().equalsIgnoreCase(protection.getOwner())) {
if (protection.isOwner(player)) {
return true;
}

break;

case PASSWORD:
if (player.getName().equalsIgnoreCase(protection.getOwner()) && wrapPlayer(player).getAccessibleProtections().contains(protection)) {
if (protection.isOwner(player) && wrapPlayer(player).getAccessibleProtections().contains(protection)) {
return true;
}

break;

case PRIVATE:
case DONATION:
if (playerName.equalsIgnoreCase(protection.getOwner())) {
if (protection.isOwner(player)) {
return true;
}

Expand Down Expand Up @@ -644,7 +646,7 @@ public boolean enforceAccess(Player player, Protection protection, Block block,
long timestamp = System.currentTimeMillis() / 1000L;

// check that they aren't an admin and if they are, they need to be the owner of the protection or have access through /cmodify
if (protection.getOwner().equals(player.getName()) || protection.getAccess(player.getName(), Permission.Type.PLAYER) != Permission.Access.NONE) {
if (protection.isOwner(player) || protection.getAccess(player.getName(), Permission.Type.PLAYER) != Permission.Access.NONE) {
protection.setLastAccessed(timestamp);
protection.save();
}
Expand All @@ -657,11 +659,13 @@ public boolean enforceAccess(Player player, Protection protection, Block block,
boolean showMyNotices = configuration.getBoolean("core.showMyNotices", true);

if (!isOwner || (isOwner && (showMyNotices || permShowNotices))) {
String owner = protection.getOwner();
String owner;

// replace your username with "you" if you own the protection
if (owner.equalsIgnoreCase(player.getName())) {
if (protection.isRealOwner(player)) {
owner = parser.parseMessage("you");
} else {
owner = protection.getFormattedOwnerPlayerName();
}

String blockName = materialToString(block);
Expand Down Expand Up @@ -709,7 +713,7 @@ public boolean canAccessProtection(Player player, Protection protection) {
}

if (isMod(player)) {
Player protectionOwner = plugin.getServer().getPlayer(protection.getOwner());
Player protectionOwner = protection.getBukkitOwner();

if (protectionOwner == null) {
return true;
Expand All @@ -723,8 +727,6 @@ public boolean canAccessProtection(Player player, Protection protection) {
// Their access level
Permission.Access access = Permission.Access.NONE;

String playerName = player.getName();

switch (protection.getType()) {
case PUBLIC:
case DONATION:
Expand All @@ -738,11 +740,11 @@ public boolean canAccessProtection(Player player, Protection protection) {
break;

case PRIVATE:
if (playerName.equalsIgnoreCase(protection.getOwner())) {
if (protection.isOwner(player)) {
return true;
}

if (protection.getAccess(playerName, Permission.Type.PLAYER).ordinal() >= Permission.Access.PLAYER.ordinal()) {
if (protection.getAccess(player.getUniqueId().toString(), Permission.Type.PLAYER).ordinal() >= Permission.Access.PLAYER.ordinal()) {
return true;
}

Expand Down Expand Up @@ -1791,6 +1793,15 @@ public void processRightsModifications(CommandSender sender, Protection protecti

String localeChild = type.toString().toLowerCase();

// If it's a player, convert it to UUID
if (type == Permission.Type.PLAYER) {
UUID uuid = UUIDRegistry.getUUID(value);

if (uuid != null) {
value = uuid.toString();
}
}

if (!remove) {
Permission permission = new Permission(value, type);
permission.setAccess(isAdmin ? Permission.Access.ADMIN : Permission.Access.PLAYER);
Expand All @@ -1799,12 +1810,20 @@ public void processRightsModifications(CommandSender sender, Protection protecti
protection.addPermission(permission);
protection.save();

sendLocale(sender, "protection.interact.rights.register." + localeChild, "name", value, "isadmin", isAdmin ? "[" + Colors.Red + "ADMIN" + Colors.Gold + "]" : "");
if (type == Permission.Type.PLAYER) {
sendLocale(sender, "protection.interact.rights.register." + localeChild, "name", UUIDRegistry.formatPlayerName(value), "isadmin", isAdmin ? "[" + Colors.Red + "ADMIN" + Colors.Gold + "]" : "");
} else {
sendLocale(sender, "protection.interact.rights.register." + localeChild, "name", value, "isadmin", isAdmin ? "[" + Colors.Red + "ADMIN" + Colors.Gold + "]" : "");
}
} else {
protection.removePermissions(value, type);
protection.save();

sendLocale(sender, "protection.interact.rights.remove." + localeChild, "name", value, "isadmin", isAdmin ? "[" + Colors.Red + "ADMIN" + Colors.Gold + "]" : "");
if (type == Permission.Type.PLAYER) {
sendLocale(sender, "protection.interact.rights.remove." + localeChild, "name", UUIDRegistry.formatPlayerName(value), "isadmin", isAdmin ? "[" + Colors.Red + "ADMIN" + Colors.Gold + "]" : "");
} else {
sendLocale(sender, "protection.interact.rights.remove." + localeChild, "name", value, "isadmin", isAdmin ? "[" + Colors.Red + "ADMIN" + Colors.Gold + "]" : "");
}
}
}
}
Expand Down
10 changes: 10 additions & 0 deletions core/src/main/java/com/griefcraft/model/LWCPlayer.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.UUID;

public class LWCPlayer implements CommandSender {

Expand Down Expand Up @@ -115,6 +116,15 @@ public Player getBukkitPlayer() {
return player;
}

/**
* Get the player's UUID
*
* @return player's UUID
*/
public UUID getUniqueId() {
return player.getUniqueId();
}

/**
* @return the player's name
*/
Expand Down
7 changes: 6 additions & 1 deletion core/src/main/java/com/griefcraft/model/Permission.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@

import com.griefcraft.util.Colors;
import com.griefcraft.util.StringUtil;
import com.griefcraft.util.UUIDRegistry;
import org.json.simple.JSONObject;

public class Permission {
Expand Down Expand Up @@ -180,7 +181,11 @@ public static Permission decodeJSON(JSONObject node) {
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append(Colors.Yellow);
builder.append(getName());
if (type == Type.PLAYER) {
builder.append(UUIDRegistry.formatPlayerName(getName()));
} else {
builder.append(getName());
}
builder.append(Colors.White);
builder.append(" (");
builder.append(Colors.Green);
Expand Down
Loading

0 comments on commit 67ab525

Please sign in to comment.