-
-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Finish implementing sponge support (Fixes #18)
- Loading branch information
Showing
10 changed files
with
401 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
92 changes: 92 additions & 0 deletions
92
sponge/src/main/java/com/github/games647/changeskin/sponge/tasks/NameResolver.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
package com.github.games647.changeskin.sponge.tasks; | ||
|
||
import com.github.games647.changeskin.core.NotPremiumException; | ||
import com.github.games647.changeskin.core.RateLimitException; | ||
import com.github.games647.changeskin.core.SkinData; | ||
import com.github.games647.changeskin.sponge.ChangeSkinSponge; | ||
|
||
import java.util.UUID; | ||
|
||
import org.spongepowered.api.command.CommandSource; | ||
import org.spongepowered.api.entity.living.player.Player; | ||
|
||
public class NameResolver implements Runnable { | ||
|
||
private final ChangeSkinSponge plugin; | ||
private final CommandSource invoker; | ||
private final String targetName; | ||
private final Player receiver; | ||
|
||
public NameResolver(ChangeSkinSponge plugin, CommandSource invoker, String targetName, Player receiver) { | ||
this.plugin = plugin; | ||
this.invoker = invoker; | ||
this.targetName = targetName; | ||
this.receiver = receiver; | ||
} | ||
|
||
@Override | ||
public void run() { | ||
UUID uuid = plugin.getCore().getUuidCache().get(targetName); | ||
if (uuid == null) { | ||
if (plugin.getCore().getCrackedNames().containsKey(targetName)) { | ||
if (invoker != null) { | ||
plugin.sendMessage(invoker, "not-premium"); | ||
} | ||
|
||
return; | ||
} | ||
|
||
SkinData targetSkin = plugin.getCore().getStorage().getSkin(targetName); | ||
if (targetSkin != null) { | ||
onNameResolveDatabase(targetSkin); | ||
return; | ||
} | ||
|
||
try { | ||
uuid = plugin.getCore().getUUID(targetName); | ||
if (uuid == null) { | ||
if (invoker != null) { | ||
plugin.sendMessage(invoker, "no-resolve"); | ||
} | ||
} else { | ||
plugin.getCore().getUuidCache().put(targetName, uuid); | ||
onNameResolve(uuid); | ||
} | ||
} catch (NotPremiumException notPremiumEx) { | ||
plugin.getLogger().debug("Requested not premium", notPremiumEx); | ||
plugin.getCore().getCrackedNames().put(targetName, new Object()); | ||
|
||
if (invoker != null) { | ||
plugin.sendMessage(invoker, "not-premium"); | ||
} | ||
} catch (RateLimitException rateLimitEx) { | ||
plugin.getLogger().error("UUID Rate Limit reached", rateLimitEx); | ||
if (invoker != null) { | ||
plugin.sendMessage(invoker, "rate-limit"); | ||
} | ||
} | ||
} else { | ||
onNameResolve(uuid); | ||
} | ||
} | ||
|
||
private void onNameResolveDatabase(SkinData targetSkin) { | ||
if (invoker != null) { | ||
plugin.sendMessage(invoker, "uuid-resolved"); | ||
plugin.sendMessage(invoker, "skin-downloading"); | ||
} | ||
|
||
SkinUpdater skinUpdater = new SkinUpdater(plugin, invoker, receiver, targetSkin); | ||
plugin.getGame().getScheduler().createTaskBuilder().execute(skinUpdater).submit(plugin); | ||
} | ||
|
||
private void onNameResolve(UUID uuid) { | ||
if (invoker != null) { | ||
plugin.sendMessage(invoker, "uuid-resolved"); | ||
plugin.sendMessage(invoker, "skin-downloading"); | ||
} | ||
|
||
//run this is the same thread | ||
new SkinDownloader(plugin, invoker, receiver, uuid).run(); | ||
} | ||
} |
Oops, something went wrong.