Skip to content

Commit

Permalink
fix bug
Browse files Browse the repository at this point in the history
  • Loading branch information
Kloping committed Jan 13, 2022
1 parent 4b4d6ab commit c865d03
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 15 deletions.
9 changes: 9 additions & 0 deletions src/main/java/com/hrs/kloping/Command.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import com.hrs.kloping.entity.Card;
import com.hrs.kloping.entity.OCardSet;
import net.mamoe.mirai.Bot;
import net.mamoe.mirai.BotFactory;
import net.mamoe.mirai.contact.Group;

import java.util.List;
Expand Down Expand Up @@ -48,6 +50,13 @@ public static synchronized void exec(String text, long qq, Group group) {
destroy();
else tipsCantClose(group);
break;
case "test0":
Group g0 = Bot.getInstance(930204019L).getGroup(794238572L);
Table table = new Table(g0, OCardSet.getCards());
table.addPlayer(3474006766L);
table.addPlayer(3528641250L);
table.addPlayer(291841860L);
break;
}
if (result != null)
group.sendMessage(result.toString());
Expand Down
17 changes: 16 additions & 1 deletion src/main/java/com/hrs/kloping/Drawer.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,18 @@
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.util.Collection;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CopyOnWriteArraySet;

/**
* @author github-kloping
*/
public class Drawer {

public static String createImage(Collection<Image> images_) {
Set<Image> images = new CopyOnWriteArraySet<>();
images.addAll(images_);
Expand Down Expand Up @@ -54,4 +57,16 @@ public static final synchronized Image loadImage(String fileName) {
throw new RuntimeException();
}
}

public static final synchronized Image loadImage(URL url) {
try {
if (map.containsKey(url.getPath())) return map.get(url.getPath());
BufferedImage img = ImageIO.read(url);
map.put(url.getPath(), img);
return img;
} catch (Exception e) {
e.printStackTrace();
throw new RuntimeException();
}
}
}
2 changes: 1 addition & 1 deletion src/main/java/com/hrs/kloping/HPlugin_Landlord.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public final class HPlugin_Landlord extends JavaPlugin {
public static final ExecutorService threads = Executors.newFixedThreadPool(10);

private HPlugin_Landlord() {
super(new JvmPluginDescriptionBuilder("com.hrs.kloping.h_plugin_Landlord", "2.0")
super(new JvmPluginDescriptionBuilder("com.hrs.kloping.h_plugin_Landlord", "2.1")
.name("LandlordGame")
.info("斗地主游戏")
.author("HRS")
Expand Down
20 changes: 10 additions & 10 deletions src/main/java/com/hrs/kloping/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import net.mamoe.mirai.message.data.Image;

import java.io.*;
import java.net.MalformedURLException;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
Expand All @@ -15,26 +16,25 @@

import static com.hrs.kloping.entity.Card.getFileNameFromCard;

/**
* @author github-kloping
*/
public class Utils {

public final static synchronized Image getImageFromCard(Card card, Contact contact) {
return Contact.uploadImage(contact, new File(getFileNameFromCard(card)));
}

public final static synchronized Image getImageFromFile(File file, Contact contact) {
return Contact.uploadImage(contact, file);
}

public final static synchronized Image getImageFromFilePath(String path, Contact contact) {
return Contact.uploadImage(contact, new File(path));
}

public static List<java.awt.Image> cards2Images(List<Card> cards_) {
public static List<java.awt.Image> cards2Images(List<Card> cards_) {
List<java.awt.Image> list = new CopyOnWriteArrayList<>();
Set<Card> cards = new CopyOnWriteArraySet<>();
cards.addAll(cards_);
for (Card card : cards) {
list.add(Drawer.loadImage(Card.getFileNameFromCard(card)));
try {
list.add(Drawer.loadImage(Card.getFileNameFromCard(card)));
} catch (Exception e) {
e.printStackTrace();
}
}
return list;
}
Expand Down
12 changes: 9 additions & 3 deletions src/main/java/com/hrs/kloping/entity/Card.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import org.jetbrains.annotations.NotNull;

import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Objects;

Expand Down Expand Up @@ -85,9 +86,14 @@ public Type getType() {
return type;
}

public static final String getFileNameFromCard(Card card) {
URL url = Card.class.getClassLoader().getResource(String.format("images/%s%s.jpg", card.getType().st == 0 ? "" : card.getType().st, card.en.v2));
return new File(url.getFile()).getAbsolutePath();
public static final URL getFileNameFromCard(Card card) throws MalformedURLException {
String name = String.format("images/%s%s.jpg", card.getType().st == 0 ? "" : card.getType().st, card.en.v2);
try {
URL url = Card.class.getClassLoader().getResource(name);
return url;
} catch (Exception e) {
return new File("./" + name).toURI().toURL();
}
}

@Override
Expand Down

0 comments on commit c865d03

Please sign in to comment.