Bukkit Custom Prefix plugin doesn't work with Essentials - java

I'm making a plugin that will have ranks in the near future, but I decided to get past prefixes first. I have this code:
Essentials ess = (Essentials) Bukkit.getServer().getPluginManager().getPlugin("Essentials");
User user = ess.getUserMap().getUser(p.getName());
//nickname
String nick = user.getDisplayName();
String prisoner = ColourMsg("&5<<&bPrisoner&5>>&r>" + " <");
p.setDisplayName(prisoner + nick);
For some reason, this code doesn't work! It only displays the nickname, and not the prefix (I would expect it to display both). Also, the only error message I get is from essentials chat, which isn't needed for my plugin and /nick still works.
If anyone can help, please let me know.
Thanks in advance!

You don't need Essentials for that (Essentials is a bad plugin anyway, since 1.8).
You can simply use scoreboard prefixes/suffix in the PlayerJoinEvent to set the tags.
Scoreboard sb = Bukkit.getScoreboardManager().getNewScoreboard();
Objective ob = sb.registerNewObjective("objName", "dummy");
public void onEnable() {
// Set Display slot
ob.setDisplaySlot(DisplaySlot.PLAYER_LIST);
}
public void onJoin(PlayerJoinEvent e) {
// Delay a task
Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(this, new Runnable() {
#Override
public void run() {
if (e.getPlayer().hasPermission("tags.example")) {
sb.registerNewTeam("Example");
Team team = sb.getTeam("Example");
team.setPrefix(ChatColor.RED + "[Example]");
team.addEntry(e.getPlayer().getName());
} else if (e.getPlayer().hasPermission("tags.otherTag")) {
sb.registerNewTeam("OtherTag");
Team team = sb.getTeam("OtherTag");
team.setPrefix(ChatColor.GREEN + "[OtherTag]");
team.addEntry(e.getPlayer().getName());
}
}
}, 20 * 1); // The 1 is the number of seconds to delay, 1 is fine
}

Related

How i can update this Setlist of users?

