Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Develop #28

Merged
merged 5 commits into from
Feb 23, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>net.kunmc.lab</groupId>
<artifactId>TeamKunPluginManager</artifactId>
<version>1.9</version>
<version>2.0</version>
<packaging>jar</packaging>

<name>TeamKunPluginManager</name>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,32 +9,43 @@

public class TokenVault
{
public synchronized void vault(String token)

private String token;

public TokenVault()
{
token = "";

if (!new File(new File("").getAbsolutePath(), "kpm.vault").exists())
return;
try
{
FileUtils.writeStringToFile(new File(new File("").getAbsolutePath(), "kpm.vault"), token, Charset.defaultCharset());
token = FileUtils.readFileToString(new File(new File("").getAbsolutePath(), "kpm.vault"), StandardCharsets.UTF_8);
}
catch (IOException e)
{
System.out.println("TOKENの保管に失敗しました。");
System.out.println("TOKENの読み込みに失敗しました。");
e.printStackTrace();
}
}

public String getToken()

public synchronized void vault(String token)
{
if (!new File(new File("").getAbsolutePath(), "kpm.vault").exists())
return "";
this.token = token;
try
{
return FileUtils.readFileToString(new File(new File("").getAbsolutePath(), "kpm.vault"), StandardCharsets.UTF_8);
FileUtils.writeStringToFile(new File(new File("").getAbsolutePath(), "kpm.vault"), token, Charset.defaultCharset());
}
catch (IOException e)
{
System.out.println("TOKENの読み込みに失敗しました。");
System.out.println("TOKENの保管に失敗しました。");
e.printStackTrace();
}
return "";
}

public String getToken()
{
return token;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -326,13 +326,20 @@ else if (PluginUtil.isPluginLoaded(description.getName()))
{
try
{
if (downloadResult.getKey())
if (PluginUtil.isPluginLoaded(description.getName()))
{
if (!PluginUtil.isPluginLoaded(description.getName()))
finalSender.sendMessage(ChatColor.RED + "E: Bukkitのインジェクションに失敗しました。");
try
{
if (!withoutRemove)
{
new File("plugins/" + f.fileName).setWritable(true);
new File("plugins/" + f.fileName).delete();
}
}
catch (Exception ex)
{
finalSender.sendMessage(ChatColor.RED + "E: Bukkitのインジェクションに失敗しました。");
success.set(false);
continue;
finalSender.sendMessage(ChatColor.RED + "E: ファイルの削除に失敗しました: " + downloadResult.getValue());
}

PluginUtil.unload(plugin);
Expand All @@ -358,8 +365,8 @@ public void run()
{
if (!withoutRemove)
{
new File("plugins/" + f).setWritable(true);
new File("plugins/" + f).delete();
new File("plugins/" + f.fileName).setWritable(true);
new File("plugins/" + f.fileName).delete();
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import net.kunmc.lab.teamkunpluginmanager.TeamKunPluginManager;
import net.kunmc.lab.teamkunpluginmanager.plugin.KnownPlugins;
import net.kunmc.lab.teamkunpluginmanager.utils.GitHubURLBuilder;
import net.kunmc.lab.teamkunpluginmanager.utils.PluginResolver;
import net.kunmc.lab.teamkunpluginmanager.utils.URLUtils;
import org.apache.commons.lang.ArrayUtils;

import java.util.Map;
Expand Down Expand Up @@ -54,30 +56,14 @@ public CompactBuilder addPlugin(String name)

this.pre.pluginName = name;

String orgName = TeamKunPluginManager.config.getString("gitHubName");
String repoName = orgName + "/" + name;
if (KnownPlugins.isKnown(name))
{
try
{
this.pre.downloadUrl = Objects.requireNonNull(KnownPlugins.getKnown(name)).url;
}
catch (Exception ignored)
{
rs = (BuildResult[]) ArrayUtils.add(rs, BuildResult.DOWNLOAD_LINK_RESOLVE_FAILED);
}
}
else if (GitHubURLBuilder.isRepoExists(repoName))
{
String preUrl = "https://github.com/" + repoName;
String url = GitHubURLBuilder.urlValidate(preUrl);
if (!url.startsWith("ERROR "))
this.pre.downloadUrl = url;
else
rs = (BuildResult[]) ArrayUtils.add(rs, BuildResult.DOWNLOAD_LINK_RESOLVE_FAILED);
}
String url = PluginResolver.asUrl(name);

if (url.startsWith("ERROR"))
this.pre.downloadUrl = url;
else
rs = (BuildResult[]) ArrayUtils.add(rs, BuildResult.DOWNLOAD_LINK_RESOLVE_FAILED);
this.rs = (BuildResult[]) ArrayUtils.add(this.rs, BuildResult.DOWNLOAD_LINK_RESOLVE_FAILED);

this.pre.downloadUrl = url;

return this;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
package net.kunmc.lab.teamkunpluginmanager.utils;

import com.google.common.collect.Iterators;
import net.kunmc.lab.teamkunpluginmanager.TeamKunPluginManager;
import net.kunmc.lab.teamkunpluginmanager.plugin.InstallResult;
import org.apache.commons.collections.IteratorUtils;
import org.bukkit.Bukkit;
import org.bukkit.NamespacedKey;
import org.bukkit.command.Command;
import org.bukkit.command.PluginCommand;
import org.bukkit.command.PluginIdentifiableCommand;
import org.bukkit.command.SimpleCommandMap;
import org.bukkit.configuration.MemorySection;
import org.bukkit.craftbukkit.v1_15_R1.inventory.CraftRecipe;
import org.bukkit.entity.Player;
import org.bukkit.event.Event;
import org.bukkit.inventory.Recipe;
import org.bukkit.inventory.ShapedRecipe;
import org.bukkit.plugin.InvalidDescriptionException;
import org.bukkit.plugin.InvalidPluginException;
import org.bukkit.plugin.Plugin;
Expand Down Expand Up @@ -37,10 +43,12 @@
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Objects;
import java.util.SortedSet;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.stream.Stream;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;

Expand Down Expand Up @@ -322,6 +330,8 @@ public static void unload(Plugin plugin)
unWrapCommand(stringCommandEntry.getKey());
});

getPluginRecipes(plugin.getName()).forEach(Bukkit::removeRecipe);

Bukkit.getOnlinePlayers().stream().parallel().forEach(Player::updateCommands);

String name = plugin.getName();
Expand Down Expand Up @@ -568,6 +578,25 @@ public static Map<String, Command> getKnownCommands()
return new HashMap<>();
}

public static List<NamespacedKey> getPluginRecipes(String pluginName)
{
List<NamespacedKey> result = new ArrayList<>();
Recipe recipe;
Iterator<Recipe> iterator = Bukkit.recipeIterator();
while(iterator.hasNext())
{
recipe = iterator.next();
if (recipe instanceof ShapedRecipe)
{
ShapedRecipe sr = (ShapedRecipe) recipe;
if (sr.getKey().getNamespace().equals(pluginName.toLowerCase(Locale.ROOT)))
result.add(sr.getKey());
}
}

return result;
}

public static void wrapCommand(Command command, String alias)
{
try
Expand Down