I'm trying to run a simple minecraft plugin I've built through a local spigot server. the plugins is
Main.java
import org.bukkit.plugin.java.JavaPlugin;
public class Main extends JavaPlugin {
#Override
public void onEnable() {
getLogger().info("onEnable has been invoked!");
// TODO Insert logic to be performed when the plugin is enabled
}
#Override
public void onDisable() {
getLogger().info("onDisable has been invoked!");
// TODO Insert logic to be performed when the plugin is disabled
}
}
plugin.yml
name: Kolo
version: 1.0
author: will
commands:
Hello:
Everytime I export the project as a jar to the plugins folder of my server and run my server it gives me this
[20:31:29 INFO]: Set PluginClassLoader as parallel capable
[20:31:29 ERROR]: Could not load 'plugins/Kolo.jar' in folder 'plugins'
org.bukkit.plugin.InvalidPluginException: Cannot find main class `me.will.Kolo'
at org.bukkit.plugin.java.PluginClassLoader.<init>(PluginClassLoader.java:66) ~[minecraft_server.jar:git-Spigot-db6de12-18fbb24]
Can someone explain this to me? Idk if the info part of the code means anything but I searched it up and couldn't really decipher any instructions on how to go about doing what it says. Im still learning java and I feel like its mostly me forgetting a simple thing but I wanted to check on here to see if maybe one of you could clarify for me so I'll understand better.
You're missing the "main" attribute in your plugin.yml file.
In case your folder structure is like "me/will/Kolo/Main.java", it should be like this:
plugin.yml
name: Kolo
version: 1.0
author: will
main: me.will.Kolo.Main
commands:
Hello:
Related
In a small Vue 3 project scaffolded with Vite, I've run into the Class constructor XX cannot be invoked without 'new' issue. My Googling suggests that the problem is a transpiled class extending a native class, but I have no such constructs in my code. I'm not fluent enough in Javascript/Typescript/transpilation/ESXXXX-whatever to figure it out.
Here's a minimum viable setup to demonstrate the problem:
npm init vue#latest
Add Typescript support, leave all other questions as default.
cd vue-project; npm-install
Replace contents of App.vue with the following:
<script setup lang="ts">
import { Credentials } from './creds'
function logIn( creds: Credentials ) {
// presumably log in here
}
</script>
<template>
<button #click="logIn(new Credentials( 'aaa', 'bbb' ))">CLICK ME</button>
</template>
Add a new file, creds.ts, with the following contents:
export class Credentials {
constructor(
public readonly username: string,
public readonly password: string
) {}
toString = (): string => `${this.username}:${this.password}`;
}
npm run build; npm run preview
Open browser to 127.0.0.1:4173 and open browser's dev tools
Click the button, check the javascript console:
index.b42911a0.js:1 TypeError: Class constructor XX cannot be invoked without 'new'
Two weird things:
No such error is seen in development (npm run dev), only when previewing the production build.
If you move the Credentials class into the script section of App.vue, the production build no longer throws the error.
What is it about instantiating a class from a different file, in an event handler, in production, that causes this mysterious error?
EDIT 2: I've removed the original question as it was all irrelevant.
I am developing a web application and intend to make use of the performance boost that caching resources give, but it comes with an important caveat. Whenever I updated a static file, users wouldn't see these changes immediately, and so had to disable the browser's cache in order to fetch the newest version. In order to fix this issue, I decided to add static assets versioning. Which works as intended with the following code.
#Override
public void addResourceHandlers(final ResourceHandlerRegistry registry) {
registry.addResourceHandler("/**")
.addResourceLocations("classpath:/static/")
.setCacheControl(CacheControl.maxAge(365, TimeUnit.DAYS))
.resourceChain(true)
.addResolver(new VersionResourceResolver().addContentVersionStrategy("/**"))
// Costume made transformer to handle JS imports
.addTransformer(new JsLinkResourceTransformer())
.addTransformer(new CssLinkResourceTransformer());
}
#Bean
public ResourceUrlEncodingFilter resourceUrlEncodingFilter() {
return new ResourceUrlEncodingFilter();
}
Everything was working as intended, except for one simple detail. JS imports were still loading the none versioned files. So something like import * from './myscrypt.js', would not work properly.
I had to implement my own resource transformer in order to avoid that new caveat. The implementation does it's job, and now my imports would fetch the right version, like import * from './myscript-149shdhgshs.js'. Then, I thought everything was fixed, but a new issue came up. Here is the scenario, which will make it easier to understand.
I load a page that includes script.js
Then Spring serve me with the correct version of the file script-v1.js
After that, script-v1.js imports functions from myscript.js
The browser fetch the right version of the script myscript-v1.js
The two of them get cached locally
I update myscript.js making a new version myscript-v2.js
I reload the page, but since script-v1.js was stored in cache, I load it with the old import myscript-v1.js, even though there is a new version
I just can't seem to make it work. Of course, I could simply stop using js modules and instead just load all the scripts at once, but that is not the solution I want to go for. Would there be a solution for js module versioning using Spring?
My way of solving this cached version will be using app version. If the project is built on Maven, I see you're using classpath resource for static file resolutions. Whenever there is a new change to js file, you will have new build and if you could change the version on every build, here is my workaround would look like.
pom.xml
<version>0.1.0</version>
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
application.yml
build:
version: #project.version#
This will push version from pom.xml to application.yml both dev on IDE and built jar
Controller
I'm using mustache view resolver here.
#Controller
public class HelloController {
#Value("${build.version}")
private String version;
private String encodedVersion;
#PostConstruct
public void setup() {
encodedVersion = new String(Base64.getEncoder().encode(version.getBytes())).replace("=", "");
}
#RequestMapping("/home")
public ModelAndView home() {
ModelAndView mv = new ModelAndView();
mv.setViewName("home.html");
return mv;
}
#ModelAttribute("version")
public String getVersion() {
return encodedVersion;
}
}
home.html
<html>
<head>
<script type="text/javascript" src="/pop.js?cache={{version}}"></script>
<script type="text/javascript">
window.version = "{{version}}" // in case you need this somewhere
</script>
</head>
<body>
<h1>Home1</h1>
version: {{version}}
</body>
</html>
Manipulating existing js files
#Configuration
#AutoConfigureAfter(DispatcherServletAutoConfiguration.class)
public class Config implements WebMvcConfigurer {
#Value("${build.version}")
private String version;
private String encodedVersion;
#PostConstruct
public void setup() {
encodedVersion = new String(Base64.getEncoder().encode(version.getBytes())).replace("=", "");
}
#Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/**").addResourceLocations("classpath:/static/").setCacheControl(CacheControl.maxAge(365, TimeUnit.DAYS)).resourceChain(true)
.addResolver(new VersionResourceResolver().addContentVersionStrategy("/**"))
.addTransformer(new ResourceTransformer() {
#Override
public Resource transform(HttpServletRequest request, Resource resource, ResourceTransformerChain transformerChain) throws IOException {
// Be aware of side effects changing line break
String result = new BufferedReader(new InputStreamReader(resource.getInputStream())).lines().collect(Collectors.joining("\n"));
result = result.replace("{{cacheVersion}}", encodedVersion);
return new TransformedResource(resource, result.getBytes());
}
});
}
}
pop.js
import mod1 from './mod1.js?cache={{cacheVersion}}';
function dis() {
console.log("hello")
}
Since the version is added as ModelAttribute it will be available in all request mapping. For every version, this will be changed and the way you pull files can be using this cache version variable.
I'm following a guide to get started in Drools 6.5, so I don't understand 100% of what I'm writing, but I'm getting a NullPointerException error on my .insert() method in my test case class. I've followed the guide in the Drools.org documentation to the tee but according to the documentation my code should be working.
I was thinking maybe the documentation is outdated and the method has been changed/depreciated, but I can't find any similar reported issues.
package Basic1;
import org.junit.BeforeClass;
import org.junit.Test;
import org.kie.api.runtime.KieContainer;
import org.kie.api.runtime.KieSession;
import org.kie.api.runtime.StatelessKieSession;
import util.KnowledgeSessionHelper;
#SuppressWarnings("restriction")
public class FirstRuleTest {
StatelessKieSession sessionStateless = null;
KieSession sessionStateful = null;
static KieContainer kieContainer;
#BeforeClass
public static void beforeClass(){
kieContainer = KnowledgeSessionHelper.createRuleBase();
}
#Test
public void firstTest(){
sessionStateful = KnowledgeSessionHelper.getStatefulKnowledgeSession(kieContainer,"ksession-rules");
Account a = new Account();
sessionStateful.insert(a); // this is throwing the error when I test with JUnit 4
sessionStateful.fireAllRules();
}
}
P.S. I hope it's alright that I just pasted all that in, the file isn't that long and I thought it was important to show everything that had been imported and defined.
I guess you are missing the kmodule.xml configuration file in your project resources. You can find the details about it in the documentation - http://docs.jboss.org/drools/release/6.2.0.CR2/drools-docs/html/KIEChapter.html#KIEBuildingSection.
I'm looking to create a Nativescript wrapper for a Java library so I can utilize functionalities of it for a Nativescript app. There does not seem to be too many articles that go into this in detail, and there does not seem to be a clear way to do this within the Nativescript app itself which is why I am now making this a plugin wrapper.
The specific Java library I am working to include is Libsignal-protocol-java. I've gone ahead and cloned the Nativescript Plugin Seed and added this Java library as a dependency:
src/platforms/android/include.gradle
android {
}
dependencies {
compile 'org.whispersystems:signal-protocol-android:2.3.0+'
}
I then found the particular package that contains the method I am trying ro access within the Java source: KeyHelper.generateRegistrationId(); source. One article mentioned this is required as you'll have to specify the package when instantiating the class and method.
I then setup my libsignal-protocol.common.ts as follows to attempt and use the native method:
src/libsignal-protocol.common.ts
import { Observable } from 'tns-core-modules/data/observable';
export class Common extends Observable {
constructor() {
// does not work
let test1 = new org.whispersystems.libsignal.util.KeyHelper.generateRegistrationId();
// does not work
let test2 = org.whispersystems.libsignal.util.KeyHelper.generateRegistrationId();
console.log(test1);
console.log(test2);
}
}
To my dismay, the logger returned this error:
System.err: Error: java.lang.Exception: Failed resolving method generateRegistrationId on class org.whispersystems.libsignal.util.KeyHelper
I am not sure where else to go here now, I wanted to go this route as it seemed safer/cleaner to create a wrapper for this awesome Java library than trying to browserify their javascript library as it requires certain features not available within Nativescript.
Any help or suggestions would be appreciated! For sanity, I will include some articles I have found on this matter that has helped lead me to where I am now.
Sources
Using libsodium in Android/Nativescript
How to use JAR file in Nativescript
As you see in the source code generateRegistrationId method expects one boolean argument.
public static int generateRegistrationId(boolean extendedRange) {
try {
SecureRandom secureRandom = SecureRandom.getInstance("SHA1PRNG");
if (extendedRange) return secureRandom.nextInt(Integer.MAX_VALUE - 1) + 1;
else return secureRandom.nextInt(16380) + 1;
} catch (NoSuchAlgorithmException e) {
throw new AssertionError(e);
}
}
So you must pass a boolean to the method,
let test2 = org.whispersystems.libsignal.util.KeyHelper.generateRegistrationId(false);
I m actually trying to work with both coffeescript and typescript in the same project.
In fact, I want to be able to chose which one I prefer when coding.
The fact is that the javascript generated by typescript doesn't seem to work as expected with the javascript generated with coffeescript
Explanation :
I wrote a Controller class with coffeescript which works perfectly when I extend it in a coffeescript file like below :
Controller = require('../node_modules/Controller/Controller')
class HelloController extends Controller
indexAction: (name) =>
console.log 'hey '+ name
module.exports = HelloController
But when I try to use it with typescript like below :
import Controller = require('../node_modules/Controller/Controller');
export class HelloController extends Controller {
constructor() {
super()
}
indexAction(name:String) {
console.log('hey '+name);
}
}
I got an error telling me that the controller cant be find at the expected place (the .js file is well generated)
Can you help me ?
If you want to do this, you'll need to supply type information about the Coffeescript-generated JavaScript file.
If you add a Controller.d.ts you can describe the types in your controller file so TypeScript can apply that type information during compilation.
For example:
declare class Controller {
protected name: string;
//... more type information
}
export = Controller;
Of course, you are essentially undertaking far more work writing JavaScript or Coffeescript and then also writing type information in another file - so you may want to make a decision on a per-unit basis about what you are going to write the program in. For example, if you write a tool-kit in Coffeescript, it is easy to write a single .d.ts file for it - whereas if you write a file here and there in Coffeescript you're going to have a bit of a maintenance nightmare (either creating lots of .d.ts files or managing a single merged one each time you change one of the parts).
Definition files work best against a stable API.