I need some help guys. I'm making a chat who read an XML each 10 sec aprox (yeah the database is the XML, congrats my teacher, we can't change database format xDD)
So on, my question now i create the function, replace the messages is easy, if the xml messages are more than RAM one, then i clear the ram and then add all messages again, but i can't do that to users, i don't know why but i think equals or something is broken(? i don't know pls help me my brain is about to break!
if (temp.getList().size() > roomList.getList().size()) {
for (Room room_xml : temp.getList()) {
if (roomList.addRoom(room_xml)) {
System.out.println("A room was loaded");
}
}
} else {
for (Room room_xml : temp.getList()) {
for (Room room_ram : roomList.getList()) {
if (room_ram.equals(room_xml)) {
if (room_ram.getMessageList().size() < room_xml.getMessageList().size()) {
room_ram.getMessageList().clear();
room_ram.getMessageList().addAll(room_xml.getMessageList());
}
Set<User> us_xml = room_xml.getUserList();
for(User u_xml: us_xml){
for(User u_ram: room_ram.getUserList()){
if(room_ram.getUserList().add(u_xml)){
System.out.println("User was added(?");
}
}
}
/*for (User u_xml : room_xml.getUserList()) {
if(room_ram.getUserList().add(u_xml)){
System.out.println("User was added(?");
}else{
break;
}
}*/
I share my proyect on github if u need more info about that : https://github.com/Varo95/ChaTerra
This code is on RoomListDAO.java
PD: I put print but i use javafx xd
I got another idea, like declaring actual_user on roomdao and check on xml is on the list to add one....but doesn't seems to work :(
I already resolve it, thanks any way, i already do this and seems to work:
RoomList temp = load();
if (temp.getList().size() > roomList.getList().size()) {
for (Room room_xml : temp.getList()) {
if (roomList.addRoom(room_xml)) {
System.out.println("Room was loaded on RAM");
}
}
} else {
for (Room room_xml : temp.getList()) {
for (Room room_ram : roomList.getList()) {
if (room_ram.equals(room_xml)) {
if (room_ram.getMessageList().size() < room_xml.getMessageList().size()) {
room_ram.getMessageList().clear();
room_ram.getMessageList().addAll(room_xml.getMessageList());
}
room_ram.getUserList().clear();
room_ram.getUserList().addAll(room_xml.getUserList());
}
break;
}
}
}
saveFile(roomList);
And saving it too when user left the room or join but i need to make some little fixes more hahahaha well now i feel good with myself

View all comments on a YouTube video

I am trying to get all the comments on a YouTube video using a Java program. I cannot get them though as it has the "Show More" instead of all the comments. I'm looking for a way to get all the comments or pages of comments that I can go through. I have a video id and things, just need the comments.
I have tried all_comments instead of watch in the URL but it doesn't show all comments still and redirects to watch again.
I have also looked at the YouTube api and can only find how to get comments with their id but I need to get all comments from a video id.
If anyone knows how to do this please tell me.
I have added a 50 rep bounty for whoever can give me a good answer to this.
You need to get comment threads list request for your video and then scroll forward using next page token from the last response:
private static int counter = 0;
private static YouTube youtube;
public static void main(String[] args) throws Exception {
// For Auth details consider:
// https://github.com/youtube/api-samples/blob/master/java/src/main/java/com/google/api/services/samples/youtube/cmdline/Auth.java
// Also don't forget secrets https://github.com/youtube/api-samples/blob/master/java/src/main/resources/client_secrets.json
List<String> scopes = Lists.newArrayList("https://www.googleapis.com/auth/youtube.force-ssl");
Credential credential = Auth.authorize(scopes, "commentthreads");
youtube = new YouTube.Builder(Auth.HTTP_TRANSPORT, Auth.JSON_FACTORY, credential).build();
String videoId = "video_id";
// Get video comments threads
CommentThreadListResponse commentsPage = prepareListRequest(videoId).execute();
while (true) {
handleCommentsThreads(commentsPage.getItems());
String nextPageToken = commentsPage.getNextPageToken();
if (nextPageToken == null)
break;
// Get next page of video comments threads
commentsPage = prepareListRequest(videoId).setPageToken(nextPageToken).execute();
}
System.out.println("Total: " + counter);
}
private static YouTube.CommentThreads.List prepareListRequest(String videoId) throws Exception {
return youtube.commentThreads()
.list("snippet,replies")
.setVideoId(videoId)
.setMaxResults(100L)
.setModerationStatus("published")
.setTextFormat("plainText");
}
private static void handleCommentsThreads(List<CommentThread> commentThreads) {
for (CommentThread commentThread : commentThreads) {
List<Comment> comments = Lists.newArrayList();
comments.add(commentThread.getSnippet().getTopLevelComment());
CommentThreadReplies replies = commentThread.getReplies();
if (replies != null)
comments.addAll(replies.getComments());
System.out.println("Found " + comments.size() + " comments.");
// Do your comments logic here
counter += comments.size();
}
}
Consider api-samples, if you need a sample skeleton project.
Update
The situation when you can't get all the comments can be also caused by the quota limits (at least I faced it):
units/day 50,000,000
units/100seconds/user 300,000
This is not a java, python, js, or whatever language specific rules. If you want to get above the quota, you cant try to apply for higher quota. Though, I would start from controlling your throughput. It's very easy to get above the 100seconds/user quota.
try this it can download all the comments for a given video which i have tested.
https://github.com/egbertbouman/youtube-comment-downloader
python downloader.py --youtubeid YcZkCnPs45s --output OUT
Downloading Youtube comments for video: YcZkCnPs45s
Downloaded 1170 comment(s)
Done!
output is in the JSON format:
{
"text": "+Tony Northrup many thanks for the prompt reply - I'll try that.",
"time": "1 day ago",
"cid": "z13nfbog0ovqyntk322txzjamuensvpch.1455717946638546"
}

Robovm Local notifications not showing up. Scheduling seems successful. Am I missing something?

I am trying to get local/scheduled notifications working. With push messages (using Parse) working fine I though local would be easy, but even though the registration seems to go fine (didRegisterUserNotificationSettings is fired) and the scheduling seems to work too, the notification does not show up. I have tested on iOS 7 (iphone 4) and iOS 9 (iphone simulator). What am I missing?
here is my code:
#Override
public boolean didFinishLaunching(UIApplication application,UIApplicationLaunchOptions launchOptions)
{
boolean retval = super.didFinishLaunching(application, launchOptions);
//some other stuff happens here regarding parse push. But since this works I have cut it out
registerForPush();
return retval;
}
public void registerForPush()
{
if (IOSLauncher.getOSMajorVersion() >= 8)
{
UIUserNotificationType userNotificationTypes = UIUserNotificationType.with(UIUserNotificationType.Alert, UIUserNotificationType.Badge, UIUserNotificationType.Sound);
UIUserNotificationSettings settings = new UIUserNotificationSettings(userNotificationTypes, null);
application.registerUserNotificationSettings(settings);
application.registerForRemoteNotifications();
}
else
{
UIRemoteNotificationType type = UIRemoteNotificationType.with(UIRemoteNotificationType.Alert, UIRemoteNotificationType.Badge, UIRemoteNotificationType.Sound);
application.registerForRemoteNotificationTypes(type);
}
}
public void scheduleNotification(String title, String text, Date date, int ID)
{
UILocalNotification notification = new UILocalNotification();
if(getOSMajorVersion() >= 8 && getOSMinorVersion() >= 2)
notification.setAlertTitle(title);
notification.setAlertBody(text);
notification.setFireDate(new NSDate(date));
NSMutableDictionary<NSObject, NSObject> dict = new NSMutableDictionary<>();
dict.put("id",NSNumber.valueOf(ID));
notification.setUserInfo(dict);
UIApplication.getSharedApplication().scheduleLocalNotification(notification);
}
Edit:
After settting the notification it is present in the array returned by:
UIApplication.getSharedApplication.getScheduledLocalNotifications();
The problem was resolved after Adding:
notification.setTimeZone(NSTimeZone.getLocalTimeZone());
and setting the expire time of my test timer from 1 minute to 5 minutes
I'm not sure which is the actual solution, but the problem is gone, so I'm happy!
EDIT:
UILocalNotification notification = new UILocalNotification();
notification.setAlertTitle("title");
notification.setAlertBody("text");
NSMutableDictionary<NSObject, NSObject> dict = new NSMutableDictionary<>();
//add any customer stuff to your dictionary here
notification.setUserInfo(dict);
notification.setFireDate(new NSDate(date)); //date is some date in the future. Make sure it is in the correct TZ. If it does not work, try to make it at least 5 minutes in the future. I remember this helping my situation
notification.setTimeZone(NSTimeZone.getLocalTimeZone());
UIApplication.getSharedApplication().scheduleLocalNotification(notification);

Tree Tagger for Java (tt4j)

I am creating a Twitter Sentiment Analysis tool in Java. I am using the Twitter4J API to search tweets via the hashtag feature in twitter and then provide sentiment analysis on these tweets. Through research, I have found that the best solution to doing this will be using a POS and TreeTagger for Java.
At the moment, I am using the examples provided to see how the code works, although I am encountering some problems.
This is the code
import org.annolab.tt4j.*;
import static java.util.Arrays.asList;
public class Example {
public static void main(String[] args) throws Exception {
// Point TT4J to the TreeTagger installation directory. The executable is expected
// in the "bin" subdirectory - in this example at "/opt/treetagger/bin/tree-tagger"
System.setProperty("treetagger.home", "/opt/treetagger");
TreeTaggerWrapper tt = new TreeTaggerWrapper<String>();
try {
tt.setModel("/opt/treetagger/models/english.par:iso8859-1");
tt.setHandler(new TokenHandler<String>() {
public void token(String token, String pos, String lemma) {
System.out.println(token + "\t" + pos + "\t" + lemma);
}
});
tt.process(asList(new String[] { "This", "is", "a", "test", "." }));
}
finally {
tt.destroy();
}
}
}
At the moment, when this is run, I receive an error which says
TreeTaggerWrapper cannot be resolved to a type
TokenHandler cannot be resolved to a type
I will be grateful for any help given
Thank you

How do I get a RateLimitStatus object in Twitter4j?

I'm trying to make a method public void limit() that checks the rate limit and sleeps however long it is until the reset if it is being rate limited. I cannot, however, figure out how to make a RateLimitStatus. I have tried:
RateLimitStatus status = twitter.getRateLimitStatus();
but it doesn't actually return a RateLimitStatus... Quite frankly, I'm not sure what the point of that is. Anyway, if anyone is aware of how to get a RateLimitStatus, their help would be much appreciated as currently my project is capable of crashing due to rate limits and I'd like to change this.
Thanks in advance!
The new Twitter API has a rate limit status per resource “family”, so twitter.getRateLimitStatus() returns a mapping between families/endpoints and rate limit statuses, e.g.:
RateLimitStatus status = twitter.getRateLimitStatus().get("/users/search");
// Better: specify the family
RateLimitStatus status2 = twitter.getRateLimitStatus("users").get("/users/search");
So, you could write a method public void limit(String endpoint), which would check the proper rate limit status.
public void limit(String endpoint) {
String family = endpoint.split("/", 3)[1];
RateLimitStatus status = twitter.getRateLimitStatus(family).get(endpoint);
// do what you want…
}
You’ll then call it with .limit("/users/search").
Map<String ,RateLimitStatus> rateLimitStatus = twitter.getRateLimitStatus();
for (String endpoint : rateLimitStatus.keySet()) {
RateLimitStatus status = rateLimitStatus.get(endpoint);
System.out.println("Endpoint: " + endpoint);
System.out.println(" Limit: " + status.getLimit());
System.out.println(" Remaining: " + status.getRemaining());
System.out.println(" ResetTimeInSeconds: " + status.getResetTimeInSeconds());
System.out.println(" SecondsUntilReset: " + status.getSecondsUntilReset());
}
Twitter API also allows for:
Log.d("TwitterActivity", "Limit:" + mTwitter.getFavorites().getRateLimitStatus().getLimit());
Where:
mTwitter is your Twitter object
getFavorites() can be replaced by any other function that Twitter4j provides for the Twitter object
getLimit() is but one of the various options you can choose
You can check like so:
if(mTwitter.getFavorites().getRateLimitStatus().getLimit() <= 0){
//do something
}

Categories

Resources