mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-19 08:29:05 +00:00
Add Soulbind and Slot Bind Requirements for Item Attributes
This commit is contained in:
1 parent
d2cf8d7100
commit
2fc83cdfc4
4 files changed
+167
-4
No files matched your search
@@ -4,8 +4,10 @@ import kamkeel.npcs.controllers.AttributeController;
|
||||
import kamkeel.npcs.controllers.data.attribute.AttributeDefinition;
|
||||
import kamkeel.npcs.controllers.data.attribute.AttributeValueType;
|
||||
import kamkeel.npcs.controllers.data.attribute.requirement.RequirementCheckerRegistry;
|
||||
import kamkeel.npcs.controllers.data.attribute.requirement.types.ProfileSlotRequirement;
|
||||
import kamkeel.npcs.controllers.data.attribute.requirement.types.QuestActiveRequirement;
|
||||
import kamkeel.npcs.controllers.data.attribute.requirement.types.QuestCompletedRequirement;
|
||||
import kamkeel.npcs.controllers.data.attribute.requirement.types.SoulbindRequirement;
|
||||
|
||||
/**
|
||||
* ModAttributes registers the core attributes (both non–magic and magic–based).
|
||||
@@ -74,9 +76,7 @@ public class CustomAttributes {
|
||||
// Requirement
|
||||
RequirementCheckerRegistry.registerChecker(new QuestCompletedRequirement());
|
||||
RequirementCheckerRegistry.registerChecker(new QuestActiveRequirement());
|
||||
|
||||
// TODO: Requirements
|
||||
// Player Requirement : Soulbound UUID
|
||||
// Profile Requirement : Slot Number
|
||||
RequirementCheckerRegistry.registerChecker(new ProfileSlotRequirement());
|
||||
RequirementCheckerRegistry.registerChecker(new SoulbindRequirement());
|
||||
}
|
||||
}
|
||||
+53
@@ -0,0 +1,53 @@
|
||||
package kamkeel.npcs.controllers.data.attribute.requirement.types;
|
||||
|
||||
import kamkeel.npcs.controllers.data.attribute.requirement.IRequirementChecker;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import noppes.npcs.controllers.QuestController;
|
||||
import noppes.npcs.controllers.data.PlayerData;
|
||||
|
||||
public class ProfileSlotRequirement implements IRequirementChecker {
|
||||
|
||||
@Override
|
||||
public String getKey() {
|
||||
return "cnpc_profile_slot";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTranslation() {
|
||||
return "profile.slot";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTooltipValue(NBTTagCompound nbt) {
|
||||
if (nbt.hasKey(getKey())) {
|
||||
int profileSlot = nbt.getInteger(getKey());
|
||||
return String.valueOf(profileSlot);
|
||||
}
|
||||
return "null";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void apply(NBTTagCompound nbt, Object value) {
|
||||
if (value instanceof Integer) {
|
||||
nbt.setInteger(getKey(), (Integer) value);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getValue(NBTTagCompound nbt) {
|
||||
if (nbt.hasKey(getKey())) {
|
||||
return nbt.getInteger(getKey());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean check(EntityPlayer player, NBTTagCompound nbt) {
|
||||
if (nbt.hasKey(getKey())) {
|
||||
int profileSlot = nbt.getInteger(getKey());
|
||||
return PlayerData.get(player).profileSlot == profileSlot;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
+108
@@ -0,0 +1,108 @@
|
||||
package kamkeel.npcs.controllers.data.attribute.requirement.types;
|
||||
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParser;
|
||||
import kamkeel.npcs.controllers.data.attribute.requirement.IRequirementChecker;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import noppes.npcs.controllers.QuestController;
|
||||
import noppes.npcs.controllers.data.PlayerData;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
import java.util.HashMap;
|
||||
import java.util.UUID;
|
||||
|
||||
public class SoulbindRequirement implements IRequirementChecker {
|
||||
|
||||
public static HashMap<String, String> uuidToUsername = new HashMap<>();
|
||||
|
||||
@Override
|
||||
public String getKey() {
|
||||
return "cnpc_soulbind";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTranslation() {
|
||||
return "requirement.soulbind";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTooltipValue(NBTTagCompound nbt) {
|
||||
if (nbt.hasKey(getKey())) {
|
||||
String uuid = nbt.getString(getKey());
|
||||
if (uuid != null && !uuid.isEmpty()) {
|
||||
return getUsernameFromUUID(uuid);
|
||||
}
|
||||
}
|
||||
return "null";
|
||||
}
|
||||
|
||||
private String getUsernameFromUUID(String uuid) {
|
||||
if(uuidToUsername.containsKey(uuid)){
|
||||
if(!uuidToUsername.get(uuid).equals("null")){
|
||||
return uuidToUsername.get(uuid);
|
||||
}
|
||||
}
|
||||
try {
|
||||
String strippedUUID = uuid.replace("-", "");
|
||||
String urlStr = "https://sessionserver.mojang.com/session/minecraft/profile/" + strippedUUID;
|
||||
HttpURLConnection connection = (HttpURLConnection) new URL(urlStr).openConnection();
|
||||
connection.setConnectTimeout(5000);
|
||||
connection.setReadTimeout(5000);
|
||||
connection.setRequestMethod("GET");
|
||||
connection.connect();
|
||||
|
||||
InputStream stream = connection.getInputStream();
|
||||
InputStreamReader reader = new InputStreamReader(stream, "UTF-8");
|
||||
|
||||
JsonElement element = new JsonParser().parse(reader);
|
||||
JsonObject jsonObj = element.getAsJsonObject();
|
||||
|
||||
if (jsonObj.has("name")) {
|
||||
String name = jsonObj.get("name").getAsString();
|
||||
uuidToUsername.put(uuid, name);
|
||||
return name;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return "null";
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Object getValue(NBTTagCompound nbt) {
|
||||
if (nbt.hasKey(getKey())) {
|
||||
return nbt.getString(getKey());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void apply(NBTTagCompound nbt, Object value) {
|
||||
if (value instanceof String) {
|
||||
nbt.setString(getKey(), (String) value);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean check(EntityPlayer player, NBTTagCompound nbt) {
|
||||
if (nbt.hasKey(getKey())) {
|
||||
String uuidString = nbt.getString(getKey());
|
||||
if(uuidString != null && !uuidString.isEmpty()){
|
||||
UUID convert = null;
|
||||
try {
|
||||
convert = UUID.fromString(uuidString);
|
||||
} catch (Exception ignored){}
|
||||
if(convert != null)
|
||||
return player.getUniqueID().equals(convert);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user