Ebean错误 - 模型没有增强?

时间:2017-03-02 04:11:57

标签: java plugins minecraft ebean

Spigot显然在1.12中删除了Ebean支持,因此我转而使用手动Ebean。我自己能够解决大部分错误,但这个错误超出了我的范围。我已经尝试了所有不同的maven增强插件等,但它们似乎都没有解决它。

错误:https://gyazo.com/50cf77c853ceb492e5389394d37c6088

代码:

    MysqlDataSource dataSource = new MysqlDataSource();
    dataSource.setUser(getConfig().getString("database.username"));
    dataSource.setPassword(getConfig().getString("database.password"));
    dataSource.setServerName(getConfig().getString("database.url"));
    dataSource.setDatabaseName("minecraft");
    ServerConfig config = new ServerConfig();
    config.setDataSource(dataSource);
    config.setDefaultServer(true);
    config.setRegister(true);
    config.setClasses(getDatabaseClasses());
    if (getConfig().getBoolean("database.rebuild")) {
        config.setDdlGenerate(true);
    }
    config.setDdlRun(true);
    EbeanServerFactory.create(config);

筛选数据:

@Entity
@Table(name = "erudition_filters")
public class FilterData extends Model {

@Id
private long id;

@NotNull
private String world;

private double x, y, z;

public double getX() {
    return x;
}

public void setX(double x) {
    this.x = x;
}

public double getY() {
    return y;
}

public void setY(double y) {
    this.y = y;
}

public double getZ() {
    return z;
}

public void setZ(double z) {
    this.z = z;
}

public void setLocation(Location location) {
    setWorld(location.getWorld().getName());
    setX(location.getX());
    setY(location.getY());
    setZ(location.getZ());
}

public Location getLocation() {
    return new Location(Bukkit.getWorld(getWorld()), getX(), getY(), getZ());
}

@Lob
@NotNull
private String itemsString;

public Inventory getItems() {
    try {
        if (getItemsString() == null)
            return null;
        return getItemsString().equals("none") ? null : ItemSerializer.fromBase64(getItemsString());
    } catch (IOException e) {
        e.printStackTrace();
    }
    return null;
}

public void setItems(Inventory items) {
    setItemsString(items == null ? "none" : ItemSerializer.toBase64(items));
}

public static FilterData createFilterData(Block block) {
    FilterData data = new FilterData();
    data.setLocation(block.getLocation());
    data.setItems(null);
    saveFilter(data);
    return data;
}

public String getItemsString() {
    return itemsString;
}

public void setItemsString(String itemsString) {
    this.itemsString = itemsString;
}

public String getWorld() {
    return world;
}

public void setWorld(String world) {
    this.world = world;
}

public static List<FilterData> getAllFilters() {
    return Ebean.getDefaultServer().find(FilterData.class).findList();
}

public static FilterData getFilter(Location location) {
    FilterData data;

    if (location.getBlock().hasMetadata("filterid")) {
        data = Ebean.getDefaultServer().find(FilterData.class,
                location.getBlock().getMetadata("filterid").get(0).asInt());
        if (data != null) {
            data.setLocation(location);
            return data;
        }
    }
    List<FilterData> filterDataList = Ebean.getDefaultServer().find(FilterData.class).where()
            .eq("world", location.getWorld().getName()).eq("x", location.getBlockX()).eq("y", location.getBlockY())
            .eq("z", location.getBlockZ()).findList();
    if (filterDataList.isEmpty())
        return null;
    if (filterDataList.size() > 1) {
        for (int i = 1; i < filterDataList.size(); i++) {
            if (filterDataList.get(i) == null)
                continue;
            deleteFilter(filterDataList.get(i));
        }
    }
    return filterDataList.get(0);
}

public static void saveFilter(FilterData data) {
    Ebean.getDefaultServer().save(data);
}

public static void updateFilter(FilterData data) {
    deleteFilter(Ebean.getDefaultServer().find(FilterData.class, data.getId()));
    Ebean.getDefaultServer().insert(data);
}

public static void deleteFilter(FilterData data) {
    Ebean.getDefaultServer().delete(data);
}

public long getId() {
    return id;
}

public boolean supports(ItemStack item) {
    if (getItems() == null)
        return false;
    for (ItemStack supportedItem : getItems()) {
        if (supportedItem == null)
            continue;
        if (supportedItem.getType() == item.getType() && (supportedItem.getData().equals(item.getData())))
            return true;
    }
    return false;
}

public void setId(long id) {
    this.id = id;
}
}

1 个答案:

答案 0 :(得分:0)

我使用Gradle而不是Maven,我很容易就能使用它。 (字面意思只是添加了插件{   id“com.github.kt3k.ebean.enhance”version“3.0.0” } 在开始时,它与Gradle合作)